// JavaScript Document

function troca(obj){
	if(document.getElementById("DIV_DET_PEDI")){
		pedi = document.getElementById("DIV_DET_PEDI")
		pedi.style.zIndex = 10
	}
	if(document.getElementById("DIV_DET_ORCA")){
		orca = document.getElementById("DIV_DET_ORCA")
		orca.style.zIndex = 10
	}
	obj.style.zIndex = 11
}
function Message(MSG,URL){
	alert(MSG);
	location=URL
}
function validafrmlogon()
{
	des_logn = document.getElementById('DES_LOGN')
	des_pass = document.getElementById('DES_PASS')
	
	if (validaEmail(des_logn)==false)
	{
    	des_logn.focus();
		return false;
	} 	
	if(des_pass.value == "")
	{
		alert("Informe sua senha de acesso.");
		des_pass.focus();
		return false;	
	}	
}

function validFrmSubCate(){
		cod_cate_paii = document.getElementById("COD_CATE_PAII").options[document.getElementById("COD_CATE_PAII").selectedIndex]
		nom_cate = document.getElementById("NOM_CATE")
		
		if(cod_cate_paii.value == ""){
			alert("O campo categoria deve ser informado");
			document.getElementById("COD_CATE_PAII").focus();
			return false;
		}
		if(nom_cate.value == ""){
			alert("O campo nome da sub-categoria deve ser informado");
			nom_cate.focus();
			return false;
		}	
}


function validFrmFaq(){
		cod_cate = document.getElementById("COD_CATE").options[document.getElementById("COD_CATE").selectedIndex]
		des_qust = document.getElementById("DES_QUST")
		des_answ = document.getElementById("DES_ANSW")
		
		if(cod_cate.value == ""){
			alert("O campo categoria deve ser informado");
			cod_cate.focus();
			return false;	
		}
		if(des_qust.value == ""){
			alert("O campo pergunta deve ser informado");
			des_qust.focus();
			return false;	
		}
		if(des_answ.value == ""){
			alert("O campo resposta deve ser informado");
			des_answ.focus();
			return false;	
		}
	}

function validFrmQuestionario()
{
	nom_qust = document.getElementById("NOM_QUST")

	if(nom_qust.value == ""){
			alert("O campo questionário deve ser informado");
			nom_qust.focus();
			return false;
		}
	
}
function validFrmQuestao(){
		cod_qust = document.getElementById("COD_QUST").options[document.getElementById("COD_QUST").selectedIndex]
		cod_tipo_perg = document.getElementById("COD_TIPO_PERG").options[document.getElementById("COD_TIPO_PERG").selectedIndex]
		des_perg = document.getElementById("DES_PERG")

		if(cod_qust.value == ""){
			alert("O campo questionário deve ser informado");
			document.getElementById("COD_QUST").focus();
			return false;	
		}
		if(cod_tipo_perg.value == ""){
			alert("O campo tipo de questão deve ser informado");
			document.getElementById("COD_TIPO_PERG").focus();
			return false;	
		}
		if(des_perg.value == ""){
			alert("O campo pergunta deve ser informado");
			des_perg.focus();
			return false;	
		}
	
	}

