function verify(f){
	/*
	Function to verify that all the elements have been filled or filled correctly.
	The name and details fields require filling if the submit button is pressed.
	The telephone and email fields are optional but if filled must be filled
	correctly	NOT WORKING CORRECTLY
	*/
	var msg;
	var validateMessage = "";
	var radioName = "";
	var rSetName;
//alert "we got to here";	//TAKE OUT THIS LINE
	for(var i=0;i<f.length;i++){		//for loop 0 to number of input elements on form
		var e = f.elements[i];		//assigns element value i to variable e
		
			//check radio buttons have been selected
		if (e.type=="radio") {
			rSetName = eval(f.name+"."+e.name);						//make an object reference
			if ((radioName == e.name) || (rSetName.optional)) {		//have we already looked at this array
				continue;
			}
			radioName = e.name;										//set the name of the array being processed
			if (checkRadio(rSetName)) {
				validateMessage += "\nPlease select a category";
			}
		}	//end of outer if
			//---------------------------------------
			//check if form element with name image to see if photo has been entered
		if (e.name=="image") {
			//check if the field is empty
			if((e.value==null)||(e.value=="")|| isBlank(e.value)){
				validateMessage +="\n You have not added a photo to be uploaded";  //adds text to the empty fields variable
			}	//end of inner if
		}	//end of outer if
			//---------------------------------------
			//check if form element name message has had soe text enetered however this is optional
		if (e.name=="message") {
			//check if the field is empty
			if((e.value==null) || (e.value=="overwrite this text with some text to accompany your photo...") || (e.value=="") || isBlank(e.value)){
				validateMessage +="\n You have not added any text with your photo";  //adds text to the empty fields variable
			}	//end of inner if
		}	//end of outer if
			//---------------------------------------
/*		if((e.name=="texttelephone") && (!isBlank(e.value))){
			for(var j=0;j<e.value.length;j++){
				var c = e.value.charAt(j);
				if(c < "0" ||c > "9"){			//check the value of variable c is not less than 0 or greater than 9
					j=e.value.length;
					validateMessage += "\n The telephone number requires all numbers with no spaces";
				}	//end of if
			}	//end of loop	
		}	//end of outer if
			//---------------------------------------
		if((e.name=="textemail") && (!isBlank(e.value))){
			if(!emailCheck(e.value)){
				validateMessage += "\n Your email address must contain @ and . ";
			}	//inner if		
		}	//end outer if	*/
	}//end for loop
			//---------------------------------------
	//if statement to display alert message if there are emprty fields
	if(!validateMessage){		//if there are no validation messages then next line
		return true;	//return true
	}	// end if

		//if there are empty fields then display fields in alert message
	msg = "___________________________________\n\n";
	msg+="The form has not been submitted because of the following....";
	msg+="\n";
	msg+=validateMessage;
	msg+= "\n_________________________________\n\n";
	alert(msg);
	return false;
}



//------------------------------------------------------------------------------------------------
function emailCheck(n){
/*
function  to check the email. IndexOf is to check the entered string.  If it can't find the
specified character it returns a value of -1.  n is the reference to the form element, and I 
am checking the value of that element.  Read this in javascript in easy steps by Mike McGrath
*/	
	if((n.indexOf("@")==-1) || (n.indexOf(".")==-1)) {
		return false;
	}
	return true;
}


//------------------------------------------------------------------------------------------------
function isBlank(s){
/*
checks to see if the field value is blank, tab or new line.  Reference to e.value from 
function verify is passed as s into this function which then checks the length of the value. 
*/
	for(var i=0;i<s.length;i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\t') && (c != '\n')){
			return false;
			}
	return true;
		}
}


/*###############################################################################################
The code below runs the stylesheet switching.  setActiveStyleSheet function is called from the 
access page and basically stores a cookie on the PC.  The function getActiveStyleSheet calls the
readcookie function. The cookie value is then used to disable all the stylesheets and enable 
the sheet according to the cookie value.
################################################################################################*/
function setActiveStyleSheet(f) {
	var mystyle = document.getElementsByTagName("link");
		for(var i=0;i<mystyle.length;i++){
			var e = mystyle[i];
			if(e.getAttribute("rel").indexOf("style")>-1 && e.getAttribute("title")){
				e.disabled=true;
				if(e.getAttribute("title")== f){
					e.disabled = false;
				}
			}
		}

	var cookievalue = "";
	var expirydate = new Date();
	expirydate.setDate(expirydate.getDate()+120);
	cookieValue = ";expires="+expirydate.toGMTString()+";";
	cookieValue += "path=/";
    document.cookie = "style="+escape(f)+";"+cookieValue;
}


