CheckTAB=true;
function Mostra(quem,tammax) {
   if ( (quem.value.length == tammax) && (CheckTAB) ) { 
     var i=0,j=0, indice=-1;
     for (i=0; i<document.forms.length; i++) { 
       for (j=0; j<document.forms[i].elements.length; j++) { 
          if (document.forms[i].elements[j].name == quem.name) { 
            indice=i;
            break;
          } 
       } 
       if (indice != -1) break; 
     } 
     for (i=0; i<=document.forms[indice].elements.length; i++) { 
       if (document.forms[indice].elements[i].name == quem.name) { 
          while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
                  (i < document.forms[indice].elements.length) ) { 
             i++;
          }
          document.forms[indice].elements[(i+1)].focus();
          CheckTAB=false;
          break;
       } 
     } 
   } 
} 

function isNum( caractere )
{
        var strValidos = "0123456789"
        if ( strValidos.indexOf( caractere ) == -1 )
                return false;
        return true;
}

function PararTAB(quem) { CheckTAB=false; } 
function validaTecla(campo, event)
{
        var BACKSPACE=  8;
        var key;
        var tecla;

        CheckTAB=true;
        if(navigator.appName.indexOf("Netscape")!= -1)  
                tecla= event.which;     
        else
                tecla= event.keyCode;

        key = String.fromCharCode( tecla);
        //alert( 'key: ' + tecla + '  -> campo: ' + campo.value);

        if ( tecla == 13 )
                return false;
        if ( tecla == BACKSPACE )
                return true;
        return ( isNum(key));   
} 

function FormataData( el )
{
        vr = el.value;
        tam = vr.length;

        if ( tam > 2 && tam <= 4 )
                el.value = vr.substr( 0, 2 ) + "/" + vr.substr( 2, tam );
        else if ( tam > 4 ) 
                el.value = vr.substr( 0, 2 ) + "/" + vr.substr( 2, 2 ) + "/" + vr.substr( 4, 4 );
        
        return true;
}

var nome_ent = "";
var endereco_ent = "";
var bairro_ent = "";
var cep_ent = "";
var cidade_ent = "";
var uf_ent = "";
var state_province_ent = "";
var pais_ent = "";
var pais_ent_Index = 0;
var uf_ent_Index = 0;


function Init(form) {
nome_ent = form.nome_ent.value;
endereco_ent = form.endereco_ent.value;
bairro_ent = form.bairro_ent.value;
cep_ent = form.cep_ent.value;
cidade_ent = form.cidade_ent.value;
pais_ent_Index = form.pais_ent.selectedIndex;
uf_ent_Index = form.uf_ent.selectedIndex;
uf_ent = form.uf_ent[uf_ent_Index].value;
pais_ent = form.pais_ent[pais_ent_Index].value;
state_province_ent = form.state_province_ent.value;
}

function EnderecoCadastroCobranca(form) {
if (form.copy.checked) {
Init(form);
form.nome_ent.value = form.nome_cliente.value;
form.endereco_ent.value = form.endereco.value;
form.bairro_ent.value = form.bairro.value;
form.cep_ent.value = form.cep.value;
form.cidade_ent.value = form.cidade.value;
form.uf_ent.selectedIndex = form.uf.selectedIndex;
form.pais_ent.selectedIndex = form.pais.selectedIndex;
form.state_province_ent.value = form.state_province.value;
}
else {
form.nome_ent.value = nome_ent;
form.endereco_ent.value = endereco_ent;
form.bairro_ent.value = bairro_ent;
form.cep_ent.value = cep_ent;
form.cidade_ent.value = cidade_ent;
form.state_province_ent.value = state_province_ent;
form.uf_ent.selectedIndex = uf_ent_Index;

   }
}

function AlterarQtde(oform,produto_id,url) {
return window.location = "" + url + "?a=1&produto_id=" + produto_id + "&qtde=" + oform + "";
}

function CalculaFrete(uf,url) {

return window.location = "" + url + "?a=2&uf=" + uf + "";

}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function OpenCertDetails()
	{
	thewindow = window.open('https://www.gruposummus.com.br/info_ssl.html', 'anew', config='height=410,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
	}
	
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
  }

//valida cadastro1
function validaCadastro (f) {
	var msg = "Campo de preenchimento obrigatório.";
    if (validaTexto(f.nome_cliente, msg) && isEmail(f.email) && notChecked(f.tipo_pessoa, 2, "Tipo de pessoa: preenchimento obrigatório.") && validaTexto(f.passwd, msg) && validaTexto(f.endereco, msg) && validaTexto(f.cep, msg) && validaTexto(f.cidade, msg) && validaTexto(f.pais, msg) && validaTexto(f.nome_ent, msg) && validaTexto(f.endereco_ent, msg) && validaTexto(f.cep_ent, msg) && validaTexto(f.cidade_ent, msg) && validaTexto(f.pais_ent, msg) && validaTexto(f.ddd, msg) && validaTexto(f.telefone, msg) && senha(f.passwd, f.passwd_confirm, 'Senhas inseridas diferentes. \n\nEntre novamente com as senhas e confirme.') && Verifica_Cep(f.cep) && Verifica_Cep(f.cep_ent)) {
		if (f.pais.value == 'Brasil') {
			if (!validaTexto(f.uf, msg)) return false;
			if (validaTexto(f.cpf_cnpj, msg)) {
				if (!validaCGC_CPF()) return false;
			} else {
				return false;
			}
		}
		if (f.pais_ent.value == 'Brasil') {
			if (!validaTexto(f.uf_ent, msg)) return false;
		}
		if(!ValidarProfessor(f)){
			return false;
			}
		
		return true;
	}
	return false;
}  

