function validNums(num) {
var validRegExp = "0123456789 -"; //telephone field can only contain these characters - this is called a regular expression
	if ((num=="") || (num==null)){ //makes sure telephone field is not empty
	return false;
	}
	for (i=0; i<num.length; i++) {
	digit = num.substring(i, i+1); //gets each character in turn from the telephone No entered by user
		if (validRegExp.indexOf(digit) == "-1"){ //checks against the valid range of allowed characters (indexOf=find string within string)
	 		return false;
		}
	}
}
//-->

<!-- Form Validator
function validator(form){

	if(notEmpty(form.firstname.value)==false){ //checks for empty first name field
		alert("Contact Information\n------------------------------------------\n\nYou did not enter your First Name.\nThis is a required field. \nPlease amend your input.");
		form.firstname.focus();
		return false
	}
	
	if(notEmpty(form.lastname.value)==false){ //checks for empty last name field
		alert("Contact Information\n------------------------------------------\n\nYou did not enter your Last Name.\nThis is a required field. \nPlease amend your input.");
		form.lastname.focus();
		return false
	}

//Contact email validation routine call
	mailStr=form.email
	mailValue=form.email.value
	if (! ( emailValidate(mailStr,mailValue,"Contact") ) ){
		return false
	}
	
	if(notEmpty(form.memo.value)==false){ //checks for empty last name field
		alert("Contact Information Error!\n------------------------------------------\n\nYou did not enter your message.\nThis is a required field. \nPlease amend your input.");
		form.memo.focus();
		return false
	}
	return true
}
// chckout_getInfo.cfm validation ends here -->

