﻿/*-----------------*/
/*      links      */
/*-----------------*/
function styleLinks() {
	// external links
	jQuery('a[href^="http://"]').addClass('external');
	// image links
	jQuery('a[href$=".jpg"]').addClass('image');
	jQuery('a[href$=".png"]').addClass('image');
	jQuery('a[href$=".gif"]').addClass('image');
	// dpci,emt öomls
	jQuery('a[href$=".txt"]').addClass('document');
	jQuery('a[href$=".htm"]').addClass('document');
	jQuery('a[href$=".html"]').addClass('document');
	jQuery('a[href$=".doc"]').addClass('document');
	jQuery('a[href$=".docx"]').addClass('document');
	jQuery('a[href$=".pdf"]').addClass('document');
}

/*-----------------*/
/*      login      */
/*-----------------*/
function initLogin(partialUrl, standardUrl) {
	if (document.location.href.indexOf(standardUrl) < 0) {
		jQuery('a[href*="' + standardUrl + '"]').click(function (e) {
			e.preventDefault();
			var lc = jQuery('#ajaxlogin');
			if (lc.css('display') == 'none') {
				jQuery.ajax({
					type: 'GET',
					url: partialUrl,
					success: function (data) {
						lc.html(data).slideToggle();
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						alert(errorThrown + "\n\n" + textStatus);
						document.location.href = standardUrl;
					}
				});
			}
			else {
				lc.slideToggle();
			}
		});
	}
}


function StatusFormatter(cellvalue, options, rowObject) {
	switch (cellvalue) {
		case "Novo":
			return "<div style='color:#ffffff;background-color:blue;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Pendente Supervisão":
			return "<div style='color:#ffffff;background-color:red;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Pendente Verificação":
			return "<div style='color:#ffffff;background-color:#CC3399;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Pendente Validação":
			return "<div style='color:#ffffff;background-color:red;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Concluído":
			return "<div style='color:#ffffff;background-color:green;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Liberado":
			return "<div style='color:#ffffff;background-color:#669933;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Em Análise":
			return "<div style='color:#000000;background-color:yellow;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		case "Falta Documentos":
			return "<div style='color:#000000;background-color:white;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
		default:
			return cellvalue;
	}
}

function DataFormatter(cellvalue, options, rowObject) {
	if (rowObject.Prioridade == "Urgente")
		return "<div style='color:#ffffff;background-color:red;width: 100%; height: 20px;text-align : center; padding-top:3px;	'>" + cellvalue + "</div>";
	else
		return cellvalue;
}


/*-------------------*/
/* dateTimeFormatter */
/*-------------------*/
function zeroPad(num, count) {
	var numZeropad = num + '';
	while (numZeropad.length < count) {
		numZeropad = "0" + numZeropad;
	}
	return numZeropad;
}
function dateTimeFormatter(cellvalue, options, rowObject) {
	if (!cellvalue) {
		return "";
	}
	var time = cellvalue.replace(/\/Date\(([0-9]*)\)\//, '$1');
	var date = new Date();
	date.setTime(time);
	var format;
	if (options && options.colModel && options.colModel.formatoptions && options.colModel.formatoptions.format) {
		format = options.colModel.formatoptions.format;
	} else {
		format = "G";
	}
	if (format.length == 1) {
		if (format == "d") {
			return zeroPad(date.getDate(), 2) + "/" + zeroPad(date.getMonth() + 1, 2) + "/" + date.getFullYear();
		} else if (format == "g") {
			return zeroPad(date.getDate(), 2) + "/" + zeroPad(date.getMonth() + 1, 2) + "/" + date.getFullYear() + " " + zeroPad(date.getHours(), 2) + ":" + zeroPad(date.getMinutes(), 2);
		} else if (format == "G") {
			return zeroPad(date.getDate(), 2) + "/" + zeroPad(date.getMonth() + 1, 2) + "/" + date.getFullYear() + " " + zeroPad(date.getHours(), 2) + ":" + zeroPad(date.getMinutes(), 2) + ":" + zeroPad(date.getSeconds(), 2);
		} else {
			return "formato desconhecido";
		}
	} else {
		var shortWeekdays = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"];
		var fullWeekdays = ["Domindo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"];
		var shortMonths = ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"];
		var fullMonths = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
		format = format.replace("dddd", "{0}");
		format = format.replace("ddd", "{1}");
		format = format.replace("MMMM", "{2}");
		format = format.replace("MMM", "{3}");
		format = format.replace("dd", zeroPad(date.getDate(), 2));
		format = format.replace("d", date.getDate());
		format = format.replace("MM", zeroPad(date.getMonth() + 1, 2));
		format = format.replace("M", date.getMonth() + 1);
		format = format.replace("yyyy", zeroPad(date.getFullYear(), 4));
		format = format.replace("yy", zeroPad(date.getFullYear(), 2));
		format = format.replace("HH", zeroPad(date.getHours(), 2));
		format = format.replace("H", date.getHours());
		format = format.replace("mm", zeroPad(date.getMinutes(), 2));
		format = format.replace("m", date.getMinutes());
		format = format.replace("{0}", fullWeekdays[date.getDay()]);
		format = format.replace("{1}", shortWeekdays[date.getDay()]);
		format = format.replace("{2}", fullMonths[date.getMonth()]);
		format = format.replace("{3}", shortMonths[date.getMonth()]);
		return format;
	}
}

