// Função Popup: <a href="arquivo.ext" onclick="popup(this.href,'360','535','1'); return false;"></a>
function popup(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));
}

//Função para impressão
function impressao(){
	popimpressao = window.open('', '_blank', 'width=578,height=450,left=0,top=0,scrollbars=yes,resizable=no,menubar=no,toolbar=no');
	var d, s ;
	d = new Date();
	s =  d.getDate()+ ".";
	s += (d.getMonth() + 1) + ".";
	s += d.getFullYear();

	with (popimpressao.document) {
		write('<html><head><title>Thyssen</title></head>');
		write('<link rel="stylesheet" href="../../css/default.css" type="text/css">');
		write('<link href="../../css/print.css" rel="stylesheet" type="text/css">');
		write('<body>');		
		write('<img src="../../img/topo_imprimir_pedido.gif" alt="">');	
		write(document.getElementById("conteudo").innerHTML);		
		write('<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin:0 0 0 40px;border-top:solid 1px #000000;width:370px"><tr><td class="txtmenor"><em>Impresso em ' + s + '</em></td><td rowspan="2" align="right"><a href="javascript:window.close();"><img alt="" border="0" src="../../img/btn_fechar_pop1.gif" class="btn_impressao"></a></td></tr><tr><td class="txtmenor"> <em>http://www.b2c.thyssen.com.br</em> </td></tr></table>');
		write('<br></body></html>');
		close();
		}
        popimpressao.print();
}

function alpha() {
	if (document.getElementById("alpha").style.display == "block") {
		document.getElementById("alpha").style.display = "none";
	} else {
		document.getElementById("alpha").style.display = "block";
		document.getElementById("alpha").style.height = document.documentElement.scrollHeight + "px";
	}
}
function perfil(op) {
	if (op == 1) {
		document.getElementById("pj").style.display = "block";
		document.getElementById("btnpj").style.display = "block";
		document.getElementById("pf").style.display = "none";
		document.getElementById("btnpf").style.display = "none";
	} else {
		document.getElementById("pj").style.display = "none";
		document.getElementById("btnpj").style.display = "none";
		document.getElementById("pf").style.display = "block";
		document.getElementById("btnpf").style.display = "block";
	}
}

function incluir(id) {
	alpha();
	if (document.getElementById(id).style.display == "block") {
		document.getElementById(id).style.display = "none";
	} else {
		document.getElementById(id).style.display = "block";
	}
}
function trocaaba(id){
	/* for para colocar todas as div´s com display none e as Abas com a class "aba" */
	var aba,div;
	for(i=0; i<=2; i++){
		aba = document.getElementById("aba"+i);
		div = document.getElementById("div_"+i);						
		aba.className = "aba";
		div.style.display = "none";
	}

	/* Coloca a div do id com display block e as Abas com a class "abaon" */
	aba = document.getElementById("aba"+id);
	div = document.getElementById("div_"+id);					
	aba.className = "abaon";
	div.style.display = "block";
}
var ant;
					function abrefecha(id) //Função que mostra/esconde as tabelas
					{
					var tabela = document.getElementById("box" + id);
					var lnk = document.getElementById("lnk" + id);
					
						if(ant == id){
						if (tabela.style.display == "block")
						{
						lnk.className="lnkSeta";
						tabela.style.display = "none";
						}
							else
							{
							lnk.className="lnkSetaon";
							tabela.style.display = "block";
							}
							}
						else{
						if(ant != undefined){
						document.getElementById("box" + ant).style.display = "none";
						document.getElementById("lnk" + ant).className="lnkSeta";
						}
						lnk.className="lnkSetaon";
						tabela.style.display = "block";
						ant = id;
						}
					}
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];}}
    }
    MM_preloadImages('../img/img_aba_ce.gif','../img/img_aba_m.gif','../img/img_aba_cd.gif','../img/img_aba_ce_on.gif','../img/img_aba_m_on.gif','../img/img_aba_cd_on.gif','../img/bg_table_td_sel.jpg','../img/bg_table_td.jpg');



/* ################################### pre load menu topo############################## */
	ItemMenu1off = new Image();
	ItemMenu1off.src = "../../img/menu/ttl_pedido.gif";
	
	ItemMenu1on = new Image();
	ItemMenu1on.src = "../../img/menu/ttl_pedido_over.gif";
