function radiobuttonvalidation(entered, alertbox)
{
	// set var radio_choice to false
	var radio_choice = false;
	

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < entered.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (entered[counter].checked){
			radio_choice = true;
		}
	}

	if (!radio_choice){
		if (alertbox!=""){
			alert(alertbox);
		}
		return false;
	} else {
	return true;
	}
}

function emailvalidation(entered, alertbox)
{
	with (entered){
	
		if (value==null || value==""){
			return true;
		} else {
			apos=value.indexOf("@"); 
			dotpos=value.lastIndexOf(".");
			lastpos=value.length-1;
			
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2){
				if (alertbox){
					alert(alertbox);
				} 
				return false;
			} else {
				return true;
			}
		}
	}
} 

function valuevalidation(entered, min, max, alertbox, datatype)
{
	with (entered){
		checkvalue=parseFloat(value);
		if (datatype){
			smalldatatype=datatype.toLowerCase();
			if (smalldatatype.charAt(0)=="i"){
				checkvalue=parseInt(value);
			}
		}
		if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue){
			if (alertbox!=""){
			alert(alertbox);
			} 
			return false;}
		else {return true;
		}
	}
}

function digitvalidation(entered, min, max, alertbox, datatype)
{
	with (entered){
		if (value==null || value==""){
			return true;
		} else {
			checkvalue=parseFloat(value);
			if (datatype){
				smalldatatype=datatype.toLowerCase();
				if (smalldatatype.charAt(0)=="i"){
					checkvalue=parseInt(value); 
					if (value.indexOf(".")!=-1) {
					checkvalue=checkvalue+1;
					}
				}
			}
			if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue){
				if (alertbox!=""){
					alert(alertbox);
				} 
				return false;
			} else {
			return true;
			}
		}
	}
}

function emptyvalidation(entered, alertbox)
{
	with (entered){
		if (value==null || value==""){
			if (alertbox!=""){
			alert(alertbox);
			} 
			return false;
		} else {
		return true;
		}
	}
}

function formvalidation(thisform)
{
	if (thisform.name == "mailing_list") {
		with (thisform){
		if (emptyvalidation(Name,"Name is required")==false) {Name.focus(); return false;};
		if (emptyvalidation(Email,"Email address is required")==false) {Email.focus(); return false;};
		if (emailvalidation(Email,"Invalid E-mail address")==false) {Email.focus(); return false;};
		}
	}

	if (thisform.name == "email_form") {
		with (thisform){
		if (emptyvalidation(Subject,"Subject is required")==false) {Subject.focus(); return false;};
		if (emptyvalidation(Name,"From is required")==false) {Name.focus(); return false;};
		if (emptyvalidation(Email,"Email address is required")==false) {Email.focus(); return false;};
		if (emptyvalidation(Body,"Body is required")==false) {Body.focus(); return false;};
		}
	}

}

