
function CheckForm(_name) {
	// Validation classes:
	// :: inputstring -> a textfield input with the class 'inputstring', checks to make sure it not empty
	// :: inputemail -> a textfield input with the class 'inputemail', checks to make sure it is a valid email address
	// :: textareastring -> a textarea with the class 'textareastring', checks to make sure it is not empty

// create array to contain items with an error
    var error_items = new Array();
	// clear error messages
	document.getElementById('errormsg').style.margin = '0';
	document.getElementById('errormsg').innerHTML = "";
    // get the form that needs to be validated
    var inputs = document.getElementsByTagName('input');
	// and iterate through them...
	for (var i=0;i<inputs.length;i++){
		if (inputs[i].className.indexOf('inputstring')>-1){
			inputs[i].className = inputs[i].className.replace("error","");
			if(inputs[i].value == ''){
				inputs[i].className += " error";
				var newErrorObj = new Object();
				newErrorObj.tagtype = 'input';
				newErrorObj.thisname = inputs[i].name;
				newErrorObj.thisclass = 'inputstring';
				error_items[error_items.length++] = newErrorObj;
			}
		} else if (inputs[i].className.indexOf('inputemail')>-1){
			inputs[i].className = inputs[i].className.replace("error","");
			if((inputs[i].value.length<6) || (inputs[i].value.indexOf(",")>0) || (inputs[i].value.indexOf(";")>0) || (inputs[i].value.indexOf(":")>0) || (inputs[i].value.indexOf("/")>0) || (inputs[i].value.indexOf(" ")>0) || (inputs[i].value.indexOf("@")==1) || (inputs[i].value.indexOf("@") != inputs[i].value.lastIndexOf("@")) || (inputs[i].value.lastIndexOf(".") < inputs[i].value.indexOf("@")) || ((inputs[i].value.lastIndexOf(".")+3) > inputs[i].value.length)){
				inputs[i].className += " error";
				var newErrorObj = new Object();
				newErrorObj.tagtype = 'input';
				newErrorObj.thisname = inputs[i].name;
				newErrorObj.thisclass = 'inputemail';
				error_items[error_items.length++] = newErrorObj;
			}
		}
	}
    var textareas = document.getElementsByTagName('textarea');
	// and iterate through them...
	for (var i=0;i<textareas.length;i++){
		if (textareas[i].className.indexOf("textareastring")>-1){
			textareas[i].className = textareas[i].className.replace("error","");
			if(textareas[i].value == ''){
				textareas[i].className += " error";
				var newErrorObj = new Object();
				newErrorObj.tagtype = 'input';
				newErrorObj.thisname = textareas[i].name;
				newErrorObj.thisclass = 'textareastring';
				error_items[error_items.length++] = newErrorObj;
			}
		}
	}
	if(error_items.length>0){
		document.getElementById('errormsg').style.margin = '10px 0 0';
		document.getElementById('errormsg').innerHTML += "<strong>Please fill in the following fields correctly:</strong><ul>";
		for(var i=0;i<error_items.length;i++){
			document.getElementById('errormsg').innerHTML += "<li>" + error_items[i].thisname + "</li>";
		}
		document.getElementById('errormsg').innerHTML += "</ul>";
		return false;
	} else {
		return true;	
	}
}

function checkMailinglistEmailAddress() {

	if(!echeck(document.mailingList.email.value)){
		//alert("Please enter a valid email address. (name@domain.domaintype)");
		//mySelect=document.getElementById("emailError");
		//mySelect.style.color = highlightColor;
		var x = document.getElementsByTagName('span');
		for (var i=0;i<x.length;i++){
			if (x[i].className == 'emailError'){
				x[i].style.display = 'block';
			//alert("onload " +x[i].className );
			}		
		}
		document.mailingList.email.focus();
		//return false;
	}
	else{
		document.mailingList.submit();
	}
}

function clearField(_theField, _theText) {
	if(_theField.value == _theText){
		document.mailingList.email.value = "";		
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}