

//################################################################################################
function Fc_FrmLogin(){
	var login = document.getElementById('Site_login').value;
	var senha = document.getElementById('Site_pass').value;
    
	login = login.replace( " ", "" );
	
	if (login.length < 6) {
		alert('Informe seu Login de acesso! \nObs: Lembre-se: Seu login é o e-mail do cadastro.');
        return false;
    } else if(!/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(login)) { 
			alert('\n- Seu login de acesso é o mesmo e-mail do seu cadastro. \nObs: Favor informar um e-mail válido');
			 return false;
	} else if (senha.length < 2) {
        alert('Por favor, informe sua senha de acesso.');
        return false;
    } else {
		//return true;
		document.getElementById('frm_login').submit();
    }
} 
function Fc_esvazia(valor_campo){
	if (valor_campo.value == valor_campo.defaultValue)
		valor_campo.value='';
}
function Fc_padrao(valor_campo){
	if (valor_campo.value == '')
		valor_campo.value=valor_campo.defaultValue;
}
function esvazia(valor_campo){
	if (valor_campo.value == valor_campo.defaultValue)
		valor_campo.value='';
}
function padrao(valor_campo){
	if (valor_campo.value == '')
		valor_campo.value=valor_campo.defaultValue;
}

//################################################################################################
function Fc_InputGanha(Item){
	var Objeto = document.getElementById(Item);
	Objeto.className='FrmInputBlue';

} 
function Fc_InputPerde(Item){
	var Objeto = document.getElementById(Item);
	Objeto.className='FrmInputNada';	
} 
// >> Limpa algum status disposto no navegador
DescStatus('');
function DescStatus(txt) {
   window.status = txt;
}
// >> MAIÚSCULO { onKeyPress="Fc_maiusculo(this);"}
function Fc_maiusculo(campo) {
	campo.value=campo.value.toUpperCase();
}
 
//  >> MINÚSCULO { onBlur="minusculo(this);" } 
function Fc_minusculo(campo) {
	campo.value=campo.value.toLowerCase();
}

//################################################################################################
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_reloadPage(init) {  //Updated by PVII. 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);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//#################################################################################################
// >> VERIFICA  funçao para checar CPF e CGC
// {  onBlur="chk_cpf_cgc(this.value,document.frm_cad.tp[0].checked,this)" } 
function chk_cpf_cgc(num,valor_J,valor_F,obj){
	var valor;
	if(valor_J == true)valor = "J";
	if(valor_F == true)valor = "F";
	
	if(valor == "F" || valor == "J"){

        //**************CPF*****************//
        if (valor == "F") {
                num = num.toString().replace( "-", "" );
                num = num.toString().replace( ".", "" );
                num = num.toString().replace( ".", "" );
                num = num.toString().replace( "/", "" );

                x = 0;
                soma = 0;
                dig1 = 0;
                dig2 = 0;
                texto = "";
                numcpf="";

                if (num.length != 11) {
                        alert ("CPF Invalido!");
                        return true;
                }

                len = num.length;
                x = len -1;
                for (var i=0; i <= len - 3; i++) {
                        y = num.substring(i,i+1);
                        soma = soma + ( y * x);
                        x = x - 1;
                        texto = texto + y;
                }
                dig1 = 11 - (soma % 11);
                if (dig1 == 10) {
                        dig1=0 ;
                }
                if (dig1 == 11) {
                        dig1=0 ;
                }
                numcpf = num.substring(0,len - 2) + dig1 ;
                x = 11;
                soma=0;
                for (var i=0; i <= len - 2; i++) {
                        soma = soma + (numcpf.substring(i,i+1) * x);
                        x = x - 1;
                }
                dig2= 11 - (soma % 11);
                if (dig2 == 10) {
                        dig2=0;
                }
                if (dig2 == 11) {
                        dig2=0;
                }
                if ((dig1 + "" + dig2) == num.substring(len,len-2)) {
                        return true;
                }
                alert ("CPF Invalido!");
                obj.focus();
                return true;
        }

        //**************CGC*****************//
        if (valor == "J") {

                num = num.replace(".", "");
                    num = num.replace(".", "");
                    num = num.replace("/", "");
                    num = num.replace("-", "");

                var i, j, k, Soma;

                if (num.length != 14) {
                        alert ("Número de CNPJ é Invalido!");
                        return true;
                }

                k = 0;
                while (k <= 1){
                        Soma = 0;
                        j = 5 + k;
                        for (i=0; i <= 11+k; i++){
                                Soma += parseInt(num.charAt(i),10)*j;
                                if ( j != 2) {
                                        j--;
                                } else {
                                        j = 9;
                                }
                        }
                        Soma = 11 - Soma%11;
                        if (Soma >= 10) {
                                Soma = 0;
                        }
                        if ( Soma != parseInt(num.charAt(12+k))) {
                                alert("CNPJ Invalido!");
                                return true;
                        }
                        k++;
                }
                return true;
        }
	}else{
		alert("Escolha a pessoa!");
	}
		
}


// >> FORMATA DATA  {onkeypress="FormataData(this,event)" }
function FormataData(Campo,teclapres){
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
		}
	}

// >> MASCARA PARA CEP { onkeypress="mascaraCep(this)" } 
function mascaraCep(objeto){
        if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; }
        if (objeto.value.length == 5){
                objeto.value += "-";
        }
}

// >> VALIDA CEP
function valida_cep(cep) {
    //var teste;teste = cep.indexOf("-");	alert(teste);
	//var tamanho;tamanho = cep.length;alert(tamanho);
	//Se (nao tiver o "-" retorna -1) e se o tamanho for < 8)
	if(cep.indexOf("-")==-1 || cep.length < 9)
	  return false;
	
	var pat = /((\d{5})(-)(\d{3}))|(\d{8})/;
	//Verifica se o "-" foi colocado no local correto
	var cepdiv = cep.match(pat);//alert(cepdiv); 
	if(cepdiv==null)
	 	return false;
	
	return true;
}

// >> FORMATAR CPF E CNPJ
// { onkeypress="FormataCPF_CGC(this,event,document.frm_cad.frm_tp[0].checked);"
function FormataCPF_CGC(Campo,teclapres,valor_J,valor_F){
	var valor;
	if(valor_J == true)valor = "J";
	if(valor_F == true)valor = "F";
  
	var tecla = teclapres.keyCode;
	if(valor == "F"){
		var vr = new String(Campo.value);
        	vr = vr.replace(".", "");
	        vr = vr.replace(".", "");
    	    vr = vr.replace("-", "");

        	tam = vr.length + 1;

        	if (tecla != 9 && tecla != 8){
                if (tam > 3 && tam < 7)
                        Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
                if (tam >= 7 && tam <10)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
                if (tam >= 10 && tam < 12)
                        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
			}
	}
	if (valor == "J"){
    	var vr = new String(Campo.value);
        vr = vr.replace(".", "");
        vr = vr.replace(".", "");
        vr = vr.replace("/", "");
        vr = vr.replace("-", "");

        tam = vr.length + 1 ;

		if (tecla != 9 && tecla != 8){
			if (tam > 2 && tam < 6)
				Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
			if (tam >= 6 && tam < 9)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
	}
}	
