  // ***************************************************************************
  // ///////////////////////////////////////////////////////////////////////////
  // ***************************************************************************
  //
  //  SOFTWARE: HorseNose.Com
  //   VERSION: 1.0
  // 
  // ***************************************************************************
  // ///////////////////////////////////////////////////////////////////////////
  // ***************************************************************************
  // Functions added by AVS
  // Copyright (c) 2011 by AV Sivaprasad and WebGenie Software Pty Ltd.
  	var oktoclosewindow = 1;
  	var confirmed_once = 0;
  	var prices = new Array('','11.00','33.00','41.80','57.20','99.00');
  	var no_mobile_number_checked = 0;
  	function CheckThisButton(item,n)
  	{
alert(item);
var form = document.getElementById('signup_form');
alert(document.getElementById('signup_form'));
  		item[n].checked = true;
  	}
  	function SubmitThisForm(form)
  	{
//alert(form);  		
  		form.submit();
  	}
  	function EnableSMSButton(form,enable)
  	{
  		if (enable) form.sms_alert.disabled = false;
  		else form.sms_alert.disabled = true;
  	}
  	function CloseDivs()
  	{
  		var divs = "step1,step2,step3,passwd_area,address,creditcard,sample,";
		var len = divs.length;
  		var m = 0;
  		var n = 0;
  		for (j=n; j <= len; j++)
  		{
  			var n = divs.indexOf(',',m);
  			var div = divs.substring(m,n);
//alert(div);  			
  			showHide(div,'none');
  			m = n+1;
  		}
  	}
	function SelectAll(id)
	{
		document.getElementById(id).focus();
		document.getElementById(id).select();
	}
  	function SwitchPaymentButton(form)
  	{
  		if (form.recurring_payment.value == '0.00')
  		{
  			showHide('agreements','none');
  			showHide('agreements2','block');
  		}
  		else
  		{
  			showHide('agreements','block');
  			showHide('agreements2','none');
  		}
  	}
  	function ForgotPassword(form)
  	{
  		if (form.email.value)
  		{
//  			alert(form.email.value);
  			ajaxFunction(8,form);
  		}
  		else
  		{
  			alert("Please enter your login email address.");
  		}
  	}
  	function disableField(form, item)
  	{
//alert(item.name);
  		if (item.checked == true)
  		{
  			form.mobile.value = "";
  			form.mobile.disabled = "disabled";
  			showHide('conf_to_mobile','none');
  			showHide('conf_to_email','block');
  		}
  		else
  		{
  			form.mobile.disabled = "";
  			showHide('conf_to_mobile','block');
  			showHide('conf_to_email','none');
  		}
  	}
    function Test()
	{
	}
	function PayViaPayPal(form)
	{
		var payment_option = "paypal";
//		if (form.payment_option[0].checked) payment_option = form.payment_option[0].value; 
//		if (form.payment_option[1].checked) payment_option = form.payment_option[1].value; 
//		if (!payment_option)
//		{
//			alert("No payment method has been selected.\n\nPlease correct and re-submit.");
//		}
		if (payment_option == 'paypal')
		{
//			if(!form.card_street.value || !form.card_suburb.value || !form.card_postcode.value || form.card_state[0].selected || form.card_country[0].selected)
//			{
//				alert("Incomplete or missing address details.\n\nPlease correct and re-submit.");
//				return;
//			}
			form.submit();
			return;
		}
		if (payment_option == 'credit_card')
		{
			if (!form.Card_N1.value || !form.Card_N2.value || !form.Card_N3.value || !form.Card_N4.value || !form.credit_card_cvv.value || !form.card_name.value)
			{
				alert("Incomplete or missing credit card details.\n\nPlease correct and re-submit.");
				return;
			}
			var ok = CheckCardEntry(form,form.card_name);
			if (ok) 
			{
				if(!form.card_street.value || !form.card_suburb.value || !form.card_postcode.value || !form.card_state.selectedindex == 0 || !form.card_country.selectedindex == 0)
				{
					alert("Incomplete or missing address details.\n\nPlease correct and re-submit.");
					return;
				}
				form.submit();
				return;
			}
			return;
		}
/*
		var no_payment_agreement = "";
		var no_sms_agreement = "";
		var no_terms_and_conditions = "";
		if (form.payment_agreement.checked == false && form.payment_agreement1.checked == false) no_payment_agreement = "Payment agreement is not checked."; 
		if (form.sms_agreement.checked == false && form.sms_agreement1.checked == false) no_sms_agreement = "SMS/Email acceptance is not checked."; 
		if (form.terms_and_conditions.checked == false && form.terms_and_conditions1.checked == false) no_terms_and_conditions = "Terms and Conditions must be accepted."; 
//alert(no_payment_agreement);		
//alert(no_sms_agreement);		
//alert(no_terms_and_conditions);		
		if (no_payment_agreement || no_sms_agreement || no_terms_and_conditions)
		{
			var msg = "ERROR!\n\n" + no_payment_agreement + "\n\n" + no_sms_agreement + "\n\n" + no_terms_and_conditions;
			alert (msg);
			showHide('PaymentButton','block');
			showHide('paymentInProgress','none');
			return;
		}
//		showHide('PaymentButton','none');
		showHide('paymentInProgress','block');
if (form.recurring_payment.value == '0.00')
{
	form.sc_action.value = 'signup';
}
		form.submit();
*/
	}
	function ShowGatheringData(n)
	{
	  if (n == 1)
	  {
		  showHide('gathering_data_show','block');
	  }
	  else
	  {
		  showHide('gathering_data_show','none');
	  }
	}
	function Monify(value)
	{
	//alert (value);
	  if (!value || value == undefined) return "0.00";
	  var str = "" + Math.round(value*100);
	  var len = str.length;
	
	  return (str=="0")?"":(str.substring(0,len-2)+"."+str.substring(len-2,len));
	}
	function ConfirmPaymentDetails(form)
	{
		if (!form.payment_agreement.checked || !form.sms_agreement.checked || !form.terms_and_conditions.checked)
		{
			alert("Please accept the three conditions listed above.");
			return;
		}
		form.submit();
		return;
/*
		var payment_option = "";
		if (form.payment_option[0].checked) payment_option = form.payment_option[0].value; 
		if (form.payment_option[1].checked) payment_option = form.payment_option[1].value; 
		if (!payment_option)
		{
			alert("No payment method selected.\n\nPlease correct and re-submit");
		}
		if (payment_option == 'paypal')
		{
			form.submit();
			return;
		}
		if (payment_option == 'credit_card')
		{
			if (!form.Card_N1.value || !form.Card_N2.value || !form.Card_N3.value || !form.Card_N4.value)
			{
				alert("Invalid or missing credit card details.\n\nPlease correct and re-submit");
				return;
			}
			var ok = CheckCardEntry(form,form.card_name);
			if (ok) form.submit();
			else
			{
//				alert("Invalid or missing credit card details.\n\nPlease correct and re-submit");
			}
			return;
		}
*/
	}
	function ConfirmPaymentDetails_0(form)
	{
var ok = CheckCardEntry(form,form.card_name);		
		var card_no = form.card_no.value;
		var credit_card_cvv = form.credit_card_cvv.value;
		var card_month = form.card_month.value;
		var card_year = form.card_year.value;
		var totPayable = form.totPayable.value;
		var billing_interval = form.billing_interval.value;
		var expiryTime = form.expiryTime.value;
		if (totPayable > 0 && (!card_no || !credit_card_cvv || !card_month || !card_year))
		{
			alert("Invalid or missing credit card details.");
			return;
		}
//alert('totPayable = ' + form.totPayable.value);
		var nowPayable = totPayable;
		var recurring_payment = totPayable;
		var discount = form.discount.value;
//		var recurring_payment = Monify(form.totPayable.value - (form.totPayable.value * discount) / 100);
//alert('1. nowPayable = ' + nowPayable);
//alert('recurring_payment = ' + recurring_payment);
//alert('discount = ' + discount);
//alert('1. totPayable = ' + totPayable);
//alert('billing_interval = ' + billing_interval);
		if (billing_interval == 14 && totPayable > 0) nowPayable = "1.00";
		if (totPayable == 0) 
		{
//alert('billing_interval = ' + billing_interval);
			nowPayable = "0.00";
			form.totPayable.value = "0";
		}
//alert('2. nowPayable = ' + nowPayable);
		var len = card_no.length;
		var first4digits = card_no.substring(0,4);
		var last4digits = card_no.substring(len-4,len);
		var blanked_card_no = first4digits + " xxxx xxxx " + last4digits;
//		var msg = "<p align=left><b><span class=\"style47\">Total payable now: </b>$" + nowPayable + "</span><br><b>Next payment :</b>$" + recurring_payment + "<br><b>Card number: </b>" + blanked_card_no + "<br><b>Expires: </b>" + card_month + "/" + card_year + "</p>";
		var msg = "<table><tr><td><p align=left><b><span class=\"style47\">Total payable now</span></b></td><td>  </td><td>$" + nowPayable + 
		"</td></tr><tr><td><p align=left><b><span class=\"style47\">Regular payment</span></b></td><td>  </td><td>$" + recurring_payment + 
		"</td></tr><tr><td><p align=left><b><span class=\"style47\">Next payment due</span></b></td><td>  </td><td>" + expiryTime + 
		"</td></tr></table>\n";
		document.getElementById('card_no_redisplay').innerHTML = msg;
//alert(msg);
		showHide('agreements','block'); 
		showHide('payment_details','none');
	}
	function ShowPaymentPage(form)
	{
		var totPayable = 0;
		var nowPayable = 0;
		var yearlydiscount = 0;
		var discount = 0;
		if (form.trial[0].checked) 
		{
			totPayable = prices[4];
			nowPayable = 1.00;
			form.billing_interval.value = 14;
		}
		
//		if (form.trial[1].checked || form.trial[2].checked) 
		if (form.trial[1].checked || form.annual.checked) 
		{
			if (form.service_level[0].checked) totPayable = prices[1];
			if (form.service_level[1].checked) totPayable = prices[2];
			if (form.service_level[2].checked) totPayable = prices[3];
			if (form.service_level[3].checked) totPayable = prices[4];
			if (form.service_level[4].checked) totPayable = prices[5];
			form.billing_interval.value = 30;
			nowPayable = totPayable;
		}
		
		if (form.annual.checked) 
		{
			totPayable = totPayable * 12;
			totPayable = Monify(totPayable);
			nowPayable = totPayable;
			form.billing_interval.value = 365;
			yearlydiscount = 10;
		}

		discount = Math.abs(form.discount.value) + Math.abs(yearlydiscount);
		if (discount > 100) discount = 100.00;
		if (discount == 100)
		{
			totPayable = 0.00;
			nowPayable = 0.00;
			form.billing_interval.value = 14;
		}
		totPayable = Monify((totPayable - (totPayable*discount/100)));
//alert(totPayable);
		if (nowPayable != "1.00") nowPayable = totPayable;
		form.totPayable.value = totPayable;
//alert(nowPayable);
		
		nowPayable = Monify(nowPayable); 
		if (!nowPayable) nowPayable = "0.00";
//		var msg = "Amount to be paid: $" + nowPayable;
//alert(msg);
		var recurring_payment = totPayable;
		var expiryTime = form.expiryTime.value;
		var billing_interval = form.billing_interval.value;
//alert(billing_interval);
		var msg = "<table><tr><td><b><span class=\"style29\">Total payable now</span></b></td><td>  </td><td>$" + nowPayable + 
		"</td></tr><tr><td><b><span class=\"style29\">Regular monthly payment</span></b></td><td>  </td><td>$" + recurring_payment + 
		"</td></tr><tr><td><b><span class=\"style29\">Next payment due in</span></b></td><td>  </td><td>" + billing_interval + " days" +
		"</td></tr></table>\n";
		
		if (nowPayable == "0.00")
		{
			msg = "<table><tr><td><b><span class=\"style29\">Total payable now</span></b></td><td>  </td><td>$" + nowPayable + 
		"</td></tr><tr><td><b><span class=\"style29\">Regular monthly payment</span></b></td><td>  </td><td>$" + recurring_payment + 
		"</td></tr><tr><td><b><span class=\"style29\">Expiry of free trial in</span></b></td><td>  </td><td>" + billing_interval + " days" +
		"</td></tr></table>\n";
		}
		document.getElementById('nowPayable_div').innerHTML = msg;
		showHide('service_level','none'); 
		showHide('agreements','block');
//		if (nowPayable != "0.00")
//		{
//			showHide('payment_details','block');
//		}
//		else
//		{
//			showHide('agreements2','block');
//		}
	}
	function DisplayMessage(msg)
	{
		alert(msg);
	}
	function CkeckMobileNumber(mobile)
	{
		var len = mobile.length;
		if (len < 10) return 0;
		
		if ((mobile.indexOf('(',0) != 0) && (mobile.indexOf('0',0) != 0) && (mobile.indexOf('+',0) != 0)) return 0;
		if (mobile.indexOf('0',0) == 0)
		{
			var nn = mobile.indexOf('4',1);
//alert(nn);
			if (nn != 1)
			{
				return 0;
			}
		}
		
		return 1;
	}
	function ValidateInput(form,page)
	{
//alert("ok");		
		ShowGatheringData(1);
		var fname = form.fname.value;
		var lname = form.lname.value;
		var email = form.email.value;
		var sales_email = form.sales_email.value;
		var home_url = form.home_url.value;
		var company = form.company.value;
		var mobile = form.mobile.value;
		var msg = "";
		if (!email)
		{
			msg = msg + "Admin email address is missing.\n";
		}
		if (!sales_email)
		{
			msg = msg + "Sales email address is missing.\n";
		}
		if (!company)
		{
			msg = msg + "Company name is missing.\n";
		}
		if (!home_url)
		{
			msg = msg + "Home page URL is missing.\n";
		}
		if (!email || !sales_email || !home_url) 
		{
			alert(msg);
			ShowGatheringData(0);
			return;
		}
		// Compare the sales email and home_url	
		var len = sales_email.length;
		var nn = sales_email.indexOf('@',0);
		var domain = sales_email.substring(nn+1,len);
		var pos = home_url.indexOf(domain,0);
		if (pos < 0) 
		{
			alert("Sales email does not contain the home page domain name");
			ShowGatheringData(0);
			return;
		}
		form.submit();		
	}
	function SendSMS(form,action)
	{
//alert(action);		
//		ShowGatheringData(1);
//		showHide('service_selection_button','none');
		if (action == 'send')
		{
			var fname = form.fname.value;
			var lname = form.lname.value;
			var email = form.email.value;
			var mobile = form.mobile.value;
//			var no_mobile_number_checked = form.no_mobile_number.checked;
			if (!mobile && !no_mobile_number_checked) 
			{
				alert("Sorry! Mobile number is missing");
				ShowGatheringData(0);
				showHide('service_selection_button','block');
				return;
			}
			else
			{
//				alert("A confirmation code will now be sent to \"" + mobile + "\"\n\nPlease allow a few seconds for it to arrive and then retrieve and type it into the page that will appear now.");  
				ShowGatheringData(0);
				ajaxFunction(5,form); // Send the sms_confirmation_code for confirmation
			}
		}
		if (action == 'verify')
		{
			var sms_confirmation_code = form.sms_confirmation_code.value;
			if (!sms_confirmation_code) 
			{
				alert("Sorry! The confirmation code is missing");
				return;
			}
			else
			{
				ajaxFunction(6,form); // Confirm the sms_confirmation_code
			}
		}
	}
  	function ServiceLevel(form,trial) 
	{
		if (trial == 1)
		{
			form.service_level[0].checked = false;
			form.service_level[1].checked = true;
//			form.service_level[2].checked = false;
//			form.service_level[3].checked = true;
//			form.service_level[4].checked = false;

			form.service_level[0].disabled = 'disabled';
			form.service_level[1].disabled = '';
//			form.service_level[2].disabled = 'disabled';
//			form.service_level[3].disabled = 'disabled';
//			form.service_level[4].disabled = '';
		}
		if (trial == 2)
		{
			form.service_level[0].disabled = '';
			form.service_level[1].disabled = '';
//			form.service_level[2].disabled = '';
//			form.service_level[3].disabled = '';
//			form.service_level[4].disabled = '';
		}
		if (trial == 3)
		{
			form.service_level[0].disabled = '';
			form.service_level[1].disabled = '';
			form.trial[0].checked = false;
			form.trial[1].checked = true;
//			form.service_level[2].disabled = '';
//			form.service_level[3].disabled = '';
//			form.service_level[4].disabled = '';
		}
	}
	function RaceDetails(date,horse_number,horse_code,horse_name,result,win,venue,race_number)
	{
		var msg = "Date: " + date + "\n" + "Race: " + race_number + " at " + venue + "\n" + "Horse: " + horse_number + " " + horse_name + " (" + horse_code + ")\n" + "Result: " + result + "\n" + "Win: " + win + "\n"; 
		alert (msg);
	}
	function DescribeLevels(msg)
	{
//alert(msg);
	  	document.getElementById('levels_definition').innerHTML = msg;
	}
  	function showFortnight(div) 
	{
//alert(div);
		if (div == 0 ) return;
		var e=document.getElementsByTagName('div');
		var n = e.length;
		var i;
		for (i=0; i < n; i++)
		{
			var last_fortnight = e[i].id;
//alert(last_fortnight);
			var nn = last_fortnight.indexOf('last_fortnight',0);
			if (nn >= 0)
			{
//alert(last_fortnight);
				showHide(last_fortnight,'none');
			}
		}
		var this_fortnight = 'last_fortnight' + div;
		showHide(this_fortnight,'block');
	}	
  	function DontCloseWindow() 
	{
		oktoclosewindow = 0;
	}	
  	function CloseWindow() 
	{
//alert (oktoclosewindow);
			if (oktoclosewindow) sample_window1.close();
	}
  	function PopUpWindow(url,width,height) 
	{
		if (!width) width = 970;
		if (!width) height = 150;
//alert(url);		
		// Show Sample Web Site popup window based on features provided
//		sample_window1 = window.open( url, "popup_window", "left=10,top=10,width=970,height=500,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
		var properties = "left=10,top=10,width="+ width + ",height=" + height +",resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0";
		sample_window1 = window.open( url, "popup_window", properties);
		sample_window1.focus();
	}
	function CheckIfDivExists(id)
	{
		var e=document.getElementsByTagName('div');
		var n = e.length;
		var i;
		for (i=0; i < n; i++)
		{
			if(e[i].id == id) return 1;
		}
		return 0;
	}
	function showHide(id,state)
	{
		if (state == undefined) state = 'block';
		var exists = CheckIfDivExists(id);
		if(id && exists)
		{
			var style = document.getElementById(id).style.display;
			document.getElementById(id).style.display=""+state;
		}
	}
	function showHideToggle(id)
	{
		var exists = CheckIfDivExists(id);
//alert(exists);		
		if(id && exists)
		{
			var style = document.getElementById(id).style.display;
			if(style == 'none') showHide(id,'block');
			else showHide(id,'none');
		}
	}
	function showFullRankings(horse_code,rankings)
	{
//		showHideToggle('rankings_div');
var rankings_row = "<span align=right>" + horse_code + ":&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + rankings + "</span>";
		document.getElementById('rankings_div').innerHTML = rankings_row;
//alert(rankings);		
	}
	function showFullMovement(oddsfirm)
	{
		alert(oddsfirm);		
	}
	function RepeatLoad()
	{
		var ran_number= Math.random()*5000;
		url = "hn_v1_1.cgi?om"+"+" + ran_number;
//alert(url);
		document.location = url;
	}
	function GetOddsMonitor()
	{
//document.write("Here");		
//alert("Here Ajax 2");
//		var t = setTimeout("RepeatLoad()",20000);		
//		ajaxFunction(2);
	}
	function CheckMobileField(form,item)
	{
//alert(form.mobile.value);
		var mobile = form.mobile.value;
		if (mobile)
		{
			var ok = CkeckMobileNumber(mobile)
			if (!ok)
			{
				alert("Mobile number is invalid.");
				item.checked = false;
				return;
			}
			return;
		}
		else
		{
			alert("Mobile number is missing");
			item.checked = false;
			return;
		}
	}
	function FormSubmit(form,src)
	{
//		var paypal_PNREF = form.paypal_PNREF.value;
//		var card_no = form.card_no.value;
		var use_existing_card = 0;
		if (form.use_existing_card.checked) use_existing_card = 1;
		var use_new_card = 0; 
		if (form.use_new_card.checked) use_new_card = 1;
		var expired = form.expired.value;
		var orig_service_level = form.orig_service_level_bak.value;
		var passwd = form.passwd.value;
		var passwd1 = form.passwd1.value;
		if (passwd && passwd != passwd1)
		{
			alert ("Passwords do not match");
			return;
		}
		form.submit();
/*
		if (src == 'mem_update')
		{
//alert(expired);
			if (expired < 0) 
			{
				if (!form.resume_service.checked)
				{
					alert("Your membership has expired. Please check the button marked 'Resume' to activate.");
//					return;
				}
				else
				{
					if (confirmed_once)
					{
						ans = 1;
					}
					else
					{
						var ans = confirm("Resuming an expired membership requires payment of the subscription fee.\n\nPlease click OK to continue or Cancel to abort.", ans);
						if (!ans) return;
					}
					if (ans)
					{
						confirmed_once = 1;
						if (!use_existing_card && !use_new_card)
						{
							alert("Please choose which credit card to use.");
							showHide('Change the membership level','none');
							showHide('Change the Credit Card','block');
							return;
						}
						if (!paypal_PNREF && !card_no)
						{
							alert("ERROR: There is no payment reference on record. Please enter the credit card details.");
							showHide('Change the membership level','none');
							showHide('Change the Credit Card','block');
							return;
						}
						var amount = prices[orig_service_level];
//alert("orig_service_level = " + orig_service_level);
						amount = Monify(amount);
						var msg = "Amount to be charged to your card: $" + amount + "\n\nPlease click OK to continue or Cancel to abort";
						var ans = confirm(msg, ans);
						if (!ans) return;
					}
				}
			}
			for (var j = 0; j <= 5; j++)
			{
				if (form.service_level[j].checked) 
				{
					service_level = form.service_level[j].value;
					break;
				}
			}
			if (service_level > orig_service_level)
			{
				if (confirmed_once)
				{
					ans = 1;
				}
				else
				{
					var ans = confirm("Upgrading the membership level requires payment of the difference.\n\nPlease click OK to continue.", ans);
				}
				if (ans)
				{
					confirmed_once = 1;
					if (!use_existing_card && !use_new_card)
					{
						alert("Please choose which credit card to use.");
						showHide('Change the membership level','none');
						showHide('Change the Credit Card','block');
						return;
					}
					if (!paypal_PNREF && !card_no)
					{
						alert("ERROR: There is no payment reference on record. Please enter the credit card details.");
						showHide('Change the membership level','none');
						showHide('Change the Credit Card','block');
						return;
					}
				}
				else
				{
					return;
				}
				var newamount = prices[service_level];
				var oldamount = prices[orig_service_level];
				var amount = Math.abs(newamount - oldamount);
				amount = Monify(amount);
				var msg = "Amount to be charged to your card: $" + amount + "\n\nPlease click OK to continue or Cancel to abort";
				var ans = confirm(msg, ans);
				if (!ans) return;
			}
		}
		
		form.submit();
*/
	}
	function FormSubmit_0(form,src)
	{
		var paypal_PNREF = form.paypal_PNREF.value;
		var card_no = form.card_no.value;
		var use_existing_card = 0;
		if (form.use_existing_card.checked) use_existing_card = 1;
		var use_new_card = 0; 
		if (form.use_new_card.checked) use_new_card = 1;
		var expired = form.expired.value;
		var orig_service_level = form.orig_service_level_bak.value;
		if (src == 'mem_update')
		{
//alert(expired);
			if (expired < 0) 
			{
				if (!form.resume_service.checked)
				{
					alert("Your membership has expired. Please check the button marked 'Resume' to activate.");
//					return;
				}
				else
				{
					if (confirmed_once)
					{
						ans = 1;
					}
					else
					{
						var ans = confirm("Resuming an expired membership requires payment of the subscription fee.\n\nPlease click OK to continue or Cancel to abort.", ans);
						if (!ans) return;
					}
					if (ans)
					{
						confirmed_once = 1;
						if (!use_existing_card && !use_new_card)
						{
							alert("Please choose which credit card to use.");
							showHide('Change the membership level','none');
							showHide('Change the Credit Card','block');
							return;
						}
						if (!paypal_PNREF && !card_no)
						{
							alert("ERROR: There is no payment reference on record. Please enter the credit card details.");
							showHide('Change the membership level','none');
							showHide('Change the Credit Card','block');
							return;
						}
						var amount = prices[orig_service_level];
//alert("orig_service_level = " + orig_service_level);
						amount = Monify(amount);
						var msg = "Amount to be charged to your card: $" + amount + "\n\nPlease click OK to continue or Cancel to abort";
						var ans = confirm(msg, ans);
						if (!ans) return;
					}
				}
			}
			for (var j = 0; j <= 5; j++)
			{
				if (form.service_level[j].checked) 
				{
					service_level = form.service_level[j].value;
					break;
				}
			}
			if (service_level > orig_service_level)
			{
				if (confirmed_once)
				{
					ans = 1;
				}
				else
				{
					var ans = confirm("Upgrading the membership level requires payment of the difference.\n\nPlease click OK to continue.", ans);
				}
				if (ans)
				{
					confirmed_once = 1;
					if (!use_existing_card && !use_new_card)
					{
						alert("Please choose which credit card to use.");
						showHide('Change the membership level','none');
						showHide('Change the Credit Card','block');
						return;
					}
					if (!paypal_PNREF && !card_no)
					{
						alert("ERROR: There is no payment reference on record. Please enter the credit card details.");
						showHide('Change the membership level','none');
						showHide('Change the Credit Card','block');
						return;
					}
				}
				else
				{
					return;
				}
				var newamount = prices[service_level];
				var oldamount = prices[orig_service_level];
				var amount = Math.abs(newamount - oldamount);
				amount = Monify(amount);
				var msg = "Amount to be charged to your card: $" + amount + "\n\nPlease click OK to continue or Cancel to abort";
				var ans = confirm(msg, ans);
				if (!ans) return;
			}
		}
		
		form.submit();
	}
