/*
Date Created: 02Aug2006
          By: JOE cabello
*/

function filterNonNumeric(field) {
var result = new String();
var numbers = "0123456789.-";
var chars = field.value.split(""); // create array
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars[i]) != -1) result += chars[i];
}
if (field.value != result) field.value = result;
}

function FocusIn(field) {
field.style.backgroundColor="#fff2d9"
}

function FocusOut(field) {
field.style.backgroundColor="white"
}

function handleEnter (field, event) {
                var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
                if (keyCode == 13) {
                        var i;
                        for (i = 0; i < field.form.elements.length; i++)
                                if (field == field.form.elements[i])
                                        break;
                        i = (i + 1) % field.form.elements.length;
                        field.form.elements[i].focus();
                        return false;
                }
                else
                return true;
        }
        
function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false
}

if (str.indexOf(at,(lat+1))!=-1){
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false
}

if (str.indexOf(dot,(lat+2))==-1){
return false
}

if (str.indexOf(" ")!=-1){
return false
}

return true
}

function validRegister() {
    missinginfo = "";
    with (document.form1){
        if (fname.value=='') {
        missinginfo += "\n     -  First Name. ";
        fname.focus();
        }

        if (lname.value=='') {
        missinginfo += "\n     -  Last Name. ";
        lname.focus();
      }

        if (address1.value=='') {
        missinginfo += "\n     -  Address1. ";
        address1.focus();
      }

        if (city.value=='') {
        missinginfo += "\n     -  City. ";
        city.focus();
      }
      

if (nonus.value==''){
        if (state.value=='') {
        missinginfo += "\n     -  State. ";
        state.focus();
        }
}

        if (zip.value=='') {
        missinginfo += "\n     -  Zip Code. ";
        zip.focus();
      }

        if (phone.value=='') {
        missinginfo += "\n     -  Phone. ";
        phone.focus();
      }

        if (echeck(email.value)==false){
        missinginfo += "\n     -  Email. ";
        email.focus()
        }
} //with
        if (missinginfo != "") {
                missinginfo ="_____________________________\n" +
                "You failed to correctly fill in your:\n" +
                missinginfo + "\n_____________________________" +
                "\nPlease re-enter and submit again!";
                alert(missinginfo);
                return false;
        } else {

                if (confirm("Are All Entries Correct")) {
                        document.form1.state.disabled=false;
                        document.form1.action="register.php";
                        return true;
                } else
                        return false;

        }
}


function validInquiry() {
    missinginfo = "";
    with (document.form1){
        if (name.value=='') {
        missinginfo += "\n     -  Name. ";
        name.focus();
        }


        if (phone.value=='') {
        missinginfo += "\n     -  Phone. ";
        phone.focus();
      }

        if (subject.value=='') {
        missinginfo += "\n     -  Subject. ";
        subject.focus();
      }
      
        if (echeck(email.value)==false){
        missinginfo += "\n     -  Email. ";
        email.focus()
        }
} //with
        if (missinginfo != "") {
                missinginfo ="_____________________________\n" +
                "You failed to correctly fill in your:\n" +
                missinginfo + "\n_____________________________" +
                "\nPlease re-enter and submit again!";
                alert(missinginfo);
                return false;
        } else {

                if (confirm("Are All Entries Correct")) {
                        document.form1.action="contact.php";
                        return true;
                } else
                        return false;

        }
}

function oncheck(frm)
{
if(frm.nonusa.checked==true)
   {
    document.form1.state.disabled=true;
    document.form1.nonus.focus();
   }else{
    document.form1.state.disabled=false;
   }
}

function shownonus(){
  if (document.form1.nonus.value==''){
    document.form1.state.disabled=false;
  }else{
    document.form1.state.disabled=true;
  }
}
