
	// Required * Do not remove *
	var FieldsChanged = new Array();
	
	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 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 = "_" + Temp;
		}
		
		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(){

		var Price = GetCurrencyPrice(g_CurrentCurrency, document.getElementById("basepriceoptions").value);
		document.getElementById("DisplayPrice").value = Price;
		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 "";
  }
  
  // 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+"="+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;
	}
	
	function DeleteCookie(name)
	{
		CreateCookie(name,"",-1);
	}
		
	// 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);
	}