function ajaxFunction(n,form)
{
  var xmlHttp;
  var url;
  try
  {  // Firefox, Opera 8.0+, Safari  
	  xmlHttp=new XMLHttpRequest();  
  }
  catch (e)
  {  // Internet Explorer  
    try
    {    
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
	}
	catch (e)
    {    
		try
		{      
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
		}
		catch (e)
      	{	      
			alert("Your browser does not support AJAX!");      
			return false;      
		}    
	}
  }
	xmlHttp.onreadystatechange=function()
	{
	  if(xmlHttp.readyState==4)
	  {
 		  response = xmlHttp.responseText;
		  if (n == 1)
		  {
		  	  document.getElementById('edit_store_form').innerHTML = response;
		  }
		  if (n == 2)
		  {
//alert(response);
			if (response == "OK") 
				form.submit.value = "Saved the changes";
			else 
				form.submit.value = response;
		  }
		  if (n == 3)
		  {
			if (response == "OK") 
				form.submit.value = "Saved the changes";
			else 
				form.submit.value = response;
		  }
		  if (n == 4)
		  {
			if (response == "OK") 
				form.submit.value = "Saved the changes";
			else 
				form.submit.value = response;
		  }
		  if (n == 5)
		  {
			if (response == "OK") 
				form.submit.value = "Saved the changes";
			else 
				form.submit.value = response;
		  }
		  if (n == 6)
		  {
		  }
		  if (n == 7)
		  {
		  }
		  if (n == 71)
		  {
		  }
		  if (n == 8)
		  {
		  }
	  }
	}
	if (n == 1) // admin.php: change store details
	{
		var ran_number= Math.random()*5000;
		var sc_action = form.sc_action.value;
		var vendor_id = form.vendor_id.value;
		var edit_action = form.edit_action.value;
		var storeid = form.storeid[form.storeid.selectedIndex].value;
		pquery = 
		"&edit_action=" + edit_action +
		"&vendor_id=" + vendor_id +
		"&storeid=" + storeid;
		pquery = escape(pquery);
		url = "wsc7.cgi?"+sc_action+ "+" + ran_number + "+" + pquery;
//alert(url);
	}
	if (n == 2) // admin.php: Update store details 
	{
		form.submit.value = "Saving...";
		var ran_number= Math.random()*5000;
		var sc_action = form.sc_action.value;
		var vendor_id = form.vendor_id.value;
		var storeid = form.storeid.value;
		var storename = form.storename.value;
		var company = form.company.value;
		var slogan = form.slogan.value;
		var image = form.image.value;
		var blurb = form.blurb.value;
		pquery = 
		"&vendor_id=" + vendor_id +
		"&storeid=" + storeid +
		"&storename=" + storename +
		"&company=" + company +
		"&slogan=" + slogan +
		"&image=" + image +
		"&blurb=" + blurb +
		"&";
		pquery = escape(pquery);
		url = "wsc7.cgi?"+sc_action+ "+" + ran_number + "+" + pquery;
	}
	if (n == 3) // admin.php: Change password
	{
		form.submit.value = "Saving...";
		var ran_number= Math.random()*5000;
		var sc_action = form.sc_action.value;
		var vendor_id = form.vendor_id.value;
		var edit_action = form.edit_action.value;
		var old_passwd = form.old_passwd.value;
		var passwd = form.passwd.value;
		var confirm_passwd = form.confirm_passwd.value;
		if (confirm_passwd != passwd)
		{
			alert("Passwords do not match");
			return;
		}
		if (!old_passwd || !confirm_passwd || !passwd)
		{
			alert("Passwords cannot be empty");
			return;
		}
		pquery = 
		"&edit_action=" + edit_action +
		"&vendor_id=" + vendor_id +
		"&old_passwd=" + old_passwd +
		"&passwd=" + passwd +
		"&confirm_passwd=" + confirm_passwd +
		"&";
		pquery = escape(pquery);
		url = "wsc7.cgi?"+sc_action+ "+" + ran_number + "+" + pquery;
	}
	if (n == 4) // admin.php: contact details
	{
		form.submit.value = "Saving...";
		var ran_number= Math.random()*5000;
		var sc_action = form.sc_action.value;
		var edit_action = form.edit_action.value;
		var vendor_id = form.vendor_id.value;
		var fname = form.fname.value;
		var lname = form.lname.value;
		var email = form.email.value;
		var sales_email = form.sales_email.value;
		var company = form.company.value;
		var home_url = form.home_url.value;
		var phone = form.phone.value;
		var mobile = form.mobile.value;
		var email_alert = form.email_alert.value;
		var sms_alert = form.sms_alert.value;
		pquery = 
		"&edit_action=" + edit_action +
		"&vendor_id=" + vendor_id +
		"&fname=" + fname +
		"&lname=" + lname +
		"&email=" + email +
		"&sales_email=" + sales_email +
		"&company=" + company +
		"&home_url=" + home_url +
		"&phone=" + phone +
		"&mobile=" + mobile +
		"&email_alert=" + email_alert +
		"&sms_alert=" + sms_alert +
		"&";
		pquery = escape(pquery);
		url = "wsc7.cgi?"+sc_action+ "+" + ran_number + "+" + pquery;
	}
	if (n == 5) // admin.php: Credit card details
	{
		form.submit.value = "Saving...";
		var ran_number= Math.random()*5000;
		var sc_action = form.sc_action.value;
		var edit_action = form.edit_action.value;
		var vendor_id = form.vendor_id.value;

//		var card_no = form.Card_N1.value + "-" +  form.Card_N2.value + "-" +  form.Card_N3.value + "-" +  form.Card_N4.value;
//		var card_month = form.ExpMonth.value;
//		var card_year = form.ExpYear.value;
//		var card_name = form.card_name.value;

		var card_street = form.card_street.value;
		var card_suburb = form.card_suburb.value;
		var card_state = form.card_state.value;
		var card_postcode = form.card_postcode.value;
		var card_country = form.card_country.value;
		pquery = 
		"&edit_action=" + edit_action +
		"&vendor_id=" + vendor_id +
		"&card_street=" + card_street +
		"&card_suburb=" + card_suburb +
		"&card_state=" + card_state +
		"&card_postcode=" + card_postcode +
		"&card_country=" + card_country +
		"&";
		pquery = escape(pquery);
		url = "wsc7.cgi?"+sc_action+ "+" + ran_number + "+" + pquery;
	}
	if (n == 6) // SMS code confirmation against database
	{
	}
	if (n == 7 || n == 71) // See whether the email/mobile is already used
	{
	}
	if (n == 8) // Forgot Password
	{
	}
//alert(url);	
//return;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


