function verifyEmail(mail){
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (mail.search(emailRegEx) == -1) {
          return false;
     }
     return true;
}
function confirmarTrocarCor(id)
{
	if(	confirm('Deseja realmente alterar o esquema de cores do site?') 	)
	{
		window.location = '?load=lay'+'&cor='+id+'&acao=t'
	}
}
function confirmarTrocarLay(id)
{
	if(	confirm('Deseja realmente alterar o Layout do site?') 	)
	{
		window.location = '?load=lay'+'&lay='+id+'&acao=t'
	}
}
function confirmarDeletar(page,id)
{
	if(	confirm('Deseja realmente excluir esse registro?') 	)
	{
		window.location = page+'&id='+id+'&acao=d'
	}
}
function confirmarDeletarMenu(page)
{
	if(	confirm('Deseja realmente excluir esta p�gina?') 	)
	{
		window.location = page+'&acao=d'
	}
}	
function confirmarPublicar(page,id,acao)
	{
		msg = 'Deseja realmente alterar o status deste registro para ';
		if (acao == 'p'){
			msg += 'PUBLICADO ?';
		}else{
			msg += 'N�O PUBLICADO ?';
		}
		if(	confirm(msg))
		{
			window.location = page+'&id='+id+'&acao='+acao
		}
	}

function confirmarAnuncioPago(page,id,acao)
	{
		msg = 'Deseja realmente alterar o status deste an�ncio para ';
		if (acao == 'pgs'){
			msg += 'AN�NCIO PAGO ?';
		}else{
			msg += 'AN�NCIO N�O PAGO ?';
		}
		if(	confirm(msg))
		{
			window.location = page+'&id='+id+'&acao='+acao
		}
	}

function confirmarPublicarAnuncio(page,id,acao)
	{
		msg = 'Deseja realmente alterar o status deste registro para ';
	alert(msg);
		if (acao == 'p'){
			msg += 'PUBLICADO ?';
		}else{
			msg += 'N�O PUBLICADO ?';
		}
		if(	confirm(msg))
		{
			window.location = page+'&id='+id+'&acao='+acao
		}
	}
function confirmarPublicarMenu(page,acao)
{
	msg = 'Deseja realmente alterar o status desta p�gina para ';
	if (acao == 'p'){
		msg += 'PUBLICADO ?';
	}else{
		msg += 'N�O PUBLICADO ?';
	}
	if(	confirm(msg))
	{
		window.location = page+'&acao='+acao
	}
}	
function confirmarPub_home(page,id,acao)
{
	msg = 'Deseja realmente alterar o status deste registro para ';
	if (acao == 'hp'){
		msg += 'PUBLICADO NA HOME ?';
	}else{
		msg += 'N�O PUBLICADO NA HOME ?';
	}
	if(	confirm(msg))
	{
		window.location = page+'&id='+id+'&acao='+acao
	}
}
function confirmarPub_homeMenu(page,acao)
{
	msg = 'Deseja realmente alterar o status deste registro para ';
	if (acao == 'hp'){
		msg += 'PUBLICADO NA HOME ?';
	}else{
		msg += 'N�O PUBLICADO NA HOME ?';
	}
	if(	confirm(msg))
	{
		window.location = page+'&acao='+acao
	}
}	
function confirmarEnviarNewsletter(page,id,partes)
	{
		msg = 'Para Evitar o envio de SPAN, A geminiBR limita o envio em 300 emails por hora.\nCaso voc� deseje enviar todos de uma vez, entre em contato conosco.\nAguarde enquanto seus email s�o enviados. Esta opera��o pode durar alguns minutos.\nO boletim ser� enviado para todos os usu�rios cadastrados.\nTem certeza que voc� quer enviar agora?';
		if(	confirm(msg))
		{
			window.location = page+'&id='+id+'&acao=e&partes='+partes
		}
	}
function confirmarEnviado(page)
	{
		msg = 'Favor confirmar se a maioria dos e-mails foram enviados corretamente\nDeseja confirmar o envio da newsletter?';
		if(	confirm(msg))
		{
			window.location = page
		}
	}	
function exibirLog(usuario,data)
	{
		hora = data.substring(10);
		dia = data.substring(8,10);
		mes = data.substring(5,7);
		ano = data.substring(0,4);
		 
		msg = "";
		msg += "Log de altera��es \n";
		msg += "Data �ltima altera��o: " +dia+ "/" +mes+ "/" +ano+ " "+hora;
		msg += "\nUsu�rio respons�vel: " +usuario;
		alert(msg);
	}
	
