var isValid = true;
var rfvArray = new Array();

function valJoin(){
	
	isValid = true;
	clearRFV();
	ddlFormValidador('ddlType', 'rfvType');
	txtFormValidador('txtCPF', 'rfvCPF');
	ValidarCPF('txtCPF','rfvCPFValido');
	return isValid;
}

function valPainter01(){
	
	isValid = true;
	clearRFV();
	txtFormValidador('txtNome', 'rfvNome');
	//txtFormValidador('txtCPF', 'rfvCPF');
	txtFormValidador('txtBirthData', 'rfvBirthData');
	txtFormValidador('txtNome', 'rfvNome');
	rdoFormValidador('FormPainter01','rdoGender','rfvGender');
	ddlFormValidador('ddlCivil', 'rfvCivil');
	chkFormValidador('FormPainter01', 'chkProfissao', 'rfvProfissao');
	//rdoFormValidador('FormPainter01', 'rdoEmpresa', 'rfvEmpresa');
	txtFormValidador('txtCEP', 'rfvCEP');
	ddlFormValidador('ddlStates', 'rfvStates');
	ddlFormValidador('ddlCidade', 'rfvCidade');
	ddlFormValidador('ddlTipoLogradouro', 'rfvTipoLogradouro');
	txtFormValidador('txtLogradouro', 'rfvLogradouro');
	txtFormValidador('txtNumero', 'rfvNumero');
	txtFormValidador('txtBairro', 'rfvBairro');
	txtFormValidador('txtTelefone', 'rfvTelefone');
	txtFormValidador('txtEmail', 'rfvEmail');	
	//ValidarCPF('txtCPF','rfvCPFValido');
	ValidaData('txtBirthData','rfvBirthDataValido');
	ValidaCep('txtCEP', 'rfvCEPvalido');
	ValidaTelefone('txtTelefone', 'rfvTelefoneValido');
	ValidaTelefone('txtCelular', 'rfvCelulareValido');
	ValidaEmail('txtEmail','rfvEmailValido');
	return isValid;
}

function valPainter02(){
  isValid =true;
  clearRFV();
  //alert(document.FormSelect.ddlType.value);
  if (document.FormSelect.ddlType.value ==''){
  document.FormSelect.ddlType.focus();
  isValid=false;
  }
  //ddlFormValidador('ddlType','rfvType');
  return isValid;
}

function valNewStore(){
	isValid = true;
	clearRFV();
	txtFormValidador('txtNomeFantasia', 'rfvNomeFantasia');
	txtFormValidador('txtCNPJ', 'rfvCNPJ');
	txtFormValidador('txtCEP', 'rfvCEP');
	ddlFormValidador('ddlStates', 'rfvStates');
	ddlFormValidador('ddlCidade', 'rfvCidade');
	ddlFormValidador('ddlTipoLogradouro', 'rfvTipoLogradouro');
	txtFormValidador('txtLogradouro', 'rfvLogradouro');
	txtFormValidador('txtNumero', 'rfvNumero');
	txtFormValidador('txtBairro', 'rfvBairro');
	ValidaTelefone('txtTelefone', 'rfvCelulareValido');
	ValidarCNPJ('txtCNPJ','rfvCNPJValido');
	ValidaCep('txtCEP', 'rfvCEPvalido');
	return isValid;
}

function valEditPersonalInfo(){
	isValid = true;
	clearRFV();
	txtFormValidador('txtNome', 'rfvNome');
	txtFormValidador('txtCPF', 'rfvCPF');
	txtFormValidador('txtBirthData', 'rfvBirthData');
	rdoFormValidador('FormEditPersonalInfo','rdoGender','rfvGender');
	ddlFormValidador('ddlCivil', 'rfvCivil');
	ValidarCPF('txtCPF','rfvCPFValido');
	return isValid;
}

function valEditContactInfo(){
	
	isValid = true;
	clearRFV();
	txtFormValidador('txtCEP', 'rfvCEP');
	ddlFormValidador('ddlStates', 'rfvStates');
	ddlFormValidador('ddlCidade', 'rfvCidade');
	ddlFormValidador('ddlTipoLogradouro', 'rfvTipoLogradouro');
	txtFormValidador('txtLogradouro', 'rfvLogradouro');
	txtFormValidador('txtNumero', 'rfvNumero');
	txtFormValidador('txtBairro', 'rfvBairro');
	txtFormValidador('txtTelefone', 'rfvTelefone');
	txtFormValidador('txtEmail', 'rfvEmail');	
	ValidaCep('txtCEP', 'rfvCEPvalido');
	ValidaTelefone('txtTelefone', 'rfvTelefoneValido');
	ValidaTelefone('txtCelular', 'rfvCelulareValido');
	ValidaEmail('txtEmail','rfvEmailValido');
	return isValid;
}