/* ################################################################# */
	ItemMenu2off = new Image();
	ItemMenu2off.src = "../../img/menu/ttl_cadastrese.gif";
	
	ItemMenu2on = new Image();
	ItemMenu2on.src = "../../img/menu/ttl_cadastrese_over.gif";
		
/* ################################################################# */
	ItemMenu3off = new Image();
	ItemMenu3off.src = "../../img/menu/ttl_contato.gif";
	
	ItemMenu3on = new Image();
	ItemMenu3on.src = "../../img/menu/ttl_contato_over.gif";
/* ################################################################# */
	ItemMenu4off = new Image();
	ItemMenu4off.src = "../../img/menu/ttl_ajuda.gif";
	
	ItemMenu4on = new Image();
	ItemMenu4on.src = "../../img/menu/ttl_ajuda_over.gif";
/* ################################################################# */
	ItemMenu5off = new Image();
	ItemMenu5off.src = "../../img/menu/ttl_meu_cadastro.gif";
	
	ItemMenu5on = new Image();
	ItemMenu5on.src = "../../img/menu/ttl_meu_cadastro_over.gif";
/* ############################# fim menu topo #################################### */
	btn_cadastreseoff = new Image();
	btn_cadastreseoff.src = "../../img/btn_cadastrese.gif";
	
	btn_cadastreseon = new Image();
	btn_cadastreseon.src = "../../img/btn_cadastrese_over.gif";
	
/* ################################################################# */
var ItemAnt, ItemAnt2;
	function submenu(submenu) {
			if (ItemAnt == "boxsecao_"+submenu) {
					if (document.getElementById("boxsecao_"+submenu).style.display == "block") {
						document.getElementById("boxsecao_"+submenu).style.display = "none";
						document.getElementById("itemsecao_"+submenu).className = "normal";
					} else {
						document.getElementById("boxsecao_"+submenu).style.display = "block";
						document.getElementById("itemsecao_"+submenu).className = "ativo";
					}
			} else {
				if (ItemAnt != undefined) {
						document.getElementById(ItemAnt).style.display = "none";
						document.getElementById(ItemAnt2).className = "normal";
				}
				document.getElementById("boxsecao_"+submenu).style.display = "block";
				document.getElementById("itemsecao_"+submenu).className = "ativo";
				ItemAnt = "boxsecao_"+submenu;
				ItemAnt2 = "itemsecao_"+submenu;
			}
	}
			
	
	function me_box(id,op){
		if(op == 1)
			document.getElementById(id).style.display = "block";
		else
			document.getElementById(id).style.display = "none";
		}




   // 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
        }
    }


// Função para aceitar apenas números em campos texto

function soNumeros(e){
 //Caso Internet Explorer(IE) outros (Other)
 if (navigator.appName.indexOf('Microsoft') != -1){
 	clientNavigator = "IE";
 }else{
 	clientNavigator = "Other";
 }

 //Função permite digitação de números
 	if (clientNavigator == "IE"){
 		if (e.keyCode < 48 || e.keyCode > 57){
 			return false
 		}
 	}else{
 		if ((e.charCode < 48 || e.charCode > 57) && e.keyCode == 0){
 			return false
 		}
 	}

/*
    //alert(e.keyCode)
    var KEY_NUMPAD_ZERO = 96;
    var KEY_NUMPAD_NINE = 105;
    var KEY_LEFT = 37;
    var KEY_RIGHT = 39;
    var KEY_HOME = 36;
    var KEY_END = 35;
    var KEY_DELETE = 46;
       var key;
    var keychar;

    if (window.event) {
       //key = e.keyCode;
       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 >=KEY_NUMPAD_ZERO && key <= KEY_NUMPAD_NINE  ) ||
          (key==KEY_LEFT) || (key==KEY_RIGHT) || (key==KEY_HOME) || (key==KEY_END) || (key==KEY_DELETE)
       )
    {

       return true;
    } else if ((("0123456789").indexOf(keychar) > -1)) {
       return true; 

       } else {
       return false;

    } */
}
/*
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;
     }
}*/




