function high(which2){
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",50)
}

function low(which2){
	clearInterval(highlighting)
	which2.filters.alpha.opacity=50
}

function highlightit(cur2){
	if (cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=15
	else if (window.highlighting)
		clearInterval(highlighting)
}

function mascara_hora(hora){ 
	 var mytime = ''; 
	 mytime = mytime + hora; 
	 if (mytime.length == 2){ 
		 mytime = mytime + ':'; 
		 document.form.hora.value = mytime; 
	 } 
}

function mOvr(src) {
	src.style.cursor = 'hand';
}

// -- Função valida CPF/CNPJ -- //
function cpf_cnpj() {
    s = limpa_string(document.form.cadastro_cpfcnpj.value);
	if (s.length == 11) {
		if (valida_CPF(document.form.cadastro_cpfcnpj.value) == false ) {
		document.form.cadastro_cpfcnpj.focus();
		return false;
		}
	}
	else if (s.length == 14) {
		if (valida_CNPJ(document.form.cadastro_cpfcnpj.value) == false ) {
			document.form.cadastro_cpfcnpj.focus();
			return false;
			}
		}
	else {
		return false;
	}
	return true;
}

function limpa_string(S){ 
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";

    for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){temp=temp+digito}
	}
	return temp;
}

function valida_CPF(s){
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;

	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
	return true;
}

function valida_CNPJ(s){
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;

	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) {
		return false;
	}

	return true;
}

// -- Função valida e-mail -- //
function validanr(vlr){
	if (vlr == "" || vlr.length < 0 ) {
		return true;
	}
	for (i = 0; i < vlr.length; i++) {
		ch = vlr.substring(i, i + 1) ;
		if ((ch < "0" || "9" < ch)) {
			return true;
		}
	}
	if(eval(vlr) == 0){
		return true;
	}
	return false
}

function chkmail(mail){
	var permitido = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@-_";
	var tamanho = mail.length;
	if (mail.indexOf('@')==-1 || mail.indexOf('.')==-1){
		return true;
	}
	for (i=0;i<=tamanho+1;i++){
		if (permitido.indexOf(mail.charAt(i))==-1){
			return true;
		}
	}
	return false;
}

function avisa(item,msg) {
	item.focus()
	item.select()
	alert(msg)
}

function ProxTab(){
	
 	if (navigator.appName == 'Microsoft Internet Explorer') {
		if(event.keyCode==13) event.keyCode=9;
 	} else if (navigator.appName == 'Netscape') {
		if(event.which==13) event.which=9;
 	}
}

function doprint() {

//save existing user's info
var h = factory.printing.header;
var f = factory.printing.footer;

	//hide the button
		document.all("printbtn").style.visibility = 'hidden';

	//set header and footer to blank
		factory.printing.header = "";
		factory.printing.footer = "";

	//print page without prompt
		factory.DoPrint(false);

	//restore user's info
		factory.printing.header = h;
		factory.printing.footer = f;

	//show the print button
		document.all("printbtn").style.visibility = 'visible';
}

function mascara_cnpj(cnpj, nome){ 
	 var mycnpj = ''; 
	 mycnpj = mycnpj + cnpj; 

	//00.000.000/0001-00
	 if (mycnpj.length == 2){ 
		 mycnpj = mycnpj + '.'; 
		 eval("document.forms[1]."+nome+".value = mycnpj"); 
	 } 
	 if (mycnpj.length == 6){ 
		 mycnpj = mycnpj + '.'; 
		 eval("document.forms[1]."+nome+".value = mycnpj"); 
	 } 
	 if (mycnpj.length == 10){ 
		 mycnpj = mycnpj + '/'; 
		 eval("document.forms[1]."+nome+".value = mycnpj"); 
	 } 	 
	 if (mycnpj.length == 15){ 
		 mycnpj = mycnpj + '-'; 
		 eval("document.forms[1]."+nome+".value = mycnpj"); 
	 } 	 
	 
	 if (mycnpj.length >= 18){ 
		 if (valida_CNPJ(mycnpj) ==  false) {
			alert("CNPJ inválido !");
			document.form.cadastro_cpfcnpj.focus();
		 } 
	 } 
	  
 }