function valEditProfessionalInfo(Tipo){
	
	isValid = true;
	clearRFV();
	chkFormValidador('FormEditProfessionalInfo', 'chkProfissao', 'rfvProfissao');
	//rdoFormValidador('FormEditProfessionalInfo', 'rdoEmpresa', 'rfvEmpresa');
	return isValid;
}

function valEditRelative(){
	
	isValid = true;
	clearRFV();
	ddlFormValidador('ddlTypeRelative', 'rfvTypeRelative');
	txtFormValidador('txtRelativeName', 'rfvRelativeName');
	txtFormValidador('txtRelativeBirthData', 'rfvRelativeBirthData');
	//rdoFormValidador('FormEditPersonalInfo','rdoGender','rfvGender');
	ValidaData('txtRelativeBirthData','rfvRelativeBirthDataValido');
	
	return isValid;
}

function valFormContact(){
	isValid = true;
	clearRFV();
	
	ddlFormValidador('ddlAssunto', 'rfvAssunto');
	
	txtFormValidador('txtNome', 'rfvNome');
	txtFormValidador('txtEmail', 'rfvEmail');
	txtFormValidador('txtTelefone', 'rfvTelefone');
	txtFormValidador('txtMensagem', 'rfvMensagem');	
	ValidaTelefone('txtTelefone', 'rfvTelefoneValido');
	ValidaEmail('txtEmail','rfvEmailValido');
	
	return isValid;
}

function valForgotPassword(){
	isValid = true;
	clearRFV();
	txtFormValidador('txtNome', 'rfvNome');
	txtFormValidador('txtCPF', 'rfvCPF');
	ValidarCPF('txtCPF','rfvCPFValido');
	return isValid;
}


function txtFormValidador( txtID, rfvID ){
	if( $F(txtID) == '' ) {
		if(rfvID){
			$(rfvID).style.display = 'block';
			rfvArray[rfvArray.length] = rfvID;
		}
		if(isValid){$(txtID).focus();}
		isValid = false;
	}
}

function rdoFormValidador( formID, rdoName, rfvID ) { 
	var myform = $(formID);
	var rdoForm = myform.getInputs('radio', rdoName);	
	var ctRdo = 0;
	
	for (var i = 0; i < rdoForm.length; ++i) {
		if(rdoForm[i].checked)
			ctRdo++;
	} 
	if (ctRdo==0) {
		if(rfvID){
			$(rfvID).style.display = 'block';
			rfvArray[rfvArray.length] = rfvID;
		}
		if(isValid){$(rdoForm[0]).focus();}
		isValid = false;
	}
}

function ddlFormValidador( ddlID, rfvID ) { 
	if( $F(ddlID) == '' ) {
		if(rfvID){
			$(rfvID).style.display = 'block';
			rfvArray[rfvArray.length] = rfvID;
		}
		if(isValid){$(ddlID).focus();}
		isValid = false;
	}
}

function chkFormValidador( formID, chkName, rfvID, minSelected ) { 
	var myform = $(formID);
	var chkForm = myform.getInputs('checkbox', chkName);	
	var ctChk = 0;
	if(!minSelected){minSelected=1;}
	//alert(chkForm.length);
	for (var i = 0; i < chkForm.length; ++i) {
		if(chkForm[i].checked)
			ctChk++;
	} 
	if (ctChk<minSelected) {
		if(rfvID){
			$(rfvID).style.display = 'block';
			rfvArray[rfvArray.length] = rfvID;
		}
		if(isValid){$(chkForm[0]).focus();}
		isValid = false;
	}
}

