/********************************
* Realiza efeito no carrinho.
********************************/
$(document).ready(function (){
	$(".DivCarrinhoLayout").fadeTo("slow", 0.9);
	
	$("#conteudo_atendimento_fundo").mouseover(function(){
		$(".DivCarrinhoLayout").show("slow");
	});
	
	$(".fechar_carrinho").click(function(){
		$(".DivCarrinhoLayout").hide("slow");
	});
	
	$("#nomeproduto").keyup(function(e){
		if(isEnter(e))
			fazBusca();	
	});
	
	if($(".linkatual").html() != null){
		$(".linkatual").html($(".linkatual").html().replace("PÁGINA: ",""));
	}
	
	
/*	$(".alinhamentoImagemProduto a img").draggable({helper: 'clone'});
	$(".DivCarrinhoLayout").droppable({
		accept: ".block",
		activeClass: 'droppable-active',
		hoverClass: 'droppable-hover',
		drop: function(ev, ui) {
			$(this).addClass('ui-state-highlight').html('Dropped!');
			alert(ui.src);
			var idproduct = ui.src.search(/(.+).jpg/ig);
			AddCarrinho("Loja_Inicial", idproduct, 68);
		}
	});	*/
    
});



addEvent(window, "load", novoLoad, true);
/*
	Busca
*/
//pasta do cliente
//try{	
	var componentes = new com.webvenda.componentes('celulares');
	function GEBI(elem){
		return (document.getElementById(elem)?document.getElementById(elem):null);
	}
	function GEBIV(elem){
		return (GEBI(elem)?GEBI(elem).value:'');
	}	
	function fazBusca(){
		componentes = new com.webvenda.componentes("celulares");
		var busca = new componentes.busca;
		//ordem dos valores: nomeproduto,departamento,fabricante,valorminimo,valormaximo,ordem
		busca.fazBusca(GEBIV('prod'),GEBIV('pdep'),GEBIV('pfab'),GEBIV('valorminimo'),GEBIV('valormaximo'),GEBIV('ordem'))
	}
	function preencheDepartamento(pdep){
		componentes = new com.webvenda.componentes("celulares");
		if (pdep.options.length==1)
			componentes.preencheDepartamento(pdep);
	}
	function preencheFabricante(pfab){
		componentes = new com.webvenda.componentes("celulares");
		if (pfab.options.length==1)
			componentes.preencheFabricante(pfab);
	}
//}catch(e){}


function maisMenos(iframe, div, div2)
{
	iframe = parent.document.all(iframe);
	div = document.all(div);
	div2 = document.all(div2);
	var divs = document.body.getElementsByTagName('div');
	for(var i=0; i < divs.length; i++)
		if(i%2==0)
			divs[i].style.display = 'block';
		else
			divs[i].style.display = 'none';
	div.style.display = 'block';
	div2.style.display = 'none';
	redimenciona(iframe);
}

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.innerHTML = "";
		_divBusca2.appendChild(_divBusca);
		_divBusca.style.display = 'block';
	}catch(e){}

	if(document.getElementById('saudacao') != null)
	{
		document.getElementById('saudacao').style.display = 'block';
		if (!isNaN(lerCookie('CEPSmartGeo')) && lerCookie('CEPSmartGeo')!= null)  {
			if (window.location.href.indexOf("interno") < 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 Araujo mais próxima de você.<br>Ligue para (31)3270.5000.";	
			}
		}
		else {
			var localizacao = document.getElementById('DivLocalizacao');									
			localizacao.innerHTML = "Encontre a Araujo 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, 'celulares', '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=celulares','IndiqueSite','width=420,height=510,scrollbars=no,menubar=no, resizable=yes, status=no, toolbar=no, location=no');
}

function Newsletter()
{
	window.open('/Tools/Newsletter/Newsletter.aspx?siteUrl=celulares','Newsletter','width=420,height=410,scrollbars=no,menubar=no, resizable=yes, status=no, toolbar=no, location=no');
}

function Restrito()
{
	//Funcao para produtos restritos.
	alert("Este produto nao pode ser comercializado pela internet. Entre em contato por email.");
}

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=565,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=565,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 = "/celulares/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;
	}
	if(TelaDeCEP != null)
	{
		TelaDeCEP.style.width= document.body.scrollWidth;
		TelaDeCEP.style.height= document.body.scrollHeight;	
		TelaDeCEP.style.padding = "" + paddingTop + " 0 0 " + paddingLeft+ "";
	}	
	Load();
}

//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';
		}
	}
}

function GE(i){return document.getElementById(i);}

function CopiaLink(objOrigem,objDestino) {
	if (objOrigem != null && objDestino != null) {
		objDestino.onclick = objOrigem.onclick;
	}
}



function trocaImagem(obj,img){
		obj.src = img;
}


function ComprarProd(idProduto){
	location.href = "/celulares/Carrinho.aspx?IDProduct=" + idProduto;
}
