// just testing for now
function showVideo(video_name) {
	var path = "http://images.rom.on.ca/public/video/";							// edit this if u ever move the video files
	var video = path + video_name;
	var my_window = null;
	
	my_window = window.open('',"newWin","width=333px,height=333px,left=0,top=0,titlebar=no,status=no,menubar=no,toolbar=no,scrollbars=yes,resizeable=yes");
	var out = my_window.document;
	out.open();
  	out.write('<html><head><title>ROM Images</title>');
	out.write('<link rel="stylesheet" href="images.css" type="text/css"></head>');
  	out.write('<body bgcolor="#ffffff" onLoad="window.focus()">');
  	out.write('<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">');
  	out.write('<tr><td align="center" valign="top" bgcolor="#ffffff">\n');
	
	out.write('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="270" HEIGHT="220">\n');
	out.write('<PARAM name="SRC" VALUE="' + video + '">\n');
	out.write('<PARAM name="AUTOPLAY" VALUE="true">\n');
	out.write('<PARAM name="CONTROLLER" VALUE="true">\n');
	out.write('<param name="loop" value="true">\n');
	out.write('<EMBED SRC="' + video + '" WIDTH="270" HEIGHT="220" loop="true" AUTOPLAY="true" CONTROLLER="true">\n');
	out.write('</EMBED>\n');
	out.write('</OBJECT>\n');

	out.write('</td></tr>');
	out.write('<tr><td height="30" align="center" valign="middle"><a href="JavaScript:parent.parent.close()" class="small">Close this window </a></td></tr>');
  	out.write('</table></body></html>');
  	out.close();
}

function detailText(detail_out) {				
	my_window = window.open('',"newWin","width=700px,height=400px,left=0,top=0,titlebar=no,status=no,menubar=no,toolbar=no,scrollbars=yes,resizeable=yes");
	var out = my_window.document;
	out.open();
  	out.write('<html><head><title>ROM Images</title>');
	out.write('<link rel="stylesheet" href="images.css" type="text/css"></head>');
  	out.write('<body bgcolor="#F0F0F0" onLoad="window.focus()">');
  	out.write('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
	if(detail_out){
		out.write('<tr><td align="left" valign="top" class="bodytext">');
		out.write(detail_out);
		out.write('</td></tr>');
	}  	
	out.write('<tr><td height="30" align="left" valign="middle"><a href="JavaScript:parent.parent.close()" class="small"><b>Close this window</b></a></td></tr>');
  	out.write('</table></body></html>');
  	out.close();
	
}



// validate required fields for making a non f500 image request
// apparently none of the fields are mandatory according to rights n repro coordinator. oct 15/2004 (dba)
// thus i can request a bunch of images n not provide rights n repro with anything at all. go figure ... 
function validate_personal_request(form){
	return true;
}

// validate select boxes in users cart. make sure theyve all been selected
function validate_cart(form){
	for(var i = 0; i < form.length; i++) {		
		var e = form.elements[i];
		var etype = e.type;
		if(etype == "select-one"){
			var evalue = e.value;
			if(!evalue){	
				alert('Form incomplete. Please provide all required information.');
				e.focus();
				return false;
			}			
		}		
	}	
}

// were lookin for the "image_number_" select box array with the productid appended to it, indexed by a loop counter. 
// image number select boxes are arrays. there could be many of them, bcuz 1 or many products can have 1 or many images
// gotta determine which select box u is refering to thus the confusion below
// arg "whichone" signifies which array of dropdown lists u selected
// put yer mouse over the link that calls this function for a better idea of how this  works (ie. function new_commorder_form())
function showThisImage(form,whichone,prodid){
	var theone = "[" + whichone + "]";
	var criteria = "image_number_|" + prodid + "|" + theone;
	for(var i = 0; i < form.length; i++) {		
		var e = form.elements[i];
		var etype = e.type;
		var ename = e.name;
		if(ename.indexOf(criteria) != -1 && etype == "select-one"){
			var imgname = e.value;
			if(imgname != ""){										// could be a null value thus ...
				var image_name = imgname + "_t.jpg";				// obviously for for thumbs only
				var width = 200;
				var height = 150;
				showImage(image_name,width,height);					// why rewrite what i already wrote ? 
			}
		}
	}
}

// tells u they are about to save an image to their folder
// if sid doesnt have value, u is not logged in thus tell them to log in 
function confirm_save(form){
	var sid = document.theform.sid.value;		
	if(!sid){
		alert('You must be a registered user to save image searches.\nTo create an account, click on \'Register\' in the top navigation bar.\nIf you already have an account, you need to first login.');
		return false;
	}
	else{
		var image = document.theform.js_image.value;		
		var w = document.theform.pid.selectedIndex;
		var folder_name = document.theform.pid.options[w].text;
		var msg = "Image " + image + " will be saved to " + folder_name + "\n\nDo you wish to continue?";
		if(confirm(msg)) return true;
		else return false;
	}
}

// prompts user re folder deletion
function confirm_delete(){
	var msg = "You are about to delete the selected folder and its contents!\n\nDo you wish to continue ?"
	if(confirm(msg))
		return true;
	else
		return false;
}

// 	ensures user entered something in folder text box of the create new folder form 
function check_new_folder_form(form){
	var folder = document.theform.folder.value;								
	if(folder.length == 0){
		alert('You must provide a valid folder name.');
		document.theform.folder.select();
		return false;
	}	
	// now validate folder
	var ValidChars = "&?_-'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	for(i = 0; i < folder.length; i++){
		if(ValidChars.indexOf(folder.charAt(i)) == -1){
			alert('Invalid folder name. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPlease try again.');
			document.theform.folder.select();
			return false;
		}			
	}			
	// now make sure its more than just white space
	var my_char = "";
	var my_string = "";
	for(i = 0; i < folder.length; i++){								
		my_char = folder.charAt(i);
		if(my_char != " ") {
			my_string += my_char;
		}
	}			
	if(my_string == "" ){
		alert('You must provide a valid folder name.');
		document.theform.folder.select();
		return false;
	}
	return true;
}

