// JavaScript Document

// Bloomfield - copyright 2008

function validFormContact(comeIn)
{
    var errorm = "";
    if(!validarEmail(comeIn.Email.value)){
        if(errorm == "")
            comeIn.Email.focus();
        errorm += "- Your email must be valid.\n";	
    }

    /*
    if(replace_all_occurrences(comeIn.CompanyName.value," ","").length == 0){
        if(errorm == "")
            comeIn.CompanyName.focus();
        errorm += "- Please type your company name.\n";	
    }

    if(replace_all_occurrences(comeIn.FirstName.value," ","").length == 0){
        if(errorm == "")
            comeIn.FirstName.focus();
        errorm += "- Please type your first name.\n";	
    }
    */

    if(replace_all_occurrences(comeIn.ContactDesc.value," ","").length == 0){
        if(errorm == "")
            comeIn.ContactDesc.focus();
        errorm += "- Please type your message.\n";
    }

    if(errorm == ""){
        comeIn.submit();
        return true;
    }
    else{
        alert(errorm);
        return false;
    }
}

//Function that valid a email structure.
function validarEmail(email_p)
{
  var email = email_p;

  var regEx = new RegExp("^[\\w\.=-]+@([\\w\-]+\\.)+[a-zA-Z]{2,4}$");
  if(!regEx.test(email)) 
    return false
  else
    return true;
}

//Function that valid a chain of characters.
function replace_all_occurrences(str,str_rep,str_fin){
    while(str.indexOf(str_rep) > -1){
        str = str.replace(str_rep,str_fin);
    }
    return str;
}
