/****************************************************************
*	Criado em: 30/01/2007			Por: ANDRÉ LUIZ
****************************************************************/



/*#ONLOAD#*/
window.name = 'dm_browser';




/*# iFrame virtual [ crossBrowser ] #*/
function iframeVirtual(vc_url) {
	// pega iframeVirtual pelo ID ou cria um iframeVirtual caso ñ exista
	var tempIFrame = (document.getElementById('iframe_virtual')) ? document.getElementById('iframe_virtual') : document.createElement('iframe');
	
	tempIFrame.style.border		= '0px';
	tempIFrame.style.width		= '0px';
	tempIFrame.style.height		= '0px';
	
	tempIFrame.setAttribute('id','iframe_virtual');
	tempIFrame.setAttribute('name','iframe_virtual');
	tempIFrame.setAttribute('src',vc_url);
	
	IFrameObj		= document.body.appendChild(tempIFrame);
}


/***********************************************************************
*		B A N N E R S 
***********************************************************************/

/*# BANNER #*/
function bannerCount(bannerID) {
	vc_url ='codigos/banner.asp?bannerID='+bannerID;
	iframeVirtual(vc_url);
	//window.location=vc_url
}


/*# VERIFICA DATA #*/
function verificaData(vc_campo) { 
	if (vc_campo.value.length > 0) {  
		it_dia		= (vc_campo.value.substring(0,2)); 
		it_mes		= (vc_campo.value.substring(3,5)); 
		it_ano		= (vc_campo.value.substring(6,10)); 
		it_erro		= 0; 
		
		if ((it_dia < 01) || (it_dia < 01 || it_dia > 30) && (it_mes == 04 || it_mes == 06 || it_mes == 09 || it_mes == 11 ) || it_dia > 31) { 
			it_erro	= 1; 
		} 

		if (it_mes < 01 || it_mes > 12 ) { 
			it_erro	= 1; 
		} 

		if (it_mes == 2 && (it_dia < 01 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) { 
			it_erro	= 1; 
		} 

		if ((it_ano < 1900) || (it_ano>2078)){
			it_erro	= 1;
		}
		
		if (it_erro == 1) { 
			alert("Por favor, preencha uma data válida!"); 
			vc_campo.value	= '';
			vc_campo.focus(); 
		}
	} 
}


function centralizar(){
			
			var it_largura
	
			window.status = document.body.clientWidth;
		
			if(document.body.clientWidth>991){
				
				if(document.getElementById('id_lista_vitrine')){
			
				document.getElementById('id_lista_vitrine').style.width = (document.body.clientWidth-225) + 'px';	
				
				}
				
				if(document.all){it_largura =  (document.body.clientWidth-228) + 'px';}else{it_largura =  (document.body.clientWidth-233) + 'px';}

				if(document.getElementById('ul_produto')){
					document.getElementById('ul_produto').style.width = it_largura;												
				}
				
			}else{
				
				if(document.getElementById('id_lista_vitrine')){
				
					document.getElementById('id_lista_vitrine').style.width = 770 + 'px';
				}
				
				if(document.all){it_largura =  768 + 'px';}else{it_largura =  764 + 'px';}
				
				if(document.getElementById('ul_produto')){
					document.getElementById('ul_produto').style.width = it_largura;	
				}
			}	
			
}

/*# mostra/esconde responstas das FAQs 
	Exemplo do HTML a ser utilizado com essa função

	<div class="dv_05"><span>+&nbsp;</span>
		<a class="lk_03" name="lk_duvida" href="javascript: void(0);" onclick="javascript: showHideDuvida(this);" title="<%=vc_pergunta%>"><%=vc_pergunta%></a>
		<span class="dv_05" style="display:none">
			<%=vc_pergunta_resposta%>
	</span></div><%
*/
function showHideDuvida(objLink){
	var vc_display						= new String(objLink.parentNode.lastChild.style.display);
	var vc_display_original				= new String(vc_display);
	var objContainer					= objLink.parentNode.lastChild.style;
	var objSinal						= objLink.parentNode.firstChild;
	var ar_links						= document.getElementsByName('lk_duvida');
	
	// fecha todas as perguntas abertas
	for (var i = 0; i < ar_links.length; i++){
		if(typeof(ar_links[i]) == 'object'){
			with(ar_links[i].parentNode){
				lastChild.style.display	= 'none';
				firstChild.innerHTML	= '+&nbsp;';
			}
		}
	}
	
	// exibe a resposta da pergunta clicada
	if(vc_display_original == 'block'){
		objContainer.display			= 'none';
		objSinal.innerHTML				= '+&nbsp;';
	} else {
		objContainer.display			= 'block';
		objSinal.innerHTML				= '&minus;&nbsp;';
	}
}
/*function showHideResposta(vc_obj) {
	// verifica se o elemento existe
	if (document.getElementById(vc_obj)) {
		var obj_detalhe	= document.getElementById(vc_obj);
		
		if (obj_detalhe.style.display != 'none')
			obj_detalhe.style.display	= 'none';
		else
			obj_detalhe.style.display	= 'inline';
	}
}*/

/*# VALIDA E-MAIL [expressão regular] */
function verficaEmail(campo) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo)) {
		return	'';
	}
	return '- O E-MAIL digitado é inválido.\n';
}

