//ONFOCUS CLEAR TEXT FOR FORM VALUES
function clearText (thefield) {
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
}
//ONBLUR TEXT FOR FORM VALUES
function addText (thefield,thetext) {
	if (""==thefield.value)
		thefield.value = thetext
}
function camcheckrequired(theform) {
	var returnval=true //by default, allow form submission
	var checkit = document.getElementById('required_fields').value;
	var requireds=theform.required_fields.value.split(";") //split using blank space as delimiter
	for (i=0; i<requireds.length; i++){
		var fieldnamez = requireds[i];
		theform[fieldnamez].style.border = ''
		if(fieldnamez.length > 1){
			if (theform[fieldnamez].type=="text" || theform[fieldnamez].type=="textarea" || theform[fieldnamez].type=="file"){
				if (theform[fieldnamez].value==""){ //if empty field
					alert("Please make sure all required fields are filled out.") //alert error message
					theform[fieldnamez].style.border = '1px solid red'
					theform[fieldnamez].focus();
					returnval=false //disallow form submission
					break //end loop. No need to continue.
				}
			}
			if (theform[fieldnamez].type=="select-one"){
				if (theform[fieldnamez].value==""){
					alert("Please make sure all required fields are filled out.") //alert error message
					theform[fieldnamez].style.border = '1px solid red'
					theform[fieldnamez].focus();
					returnval=false //disallow form submission
					break //end loop. No need to continue.
				}
			}
			if(theform[fieldnamez].name=="emailaddr"){
				var str = theform.emailaddr.value
				var at="@"
				var dot="."
				var comma=","
				var lat=str.indexOf(at)
				var lstr=str.length
				var ldot=str.indexOf(dot)
				if (str.indexOf(at)==-1){
					alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
				}
				if (str.indexOf(comma)>0){
					alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
				}
				if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
   			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
  			}
  			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
  			}
  			if (str.indexOf(at,(lat+1))!=-1){
    			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
  			}
  			if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
  			}
  			if (str.indexOf(dot,(lat+2))==-1){
    			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
  			}
  			if (str.indexOf(" ")!=-1){
    			alert("Invalid E-mail Address")
					theform.emailaddr.style.border = '1px solid red'
					theform.emailaddr.focus();
					returnval=false //disallow form submission
					return false; 
					break //end loop. No need to continue.
				}
			}
		}
		theform[fieldnamez].style.border = ''
	}
	return returnval; 
}
function mtwmenu_open() {
	$(this).find('ul').eq(0).show();
	$(this).find('a').eq(0).addClass("selected");
}
function mtwmenu_close() {
	$(this).find('ul').eq(0).hide();
	$(this).find('a').eq(0).removeClass("selected");
}
$(document).ready(
	function() {
		$('#menu > li').bind('mouseover', mtwmenu_open);
		$('#menu > li').bind('mouseout',  mtwmenu_close);
	}
);
