// JavaScript Document


function addLoadEvent(func){
	var oldonload = window.onload;
	
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			if(oldonload){
				oldonload();
			}
			func();
		}
	}
}





/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display=="block"){
			el.style.display = "none";
		} else
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			el.style.lineheight = "20px";
		}else{
			el.style.display = "none";
		}
	}
}





/*
 * Form Validation  functions
 */
function validateForm(theform){
	
	var reason = "";
	
	reason += validateEmpty(theform.name);
	reason += validateEmpty(theform.phone);
	reason += validateEmail(theform.email);
	
	if(theform.datetime){
		reason += validateEmpty(theform.datetime);
	}
	
	reason += validateEmpty(theform.description);
	
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	}

  	return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value == "Name" || fld.value == "Phone" || fld.value == "Description" || fld.value == "Requested Date") {
        fld.style.background = '#bb1930';
		fld.style.color = 'White';
        error = "The required field " + fld.value + " has not been filled in.\n"
    } else {
        fld.style.background = 'White';
		fld.style.color = 'Black';
    }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "" || fld.value == "Email") {
        fld.style.background = '#bb1930';
		fld.style.color = 'White';
        error = "The required field " + fld.value + " has not been filled in.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#bb1930';
		fld.style.color = 'White';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#bb1930';
		fld.style.color = 'White';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
		fld.style.color = 'Black';
    }
    return error;
}

