/*
	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,obj1,obj2)
{
    if(document.getElementById(obj1.id).value.length >=size)
    {
        document.getElementById(obj2.id).focus();
    }
}
 
function ChangeClientType()
{
    if (isDOM) 
    {
        if (arguments[0] == 'F')
        {
            document.getElementById('trPF').className = 'visiblediv';
            document.getElementById('trPJ').className = 'invisiblediv';
        }
        else if (arguments[0] == 'J')
        {   
            document.getElementById('trPF').className = 'invisiblediv';
            document.getElementById('trPJ').className = 'visiblediv';
        }
    }
    else if (isN4) 
    {
        if (arguments[0] == 'F')
        {
            document.layers['trPF'].className = 'visiblediv';
            document.layers['trPJ'].className = 'invisiblediv';
        }
        else if (arguments[0] == 'J')
        {   
            document.layers['trPF'].className = 'invisiblediv';
            document.layers['trPJ'].className = 'visiblediv';
        }
    }
    else if (isIE)
    {
        if (arguments[0] == 'F')
        {
            if (document.all['trPF'] != null)
                document.all['trPF'].className = 'visiblediv';
            if (document.all['trPJ'] != null)
                document.all['trPJ'].className = 'invisiblediv';
        }
        else if (arguments[0] == 'J')
        {   
            if (document.all['trPF'] != null)
                document.all['trPF'].className = 'invisiblediv';
            if (document.all['trPJ'] != null)
                document.all['trPJ'].className = 'visiblediv';
        }
    }
}

/*
    função que avança o focus de uma caixa de texto para a seguinte 

*/
function ChangeFieldFocus(textbox1, textbox2, nuLength)
{
    var txt1;
    var txt2;
        
    if (isDOM) 
    {
	    txt1 = document.getElementById(textbox1.id);
	    txt2 = document.getElementById(textbox2.id);
    }
    else if (isN4) 
    {
        txt1 = document.layers[textbox1.id];
        txt2 = document.layers[textbox2.id];
    }
    else if (isIE)
    {
		txt1 = document.all[textbox1.id];
        txt2 = document.all[textbox2.id];
    }
    
    if (txt1.value.length >= nuLength)
        txt2.focus();
}

/*
	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 ChangeImage(path, imgDetalhe, imgZoom, idProduct, imgBig, href, hdn)
{       
    if (isDOM) 
    {
        document.getElementById(imgBig).src = path + "/images/product/" + imgDetalhe;
        	    
        if (imgZoom != "")
            document.getElementById(href).setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1'," + hdn + ");");
        else
            document.getElementById(href).removeAttribute("href");
    }
    else if (isN4) 
    {
        document.layers[imgBig].src = path + "/images/product/" + imgDetalhe;
        	    
        if (imgZoom != "")
            document.layers[href].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1');");
        else
            document.layers[href].removeAttribute("href");
    }
    else if (isIE)
    {
        document.all[imgBig].src = path + "/images/product/" + imgDetalhe;
            	    
        if (imgZoom != "")
            document.all[href].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1');");
        else
            document.all[href].removeAttribute("href");
    }
}

function OpenPopupWarnMe(url)
{   
    window.open(url,'ProductRemember','toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=100,left=50,width=300,height=365');                             
    //pLX = 305;
    //pAY = 400;
    //xx=parseInt(((screen.width-pLX-8)/2));
    //yy=parseInt(((screen.height-pAY-15)/2));
	//pUrl = 'productpopupwarnme.aspx?idproduct=' + idProduct;    		
	//s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);		
}

function OpenPopupStaticText( url, vwidth, vheight )
{
    window.open(url,'StaticText','toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=100,left=50,width='+vwidth+',height='+ vheight + '');
}

function OpenPopupNewsletter(txtEmail,sTeams,sInterest)
{
    var email, team, interest;
    
    if (isDOM)
    {
        email    = document.getElementById(txtEmail).value;
        team     = document.getElementById(sTeams).value;
        interest = document.getElementById(sInterest).value;
    }
    else if (isN4)
    {
        email    = document.layers[txtEmail].value;
        team     = document.layers[sTeams].value;
        interest = document.layers[sInterest].value;        
    }
    else if (isIE)
    {
        email    = document.all[txtEmail].value;
        team     = document.all[sTeams].value;
        interest = document.all[sInterest].value;
    }
                             
    pLX  = 305;
    pAY  = 300;
    xx   = parseInt(((screen.width-pLX-8)/2));
    yy   = parseInt(((screen.height-pAY-15)/2));
	pUrl = 'popupnewsletter.aspx?email=' + email + '&team=' + team + '&interest=' + interest;
    		
	s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);
}

function OpenPopupIndicate(idProduct)
{                                 
    pLX  = 455;
    pAY  = 550;
    xx   = parseInt(((screen.width-pLX-8)/2));
    yy   = parseInt(((screen.height-pAY-15)/2));
	pUrl = 'productpopupindicate.aspx?idproduct=' + idProduct;
    		
	s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);		
}

function ProductZoom(imageUrl, fgType, idProduct)
{                                       
    pLX  = 400;
	pAY  = 400;
	xx   = parseInt(((screen.width-pLX-8)/2));
	yy   = parseInt(((screen.height-pAY-15)/2));
	pUrl = 'productpopupzoom.aspx?idproduct=' + idProduct + '&img=' + imageUrl + '&type=' + fgType;
	pTit = 'TimesTorcidas';
    		
	s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);
}

function setVisibility(layerName, on)
{
    if(document.getElementById(layerName) == null)
        return;

    if (on)
        document.getElementById(layerName).className = "visiblediv";
    else
		document.getElementById(layerName).className = "invisiblediv";
}