document.write('<link rel="stylesheet" href="../../css/ag2.css" type="text/css">')

function pop(url,w,h,s) {
	var oW=window.open(url,'popup','width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+s+',status=0,toolbar=0,marginleft=0,margintop=0,left='+(((screen.availWidth-w)/2)+-10)+',top='+(((screen.height-h)/2)+-10));
}

function impressao(){
popimpressao = window.open('', '_blank', 'width=650,height=450,left=0,top=0,scrollbars=yes,resizable=no,menubar=no,toolbar=no');

with (popimpressao.document) {
	var d, s ;
	d = new Date();
	s =  d.getDate()+ ".";
	s += (d.getMonth() + 1) + ".";
	s += d.getYear();

	write('<html><head><title>.: Zanthus :.</title></head>');
	write('<link rel="stylesheet" href="../../css/ag2.css" type="text/css">');
	write('<link rel="stylesheet" href="../../css/print.css" type="text/css">');	
	write('<body class="cinza" style="background:none;padding:10px">');
	write('<img alt="" border="0" src="../../img/logo_branco.jpg"><br><br>');
	write(document.getElementById("impressao").innerHTML);
	write('<br><img style="margin-top:25px;" alt="" border="0" src="../../img/pix_646464.gif" width="100%" height="1"><br>');
	write('<table cellpadding="0" cellspacing="0" border="0" class="rodape" width="100%" style="margin-top:5px;"><tr><td>Impresso em ' + s + '</td><td rowspan="2" align="right"><a href="javascript:window.close();"><img alt="" border="0" src="../../img/btn_fechar.gif"></a></td></tr><tr><td> ' + window.location.href + ' </td></tr></table>');
	write('</body></html>');
	close();
	}
       popimpressao.print();
}

//##funcoes de paginacao

function Pagina(intPage){
	frm.action = strPagina + "?pagina_atual=" + intPage;
	frm.submit();
}


function setPage(intPage) {
	var url;
	url = window.location.href;
	//alert(url);

	if (url.indexOf("?pg=")>=0)  {
		url = url.replace(/\?{0,1}pg=\d{1,5}&{0,1}/,"");
	} else {
		url = url.replace(/&{0,1}pg=\d{1,5}&{0,1}/,"");
	}

	//procura inicio da querystring
	if (url.indexOf("?")>=0)  {
		url += "&pg="+intPage;
	} else {
		url += "?pg="+intPage;
	}
	
	//frm.action = url;
	//frm.submit();
	window.location.href = url;
}

function search() {
	var txt = trim(document.busca.palavraChave.value);
	
	//if ((txt!="") || (txt!=" buscar produto")) {
	if (txt!="") {
		document.busca.action = "../busca/resposta.asp";
		document.busca.submit();
	}	
}

	function soMoney(tammax){
		event.srcElement.maxLength=tammax;
		if (event.srcElement.value.length+1>tammax) { 
			event.KeyCode=0;
		}
		if ( (event.keyCode >= 48) && (event.keyCode <= 57 ) || (event.keyCode == 44)) {
			if (event.keyCode == 44){
				if (event.srcElement.value.indexOf(",") > -1) {			
					event.keyCode = 0
					return false
				}
			}
			return true
		} else {
			if (event.keyCode != 8){
				 event.keyCode = 0
				 return false
			 }
		}
	}

// Função para aceitar apenas números em campos texto
function soNumeros(e){
     var key;
     var keychar;

     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }	

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) ) {
        return true;
     } else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}



function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

function validaCPF(cpf) {
	cpf = cpf.value;
	valor = true;
	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		  erro += "Numero de CPF invalido!\n"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!\n";
	}
	if (erro.length > 0){		
		return false;
	}
	return true;
}

 function validaCNPJ(CNPJ) {
		 erro = new String;
		 erro = '';
		 if (CNPJ =='00.000.000/0000-00'){
			 erro += "É necessario preencher corretamente o número do CNPJ!\n ";
			 return erro;
		 }
		 if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ!\n "; 
		 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ!\n ";
		 }
		 //substituir os caracteres que não são números
	   if(document.layers && parseInt(navigator.appVersion) == 4){
			   x = CNPJ.substring(0,2);
			   x += CNPJ. substring (3,6);
			   x += CNPJ. substring (7,10);
			   x += CNPJ. substring (11,15);
			   x += CNPJ. substring (16,18);
			   CNPJ = x; 
	   } else {
			   CNPJ = CNPJ. replace (".","");
			   CNPJ = CNPJ. replace (".","");
			   CNPJ = CNPJ. replace ("-","");
			   CNPJ = CNPJ. replace ("/","");
	   }
	   var nonNumbers = /\D/;
	   if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números!\n "; 
	   var a = [];
	   var b = new Number;
	   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	   for (i=0; i<12; i++){
			   a[i] = CNPJ.charAt(i);
			   b += a[i] * c[i+1];
}
	   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	   b = 0;
	   for (y=0; y<13; y++) {
			   b += (a[y] * c[y]); 
	   }
	   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	   if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			   erro +="Dígito verificador com problema!\n";
	   }
	   if (erro.length > 0){
			   return erro;
	   } 
	   return '';
}

