var isie = (navigator.appVersion.indexOf("MSIE") != -1) ? (navigator.appVersion.indexOf("Mac") != -1) ? false : true  : false;

/* Ativa ou desativa o DIV listaItens... da lista de desejos... mudando a classe. */
function mostrarObj(id) {
var idObj = document.getElementById(id).className;
if (idObj=="ligado") {
	document.getElementById(id).className = 'desligado';
	try	{
		document.getElementById('nItensWishList').className = 'desligado';
		} catch(err) {}

	} else {
		document.getElementById(id).className = 'ligado';
			try	{
			document.getElementById('nItensWishList').className = 'ligado';
			} catch(err) {}
		}
}




/* Retorna dimensoes da pagina */
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	
	
	return arrayPageSize;
}

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
	else if (document.body) yScroll = document.body.scrollTop;
	arrayPageScroll = {yScroll:yScroll};
	return arrayPageScroll;
}

/* Desaparece com as div de Zoom e a Sombra que fica sobre o site. */
function fechaPop(obj) {
	
	var selectBox = document.getElementsByTagName("select");
	var selectTamanho = selectBox.length;
	
	if ((selectTamanho!=null) && (isie)) {
		for(var x=0;x<selectTamanho;x++)
			selectBox[x].style.visibility="visible"
	}
	
	//document.getElementById("divSky").style.visibility="visible";
	
	try {
		document.body.removeChild(document.getElementById('popZoom'));
		document.body.removeChild(document.getElementById('popSombra'));
	} catch(e) {}

}

/* Função responsável por criar a Sombra sobre o site e a div Container que vai abrigar o conteudo da página a ser carrega */
function abrePop(params) {
	var selectBox = document.getElementsByTagName("select");
	var selectTamanho = selectBox.length;
	
	if ((selectTamanho!=null) && (isie)) {
		for(var x=0;x<selectTamanho;x++)
			selectBox[x].style.visibility="hidden";
	}
	
	var embed = document.getElementsByTagName("embed");
	var embedTamanho = embed.length;
	
	if ((embedTamanho!=null) && (isie)) {
		for(var x=0;x<embedTamanho;x++)
			embed[x].style
	}
	
	//document.getElementById("divSky").style.visibility="hidden";
	//document.getElementById("divSuperbanner").style.visibility="hidden";
	
	//capturando caminho e classe
	var url = params.popUrl;
	var popClass = params.popClass;

	//capturando array com as dimensoes
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	
	//Verifica se já existe algum div aparente... se tiver remove
	try {
		document.body.removeChild(document.getElementById('popZoom'));
		document.body.removeChild(document.getElementById('popSombra'));
	} catch(e) {}
	
	//Cria div que vai abrigar o conteudo da página
	var divContainer = document.createElement('div');
	divContainer.style.visibility = 'hidden';
	divContainer.id = 'popZoom';
	divContainer.className = 'popZoom';
	divContainer.style.height = (pageSize.pageHeight + 'px');
	
	//Cria sombra que fica sobre o site.
	var divSombra = document.createElement('div');
	divSombra.id = 'popSombra';
	divSombra.className = 'popSombra';
	
	divSombra.style.height = (pageSize.pageHeight + 'px');
	divSombra.style.backgroundPosition = 'center ' + (pageScroll.yScroll + ((pageSize.windowHeight - 100)/2)) + 'px';
	
	//Adiciona as divs criadas como filho da tag BODY
	document.body.appendChild(divSombra);
	document.body.appendChild(divContainer);
	
	//Cria objeto passando os valores necessários
	var pop = new popObj(url,divContainer,divSombra,popClass);
}
	
function popObj(url,divContainer,divSombra,popClass) {
	var self = this;
	//Cria um novo objeto XML passando os valores. Esse obj e funções estao no arq. xml.js
	this.xml = new xmlObj( {
		url: url,
		obj: self, 
		func: 'show', 
		args: { divContainer:divContainer,divSombra:divSombra,popClass:popClass }
	} );
}

popObj.prototype.show = function(args) {
	var htm = args.responseText;
	var divContainer = args.divContainer;
	var divSombra = args.divSombra;
	divContainer.innerHTML = htm;
	var popClass = args.popClass;
	var box = false;
	var tags = divContainer.getElementsByTagName('div');
	for(var i=0,len=tags.length;i<len;i++) if(tags[i].className.indexOf(popClass)>-1) box = tags[i];
	if(!box) return;
	var largura = box.offsetWidth;
	var altura = box.offsetHeight;
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	var boxTop = pageScroll.yScroll + ((pageSize.windowHeight - altura) / 2);
	var boxLeft = ((pageSize.pageWidth - largura) / 2);
	box.style.position = 'absolute';
	box.style.top = (boxTop < 0) ? "0px" : boxTop + "px";
	box.style.left = (boxLeft < 0) ? "0px" : boxLeft + "px";
	
	
	//alteraIcones(divContainer);
	
	divContainer.style.visibility = 'visible';
	
	
	setPopUpFocus(divContainer);
	
	
	divSombra.style.backgroundImage = 'none';

}

function setPopUpFocus(n){
	
    var children = n.childNodes;
	
	for(var i=0; i < children.length; i++) {    
        
		if(children[i].type == 'text'){
			children[i].focus();
			return false;
		}
		
		setPopUpFocus(children[i]);
    }
	
}
						
/* --------- */