function clearRFV(){
	for (var i = 0; i < rfvArray.length; ++i) {
		$(rfvArray[i]).style.display = 'none';
	} 
}

		 function findCEP(){
	       
		   if (document.FormPainter01.txtCEP.value.replace('-','').length == 8){
			
			vPagina = ObtemPagina("GET","../cep/findCEP.asp?cep="+document.FormPainter01.txtCEP.value, false);
			
			if (vPagina != "0")
			{
			var strFullCep = vPagina;
		    var arCep = strFullCep.split(';');
			//alert(arCep);
			//alert(arCep[3]);
			document.FormPainter01.ddlTipoLogradouro.value = arCep[0];
			document.FormPainter01.txtLogradouro.value = arCep[1];
			document.FormPainter01.txtBairro.value = arCep[2];
			//document.FormPainter01.ddlCidade.value = arCep[3];
			document.FormPainter01.ddlStates.value = arCep[4];								
			getCities(arCep[4],'ddlCidade',arCep[3]);
			document.FormPainter01.txtCEP.value = arCep[5].substring(0,5)+"-"+arCep[5].substring(5,8);
            
            }
			else {
                
				alert('CEP Não encontrado, por favor digite o Endereço Completo.');

			document.FormPainter01.ddlTipoLogradouro.value = "";
			document.FormPainter01.txtLogradouro.value = "";
			document.FormPainter01.txtBairro.value = "";
			document.FormPainter01.ddlCidade.value = "";
			document.FormPainter01.ddlStates.value = "";	
			document.FormPainter01.txtCEP.value = "";
				
				}
				
               }
		else {
		alert('O CEP deve ter 8 Dígitos');
		document.FormPainter01.txtCEP.focus();
		}
		}
		
		 function EditfindCEP(){
	       
		   if (document.FormEditContactInfo.txtCEP.value.replace('-','').length == 8){
			
			vPagina = ObtemPagina("GET","../cep/findCEP.asp?cep="+document.FormEditContactInfo.txtCEP.value, false);
			
			if (vPagina != "0")
			{
			var strFullCep = vPagina;
		    var arCep = strFullCep.split(';');
			//alert(arCep[3]);
			document.FormEditContactInfo.ddlTipoLogradouro.value = arCep[0];
			document.FormEditContactInfo.txtLogradouro.value = arCep[1];
			document.FormEditContactInfo.txtBairro.value = arCep[2];
			document.FormEditContactInfo.ddlStates.value = arCep[4];	
			getCities(arCep[4],'ddlCidade',arCep[3]);
			//document.FormEditContactInfo.ddlCidade.value = arCep[3];
										
			document.FormEditContactInfo.txtCEP.value = arCep[5].substring(0,5)+"-"+arCep[5].substring(5,8);
            
            }
			else {
                
				alert('CEP Não encontrado, por favor digite o Endereço Completo.');

			document.FormEditContactInfo.ddlTipoLogradouro.value = "";
			document.FormEditContactInfo.txtLogradouro.value = "";
			document.FormEditContactInfo.txtBairro.value = "";
			document.FormEditContactInfo.ddlCidade.value = "";
			document.FormEditContactInfo.ddlStates.value = "";	
			document.FormEditContactInfo.txtCEP.value = "";
				
				}
				
               }
		else {
		alert('O CEP deve ter 8 Dígitos');
		document.FormEditContactInfo.txtCEP.focus();
		}
		}
		
		 function NewStorefindCEP(){
	       
		   if (document.FormNewStore.txtCEP.value.replace('-','').length == 8){
			
			vPagina = ObtemPagina("GET","../cep/findCEP.asp?cep="+document.FormNewStore.txtCEP.value, false);
			
			if (vPagina != "0")
			{
			var strFullCep = vPagina;
		    var arCep = strFullCep.split(';');
			//alert(arCep[3]);
			document.FormNewStore.ddlTipoLogradouro.value = arCep[0];
			document.FormNewStore.txtLogradouro.value = arCep[1];
			document.FormNewStore.txtBairro.value = arCep[2];
			//document.FormNewStore.ddlCidade.value = arCep[3];
			document.FormNewStore.ddlStates.value = arCep[4];								
			getCities(arCep[4],'ddlCidade',arCep[3]);
			document.FormNewStore.txtCEP.value = arCep[5].substring(0,5)+"-"+arCep[5].substring(5,8);
            
            }
			else {
                
				alert('CEP Não encontrado, por favor digite o Endereço Completo.');

			document.FormNewStore.ddlTipoLogradouro.value = "";
			document.FormNewStore.txtLogradouro.value = "";
			document.FormNewStore.txtBairro.value = "";
			document.FormNewStore.ddlCidade.value = "";
			document.FormNewStore.ddlStates.value = "";	
			document.FormNewStore.txtCEP.value = "";
				
				}
				
               }
		else {
		alert('O CEP deve ter 8 Dígitos');
		document.FormNewStore.txtCEP.focus();
		}
		}