
/*
  Panasonic GloRIA
  JS FILE [ls-common.js]

Update history ---------------------------------------------------
07/03 fixed css propaty function.
------------------------------------------------------------------

 */

/* 1. global value;
--------------------------------------------------------------------------  */
var agent = navigator.userAgent.toLowerCase();
var vers = navigator.appVersion.charAt(0);
var win = (agent.indexOf("windows") != -1);
var mac = (agent.indexOf("mac") != -1);
var w3c = document.getElementById;
var gecko = agent.indexOf("gecko") != -1;
var opera = agent.indexOf("opera",0) != -1;
var safari = agent.indexOf("safari") != -1;
var ie = agent.indexOf("msie") != -1 && !opera;
var ie5win = (agent.indexOf("msie 5.0") != -1) && win;
var ie55win = (agent.indexOf("msie 5.5") != -1) && win;
var ie6win = (agent.indexOf("msie 6.") != -1) && win;
var ie5mac = (agent.indexOf("msie") != -1) && mac;
var ns6 = (agent.indexOf("netscape") != -1) && (vers > 4) && !opera;

var dname = new String(document.domain);
//var path = new String(location.pathname);
var pth = new String(location.pathname);

// Define "Dev Site" path. (sec.panasonic.net)
var rpath = (pth.indexOf("sec.panasonic.net") > 0 || dname.indexOf("gloria") > 0)? "../common" : "/common";

getCurrentDir = function(){
	var pth_array = pth.match(/[\w-_\.]+/g);
	slash = pth.match(/\//g);
	var dir = "/";
	for( var i=0,f=(slash.length-1) ; i<f ; i++ ){dir += pth_array[i] + "/";}
	return dir
}

var cdir = getCurrentDir();




/* 2. Header Form
--------------------------------------------------------------------------  */
function commonSearchKey(){
  if(document.commonSearch.qt.value.length == 0){
    alert("Please enter keyword.");
    return false;
  } else {
    return true;
  }
}

function setvalue_E(id,sw){
  if (sw == 'on'){
    if (id.value.indexOf('> Busca') > -1) {
      id.value='';
    }
  } else {
    if (id.value == '') {
      id.value = '> Busca';
    }
  }
}



/* 3. Onlod function
--------------------------------------------------------------------------  */
function addEvent(obj, type, listener) {
  if(window.addEventListener) window.addEventListener('load',listener,false);
  else {
    var prev  = obj[type];
    obj[type] = (prev) ? function() { prev(); listener(); } : listener;
  }
}

window.addOnload = function(listener){
  addEvent(window, 'onload', listener);
}



/* 5. Set html class attributes
gecko, opera, msie(ie:bugged Mac IE) , ie5, ie55, ie6, ie7, macie5, js
ie5-non-dtd, ie5-dtd (ie50,ie5.5)
ie-non-dtd, ie-dtd (ie6,ie7)
ien-non-dtd, ien-dtd (ie7 over)
ge-non-dtd, ge-dtd (ns,firefox,opera)
--------------------------------------------------------------------------  */
var sethtmlCls = function(){
	var u = navigator.userAgent.toLowerCase(),
		is = function(t){ return u.indexOf(t) != -1;},
		hs = document.getElementsByTagName('html')[0],
		brw = (/msie ([\d.]{0,3})/i.test(u))? ("msie " + (is("mac")? "mac" : "") + "ie" + ((RegExp.$1.replace(".","")%55==0)? "55": RegExp.$1.substring(0,1))) : is('opera')? "opera" : "gecko";
	if(win&&ie){
		cn = document.childNodes[0];
		brw += (!(ie5win || ie55win))? ((cn.text.indexOf("dtd") < 0)? " ie-non-dtd" :" ie-dtd") : ((cn.text.indexOf("dtd") < 0)? " ie5-non-dtd":" ie5-dtd");
		brw += (typeof document.documentElement.style.msInterpolationMode != "undefined")? ((cn.text.indexOf("dtd") < 0)? " ien-non-dtd" : " ien-dtd") : "";
	}else if( !safari && !(mac&&ie) ){
		//ns,firefox,opera
		brw += (document.doctype.systemId.indexOf("dtd") < 0)? " ge-non-dtd" : " ge-dtd";
	}
	brw += " js";
	hs.className += brw;
}();




/* 6. popup function
--------------------------------------------------------------------------  */
function is_opener() {
  var ua = navigator.userAgent
  if(!!window.opener)
    if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1) 
      return !window.opener.closed
    else return typeof window.opener.document  == 'object'
  else return false
}


