addEvent(window, "load", novoLoad, true);

function addEvent(object, evType, func, useCapture)
{
	if (func !== -1) {
		if(object.addEventListener)
		{
			object.addEventListener(evType, func, useCapture);
		} else
		if(object.attachEvent)
		{
			object.attachEvent("on" + evType, func);
		}
	}
}

var strTDAnterior="TDFoto_1";
var Menu;
function novoLoad() {
	//alert(lerCookie('Banner'));
	//MaximizarDiv();
	verifica = document.getElementById('Menu');	
	if (verifica != undefined) {	
		Menu = new SDMenu("Menu");	
		Menu.init();
		Menu.speed = 7;
		Menu.oneSmOnly = true;	
		Menu.remember = true; 
	}
	
	try{
		var _divBusca = document.getElementById("divBusca");
		var _divBusca2 = document.getElementById("divBusca2");		
		_divBusca2.appendChild(_divBusca);
		_divBusca.style.display = 'block';
	}catch(e){}
	/*
	if(document.getElementById('saudacao') != null)
	{
		document.getElementById('saudacao').style.display = 'block';
		if (lerCookie('CEPSmartGeo')!= null)  {
			if (window.location.href.indexOf("drogariaweb") < 0) {
				ConsultaCEP("http://200.198.190.140/sdb/index.asp?cod_empresa=MTU=&acao=1&cep=" + lerCookie('CEPSmartGeo'),"codLoja");
			}else {
				var localizacao = document.getElementById('DivLocalizacao');									
				localizacao.innerHTML = "Encontre a stoque mais próxima de você.<br>Ligue para (31)3270.5000.";	
			}
		}
		else {
			CepHabilitado();
			//var localizacao = document.getElementById('DivLocalizacao');									
			//localizacao.innerHTML = "Encontre a stoque mais próxima de você.<br>Ligue para (31)3270.5000.";
		}		
	}
	*/
	TrabalheConosco();
	//Load();

};

