// Version 2.012
// Jonathan Maxwell Copyright 2005-2008
// Updated 20 August 2008

	// Required * Do not remove *
	var FieldsChanged = new Array();

	function isDate(value){
		// Checks date format
		return (!isNaN (new Date (value).getYear()) ) ;
	}

	function isValidEmail (emailStr) {
		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) return false;
		
		var user=matchArray[1]
		var domain=matchArray[2]
		
		// See if "user" is valid 
		if (user.match(userPat)==null) return false;
		
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			// this is an IP address
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) return false;
			}
			return true;
		}
		
		// Domain is symbolic name
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false
		}
		
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
		   return false
		}
		
		if (len<2) return false;
		
		return true;
	}
	
	function CDate(str){
		// Converts format dd mmmmm yyyy to date
		var DD = str.substring(0,2);
		var MM = str.substring(3,str.indexOf(" ",4));
		MM = GetDateMonth(MM,false);
		var YYYY = str.substring(str.indexOf(" ",4));

		var d = new Date();
		d.setFullYear(YYYY,MM,DD);
		return d;
	}
	
	function GetDateDay(dayval){
		// Gets correctly formatted day
		dayval = (dayval!=null&&dayval<10&&dayval>=0?"0":"") + dayval
		return dayval;
	}
	
	function GetDateMonth(monthval,getnumber){
		// Gets Javascript month number
		if (getnumber){
			switch (monthval){
				case 0:
					monthval="January";
					break;
				case 1:
					monthval="February";
					break;
				case 2:
					monthval="March";
					break;
				case 3:
					monthval="April";
					break;
				case 4:
					monthval="May";
					break;
				case 5:
					monthval="June";
					break;
				case 6:
					monthval="July";
					break;
				case 7:
					monthval="August";
					break;
				case 8:
					monthval="September";
					break;
				case 9:
					monthval="October";
					break;
				case 10:
					monthval="November";
					break;
				case 11:
					monthval="December";
					break;
			
			}
		}else{
			switch (monthval.toLowerCase()){
				case "jan": case "january":
					monthval=0;
					break;
				case "feb": case "february":
					monthval=1;
					break;
				case "mar": case "march":
					monthval=2;
					break;
				case "apr": case "april":
					monthval=3;
					break;
				case "may": case "may":
					monthval=4;
					break;
				case "jun": case "june":
					monthval=5;
					break;
				case "jul": case "july":
					monthval=6;
					break;
				case "aug": case "august":
					monthval=7;
					break;
				case "sep": case "september":
					monthval=8;
					break;
				case "oct": case "october":
					monthval=9;
					break;
				case "nov": case "november":
					monthval=10;
					break;
				case "dec": case "december":
					monthval=11;
					break;
			}
		}
		return(monthval);
	}

	function GetDateWeek(weekval,getnumber){
		// Gets Javascript week number
		if (getnumber){
			switch (weekval){
				case 0:
					dayval="Sunday";
					break;
				case 1:
					dayval="Monday";
					break;
				case 2:
					dayval="Tuesday";
					break;
				case 3:
					dayval="Wednesday";
					break;
				case 4:
					dayval="Thursday";
					break;
				case 5:
					dayval="Friday";
					break;
				case 6:
					dayval="Saturday";
					break;
			
			}
		}else{
			switch (dayval.toLowerCase()){
				case "sun": case "sunday":
					dayval=0;
					break;
				case "mon": case "monday":
					dayval=1;
					break;
				case "tue": case "tuesday":
					dayval=2;
					break;
				case "wed": case "wednesday":
					dayval=3;
					break;
				case "thu": case "thursday":
					dayval=4;
					break;
				case "fri": case "friday":
					dayval=5;
					break;
				case "sat": case "saturday":
					dayval=6;
					break;
				
			}
		}
		return(dayval);
	}

	function FixInput(str){
		// Gets rid of non-alphanumeric and removes spaces
		return str.replace(/[^0-9a-zA-Z]/gi,"");
	}

	function FixInputWithSpaces(str){
		// Gets rid of non-alphanumeric and includes spaces
		return str.replace(/[^0-9a-zA-Z\s]/gi,"");
	}
	
	function FixApostrophe(theString){
		// Replaces ' with ascii code equivalent'
		var strTemp = "";
		if (theString != null){
			strTemp = theString.toString();
			strTemp = Replace(strTemp,"'","&#39;");
			strTemp = Replace(strTemp,'"',"&#34;");
			strTemp = Replace(strTemp,",","&#44;");

			return trim(strTemp);
		}else{
			return null;
		}
	}
	
	function Request( name ){
		// URL Paramaters
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null ) 
			return "";  
		else    
			return results[1];
	}
	
	function GetCountryCode(Country,ReturnType){
		// Checks XML file of countries and codes ands returns
		// either matching code or country name
		// Country = either name or code of country
		// ReturnType = either 'code' or 'name'
		
		if (!window.ActiveXObject) return "";
		
		// IE only
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.load("../shop/country_codes.xml");
		
		var TempCountryCode = "";
		var TempCountryName = "";
		
		var CountryCodeArray = xmlDoc.selectNodes("/countries/country");
		for (var i=0;i < CountryCodeArray.length;i++){
			TempCountryCode = CountryCodeArray[i].childNodes(0).text;
			TempCountryName = CountryCodeArray[i].childNodes(1).text;
			
			if (ReturnType.toLowerCase() == "name"){
				if (TempCountryCode.toLowerCase() == Country.toLowerCase()) return TempCountryName;				
			}else{
				if (TempCountryName.toLowerCase() == Country.toLowerCase()) return TempCountryCode;
			}
		}		

		return "";
	}

	function IsCountryInRegion(Country,Region){
		// Checks XML file of country code and regions
		// Returns true if in selected region
		
		var xmlDoc;
		
		if (window.ActiveXObject){// code for IE
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
			return true;
		}else{
			return true;
		}

		xmlDoc.async = "false";
		xmlDoc.load("../shop/country_codes.xml");
		
		var TempCountryRegion = "";
		
		var CountryRegionArray = xmlDoc.selectNodes("/countries/country[paypalcode='" + Country + "']/regions");
		for (var i=0;i <= CountryRegionArray.length;i++){
			TempCountryRegion = CountryRegionArray[0].childNodes(i).text;
			if (TempCountryRegion.toLowerCase() == Region.toLowerCase()) return true;				
		}		

		return false;
	}
	
	function MultiArray(iRows,iCols) { 
		var i; 
		var j; 
		var a = new Array(iRows); 
		for (i=0; i < iRows; i++) { 
		   a[i] = new Array(iCols); 
		   for (j=0; j < iCols; j++){ 
			   a[i][j] = ""; 
		   } 
		} 
		return(a); 
	} 
	
	function CheckPageName(that, BlankAlert, Message){
		// Checks page name is valid	
		var PageName = that.value;
		if (AlphaNumeric(PageName)==false || (BlankAlert && PageName == "")){
			//alert(Message);
			//that.focus();
		}

	}
	
	
	function AlphaNumeric(alphane)
		{
			var numaric = alphane;
			for(var j=0; j<numaric.length; j++)
				{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==32))
				  {
				  }
				else	{
					 return false;
				  }
				}
		 return true;
		}
	
	
	function DiscountDealDisabled(that,OptionName){
		// Checks if associated product options are disabled and then enables them if option selected
		for (var i=0;i<that.form.elements.length;i++){
			if (that.form.elements[i].name == OptionName){if((that.checked) ? that.form.elements[i].disabled = false : that.form.elements[i].disabled = true);}
		}
	}

	
	function PasswordReminder(thatForm){
		var URL;
		URL = "http://www.orderhistorysoftware.com/orderhistory/ohy/passwordreminder.asp?";
		URL += "LoginUsername="+ escape(thatForm.LoginUsername.value);
		URL += "&MMCustomerID=" + escape(thatForm.MMCustomerID.value);
		URL += "&Subject=" + escape(thatForm.Subject.value);
		URL += "&Message=" + escape(thatForm.Message.value);
		URL += "&FromEmail=" + escape(thatForm.FromEmail.value);
		URL += "&FromName=" + escape(thatForm.FromName.value);
		document.location.href = URL;
	
	}

	function Left(str, n){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}
	
	function Right(str, n){
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
	}
	
	
	function URLDecode(psEncodeString) {
	  // Create a regular expression to search all +s in the string
	  var lsRegExp = /\+/g;
	  // Return the decoded string
	  return unescape(String(psEncodeString).replace(lsRegExp, " ")); 
	}
	
	function URLEncode(sStr) {
		return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
	}

	function SetRowBackground (childCheckbox) {
		var row = childCheckbox.parentNode;
		while (row && row.tagName.toLowerCase() != 'tr') {
			row = row.parentNode;
		}
		
		if (row && row.style) {
			if (childCheckbox.checked) {
				row.style.backgroundColor = "orange";
			}else {
				row.style.backgroundColor = '';
			}
		}
	}
	
	function Currency(dbAmount) { 
		// returns the amount in the .99 format 
		dbAmount -= 0; 
		dbAmount = (Math.round(dbAmount*100))/100; 
		return (dbAmount == Math.floor(dbAmount)) ? dbAmount + '.00' : ( (dbAmount*10 == Math.floor(dbAmount*10)) ? dbAmount + '0' : dbAmount); 
	} 
	
	function trim(strText) { 
		// this will get rid of leading spaces 
		while (strText.substring(0,1) == ' ') 
			strText = strText.substring(1, strText.length);
	
		// this will get rid of trailing spaces 
		while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
	
	   return strText;
	}
	

	function CheckForm(thatForm){
		// Checks if form has been changed
		if (thatForm.RecordsChanged.value != ""){
			var agree=confirm("Information has been changed on this page without saving.\nDo you wish to continue without saving?");
			if (agree)
				return true ;
			else
				return false ;
			}
	}

	function FormUpdated(thatForm,field){
		// Changes hidden form to indicate if form has been changed
		if (field=='CurrentStatus'){
			thatForm.CurrentStatusChanged.value = "true";
		}
		thatForm.RecordsChanged.value = "true";
		
		// Adds to array of fields changed
		FieldsChanged[FieldsChanged.length] = field;

		var CleanList = CleanArray(FieldsChanged);
		thatForm.RecordsChanged.value = CleanList;
		//alert(thatForm.RecordsChanged.value)
	}

	function CleanArray(arr){
		
		var newArray = new Array(); 
		arr.sort(); 
		
		var lgn = arr.length; 
		var j = 1; 
		var t = 0; 
		var temp = 0; 
		
		if (lgn>1){
			var tempfirst = arr[0];
			for(j = 1; j <= lgn; j++){ 
				temp = arr[j-1]; 
				if(temp == arr[j%lgn]){ 
					continue; 
				} 
		
				newArray[t++] = temp; 
			
			} 
		}else{
			newArray[0] = arr[0];
		}

		if (newArray.length == 0) newArray = tempfirst;
		return newArray;
	} 

	// Dynamic show/hide layers
	function SwitchMenu(obj, div){
		if(document.getElementById){	
		var el = document.getElementById(obj);
		var ar = document.getElementById(div).getElementsByTagName("span"); 
			if(el.style.display != "block"){ 
				for (var i=0; i<ar.length; i++){
					if (ar[i].className=="submenu") 
					ar[i].style.display = "none";
				}
				el.style.display = "block";
			}else{
				el.style.display = "none";
			}
		}
	}
	
	// Dynamic show/hide layers for Action panel
	function ActionSettings(ActionType,div){
		SwitchMenu("ActionSettings"+ActionType,div);
	}
	
	// Gets MMOrderID(s) for Action settings
	function ActionSubmit(thatForm,thatFormOrders){
		var strTempMMOrderID = "";
		if (thatFormOrders.Action){
		
			for (var i=0;i<thatFormOrders.Action.length;i++){
				if (thatFormOrders.Action[i].checked) {
					strTempMMOrderID += thatFormOrders.Action[i].value + ",";
				}	
			}
			
			if (thatFormOrders.Action.length==undefined && thatFormOrders.Action.checked) {
				// Only one row
				strTempMMOrderID = thatFormOrders.Action.value;
			}else{			
				// Gets rid of last comma for multiple rows
				if(strTempMMOrderID=="") return false;
				strTempMMOrderID = Left(strTempMMOrderID,strTempMMOrderID.length-1);
			}
			
			// Update hidden field
			thatForm.MMOrderID.value = strTempMMOrderID;
			return true;
		}
		
		// Single Order Only from Order Page
		if (thatFormOrders.MMOrderID) {
			strTempMMOrderID = thatFormOrders.MMOrderID.value;

			// Update hidden field
			thatForm.MMOrderID.value = strTempMMOrderID;
			return true;
		}
		return false;
	}
	
	function CheckAll(thatForm, Checked){
		// Checks/unchecks all checkboxes in form
		for(var i=0 ; i<thatForm.elements.length ; i++) {
			if (thatForm.elements[i].type=='checkbox') {
				thatForm.elements[i].checked=Checked;
				SetRowBackground(thatForm.elements[i]);
			}
		}	
		
	}
	
	function parseTime(time) {
		if (time.indexOf('0') == 0) {
			return parseInt(time.substr(1));
		} else {
			return parseInt(time);
		}
	}

	function CalculateCartTotals(thatForm, type){
		// Caluclate sub totals and totals for cart
		var curTempPrice = 0;
		var intTempQty = 0;
		var curSubTotal = 0;
		
		if (type=='SubTotal'){
			// SubTotal
			for(var i=0 ; i<thatForm.elements.length ; i++) {	
				if (thatForm.elements[i].name.indexOf('Price') > -1){
					curTempPrice = thatForm.elements[i].value;
					//alert(curTempPrice)
				}
	
				if (thatForm.elements[i].name.indexOf('Qty') > -1){
					intTempQty = thatForm.elements[i].value;
					//alert(intTempQty)
				}
				
				if (intTempQty!=""){
					curSubTotal += (curTempPrice*intTempQty);
					curTempPrice = 0;
					intTempQty = 0
				}
			}
	
			// Update form
			thatForm.SubTotal.value = Currency(curSubTotal-0);
		}else{
			// Total
			thatForm.Total.value = Currency((thatForm.SubTotal.value-0) - ((thatForm.VoucherValue.value-0) + (thatForm.Discount.value-0)) + (thatForm.ShippingValue.value-0)  + (thatForm.TaxValue.value-0));
		}
	}	
	
	// Calculates totals for reports
	function ReportCalculateTotals(thatForm, fields){
	
		var ArrayFields = fields.split(",");
		var TempTotal = 0;
		
		// Loop all columns
		for (var i=0;i<ArrayFields.length;i++){
			TempTotal = 0;
			
			// Checks for su			
			if (ArrayFields[i].toLowerCase().substring(0,5) == "sumof"){
				// Totals all fields by looping through each form
				for (var j=0;j<thatForm.elements.length;j++){
					if (thatForm.elements[j].name.indexOf(ArrayFields[i]) > -1 && thatForm.elements[j].name != ArrayFields[i]+'Total'){
						TempTotal += parseFloat(thatForm.elements[j].value);
					}
				}
				
				// Shows Total in total input textbox
				thatForm.elements[ArrayFields[i]+'Total'].value = "Total: " + Currency(TempTotal);
				
			}
		
			// Checks for count
			if (ArrayFields[i].toLowerCase().substring(0,7) == "countof"){
				// Totals all fields by looping through each form
				for (var j=0;j<thatForm.elements.length;j++){
					if (thatForm.elements[j].name.indexOf(ArrayFields[i]) > -1 && thatForm.elements[j].name != ArrayFields[i]+'Total'){
						TempTotal += parseInt(thatForm.elements[j].value);
					}
				}
				
				// Shows Total in total input textbox
				thatForm.elements[ArrayFields[i]+'Total'].value = "Total: " + TempTotal;
				
			}
		}	
	}
	
	function ProductPageName(Product){
	// Formats product name page.asp
		var Temp = Product;
		if (Product != ""){
			Temp = Temp.toLowerCase();
			Temp = Replace(Temp," ","_");
			Temp = Replace(Temp,"+","_");
			Temp = "_" + Temp;
		
			var TempProduct = Temp;
			Temp = "";

			// Checks non alphanumeric and . and _
			var regExp = new RegExp( /[A-Z]|[a-z]|\\s|[_]|[0-9]|[.]/i );

			for (i=0;i<=TempProduct.length;i++){
				spec = TempProduct.substring(i,i+1);
				
				var match = regExp.exec(spec);
				if( match == null ){
					//Temp += URLEncode(spec);
				}else    {
					Temp += spec
				}
			}
		}
		return Temp
	}
	
	function Replace(checkMe,toberep,repwith){ 
		var temp = checkMe; 
		var i = temp.indexOf(toberep); 
		while(i > -1){ 
		temp = temp.replace(toberep, repwith); 
		i = temp.indexOf(toberep); 
		} 
		return temp; 
	} 
	
	// Currency Functions
	
	// Set Defaults
	g_CurrentCurrency = ReadCookie("CartCurrency");
	if (g_CurrentCurrency == null || g_CurrentCurrency == "" || g_CurrentCurrency == 'undefined') g_CurrentCurrency = "&pound;";

	function SelectCurrency(Page){
		// Create Currency drop-down depending on current page requirements
		var CurrencyOptions = '<option value="&pound;"' + Selected("&pound;",g_CurrentCurrency) + '>&pound;</option>' + 
			'<option value="$"' + Selected("$",g_CurrentCurrency) + '>$</option>' + 
			'<option value="&euro;"' + Selected("€",g_CurrentCurrency) + '>&euro;</option>' + 
		  '</select>';
		
		// Pages
		switch(Page){
			case "details":
				CurrencyOptions = '<select name="Currency" onChange="ChangeCurrency(this.options[this.selectedIndex].value)" class="DetailsCurrencySelect">' + CurrencyOptions;
				break;
			
			default:
				CurrencyOptions = '<select name="Currency" onChange="CreateCookie(\'CartCurrency\',this.options[this.selectedIndex].value,365);window.location.reload()" class="DetailsCurrencySelect">' + CurrencyOptions;
				break;
		} 
		return CurrencyOptions;
	}
	
	function GetCurrencyPrice(Currency, Price){
		// Gets price based on selected currency
		switch(Currency){
		  case "&pound;","£": Price = (PoundRate*Price);break;
		  case "$": Price = (DollarRate*Price);break;
		  case "&euro;", "€": Price = (EuroRate*Price);break;
		  default: Price = (PoundRate*Price);break;
		}
	
		return ChangeToCurrency(Price);
	}
	
	function GetCurrencyName(Currency){
		// Gets name of currency for Paypal etc.
		var CurrencyName = "";
		switch(Currency){
		  case "&pound;","£": CurrencyName = "GBP";break;
		  case "$": CurrencyName = "USD";break;
		  case "&euro;", "€": CurrencyName = "EUR";break;
		  default: CurrencyName = "GBP";break;
		}
		
		return CurrencyName;
	}
	
	function ChangeCurrency(Currency){
		// Change default global currency
		// and current price
		
		g_CurrentCurrency = Currency;
		CreateCookie('CartCurrency',Currency,365);
		
		UpdateCurrencyPrices();
		return false;
	}
	
	function UpdateCurrencyPrices(){
		if(document.getElementById("basepriceoptions")){
			var Price = GetCurrencyPrice(g_CurrentCurrency, document.getElementById("basepriceoptions").value);
			if (document.getElementById("DisplayPrice"))document.getElementById("DisplayPrice").value = Price;
		}
		if (document.getElementById("CurrentCurrency")) document.getElementById("CurrentCurrency").innerHTML = g_CurrentCurrency;
	}
  

  function ChangeToCurrency(dbAmount) { 
    // returns the amount in the .99/currency format 
    dbAmount -= 0; 
    dbAmount = (Math.round(dbAmount*100))/100; 
    return (dbAmount == Math.floor(dbAmount)) ? dbAmount + '.00' : ( (dbAmount*10 == Math.floor(dbAmount*10)) ? dbAmount + '0' : dbAmount); 
  } 
  
  function Selected(String1,String2){
	// Select for list/menu  
	if (String1.toString() == String2.toString()) return "selected";
	return "";
  }
  
	function GetPageName(){
		// Gets current page name
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		return(sPage);
	}
	
	function Capitalise(a) {
		var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
		a = a.split(/\s+/g); // split the sentence into an array of words
	
		for (i = 0 ; i < a.length ; i ++ ) {
			var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
	
			var firstLetter = parts[1].toUpperCase();
			var restOfWord = parts[2].toLowerCase();
	
			a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
		}
		
		return a.join(' '); // join it back together
	}
	
  
  // Cookie functions
  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 var expires = "";
		document.cookie = name+"="+URLEncode(value)+expires+"; path=/";
	}
	
	function ReadCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = URLDecode(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;
	}
	
	function DeleteCookie(name)
	{
		CreateCookie(name,"",-1);
	}
	
	// Dropdown/Listbox functions
	function AddDropdownOption(selectbox,text,value){
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
	}
	
	function RemoveAllDropdownOptions(selectbox){
		var i;
		for(i=selectbox.options.length-1;i>=0;i--){
			selectbox.remove(i);
		}
	}

	function RemoveSelectedDropdownOptions(selectbox){
		var i;
		for(i=selectbox.options.length-1;i>=0;i--){
			if(selectbox.options[i].selected)
			selectbox.remove(i);
		}
	}	
		
	// DW Functions
	
	function OpenWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_validateForm() { //v4.0
	  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { nm=val.name; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
		  } else if (test!='R') { num = parseFloat(val);
			if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	  } if (errors) alert('The following error(s) occurred:\n'+errors);
	  document.MM_returnValue = (errors == '');
	}

	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	
	function MM_jumpMenuGo(selName,targ,restore){ //v3.0
	  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}