// Função que seleciona um campo
function Seleciona(campo)
{
	campo.focus();
	campo.select();
}

// Função que muda o título da página
document.on_load = new function()
{
    top.document.title = document.title;
    return;
}

// Função que preenche as variáveis para centralizar uma janela
function AbrirJanela(url, largura, altura, parametros)
{
	var esquerda = ((screen.width / 2) - (largura / 2));
	var topo     = ((screen.height / 2) - (altura / 2));
	window.open(url, 'Janela', 'left=' + esquerda + ', top=' + topo + ', width=' + largura + ', height=' + altura);
	return;
}

// Função que retira os espaços excedentes de uma string
function Trim(texto){
	texto = texto.replace(/^\s/ig, "");
	texto = texto.replace(/\s+$/ig, "");
	texto = texto.replace(/\s+/ig, " ");
	return(texto);
}

// Função que abre uma janela com a caixa de promessas
/*function Promessas(){
	window.open('/outros/promessa.asp', 'promessa', 'left=' + ((screen.width / 2) - 250) + '; top=' + ((screen.height / 2) - 100) + '; height=200; width=500; location=no; menubar=no; resizable=no; scrollbars=no; status=no; toolbar=no;');
	return;
}*/

function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null){
		//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
	}

	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn`t have 31 days!")
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("O mês de Feveriro de " + year + " não possui o dia " + day + "!");
			return false;
		}
	}
	return true; // date is valid
}
