//CSS functions.//Sets the className property of an element, to make it use a style class.function setClass(elementId,className) {document.getElementById(elementId).className = className;}//Sets the display property of an element to 'none', hiding it.function hideElement(elementId) {document.getElementById(elementId).style.display = "none";}//End of CSS functions.//Used to display a part record photo.function previewWindow(url) {var partWindow;/*If the window hasn't been created, or has been closed, we can create it.*/if ((!partWindow) || (partWindow.closed)) {	partWindow = window.open(url,'part_window','screenX=10,left=20,screenY=20,top=10,width=500,height=400,resizable=true,scrollbars=yes,titlebar=true');	}/*Else the window already exists and we simply need to update its url.*/else {	partWindow.location.href = url;	}/*Give the window focus to bring it to the front in case it was already open.*/partWindow.focus();}//Order list shopping cart functions.//Expiry date for cookies. 1 year in the future.var date = new Date();date.setTime(date.getTime()+(365*24*60*60*1000));//var expires = "; expires="+date.toGMTString();var expires = date.toGMTString();//Used to add items to the order list.function addOrder(idx) {/*Check if 'interpartOrders' cookie already exists.*/if (WM_readCookie('interpartOrders')) {	/*Read the cookie and save it as a variable.*/	theCookie = WM_readCookie('interpartOrders');	/*We're looking for a match on 'idx=X' where X is the idx argument. This would mean that the user has already added this part to their order list.*/	searchString = "idx=" + idx;	/*Search for an order where 'idx' matches the current part.*/	if (theCookie.indexOf(searchString) != -1) {		/*Split the cookie into individual orders.*/		ordersArray = theCookie.split('END');		/*Find the length of the ordersArray array.*/		arrayLength = ordersArray.length;		/8Use this to loop through each member of the array.*/		for (i = 0; i < arrayLength; i++) {			/*As before, we are looking for a match on 'idx=X'. This will find the matching order.*/			if (ordersArray[i].indexOf(searchString) != -1) {				/*Split the matched order item into its separate parts.*/				orderItem = ordersArray[i].split('&');				/*Get the current quantity value pair.*/				quantity = orderItem[1].split('=');				/*Update the quantity.*/				newQuantity = parseInt(quantity[1]);				newQuantity += 1;				/*Put the updated quantity back into the orderItem array.*/				orderItem[1] = "quantity=" + newQuantity;				/*Put the orderItem value back into the ordersArray array. We use i, the loop variable, as the array index, making sure the values go back into the correct place. We use the array.join() method to recreate the ordersArray value. The delimeter character is '&', matching the original.*/				ordersArray[i] = orderItem.join('&');							/*Update the cookie with the new value.*/				/*Create a variable to hold the new cookie value. As before, we create this by using the join() method. This time we take the values in the ordersArray array, joining them together using the delimeter 'END' to match the original format.*/				newCookieValue = ordersArray.join('END');				/*Set the cookie. Note the '/' in the domain argument. Without this we'd be limiting the cookie to the site folder it was set in.*/				WM_setCookie('interpartOrders', newCookieValue, expires,'/');				}			}		}	/*Else, we need add a new order item to the end of the list.*/	else {		/*Create a string to hold the value of the new order item.*/		newOrder = "idx=" + idx + "&quantity=1END";		/*Add this to the end of the current cookie value.*/		newCookieValue = theCookie + newOrder;		/*Set the cookie with the updated value.*/		WM_setCookie('interpartOrders', newCookieValue, expires,'/');		}	}/*If the cookie doesn't exist we need to create it.*/else {	cookieValue = "idx=" + idx + "&quantity=1END";	WM_setCookie('interpartOrders', cookieValue, expires,'/');	}/*Update the addButton icon to indicate that this part is in the user's order list. We do this by applying the 'itemInList' class to the appropriate link element.*/document.getElementById('addButton' + idx).className = "addToOrderActive";}/*This function is called whenever the quantity of an item in the order list is changed. First we check that a number has been entered, then we get the value of this. If it's 0 we call the deleteItem() function, otherwise we update the quantity using the entered value by calling the updateItem() function.*/function updateOrderItem(idx) {//First we get the value entered into the form element.quantityName = "quantity" + idx;quantityValue = document.getElementById(quantityName).value;//Then we check that it's actually a number.//If not a number.if(isNaN(quantityValue)) {	alert("Sorry.\nThe Quantity field must contain a number.");	}//Else, if it is a number.else {	/*Round the entered quantity value down to the nearest integer. We don't want fractions here.*/	newQuantity = Math.floor(quantityValue);	/*If the quantity is 0 we should actually delete this order item.*/	if (newQuantity == "0") {		deleteOrder(idx);		}	/*Else it's safe just to update the quantity.*/	else {		updateQuantity(idx);		}	}}//Used to update the quantity of an item in the order list.function updateQuantity(idx) {if (WM_readCookie('interpartOrders')) {	//Read the cookie and save it as a variable.	theCookie = WM_readCookie('interpartOrders');	/*We're looking for a match on 'idx=X' where X is the idx argument. This would mean that the user has already added this part to their order list.*/	searchString = "idx=" + idx;	//Search for an order where 'idx' matches the current part.	if (theCookie.indexOf(searchString) != -1) {		//Split the cookie into individual orders.		ordersArray = theCookie.split('END');		//Find the length of the ordersArray array.		arrayLength = ordersArray.length;		//Use this to loop through each member of the array.		for (i = 0; i < arrayLength; i++) {			/*As before, we are looking for a match on 'idx=X'. This will find the matching order.*/			if (ordersArray[i].indexOf(searchString) != -1) {				/*Split the matched order item into its separate parts.*/				orderItem = ordersArray[i].split('&');				/*Get the current quantity value pair.*/				quantity = orderItem[1].split('=');				/*Update the quantity.*/				/*Put the updated quantity back into the orderItem array.*/				orderItem[1] = "quantity=" + newQuantity;				/*Put the orderItem value back into the ordersArray array. We use i, the loop variable, as the array index, making sure the values go back into the correct place. We use the array.join() method to recreate the ordersArray value. The delimeter character is '&', matching the original.*/				ordersArray[i] = orderItem.join('&');							/*Update the cookie with the new value. Create a variable to hold the new cookie value. As before, we create this by using the join() method. This time we take the values in the ordersArray array, joining them together using the delimeter 'END' to match the original format.*/				newCookieValue = ordersArray.join('END');				/*Set the cookie. Note the '/' in the domain argument. Without this we'd be limiting the cookie to the site folder it was set in.*/				WM_setCookie('interpartOrders', newCookieValue, expires,'/');				/*Update the appropriate input field to reflect the new quantity value. This will only mean a change if the user entered a decimal number and we rounded it down to the nearest integer.*/				document.getElementById(quantityName).value = newQuantity;				/*UPDATE total price. Update the appropriate index in the subTotals array. The sub total is the item price * the new quantity value. The loop variable i is used to select the indices of the arrays.*/				subTotals[i] = itemPrices[i] * newQuantity;				/*Call the calculatePrice() function to update the total price.*/				calculatePrice();				/*Update the appropriate status indicator to provide a visual sign that the quantity has been changed.*/				statusIcon = "updateStatus" + idx;				document.getElementById(statusIcon).src = "../images/inlineEditing/success.gif";				}			}		}	}//If the order cookie doesn't exist.else {	alert("Sorry.\nThere has been a browser error.\nPlease check that your web browser supports cookies and javascript. It may be helpful to reload this page too.");	}}//Used to delete items from the order list.function deleteOrder(idx) {//Display a warning, allowing the user to cancel the delete.if (confirm("Are you sure you want to delete this order item?")) {//Check that the order cookie exists.	if (WM_readCookie('interpartOrders')) {		//Read the cookie and save it as a variable.		theCookie = WM_readCookie('interpartOrders');		//We're looking for a match on 'idx=X' where X is the idx argument.		//This would mean that the user has already added this part to their		//order list.		searchString = "idx=" + idx;		//Search for an order where 'idx' matches the current part.		if (theCookie.indexOf(searchString) != -1) {			//Split the cookie into individual orders.			ordersArray = theCookie.split('END');			//Find the length of the ordersArray array.			arrayLength = ordersArray.length;			//Use this to loop through each member of the array.			for (i = 0; i < arrayLength; i++) {				//As before, we are looking for a match on 'idx=X'. This will find				//the matching order.				if (ordersArray[i].indexOf(searchString) != -1) {					//Create a new array containing all members of the ordersArray					//array from index 0 up to the index just before the matching order.					var startSlice = ordersArray.slice(0,i);					//Create another new array containing all members of the ordersArray					//array from the index just after the matching order to the last index.					var endSlice = ordersArray.slice(i+1);					//Join these slice arrays to create a new orders array.					//We could have used the more specific splice() function for this,					//but it isn't supported in so many browsers. E.g. IE Win 5.					newOrders = startSlice.concat(endSlice);					//Update the cookie with the new value.					//Create a variable to hold the new cookie value. As before, we					//create this by using the join() method. This time we take the values					//in the newOrders array, joining them together using the delimeter					//'END' to match the original format.					newCookieValue = newOrders.join('END');					//Set the cookie. Note the '/' in the domain argument. Without this					//we'd be limiting the cookie to the site folder it was set in.					WM_setCookie('interpartOrders', newCookieValue, expires,'/');										//UPDATE TOTAL PRICE.					//Create a new array containing all members of the itemPrices					//array from index 0 up to the index just before the matching order.					//In effect we are deleting an index from each array.					var startSlice1 = itemPrices.slice(0,i);					//Create another new array containing all members of the itemPrices					//array from the index just after the matching order to the last index.					var endSlice1 = itemPrices.slice(i+1);					//Join these slice arrays to create a itemPrices array.					//We could have used the more specific splice() function for this,					//but it isn't supported in so many browsers. E.g. IE Win 5.					itemPrices = startSlice1.concat(endSlice1);					//Do the same again for the subTotals array.					var startSlice2 = subTotals.slice(0,i);					var endSlice2 = subTotals.slice(i+1);					subTotals = startSlice2.concat(endSlice2);					//Call the calculatePrice() function to update the total price.					calculatePrice();										//Update the appropriate status indicator to provide a visual					//sign that the quantity has been changed.					statusIcon = "updateStatus" + idx;					document.getElementById(statusIcon).src = "../images/inlineEditing/success.gif";					//For more advanced browsers we now hide the appropriate table					//row, providing a visual indication that the order has been deleted.					rowId = "orderRow" + idx;					hideElement(rowId);					}				}			}	}//If the order cookie doesn't exist.else {		alert("Sorry.\nThere has been a browser error.\nPlease check that your web browser supports cookies and javascript. It may be helpful to reload this page too.");		}}//End of confirm block.}//Used to check each part record being displayed against the contents//of the user's order cookie. If a match is found we provide a visual//indicator that the current part is already in the order list.//This function is called as each record set row is written. The equivalent//code is also used in addOrder();function orderIndicator(idx) {if(WM_readCookie('interpartOrders')) {	//Create a variable to hold the value of the cookie.	var theOrderCookie = WM_readCookie('interpartOrders');	//Create the string to use in our search. We're looking for a match	//with the current part record.	searchString = "idx=" + idx;	//If a match is found it means the user has already added this item to	//their order list.	if (theOrderCookie.indexOf(searchString) != -1) {		//Update the appropriate link element by applying the 'itemInList' class.		document.getElementById('addButton' + idx).className = "addToOrderActive";		}	}}/*Format prices to two decimal places. If IE Win 5 supported Number.toFixed() we wouldn't have to do all the following. Grr. Bloody Microsoft.*/function formatPrice(amount) {var i = parseFloat(amount);if(isNaN(i)) { i = 0.00; }var minus = '';if(i < 0) { minus = '-'; }i = Math.abs(i);i = parseInt((i + .005) * 100);i = i / 100;s = new String(i);if(s.indexOf('.') < 0) { s += '.00'; }if(s.indexOf('.') == (s.length - 2)) { s += '0'; }s = minus + s;return s;}//End of order list shopping cart functions.//Used by the form validation function.function isEmpty(inputStr) {if (inputStr == null || inputStr == "") {	return true	}else {	return false;	}}//Cookie functions.// This next little bit of code tests whether the user accepts cookies.var WM_acceptsCookies = false;if(document.cookie == '') {	document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {		WM_acceptsCookies = true;     }// If it succeeds, set variable.}else { // There was already a cookie.	WM_acceptsCookies = true;}function WM_setCookie(name, value, hours, path, domain, secure) {if (WM_acceptsCookies) {	var not_NN2 = (navigator && navigator.appName && (navigator.appName == 'Netscape') && navigator.appVersion && (parseInt(navigator.appVersion) == 2))?false:true;	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string		var numHours = hours;	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();	    }	}	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.    }} // WM_setCookiefunction WM_readCookie(name) {    if(document.cookie == '') { // there's no cookie, so go no further	return false;     } else { // there is a cookie	var firstChar, lastChar;	var theBigCookie = document.cookie;	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'	var NN2Hack = firstChar + name.length;	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie	    firstChar += name.length + 1; // skip 'name' and '='	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').	    if(lastChar == -1) lastChar = theBigCookie.length;	    return unescape(theBigCookie.substring(firstChar, lastChar));	} else { // If there was no cookie of that name, return false.	    return false;	}    }	} // WM_readCookiefunction WM_killCookie(name, path, domain) {  var theValue = WM_readCookie(name); // We need the value to kill the cookie  if(theValue) {      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie  }} // WM_killCookie//End of cookie functions./*Style switcher*/function setActiveStyleSheet(title,imageName) {  var i, a, main;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {      a.disabled = true;      if(a.getAttribute("title") == title) a.disabled = false;    }  }  //If the page has loaded it's safe to update the text size buttons.  if ((document.getElementById("textSmaller")) && (document.getElementById("textLarger"))) {  	updateAccessibility();  	}}function getActiveStyleSheet() {  var i, a;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");  }  return null;}function getPreferredStyleSheet() {  var i, a;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1       && a.getAttribute("rel").indexOf("alt") == -1       && a.getAttribute("title")       ) return a.getAttribute("title");  }  return null;}function createCookie(name,value,days) {  if (days) {    var date = new Date();    date.setTime(date.getTime()+(days*24*60*60*1000));    var expires = "; expires="+date.toGMTString();  }  else expires = "";  document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name) {  var nameEQ = name + "=";  var ca = document.cookie.split(';');  for(var i=0;i < ca.length;i++) {    var c = ca[i];    while (c.charAt(0)==' ') c = c.substring(1,c.length);    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);  }  return null;}window.onload = function(e) {  var cookie = readCookie("style");  var title = cookie ? cookie : getPreferredStyleSheet();  setActiveStyleSheet(title);}window.onunload = function(e) {  var title = getActiveStyleSheet();  createCookie("style", title, 365);}var cookie = readCookie("style");var title = cookie ? cookie : getPreferredStyleSheet();setActiveStyleSheet(title);//Update the text size buttons.function updateAccessibility() {var activeStyle = getActiveStyleSheet();if (document.getElementById) {	if (activeStyle == "bigText") {		document.getElementById("textSmaller").src = "/images/accessibility/textSmaller.gif";		document.getElementById("textLarger").src = "/images/accessibility/textLargerActive.gif";		}	else {		document.getElementById("textSmaller").src = "/images/accessibility/textSmallerActive.gif";		document.getElementById("textLarger").src = "/images/accessibility/textLarger.gif";		}	}}/*End of style switcher*/