//################################################################################################
// Script de mouseover
function menuOn(menu, className){
	if (!menu.isMenuSelected){
		menu.oldClassName = menu.className;
		menu.className = className;
	}
}
// Script de mouseout
function menuOff(menu){
	if (!menu.isMenuSelected){
		menu.className = menu.oldClassName;
	}
}
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;
}
// >> CEP
function Fc_bucaCep(cep){
	document.getElementById('ifrCEP').src = "/adm/scr/scr_cep.php?cep="+cep;
}

function Fc_Cep() {
	window.open("/adm/scr/cep/busca_cep.htm","extra","status=no,menubar=no,location=no,toolbar=no,scrollbars=no,width=360,height=360,top=0,left=0");
}

function Fc_apresenta(botao,aDiv,Obj) {
	if(document.getElementById(aDiv).style.display=='none'){
		document.getElementById(aDiv).style.display='';
		Obj.attributes["src"].value = '/imgTmp/menos.png';
	}else{
		document.getElementById(aDiv).style.display='none';
		Obj.attributes["src"].value = '/imgTmp/mais.gif';
	}
}

//################################################################################################
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
Fc_descStatus('');
function Fc_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];}
}

// #################
// >> Somente numeros ou -  onKeyPress="return Fc_numeros(event);"   
function Fc_numeros(event){
  	 var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
	 // 8-> BackSpace 46 -> Delete 13->Enter
	 // 37-> seta esq. |  39-> seta dir  | 9 -> Tab | 35 -> end | 36 -> home
	 // 45 -> - | 46 -> . | 47 -> /
	 //alert(key);
	 if(key != 8 && key != 13 && key != 9 && key != 37 && key != 9 && key != 35 && key != 36){
		if( key < 45 || key > 57 ){
			return false;
		 }else{
			return true;
	 	}
	}else{
		return true;
	}
}	

function Fc_mascTempoReal(ConteudoCampo,event){
	var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 

    if(key != 8 && key != 13 && key != 46 && key != 9 && key != 37 && key != 9 && key != 35 && key != 36){
	  if (((key) > 47) && ((key) < 58)){
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;
		Contador = 0;
		if (TamDig > 1){
			numer = "";
			for (i = TamDig; (i >= 0); i--){
				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
					Contador++;
					if ((Contador == 2) && ((TamDig -i) < 4)){
						numer = ","+numer;
						Contador = 0;
					}else if (Contador == 3){
						numer = "."+numer;
						Contador = 0;
					}
					numer = NumDig.substr(i, 1)+numer;
				}
			}
			ConteudoCampo.value = numer;
		};
  		return(true)
	 }
	 else return(false)
   }
   else return(true)
}

function Fc_formataCampo(Campo,teclapres,mascara){ 
    //pegando o tamanho do texto da caixa de texto com delay de -1 no event 
    //ou seja o caractere que foi digitado não será contado. 
    strtext = Campo.value 
    tamtext = strtext.length 
    //pegando o tamanho da mascara 
    tammask = mascara.length 
    //criando um array para guardar cada caractere da máscara 
    arrmask = new Array(tammask)     
    //jogando os caracteres para o vetor 
    for (var i = 0 ; i < tammask; i++){ 
        arrmask[i] = mascara.slice(i,i+1) 
    } 
    //alert (teclapres.keyCode) 
    //começando o trabalho sujo 
    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)
			){ 
            int_organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)         
        }else{ 
            int_detona_Event(Campo,strtext) 
        } 
    }else{//Aqui funcionaria a mascara para números mas eu ainda não implementei 
        if ((arrmask[tamtext] == "A")){ 
			if ((teclapres.keyCode > 64 && teclapres.keyCode < 91) || 
	    	 	(teclapres.keyCode > 96 && teclapres.keyCode < 123)){
				int_organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
			}
		}
        charupper = event.valueOf() 
        //charupper = charupper.toUpperCase() 
        int_detona_Event(Campo,strtext) 
        masktext = strtext + charupper 
        Campo.value = masktext 
    } 
} 
function int_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 int_detona_Event(Campo,strtext){ 
    event.returnValue = false 
    if (strtext != "") { 
        Campo.value = strtext 
    } 
} 




// >> FORMATAR CPF E CNPJ
// onkeypress="Fc_formataDOC(this,event,'FORM');"   => Quando tiver OBJ. TIPO no FORM
// onkeypress="Fc_formataDOC(this,event,'F');" 		=> Quando não tiver TIPO. Ex. Em Func
function Fc_formataDOC(Campo,event,tipoExtra){
	
	// Evento
	if (event.keyCode) tecla = event.keyCode;       
	else if (event.which) tecla = event.which; // Netscape 4.?   
	else if (event.charCode) tecla = event.charCode; // Mozilla  
	
	// Pessoa
	var valor = '';
	if(tipoExtra == 'FORM'){
		if(document.getElementById('frm_tp_J').checked == true){
			valor = 'J'
		}else if(document.getElementById('frm_tp_F').checked == true){
			valor = 'F'
		}
		if(valor == ""){
			alert("Escolha o Tipo de pessoa! \n Física ou Jurídica;");
			return false;
		}
	}else{
		valor = tipoExtra; // Para formulários que tem MAIS de 1 entrada de CPF ou CNPJ
	}
	
	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);
		}
	}
}


// >> VERIFICA  funçao para checar CPF e CGC
// onblur="Fc_verificaDOC(this);"
function Fc_verificaDOC(obj,tipoExtra){

	var num = obj.value;
	var valor = '';
	
	if(tipoExtra == 'FORM'){
		if(document.getElementById('frm_tp_J').checked == true){
			valor = 'J'
		}else{
			valor = 'F'
		}
	}else{
		valor = tipoExtra; // Para formulários que tem MAIS de 1 entrada de CPF ou CNPJ
	}
		

	
	if(num == '') return false;
	
	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 o Tipo de pessoa! \n Física ou Jurídica;");
	}
}

function Fc_validaDoc(ObjDoc){
	alert(ObjDoc);
}