function mascara_cpf(cpf, nome){ 
	 var mycpf = ''; 
	 mycpf = mycpf + cpf; 

	//000.000.000-00
	 if (mycpf.length == 3){ 
		 mycpf = mycpf + '.'; 
		 eval("document.forms[1]."+nome+".value = mycpf"); 
	 } 
	 if (mycpf.length == 7){ 
		 mycpf = mycpf + '.'; 
		 eval("document.forms[1]."+nome+".value = mycpf"); 
	 } 
	 if (mycpf.length == 11){ 
		 mycpf = mycpf + '-'; 
		 eval("document.forms[1]."+nome+".value = mycpf"); 
	 } 	 
	 if (mycpf.length >= 14){ 
		 if (valida_CPF(mycpf) ==  false) {
			alert("CPF inválido !");
			document.form.cadastro_cpfcnpj.focus();

		 } 
	 } 
	  
 }
	
function mascara_rg(rg, nome){ 
	 var myrg = ''; 
	 myrg = myrg + rg; 

	//0.000.000-0
	 if (myrg.length == 1){ 
		 myrg = myrg + '.'; 
		 eval("document.forms[1]."+nome+".value = myrg"); 
	 } 
	 if (myrg.length == 5){ 
		 myrg = myrg + '.'; 
		 eval("document.forms[1]."+nome+".value = myrg"); 
	 } 
	 if (myrg.length == 9){ 
		 myrg = myrg + '-'; 
		 eval("document.forms[1]."+nome+".value = myrg"); 
	 } 	 
}

function flash(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><embed src="'+arquivo+'" wmode="transparent" quality="best" width="'+largura+'" height="'+altura+'" name="root" align="middle" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" />');
	document.write('</object>');
}

function flash2(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="no-transparent" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><embed src="'+arquivo+'" wmode="no-transparent" quality="best" width="'+largura+'" height="'+altura+'" name="root" align="middle" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" />');
	document.write('</object>');
}

function showFoto(src){
    //criando um link falso, para o LightBox captar as informações
    var a_false = document.createElement("A");
    a_false.rel = "lightbox";
    a_false.href = src;
    //chamando a função do lightbox responsável pelo início das ações
    myLightbox.start(a_false);
    //anulando o link
    a_false = null;
}

function mascara_data(data, nome){ 
	 var mydata = ''; 
	 mydata = mydata + data; 
	 if (mydata.length == 2){ 
		 mydata = mydata + '/'; 
		 eval("document.forms[1]."+nome+".value = mydata"); 
	 } 
	 if (mydata.length == 5){ 
		 mydata = mydata + '/'; 
		 eval("document.forms[1]."+nome+".value = mydata"); 
	 } 
	 if (mydata.length == 10){ 
		 verifica_data(nome); 
	 } 
	  
 }
 
function verifica_data(data) { 
   tot = eval("document.forms[1]."+data+".value");
   dia = eval("document.forms[1]."+data+".value.substring(0,2)"); 
   mes = eval("document.forms[1]."+data+".value.substring(3,5)"); 
   ano = eval("document.forms[1]."+data+".value.substring(6,10)"); 
   situacao = true; 
   
   if (tot.length < 10) {
   	   situacao = false;
   }	
   // verifica o dia valido para cada mes 
   if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
	   situacao = false; 
   } 
   // verifica se o mes e valido 
   if (mes < 01 || mes > 12 ) { 
	   situacao = false; 
   } 
	// verifica se e ano bissexto 
   if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
	   situacao = false; 
   } 

   if (eval("document.forms[1]."+data+".value == ''")) { 
	   situacao = false;
   } 

   if (!situacao) { 
       alert("Data cadastro inválida!"); 
   	   eval("document.forms[1]."+data+".value = ''");
	   eval("document.forms[1]."+data+".focus();");
   } 
}

function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(document.all) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(document.layers) { // Nestcape
       nTecla = evtKeyPress.which;
     }

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
   }