function verificaBusca(){
	
	var mensagem1		= 'ATENÇÃO!\n\n';
	var mensagem2		= '';
	var form			=	document.getElementById('frmBusca');
	var LowerTermoVC	= 	form.termoVC.value.toLowerCase(); 
	
	if(form.termoVC.value.length <= 2){
		mensagem2	+= '- Digite alguma palavra com no mínimo 2 caracteres.\n';
	}
	else if	(LowerTermoVC.indexOf("<") > -1  || LowerTermoVC.indexOf(">") > -1  || LowerTermoVC.indexOf("_") > -1 || LowerTermoVC.indexOf("%3c") > -1  || LowerTermoVC.indexOf("%3e") > -1 || LowerTermoVC.indexOf("%") > -1 || LowerTermoVC.indexOf("insert") > -1 || LowerTermoVC.indexOf("update") > -1 || LowerTermoVC.indexOf("delete") > -1 || LowerTermoVC.indexOf("declare") > -1 || LowerTermoVC.indexOf("sysobjects") > -1 || LowerTermoVC.indexOf("drop") > -1 || LowerTermoVC.indexOf("select") > -1 || LowerTermoVC.indexOf("alert") > -1 || LowerTermoVC.indexOf("(") > -1 || LowerTermoVC.indexOf(")") > -1){
		mensagem2	+= '- O texto de busca possui caracter(s) inválido(s)!\nPor favor remova-o(s) e tente novamente.';
	}
	
	
	if (mensagem2 != ''){
		alert(mensagem1 + mensagem2);
		return false;
	} else {
		return true
	}
	

}

/*# aceita só números digitados num campo */
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	
	if((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9)
		return true;
	else
		return false;
}

/*# MASCARA */
function mascarar(vc_campo,vc_mascara) {
	var i		= vc_campo.value.length;
	var x		= vc_mascara.substring(0,1);
	var y		= vc_mascara.substring(i);
	
	if (y.substring(0,1) != x) {
		vc_campo.value += y.substring(0,1);
	}
}

/*# VERIFICA DATA #
function verificaData(vc_campo) { 
	if (vc_campo.value.length > 0) {  
		it_dia		= (vc_campo.value.substring(0,2)); 
		it_mes		= (vc_campo.value.substring(3,5)); 
		it_ano		= (vc_campo.value.substring(6,10)); 
		it_erro		= 0; 
		
		if ((it_dia < 01) || (it_dia < 01 || it_dia > 30) && (it_mes == 04 || it_mes == 06 || it_mes == 09 || it_mes == 11 ) || it_dia > 31) { 
			it_erro	= 1; 
		} 

		if (it_mes < 01 || it_mes > 12 ) { 
			it_erro	= 1; 
		} 

		if (it_mes == 2 && (it_dia < 01 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) { 
			it_erro	= 1; 
		} 

		if ((it_ano < 1900) || (it_ano>2078)){
			it_erro	= 1;
		}
		
		if (it_erro == 1) { 
			alert("Por favor, preencha uma data válida!"); 
			vc_campo.value	= '';
			vc_campo.focus(); 
		}
	} 
}
*/

