/*
	variáveis globais
*/
	// variáveis determinantes de browsers
	var isN4  	= (document.layers) ? true : false;
	var isIE  	= (document.all) ? true : false;
	var isDOM 	= (document.getElementById && !document.all) ? true : false;
	
/*
	PrintPage()
	função responsável por chamar a caixa de diálogo do navegador para impressão.
*/
function PrintPage()
{
	if (isIE)
		window.print();
	else
		alert('Por favor selecione a opcao "Arquivo -> Imprimir" do menu superior para imprimir.');
}

/*
    função que avança o focus de uma caixa de texto para a seguinte 

*/
function GoToNext(size,cep1,cep2)
{
   if(document.getElementById(cep1.id).value.length >=size)
   {
      document.getElementById(cep2.id).focus();
      
   }
 
}

/*
	OpenPopup()
	função genérica para abertura de popups no site.
*/
function OpenPopup(idPopup, url, popupW, popupH){
	window.open(url, idPopup, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + popupW + ',height=' + popupH + ',top=55,left=55');
}

function OpenProductRememberPopup(idProduct){
    OpenPopup('productremember', 'productremember.aspx?idproduct=' + idProduct, 330, 300);
}

function OpenProductIndicatePopup(idProduct){
    OpenPopup('indicate', 'indicate.aspx?idproduct=' + idProduct, 480, 350);
}

function OpenGiftCardPopup(idPopup, url, popupW, popupH){
	window.open(url, idPopup, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + popupW + ',height=' + popupH + ',top=55,left=55');
}

function OpenCorreiosPopup() {
    window.open('http://websro.correios.com.br/sro_bin/txect01$.startup?P_LINGUA=001&P_TIPO=001','SRO','width=550,height=400,scrollbars=yes,resizable=no,toolbar=no');
}

function OpenOnlineHelpPopup() {
    window.open('http://corp2.aloweb.com.br/atendimento.php?l=webracing&x=140&deptid=0','website','top=10,left=10,width=450,height=380');
}

 function oPenPopupShipCost(zipCode, zipCodeComplement)
 {
    var zipfull = zipCode + zipCodeComplement;
    window.open('popupshipcost.aspx?zip='+zipfull,null ,'width=500,height=200')
    return false;
 }

/*
	ValidateNumberOfChars()
	função responsável por validar a quantidade de caracteres dentro de uma área de texto.
*/
function ValidateNumberOfChars(textBox, limit, divResponse){

	var validKey = true;
	var obj = document.getElementById(textBox);
	var divResponse = document.getElementById(divResponse);
	var diff = limit - obj.value.length;
	
	if(diff < 0 && 
		window.event.keyCode != 8 &&
		window.event.keyCode != 17 &&
		!(window.event.keyCode >= 33 && window.event.keyCode <= 40) &&
		window.event.keyCode != 46
		)
	{
		obj.value = obj.value.substr(0, limit);
		alert('Atenção: Você não pode exceder ' + limit + ' caracteres neste campo!');
		validKey = false;
	}
	
	divResponse.innerHTML = "Total de <font color=\"red\"><strong>" + obj.value.length + "</strong></font> caracteres digitados de no máximo <strong>" + limit + "</strong>.";
	
	return validKey;
}

function GoToNext(tamanho, campo1, campo2)
{
    if(document.getElementById(campo1.id).value.length >= tamanho)
        {
            document.getElementById(campo2.id).focus();
        }
}

function RGFormat(campo) 
{ 
    var tamanho = document.getElementById(campo.id).value.length; 

    if (tamanho == 2 || tamanho == 6) 
        {
	        document.getElementById(campo.id).value += '.';
	    } 
		
    if (tamanho == 10) 
        {
	        document.getElementById(campo.id).value += '-';
	    } 
}

function CPFFormat(campo) 
{ 
    var tamanho = document.getElementById(campo.id).value.length; 

    if (tamanho == 3 || tamanho == 7) 
        {
	        document.getElementById(campo.id).value += '.';
	    } 
		
    if (tamanho == 11) 
        {
	        document.getElementById(campo.id).value += '-';
	    } 
}

function closeDiv(){
    document.getElementById("divBanner").style.display="none";
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}