//Validação de CPF ou CNPJ
//EX: ... NAME="cpf" maxlength="11" value="" onBlur="return isValidCPFCGC(this.value,'CPF')
  function isValidCPFCGC(sText, tipo) {
    var flgStatus;
	var frm;
	frm = document.form1;
	if(tipo=="CPF"){
		campo = sText;
	}else{
		campo = sText;
	}
	
    flgStatus = true;
	sText = new String(sText.value).toString();
	
	if(sText.length == 11) {
      
	  // CPF
      for(i=0;((i<=(sText.length-1))&& flgStatus); i++) {
        val = sText.charAt(i);

              if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
                 (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
                    //alert('inválido');
					flgStatus = false;
              }
      }
      if(flgStatus) {
        soma = 0;
        for(i=0;i<=8;i++) {
          val = eval(sText.charAt(i));
          soma = soma + (val*(i+1));
          }
        resto = soma % 11;
        if(resto>9) {
          dig = resto-10;
          } else {
              dig = resto;
              }
        if(dig != eval(sText.charAt(9))) {
		//alert('inválido');
          flgStatus = false;
          } else {
              soma = 0;
              for(i=0;i<=7;i++) {
                val = eval(sText.charAt(i+1));
                soma = soma + (val*(i+1));
                }
              soma = soma + (dig * 9);
              resto = soma % 11;
              if(resto>9) {
                dig = resto-10;
                } else {
                    dig = resto;
                    }
              if (dig != eval(sText.charAt(10))) {
			  //alert('inválido');
                flgStatus = false;
                }
              }
        }
      } else if(sText.length == 14) {
               // CGC-CNPJ
               for(i=0;((i<=(sText.length-1))&& flgStatus); i++) {
                 val = sText.charAt(i);
                 if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
                     (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
                       flgStatus = false;
                 }
               }
               if(flgStatus) {
                 m2 = 2;
                 soma1 = 0;
                 soma2 = 0;
                 for(i=11;i>=0;i--) {
                   val = eval(sText.charAt(i));
                   m1 = m2;
                   if (m2<9) {
                     m2 = m2+1;
                     } else {
                         m2 = 2;
                         }
                   soma1 = soma1 + (val * m1);
                   soma2 = soma2 + (val * m2);
                   }  // fim do for de soma

                 soma1 = soma1 % 11;
                 if (soma1 < 2) {
                   d1 = 0;
                   } else {
                       d1 = 11-soma1;
                       }

                 soma2 = (soma2 + (2 * d1)) % 11;
                 if (soma2 < 2) {
                   d2 = 0;
                   } else {
                       d2 = 11-soma2;
                       }
                 if (!((d1==sText.charAt(12)) && (d2==sText.charAt(13)))) {
                   flgStatus = false;
                   }
                 }
               } else {
                   // Inválido
                   flgStatus = false;
                   }

    //alert(flgStatus);
    //alert(campo);
	if(campo.value!=""){
		if(flgStatus == true && campo.value!=""){
			//alert('válido');
			//campo.focus();
		}else{
			alert(tipo + ' incorreto!');
			campo.value="";
			campo.focus();
		}
	}
    return(flgStatus);

}
	
	
	
//verifica se foi digitado a quantidade solicitada
function validaQuantidadeDigitos(campo,msg){
   var limite = campo.getAttribute('maxlength');
   
   if (campo.value != "" && campo.value.length < limite){ 
    alert(msg);
    //campo.value="";
    campo.focus();
  
   }
}	 


//validações no cadastro do cliente
function validaSenha(campo){
   //var frm = document.form1;
   if (campo.value != "" && campo.value.length < 6){ 
    alert('Senha inválida!\nMínimo 6 e no máximo 10 caracteres');
    campo.value="";
    campo.focus();
   }else{
    document.getElementById("senhaDigitada").value = campo.value;
   }
}

function confirmaSenha(campo){
    var senha = document.getElementById("senhaDigitada").value;
	//var frm = document.form1;
	if(campo.value!=""){
		if(senha != campo.value){
			alert('Confirmação de senha inválida!');
			campo.value="";
			//frm.senha2.focus();	
		}
	}
}


function imprimirBoleto()
{
    document.formBoleto.submit();
}


function openBoleto()
{
    window.open('', 'SHOPLINE', 'toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');
}