function verificar_campo_vazio(formulario, campos, erro)
{
	if (erro==undefined)
	    erro = 'O(s) seguinte(s) campo(s) deve(m) ser preenchido(s):';
	
	var erros = "";
	
	
	if (campos==undefined)
	{
	    
		for(i=0; i<formulario.elements.length; i++)
		{
			var erro_tmp = 0;
			
			with (formulario.elements[i])
			{
				switch(type)
				{
				    case "text":
					case "select-one":					
					case "hidden":
					case "password":
					case "file":
					    if (value=="" || (value.substring(0,1)==" " && value.length < 2))
						    erro_tmp = 1;
					    break;
					case "textarea":
					    if (value.length==0 || (value.substring(0,1)==" " && value.length < 2 ) )
						    erro_tmp = 1;					
					    break;
					case "checkbox":
					    if (checked==false)
						    erro_tmp = 1;
					    break;

				}
				
				switch(value)
				{
				    case      "00:00":
					case   "00:00:00":
					case "00/00/0000":
					    erro_tmp = 1;
					    break;
				}
				
				if (erro_tmp==1)
				{
				   
				   if (title!="")
					   tmp = title.toUpperCase();
				   else
				   {
				       tmp = id;
					   tmp = tmp.toUpperCase();
				   }
				   tmp = new String(id);
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.toUpperCase();
				   erros += "- "+tmp+"\n";
				}
			}
		}
		
		if (erros!="")
		{
		    alert(erro+"\n\n"+erros);
			return false;
		}
		else
		    return true;
	}    
	else
	{
	    for (i=0;i<campos.length;i++)
		{
			var erro_tmp = 0;		
		    			
			with (eval('formulario.'+campos[i]))
			{
				switch(type)
				{
					case "text":
					case "select-one":
					case "hidden":
					case "password":
					case "file":
					    if (value=="" || (value.substring(0,1)==" " && value.length < 2))
						    erro_tmp = 1;
					    break;
					case "textarea":
					   if (value.length==0 || (value.substring(0,1)==" " && value.length < 2 ) )
						    erro_tmp = 1;					
					    break;
					case "checkbox":
					    if (checked==false)
						    erro_tmp = 1;
					    break;
				}
				
				switch(value)
				{
				    case      "00:00":
					case   "00:00:00":
					case "00/00/0000":
					    erro_tmp = 1;
					    break;
				}
				
				if (erro_tmp==1)
				{
				   
				   if (title!="")
					   tmp = title.toUpperCase();
				   else
				   {
				       tmp = id;
					   tmp = tmp.toUpperCase();
				   }
				   tmp = new String(tmp);
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   tmp = tmp.replace("_", " ");
				   erros += "- "+tmp+"\n";
				}			
			}			
		}
		
		if (erros!="")
		{
		    alert(erro+"\n\n"+erros);
			return false;
		}
		else
		    return true;		
	}
}

function mascara_email_onkeypress(campo,event)
{
	
	var caracteres = ["34","39","35","36","37","168","38","40","41","43","61","92","124","44","60","62","58","59","63","47","225","180","96","94","126","123","91","93","125","225","224","233","232","237","236","243","242","250","249","33","42"];

	
	for(i=0;i<caracteres.length;i++) 
	{
	    if (event.keyCode==caracteres[i])
		{
		    event.returnValue = false;
			break;
		}	
	}
}


function mascara_email_onblur(campo, erro)
{
    if (erro==undefined)
	    erro = "Informe um e-mail correto.";
	
	valor = new String(campo.value);
	if (valor.length>0)
	{
		if (valor.search(/^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9_\-\.]+$/)>-1)
			return true;
		else
		{
			alert(erro);
			campo.focus();
			return false;
		}	
	}

}


function mascara_email_onfocus(campo)
{
	    campo.select(); 
}

function mascara_data_onkeypress(campo,evtKeyPress)
{

	if(document.all) { // Internet Explorer
	    nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
	    nTecla = evtKeyPress.which;
	} else {
	    nTecla = evtKeyPress.which;
	    if (nTecla == 8) {
	        return true;
	    }
	}
	if ((nTecla > 47) && (nTecla < 58))
	{
		valor = new String(campo.value);
		if ((valor.length==2) || (valor.length==5))
		    campo.value += "/";
	}
	else
	    return false;
}


function mascara_data_onblur(campo, erro1, erro2)
{
	
	if (erro1==undefined)
	    erro1 = "Digite a data corretamente.";
	if (erro2==undefined)
	    erro2 = "Preencha a data por completo.";
		
	valor = new String(campo.value);
	if ((valor.length>0) && (valor.toString()!="00/00/0000"))
	{
		
		if (valor.length==10)
		{
		    
			if (valor.search(/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-9]{4}$/)>-1)
			    return true;
			else
			{
			    alert(erro1);
				campo.focus();
				return false;
			}
		}
		else
		{
			
		    alert(erro2);
			campo.focus();
			return false;
		}
	}
}


