
function setCookie(name, value) {
		document.cookie = name + "=" + value;
	}
	
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
	
	
function setCurrency(curr) {
		setCookie('moonprocurr',curr);
		location.reload(true);
		
	}


var showing, showing2;
showing = false;
showing2 = false;
	
function toggle(str1,str2,str3,str4) {

if (showing)   {
	var obj1;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "hidden";
	obj1.style.height = "0px";
	obj1.style.display = "none";
	if (str2 != null) {
		obj2 = document.getElementById(str2);
		obj2.innerHTML = str3;	
		}
	
	showing = false;
	} else {
	var obj1;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "visible";
	obj1.style.height = "auto";
	obj1.style.display = "block";	
	if (str2 != null) {
		obj2 = document.getElementById(str2);
		obj2.innerHTML = str4;	
		}
	showing = true;
	}
}



function toggle2(str1,str2,value) {

if (showing2)   {
	var obj1,obj2;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "hidden";
	obj1.style.height = "0px";
	obj1.style.display = "none";	
	obj2 = document.getElementById(str2);
	obj2.style.visibility = "hidden";
	obj2.style.height = "0px";
	obj2.style.display = "none";	
	showing2 = false;
	} else {
	var obj1,obj2;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "visible";
	obj1.style.height = "auto";
	obj1.style.display = "none";
	obj2 = document.getElementById(str2);
	obj2.style.visibility = "visible";
	obj2.style.height = "auto";
	obj1.style.display = "none";
	showing2 = true;
	}
}

function show(str1) {
	var obj1;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "visible";
	obj1.style.height = "auto";
	obj1.style.display = "block";
}

function hide(str1) {
	var obj1;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "hidden";
	obj1.style.height = "0px";
	obj1.style.display = "none";
}

function show2(str1,str2) {
	var obj1,obj2;
	obj1 = document.getElementById(str1);
	obj1.style.visibility = "visible";
	obj1.style.height = "auto";
	obj1.style.display = "block";
	obj2 = document.getElementById(str2);
	obj2.style.visibility = "visible";
	obj2.style.height = "auto";
	obj2.style.display = "block";
	showing2 = true;
}


function checkReviewForm(productID) {
		document.getElementById('nameCheck').innerHTML = '';
		document.getElementById('locationCheck').innerHTML = '';
		document.getElementById('reviewCheck').innerHTML = '';
		reviewForm.reviewName.style.border = '1px solid #ccc';				
		reviewForm.reviewLocation.style.border = '1px solid #ccc';				
		reviewForm.reviewReview.style.border = '1px solid #ccc';
		
		if ((reviewForm.reviewName.value.length < 3) || (reviewForm.reviewLocation.value.length < 3) || (reviewForm.reviewReview.value.length < 3)) {
			if (reviewForm.reviewName.value.length<3) {
				reviewForm.reviewName.style.border = '1px solid red';
				document.getElementById('nameCheck').innerHTML = 'Please enter a name';
				}
			if (reviewForm.reviewLocation.value.length<3) {
				reviewForm.reviewLocation.style.border = '1px solid red';
				document.getElementById('locationCheck').innerHTML = 'Please enter a location';
				}
			if (reviewForm.reviewReview.value.length<3) {
				reviewForm.reviewReview.style.border = '1px solid red';
				document.getElementById('reviewCheck').innerHTML = 'Please enter a review';
				}
			}
		else {
		callAHAH('ajax/ajaxSubmitReview.asp?PID='+productID+'&name='+ reviewForm.reviewName.value + '&location='+ reviewForm.reviewLocation.value + '&review='+ reviewForm.reviewReview.value + '&stars='+ reviewForm.reviewRating2.value,'newreview','Adding review...');		
		}
	}

