<!--
function getElement(f,n){
    for (x=0;x<f.length;x++)
    {
		if (f[x].name.indexOf(n) >-1)
		{
			return f[x];
			break;
		}
    }
}

function checkRadioButtonSelected(f,clientID,name)
{
	var checked=false;
	for (x=0;x<f.length;x++)
	{
		var elem=f[x];
		if (elem.name.indexOf(name) > -1)
		{
			if (elem.type=="radio")
			{
				if (elem.checked)
				{
					checked=true;
					break;
				}
			}
		}
	}
	return checked;
}

function checkWhitespace(f, clientID, name, text){
    var t=getElement(f, name);
    if (isWhitespace(t.value)){
        alert("Please complete the " + text + " field.");
        t.focus();
        return true;
    }    
    return false;
}

function checkContactUs(f, clientID){
	var formType=f.formType.value;
	switch(formType)
		{
		case "RequestForProposal":
			return checkRequestForProposal(f,clientID);
		case "RequestWorkOrder":
			return checkRequestWorkOrder(f,clientID);
		case "ContactUs":
			return checkContactUsForm(f,clientID);
		default: return true;
		}
	}
	
function checkContactUsForm(f, clientID){    
    if (checkWhitespace(f, clientID, "FirstName", "First name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "LastName", "Last name")){
        return false;
    }
    var t = getElement(f, 'EMailTextBox');
	if (!validateEmail(t.value,1,1)) 
	{
		t.focus();
		return false;
	}
	if (checkWhitespace(f, clientID, "Address1TextBox", "Address")){
        return false;
    }
	if (checkWhitespace(f, clientID, "CityTextBox", "City")){
        return false;
    }
	if (checkWhitespace(f, clientID, "ZipCodeTextBox", "ZIP code")){
        return false;
    }
	if (checkWhitespace(f, clientID, "PhoneNumberTextBox", "Phone number")){
        return false;
    }
}

function checkRequestWorkOrder(f, clientID){ 
    if (checkWhitespace(f, clientID, "JobName", "Job name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "JobLocation", "Job location")){
        return false;
    }
    if (checkWhitespace(f, clientID, "CompanyName", "Company name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "FirstName", "First name")){
        return false;
    }

    if (checkWhitespace(f, clientID, "LastName", "Last name")){
        return false;
    }
    var t = getElement(f, 'EMailTextBox');
	if (!validateEmail(t.value,1,1)) 
	{
		t.focus();
		return false;
	}
	if (checkWhitespace(f, clientID, "PhoneNumberTextBox", "Phone number")){
        return false;
    }
    t = getElement(f, 'CurrentClient');
    if (!checkRadioButtonSelected(f,clientID, "CurrentClient"))
    {
		alert("Please indicate whether you are a current ALS client.");
		return false;
    }
	if (checkWhitespace(f, clientID, "ServicesRequired", "Problem/Description of work")){
        return false;
    }
	if (checkWhitespace(f, clientID, "ResponseTime", "Response time")){
        return false;
    }
}

function checkRequestForProposal(f, clientID){  
    if (checkWhitespace(f, clientID, "JobName", "Job name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "JobLocation", "Job location")){
        return false;
    }
    if (checkWhitespace(f, clientID, "CompanyName", "Company name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "FirstName", "First name")){
        return false;
    }
    if (checkWhitespace(f, clientID, "LastName", "Last name")){
        return false;
    }
    var t = getElement(f, 'EMailTextBox');
	if (!validateEmail(t.value,1,1)) 
	{
		t.focus();
		return false;
	}
	if (checkWhitespace(f, clientID, "Address1TextBox", "Address")){
        return false;
    }
	if (checkWhitespace(f, clientID, "CityTextBox", "City")){
        return false;
    }
	if (checkWhitespace(f, clientID, "ZipCodeTextBox", "ZIP code")){
        return false;
    }
	if (checkWhitespace(f, clientID, "PhoneNumberTextBox", "Phone number")){
        return false;
    }
	if (checkWhitespace(f, clientID, "BestTimeToCall", "Best time to call")){
        return false;
    }
    t = getElement(f, 'HearAbout');
    if (t.options[t.selectedIndex].value=="")
    {
		alert("Please indicate how you heard about ALS.");
		t.focus();
		return false;
    }  
}

// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('Email address is mandatory.');
   return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('Email address contains invalid characters.');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('Email address must contain an @.');
   return false;
}
if (atPos == 0) {
   if (db) alert('Email address must not start with @.');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('Email address must contain only one @.');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('Email address must contain a period in the domain name.');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('Period must not immediately follow @ in email address.');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('Period must not immediately precede @ in email address.');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('Two periods must not be adjacent in email address.');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Invalid primary domain in email address.');
   return false;
}
return true;
}
//-->

