// FUNDACAO MT [WWW.FUNDACAOMT.COM.BR]

function formGuest(theForm)
{
    if (theForm.nome.value == "")
    {
	alert("Fundação MT - GuestBook\n\nFavor informar seu Nome.");
	theForm.nome.focus();
	return (false);
    }
    if (theForm.email.value.indexOf("@",0) == -1)
    {
	alert("Fundação MT - GuestBook\n\nEste E-Mail não é válido.");
	theForm.email.focus();
	return (false);
    }
    x = theForm.email.value.length;
	x = x - 1;
    if (theForm.email.value.indexOf("@",0) == x)
    {
	alert("Fundação MT - GuestBook\n\nEste E-Mail não é válido.");
	theForm.email.focus();
	return (false);
    }
    if (theForm.email.value.indexOf("@",0) == 0)
    {
	alert("Fundação MT - GuestBook\n\nEste E-Mail não é válido.");
	theForm.email.focus();
	return (false);
    }
    if (theForm.email.value.indexOf(".@",0) != -1)
	{
	alert("Fundação MT - GuestBook\n\nEste E-Mail não é válido.");
	theForm.email.focus();
	return (false);
    }
    if (theForm.email.value.indexOf("@.",0) != -1)
    {
	alert("Fundação MT - GuestBook\n\nEste E-Mail não é válido.");
	theForm.email.focus();
	return (false);
    }
    if (theForm.mensagem.value == "")
    {
	alert("Fundação MT - GuestBook\n\nFavor Escrever a sua Mensagem.");
	theForm.mensagem.focus();
	return (false);
    }
	theForm.submit;
}

function ask(theForm)
{
    if (confirm ("Deseja realmente excluir este item?"))
    {
        theForm.submit;
    }
    else
    {
        return (false);
    }
}

function returnCidade(form) {
    var txt = document.fmt.cidade.value
    window.opener.cad.cidade.value = txt;
    window.close();
}

function digitar_data(data) {
    var mydata = '';
    mydata = mydata + data;
    if (mydata.length == 2) {
    	mydata = mydata + '/';
    	document.form.data.value = mydata;
   	}
    if (mydata.length == 5) {
        mydata = mydata + '/';
        document.form.data.value = mydata;
    }
}

// SOJANET

function cad_sojanet(theForm)
{
    if (theForm.nome.value == "") {
	alert("Fundação MT - SOJANET\n\nFavor informar seu Nome.           ");
	theForm.nome.focus();
	return (false);
    }

    if (theForm.email.value.indexOf("@",0) == -1)
    {
	alert("Fundação MT - SOJANET\n\nEste E-Mail não é válido.           ");
	theForm.email.focus();
	return (false);
    }

	x = theForm.email.value.length;

	x = x - 1;

	if (theForm.email.value.indexOf("@",0) == x) {
	alert("Fundação MT - SOJANET\n\nEste E-Mail não é válido.           ");
	theForm.email.focus();
	return (false);
    }

    if (theForm.email.value.indexOf("@",0) == 0) {
	alert("Fundação MT - SOJANET\n\nEste E-Mail não é válido.           ");
	theForm.email.focus();
	return (false);
    }

    if (theForm.email.value.indexOf(".@",0) != -1) {
	alert("Fundação MT - SOJANET\n\nEste E-Mail não é válido.           ");
	theForm.email.focus();
	return (false);
    }

    if (theForm.email.value.indexOf("@.",0) != -1) {
	alert("Fundação MT - SOJANET\n\nEste E-Mail não é válido.           ");
	theForm.email.focus();
	return (false);
    }

    theForm.btf.disabled = true;
    theForm.btf.value = 'Aguarde, carregando...';
    theForm.submit;
}

function checar_fale(theForm)
{
    var NomeSite = "Fundação MT           \n\nAviso          \n\n";

    if (theForm.nome.value == "") {
    alert(NomeSite+"Informe o seu Nome.         ");
	theForm.nome.focus();
	return (false);
    }

    if (theForm.telefone.value == "") {
    alert(NomeSite+"Informe o seu Telefone.         ");
	theForm.telefone.focus();
	return (false);
    }

    if (theForm.email.value.indexOf("@",0) == -1) {
    alert(NomeSite+"Informe o E-mail corretamente.         ");
    theForm.email.focus();
    return (false);
    }

    x = theForm.email.value.length;
    x = x - 1;

    if (theForm.email.value.indexOf("@",0) == x) {
    alert(NomeSite+"Informe o E-mail corretamente.         ");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@",0) == 0) {
    alert(NomeSite+"Informe o E-mail corretamente.         ");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf(".@",0) != -1) {
    alert(NomeSite+"Informe o E-mail corretamente.         ");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@.",0) != -1) {
    alert(NomeSite+"Informe o E-mail corretamente.         ");
    theForm.email.focus();
    return (false);
    }

    if (theForm.mensagem.value == "") {
    alert(NomeSite+"Digite a sua Mensagem.         ");
	theForm.mensagem.focus();
	return (false);
    }

    theForm.btf.disabled = true;
    theForm.btf.value = 'Aguarde, carregando...';
    theForm.submit;
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode;
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

function formatFone(objFormField) {
    intFieldLength = objFormField.value.length;
    if(intFieldLength == 4){
         objFormField.value = objFormField.value + "-";
         return false;
         }
}

//