function confirmDelete(text)
{
var agree=confirm(text);
if (agree) 
	return true ;
else
	return false ;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function ValidateNewsletterEmail(){
	// clear fields and warnings first
	$('#bothWarning').css({'visibility' : 'hidden'});
	$('#emailWarning').css({'visibility' : 'hidden'});	
	$('#nameWarning').css({'visibility' : 'hidden'});			
	$("#newsletterEmail").removeClass("inputWarning");
	$("#newsletterName").removeClass("inputWarning");
	
	var newsError = 0;
	var emailID=document.formNewsletter.newsletterEmail;
	var nameID=document.formNewsletter.newsletterName;
	
	if ((emailID.value==null)||(emailID.value=="")){
		newsError = 1;
	}
	
	if (echeck(emailID.value)==false){
		newsError = 1;
	}
	
	if ((nameID.value==null)||(nameID.value=="")){
		newsError += 10;
	}
	
	
	switch(newsError)
		{
		case 1:
			$('#emailWarning').css({'visibility' : 'visible'});	
			$("#newsletterEmail").addClass("inputWarning");
			emailID.focus();
			return false;
		case 10:
			$('#nameWarning').css({'visibility' : 'visible'});	
			$("#newsletterName").addClass("inputWarning");
			nameID.focus();
			return false;
		case 11:
			$('#bothWarning').css({'visibility' : 'visible'});		
			$("#newsletterEmail").addClass("inputWarning");
			$("#newsletterName").addClass("inputWarning");
			emailID.focus();
			return false;		
		case 0:
			$('#emailWarning').html('');
			callAHAH('ajax/ajaxNewsletter.asp?newsletterEmail='+emailID.value + '&newsletterName='+nameID.value,'feedback','<p>Loading...</p>');
			nameID.value = '';
			emailID.value = '';			
		   return true;
		}
	
 }
 
function validAccount()
{
	// Set up control variables 
	var valid = 0;
	var accFirstName=document.formCustomerDetails.customerFirstName;
	var accLastName=document.formCustomerDetails.customerSecondName;
	var accBillAddress=document.formCustomerDetails.customerBillingAddress;
	var accBillPC=document.formCustomerDetails.customerBillingPostcode;
	var accBillCountry=document.formCustomerDetails.customerBillingCountry;	
	var accPhone=document.formCustomerDetails.customerTelephone;
	var accEmail=document.formCustomerDetails.customerEmail;
	var accPassword1=document.formCustomerDetails.customerPassword;
	var accPassword2=document.formCustomerDetails.customerPasswordRepeat;
	var accShipBillSame=document.formCustomerDetails.customerShippingBillingSame;
	var accDelAddress=document.formCustomerDetails.customerShippingAddress;
	var accDelPC=document.formCustomerDetails.customerShippingPostcode;		
	var accShipCountry=document.formCustomerDetails.customerShippingCountry;			



	// Clear messages
	$('#firstNameEmptyWarning').hide();
	$('#lastNameEmptyWarning').hide();
	$('#billAddressEmptyWarning').hide();
	$('#billPCEmptyWarning').hide();
	$('#phoneEmptyWarning').hide();
	$('#emailWarning').hide();
	$('#passwordWarning1').hide();
	$('#passwordWarning2').hide();
	$('#delPCEmptyWarning').hide();
	$('#delAddressEmptyWarning').hide();
	 
	$('#customerFirstName').removeClass('inputWarning');
	$('#customerSecondName').removeClass('inputWarning');
	$('#customerBillingAddress').removeClass('inputWarning');
	$('#customerBillingAddress').removeClass('inputWarning');
	$('#customerTelephone').removeClass('inputWarning');
	$('#customerEmail').removeClass('inputWarning');
	$('#customerPassword').removeClass('inputWarning');
	$('#customerPasswordRepeat').removeClass('inputWarning');
	$('#customerShippingAddress').removeClass('inputWarning');
	$('#customerShippingPostcode').removeClass('inputWarning');
	
	if ((accFirstName.value==null)||(accFirstName.value=="")){
		$('#firstNameEmptyWarning').show();	
		$('#customerFirstName').addClass('inputWarning');
		accFirstName.focus();
		valid += 1;
	}
	
	if ((accLastName.value==null)||(accLastName.value=="")){
		$('#lastNameEmptyWarning').show();	
		$('#customerSecondName').addClass('inputWarning');
		accLastName.focus();
		valid += 1;
	}
	
	if ((accBillAddress.value==null)||(accBillAddress.value=="")){
		$('#billAddressEmptyWarning').show();	
		$('#customerBillingAddress').addClass('inputWarning');
		accBillAddress.focus();
		valid += 1;
	}		
	
	if (accBillCountry.value=="199") { // Postcode required for UK
		if ((accBillPC.value==null)||(accBillPC.value=="")){
			$('#billPCEmptyWarning').show();	
			$('#customerBillingPostcode').addClass('inputWarning');
			accBillAddress.focus();
			valid += 1;
		}
	}
	
	if ((accPhone.value==null)||(accPhone.value=="")){
		$('#phoneEmptyWarning').show();	
		$('#customerTelephone').addClass('inputWarning');
		accPhone.focus();
		valid += 1;
	}		
		
	if ((accEmail.value==null)||(accEmail.value=="")||(echeck(accEmail.value)==false)){
		$('#emailWarning').show();	
		$('#customerEmail').addClass('inputWarning');
		accEmail.focus();
		valid += 1;
	}
	
	if (accPassword1.value.length<6){
		$('#passwordWarning1').show();	
		$('#customerPassword').addClass('inputWarning');
		$('#customerPasswordRepeat').addClass('inputWarning');
		valid += 1;
	}
	
	if (accPassword1.value!=accPassword2.value){
		$('#passwordWarning2').show();	
		$('#customerPassword').addClass('inputWarning');
		$('#customerPasswordRepeat').addClass('inputWarning');
		valid += 1;
	}

	if(accShipBillSame.checked == 0){
		if ((accDelAddress.value==null)||(accDelAddress.value=="")){
			$('#delAddressEmptyWarning').show();	
			$('#customerShippingAddress').addClass('inputWarning');
			accShipBillSame.focus();
			valid += 1;
		}	
		if (accShipCountry.value=="199") { // Postcode required for UK
			if ((accDelPC.value==null)||(accDelPC.value=="")){
				$('#delPCEmptyWarning').show();	
				$('#customerShippingPostcode').addClass('inputWarning');
				accDelPC.focus();
				valid += 1;
			}	
		}
	}
	  
		
	if (valid > 0) 
	{			
		return false;		
	}
	else
	{		
		return true;		
	}
}



function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   if (validAccount()) {formCustomerDetails.submit()};
   return false;
   }
else
   return true;
}


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 YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

