/*-------------------------------------------------------------------------------------------------------------*/
/* GERAL JS - CADIAN 
/* BY RENATO_ABREU 
/* DATA: 05/06/2009
/*-------------------------------------------------------------------------------------------------------------*/
// FUNCAO MOSTRA-ESCONDE
/*-------------------------------------------------------------------------------------------------------------*/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function esconde( _levelId ) {
	var thisLevel = document.getElementById('pergunta'+_levelId);
	thisLevel.style.display = "none";
	}

function mostra(_levelId) {
    var nomeObjeto, nomeLinkObjeto;
 
 var thisLevel = document.getElementById('pergunta'+_levelId);
        var thisLink  = document.getElementById('linkPergunta'+_levelId);
 
 for(i=1;i<=50;i++){
  nomeObjeto = "pergunta"+i
         nomeLinkObjeto = "linkPergunta"+i;
 
  if(ObjetoExiste(document.getElementById(nomeObjeto))){
    if(i != parseInt(_levelId)){
       document.getElementById('pergunta'+i).style.display='none';
    }
  }
 
  if(ObjetoExiste(document.getElementById(nomeLinkObjeto))){
    if(i != parseInt(_levelId)){
       document.getElementById('linkPergunta'+i).className = "FonteNormal11 Negrito TextoVermelho";
    }
  }
 
 }
 if (thisLevel.style.display == "none") {
           thisLink.className="FonteNormal11 Negrito";
      thisLevel.style.display = "block";
 }
 else {
           thisLink.className="FonteNormal11 Negrito TextoVermelho";
      esconde( _levelId);
 }
   }
 
function ObjetoExiste(paramObjeto) {
   return (typeof(paramObjeto) != "undefined" && paramObjeto != null);
}
/*-------------------------------------------------------------------------------------------------------------*/
// FUNCAO BOTAO OVER
/*-------------------------------------------------------------------------------------------------------------*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*-------------------------------------------------------------------------------------------------------------*/
// ABRE POPUP
/*-------------------------------------------------------------------------------------------------------------*/
function ampliar(URL)
		{window.open(URL,'ampliar', 'width=398, height=335, top=50, left=300, scrollbars=no');
} 

