function emailvalidation(entered, alertbox) {
	with (entered) {
		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) {
		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 selectvalidation(entered, alertbox) {
	with (entered) {
		if (selectedIndex==0) {
			if (alertbox!="") {
				alert(alertbox);
			}
			return false;
		}
		else {
			return true;
		}
	}
}

function radiovalidation(entered, alertbox,length) {
	flag=false;
	for (i=0;i<length;i++) {
		if (entered[i].checked) {
			flag=true;
		}
	}

	if (!flag) {
		if (alertbox!="") {
			alert(alertbox);
		}
	}

	return flag;
}

function formvalidation(thisform) {
	with (thisform) {
		if (emptyvalidation(company,"Please fill in your company name")==false) {
			company.focus();
			return false;
		}
//		if (emptyvalidation(address,"Please fill in your company address")==false) {
//			address.focus();
//			return false;
//		}
		if (emptyvalidation(contact,"Please fill in your person to contact")==false) {
			contact.focus();
			return false;
		}
		if (emptyvalidation(phone,"Please fill in your telephone number")==false) {
			phone.focus();
			return false;
		}
		if (emailvalidation(email,"Please fill in a valid email address")==false) {
			email.focus();
			return false;
		}
		if (emptyvalidation(enquiries,"Please fill in your enquiries")==false) {
			enquiries.focus();
			return false;
		}
	}
}