// validates advanced search form. text boxes have the same name as the corresponding checkbox values.
function validate_advanced_searchform(form){
	var num_checked = 0;
	var textname = "";
	var textbox_names = [0,0,0];	
			
	// determine how many checkboxes u selected
	for(var i = 0; i < form.length; i++) {
		var e = form.elements[i];
		if(e.type == "checkbox" && e.checked == true){		
			textname = e.value;
			textbox_names[num_checked] = textname;
			num_checked += 1;			
		}		
	}
		
	// if 0 or more than 3 selected, return false
	if(num_checked == 0 || num_checked > 3) {
		alert('You have selected ' + num_checked + ' checkboxes \nPlease select a minimum of 1 to a maximum of 3 checkboxes');
		return false;
	}
		
	// loop through textbox_names array and form and determine if corresponding text element is null. if so, return false
	for(var y = 0; y < num_checked; y++){	
		textname = textbox_names[y];
		for(var i = 0; i < form.length; i++) {
			var e = form.elements[i];
			if(e.type == "text" && e.name == textname && is_null(e)){
				alert("Invalid criteria");
				e.select();
				return false;
			}
		}		
	}	
	
	return true;		
}

// shows fullsize image in a new window in precisely the center of users screen. subtract the window width (w) and pixel width of 
// the side chrome borders (10) from the available screen width (chasm) and multiply by the x coordinate (.5)
// Then subtract the window height (h) and the pixel height of the top and bottom chrome (30) from the available screen 
// height (mount) and multiply by the y coordinate (.5)
function showImage(image_name,width,height) {
	var path = "http://images.rom.on.ca/public/images/";						// edit this if u ever move the image files
	var image = path + image_name;
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var w = parseInt(width) + 20;
	var pos_left = ((chasm - w - 10) * .5);
	var h = parseInt(height) + 45;										// remember to allow some height for our close link
	var top = ((mount - h - 30) * .5);	
	var my_window = null;
	
	my_window = window.open('',"newWin","width=" + w + ",height=" + h + ",left=" + pos_left + ",top=" + top + "titlebar=no,status=no,menubar=no,toolbar=no,scrollbars=no,resizeable=no");
	var out = my_window.document;
	out.open();
  	out.write('<html><head><title>ROM Images</title>');
	out.write('<link rel="stylesheet" href="images.css" type="text/css"></head>');
  	out.write('<body bgcolor="#F0F0F0" onLoad="window.focus()">');
  	out.write('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
  	out.write('<tr><td align="center" valign="top"><img src="' + image + '"></td></tr>');
	out.write('<tr><td height="30" align="center" valign="middle"><a href="JavaScript:parent.parent.close()" class="small">Close this window </a></td></tr>');
  	out.write('</table></body></html>');
  	out.close();
}

// formats a floating point number for decent looking output, which js doesn't provide in the least
function FormatNumber(Number,Decimals,Separator) {
	Number += ""          												// Force argument to string.
	Decimals += ""        												// Force argument to string.
	Separator += ""       												// Force argument to string.
	if((Separator == "") || (Separator.length > 1))
		Separator = "."
	if(Number.length == 0)
		Number = "0"
		
	var OriginalNumber = Number  										// Save for number too large.
	var Sign = 1
	var Pad = ""
	var Count = 0
																		// If no number passed, force number to 0.
	if(parseFloat(Number)){
		Number = parseFloat(Number)} 
	else{
		Number = 0
	}		
	if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){		// If no decimals passed, default decimals to 2.
		Decimals = parseInt(Decimals,10)} else {
		Decimals = 2}
		if(Number < 0){
			Sign = -1         											// Remember sign of Number.
			Number *= Sign    											// Force absolute value of Number.
		}
		if(Decimals < 0) Decimals *= -1 								// Force absolute value of Decimals.				   										
			// Next, convert number to rounded integer and force to string value.
			// (Number contains 1 extra digit used to force rounding)
			Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
			if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
				return(OriginalNumber) // Number too large to format as specified.
			// If length of Number is less than number of decimals requested +1,
			// pad with zeros to requested length.
			if(Number.length < Decimals +1){
				for(Count = Number.length; Count <= Decimals; Count++)
					Pad += "0"
			}
		Number = Pad + Number 										// Pad number as needed.
		if(Decimals == 0){											// Drop extra digit -- Decimal portion is formatted.			
			Number = Number.substring(0, Number.length -1)
		}else{														// Or, format number with decimal point and drop extra decimal digit.			
			Number = Number.substring(0,Number.length - Decimals -1) +
			Separator + Number.substring(Number.length - Decimals -1,Number.length -1)
		}
		if((Number == "") || (parseFloat(Number) < 1)) Number="0"+Number 	// Force leading 0 for |Number| less than 1.
		if(Sign == -1) Number = "-" + Number  								// Set sign of number.
	return(Number)
}

