/****************************************************************
*	Criado em: 30/01/2007			Por: ANDRÉ LUIZ
****************************************************************/

/*# abre popUps via DOM e AJAX */
function winPopUpDOM(W, H, it_zIndex, vc_titulo, vc_url) {
	var win		= new Window({className:"alphacube", width:W, height:H, zIndex:it_zIndex, resizable:false, title:vc_titulo,  draggable:true, maximizable:false, minimizable:false, wiredDrag:true, url:vc_url, destroyOnClose:true, showEffect:Effect.SlideDown, hideEffect: Effect.SlideUp, fps:40, duration:12});
	win.showCenter(true);
	win.refresh(this);
}

/*# abre popUps via DOM e AJAX */
function winPopUpDOMSemEfeito(W, H, it_zIndex, vc_titulo, vc_url) {
	var win		= new Window({className:"alphacube", width:W, height:H, zIndex:it_zIndex, resizable:false, title:vc_titulo,  draggable:true, maximizable:false, minimizable:false, wiredDrag:true, url:vc_url, destroyOnClose:true});
	win.showCenter(true);
	win.refresh(this);
}

/*# mostra/esconde responstas das FAQs */
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';
	}
}

/*# mostra/esconde forms */
function showHideForm(vc_obj) {
	// verifica se o elemento existe
	if (document.getElementById(vc_obj)) {
		var dv_00	= document.getElementById(vc_obj);
		
		if (dv_00.style.display != 'none')
			dv_00.style.display	= 'none';
		else
			dv_00.style.display	= 'block';
		
		// reseta form
		eval('document.frm_' + vc_obj + '.reset()');
	}
}

/*# 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';
}

/*# VALIDA E-MAIL 
function verficaEmail(campo) {
	var vc_err			= '';
	
	if (campo.length != 0) {
		invalidChars	= "/:,;!?<>*&^%$#(){}|~`";
		atPos			= campo.indexOf("@",1);
		periodPos		= campo.indexOf(".",atPos);
		
		for (i=0; i<invalidChars.lenght; i++) {
			badChar		= invalidChars.charAt(i);
			
			if (campo.length.indexOf(badChar,0) > -1) {
			 	vc_err = '- O E-MAIL digitado é inválido.\n';
			}
		}
		if (atPos == -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if(campo.indexOf("@",atPos+1) > -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if (periodPos == -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if ((periodPos+3) > campo.length) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
	}
	return vc_err;
}
*/

/*# 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');
	
	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);
}

function AbrirGaleria(){
		var W = 674;
		var H = 425;
		var X = Math.ceil( (window.screen.height - H) / 2 ) - 50;
		var Y = Math.ceil( (window.screen.width - W) / 2 ) - 16;
		window.open('popup/popup/galeria.asp','galeria','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=n,scrollbars=no,resizable=no,directories=no,toolbar=no').focus();
}

function AbrirMural(){
		var W = 674;
		var H = 425;
		var X = Math.ceil( (window.screen.height - H) / 2 ) - 50;
		var Y = Math.ceil( (window.screen.width - W) / 2 ) - 16;
		window.open('popup/popup/mural.asp','mural','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=n,scrollbars=no,resizable=no,directories=no,toolbar=no').focus();
	
}

function popVoucher(){
	
	
}

function AdquiraRepresentantes(){
		var W = 695;
		var H = 425;
		var X = Math.ceil( (window.screen.height - H) / 2 ) - 50;
		var Y = Math.ceil( (window.screen.width - W) / 2 ) - 16;
		window.open('popup/adquira/adquira.asp','adquira','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=n,scrollbars=yes,resizable=no,directories=no,toolbar=no').focus();	
}

function EnviarContato(nome, cidade, universidade, email, ddd, telefone, mensagem){
	codigo.location.href = "contato.asp?fnome="+nome+"&fcidade="+cidade+"&funiversidade="+universidade+"&femail="+email+"&fddd="+ddd+"&ftelefone="+telefone+"&fmensagem="+mensagem;
}

function preencheCidade(vc_estado,vc_cidade_selec) {
	
	var tempIFrame					= document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_refresh');
	tempIFrame.setAttribute('name','iframe_refresh');

	tempIFrame.style.border			='0px';
	tempIFrame.style.width			='0px';
	tempIFrame.style.height			='0px';
	tempIFrame.style.display		='none';
	
	tempIFrame.setAttribute('src','../codigos/cidade.asp?vc_estado='+vc_estado+'&vc_cidade='+vc_cidade_selec);
	IFrameObj						= document.body.appendChild(tempIFrame);
	
	//Limpa as informações no combo página
	var selec						= eval('document.getElementById("vc_cidade")');

	for (var x = selec.length; x >= 0; x--) 
	{
		selec.options[x]	= null;
	}	

	selec.options[0] = new Option('Carregando...', '0');
	
}

function preenchePagina(vc1,vc_cidade_selec) {

	var array_cidade			= vc1.split("|");
//	var array_nome 				= nome.split("|");
	var selec					= eval('document.getElementById("vc_cidade")');

	
	if (vc1.length != 0) 
	{
		/*#LIMPAR CAIXA#*/
	
		for (var x = selec.length; x >= 0; x--) 
		{
			selec.options[x]	    = null;
		}	
		
		/*#INSERE NOVOS#*/
		var n = 1;
		selec.options[0] 		= new Option('Selecione a opção', '0');


		// Carrega combo pagina
		for (var t = 0; t < (array_cidade.length)-1 ; t++) 
		{
			selec.options[n] 	     = new Option(array_cidade[t], array_cidade[t]);
			//Verifica qual das cidades que retornar ficará selecionada
			if (vc_cidade_selec.toLowerCase() == array_cidade[t].toLowerCase()) {
					selec.options[n].selected = true;
			}
			n++;
		}
				
	}	
	else	
	{
		selec.options[0] 	    = new Option('Selecione a opção', '0');	
	}

}

function pesquisa(vc_estado, vc_cidade) {
	location.href = "adquira.asp?estadoVC="+vc_estado+"&cidadeVC="+vc_cidade;
}


function atendimento(id_filial,bt){
	var current 	= document.getElementById(id_filial);
	var current1 	= document.getElementById(bt);
	if(current.style.display == 'none'){
		current.style.display 		= 'block';
	}
	else{
		current.style.display 		= 'none';
	}
}

