//<script language="JavaScript" src="../includes/valida_data.js" type="text/JavaScript">
function valida_campos(path){
	for (a=0;a < path.length;a++) {
		if (path[a].getAttribute("obrigatorio") != null && path[a].value == "") {
			alert("O campo '"+ path[a].getAttribute("legenda")+"' deve ser preenchido!");
			path[a].focus();
			return false;
		}
	
	}
	return true;
}

function FormatText(campo) { 
		var valid = /[a-zA-Z0-9 @.();,:\/\\]/;
		var ok = "yes";
		var val = "";
		var temp;
		for (var i=0; i< campo.value.length; i++) {
			
			temp = "" + campo.value.substring(i, i+1);
			if (!valid.exec(temp)){
				ok = "no";
				val = campo.value.substring(0, i);
			}
		}
		if (ok == "no") {
			campo.value = val;
	    }
}
//função que forma o horário 
function formatHora(campo, proximo_campo) { 
	 if((event.keyCode != 8) && (event.keyCode != 37 )&&( event.keyCode != 39)) 
	 { 
		 var cont = campo.value.length; // verifica a qtd de letra
		 if (cont = 2){ // verifica se hora foidigitada
		   campo.value += ":";
		 }
		 else if(cont >= 5 ){  // verifica se minutos foi digitado
		   document.form1[proximo_campo].focus(); 
		 }
	 }  
} 
function validaChecked(obj,texto){

	var a=0;
	count = obj.length;
	for (i=0;i < count;i++){
		if  (obj[i].checked == true) {
			a = 1;
		}
	}
	return alerta(a,texto);
}
function alerta(a,texto){

	if (a == 1) {
		return true;
	}
	else {
		alert(texto);
		return false;
	}

}
/* funcao que verifica o preenchimento dos campos do formulario */
function validacampo(campo, msg){
    if(campo.value == ""){
		alert(msg);
		campo.focus();
		return false;
	}
	return true;
}

/* funcao que verifica o preenchimento dos campos de e-mail do formulário */
function validaemail(campo, msg) {
	if (campo.value.indexOf("@") == -1 ){
		alert(msg);
		campo.focus();
		return false;
	}

	 return true;
}

/* funcao que verifica o preenchimento dos campos select */
function validacamposelect(campo, msg){
	if (campo.selectedIndex == "0"){
		alert(msg);
		campo.focus();
		return false;
	}
	return true;
}

//Declarando variáveis para controlar a versão do navegador.
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
var ns6=document.getElementById&&!document.all;
var ns4=document.layers;

function retornaObj(obj){
	if (ie4){
		return document.all[obj];
	} else if (ns6) { 
		return document.getElementById(""+obj+"");
	} else if (ns4) { 
	 	return document[obj];
	} else {
		return document.getElementById(""+obj+"") ;
	}
}
function retornaObjPai(obj){
	if (ie4){
		return parent.document.all[obj];
	} else if (ns6) { 
		return parent.document.getElementById(""+obj+"");
	} else if (ns4) { 
	 	return parent.document[obj];
	} else {
		return parent.document.getElementById(""+obj+"") ;
	}
}
//funcção  para abrir janela popup
function NewWindow(mypage,myname,w,h,scroll,bars){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=no,';
	settings +='scrollbars='+bars;
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}
function centralizar()
{
	var top = (screen.width-window.document.body.clientWidth)/2;
	var left = (screen.height-window.document.body.clientHeight)/2;
	window.moveTo(top,left); 
}
//Funcção para somente deixar digitar números;
function ValidaNum(Campo) {
	var valid = "0123456789";
	var ok = "yes";
	var val = "";
	var temp;
	for (var i=0; i< Campo.value.length; i++) {
		temp = "" + Campo.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			ok = "no";
			val = Campo.value.substring(0, i);
		}
	}
	if (ok == "no") {
		Campo.value = val;
		Campo.focus();
   }
}
//Funcção para somente deixar digitar números;
function ValidaNumUm(Campo) {
	var valid = "123456789";
	var ok = "yes";
	var val = "";
	var temp;
	for (var i=0; i< 1; i++) {
		temp = "" + Campo.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			ok = "no";
			val = Campo.value.substring(0, i);
		}
	}
	if (ok == "no") {
		Campo.value = val;
		Campo.focus();
   }
}
function validaCEP(obj) {

 var data = new String(obj.value);
 var dataok = '';
 var cont = 0;

 
	 for (i = 0; i < data.length; i++) {
		  if ((data.charAt(i) >= '0') && (data.charAt(i) <= '9') || (data.charAt(i) == '-') && i==5) {
			dataok += data.charAt(i);
		  }
		  else cont++;
	 }
		
	 if (cont > 0) {  
		obj.value = dataok;
	 }

	if (obj.value.indexOf("-") == -1 && obj.value.length > 5){ 
		obj.value = ""; 
	}
	if (obj.value.length == 5){
		obj.value += "-";
	}
}