/** validate_required function
* This method validates empty fields. */
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}

// Validate's the forms input data
function ValidateQuoteForm(thisform) {
with (thisform) {
     // Illegal characters
     var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

    // Blank name check
    if (validate_required(name,"Please enter your name.")==false)
    {name.focus();return false;}
    // Check username for illegal characters
    if(validate_required(name, "")==true) {
        for (var i = 0; i < name.value.length; i++) {
  	        if (iChars.indexOf(name.value.charAt(i)) != -1) {
  	            alert ("Your name contains special characters. \nSpecial characters are not allowed.\n Please remove them and try again.");
  	            return false;
  	        }
        }
    }
    // Count the characters in the name
    if(name.value.length > 45) {
        alert('Your name cannot be more than (45) characters long.');
        name.focus();
        return false;
    }

    // Blank email check
    if (validate_required(email,"Please enter you email address.")==false)
    {email.focus();return false;}
    // Valid email check
    if(validate_required(email, "")==true) {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = email.value;
        if(reg.test(address) == false) {
            alert('Your email address is not valid. Please enter a valid email address.');
            return false;
        }
   }
    // Email length check
    if(email.value.length > 70) {
        alert('Your email cannot be more than (70) characters long.');
        email.focus();
        return false;
    }

    // Blank phone check
    if (validate_required(phone,"Please enter your phone number (this is incase we have trouble emailing you).")==false)
    {phone.focus();return false;}
    // phone Length Check
    if(phone.value.length > 20) {
        alert('Your phone number cannot be more than (20) characters long.');
        phone.focus();
        return false;
    }

    // Blank info check
    if (validate_required(info,"Please enter some basic information about your project.")==false)
    {info.focus();return false;}
    // Info Length Check
    if(info.value.length > 2000) {
        alert('The basic information about your project cannot be more than (2000) characters long.');
        info.focus();
        return false;
    }

    // similar field length check
    if(similar.value.length > 2000) {
        alert('The similar websites field cannot be more than (2000) characters long.');
        similar.focus();
        return false;
    }

    // budget Length Check
    if(budget.value.length > 30) {
        alert('The budget field cannot be more than (30) characters long.');
        budget.focus();
        return false;
    }

    // completion Length Check
    if(completion.value.length > 45) {
        alert('The completion date field (45) characters long.');
        completion.focus();
        return false;
    }

    // offers Length Check
    if(offers.value.length > 2000) {
        alert('The offers field cannot be more than (2000) characters long.');
        offers.focus();
        return false;
    }
}
}

// Validate's the forms input data
function ValidateContactForm(thisform) {
with (thisform) {
     // Illegal characters
     var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

    // Blank name check
    if (validate_required(name,"Please enter your name.")==false)
    {name.focus();return false;}
    // Check username for illegal characters
    if(validate_required(name, "")==true) {
        for (var i = 0; i < name.value.length; i++) {
  	        if (iChars.indexOf(name.value.charAt(i)) != -1) {
  	            alert ("Your name contains special characters. \nSpecial characters are not allowed.\n Please remove them and try again.");
  	            return false;
  	        }
        }
    }
    // Count the characters in the name
    if(name.value.length > 45) {
        alert('Your name cannot be more than (45) characters long.');
        name.focus();
        return false;
    }

    // Blank email check
    if (validate_required(email,"Please enter you email address.")==false)
    {email.focus();return false;}
    // Valid email check
    if(validate_required(email, "")==true) {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = email.value;
        if(reg.test(address) == false) {
            alert('Your email address is not valid. Please enter a valid email address.');
            return false;
        }
   }
    // Email length check
    if(email.value.length > 70) {
        alert('Your email cannot be more than (70) characters long.');
        email.focus();
        return false;
    }

    // Blank message check
    if (validate_required(message,"Please enter your message.")==false)
    {message.focus();return false;}
    // Info Length Check
    if(message.value.length > 2000) {
        alert('Your message cannot be more than (2000) characters long.');
        message.focus();
        return false;
    }

}
}