function setFooter(){
  if(is_opener()){document.write('<ul><li class="btn-close"><a href="#" onclick="window.close();return false;">Close</a></li></ul>');}
  else{document.write('<ul><li class="btn-back"><a href="#" onclick="history.back(-1);return false;">Return to Page</a></li></ul>');}
}


/* 4. Popup window
-------------------------------------------------------------------------- */
function openWin(url,wname,w,h,scroll){
    if(win && ie){w += (scroll)? 16:0;h -= 19;}
    var str = 'width=' + w+ ',height=' + h 
           + ',location=0,toolbar=1,menubar=1,scrollbars=' + scroll + ',resizable=1';
    swin = window.open(url,wname,'width=' + w + ',height=' + h + str);
    swin.focus();
}
function setLogolnk(){
    this.w3c = document.getElementById; if (!this.w3c) return false;
    return this;
}
setLogolnk.prototype = {
    init: function(){
       SL.logolnk = document.getElementById("popuptop");if(!SL.logolnk) return false;
       SL.logolnk.onclick = function(){
            if(is_opener()){
                  window.opener.focus();
                  window.opener.location.href = "/";
                  return false;
            }else{
                  location.href = "/";
            }
       }
    }
}
var SL = new setLogolnk();
window.addOnload(SL.init);



function Imprimir(URL, cat, id, page)
{		
		//alert(""+url+"/products/compare/print.aspx?id="+QueryString("id")+"&cat="+QueryString("cat")+"");
		//window.open(""+URL+"/products/compare/print.aspx?id="+id+"&cat="+cat+"",'page','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=650,height=800');  
		if (page == 'rec')
		{
		    window.open(""+URL+"/products/compare/printrec.aspx?id="+id+"&cat="+cat+"",'page','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=650,height=650');  
        }
        else
        {
            window.open(""+URL+"/products/compare/print.aspx?id="+id+"&cat="+cat+"",'page','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=650,height=650');  
        }
}


function Comparar(MaxProdComp,Categoria,URL){
    
		var totalItens = 0;
		var ItensCod = "";

		divs=document.getElementsByTagName("input");
		
		for (i=0;i<divs.length;i++) 
		{
			if (divs[i].type == "checkbox")
			{
				if (divs[i].name.indexOf("chkComparar") >= 0)
				{
					if(divs[i].checked)
					{
					    
						if (ItensCod == "")
						{
							ItensCod = divs[i].value;
						}
						else
						{
							ItensCod += "|" + divs[i].value;
						}

						totalItens++;
					}
				}
			}
		}
		
		

		if (totalItens > 1 && totalItens < parseInt(MaxProdComp) + 1)
		{
		    window.open(""+URL+"/products/compare/comparing.aspx?id="+ItensCod+"&cat="+Categoria+"",'page','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=800,height=650');  
		}
		else if (totalItens > parseInt(MaxProdComp))
		{
			alert("Você pode selecionar no máximo " + MaxProdComp + " produtos para poder fazer a comparação.");
		}
		else
		{
			alert("Voce precisa selecionar mais de 1 produto para poder fazer a comparacão de produtos.");
		}
	}
	
	
	
	function Popup(Pagina,width,height)
	{
	qs=new Array()
        variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")
        if(variaveis!="")
        {
            for(i=0;i<variaveis.length;i++)
            {
                nvar=variaveis[i].split("=")
                qs[nvar[0]]=unescape(nvar[1])
            }
        }
        function QueryString(variavel)
        {
            return qs[variavel]
        }
        
	//window.open(""+Pagina+"",'page','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="'+width+'",height="'+height+'"');
	//window.alert('teste');
	window.open(''+Pagina+'','Title','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width='+width+', height='+height+'');
    
    }
	
	