// 	ensures user entered something in the username and password text boxes of the client login form 
function Check_www_LoginForm(form){
	var ValidChars = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	var username = document.theform.username.value;								
	if(username.length == 0){
		alert('Please provide your username.');
		document.theform.username.select();
		return false;
	}
	for(i = 0; i < username.length; i++){
		if(ValidChars.indexOf(username.charAt(i)) == -1){
			alert('Invalid username. The following is a list of valid characters:\n\n' + ValidChars + '\n\nUsernames do not contain white space and are 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.username.select();
			return false;
		}			
	}			
	// now validate password	
	var pswd = document.theform.pswd.value;
	if(pswd.length == 0){
		alert('Please provide your password.');
		document.theform.pswd.select();
		return false;
	}
	for(i = 0; i < pswd.length; i++){
		if(ValidChars.indexOf(pswd.charAt(i)) == -1){
			alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords do not contain white space and are 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.pswd.select();
			return false;
		}			
	}			
	return true;
}

// prompts user re entire order cancellation
function CancelOrder(){
	var msg = "\n You are about to cancel the Entire Order !\n Do you wish to continue ?"
	if(confirm(msg))
		return true;
	else
		return false;
}

// prompts user re entire order cancellation
function CancelOrderDetail(){
	var msg = "\n You are about to cancel the selected image from this Order !\n Do you wish to continue ?"
	if(confirm(msg))
		return true;
	else
		return false;
}

// opens htmlpage 
function openWin(htmlpage) {
	var x = 0, y = 0;
	var directory = "html";													// edit this if u ever move the html files
	var page = directory + "/" + htmlpage ;
	win = window.open(page,"thewindow","width=600,height=400,status=no,menubar=no,toolbar=no,scrollbars=yes,resizeable=yes");
	//win.moveTo(x,y);
}

// helper function. tests for valid province 
// need 2 do this for the taxman
function is_valid_province(element){
	var upperstring = element.toUpperCase();			// convert the string u entered to upper case
	var parray = new Array();
	parray[0] = "Newfoundland and Labrador";
	parray[1] = "Prince Edward Island";
	parray[2] = "Nova Scotia";
	parray[3] = "New Brunswick";
	parray[4] = "Quebec";
	parray[5] = "Ontario";
	parray[6] = "Manitoba";
	parray[7] = "Saskatchewan";
	parray[8] = "Alberta";
	parray[9] = "British Columbia";
	parray[10] = "Yukon";
	parray[11] = "Northwest Territories";
	parray[12] = "NL";
	parray[13] = "PE";
	parray[14] = "NS";
	parray[15] = "NB";
	parray[16] = "QC";
	parray[17] = "MB";
	parray[18] = "SK";
	parray[19] = "AB";
	parray[20] = "BC";
	parray[21] = "YT";
	parray[22] = "NT"; 
	parray[23] = "ON"; 
	parray[24] = "Nunavut"; 
	parray[25] = "NU"; 	
	for(var i = 0; i < parray.length; i++){
		var upperarray = parray[i].toUpperCase();	
		if(upperstring == upperarray) 
			return true;
	}
	return false;
}

// validates NEW client form based on hidden var $type (either Personal or Commercial)
function Validate_wwwClient(form){
	var type = document.theform.type.value;									// the following are common in either case
	// first validate email field
	var email = document.theform.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(email)){
		alert('Invalid email address');
		document.theform.email.select();
		return false;
	}	
	// next validate passwords and username
	var username = document.theform.username.value;
	var pswd = document.theform.pswd.value;
	var pswd2 = document.theform.pswd2.value;
	var ValidChars = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	if(document.theform.username.value.length == 0 || document.theform.username.value.length > 12 || document.theform.username.value.length < 6){
		alert('Invalid username. The following is a list of valid characters:\n\n' + ValidChars + '\n\nYour username may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
		document.theform.username.select();
		return false;
	}	
	for(i = 0; i < username.length; i++){
		if(ValidChars.indexOf(username.charAt(i)) == -1){
			alert('Invalid username. The following is a list of valid characters:\n\n' + ValidChars + '\n\nYour username may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.username.select();
			return false;
		}			
	}			
	if(document.theform.pswd.value.length == 0 || document.theform.pswd2.value.length == 0 ||
	   document.theform.pswd.value.length > 12 || document.theform.pswd2.value.length > 12 ||
	   document.theform.pswd.value.length < 6 || document.theform.pswd2.value.length < 6 ){
		alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
		document.theform.pswd.select();
		return false;
	}
	for(i = 0; i < pswd.length; i++){
		if(ValidChars.indexOf(pswd.charAt(i)) == -1){
			alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.pswd.select();
			return false;
		}			
	}			
	for(i = 0; i < pswd2.length; i++){
		if(ValidChars.indexOf(pswd2.charAt(i)) == -1){
			alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.pswd2.select();
			return false;
		}			
	}			
	if(pswd != pswd2){
		alert('You have re-typed your password incorrectly.\nPlease try again.');
		document.theform.pswd2.select();
		return false;
	}
	
	// now validate first_name, last_name fields which are common in either case
	if(is_null(document.theform.first_name)){
		alert('Please provide your first name');
		document.theform.first_name.select();
		return false;
	}
	if(is_null(document.theform.last_name)){
		alert('Please provide your last name');
		document.theform.last_name.select();
		return false;
	}
				
	// now validate form according to type
	if(type == "Personal" ){
		if(is_null(document.theform.address)){
			alert('Please provide your address');
			document.theform.address.select();
			return false;
		}
		if(is_null(document.theform.city)){
			alert('Please provide your city.');
			document.theform.city.select();
			return false;
		}
		if(is_null(document.theform.zip_postal)){
			alert('Please provide your zip / postal code.');
			document.theform.zip_postal.select();
			return false;
		}
		if(is_null(document.theform.telephone)){
			alert('Please provide your telephone number.');
			document.theform.telephone.select();
			return false;
		}
	}
	else if(type == "Commercial" ){
		if(is_null(document.theform.company)){
			alert('Please provide the company name.');
			document.theform.company.select();
			return false;
		}
		if(is_null(document.theform.address)){
			alert('Please provide the company address.');
			document.theform.address.select();
			return false;
		}
		if(is_null(document.theform.city)){
			alert('Please provide company city.');
			document.theform.city.select();
			return false;
		}
		if(is_null(document.theform.zip_postal)){
			alert('Please provide company zip / postal code');
			document.theform.zip_postal.select();
			return false;
		}
		if(is_null(document.theform.telephone)){
			alert('Please provide the company telephone number');
			document.theform.telephone.select();
			return false;
		}
	}
	else return false;
	
	// if new client is from canada we need to get the province in order to later determine if the taxman gets their cut
	var valid_provinces = "Alberta - AB\nBritish Columbia - BC\nManitoba - MB\nNew Brunswick - NB\nNewfoundland and Labrador - NL\nNorthwest Territories - NT\nNova Scotia - NS\nNunavut - NU\nOntario - ON\nPrince Edward Island - PE\nQuebec - QC\nSaskatchewan - SK\nYukon - YT";
	var country = document.theform.country.value;	
	if(country == "Canada"){
		if(is_null(document.theform.state_prov)){
			alert('Please provide your province');
			document.theform.state_prov.select();
			return false;
		}
		var valid_province = is_valid_province(document.theform.state_prov.value);
		if(!valid_province){
			alert('The following are Canadian provinces and their abbreviations :\n\n' + valid_provinces + '\n\nPlease provide one.');
			document.theform.state_prov.select();
			return false;
		}
	}		
	return true;
}

// helper function. tests arg for null value
function is_null(element){
	if(element.value.length == 0){
		return true;
	} 	
	var my_char = "";
	var my_string = "";
	for(i = 0; i < element.value.length; i++){								// get rid of any spaces user may have entered
		my_char = element.value.charAt(i);
		if(my_char != " ") {
			my_string += my_char;
		}
	}			
	if(my_string == "" ){
		return true;
	}
}

// validate email address. called when user forgor password and is requesting we email them their password
function Check_Email(form){
	var email = document.the_form.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(email)){
		alert('Invalid email address');
		document.the_form.email.select();
		return false;
	}	
	return true;
}

// validates EXISTING client form based on hidden var $type (either Personal or Commercial)
function Validate_Client(form){
	var type = document.theform.type.value;		
	// validate password fields IF THEY HAVE ANYTHING IN THEM. if null user is not updating their password
	var username = document.theform.username.value;
	var current_pswd = document.theform.current_pswd.value;
	var pswd = document.theform.pswd.value;
	var pswd2 = document.theform.pswd2.value;

    if(pswd.length > 0 || pswd2.length > 0){   //BT FEB 01,2006
        if (current_pswd.length == 0){
          alert('Please provide your current password in order to change it');
          return false;
        }
        if(pswd.length == 0 || pswd2.length == 0){
          alert('You must re-type your new password');
          return false;
        }
    } //BT

	if(current_pswd.length > 0 && pswd.length > 0 && pswd2.length > 0){
		var ValidChars = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";		
		if(current_pswd.length > 12 || current_pswd.length < 6 || pswd.length > 12 || pswd2.length > 12 ||
		   pswd.length < 6 || pswd2.length < 6 ){
			alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
			return false;
		}		
		for(i = 0; i < current_pswd.length; i++){
			if(ValidChars.indexOf(current_pswd.charAt(i)) == -1){
				alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
				document.theform.current_pswd.select();
				return false;
			}			
		}			
		for(i = 0; i < pswd.length; i++){
			if(ValidChars.indexOf(pswd.charAt(i)) == -1){
				alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
				document.theform.pswd.select();
				return false;
			}			
		}			
		for(i = 0; i < pswd2.length; i++){
			if(ValidChars.indexOf(pswd2.charAt(i)) == -1){
				alert('Invalid password. The following is a list of valid characters:\n\n' + ValidChars + '\n\nPasswords may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
				document.theform.pswd2.select();
				return false;
			}			
		}			
		if(pswd != pswd2){
			alert('You have re-typed your new password incorrectly.\nPlease try again.');
			document.theform.pswd2.select();
			return false;
		}		
		if(username.length > 12 || username.length < 6 ){
			alert('Invalid username. The following is a list of valid characters:\n\n' + ValidChars + '\n\nYour username may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
			document.theform.username.select();
			return false;
		}		
		for(i = 0; i < username.length; i++){
			if(ValidChars.indexOf(username.charAt(i)) == -1){
				alert('Invalid username. The following is a list of valid characters:\n\n' + ValidChars + '\n\nYour username may not contain white space and must be from 6 to 12 characters in length.\n' +  'Please try again.');
				document.theform.username.select();
				return false;
			}			
		}					
	}
								
	// validate email field
	var email = document.theform.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(email)){
		alert('Invalid email address');
		document.theform.email.select();
		return false;
	}	
		
	// now validate first_name, last_name fields which are common in either case
	if(is_null(document.theform.first_name)){
		alert('Please provide your first name');
		document.theform.first_name.select();
		return false;
	}
	if(is_null(document.theform.last_name)){
		alert('Please provide your last name');
		document.theform.last_name.select();
		return false;
	}
	
	// now validate form according to type
	if(type == "Personal" ){
		if(is_null(document.theform.address)){
			alert('Please provide your address');
			document.theform.address.select();
			return false;
		}
		if(is_null(document.theform.city)){
			alert('Please provide your city.');
			document.theform.city.select();
			return false;
		}
		if(is_null(document.theform.zip_postal)){
			alert('Please provide your zip / postal code.');
			document.theform.zip_postal.select();
			return false;
		}
		if(is_null(document.theform.telephone)){
			alert('Please provide your telephone number.');
			document.theform.telephone.select();
			return false;
		}
	}
	else if(type == "Commercial" ){
		if(is_null(document.theform.company)){
			alert('Please provide the company name.');
			document.theform.company.select();
			return false;
		}
		if(is_null(document.theform.address)){
			alert('Please provide the company address.');
			document.theform.address.select();
			return false;
		}
		if(is_null(document.theform.city)){
			alert('Please provide company city.');
			document.theform.city.select();
			return false;
		}
		if(is_null(document.theform.zip_postal)){
			alert('Please provide company zip / postal code');
			document.theform.zip_postal.select();
			return false;
		}
		if(is_null(document.theform.telephone)){
			alert('Please provide the company telephone number');
			document.theform.telephone.select();
			return false;
		}
	}
	else return false;
		
	// if new client is from canada we need to get the province in order to later determine if the taxman gets their cut
	var valid_provinces = "Alberta - AB\nBritish Columbia - BC\nManitoba - MB\nNew Brunswick - NB\nNewfoundland and Labrador - NL\nNorthwest Territories - NT\nNova Scotia - NS\nNunavut - NU\nOntario - ON\nPrince Edward Island - PE\nQuebec - QC\nSaskatchewan - SK\nYukon - YT";
	var country = document.theform.country.value;	
	if(country == "Canada"){
		if(is_null(document.theform.state_prov)){
			alert('Please provide your province');
			document.theform.state_prov.select();
			return false;
		}
		var valid_province = is_valid_province(document.theform.state_prov.value);
		if(!valid_province){
			alert('The following are Canadian provinces and their abbreviations :\n\n' + valid_provinces + '\n\nPlease provide one.');
			document.theform.state_prov.select();
			return false;
		}
	}
		
	return true;
}	

// validates simple search form 
function validate_search_form(form){
	
	if(is_null(document.searchform.criteria)){
		alert('Please provide valid search criteria');
		document.searchform.criteria.select();
		return false;
	}
	
	var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ *;/+-_)(&^$#@!.,'\"";
	var criteria = document.searchform.criteria.value;
	
	for(i = 0; i < criteria.length; i++){
		if(ValidChars.indexOf(criteria.charAt(i)) == -1){
			alert('The following is a list of characters that make valid search criteria:\n\n' + ValidChars + '\n\nPlease try again.');
			document.searchform.criteria.select();
			return false;
		}			
	}		
	// ensure user didnt enter some white space and just the wild card 
	var my_char = "";
	var my_string = "";
	for(i = 0; i < criteria.length; i++){
		my_char = criteria.charAt(i);
		if(my_char != " ") {
			my_string += my_char;
		}
	}
	if(my_string == "*"){
		alert('Please provide valid search criteria');
		document.searchform.criteria.select();
		return false;
	}
	return true;
}
