// 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){
	window.alert(MSG);
	window.location=URL
}
function validafrmlogon()
{
	des_logn = document.getElementById('DES_LOGN')
	des_pass = document.getElementById('DES_PASS')
	
	if (!checkMail(des_logn))
	{
    	alert("Email inválido");
		des_logn.focus();
		return false;
	} 	
	if(des_pass.value == "")
	{
		window.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 == ""){
			window.alert("O campo categoria deve ser informado");
			document.getElementById("COD_CATE_PAII").focus();
			return false;
		}
		if(nom_cate.value == ""){
			window.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 == ""){
			window.alert("O campo categoria deve ser informado");
			cod_cate.focus();
			return false;	
		}
		if(des_qust.value == ""){
			window.alert("O campo pergunta deve ser informado");
			des_qust.focus();
			return false;	
		}
		if(des_answ.value == ""){
			window.alert("O campo resposta deve ser informado");
			des_answ.focus();
			return false;	
		}
	}

function validFrmQuestionario()
{
	nom_qust = document.getElementById("NOM_QUST")

	if(nom_qust.value == ""){
			window.alert("O campo questionario 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 == ""){
			window.alert("O campo questionario deve ser informado");
			document.getElementById("COD_QUST").focus();
			return false;	
		}
		if(cod_tipo_perg.value == ""){
			window.alert("O campo tipo de questao deve ser informado");
			document.getElementById("COD_TIPO_PERG").focus();
			return false;	
		}
		if(des_perg.value == ""){
			window.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 == ""){
			window.alert("O campo nome deve ser informado");
			nom_pess.focus();
			return false;	
		}
		if(dat_nasc.value == ""){
			window.alert("O campo data de nascimento deve ser informado");
			dat_nasc.focus();
			return false;	
		}
		if(des_sexo.value == ""){
			window.alert("O campo sexo deve ser informado");
			des_sexo.focus();
			return false;	
		}
		if(cod_esta_civi.value == ""){
			window.alert("O campo estado civil deve ser informado");
			cod_esta_civi.focus();
			return false;	
		}
		if(des_mail.value == ""){
			window.alert("O campo e-mail deve ser informado");
			des_mail.focus();
			return false;	
		}
		if(cod_perf.value == ""){
			window.alert("O campo perfil deve ser informado");
			cod_perf.focus();
			return false;	
		}
		if(des_logn.value == ""){
			window.alert("O campo usuario deve ser informado");
			des_logn.focus();
			return false;	
		}
		if(des_pass.value == ""){
			window.alert("O campo senha deve ser informado");
			des_pass.focus();
			return false;	
		}
		if(des_pass.value != con_pass.value){
			window.alert("A senha nao confere");
			des_pass.focus();
			return false;	
		}
		if(cod_tipo_tele.value != "" || des_numb_tele.value != ""){
			if(cod_tipo_tele.value == ""){
				window.alert("O campo tipo de telefone deve ser informado");
				cod_tipo_tele.focus();
				return false;	
			}
			if(des_numb_tele.value == ""){
				window.alert("O campo telefone deve ser informado");
				des_numb_tele.focus();
				return false;	
			}
		}
		if(document.getElementById("FLG_EXIST").value == "1"){
			window.alert("A verificacao de usuario e necessaria")
			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'
			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'
			document.getElementById("liMsgPessoa").style.display = 'none'
		}else{
			document.getElementById("liPfisica").style.display = 'none'
			document.getElementById("liPjuridica").style.display = 'none'
			document.getElementById("liMsgPessoa").style.display = 'block'
		}
	}
	
	function validFrmCliente(){
		
		cod_tipo_pess = document.getElementById("COD_TIPO_PESS").options[document.getElementById("COD_TIPO_PESS").selectedIndex]
		
		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")
		
		des_logn = document.getElementById("DES_LOGN")
		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 == ""){
			window.alert("O campo tipo de pessoa deve ser informado");
			document.getElementById("COD_TIPO_PESS").focus();
			return false;	
		}
		if(parseInt(cod_tipo_pess.value) == 1){
			if(nom_pess.value == ""){
				window.alert("O campo Nome deve ser informado");
				nom_pess.focus();
				return false;	
			}
			if(dat_nasc_diaa.value == "" || dat_nasc_mess.value == "" || dat_nasc_anoo.value == "" ){
				window.alert("O campo Data de nascimento deve ser informado");
				document.getElementById("DAT_NASC_DIAA").focus();
				return false;	
			}
			if(des_sexo.value == ""){
				window.alert("O campo Sexo deve ser informado");
				document.getElementById("DES_SEXO").focus();
				return false;	
			}
			if(cod_esta_civi.value == ""){
				window.alert("O campo Estado civil deve ser informado");
				document.getElementById("COD_ESTA_CIVI").focus();
				return false;	
			}
			/*if(des_numb_doc1.value == ""){
				window.alert("O campo R.G. deve ser informado");
				des_numb_doc1.focus();
				return false;	
			}
			if(des_numb_doc2.value == ""){
				window.alert("O campo C.P.F. deve ser informado");
				des_numb_doc2.focus();
				return false;	
			}*/
		}

		if(parseInt(cod_tipo_pess.value) == 2){

			if(nom_pess_juri.value == ""){
				window.alert("O campo Razão social deve ser informado");
				nom_pess_juri.focus();
				return false;	
			}
			/*if(nom_fant.value == ""){
				window.alert("O campo Nome fantasia deve ser informado");
				nom_fant.focus();
				return false;	
			}
			if(des_numb_doc1_juri.value == ""){
				window.alert("O campo I.E. deve ser informado");
				des_numb_doc1_juri.focus();
				return false;	
			}
			if(des_numb_doc2_juri.value == ""){
				window.alert("O campo C.N.P.J. deve ser informado");
				des_numb_doc2_juri.focus();
				return false;	
			}*/
			if(nom_pess_cont.value == ""){
				window.alert("O campo Nome do contato deve ser informado");
				nom_pess_cont.focus();
				return false;	
			}
			if(des_dept_cont.value == ""){
				window.alert("O campo departamento deve ser informado");
				des_dept_cont.focus();
				return false;	
			}		

		}

		if(cod_tipo_ende.value == ""){
			window.alert("O campo Tipo de endereço deve ser informado");
			document.getElementById("COD_TIPO_ENDE").focus();
			return false;	
		}
		if(cod_tipo_logr.value == ""){
			window.alert("O campo Tipo de logradouro deve ser informado");
			document.getElementById("COD_TIPO_LOGR").focus();
			return false;	
		}
		if(nom_logr.value == ""){
			window.alert("O campo Logradouro deve ser informado");
			nom_logr.focus();
			return false;	
		}
		if(cod_esta.value == ""){
			window.alert("O campo Estado deve ser informado");
			document.getElementById("COD_ESTA").focus();
			return false;	
		}
		if(cod_cida.value == ""){
			window.alert("O campo Cidade deve ser informado");
			document.getElementById("COD_CIDA").focus();
			return false;	
		}
		if(des_numb_cepp.value == ""){
			window.alert("O campo C.E.P. deve ser informado");
			des_numb_cepp.focus();
			return false;	
		}
		if(des_logn.value == ""){
			window.alert("O campo E-Mail deve ser informado");
			des_logn.focus();
			return false;	
		}
		if (!checkMail(des_logn.value)){
			window.alert("O E-Mail não e válido");
			des_logn.focus();
			return false;	
		}
		if(flg_exist.value == "1"){
			window.alert("Verifique o nome de usuario");
			document.getElementById("BTO_VERI_LOGN").focus();
			return false;	
		}
		if(des_pass.value == ""){
			window.alert("O campo Senha deve ser informado");
			des_pass.focus();
			return false;	
		}
		if(con_pass.value != des_pass.value){
			window.alert("A senha não confere");
			con_pass.focus();
			return false;	
		}

		if(cod_tipo_tele.value != "" || des_numb_tele.value != "" ){
			if(cod_tipo_tele.value == ""){
				window.alert("O campo Tipo de telefone deve ser informado");
				document.getElementById("COD_TIPO_TELE").focus();
				return false;	
			}
			if(des_numb_tele.value == ""){
				window.alert("O campo Telefone deve ser informado");
				des_numb_tele.focus();
				return false;	
			}
		}

		if(cod_tipo_tele2.value != "" || des_numb_tele2.value != "" ){
			if(cod_tipo_tele2.value == ""){
				window.alert("O campo Tipo de telefone (secundario) deve ser informado");
				document.getElementById("COD_TIPO_TELE2").focus();
				return false;	
			}
			if(des_numb_tele2.value == ""){
				window.alert("O campo Telefone (secundario) deve ser informado");
				des_numb_tele2.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 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)
    {
    	window.location = "default.asp?Page=12";
    }
  else
    {
		return false;
    }
}