﻿function NewWindow(url, windowName, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(url, windowName, winprops);
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus();
    }
}
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;
    }
}