/*# iFrame virtual [ crossBrowser ] #*/
function iframe_virtual(vc_url) {
	// pega iframeVirtual pelo ID ou cria um iframeVirtual caso ñ exista
	var tempIFrame		= (document.getElementById('iframe_virtual')) ? document.getElementById('iframe_virtual') : document.createElement('iframe');
	
	with(tempIFrame) {
		style.border	= '0px';
		style.width		= '0px';
		style.height	= '0px';
	
		setAttribute('id','iframe_virtual');
		setAttribute('name','iframe_virtual');
		setAttribute('src',vc_url);
	}
	
	IFrameObj		= document.body.appendChild(tempIFrame);
}


/*# Alternativa ao getElementsByName [ apenas p/ o IE ] */
function getElementsByNameIE(vc_tag, vc_name) {
	var ar_elem		= document.getElementsByTagName(vc_tag);
	var ar_retorno	= new Array();
	var vc_atributo	= new String();
	
	for(i = 0, iarr = 0; i < ar_elem.length; i++) {
		vc_atributo = ar_elem[i].getAttribute('name');
		
		if(vc_atributo == vc_name) {
			ar_retorno[iarr] = ar_elem[i];
			iarr++;
		}
	}
	
	return ar_retorno;
}


/************************************************************************
*	MascaraMoeda CROSSBROWSER				ANDRÉ LUIZ					*
*																		*
*	Exemplo de chamada:		mascaraMoeda(this.value, this.id, event);	*
*************************************************************************/
function mascaraMoeda(valor,cx,evtKeyPress) {
	if (valor) {
		var doc     = eval('document.getElementById("'+cx+'")');
		var nTecla	= (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
		
		if (nTecla == 110 || nTecla == 188 || nTecla == 190 || nTecla == 194) {
			return false;
		} else {
			valor		= mascararCentavo(valor);
		
			if (mascararCentavo(valor).length > 2) {
				str			= valor.replace(".", "");
				doc.value	= str.substr(0,(str.length-2)) + "." + str.substr((str.length-2),str.length);
			} else {
				valor		= mascararCentavo(valor);
				
				if (valor.length == 1) {
					doc.value	= "0.0" + valor;
				} else {
					doc.value	= "0." + valor;
				}
			}
		}
	}
}
	
function mascararCentavo(mn_valor) {
	if (mn_valor.indexOf('0') == 0) {
		mn_valor	= mn_valor.replace('0.','');
		mn_valor	= mn_valor.replace('0.0','');
	}
	
	mn_valor	= mn_valor.replace('.','');
	
	return		mn_valor;
}


/*# alternativa ao getElementsByName [ APENAS P/ IE ] */
function getElementsByNameIE(vc_tag, vc_name) {
	var ar_elem		= document.getElementsByTagName(vc_tag);
	var ar_retorno	= new Array();
	var vc_atributo	= new String();
	
	for(i = 0, iarr = 0; i < ar_elem.length; i++) {
		vc_atributo = ar_elem[i].getAttribute('name');
		
		if(vc_atributo == vc_name) {
			ar_retorno[iarr] = ar_elem[i];
			iarr++;
		}
	}
	
	return ar_retorno;
}

/*# abre popUp */
function popUp(vc_url, W, H) {
	var W	= (W) ? parseInt(W) : parseInt(window.screen.width * 0.7);
	var H	= (H) ? parseInt(H) : parseInt(window.screen.height * 0.7);
	var X	= Math.ceil((window.screen.height - H) / 2);
	var Y	= Math.ceil((window.screen.width - W) / 2);
	
	window.open(vc_url, 'ap_select', 'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no').focus();
}

/**/

function mascaraSelect(id){
	var current	= document.getElementById('mascDepartamento');
	var obj 	= document.getElementById(id);
	var indice	= obj.options.selectedIndex;
	var texto	= obj.options[indice].text;
	current.value = texto;
}

/* Muda a Cor do fundo do campo quando tiver em focus e blur */
function setBg(campo,cor){
	var current	= document.getElementById(campo);
	current.style.backgroundColor = cor;
}

function validaNews(nivel){
	
	
	
	var form		= document.getElementById('frmNews');
	var vc_erro		= new String();
	var vc_foco		= 0;
	
	if (form.contatoVC.value.length == 0){
	 	vc_erro		+= '- Digite o NOME.\n';
		if(vc_foco == 0) {
			vc_foco = form.contatoVC;
		}
	}
	
	if (form.emailVC.value.length != 0){
		vc_erro	+= verficaEmail(form.emailVC.value);
		if(vc_foco == 0) {
			vc_foco = form.emailVC;
		}
	}else{
		vc_erro	+= '- Digite o E-MAIL.\n';
		if(vc_foco == 0) {
			vc_foco = form.emailVC;
		}
	}
	
	
	
	if (vc_erro.length == 0) {	
			if (nivel.length > 0 ){
				vc_url = nivel +'codigos/newsletter.asp'				
				iframe_upload('frmNews',vc_url,'divTemp','','')		
			}else{
				iframe_upload('frmNews','codigos/newsletter.asp','divTemp','','')		
			}
			
	} else {
		alert('ATENÇÃO!\n\n' + vc_erro);
		if (vc_foco != 1 && vc_foco != 0){
			vc_foco.focus();
		}
		
		return false;
		
	}
}


function iframe_upload(form,url_action,id_elemento_retorno,html_exibe_carregando,html_erro_http){
	
	/* Versão: 1.0 - 03/03/2007 - Testado no FF2.0 IE6.0 e OP9.1
	* Autor: Micox - Náiron JCG - elmicox.blogspot.com - micoxjcg@yahoo.com.br
	* Parametros:
	* form - o form a ser submetido ou seu ID
	* url_action - url pra onde deve ser submetido o form
	* id_elemento_retorno - id do elemento que irá receber a informação de retorno
	* html_exibe_carregando - Texto (ou imagem) que será exibido enquanto se carrega o upload
	* html_erro_http - texto (ou imagem) que será exibido se der erro HTTP.
	*******/
	
	 form = typeof(form)=="string"?document.getElementById(form):form;
	 
	 var erro="";
	 if(form==null || typeof(form)=="undefined"){ erro += "O form passado no 1o parâmetro não existe na página.\n";}
	 else if(form.nodeName!="FORM"){ erro += "O form passado no 1o parâmetro da função não é um form.\n";}
	 if(document.getElementById(id_elemento_retorno)==null){ erro += "O elemento passado no 3o parâmetro não existe na página.\n";}
	 if(erro.length>0) {
	  alert("Erro ao chamar a função iframe_upload:\n" + erro);
	  return;
	 }
	
	 

	 
	 var iframe = document.createElement("iframe");
	 iframe.setAttribute("id","iframe-temp");
	 iframe.setAttribute("name","iframe-temp");
	 iframe.setAttribute("width","0");
	 iframe.setAttribute("height","0");
	 iframe.setAttribute("border","0");
	 iframe.setAttribute("style","width: 0; height: 0; border: none;");
	 form.parentNode.appendChild(iframe);
	 window.frames['iframe-temp'].name="iframe-temp"; //ie sucks
	 
	/* var carregou = function() { 
	   removeEvent( document.getElementById('iframe-temp'),"load", carregou);
	   var cross = "javascript: ";
	   cross += "window.parent.document.getElementById('" + id_elemento_retorno + "').innerHTML = document.body.innerHTML; void(0); ";
	   
	   document.getElementById(id_elemento_retorno).innerHTML = html_erro_http;
	   document.getElementById('iframe-temp').src = cross;
	   
	   setTimeout(function(){ remove(document.getElementById('iframe-temp'))}, 250);
	  }
	 addEvent( document.getElementById('iframe-temp'),"load", carregou)*/
	 
	 form.setAttribute("target","iframe-temp");
	 form.setAttribute("action",url_action);
	 form.setAttribute("method","post");
	// form.setAttribute("enctype","multipart/form-data");
	// form.setAttribute("encoding","multipart/form-data");
	 
	 form.submit();
	 
	 if(html_exibe_carregando.length > 0){
	  document.getElementById(id_elemento_retorno).innerHTML = html_exibe_carregando;
	 }
	 
}


function validaBusca(){
	var form		= document.getElementById('frmBusca');
	var vc_erro		= new String();
	var vc_foco		= 0;
	
	if (form.termoVC.value.length == 0 || form.termoVC.value == 'Digite aqui a sua busca'){
	 	vc_erro		+= '- Digite uma palavra chave para pesquisar!\n';
		if(vc_foco == 0) {
			vc_foco = form.termoVC;
		}
	}
	
	if (vc_erro.length == 0) {
		return true;
	} else {
		alert('ATENÇÃO!\n\n' + vc_erro);
		if (vc_foco != 1 && vc_foco != 0){
			vc_foco.focus();
		}
		return false;
	}
}

/*# GET RADIO VALUE  #*/
function get_radio_value (radio_array){
	var i;
	for (i = 0; i < radio_array.length; ++ i)	
		if (radio_array [i].checked)
		return radio_array [i].value;
	return null;
}

/*# TRIM - Função que verifica se há espaços no início e fim de uma string, semelhante ao trim #*/
function trim(vc_string) {
 
  //Remove os espaços do Inicio
  while ((vc_string.substring(0,1) == ' ') || (vc_string.substring(0,1) == '\n') || (vc_string.substring(0,1) == '\r')) {
    vc_string = vc_string.substring(1,vc_string.length);
  }
 
  //Remove os espaços do Final
  while ((vc_string.substring(vc_string.length-1,vc_string.length) == ' ') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\n') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\r')) {
    vc_string = vc_string.substring(0,vc_string.length-1);
  }
 
 return vc_string;
}