function validFrmColaborador()
{
		nom_pess = document.getElementById("NOM_PESS")
		dat_nasc = document.getElementById("DAT_NASC")
		des_sexo = document.getElementById("DES_SEXO")
		cod_esta_civi = document.getElementById("COD_ESTA_CIVI").options[document.getElementById("COD_ESTA_CIVI").selectedIndex]
		des_mail = document.getElementById("DES_MAIL")
		cod_perf = document.getElementById("COD_PERF").options[document.getElementById("COD_PERF").selectedIndex]
		des_logn = document.getElementById("DES_LOGN")
		des_pass = document.getElementById("DES_PASS")
		con_pass = document.getElementById("CON_PASS")
		
		cod_tipo_tele = document.getElementById("COD_TIPO_TELE").options[document.getElementById("COD_TIPO_TELE").selectedIndex]
		des_numb_tele = document.getElementById("DES_NUMB_TELE")
		
		if(nom_pess.value == ""){
			alert("O campo nome deve ser informado");
			nom_pess.focus();
			return false;	
		}
		if(dat_nasc.value == ""){
			alert("O campo data de nascimento deve ser informado");
			dat_nasc.focus();
			return false;	
		}
		if(des_sexo.value == ""){
			alert("O campo sexo deve ser informado");
			des_sexo.focus();
			return false;	
		}
		if(cod_esta_civi.value == ""){
			alert("O campo estado civil deve ser informado");
			cod_esta_civi.focus();
			return false;	
		}
		if(des_mail.value == ""){
			alert("O campo e-mail deve ser informado");
			des_mail.focus();
			return false;	
		}
		if(cod_perf.value == ""){
			alert("O campo perfil deve ser informado");
			cod_perf.focus();
			return false;	
		}
		if(des_logn.value == ""){
			alert("O campo usuario deve ser informado");
			des_logn.focus();
			return false;	
		}
		if(des_pass.value == ""){
			alert("O campo senha deve ser informado");
			des_pass.focus();
			return false;	
		}
		if(des_pass.value != con_pass.value){
			alert("A senha não confere");
			des_pass.focus();
			return false;	
		}
		if(cod_tipo_tele.value != "" || des_numb_tele.value != ""){
			if(cod_tipo_tele.value == ""){
				alert("O campo tipo de telefone deve ser informado");
				cod_tipo_tele.focus();
				return false;	
			}
			if(des_numb_tele.value == ""){
				alert("O campo telefone deve ser informado");
				des_numb_tele.focus();
				return false;	
			}
		}
		if(document.getElementById("FLG_EXIST").value == "1"){
			alert("A verificacao de usuário é necessária")
			document.getElementById("BTO_VERI_LOGN").focus()
			return false;
		}
}

	function MostraFormPessoa(){
		cod_tipo_pess = document.getElementById("COD_TIPO_PESS").options[document.getElementById("COD_TIPO_PESS").selectedIndex]
		if(parseInt(cod_tipo_pess.value) == 2){
			document.getElementById("liPjuridica").style.display = 'block'
			document.getElementById("liPfisica").style.display = 'none'
			if(document.getElementById("liMsgPessoa"))
			document.getElementById("liMsgPessoa").style.display = 'none'
		}else if(parseInt(cod_tipo_pess.value) == 1){
			document.getElementById("liPfisica").style.display = 'block'
			document.getElementById("liPjuridica").style.display = 'none'
			if(document.getElementById("liMsgPessoa"))
			document.getElementById("liMsgPessoa").style.display = 'none'
		}else{
			document.getElementById("liPfisica").style.display = 'none'
			document.getElementById("liPjuridica").style.display = 'none'
			if(document.getElementById("liMsgPessoa"))
			document.getElementById("liMsgPessoa").style.display = 'block'
		}
	}
	
	function validFrmCliente(){
		
		cod_tipo_pess = document.getElementById("COD_TIPO_PESS").options[document.getElementById("COD_TIPO_PESS").selectedIndex]
		DES_NUMB_DDDD = document.getElementById("DES_NUMB_DDDD")
		DES_NUMB_TELE = document.getElementById("DES_NUMB_TELE")
		
		nom_pess = document.getElementById("NOM_PESS")
		dat_nasc_diaa = document.getElementById("DAT_NASC_DIAA").options[document.getElementById("DAT_NASC_DIAA").selectedIndex]
		dat_nasc_mess = document.getElementById("DAT_NASC_MESS").options[document.getElementById("DAT_NASC_MESS").selectedIndex]
		dat_nasc_anoo = document.getElementById("DAT_NASC_ANOO").options[document.getElementById("DAT_NASC_ANOO").selectedIndex]
		des_sexo = document.getElementById("DES_SEXO").options[document.getElementById("DES_SEXO").selectedIndex]
		cod_esta_civi = document.getElementById("COD_ESTA_CIVI").options[document.getElementById("COD_ESTA_CIVI").selectedIndex]
		des_numb_doc1 = document.getElementById("DES_NUMB_DOC1")
		des_numb_doc2 = document.getElementById("DES_NUMB_DOC2")
		
		nom_pess_juri = document.getElementById("NOM_PESS_JURI")
		nom_fant = document.getElementById("NOM_FANT")
		des_numb_doc1_juri = document.getElementById("DES_NUMB_DOC1_JURI")
		des_numb_doc2_juri = document.getElementById("DES_NUMB_DOC2_JURI")
		
		nom_pess_cont = document.getElementById("NOM_PESS_CONT")
		dat_nasc_diaa_cont = document.getElementById("DAT_NASC_DIAA_CONT").options[document.getElementById("DAT_NASC_DIAA_CONT").selectedIndex]
		dat_nasc_mess_cont = document.getElementById("DAT_NASC_MESS_CONT").options[document.getElementById("DAT_NASC_MESS_CONT").selectedIndex]
		dat_nasc_anoo_cont = document.getElementById("DAT_NASC_ANOO_CONT").options[document.getElementById("DAT_NASC_ANOO_CONT").selectedIndex]
		des_sexo_cont = document.getElementById("DES_SEXO_CONT").options[document.getElementById("DES_SEXO_CONT").selectedIndex]
		des_dept_cont = document.getElementById("DES_DEPT_CONT")
		
		cod_tipo_ende = document.getElementById("COD_TIPO_ENDE").options[document.getElementById("COD_TIPO_ENDE").selectedIndex]
		cod_tipo_logr = document.getElementById("COD_TIPO_LOGR").options[document.getElementById("COD_TIPO_LOGR").selectedIndex]
		
		nom_logr = document.getElementById("NOM_LOGR")
		
		
		
		
		cod_esta = document.getElementById("COD_ESTA").options[document.getElementById("COD_ESTA").selectedIndex]
		cod_cida = document.getElementById("COD_CIDA").options[document.getElementById("COD_CIDA").selectedIndex]
		des_numb_cepp = document.getElementById("DES_NUMB_CEPP")
		
		email = document.getElementById("email")
		flg_exist = document.getElementById("FLG_EXIST")
		des_pass = document.getElementById("DES_PASS")
		con_pass = document.getElementById("CON_PASS")
		
		cod_tipo_tele = document.getElementById("COD_TIPO_TELE").options[document.getElementById("COD_TIPO_TELE").selectedIndex]
		des_numb_tele = document.getElementById("DES_NUMB_TELE")
		
		cod_tipo_tele2 = document.getElementById("COD_TIPO_TELE2").options[document.getElementById("COD_TIPO_TELE2").selectedIndex]
		des_numb_tele2 = document.getElementById("DES_NUMB_TELE2")
		
		if(cod_tipo_pess.value == ""){
			alert("O campo tipo de pessoa deve ser informado");
			document.getElementById("COD_TIPO_PESS").focus();
			return false;	
		}
		
if(parseInt(cod_tipo_pess.value) == 1){
			
			//Nome contato
			if(nom_pess.value == ""){
				alert("O campo Nome deve ser informado");
				nom_pess.focus();
				return false;	
			}
			


			//tipo	
			if(document.getElementById("COD_TIPO_ENDE").value == ""){
				alert("O campo Tipo de Endereço deve ser informado");
				document.getElementById("COD_TIPO_ENDE").focus();
				return false;	
			}

			if(document.getElementById("COD_TIPO_LOGR").value == ""){
				alert("O campo Tipo deve ser informado");
				document.getElementById("COD_TIPO_LOGR").focus();
				return false;	
			}

			//logradouro
			if(nom_logr.value == ""){
				alert("O campo Endereço deve ser informado");
				nom_logr.focus();
				return false;	
			}
			
			if(document.getElementById("DES_NUMB_LOGR").value == ""){
				alert("O campo Número deve ser informado");
				document.getElementById("DES_NUMB_LOGR").focus();
				return false;	
			}
			
			if(document.getElementById("DES_BAIR").value == ""){
				alert("O campo Bairro deve ser informado");
				document.getElementById("DES_BAIR").focus();
				return false;	
			}
			
			if(document.getElementById("DES_BAIR").value == ""){
				alert("O campo Bairro deve ser informado");
				document.getElementById("DES_BAIR").focus();
				return false;	
			}
			
			if(cod_esta.value == ""){
				alert("O campo Estado deve ser informado");
				cod_esta.focus();
				return false;	
			}
			
			if(cod_cida.value == ""){
				alert("O campo Cidade deve ser informado");
				cod_cida.focus();
				return false;	
			}
			
			if(des_numb_cepp.value == ""){
				alert("O campo CEP deve ser informado");
				des_numb_cepp.focus();
				return false;	
			}
			
			
			
			
			
			

		//e-mail
		if(email.value == ""){
			alert("O campo E-Mail deve ser informado");
			email.focus();
			return false;	
		}

		if (validaEmail(email)==false){
			//alert("O E-Mail não e válido");
			email.focus();
			return false;	
		}

		if(flg_exist.value == "1"){
			alert("Verifique o nome de usuário");
			document.getElementById("BTO_VERI_LOGN").focus();
			return false;	
		}

		if(des_pass.value == ""){
			alert("O campo Senha deve ser informado");
			des_pass.focus();
			return false;	
		}

		if(con_pass.value == ""){
			alert("O confirme sua senha");
			con_pass.focus();
			return false;	
		}

		if(cod_tipo_tele.value == ""){
			alert("O campo Tipo do telefone deve ser informado");
			document.getElementById("COD_TIPO_TELE").focus();
			return false;	
		}

		
		if(DES_NUMB_DDDD.value == ""){
			alert("O campo DDD deve ser informado");
			DES_NUMB_DDDD.focus();
			return false;	
		}

		if(DES_NUMB_TELE.value == ""){
			alert("O campo Telefone deve ser informado");
			DES_NUMB_TELE.focus();
			return false;	
		}

			
}

if(parseInt(cod_tipo_pess.value) == 2){
	
		if(nom_pess_juri.value == ""){
			alert("O campo Razão Social deve ser informado");
			nom_pess_juri.focus();
			return false;	
		}
	
		if(des_numb_doc2_juri.value == ""){
			alert("O campo C.N.P.J deve ser informado");
			des_numb_doc2_juri.focus();
			return false;	
		}

		if(nom_pess_cont.value == ""){
			alert("O campo Nome do contato deve ser informado");
			nom_pess_cont.focus();
			return false;	
		}

		if(des_dept_cont.value == ""){
			alert("O campo Departamento deve ser informado");
			des_dept_cont.focus();
			return false;	
		}

		//tipo	
		if(document.getElementById("COD_TIPO_ENDE").value == ""){
			alert("O campo Tipo de Endereço deve ser informado");
			document.getElementById("COD_TIPO_ENDE").focus();
			return false;	
		}

		if(document.getElementById("COD_TIPO_LOGR").value == ""){
			alert("O campo Tipo deve ser informado");
			document.getElementById("COD_TIPO_LOGR").focus();
			return false;	
		}


		if(nom_logr.value == ""){
			alert("O campo Endereço deve ser informado");
			nom_logr.focus();
			return false;	
		}
		
		
					
		if(document.getElementById("DES_NUMB_LOGR").value == ""){
				alert("O campo Número deve ser informado");
				document.getElementById("DES_NUMB_LOGR").focus();
				return false;	
			}
			
		if(document.getElementById("DES_BAIR").value == ""){
				alert("O campo Bairro deve ser informado");
				document.getElementById("DES_BAIR").focus();
				return false;	
			}
			
		if(document.getElementById("DES_BAIR").value == ""){
				alert("O campo Bairro deve ser informado");
				document.getElementById("DES_BAIR").focus();
				return false;	
			}
			
			if(cod_esta.value == ""){
				alert("O campo Estado deve ser informado");
				cod_esta.focus();
				return false;	
			}
			
			if(cod_cida.value == ""){
				alert("O campo Cidade deve ser informado");
				cod_cida.focus();
				return false;	
			}
			
			if(des_numb_cepp.value == ""){
				alert("O campo CEP deve ser informado");
				des_numb_cepp.focus();
				return false;	
			}
		
		
		
		
		
		
		
		

		//e-mail
		if(email.value == ""){
			alert("O campo E-Mail deve ser informado");
			email.focus();
			return false;	
		}

		if (validaEmail(email)==false){
			//alert("O E-Mail não e válido");
			email.focus();
			return false;	
		}

		if(flg_exist.value == "1"){
			alert("Verifique o nome de usuário");
			document.getElementById("BTO_VERI_LOGN").focus();
			return false;	
		}

		if(des_pass.value == ""){
			alert("O campo Senha deve ser informado");
			des_pass.focus();
			return false;	
		}

		if(con_pass.value == ""){
			alert("O confirme sua senha");
			con_pass.focus();
			return false;	
		}


		if(cod_tipo_tele.value == ""){
			alert("O campo Tipo do telefone deve ser informado");
			document.getElementById("COD_TIPO_TELE").focus();
			return false;	
		}


		if(DES_NUMB_DDDD.value == ""){
			alert("O campo DDD deve ser informado");
			DES_NUMB_DDDD.focus();
			return false;	
		}

		if(DES_NUMB_TELE.value == ""){
			alert("O campo Telefone deve ser informado");
			DES_NUMB_TELE.focus();
			return false;	
		}


}


}

	function validFrmClienteSimples(){

		nom_pess = document.getElementById("NOM_PESS")
	
		nom_logr = document.getElementById("NOM_LOGR")
		
		cod_esta = document.getElementById("COD_ESTA")
		cod_cida = document.getElementById("COD_CIDA")
		des_numb_cepp = document.getElementById("DES_NUMB_CEPP")
		
		email = document.getElementById("email")
		flg_exist = document.getElementById("FLG_EXIST")
		des_pass = document.getElementById("PASS")
		con_pass = document.getElementById("CON_PASS")
		
//alert(email.value);		
//alert(des_pass.value);		
//alert(con_pass.value);		
			
		//e-mail
		if(email.value == ""){
			alert("O campo E-Mail deve ser informado");
			email.focus();
			return false;	
		}

		if (validaEmail(email)==false){
			alert("O E-Mail não e válido");
			email.focus();
			return false;	
		}

		if(flg_exist.value == "1"){
			alert("Verifique o nome de usuário");
			document.getElementById("BTO_VERI_LOGN").focus();
			return false;	
		}

		if(des_pass.value == ""){
			alert("O campo Senha deve ser informado");
			des_pass.focus();
			return false;	
		}

		if(con_pass.value == ""){
			alert("Confirme sua senha");
			con_pass.focus();
			return false;	
		}

		if(con_pass.value != des_pass.value){
			alert("A confirmação da senha não confere");
			con_pass.focus();
			return false;	
		}

		
			//Nome contato
			if(nom_pess.value == ""){
				alert("O campo Nome deve ser informado");
				nom_pess.focus();
				return false;	
			}
			
			if(des_numb_cepp.value == ""){
				alert("O campo CEP deve ser informado");
				des_numb_cepp.focus();
				return false;	
			}


			//logradouro
			if(nom_logr.value == ""){
				alert("O campo Endereço deve ser informado");
				nom_logr.focus();
				return false;	
			}
			
			if(document.getElementById("DES_NUMB_LOGR").value == ""){
				alert("O campo Número deve ser informado");
				document.getElementById("DES_NUMB_LOGR").focus();
				return false;	
			}
			
			if(document.getElementById("DES_BAIR").value == ""){
				alert("O campo Bairro deve ser informado");
				document.getElementById("DES_BAIR").focus();
				return false;	
			}
			
			if(cod_esta.value == ""){
				alert("O campo Estado deve ser informado");
				cod_esta.focus();
				return false;	
			}
			
			if(cod_cida.value == ""){
				alert("O campo Cidade deve ser informado");
				cod_cida.focus();
				return false;	
			}
			
}


	function contato()
	{
		if(document.getElementById("nome_contato").value == ""){
			alert("O campo Nome Contato deve ser informado");
			document.getElementById("nome_contato").focus();
			return false;	
		}
		
		if(document.getElementById("email_contato").value == ""){
			alert("O campo E-mail deve ser informado");
			document.getElementById("email_contato").focus();
			return false;	
		}
		
		if(document.getElementById("telefone_contato").value == ""){
			alert("O campo Telefone deve ser informado");
			document.getElementById("telefone_contato").focus();
			return false;	
		}
		
	}