function verifica()
	{
		
		if (document.form.cadastro_razaosocial.value == '')
		{
			alert('Preencha o campo Nome / Razão Social corretamente !');
			document.form.cadastro_razaosocial.focus();
			return false;
		}
		
		if (document.form.cadastro_endereco.value == '')
		{
			alert('Preencha o campo Endereço corretamente !');
			document.form.cadastro_endereco.focus();
			return false;
		}
		
		if (document.form.cadastro_numero.value == '')
		{
			alert('Preencha o campo Número corretamente !');
			document.form.cadastro_numero.focus();
			return false;
		}

		if (document.form.cadastro_cidade.value == '')
		{
			alert('Preencha o campo Cidade corretamente !');
			document.form.cadastro_cidade.focus();
			return false;
		}

		if (document.form.cadastro_cep.value == '')
		{
			alert('Preencha o campo CEP corretamente !');
			document.form.cadastro_cep.focus();
			return false;
		}
		
		if (document.form.cadastro_nomecontato.value == '')
		{
			alert('Preencha o campo Nome para Contato corretamente !');
			document.form.cadastro_nomecontato.focus();
			return false;
		}
				
		if (document.form.cadastro_email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
		{
			alert("Informe o seu E-mail Pessoal corretamente !");
			document.form.cadastro_email.focus();
			return false;
		}
		
		if (document.form.cadastro_foneres.value == '')
		{
			alert('Preencha o campo Tel. Residencial corretamente !');
			document.form.cadastro_foneres.focus();
			return false;
		}
}

function somente_numero(campo){
    var digits="0123456789.-/() "
    var campo_temp 
    for (var i=0;i<campo.value.length;i++){
      campo_temp=campo.value.substring(i,i+1)    
      if (digits.indexOf(campo_temp)==-1){
            alert('Digite somente números !');
			campo.value = campo.value.substring(0,i);
            break;
       }
    }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ProxTab(){
	if(event.keyCode==13) event.keyCode=9;
}

//window.name = "root" // nome pagina

function abre(link, width, height){
  var left = Math.round((screen.width / 2) - (width / 2)) - 5;
  var top = Math.round((screen.height / 2) - (height / 2)) - 20;
	window.open (link, 'abre', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left);
}

function get_idcidade(x) {
	document.form.id_cidade.value = x;
}

function get_idbairro(x) {
	document.form.id_bairro.value = x;
}

function habilitar(vlr) {
	x = vlr;
	if(x == '0') {
		document.form.pessoa_username.disabled=true;
		document.form.pessoa_senha.disabled=true;	
		document.form.pessoa_senha2.disabled=true;				
		//document.form.pessoa_nivel.disabled=true;			
	} else if (x == '1') {
		document.form.pessoa_username.disabled=false;
		document.form.pessoa_senha.disabled=false;	
		document.form.pessoa_senha2.disabled=false;				
		//document.form.pessoa_nivel.disabled=false;			
	}

}

var tipopessoa = "";
function tipocampo(txt) {
	tipopessoa = txt;
	document.form.cadastro_cpfcnpj.value='';
	document.form.cadastro_inscrg.value='';
	document.form.cadastro_cpfcnpj.focus();
}

function valida_cnpj_cpf(valor, nome) {
	if (tipopessoa == 'F') { 
		mascara_cpf(valor, nome);
	} else if (tipopessoa == 'J') { 
		mascara_cnpj(valor, nome)
	}
}

function valida_rg(valor, nome) {
	if (tipopessoa == 'F') { 
		mascara_rg(valor, nome);
	} 
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cep(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2-$3") //Coloca ponto entre o quinto e o sexto dígitos
	//v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    //v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

function mascaraData(campoData){              

	var data = campoData.value;
	    if (data.length == 2){                  
		
		data = data + '/';                  
		document.forms[1].cadastro_datanasc.value = data;      
		return true;                            
	}             
		if (data.length == 5){                  
		
		data = data + '/';
		document.forms[1].cadastro_datanasc.value = data;                  
		return true;              
	}
}

function load1(form) {
		 var url = form.Llist_1.options[form.Llist_1.selectedIndex].value;
		 if (url != '') open(url);
		 return false;
}

function load2(form) {
 	    var url = form.Llist_2.options[form.Llist_2.selectedIndex].value;
    	if (url != '') open(url);
    	return false;
}

function load3(form) {
		 var url = form.Llist_3.options[form.Llist_3.selectedIndex].value;
		 if (url != '') open(url, "iframeNoticias");
			
		 return false;
}	