/***********************************************************************
*		N E W S L E T T E R 
***********************************************************************/

/*# VERIFICAR #*/
function newsletterVerificar() {
	vc_erro		= '';
	
	if (trim(document.getElementById('newsletterFRM').contatoVC.value).length == 0){
		vc_erro	= vc_erro + '- Digite o NOME.\n';		
	}
	
	if (trim(document.getElementById('newsletterFRM').emailVC.value).length == 0) {
		vc_erro	= vc_erro + '- Digite o E-MAIL.\n';		
	} else {
		vc_erro	= vc_erro + verficaEmail(document.getElementById('newsletterFRM').emailVC.value);
	}
	
	if (vc_erro.length == 0) {
		document.getElementById('newsletterFRM').submit();
		return true;
	} else {
		alert('ATENÇÃO!\n\n' + vc_erro);
		return false;
	}
}

function v4(site,largura,altura,atributo){
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+largura+"' height='"+altura+"'>");
   document.write("<param name='movie' value='"+site+"'>");
   document.write("<param name='quality' value='high'>");
   document.write("<param name='menu' value='false'>");
   document.write("<param name='wmode' value='transparent'>");
   document.write(" <param name='scale' value='noscale' />");
   if (atributo == ""){ 
	    document.write("<embed src='"+site+"' wmode='transparent'  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+largura+"' height='"+altura+"' ></embed>");

   }else{
   document.write(" <PARAM NAME=FlashVars VALUE= '"+atributo+"'>");
   document.write("<embed src='"+site+"' wmode='transparent'  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+largura+"' height='"+altura+"' FlashVars= '"+atributo+"'></embed>");	   
   
   }
   document.write("</object>");
}
