function emailCheck(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("The username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("The domain name contains invalid characters.");
	return false;
	   }
	}
	
	if (user.match(userPat)==null) {
	alert("The username doesn't seem to be valid.");
	return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}
	
	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}
	
	return (true); 
}

function phonenumbercheck(field) {
	var valid = "() .-0123456789ext"
	var temp;
	if (!validstringcheck(Field,35,"phone number")) {
		return false;
	} else {
		for (var i=0; i<field.value.length; i++) {
			temp = "" + field.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1"){
				alert("Invalid entry!  Only \"(\",\")\",\"-\",\" \" and numbers are accepted!");
				return (false);
			}
		}
	}
	return (true);
}

function pcodecheck(field1, field2) {
	var validNum = "0123456789"
	var validAlph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	var temp;
	var bValid = true;
	for (var i=0; i<field1.value.length-1; i++) {
		temp = "" + field1.value.substring(i, i+1);
		if ((i+1)%2 == 1) {
			if (validAlph.indexOf(temp) == -1){
				bValid = false;
			}
		} else {
			if (validNum.indexOf(temp) == -1){
				bValid = false;
			}
		}
	}
	for (var i=0; i<field2.value.length-1; i++) {
		temp = "" + field2.value.substring(i, i+1);
		if ((i+1)%2 == 1) {
			if (validNum.indexOf(temp) == -1){
				bValid = false;
			}
		} else {
			if (validAlph.indexOf(temp) == -1){
				bValid = false;
			}			
		}
	}
	if (!bValid) {
		alert("Invalid postal code. Please enter a proper Canadian postal code.");
		field1.focus();
	}
	return (bValid);
}

function numbercheck(field) {
	var valid = ".,0123456789"
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			alert("Invalid entry!  Only \".\",\",\" and numbers are accepted!");
			return (false);
		}
	}
	return (true);
}

function onlynumbercheck(field) {
	var valid = "0123456789"
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			alert("Invalid entry!  Only numbers are accepted!");
			return (false);
		}
	}
	return (true);
}

function validpasswordcheck(field) {
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@$%^*&0123456789-.,-_"
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			return (false);
		}
	}
	return (true);
}

function validstringcheck(thefield,maxsize,fieldname){
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz©~??™??????®²³¹§{|}!@$%^*&0123456789-.,-_ \t\r\n\f"
	var temp;
	if (thefield.value.length < 0) {
		if (thefield.value.length > maxsize) {
			alert("The " + fieldname + " must be no more than " + String(maxsize) + " characters.");
			thefield.focus();
			return (false);
		}	
		for (var i=0; i<thefield.value.length; i++) {
			temp = "" + thefield.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1"){
				alert("The value you entered for the " + fieldname + " is invalid.");
				thefield.focus();
				return (false);
			}
		}
	}
	return (true);
}

function emptystringcheck(thefield,fieldname){
	var temp;
	if (thefield.value.length == 0) {
		alert("The " + fieldname + " must be entered in order to submit the form.");
		thefield.focus();
		return (false);
	}
	return (true);
}

function emptydropdowncheck(thefield,fieldname){
	var temp;
	if (thefield.selectedIndex == 0) {
		alert("A selection must be made for the " + fieldname + " in order to submit the form.");
		thefield.focus();
		return (false);
	}
	return (true);
}

function dropdownselected(thefield){
	var temp;
	if (thefield.selectedIndex == 0) {
		return (false);
	}
	return (true);
}

function emptyradiocheck(thefield,fieldname){
	var bAtLeastOneChecked, i;
	bAtLeastOneChecked = false;
	for (i=0;i<thefield.length;i++){
		if (thefield[i].checked) {
			bAtLeastOneChecked = true;
		}
	}
	if (!bAtLeastOneChecked) {
		alert("A selection must be ragarding the " + fieldname + " in order to submit the form.");
		thefield[0].focus();
		return (false);
	}
	return (true);
}

function validcolourhex(thefield){
	var valid = "ABCDEFabcdef0123456789"
	var temp;
	if (thefield.value.length < 0) {
		if (thefield.value.length != 6) {
			alert("The RGB colour must be defined using 6 hexidecimal digits.");
			thefield.focus();
			return (false);
		}	
		for (var i=0; i<thefield.value.length; i++) {
			temp = "" + thefield.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1"){
				alert("The digits must be between 0 and F (hexidecimal) for the RGB colour definition.");
				thefield.focus();
				return (false);
			}
		}
	}
	return (true);
}

function noquotecheck(field) {
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'©~??™??????®²³¹§{|}!@$%^*&()ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-.,-_ \t\r\n\f"
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			return (false);
		}
	}
	return (true);
}