function emailValidate(mailStr,mailValue,alertName){ 
	
if(mailValue=="") { //checks for an empty e-mail field
		alert(alertName+" Information\n------------------------------------------\n\nPlease enter an e-mail address.")
		mailStr.focus()
		return false
	}
	
	x = String(mailValue) //evaluates 1st character for invalid entry
	y = x.substring(0,1) //extracts the 1st character of of the entered e-mail string
	var RefString="1234567890[]{};'#:@~,./<>?|\\`¬!\"£$%^&*()_+=- " //set up a regular expression
	if (RefString.indexOf (y) != -1) { //checks 1st character within reg expression
		alert(alertName+" Information\n-------------------------------------------------------------\n\nYou have entered an invalid E-mail format.\nE-mail addresses cannot begin with a numerical or\nspecial character.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	if(mailValue.indexOf("[",1) != -1) { //checks for existence of '[' character after 1st character as it is allowed
		alert(alertName+" Information\n-------------------------------------------------------------------\n\nYour e-mail contains a blank space or special character.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	var atPos = mailValue.indexOf("@",1) //checks for missing '@' character within email
	if (atPos == -1){
		alert(alertName+" Information\n-----------------------------------------------------------------------------------------\n\nPlease note! The '@' character cannot be found in the e-mail you entered.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	if (mailValue.indexOf("@",atPos+1)> -1){ //checks for more than 1 "@" character in an email
		alert(alertName+" Information\n-------------------------------------------------------------\n\nYour E-mail contains more than one \"@\" character.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	var dot = mailValue.substring(atPos, mailValue.length) //extracts the portion of the email after the "@" character
	dotPos = dot.indexOf(".",1) //looks for "." sign after 1st character
		if (dotPos == -1){ //checks for 1st "." sign
			alert(alertName+" Information\n-----------------------------------------------------------------------------------------------\n\nPlease note! The '.' (dot) character cannot be found in the e-mail you entered.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	/*if (dot_b.indexOf(".",dotPos_b+1)> -1){ //checks for more than 1 "@" character in an email. Not used domain name routine covers this
		alert("Contact Information\n-------------------------------------------------------------\n\nYour E-mail contains more than one \".\" character after the \"@\" character.\nPlease amend your input.")
		form.b_email.focus()
		form.b_email.select()
		return false
	}*/

	var combination = "" //checks or invalid characters before the '@' character
	var CombString="[]{};'#:~,./<>?|\\`¬!\"£$%^&*()_+=-"
	a = mailValue.indexOf("@")
	prevChar = mailValue.substring(a-1, a)
	if (CombString.indexOf(prevChar) != -1){
		alert(alertName+" Information\n-----------------------------------------------------------\n\nPlease note! The '@' character cannot follow any\nspecial character or space in an e-mail address.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}

	var combination = "" //checks missing domain names
	var CombString="0123456789[]{};'#:~,/<>?|\\`¬!\"£$%^&*()_+=-_."
	var a = mailValue.indexOf("@")
	var nextChar = mailValue.substring(a+1, a+2)
	if (CombString.indexOf(nextChar) != -1){
		alert(alertName+" Information\n-------------------------------------------------------------\n\nMissing domain name between the '@' and '.' (dot)\nor special character entered after \"@\" the sign.\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	
	var CombString = "[]{};'#:~,/<>?|\\`¬!\"£$%^&*()+= " //checks invalid characters after 1st character
	for (i=0; i<mailValue.length; i++){
	var tempStr = mailValue.substring(i,i+1)
		if (CombString.indexOf(tempStr)> -1){
			alert(alertName+" Information\n-------------------------------------------------------------------\n\nYour e-mail contains a blank space or special character.\nPlease amend your input.")
			mailStr.focus()
			mailStr.select()
			return false
		}
	}

	var dot = mailValue.substring(atPos, mailValue.length) //extracts the portion of the email after the "@" character
	var dotPos = dot.indexOf(".",1) //looks for "." sign after 1st character
	var count=dotPos+1 //add 1 to begin counting past the '.' sign
	var domain="" //initialises variable 'domain'
	for(count; count<dot.length; count++){ //builds the complete somain name string ie @yahoo.com
		domain=domain+dot.charAt(count)		
	}
	//dom is an array that holds domain names to be checked against
	dom=new Array("au","com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum","co.uk")
	var error="yes"
	for(k=0; k<dom.length; k++) { 
		if(domain==dom[k]) { //checks current value of entered domain with stored domain names in array
			k=dom.length //if found the error message switch is set to 'no' to prevent error message from displaying
			error="no"
		}
	}
	if((error=="yes" && (domain.length>2)) || (domain.length<2)) { //makes sure if error message is to be displayed
		alert(alertName+" Information\n-----------------------------------------------------------------\n\nDomain name must end with well known domains or\n2-lettered country name. eg com,edu,au,co.uk etc\nPlease amend your input.")
		mailStr.focus()
		mailStr.select()
		return false
	}
	return true	
}


// Support Functions
function strip(filter,str){
	var i,curChar;
	var retStr = '';
	var len = str.length;
	for(i=0; i<len; i++){
		curChar = str.charAt(i);
		if(filter.indexOf(curChar)<0) //not in filter, keep it
			retStr += curChar;
	}
	return retStr;
}
function reformat(str){
	var arg;
	var pos = 0;
	var retStr = '';
	var len = reformat.arguments.length;
	for(var i=1; i<len; i++){
		arg = reformat.arguments[i];
		if(i%2==1)
			retStr += arg;
		else{
			retStr += str.substring(pos, pos + arg);
			pos += arg;
		}
	}
	
	
	return retStr;
}
//End Support Functions
//Validation Rules
function notEmpty(str){
	if(strip(" \n\r\t",str).length ==0)
		return false;
	else
		return true;
}
function validateInteger(str){
	str = strip(' ',str);
	//remove leading zeros, if any
	while(str.length > 1 && str.substring(0,1) == '0'){
		str = str.substring(1,str.length);
	}
	var val = parseInt(str);
	if(isNaN(val))
		return false;
	else
		return true;
}
function validateFloat(str){
	str = strip(' ',str);
	//remove leading zeros, if any
	while(str.length > 1 && str.substring(0,1) == '0'){
		str = str.substring(1,str.length);
	}
	var val = parseFloat(str);
	if(isNaN(val))
		return false;
	else
		return true;
}
function validateUSPhone(str){
	str = strip("*() -./_\n\r\t\\",str);
	if(str.length == 10 || str.length == 7)
		return true;
	else
		return false;
}
function validateSSN(str){
	str = strip(" -.\n\r\t",str);
	if(validateInteger(str) && str.length == 9)
		return true;
	else
		return false;
}
function validateZip(str){
	str = strip("- \n\r\t",str);
	if(validateInteger(str)&&(str.length==9 || str.length==5))
		return true;
	else
		return false;
}
function validateCC(str,type){
	str = strip("-./_\n\r\t\\",str);
	if(type=="1")
		if(str.charAt(0)!="4")
			return false;
	if(type=="2")
		if(str.charAt(0)!="5")
			return false;
	if(type=="3")
		if(str.charAt(0)!="6")
			return false;
	if(type=="4")
		if(str.charAt(0)!="3")
			return false;
	if(validateInteger(str)&&((str.length==15&&type=="4") || str.length==16))
		return true;
	else
		return false;
}
function validateDate(str){
	var dateVar = new Date(str);
	if(isNaN(dateVar.valueOf()) || (dateVar.valueOf() ==0))
		return false;
	else
		return true;
}
function validateEMail(str){
	str = strip(" \n\r\t",str);
	if(str.indexOf("@")>-1 && str.indexOf(".")>-1)
		return true;
	else
		return false;
}
//End Validation Rules
//Formatting functions
function formatPhone(str){
	str = strip("*() -./_\n\r\t\\",str);
	if(str.length==10)
		return reformat(str,"(",3,") ",3,"-",4);
	if(str.length==7)
		return reformat(str,"",3,"-",4);
}
function formatSSN(str){
	str = strip(" -.\n\r\t",str);
	return reformat(str,"",3,"-",2,"-",4);
}
function formatZip(str){
	str = strip("- \n\r\t",str);
	if(str.length==5)
		return str;
	if(str.length==9)
		return reformat(str,"",5,"-",4);
}
function formatCC(str,type){
	str = strip("-./_\n\r\t\\",str);
	switch(type){
		case "1": 
			return reformat(str,"",4,"-",4,"-",4,"-",4);
			break;
		case "2": 
			return reformat(str,"",4,"-",4,"-",4,"-",4);
			break;
		case "3": 
			return reformat(str,"",4,"-",4,"-",4,"-",4);
			break;
		case "4":
			return reformat(str,"",4,"-",6,"-",5);
	}
}
function formatDate(str,style){
	var dateVar = new Date(str);
	var year = dateVar.getYear();
	if(year<10)
		year += 2000;
	if(year<100)
		year += 1900;
	switch(style){
		case "MM/DD/YY":
			return (dateVar.getMonth() + 1) + "/" + dateVar.getDate() + "/" + year;
			break;
		case "DD/MM/YY":
			return dateVar.getDate() + "/" + (dateVar.getMonth() + 1) + "/" + year;
			break;
		case "Month Day, Year":
			return getMonthName(dateVar) + " " + dateVar.getDate() + ", " + year;
			break;
		case "Day, Month Day, Year":
			return getDayName(dateVar) + ", " + getMonthName(dateVar) + " " + dateVar.getDate() + ", " + year;
			break;
		default:
			return (dateVar.getMonth() + 1) + "/" + dateVar.getDate() + "/" + year;
			break;
	}
}
//End Formatting Functions

// Reset as an image button begins here
var resetRolls = new Object();
function resetimage(src)
{
this.src=src;
this.confirm=true;
this.alt="Reset form fields to intial values";
this.write=resetimage_write;
}
function resetimage_write()
{
document.write('<A ');
if (this.rollover)
{
if (! this.name)
{
alert('to create a rollover you must give the image a name');
return;
}
resetRolls[this.name] = new Object();
resetRolls[this.name].over = new Image();
resetRolls[this.name].over.src=this.rollover;
resetRolls[this.name].out = new Image();
resetRolls[this.name].out.src=this.src;
document.write(
' onMouseOver="if (document.images)document.images[\'' + 
this.name + '\'].src=resetRolls[\'' + this.name + '\'].over.src"' + 
' onMouseOut="if (document.images)document.images[\'' + 
this.name + '\'].src=resetRolls[\'' + this.name + '\'].out.src"'
);
}
document.write(' HREF="javascript:');
if (this.confirm)
//document.write('if(confirm(\'Are you sure you want to reset?\'))');
document.write(
'document.forms[' + 
(document.forms.length - 1) + '].reset();void(0);">');
document.write('<IMG SRC="' + this.src + '" ALT="' + this.alt + '"');
document.write(' BORDER=0');
if (this.name)document.write(' NAME="' + this.name + '"');
if (this.height)document.write(' HEIGHT=' + this.height);
if (this.width)document.write(' WIDTH=' + this.width);
if (this.otheratts)document.write(' '+ this.otheratts);
document.write('></A>');
}
// Reset as an image button ends here

// profanity check starts here
function checkForProfanity(elnum) {
var k = 23;
var isProfane = new makeArray(k);
var word = new makeArray(k);
var temp = document.forms[0].elements[elnum].value;
temp = temp.toLowerCase();
word[1] = "shit";
word[2] = "nerd";
word[3] = "stupid";
word[4] = "ass";
word[5] = "cunt";
word[6] = "suck";
word[7] = "pussy";
word[8] = "cock";
word[9] = "cum";
word[10] = "penis";
word[11] = "nuts";
word[12] = "dick";
word[13] = "fuck";
word[14] = "ass";
word[15] = "fag";
word[16] = "idiot";
word[17] = "asshole";
word[18] = "bitch";
word[19] = "gimp";
word[20] = "freak";
word[21] = "wanker";
word[22] = "clitoris";
word[23] = "prat";
for (var j = 1; j <= k; j++) {
isProfane[j] = temp.indexOf(word[j]);
}
for (var j = 1; j <= k; j++) {
   if (isProfane[j] != -1) {
	  alert("Please refrain from using the word \'"+word[j]+"\'.");
      document.forms[0].elements[elnum].value = "";
      j = k + 1;
      document.forms[0].elements[elnum].focus();
       }
   else {}
}
}
function makeArray(n) {
   this.length = n
   for (var i = 1; i<=n; i++) {
       this[i] = new String();
   }
   return this
}
// profanity check ends here
