//***************************************************************
// Autor: Leo Andrade										   	*
// Por Leo Andrade (Programador)							 	*
// Contato: leobandrade@gmail.com                               *
// Data : Maio/2011												*
// Site : www.celebre.com.br									*
//****************************************************************


// Função para iniciarmos o Ajax no browser do cliente.
function openAjax() {

var ajax;

try{
    ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
}catch(ee){
    try{
        ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
    }catch(e){
        try{
            ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
        }catch(E){
            ajax = false;
        }
    }
}
return ajax;
}

function isValidDate(day,month,year){

var dteDate;
//javascript months start at 0 (0-11 instead of 1-12)
dteDate=new Date(year,month,day);


return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}

// Função para testar que colocou somente números

function sonum(e) {
if(window.event) {
	key = e.keyCode;
}
else if(e.which) {
	key = e.which;
}
if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8));
{    return true;  }
}

// Máscara para formatar
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);
		  }
}

// Verifica o E-mail
function Verifica_Email(varemail){
	retorno = 0;
	if (varemail.indexOf("@") < 0 || varemail.indexOf(".") < 0) {
		retorno = 1;
	}
	
	return retorno;
}

//--------------------------------------------------------------------------------------------
// Função para validar o fale conosco
function valida_falecom()
{	d = document.contato;
	falta = "";
	if(d.campo1.value == "")
	{	falta = falta +"Nome\n";	}
	if(d.campo4.value == "")
	{	falta = falta +"E-mail\n";	}
	if(d.campo7.value == "" )
	{	falta = falta +"Mensagem\n";	}	


	if( d.campo1.value == "" ||  d.campo4.value == "" ||  d.campo7.value == "" )
    {
      alert("Os seguinte campos obrigatórios estão em branco:\n"+falta); 
	   if (d.campo7.value == "")
	  { d.campo7.focus();  }
	   if (d.campo4.value == "")
	  { d.campo4.focus();  }
	   if (d.campo1.value == "")
	  { d.campo1.focus();  }
  
      return false;
    }
	else
	if(!d.campo4.value == "") 
	{
		if (d.campo4.value.indexOf("@") < 0 || d.campo4.value.indexOf(".") < 0)
		{
			alert("EMAIL Inválido!");
			d.campo4.focus();
			return false;
		 }
	}
	
	
  return true;
}