//valida cadastro 2
function validaCadastro1 (f) {
	var msg = "Campo de preenchimento obrigatório.";
    if (validaTexto(f.nome_cliente, msg) && isEmail(f.email) && notChecked(f.tipo_pessoa, 2, "Tipo de pessoa: preenchimento obrigatório.")  && validaTexto(f.endereco, msg) && validaTexto(f.cep, msg) && validaTexto(f.cidade, msg) && validaTexto(f.pais, msg) && validaTexto(f.nome_ent, msg) && validaTexto(f.endereco_ent, msg) && validaTexto(f.cep_ent, msg) && validaTexto(f.cidade_ent, msg) && validaTexto(f.pais_ent, msg) && validaTexto(f.ddd, msg) && validaTexto(f.telefone, msg)  && Verifica_Cep(f.cep) && Verifica_Cep(f.cep_ent)) {
		if (f.pais.value == 'Brasil') {
			if (!validaTexto(f.uf, msg)) return false;
			if (validaTexto(f.cpf_cnpj, msg)) {
				if (!validaCGC_CPF()) return false;
			} else {
				return false;
			}
		}
		if (f.pais_ent.value == 'Brasil') {
			if (!validaTexto(f.uf_ent, msg)) return false;
		}
		if(!ValidarProfessor(f)){
			return false;
			}
		
		return true;
	}
	return false;
}  





//cep
 //                     aqui 
 //, obrigatorio --------|
 function Verifica_Cep(cep){
 //Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
 	//var cep    = document.getElementById(cep);
 	var strcep = cep.value;
 	//if((obrigatorio == 1) || (obrigatorio == 0 && strcep != "")){
 		if (strcep.length != 8){
 			alert("CEP informado inválido.");
 			cep.focus();
 			return false
 		}
 			/*		
		else{
			if (strcep.indexOf("-") != 5){
 				alert("Formato de CEP informado inválido.");
 				cep.focus();
 				return false
 			}else{
 				if (isNaN(strcep.replace("-","0"))){
 					alert("CEP informado inválido.");
 					cep.focus();
 					return false
 				}
 			}
 		}
			*/
	//}	
	return true;
 }


//fim cep


function senha (a, b, msg) {
	if (a.value != b.value) {
		alert (msg);
		a.select();
		a.focus();
		return false;
	}
	return true;
}

function isEmail(field) 
{
	if (field.value == '') 
	{
		alert ("\n O campo e-mail está em branco. \n\n\n Por favor preencha o campo e-mail.");
		field.focus();
		return false;
	}
	if (field.value.indexOf ('@',0) == -1 ||
	field.value.indexOf ('.',0) == -1) 
	{
		alert ("\n Seu e-mail está sem \"@\" ou incorreto. \n\n Por favor digite corretamente.")
		field.select();
		field.focus();
		return false;
	}
	return true;
}


function validaTexto (campo, msg){
  if (campo.value == '') {
    alert(msg);
    campo.focus();
    return false;
  }
  return true;
}
function notChecked(a, count, msg) {
	for (x=0; x < count; x++) {
		if (a[x].checked == true) {
			return true;
		}
	}
	alert(msg);
	return false;
}

function date_brzTousa (databrz, destino) {
	dia = databrz.substr(0, 2);
	mes = databrz.substr(3, 2);
	ano = databrz.substr(6, 4);
	destino.value = (ano + '-' + mes + '-' + dia); //retorna data no formato americano.
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


//Validação do professor

function ValidarProfessor(f){
	//validar escola
	if(!f.escola.value){
		alert('Campo de preenchimento obrigatório');
		f.escola.focus();
		return false;
		}
	//validar campus
	if(!f.campus.value){
		alert('Campo de preenchimento obrigatório');
		f.campus.focus();
		return false;
		}
	//validar campus
	if(!f.endereco_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.endereco_escola.focus();
		return false;
		}
	//validar cidade_escola
	if(!f.cidade_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.cidade_escola.focus();
		return false;
		}
	//validar uf_escola
	if(!f.uf_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.uf_escola.focus();
		return false;
		}
	//validar cep_escola
	if(!f.cep_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.cep_escola.focus();
		return false;
		}
	//validar telefone_escola
	if(!f.telefone_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.telefone_escola.focus();
		return false;
		}
	//validar departamento_escola
	if(!f.departamento_escola.value){
		alert('Campo de preenchimento obrigatório');
		f.departamento_escola.focus();
		return false;
		}
	return true;
	
	}