function openWindow(url, name) {
	     popupWin = window.open(url,name,"width=1044,height=830,top=0,resizable=no,scrollbars=yes,statusbar=yes");
	     popupWin.location.href = url;
         if (popupWin.opener == null) popupWin.opener = self;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function AbrePopup(theURL,winName,features) {
  window.open(theURL,winName,features);
};

// <p><a href="javascript:openWindow('LINK.asp', 'Cadian', '');">TEXTO</a></p>
/*-------------------------------------------------------------------------------------------------------------*/
// ABAS
/*-------------------------------------------------------------------------------------------------------------*/
function exibeInfoDetalhadas(obj){
	if(obj != null){
		var pai =obj.parentNode;
		try{
			//filhos = cada tab
			var filhos = pai.getElementsByTagName('li');
			var tabCount=filhos.length;
			for (var i=0; i < tabCount;i++){
				try{
					if(obj.id==filhos[i].id){
						filhos[i].style.zIndex = tabCount;
						filhos[i].setAttribute('class','selected');
						filhos[i].className='selected';
					}else{
						filhos[i].style.zIndex = tabCount-(i+1);
						filhos[i].setAttribute('class','');
						filhos[i].className='';
					}
				}catch(e){
				}
			}
			obj.getElementsByTagName('a')[0].blur();
		}catch(err){}
		if(document.getElementById('InfoDetalhadas_Conteudo') != null){
			document.getElementById('InfoDetalhadas_Conteudo').innerHTML=obj.getElementsByTagName('div')[0].innerHTML;
		}
	}
	return false;
}

try{
	document.getElementsByTagName('body')[0].onload = function(){
		exibeInfoDetalhadas(document.getElementById('abaInfoDetalhadas0'));
	}
}catch(err){}
/*-------------------------------------------------------------------------------------------------------------*/
// LOJA.ASPX
/*-------------------------------------------------------------------------------------------------------------*/
function fnProdutoEsgotado(IDProduct){
	var elemEsgotado = document.getElementById('ProdutoEsgotadoDepartamento');
	if (elemEsgotado != null)
		return (elemEsgotado.innerHTML.replace('<$IDProduct$>', IDProduct));
	else
		 return '<br><div class="BotaoComprarDiv" onclick="AviseMe('+ IDProduct +');"><div class="ComprarDiv_ProdutoIndisponivel">Mais informações</div><div class="ComprarDiv_AviseMe">Consulte-nos!</div></div>';
}

function Preco(OldPrice,NewPrice,Discount,DePor,IDProduct)
{
	var Saida;
	if (DePor==2) return fnProdutoEsgotado(IDProduct);
	//Formatar a saida	
	if (DePor==0)
		Saida='<span class="preco2">R$ '+OldPrice.toString()+'</span>';
	else if (DePor==1 || DePor==3)		
		Saida='<span class="preco1">De R$ '+OldPrice.toString()+'</span><br><span class="preco2">Por R$ '+NewPrice.toString()+'</span>';
	else 
		Saida = '<span class="preco2">R$ '+NewPrice.toString()+'</span>';
	return Saida;

}

function AviseMe(IDProduct)
{
window.open('/Commerce/B2C/B2C_Controles/ProdutoEsgotado.aspx?IDProduct='+ IDProduct +'','AviseMe','width=420,height=510,scrollbars=no,menubar=no, resizable=no, status=no, toolbar=no, location=no');
}
/*-------------------------------------------------------------------------------------------------------------*/
// DETALHES.ASPX
/*-------------------------------------------------------------------------------------------------------------*/
function Avalie(IDProduct){
	window.open('/Commerce/B2C/B2C_Controles/OpineProduto.aspx?IDProduct=' + IDProduct,'OpineProduto','width=420,height=520,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');
}
/*-------------------------------------------------------------------------------------------------------------*/
// BUSCA
/*-------------------------------------------------------------------------------------------------------------*/
function PreencheDescricaoCurta() {
	var tbProdutoAvancado = document.getElementById('tbProdutoAvancado');	
	var tbDescricaoCurta = document.getElementById('tbDescricaoCurta');
	tbDescricaoCurta.value = tbProdutoAvancado.value;
}

function EnterDaPesquisa(e) {
	if(isEnter(e))
		fazBusca();	
}

function EnterDaPesquisa_Footer(e){
	if(isEnter(e))
		location.href = "http://www.intellicadian.com.br/IntelliCAD/" + nomeprodutoRodape.value;
}	

function CliqueParaPesquisa(){
	location.href = "http://www.intellicadian.com.br/IntelliCAD/" + nomeprodutoRodape.value;	
}
function Busca(formulario){
	var Componente_Busca = new componentes.busca();
	return Componente_Busca.fazBusca(formulario.prod.value,formulario.pdep.options[formulario.pdep.selectedIndex].value,formulario.pfab.options[formulario.pfab.selectedIndex].value,null,null,null);
}

function PreencheCEP(cep){
	cep = new String(cep);
	var txtCEPInicial = document.getElementById('txtCEPInicial');
	var txtCEPInicial2 = document.getElementById('txtCEPInicial2');
	if (cep.length == 8){
		txtCEPInicial.value = cep.substring(0, 2) + '.' + cep.substring(2, 5);
		txtCEPInicial2.value = cep.substring(5, 8);
		retornoCep();
	}
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";

function JSFX_FloatDiv(id, sx, sy)
{
	var el;
	try {
		el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	}catch(e){
		el= document.getElementById(id);
	}
	
	window[id + "_obj"] = el;									
	if (ns)
		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;	
}
/*-------------------------------------------------------------------------------------------------------------*/
// BOTOES / IMPRIMIR
/*-------------------------------------------------------------------------------------------------------------*/
function AumetaFonte(elem, percent){
	elem= document.getElementById(elem);
	if(elem.style.fontSize == "")
		elem.style.fontSize="100%";
	percent=(parseInt(elem.style.fontSize.replace("%",""), 10) + percent) + "%";
	elem.style.fontSize = percent;
}
function Imprimir(elem){
	var oPrint, oJan;
	elem= document.getElementById(elem);
	oPrint     = elem.innerHTML;
	oJan     = window.open("", "Imprimir", "top=9999,left=9999,width=1,height=1,scrollbars=no,menubar=no, resizable=no, status=no, toolbar=no, location=no");
	try{
		oJan.document.write(oPrint);
		oJan.history.go();
		oJan.window.print();
	}catch(err){}
	oJan.close();
}
/*-------------------------------------------------------------------------------------------------------------*/
// Realiza efeito na Central de Atendimento (HEADER)
/*-------------------------------------------------------------------------------------------------------------*/
$(document).ready(function (){
	$("#conteudo_atendimento").hide("fast");

	$("#central_Atendimento").mouseover(function(){
		$("#conteudo_atendimento").show("slow");
	});
	
	$(document).mouseout(function(){
		$("#conteudo_atendimento").hide("slow");
	});

});
/*-------------------------------------------------------------------------------------------------------------*/
// Realiza inclusão de cliente em potencial no CRM
/*-------------------------------------------------------------------------------------------------------------*/
function addLead(url, formulario, firstname, lastname, address1_line1, address1_line3, address1_line2, address1_city, address1_stateorprovince, new_address1_complemento, address1_postalcode, new_tipodoendereco, transferir){
    try{
        $.post(url, 
                {
                    cmd : "addLead"
                    ,firstname : firstname
                    ,lastname : lastname
                    ,address1_line1 : address1_line1
                    ,address1_line3 : address1_line3
                    ,address1_line2 : address1_line2
                    ,address1_city : address1_city
                    ,address1_stateorprovince : address1_stateorprovince
                    ,new_address1_complemento : new_address1_complemento
                    ,address1_postalcode : address1_postalcode
                    ,new_tipodoendereco : new_tipodoendereco
                    ,transferir: transferir
                },
			    function(resposta){
			        if (resposta != ""){
			            alert('Incluído com sucesso!');
    				    formulario.submit();
    				}else{
    				    alert('Falha ao incluír!');
    				}
			    }
		);
    }catch(err){
        alert(err.description);
    }
    return false;
}
/*-------------------------------------------------------------------------------------------------------------*/