window.onload = function getActiveStyleSheet(f) {
	var style = "";
	style = readcookie();
	var mystyle = document.getElementsByTagName("link");
		for(var i=0;i<mystyle.length;i++){
			var e = mystyle[i];
			if(e.getAttribute("rel").indexOf("style")>-1 && e.getAttribute("title")){
				e.disabled=true;
				if(e.getAttribute("title")==style){
					e.disabled = false;
				}
			}
		}
	if(style=="") {
		setActiveStyleSheet('default');
	}
}


//############################################################################
//This function reads the cookie details and stores them in a local variable
//cookieValue.  It then searches the index of the cookie to find start and end
//points.  The function returns the found/selected value.
function readcookie(){
var fieldValue="";
var cookieValue=document.cookie;
var pos=cookieValue.indexOf("=");
var start;
var end;
	if (pos!=-1){
	start=pos+1;
		end=cookieValue.indexOf(";",start);
		if (end==-1) {
			end=cookieValue.length;
		}
		fieldValue=unescape(cookieValue.substring(start,end));
	}
	return (fieldValue);
}
//###############################################################################


//function to send website feedback to designer
function webDetails() {
	text = "mailto:webdetails@hastingsmotorsheetmetalworks.com?subject=Web Site Feedback";
	text += "&body= Feedback to the website designer.......";
	location.href = text;
}


/*###############################################################################
function to open a new winow and display passed in data.  Used for popup window for
enlarging gallery images
Parameters : n - (type - string)
*/
function newWindow(n) {
	var temp = n;
	var stringArray = temp.split(",");
	var picture = "uploadedImages/" + stringArray[0];
	var altTag = stringArray[1];
	var myWindow = window.open("images.htm","uploadedImages","toolbar=no,scrollbars=yes,resizable=yes,width=800,height=650");
	myWindow.document.open;
	myWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>\n");	
	myWindow.document.write("<html>\n");
	myWindow.document.write("<head>\n");
	myWindow.document.write("<title>Hastings Motor Sheet Metal Works Gallery Image</title>\n");
	myWindow.document.write("<link href='../cssStyles/style1.css' rel='stylesheet' type='text/css' />\n");
	myWindow.document.write("</head>\n");
	myWindow.document.write("<body id='imagePopUp'>\n");
	myWindow.document.write("<img src=" + picture + "><br /><br />\n");
	myWindow.document.write(altTag);
	myWindow.document.write("<br /><br /><a href='javascript: onClick=window.close();'>Close</a>\n");
	myWindow.document.write("</body>\n");
	myWindow.document.write("</html>\n"); 
	myWindow.focus();
}



/*###############################################################################
function to open a new winow and display passed in data.  Used for popup window for
enlarging gallery images
Parameters : n - (type - string)
*/
function newWindow2(n) {
	var temp = n;
	var stringArray = temp.split(",");
	var	picture = stringArray[0];
	var altTag = stringArray[1];
	var myWindow = window.open("elva.htm","uploadedImages","toolbar=no,scrollbars=yes,resizable=yes,width=800,height=650");
	myWindow.document.open;
	myWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>\n");	
	myWindow.document.write("<html>\n");
	myWindow.document.write("<head>\n");
	myWindow.document.write("<title>Hastings Motor Sheet Metal Works ELva Gallery Image</title>\n");
	myWindow.document.write("<link href='../cssStyles/style1.css' rel='stylesheet' type='text/css' />\n");
	myWindow.document.write("</head>\n");
	myWindow.document.write("<body id='imagePopUp'>\n");
	myWindow.document.write("<img src=" + picture + "><br /><br />\n");
	myWindow.document.write(altTag);
	myWindow.document.write("<br /><br /><a href='javascript: onClick=window.close();'>Close</a>\n");
	myWindow.document.write("</body>\n");
	myWindow.document.write("</html>\n"); 
	myWindow.focus();
}