function mascara_data_onfocus(campo)
{
	valor = new String(campo.value);
    if ((valor.length!=2) && (valor.length!=5))
	    campo.select(); 
}
	
function validar_datas_onsubmit(id_data_inicial, id_data_final, erro, isId, bolSemErro) 
{
	
	if (erro==undefined)
	    erro = "A data inicial est� posterior a data final.";

    if(isId==undefined){
	   data_inicial = new String(document.getElementById(id_data_inicial).value);
	   data_final = new String(document.getElementById(id_data_final).value);
	}else{
	   data_inicial = new String(id_data_inicial);
	   data_final = new String(id_data_final);
    }
    
    partes_inicial = data_inicial.split("/");
    if (data_inicial.search(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)>-1)
        partes_inicial.reverse();
     
    partes_final = data_final.split("/");
    if (data_final.search(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)>-1)
        partes_final.reverse()
	
    data_inicial = new Date(partes_inicial[2], partes_inicial[1], partes_inicial[0]);
    data_final   = new Date(partes_final[2], partes_final[1], partes_final[0]);

    if (data_inicial.getTime()>data_final.getTime())
	{
	    if (bolSemErro==undefined) {
	        alert(erro);
	    }
		return false;
	}
	else
	    return true;
}

function verificar_senha_onsubmit(campo_senha_1, campo_senha_2)
{
	senha_1 = new String(document.getElementById(campo_senha_1).value);
	senha_2 = new String(document.getElementById(campo_senha_2).value);
	
	if ((senha_1.length>0) || (senha_2.length>0))
	{
		if (senha_1.length>12 || senha_1.length<6 || senha_2.length>12 || senha_2.length<6)
		{
			alert("Tamanho de senhas inv�lido. M�nimo de 6 e m�ximo de 12 caracteres!");
			
			document.getElementById(campo_senha_1).value = "";
			document.getElementById(campo_senha_2).value = "";
			
			document.getElementById(campo_senha_1).focus();
			
			return false;
		}

		if (senha_1.toString()==senha_2.toString())
		{
			return true;
		}
		else
		{
			alert("As senhas est�o diferentes.");
			
			document.getElementById(campo_senha_1).value = "";
			document.getElementById(campo_senha_2).value = "";
			
			document.getElementById(campo_senha_1).focus();
			
			return false;
		}	
	}
	else
	    return true;
}

function mascara_dinheiro_onkeypress(campo,event)
{
	clientNavigator = navigator.appName;  
	if (clientNavigator.indexOf('Microsoft') != -1)
	{
		tecla = new String(event.keyCode);
	}else
	{
		tecla = new String(event.which);
	}
	
	valor = new String(campo.value);
	
	
	if ((tecla.search(/^(4[89]|5[0-7])$/)>-1) && (valor.length<12))
	{
		
		valor = valor.replace(".", "");
		//valor = valor.replace(/\,/, "");
		
		if (valor.length==2)
			campo.value = valor.substr(0, 1)+"."+valor.substr(1, 2);
		else if (valor.length>2)
		{
			
			reais    = new String(valor.substr(0, valor.length-1));
			centavos = valor.substr(valor.length-1, 1);
			
			if (reais.length>2)
			{
				divisao = reais.length%3;
				if (divisao>0)
				{
					primeira = reais.substr(0, divisao);
					segunda  = new String(reais.substr(divisao));
					
					tmp = "";
					for(i=0;i<segunda.length;i+=3)
						tmp = tmp+""+segunda.substr(i, 3);
					
					campo.value = primeira+tmp+"."+centavos;
				}
				else
				{
					tmp = "";
					for(i=0;i<reais.length;i+=3)
						tmp = tmp+reais.substr(i, 3)+"";
					
					tmp = new String(tmp);
					reais = tmp.replace(/\,$/, "");
					
					campo.value = reais+"."+centavos;
				}			
			}
			else
			    campo.value = reais+"."+centavos;
		}
	}
	else
	    event.returnValue = false;
}

function campo_inteiro_onkeypress(event)
{
	clientNavigator = navigator.appName;  
	if (clientNavigator.indexOf('Microsoft') != -1)
	{
		tecla = new String(event.keyCode);
	}else
	{
		tecla = new String(event.which);
	}
	
	if (tecla.search(/^(4[89]|5[0-7])$/)==-1)
		event.returnValue = false;   
}



function campo_inteiro_onblur(campo, erro) 
{
	
	if (erro==undefined)
	    erro = "Esse campo s� aceita n�meros.";
	
	valor = new String(campo.value);
    if (valor.length!=0)
	{
		
		if (valor.search(/^[0-9]+$/)>-1)
			return true;
		else
		{
			alert(erro);
			campo.focus();
			return false;
		}		
	}
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

