// Retira os espaços em branco do início e fim do campo (ex: onblur="this.value=this.value.trim();").
String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
// Fim da retira espaços.

function abrir2(URL,apelido) {
  // var www = URL + ende
   var width = 625;
   var height = 500;

   var left = 99;
   var top = 01;
   var nome = document.form_pessoa.nome.value;

   window.open(URL+nome,apelido, 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, menubar=no, scrollbars=yes, resizable=no, fullscreen=no');

}

function Sele(nome,id,tp){
	if (nome != "" && id != "" ){
	//alert (tp);
		//window.opener.document.form_pessoa.nome.value = "";
		//window.opener.document.form_pessoa.id.value = "";
		//window.opener.document.form_pessoa.nome.value += nome;	
		//window.opener.document.form_pessoa.id.value += id;
		window.open('cad_cliente.php?id='+ id +'&tp='+ tp,'principal');
		window.close();
	}
	else{
		alert("Falta parâmetro!");
	}
}

	function confirma(url,apelido){ 
	
		if (confirm("Você deseja realmente exculir esse registro")){
			window.open(url,apelido);
		}
		else{
			return false;
		}
	
	}

/*---------------------------------------------------------------------*/
/* Função que só permite digitar valores numéricos. */
function SoNumero(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

/***************************************************************************************************
Função para validar email.
Parâmetros:
nform = this
ex: checaemail(this)
****************************************************************************************************/
function checaemail(nform) {
	var email = nform.value.toLowerCase();
	nform.value = email;
	if (nform.value == "") {
		//alert("Informe seu e-mail.");
		//nform.focus();
		//nform.select();
		return false;
	} else {
		prim = nform.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("hotmeil.com") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".@") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("@.") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".com.br.") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("/") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("[") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("]") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("(") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(")") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("..") >= 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if((nform.value.indexOf("<") >= 0) || (nform.value.indexOf(">") >= 0)) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if((nform.value.indexOf("script") >= 0) || (nform.value.indexOf("alert") >= 0) || (nform.value.indexOf("input") >= 0)) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
	}
		return true;
}

/*------------------------------------------------------------------------
Validar Data javaScript 2
No evento onblur do input e so vc chamar a função completaData data.
ex: completaData(campo)
------------------------------------------------------------------------*/
function completaData(ObjData) { 
var data = ''; 
var dia = ''; 
var mes = ''; 
var ano = ''; 

data = ObjData.value; 

if (data != '') { 
dia = data.substring(0, data.indexOf("/")); 
ano = data.substring(data.lastIndexOf("/") + 1, data.length); 
mes = data.substring(data.indexOf("/") + 1, data.lastIndexOf("/")) 

dia = dia - 0; 
mes = mes - 0; 

dia = dia < 10 ? "0" + dia: dia; 
mes = mes < 10 ? "0" + mes: mes; 

if(Number(ano) >= 50 && Number(ano) <= 99){ 
ano = "19" + ano; 
} 
else{ 
ano = ano.length < 4 ? "20" + ano: ano; 
} 

ObjData.value = dia + "/" + mes + "/" + ano; 
if (!ValidaDatas(ObjData.value)) { 
ObjData.value = ""; 
alert("Data inválida."); 
ObjData.focus(); 
} 
} 
} 

/*Valida datas*/
function ValidaDatas(strData) 
{ 
var dia, mes, ano, MaxDia; 
if (strData == '') return false; 

dia = strData.substring(0, 2); 
mes = strData.substring(3, 5); 
ano = strData.substring(6, strData.length); 

if(mes <= 12 && mes >= 1){ 
if(strData.length == 10){ 
MaxDia = MaxDiasMes(mes, ano); 
if(dia > MaxDia) return false; 
} 
else{ 
return false; 
} 
} 
else { 
return false; 
} 
return true; 
} 

/*Completa a função ValidaDatas*/
function MaxDiasMes(mes, ano){ 
var DiasMes = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
mes = mes - 0; 
ano = ano - 0; 
if (mes >= 1 && mes <= 12) { 
if (mes == 2) 
return (ano % 4) == 0 ? 29: 28; 
else return DiasMes[mes]; 
} 
} 