// Função para aceitar apenas ('.','/','-')
function soCNPJ(e){
     var key;
     var keychar;


     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) || (key==45) || (key==46) || (key==47) ) {
        return true;
     } else if ((("0123456789-./").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}

// Função para aceitar apenas ('-')
function soCEP(e){
     var key;
     var keychar;

     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) || (key==45) ) {
        return true;
     } else if ((("0123456789-").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}

//##//funcoes de paginacao



/***************************************************
*** Função que valida formulario de login do site
****************************************************/

function verificaLoginToto(){

	strErro = "";

	if(document.login_topo.login.value==""){			
		strErro = strErro + "Preencha o Usuário do Site . \n";
	}

	if(document.login_topo.senha.value==""){			
		strErro = strErro + "Preencha o Senha do Site . \n";
	}

	if (strErro != ""){			
		alert(strErro);
		return false;
	}else{
		document.login_topo.action="../../src/verifica_login.asp";
		document.login_topo.submit();
	}

}



   // máscara de campos
    // uso: onkeydown="FormataCampo(this,event,'##/##/####')"
    function FormataCampo(Campo,teclapres,mascara, sai) {

        if (sai == "S" && consistente == "N") {
            if (obrigatorio == "N" && Campo.value.length > 0) {
                obrig_fixo = "S";
                Consist(Campo.maxLength, Campo);
                obrig_fixo = "N";
            }
            if (obrigatorio == "S" || Campo.value.length > 0) {
                if (sai == "S") {
                    if (Campo.value.length != mascara.length) {
                        alert('O campo precisa estar neste formato:\n\n       '+ mascara);
                        Campo.value = "";
                    }
                    erro = "S";
                    return false;
                }
            }
        }
        if (sai == "S" && obrigatorio == "N" && Campo.value.length > 0) {
            obrig_fixo = "S";
            Consist(Campo.maxLength, Campo);
            obrig_fixo = "N";
            if (consistente == "N") {
                alert('O campo precisa estar neste formato:\n\n       '+ 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)
        } 

		//alert(teclapres.keyCode );
        if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))) {
            if ((teclapres.keyCode >= 35 && 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)||(teclapres.keyCode == 16)){
                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 check_date(field){
        var checkstr = "0123456789";
        var DateField = field;
        var Datevalue = "";
        var DateTemp = "";
        var seperator = "/";
        var day;
        var month;
        var year;
        var leap = 0;
        var err = 0;
        var i;
		var strDataMsg = "";

        err = 0;
        DateValue = DateField.value;
       /* Delete all chars except 0..9 */
       for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
       }
       DateValue = DateTemp;
       /* Always change date to 8 digits - string*/
       /* if year is entered as 2-digit / always assume 20xx */
       if (DateValue.length == 6) {
          DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
       if (DateValue.length != 8) {
          err = 19;
		  strDataMsg = "A data informada é inválida.";		  
		}

       /* year is wrong if year = 0000 */
       year = DateValue.substr(4,4);
       if (year == 0) {
          err = 20;
		  strDataMsg = "O ano informado é inválido.";
       }
       /* Validation of month*/
       month = DateValue.substr(2,2);
       if ((month < 1) || (month > 12)) {
          err = 21;
		  strDataMsg = "O mês informado é inválido.";
       }

       /* Validation of day*/
       day = DateValue.substr(0,2);
       if (day < 1) {
         err = 22;
		 strDataMsg = "O dia informado é inválido.";
       }

       /* Validation leap-year / february / day */
       if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
          leap = 1;
       }
       if ((month == 2) && (leap == 1) && (day > 29)) {
          err = 23;
		  strDataMsg = "O mês informado possui no máximo 29 dias.";
       }
       if ((month == 2) && (leap != 1) && (day > 28)) {
          err = 24;
		  strDataMsg = "O mês informado possui no máximo 28 dias.";
       }
       /* Validation of other months */
       if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
          err = 25;
		  strDataMsg = "O mês informado possui no máximo 31 dias.";
       }
       if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
          err = 26;
		  strDataMsg = "O mês informado possui no máximo 30 dias.";
       }
       /* if 00 ist entered, no error, deleting the entry */
       if ((day == 0) && (month == 0) && (year == 00)) {
          err = 0; day = ""; month = ""; year = ""; seperator = "";
       }
       /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
       if (err == 0) {
          //DateField.value = day + seperator + month + seperator + year;
          return true;
       }
       else {
          alert(strDataMsg);
          DateField.select();
          DateField.focus();
          return false;
       }
    }

	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 limitatext(campo,maxtamanho){
		if (campo.value.length>=maxtamanho && event.keyCode !=8 && event.keyCode !=46) { 
			event.keyCode = 0;
		}

		if (campo.value.length >= maxtamanho) {
			campo.value = campo.value.substring(0,maxtamanho);
		}

	}

	// Função para aceitar apenas números em campos texto
	function soMoneyII(e){
		 var key;
		 var keychar;

		 if (window.event) {
			key = window.event.keyCode;
		 } else if (e) {
			key = e.which;
		 } else {
			return true;
		 }

		 keychar = String.fromCharCode(key);

		 // teclas de controle
		 if ((key==null) || (key==0) || (key==8) ||
			  (key==9) || (key==13) || (key==27) || (key==44) ) {
			return true;
		 } else if ((("0123456789,").indexOf(keychar) > -1)) {
			return true;     
		 } else {
			return false;
		 }
	}

	function MM_reloadPage(init) {  //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_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//
function visForm(pe){
	booForm = (pe == 0)?"hidden":"visible";
	objForm = document.forms;
	for(i=0; i<objForm.length; ++i){
		objFormInt = objForm[i].elements;
		for(j=0; j<objFormInt.length; ++j){
			if(objFormInt[j].tagName == "SELECT" && objFormInt[j].className=="no"){
				objFormInt[j].style.visibility = booForm;
			}
		}
	}
}
function ocultar(){
	visForm(1);
}
function exibir(){
	visForm(0);
}