function FormataCampo(Campo,teclapres,mascara){ 
	strtext = Campo.value 
	tamtext = strtext.length 
	tammask = mascara.length 
	arrmask = new Array(tammask) 
	for (var i = 0 ; i < tammask; i++){ 
		arrmask[i] = mascara.slice(i,i+1) 
	} 

	if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
		if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
			Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) 
		} else { 
			Detona_Event(Campo,strtext) 
		} 
	} else {
		if ((arrmask[tamtext] == "A")) { 
			charupper = event.valueOf() 
			Detona_Event(Campo,strtext) 
			masktext = strtext + charupper 
			Campo.value = masktext 
		} 
	} 
} 

function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
	if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
		separador = arrpos 
		masktext = strtext + separador 
		Campo.value = masktext 
	} 
} 

function Detona_Event(Campo,strtext){ 
	event.returnValue = false 
	if (strtext != "") { 
		Campo.value = strtext 
	} 
} 

function resetaForm(formulario){
	formulario.reset()	
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function validaEmail(campo){
	if (campo.value!="") {
        if (/^([\w\.\-])+\@(([\w\-])+\.)+([\w ]{2,4})$/.test(campo.value)==false) {
            alert("E-mail inválido!");
            return false;
        }
    }
}
// -->

function verificaUsuario(cod_usua){
	email = $('email').value;
	new Ajax.Request('AJAX/VERIFICALOGN.asp?DES_LOGN='+email+'&COD_USUA=' + cod_usua,{
			method: 'get',
		
			onSuccess: function(transport)
			{
			var response = transport.responseText || "no response text";

			if (response == '1') {
				alert("O login "+ email +" já está cadastrado")
			}
			
			if (response == '2') {
				alert("O login "+ email +" está disponível")
				$('FLG_EXIST').value=0;
			}
			
			},
			
			onFailure: function(transport)
			{
			 	alert("Ocorreu um erro. Por favor, tente novamente.");
			
			},
			
			onException: function(err)
			{
			 	alert("Ocorreu um erro. Por favor, tente novamente.");
			}
			});
}

/*function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}
*/
function remCadastro(){
var r=confirm("Tem certeza que deseja remover seu cadastro?")
  if (r==true)
    {
    	location = "default.asp?Page=12";
    }
  else
    {
		return false;
    }
}

submenu = function() {
 
if (navigator.userAgent.match("MSIE 6.0"))
{
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
onload=submenu;