//POP UP
var popUpWin=0;
function PopUp(URLStr, left, top, width, height){if(popUpWin){if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'stoque', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');}


function redimenciona(frmname) 
{ 
	if (frmname != undefined){	
		if(navigator.userAgent.indexOf('Firefox') > -1)
		{
			frmname.height = frmname.contentDocument.height;
		}
		else		
		{
			frmname.height = frmname.contentWindow.document.body.scrollHeight*1.15;
		}
	}
} 

function VerificaEnter(e) { 
	return isEnter(e);
}

function isEnter(e)
{
	var e = e || event;
	var k = e.keyCode || e.which;
	if (k==13) return true
	else return false;
}

function teclaPressionada(e)
{
	return (e.keyCode || e.which);
}

function EnviarForm()
{
	var CEPinput= document.getElementById('CEPinput');
	var cepSemPonto = CEPinput.value.replace("-","").replace(".","");	
	PopUp("http://200.198.190.130/15/index.asp?acao=pesquisa&CEP="+ cepSemPonto,'50','50','800','700');
}

function MascaraCep(obj){
	v= obj.value;
	v=v.replace(/D/g,"");               
	v=v.replace(/^(\d{2})(\d)/,"$1.$2"); 
	v=v.replace(/(\d{3})(\d)/,"$1-$2"); 
	obj.value = v;
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function displayItem(key){
	
	var retornoPesquisa = document.getElementById('retornoPesquisa');	
	if(queryString(key)=='false') 
	{
		retornoPesquisa.src="http://200.198.190.130/15/index.asp?acao=pesquisa";
	}else{
		retornoPesquisa.src="http://200.198.190.130/15/index.asp?acao=pesquisa&CEP=" + queryString(key);
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function tipoBusca(tipo){
	if(tipo=='simples'){									
		document.getElementById('div_buscaAvancada').style.display = 'none';
		document.getElementById('div_buscaSimples').style.display = '';
		document.getElementById('tbDescricaoCurta').value = '';
	} else {									
		document.getElementById('div_buscaSimples').style.display = 'none';
		document.getElementById('div_buscaAvancada').style.display = '';
		document.getElementById('tbDescricaoCurta').value = '';									
	}
}

function IndiqueSite()
{	
	window.open('/Tools/IndiqueSite/IndiqueSite.aspx?URL=stoque','IndiqueSite','width=420,height=455,scrollbars=no,menubar=no, resizable=yes, status=no, toolbar=no, location=no');
}

function Newsletter()
{
	window.open('/Tools/Newsletter/Newsletter.aspx?siteUrl=stoque','Newsletter','width=420,height=380,scrollbars=no,menubar=no, resizable=yes, status=no, toolbar=no, location=no');
}

function Restrito()
{
	//Funcao para produtos restritos.
	/*
	alert("Por determinação da Portaria 344/98 da ANVISA - Agência Nacional de Vigilância Sanitária - este medicamento não pode ser comercializado pela Internet.");
	*/
	alert("Este produto não pode ser vendido pela Internet, maiores informações entre em contato. Tel.:(31) 3270-5000.");
}

function TrabalheConosco() {
	if (location.href.indexOf('ag=trabalheconosco') > -1)
	{	
		var iframe_vagas = document.getElementById('iframeVagas');
		redimenciona(iframe_vagas); 
	}
}

function Avalie(IDProduct){
	window.open('/Commerce/B2C/B2C_Controles/OpineProduto.aspx?IDProduct=' + IDProduct,'OpineProduto','width=420,height=550,scrollbars=no,menubar=no, resizable=no, status=no, toolbar=no, location=no');
}
function IndiqueProduto(IDProduct, IDCategoria){
	window.open('/Commerce/B2C/B2C_Controles/IndiqueProduto.aspx?IDProduct=' + IDProduct + '&IDCategoria=' + IDCategoria,'IndiqueProduto','width=420,height=485,scrollbars=no,menubar=no, resizable=no, status=no, toolbar=no, location=no');
}

function retornoCep(){
	var txtCEPInicial = document.getElementById('txtCEPInicial');
	var txtCEPInicial2 = document.getElementById('txtCEPInicial2');				
	var CEP = txtCEPInicial.value + txtCEPInicial2.value;	
	if (CEP.length >= 9) {
		criarCookie('CEPSmartGeo',CEP.replace('.',''),1);		
		location.href = "/stoque/loja.aspx?linkTo="+ document.location.pathname +"&cp=" + CEP.replace('.','');
	}else {
		alert('Informe o CEP completo da sua região.');		
		window.event.cancelBubble = true;
		window.event.returnValue = false;		
		txtCEPInicial.value = "";
		txtCEPInicial2.value= "";
		Load();
	}
}

function Load(){	
	var TelaDeCEP = document.getElementById('TelaDeCEP');
	if(TelaDeCEP != null){
		if (TelaDeCEP.style.display != 'none') {			
			document.getElementById('txtCEPInicial').focus();	
			return true;
		}
	}
	
}

function eNumero(obj)
{

	if (obj >= 48 && obj <= 57 || obj >= 96 && obj <= 105 || obj == 8 && obj == 88){							
		return true; 				
	}else if((obj != 8) && (obj != 9) && (obj != 13) && (obj != 35) && (obj != 36) && (obj != 46))
		{
			try{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}catch (e){
			}
			return false;
		}
}		

function Pula(teclapres)
{		
	var txtCEPInicial = document.getElementById('txtCEPInicial');
	var separador = '.';
	var conjunto1 = 2;	
	
	if (eNumero(teclaPressionada(teclapres))) {

		if (txtCEPInicial.value.length == conjunto1)
		{		
			txtCEPInicial.value += separador;
		}
		return true;
	}			
}

function retornaParaCepInicial(obj)
{
	var txtCEPInicial2 = document.getElementById('txtCEPInicial2');
	
	if (txtCEPInicial2.value.length == 0 && teclaPressionada(obj) == 8) {				
		var txtCEPInicial = document.getElementById('txtCEPInicial');
		txtCEPInicial.value = "";
		txtCEPInicial.focus();
		return;
	}			
	if (teclaPressionada(obj) == 13) {
		retornoCep();			
		return false;
	}else {			
		eNumero(teclaPressionada(obj));									
	}						
}
function pulaComSeisDigitos()
{
	var txtCEPInicial = document.getElementById('txtCEPInicial');
	if (txtCEPInicial.value.length >= 6) {
		var txtCEPInicial2 = document.getElementById('txtCEPInicial2')
		txtCEPInicial2.value = "";
		txtCEPInicial2.focus();					
	}	
}
function MaximizarDiv()
{
	
	var TelaDeCEP = document.getElementById('TelaDeCEP');
	var divTransparente = document.getElementById('divTransparente');
	var paddingLeft = (screen.availWidth * 0.5) - 200;
	var paddingTop = (screen.availHeight * 0.5) - 220;
	if(divTransparente != null)
	{
		divTransparente.style.width= document.body.scrollWidth;
		divTransparente.style.height= document.body.scrollHeight;
	}

	//Load();
}

function maisMenos(iframe, div, div2)
{
	var divs;
	iframe = parent.document.all(iframe);
	div = document.all(div);
	div2 = document.all(div2);
	divs = document.getElementsByTagName('div');
	for(var i=0; i < divs.length; i++)
	{
		divs[i].style.display = 'none';
		if(i%2==0)
		{
			divs[i].style.display = 'block';
		}
	}
	div.style.display = 'block';
	div2.style.display = 'none';
	redimenciona(iframe);
}

//Funcção para carregar a página de CEP depois que a loja carrega.
function CepHabilitado() {
	/*
	var TelaDeCEP = document.getElementById('TelaDeCEP');
	var divTransparente = document.getElementById('divTransparente');
	TelaDeCEP.style.display = 'block';
	divTransparente.style.display = 'block';
	Load();
	*/
}

//Funções para colocar e retirar a decoração do texto no onMouseOver.
function Over_Deparamento(obj) {	
	obj.style.textDecoration = 'underline';
}		
function Out_Deparamento(obj) {
	obj.style.textDecoration = 'none';
}

//Funções para expandir/restaurar o campo select no onFocus 
function expandeSelect(obj) {
	if(navigator.userAgent.indexOf('IE') > -1)
	{
		var div = document.getElementById('divSelect');
		div.style.height='30px';
		obj.size = "25";
		obj.style.position='absolute'; 
		obj.style.width='190px';
	}
}
      
function restauraSelect(obj) {
	if(navigator.userAgent.indexOf('IE') > -1)
	{
		if(document.activeElement.id != obj.id)
		{
			obj.size = "1";
			obj.style.position=''; 
			obj.style.width='150px';
		}
	}
}


var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";

function JSFX_FloatDiv(id, sx, sy)
{
	
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx; el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{		
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8; 
		this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 40);
	}			
	return el;	
}
