/** ---------------- VARIÁVEIS --------------------------------- */
	var cfg_url = "";
	
	var g_id = null;
	
	function cfg_execScript(i_script,i_tempo){
		if(i_tempo==null)
			i_tempo = 0;			
		setTimeout(i_script,i_tempo * 1000);	
	}
	
	function printId(i_id,i_msg){
		g_id = window.document.getElementById(""+i_id);
		
		if(i_msg==0){
			g_id.innerHTML = "";
			return;
		}
		
		g_id.style.border = "1px blue solid";
		g_id.style.width = 319;
		g_id.style.height = "auto";
		g_id.style.background = "url("+cfg_url+"/img/ewgec/caixa_dialogo.png)";
		
		i_msg = i_msg.replace(/[\n]+/g,"<br>");
		//i_msg = i_msg.replace("\n","<br>");
		
		i_msg = "<table width=100% height=100%><tr><td style='font-size:11px; color:#ffffff;font-weight:bold;'>Mensagem do Sistema:</td><td width=20 align=right height=22><a href='javascript:resetMsg()' style='text-decoration:none'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>" +
				"<tr><td colspan=2 style='padding-left:10px; font-size:11px;'>"+i_msg+"</td></tr>" +
				"<tr><td colspan=2 align=center height=22><button id='bt_ok' style='width:60px;font-size:11px;' onclick='resetMsg()'>OK</button></td></tr></table>";;
		
		g_id.innerHTML = i_msg+"";
		
		o_bt = window.document.getElementById("bt_ok").focus();
		
				
		if(navigator.appName.indexOf("Netscape")!= -1){
  			g_id.style.top = (window.innerHeight - 100)/2;
			g_id.style.left = (window.innerWidth - 319)/2;
        }else{
        	g_id.style.top = (screen.availHeight - 200)/2;
			g_id.style.left = (screen.availWidth - 319)/2;
		}
		
		setTimeout("resetMsg()",30000);	
		
	}
	
	function resetMsg(i_div){
		var o_id = g_id;
		
		if(i_div != null){
			o_id = window.document.getElementById(i_div);
		}
		
		if(o_id != null){
			o_id.innerHTML 		= "";
			o_id.style.border 	= "0px";
			o_id.style.width 	= 0;
			o_id.style.height 	= 0;
			o_id.style.background = "";
			o_id = null;
		}
	}
	
	function alertMsg(i_msg,i_id){
		if(i_msg != ""){
			if(i_id){
				printId(""+i_id,i_msg);				
			}else{
				alert(""+i_msg);
			}
		}
	}
	
	function maximizar(){
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth,screen.availHeight);
	}
	
	function cfg_abrirPopup(i_pop_id){
		var windowOptions = "history=no,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=no,resizable=yes,width=10,height=10, top=0, left=0";
		var j_pop1 = window.open(cfg_url + "/src/site/popup.php?popid="+i_pop_id, "j_pop"+i_pop_id, windowOptions);
		window.focus();
	}
	
	function cfg_abrirBanner(i_id,i_link,i_pop_img,i_posicao,i_w,i_h){
		
		var o_id = window.document.getElementById("div_banner");
		o_id.innerHTML += "<div id='div_banner"+i_id+"' style='position:absolute; top:0; left:0;'></div>";
		
		g_id = window.document.getElementById("div_banner"+i_id);
		
		o_x = 0;
		o_y = 10;
		
		switch(i_posicao){
			case "A" : 
				break;
			case "B" : 
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "C" :
					o_x = (screen.availWidth - i_w)-25-6; 
				break;
			case "D" :
					o_y = ((screen.availHeight - i_h)/2)-80;					
				break;
			case "E" :
					o_y = ((screen.availHeight - i_h)/2)-80;
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "F" :
					o_y = ((screen.availHeight - i_h)/2)-80;
					o_x = (screen.availWidth - i_w)-25-6; 
				break;
			case "G" :					
					o_y = ((screen.availHeight - 170 - i_h ));
				break;
			case "H" :
					o_y = ((screen.availHeight - 170 - i_h ));
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "I" :
					o_y = ((screen.availHeight - 170 - i_h ));
					o_x = (screen.availWidth - i_w)-25-6;  
				break;
		}
		
		//g_id.style.border = "1px blue solid";
		g_id.style.width  = i_w+10;
		g_id.style.height = 'auto';//i_h;
		//g_id.style.background = "#ffffff";
		
		g_id.style.top  = (o_y);
		g_id.style.left = (o_x);
		
		var o_banner = "<p style='text-align:right; margin:0px; font-size:10px;'><a href='javascript:resetMsg(\"div_banner"+i_id+"\");' style='font-size:11px; padding-left:10px; padding-right:10px; font-family:arial; color:#FFFFFF; font-weight:bold;text-decoration:none; background:#FFA63D;'>FECHAR</a></p>";

		o_banner += "<div style='padding:3px;100%;height:100%;background:#ffffff;border:2px #FFA63D solid'>";
		
		if(i_link != "")
			o_banner += "<a href='"+i_link+"' target='_self'><img src='"+cfg_url+"/img/upload/"+i_pop_img+"' border=0></a>";
		else
			o_banner += "<img src='"+cfg_url+"/img/upload/"+i_pop_img+"'>";
		
		o_banner += "</div>";
		
		g_id.innerHTML = o_banner;
		
		setTimeout("resetMsg('div_banner"+i_id+"')",180 * 1000);
	}
	
	function cfg_focalizar(i_temp){
		setTimeout("window.focus();",(i_temp * 1000));
	}
	
	function cfg_posicionarJanela(i_posicao,i_w,i_h){		
		o_x = 0;
		o_y = 0;
		
		switch(i_posicao){
			case "A" : 
				break;
			case "B" : 
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "C" :
					o_x = (screen.availWidth - i_w); 
				break;
			case "D" :
					o_y = (screen.availHeight - i_h)/2;					
				break;
			case "E" :
					o_y = (screen.availHeight - i_h)/2;
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "F" :
					o_y = (screen.availHeight - i_h)/2;
					o_x = (screen.availWidth - i_w);
				break;
			case "G" :
					o_y = (screen.availHeight - i_h);	
				break;
			case "H" :
					o_y = (screen.availHeight - i_h);
					o_x = (screen.availWidth - i_w)/2;
				break;
			case "I" :
					o_y = (screen.availHeight - i_h);
					o_x = (screen.availWidth - i_w); 
				break;
		}
		
		window.moveTo(o_x,o_y);
		//window.resizeTo(screen.availWidth,screen.availHeight);
		window.resizeTo(i_w,i_h);
		
	}
	
	function cfg_votarEnquete(i_id_enquete,i_id_resposta){
		var o_w = 250;
		var o_h = 250;
		var o_id = window.document.getElementById("div_banner");
		o_id.innerHTML += "<div id='div_banner"+i_id_enquete+"' style='position:absolute; top:0; left:0;'></div>";		
		g_id = window.document.getElementById("div_banner"+i_id_enquete);
		
		g_id.style.width  = o_w;
		g_id.style.height = "auto";
		g_id.style.border = "2px #cacaca solid";
		g_id.style.background = "#aaaaaa";		
		g_id.style.top  = 0;//(screen.availHeight - o_h)/2;
		g_id.style.left = 0;//(screen.availWidth - o_w)/2;
		
		var o_pergunta = document.form_enquete.enq_pergunta.value;
		
		var o_html = "<p style='text-align:right; margin:0px; font-size:10px;'><a id='topo' href='javascript:resetMsg(\"div_banner"+i_id_enquete+"\");' style='color:red; font-weight:bold;text-decoration:none; background:#aaaaaa'>Fechar</a></p>";		   
	    o_html += "<iframe height="+o_h+" width="+o_w+" frameborder=0 src='"+cfg_url+"/src/site/enquete.php?enq_id="+i_id_enquete+"&res_id="+i_id_resposta+"&enq_pergunta="+o_pergunta+"'>";
		g_id.innerHTML = o_html;
		topo.focus();
	}
	
	var g_exibe_senha_web = false;
	function emp_abrirCampoSenhaWeb(){
		g_exibe_senha_web = !g_exibe_senha_web;
		var o_id = window.document.getElementById("id_senha_web");
		if(g_exibe_senha_web){
			document.form_emprego.acao.value = "AutenticarECarregarDados";
			document.form_emprego.quero_aualizar.checked = true;
			o_id.innerHTML += "<br><center><b>Digite sua senha</b> (mesma de ART On-line):<br><input type=password onKeyUp=\"document.form_emprego.web_senha.value = this.value;\" title='Use a senha da ART-Online'></center><br><a href='/creaweb/scripts/cadastro.php'> > Clique aqui para cadastrar sua senha de ART On-line</a><br><a href='/src/site/art_recuperarSenha.php'>> Esqueci minha senha</a>";
		}else{
			document.form_emprego.acao.value = "Autenticar";
			document.form_emprego.quero_aualizar.checked = false;
			o_id.innerHTML = "";
		}
	}
	
	function validarCNPJ(CNPJ) {
              //CNPJ = document.validacao.cnpj.value;
              var erro = new String;
              if (CNPJ.length < 18) erro = "CNPJ inválido!";
              if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
              if (erro.length == 0) erro = "CNPJ inválido!";
              }
              //substituir os caracteres que não são números
              if(document.layers && parseInt(navigator.appVersion) == 4){
                      x = CNPJ.substring(0,2);
                      x += CNPJ. substring (3,6);
                      x += CNPJ. substring (7,10);
                      x += CNPJ. substring (11,15);
                      x += CNPJ. substring (16,18);
                      CNPJ = x;
              } else {
                      CNPJ = CNPJ. replace (".","");
                      CNPJ = CNPJ. replace (".","");
                      CNPJ = CNPJ. replace ("-","");
                      CNPJ = CNPJ. replace ("/","");
              }
              var nonNumbers = /\D/;
              if (nonNumbers.test(CNPJ)) erro = "CNPJ inválido!";
              var a = [];
              var b = new Number;
              var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
              for (i=0; i<12; i++){
                      a[i] = CNPJ.charAt(i);
                      b += a[i] * c[i+1];
}
              if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
              b = 0;
              for (y=0; y<13; y++) {
                      b += (a[y] * c[y]);
              }
              if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
              if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                      erro = "CNPJ inválido!";
              }
              if (erro.length > 0){
                      alert(erro+"\nVerifique também o formato '00.000.000/0000-00'.");
                      return false;
              }
              return true;
      }
      
      function validarCpf(i_cpf) { //return true;
		
		//--- Retirando ponto(.) e hifen(-) do CPF
		i_cpf = i_cpf.substring(0,3)+i_cpf.substring(4,7)+i_cpf.substring(8,11)+i_cpf.substring(12,14);		
		
		valor = true;
		erro = new String;
		if (i_cpf.length < 11) erro += "O CPF deve conter 11 dígitos! \n\n";
		var nonNumbers = /\D/;
		if (nonNumbers.test(i_cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
		if (i_cpf == "00000000000" || i_cpf == "11111111111" || i_cpf == "22222222222" || i_cpf == "33333333333" || i_cpf == "44444444444" || i_cpf == "55555555555" || i_cpf == "66666666666" || i_cpf == "77777777777" || i_cpf == "88888888888" || i_cpf == "99999999999"){
			  erro += "Número de CPF inválido!"
		}
		var a = [];
		var b = new Number;
		var c = 11;
		for (i=0; i<11; i++){
			a[i] = i_cpf.charAt(i);
			if (i < 9) b += (a[i] *  --c);
		}
		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		b = 0;
		c = 11;
		for (y=0; y<10; y++) b += (a[y] *  c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((i_cpf.charAt(9) != a[9]) || (i_cpf.charAt(10) != a[10])){
			erro +="Verique o número do CPF!";
		}
		
		if (erro.length > 0){
			//alert(erro);
			alert("CPF inválido!\n-Verifique o formato: xxx.xxx.xxx-xx");
			return false;
		}
		return true;
	}

/** --------- MAVEL CONSÓRCIO ENVIAR CONTATO ------------ */

	function validarFormMavel(){
		var o_msg 	= "";
		var f 		= document.form_mavel_consorcio;
		var fbd 	= document.form_mavel_consorcio_bd;
				
		fbd.mav_nome.value = f.mav_nome.value;
		if(f.mav_nome.value == ""){
			o_msg += "- Nome\n";
		}
		
		fbd.mav_num_crea.value = f.mav_num_crea.value;
		if(f.mav_num_crea.value == ""){
			//o_msg += "- Nº do CREA\n";
		}
		
		fbd.mav_empresa.value = f.mav_empresa.value;
		if(f.mav_empresa.value == ""){
			//o_msg += "- Empresa\n";
		}
		
		fbd.mav_email.value = f.mav_email.value;
		if(f.mav_email.value == ""){
			//o_msg += "- E-mail\n";
		}
		
		fbd.mav_fone.value = f.mav_fone.value;
		if(f.mav_fone.value == ""){
			o_msg += "- Telefone de contato\n";
		}
		
		fbd.mav_data_visita.value = f.mav_data_visita.value;
		if(f.mav_data_visita.value == ""){
			//o_msg += "- Data\n";
		}
		
		fbd.mav_horario_visita.value = f.mav_horario_visita.value;
		if(f.mav_horario_visita.value == ""){
			//o_msg += "- Horário\n";
		}
				
		return o_msg;
		
	}
	
	function enviarEmailMavel(){
		var o_msg = validarFormMavel();		
		if(o_msg == ""){
			
			var f 	= document.form_mavel_consorcio;
			var fbd = document.form_mavel_consorcio_bd;
						
			//--- Para BD
			g_target = "mavel_bd";
			abrirPopup(cfg_url+"/src/mavel_consorcio/inserirBd.php",200,20);
			fbd.submit();			
			
			g_target = "mavel_email";
			abrirPopup("http://www1.ewsite.net/mavel_consorcio/",400,350);			
			f.submit();
			f.reset();
			
		}else{
			alert("Verifique os campos: \n"+o_msg);
		}
		return false;
	}
	
	function ew_enviarEmail(){
		var f_email = document.ew_form;
		g_target = "ew_email";
		//abrirPopup("http://www.ewsite.net/_email.php",400,350);
		f_email.submit();
		setTimeout("ew_voltar()",3000);
		//alert("ok");	
	}
	
	function ew_voltar(){
		window.location = "?";
		//alert("ok");
	}
	
	
	function abrirPopup2(i_url,i_width,i_height,i_options){
		/*var windowOptions = "history=no,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=no,resizable=yes,width="+i_width+",height="+i_height+", top=50, left=50";
		var j_pop2 = window.open(i_url,"j_pop2", windowOptions);
		j_pop2 window.focus();*/
		
		var windowOptions = "history=no,toolbar=0,location=0,directories=0,status=no,menubar=1,scrollbars=no,resizable=yes,width="+i_width+",height="+i_height+", top=0, left=0";
		if(i_options){
			windowOptions = i_options+",history=no,toolbar=0,location=0,directories=0,width="+i_width+",height="+i_height+", top=0, left="+( (screen.availWidth - i_width )/ 2 );
		}
		var j_pop1 = window.open(i_url, "j_pop", windowOptions);
		j_pop1.window.focus();
		j_pop1.window.status = ' ';
		
	}
	
	// Função que auto completa CGC.
	function CompleteCGC(campo) {
	
		var cgc = campo.value;
	
		if(cgc.length == 2 || cgc.length == 6)	{campo.value += '.';}
		if(cgc.length == 10)					{campo.value += '/';}
		if(cgc.length == 15)					{campo.value += '-';}
	}
	
	function completeCPF(e,campo) {//--- Chame onkeydown="return completeCPF(event,this);"
	
		navegador = /msie/i.test(navigator.userAgent);
		if (navegador)
			var tecla = event.keyCode;
		else
			var tecla = e.which;
		//alert(tecla);
		if( tecla==8 || (tecla>=48&&tecla<=57) || (tecla>=96&&tecla<=105) ){ //--- 48-57 e 96-105 (TcNum)
			
			if (tecla != 8){ // backspace
				var cpf = campo.value;		
				if(cpf.length == 3 || cpf.length == 7)	{campo.value += '.';}
				if(cpf.length == 11)					{campo.value += '-';}
			}
						
			return true;
			
		}else{
			return false;
		}
		
		/*
		if(tecla > 47 && tecla < 58){ // numeros de 0 a 9	
			
		}else{
			if (tecla == 8) // backspace
				campo.value = '';
		}*/
	}
	
	//--- Mascarar numeros
	function cfg_mascararNumero(e,i_src,mask){
		
		navegador = /msie/i.test(navigator.userAgent);
		if (navegador)
			var tecla = event.keyCode;
		else
			var tecla = e.which;
		
		if(tecla > 47 && tecla < 58){ // numeros de 0 a 9
			
			var i = i_src.value.length;
			var texto = mask.substring(i)
			if(texto.substring(0,1) != '#'){
				i_src.value += texto.substring(0,1);
			}
			
			return true;
		
		}else{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
		}
		
	}