/*
	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();
      
   }
 
}

/*
	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 OpenOnLine(idPopup, url, popupW, popupH) {
	window.open(url, idPopup, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + popupW + ',height=' + popupH + ',top=55,left=55');
}

function OpenPopupRemenber(url)
{
    window.open(url,'ProductRemember','toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=100,left=50,width=316,height=325');
} 


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=255,left=255');
}

 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;
}

// Abre popup de zoom de imagem.
function ProductZoom(imageUrl, fgType, idProduct)
{
//    imageUrl=this.sImgBig;
//    
//    if(this.sImgBig == undefined)
//        fgType=0;
//    else
//        fgType=1;
    
    pLX  = 510;
    pAY  = 600;
    xx   = parseInt(((screen.width-pLX-8)/2));
    yy   = parseInt(((screen.height-pAY-15)/2));
    pUrl = 'productpopup.aspx?productId=' + idProduct + '&img=' + imageUrl + '&type=' + fgType;
    pTit = 'PortCasa';
    
    s = window.open(pUrl, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + pLX + ', height=' + pAY + ', top=' + yy + ', left=' + xx + ', screenX=' + xx + ', screenY=' + yy);    		
}

// Abre popup de zoom de imagem.
//function ProductZoom(imageUrl, fgType, idProduct)
//{                                        
//    pLX = 510;
//	pAY = 510;
//	xx=parseInt(((screen.width-pLX-8)/2));
//	yy=parseInt(((screen.height-pAY-15)/2));
//	pUrl = 'productpopup.aspx?productId=' + idProduct + '&img=' + imageUrl + '&type=' + fgType;
//	pTit = 'PortCasa';
//    		
//	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);		
//}

// Muda a imagem do produto de acordo com a imagem adicional clicada.
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 + "');");
            document.getElementById("ctl00_ContentSite_refProduct").setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1','" + hdn + "');");
        }
        else
        {
            document.getElementById(href).removeAttribute("href");
            document.getElementById("ctl00_ContentSite_refProduct").removeAttribute("href");
        }
    }
    else if (isN4) 
    {
        document.layers[imgBig].src = path + "/images/product/" + imgDetalhe;
        
        if (imgZoom != "")
        {
            document.layers[href].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1','" + hdn + "');"); //"javascript:ProductZoom('" + imgZoom + "','1');");
            document.layers["ctl00_ContentSite_refProduct"].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1','" + hdn + "');");
        }
        else
        {
            document.layers[href].removeAttribute("href");
            document.layers["ctl00_ContentSite_refProduct"].removeAttribute("href");
        }
    }
    else if (isIE)
    {
        document.all[imgBig].src = path + "/images/product/" + imgDetalhe;
        
        if (imgZoom != "")
        {
            document.all[href].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1','" + hdn + "');"); //"javascript:ProductZoom('" + imgZoom + "','1');");
            document.all["ctl00_ContentSite_refProduct"].setAttribute("href", "javascript:ProductZoom('" + imgZoom + "','1','" + hdn + "');");
        }
        else
        {
            document.all[href].removeAttribute("href");
            document.all["ctl00_ContentSite_refProduct"].removeAttribute("href");
        }
    }
}

// Muda a imagem de Zoom do produto de acordo com a imagem adicional escolhida.
function ChangeZoomImage(sPath, sImgZoomName, oImgZoom)
{
    if (isDOM)
    {
        document.getElementById(oImgZoom).src = sPath + "/images/product/" + sImgZoomName;
    }
    else if (isN4)
    {
        document.layers[oImgZoom].src = sPath + "/images/product/" + sImgZoomName;
    }
    else if (isIE)
    {
        document.all[oImgZoom].src = sPath + "/images/product/" + sImgZoomName;
    }
}

function OpenPopupNewsletter(oName, oEmail) 
{    
    if (isDOM)
    {
        name = document.getElementById(oName).value;
        email = document.getElementById(oEmail).value;
    }
    else if (isN4)
    {
        name = document.layers[oName].value;
        email = document.layers[oEmail].value;        
    }
    else if (isIE)
    {
        name = document.all[oName].value;
        email = document.all[oEmail].value;        
    }

    pLX = 390;
    pAY = 325;
    xx=parseInt(((screen.width-pLX-8)/2));
    yy=parseInt(((screen.height-pAY-15)/2));
    pUrl = 'newsletter.aspx?email=' + email  + '&name=' + name;
    pTit = 'Newsletter';
    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 ClearField(field, text)
{          
    if (isDOM) 
    {      
        if (document.getElementById(field) != null && document.getElementById(field).value == text) 
            document.getElementById(field).value = '';                          
    }     
    else if (isN4) 
    {
        if (document.layers[field] != null && document.layers[field].value == text) 
            document.layers[field].value = '';    
    }        
    else if (isIE)
    {               
        if (document.all[field] != null && document.all[field].value == text) 
            document.all[field].value = '';        
    } 
} 

function FillField(field, text)
{          
    if (isDOM) 
    {   
        if (document.getElementById(field) != null && document.getElementById(field).value == '') 
            document.getElementById(field).value = text;                          
    }     
    else if (isN4) 
    {
        if (document.layers[field] != null && document.layers[field].value == '') 
            document.layers[field].value = text;    
    }        
    else if (isIE)
    {           
        if (document.all[field] != null && document.all[field].value == '') 
            document.all[field].value = text;        
    } 
} 