function ISAPIPath()
{
	return 'http://www.fastfancydress.co.uk/bin/pxisapi1.exe';
}

function capitalise(s)
{
	if (navigator.appVersion.indexOf("Mac_") != -1)
	{
		return s;
	}
	if (navigator.appVersion.indexOf("Safari") != -1)
	{
		return s;
	}
	var str = s;
	str=str.toLowerCase();
	str=str.replace(/\b\w+\b/g, function(word) {
	return word.substring(0,1).toUpperCase()+ word.substring(1); });
	return str;
}

function showFlashMovie()
{
	var MM_contentVersion = 6;
	MM_FlashCanPlay = true;

	if ( MM_FlashCanPlay )
	{
	    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
		document.write(' ID="script" WIDTH="590" HEIGHT="180" ALIGN="">');
		document.write(' <PARAM NAME=movie VALUE="templates/imagedirectory/auto_scroll.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>  ');
		document.write(' <EMBED src="/templates/imagedirectory/auto_scroll.swf" quality=high bgcolor=#FFFFFF');
        	document.write(' swLiveConnect=FALSE WIDTH="590" HEIGHT="180" NAME="script" ALIGN=""');
        	document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
        	document.write(' </EMBED>');
        	document.write(' </OBJECT>');
	} 
	else
	{
		document.write('<IMG SRC="/templates/imagedirectory/kitnoflash.jpg" usemap="#script" BORDER=0>');
	}
}

function addToFavorites()
{ 
	var urlAddress = window.location.href;
	var pageName = document.title;

	if (window.external) 
		{ window.external.AddFavorite(urlAddress,pageName)} 
	else
		{ alert("Sorry! Your browser doesn't support this function."); }
} 

function emailme(item)
{
	location.replace(ISAPIPath() + '/emailme?item=' + item)
}

function showFlashMovie()
{
	var MM_contentVersion = 6;
	MM_FlashCanPlay = true;

	if ( MM_FlashCanPlay )
	{
	    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
		document.write(' ID="script" WIDTH="590" HEIGHT="180" ALIGN="">');
		document.write(' <PARAM NAME=movie VALUE="templates/imagedirectory/auto_scroll.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>  ');
		document.write(' <EMBED src="/templates/imagedirectory/auto_scroll.swf" quality=high bgcolor=#FFFFFF');
        document.write(' swLiveConnect=FALSE WIDTH="590" HEIGHT="180" NAME="script" ALIGN=""');
        document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
        document.write(' </EMBED>');
        document.write(' </OBJECT>');
	} 
	else
	{
		document.write('<IMG SRC="/templates/imagedirectory/kitnoflash.jpg" usemap="#script" BORDER=0>');
	}
}

function showpopup(popupURL, pleft, ptop, pwidth, pheight) 
{
  // open the popup window
  
var popup = window.open(popupURL,"PopUp",'toolbar=0, location=0,directories=0, status=0,menubar=0,scrollbars=1,resizable=1, width=' + (pwidth + 50) + ', height=' + (pheight + 70) + ', left=' + pleft + ', top=' + ptop);
  // set the opener if it's not already set.  it's set automatically
  // in netscape 3.0+ and ie 3.0+.
  
  if (window.focus) {popup.focus()}
  
  popup.window.resizeTo(pwidth + 50, pheight + 130)
  
  if( navigator.appName.substring(0,8) == "Netscape" ) {
    popup.location = popupURL;
  }
}

function ViewLarge(Item)
{
	location.replace(ISAPIPath() + '/large?item=' + Item)
	//window.navigate(ISAPIPath() + '/large?item=' + Item)
}

function ShowCatalogue(Level)
{
	location.replace(ISAPIPath() + '/catalogue?level=' + Level)
	//window.navigate(ISAPIPath() + '/catalogue?level=' + Level)
}

function ShowInfo(Item)
{
	location.replace(ISAPIPath() + '/info?id=' + Item)
}

function YourAccount()
{
	location.replace(ISAPIPath() + '/user')	
}

function Logout()
{
	location.replace(ISAPIPath() + '/logout')
}

function EditItem(Item)
{
	location.replace(ISAPIPath() + '/large?cartrow=' + Item)
}


function ResolvePC(postcodefield, addressfield)
{
	var x = new CrossXHR();
	var sURL = "/bin/pxisapi1.exe/postcode?postcode=" + postcodefield.value;
	var i;
	var address;
	
	if (postcodefield.value == "")
	{
		alert("Please specify a postcode");
		return false;
	}
		
	x.open( "GET", sURL, false );
	x.send();
	var addresslines = x.responseText.split("~");
	
    addressfield.options.length=0;
	var opt = document.createElement("option");
    addressfield.options.add(opt);
    opt.text = "Please select address...";
	opt.value = "-1";
	
	for(i = 1; i < addresslines.length; i++)
	{
		var opt = document.createElement("option");
       	addressfield.options.add(opt);
        address = addresslines[i].split(",");
        opt.text = address[2];
		opt.value = address[0];
	}
}

function CrossXHR() {
 var crossxhr = false;
 if(window.XMLHttpRequest) {
  crossxhr = new XMLHttpRequest();
  if(crossxhr.overrideMimeType) {
   crossxhr.overrideMimeType('text/xml');
  }
 } else if(window.ActiveXObject) {
  try {
   crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
  } catch(e) {
   try {
    crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
   } catch(e) {
    crossxhr = false;
   }
  }
 }
 return crossxhr;
}

function GetAddress(id, fieldset)
{
	var x = new CrossXHR();
	var sURL = "/bin/pxisapi1.exe/postcode?id=" + id;
	var i;
	var addressfields;
	var s = "";
	
	x.open( "GET", sURL, false );
	x.send();
	var addresslines = x.responseText.split("~");
	addressfields = addresslines[1].split(",");
	if (fieldset == 1)
	{
		document.getElementById('Bill_2').value = addressfields[11];
		if (addressfields[2] != "")
		{
			document.getElementById('Bill_3').value = addressfields[2];
			s = addressfields[4];
			if (addressfields[5] != '')
			{
				s = s + ',' + addressfields[5];
			}
			document.getElementById('Bill_4').value = s;			
		}
		else
		{
			document.getElementById('Bill_3').value = addressfields[4];
			document.getElementById('Bill_4').value = addressfields[5];
		}		
		document.getElementById('Bill_5').value = addressfields[9];	
		document.getElementById('Bill_6').value = addressfields[10];	
		document.getElementById('Bill_7').value = 'United Kingdom';	
	}
	if (fieldset == 2)
	{
		document.getElementById('Deli_2').value = addressfields[11];
		if (addressfields[2] != "")
		{
			document.getElementById('Deli_3').value = addressfields[2];
			s = addressfields[4];
			if (addressfields[5] != '')
			{
				s = s + ',' + addressfields[5];
			}
			document.getElementById('Deli_4').value = s;			
		}
		else
		{
			document.getElementById('Deli_3').value = addressfields[4];
			document.getElementById('Deli_4').value = addressfields[5];
		}		
		document.getElementById('Deli_5').value = addressfields[9];	
		document.getElementById('Deli_6').value = addressfields[10];	
		document.getElementById('Deli_7').value = 'United Kingdom';	
	}
}

function ViewCart()
{
	location.replace(ISAPIPath() + '/cart')
}

function ShowCheckout()
{
	document.form2.action = ISAPIPath() + '/checkout1';
	document.form2.method = 'POST';
	document.form2.submit();
}

function AddDeliAddress(callerpage,id,callerid)
{
	document.form1.action=ISAPIPath() + '/checkout1?id=-1&caller=' + callerid
	document.form1.submit();
}

function EditDeliAddress(callerpage,id,callerid)
{
	document.form1.action=ISAPIPath() + '/checkout1?id=' + document.form1.DeliAdd.value + '&caller=' + callerid
	document.form1.submit();
}

function DeliAddDropDown(caller)
{
	document.form1.onsubmit="return(true)";
	document.form1.action=ISAPIPath() + '/checkout1?deliadd=' + document.form1.DeliAdd.value + '&caller=' + caller;
	document.form1.submit();
}

function checkmandatories()
{
	var i;
	var b;
	var check_delivery;
	b = true;

	if (document.form1.Bill_9.value == "")
	{
		b = false;
		alert("Please complete field : Forename");
		return b;
	}		
	
	if (document.form1.Bill_10.value == "")
	{
		b = false;
		alert("Please complete field : Surname");
		return b;
	}		
	
	if (document.form1.Bill_3.value == "")
	{
		b = false;
		alert("Please complete field : Address 1");
		return b;
	}		


	if (document.form1.Bill_2.value == "")
	{
		b = false;
		alert("Please complete field : Postcode");
		return b;
	}

	if (document.form1.Bill_7.value == "")
	{
		b = false;
		alert("Please complete field : Country");
		return b;
	}
			
	if (document.form1.Bill_11.value == "")
	{
		b = false;
		alert("Please complete field : Telephone");
		return b;
	}

	if (document.form1.Bill_12.value == "")
	{
		b = false;
		alert("Please complete field : Mobile No");
		return b;
	}

	if (document.form1.Bill_13.value == "")
	{
		b = false;
		alert("Please complete field : E-Mail Address");
		return b;
	}

	//See if any delivery fields are filled in
	//If any are, check them all and warn if any are missing
	check_delivery = false;
	if (document.form1.Deli_8.value != "") {check_delivery = true};
	if (document.form1.Deli_9.value != "") {check_delivery = true};
	if (document.form1.Deli_10.value != "") {check_delivery = true};
	if (document.form1.Deli_3.value != "") {check_delivery = true};
	if (document.form1.Deli_4.value != "") {check_delivery = true};
	if (document.form1.Deli_5.value != "") {check_delivery = true};
	if (document.form1.Deli_6.value != "") {check_delivery = true};
	if (document.form1.Deli_7.value != "") {check_delivery = true};
	if (document.form1.Deli_2.value != "") {check_delivery = true};
	if (document.form1.Deli_11.value != "") {check_delivery = true};
	if (document.form1.Deli_13.value != "") {check_delivery = true};

	if (check_delivery == true)
	{
		if (document.form1.Deli_9.value == "")
		{
			b = false;
			alert("Please complete field : Delivery Forename");
			return b;
		}		
	
		if (document.form1.Deli_10.value == "")
		{
			b = false;
			alert("Please complete field : Delivery Surname");
			return b;
		}		
	
		if (document.form1.Deli_3.value == "")
		{
			b = false;
			alert("Please complete field : Delivery Address 1");
			return b;
		}		

		if (document.form1.Deli_7.value == "")
		{
			b = false;
			alert("Please complete field : Delivery Country");
			return b;
		}

		if (document.form1.Deli_2.value == "")
		{
			b = false;
			alert("Please complete field : Delivery Postcode");
			return b;
		}		

	}

	
	if (document.form1.Campaign.value == -1)
	{
		b = false;
		alert("Please complete field : How did you hear about us");
		return b;
	}	

	if (document.form1.CardType.options[0].selected)
	{
		b = false;
		alert('Please select card type');  
		return b;
	}


	if (document.form1.CardNumber.value == "")
	{
		b = false;
		alert("Please complete field : Card Number");
		return b;
	}

	if (document.form1.CV2.value == "")
	{
		b = false;
		alert("Please complete field : CVV Verification No. (3 digit number on back of card)");
		return b;
	}
	return b;
}

function checkmandatories_delivery()
{
	var i;
	var b;
	b = true;

	if (document.form1.Deli_10.value == "")
	{
		b = false;
		alert("Please complete field : Surname");
		return b;
	}		
	
	if (document.form1.Deli_3.value == "")
	{
		b = false;
		alert("Please complete field : Address 1");
		return b;
	}		
	
	if (document.form1.Deli_2.value == "")
	{
		b = false;
		alert("Please complete field : Postcode");
		return b;
	}
			
	return b;
}

function checkuserfields()
{
	var i;
	var b;
	b = true;

	if (document.form1.FullName.value == "")
	{
		b = false;
		alert("Please complete field : Full Name");
		return b;
	}		

	if (document.form1.FullName.value.length < 6)
	{
		b = false;
		alert("E-Mail Address (Full Name) must be at least 6 characters");
		return b;
	}
		
	if (document.form1.LoginName.value == "")
	{
		b = false;
		alert("Please complete field : E-Mail Address (Login Name)");
		return b;
	}		

	if (document.form1.LoginName.value.length < 6)
	{
		b = false;
		alert("E-Mail Address (Login Name) must be at least 6 characters");
		return b;
	}

	if (document.form1.LoginName.value.indexOf("@") < 0)
	{
		b = false;
		alert("E-Mail Address (Login Name) is invalid - Please re-enter");
		return b;
	}
	
	if (document.form1.LoginName.value.indexOf(".") < 0)
	{
		b = false;
		alert("E-Mail Address (Login Name) is invalid - Please re-enter");
		return b;
	}
		
	if (document.form1.Password.value == "")
	{
		b = false;
		alert("Please complete field : Password");
		return b;
	}	
	
	if (document.form1.Password.value.length < 6)
	{
		b = false;
		alert("Password must be at least 6 characters");
		return b;
	}	
	
	if (document.form1.Password2.value == "")
	{
		b = false;
		alert("Please complete field : Verify Password");
		return b;
	}
	
	if (document.form1.Password.value != document.form1.Password2.value)
	{
		b = false;
		alert("Passwords do not match - Please re-enter");
		return b;
	}		
	
	if (document.form1.Bill_3.value == "")
	{
		b = false;
		alert("Please complete field : Address 1");
		return b;
	}		
	
	if (document.form1.Bill_2.value == "")
	{
		b = false;
		alert("Please complete field : Postcode");
		return b;
	}	
	return b;
}

function ConfirmDelete()
{
	return (confirm("Are you sure that you wish to delete this address?"));
}

function CardTypeChange()
{
//	if (document.getElementById("CardType").value == "SW")
//		document.getElementById("IssueNo").mandatory = "true"
//	else
  document.getElementById("IssueNo").mandatory = "false";
}

function ClickSubmit()
{
	if (checkmandatories())
		{
			document.form1.S1.disabled=true;
			document.form1.submit();
		}
}

function CountGroupItems(formName,GroupNo)
{
	var i;
	var iGroup;
	var iCounter = 0;
	var lcol = document.getElementById(formName).all;;
	for (i = 0;i <= lcol.length - 1; i++)
		{
			if ((lcol[i].tagName == 'SELECT') | (lcol[i].tagName == 'INPUT'))
				{
					iGroup = lcol[i].group;
					if (iGroup == GroupNo)
						{
							if (lcol[i].value != '-1')
								if (lcol[i].tagName == 'SELECT')
									iCounter++
								else
									if (lcol[i].checked)
										iCounter++;
						}
				}
		}
	return iCounter;
}

function CheckProductFields(formName)
{
	var iMinFields;
	var i;
	var iGroup;
	var sMandatory;
	var b = false;
	var bFinal = true;
	var iTotalEntered = 0;
	var showalert = false;

	if (navigator.appVersion.indexOf("MSIE") == -1)
	{
		//return true;
	}

	var col = document.forms[formName].elements;
	
	if (col != null)
		{
			for (i=0;i <= col.length - 1;i++)
				if (document.getElementById("option_" + col[i].choiceid) != undefined)
					document.getElementById("option_" + col[i].choiceid).style.color = "black";
//					document.getElementById("option_" + col[i].choiceid).classname = "ClassMandatoryFieldNormal";
			for (i=0;i <= col.length - 1;i++)
				{
					if ((col[i].value == 'Out of Stock') || (col[i].value == 'Out of stock') || (col[i].value == 'Call Us'))
					{
						alert("Sorry, this item is currently out of stock");
						return false;
					}
					
					iGroup = col[i].group;
					if (iGroup != undefined)
						{
							iMinFields = document.getElementById("group_" + iGroup).value;
							sMandatory = document.getElementById("group_" + iGroup).mandatory;
							iTotalEntered = CountGroupItems(formName,iGroup);
							b = false;
							if (sMandatory == 'true')
								{
									if (iTotalEntered >= iMinFields)
										b = true;
								}
							else
								{
									if ((iTotalEntered >= iMinFields) | (iTotalEntered == 0))
										b = true;
								}
							bFinal = (bFinal && b);
							if (!b)
								{
									if ((col[i].value == '-1') & (document.getElementById("option_" + col[i].choiceid) != undefined))
									{
											showalert = true;
											document.getElementById("option_" + col[i].choiceid).style.color = 'red';
									}
//										document.getElementById("option_" + col[i].choiceid).classname = 'ClassMandatoryFieldMissing';
								}
						}
				}
		}
	if ((!bFinal) & (document.getElementById(formName + 'mandatorywarning') != undefined))
	{
		showalert = true;
		document.getElementById(formName + 'mandatorywarning').style.visibility = 'visible';
	}
	
	if (showalert == true)
	{
				alert("Please select an item from the 'please choose one' list");
	}
	return bFinal;
}


function PaymentSection()
{
	if (document.getElementById("d_paymentmethod").value == '7')
		document.getElementById("divCCPayment").style.visibility = "visible"
	else
		document.getElementById("divCCPayment").style.visibility = "hidden";
}

function checkcarddetails2(form)
{
	var letter = /^[a-zA-Z\s]+$/;
	var today = new Date();
	var start_date = new Date(2000 + parseInt(form.IssueYear.options[form.IssueYear.selectedIndex].value), form.IssueMonth.options[form.IssueMonth.selectedIndex].value-1);
	var expiry_date = new Date(2000 + parseInt(form.ExpYear.options[form.ExpYear.selectedIndex].value), form.ExpMonth.options[form.ExpMonth.selectedIndex].value);
	var ccno = form.CardNumber.value; //Card number
	var ccno = ccno.replace(/ /g, "");
	var msg = 'The credit card number you entered could not be\n validated. Please check the number and try again.';
	var start_date_present = false;
	
	//########## CHECK CARD TYPE ##########
	if (form.CardType.options[0].selected)
	{
		alert('Please select card type');  
		form.CardType.focus();
		return false;
	}

	//########## CHECK CARD DETAILS ##########
	vlengthgood=0;
	ccsum=0;
	cclen=ccno.length;
	if (cclen<13)
	{
		alert("Card number must have at least 13 digits.");
		return false;
	}
	else
	{
		for (i=1; i<cclen; i++)
		{
			ccdig=parseInt(ccno.charAt(cclen-(i+1)));
			if (i%2==1)
			{
				ccdig*=2;
				if (ccdig.toString().length==2)
				{
					ccdig=(parseInt(ccdig.toString().charAt(0))+parseInt(ccdig.toString().charAt(1)));
				} 
			}
			ccsum+=ccdig;
		}
		ccsum+=parseInt(ccno.charAt(cclen-1));
		if (ccsum%10!=0)
		{
			alert('Incorrect Card Number - Please re-enter');
			return false;
		}
	}

	//########## CHECK START DATE PRESENT ##########
	if ((form.IssueMonth.options[0].selected) && (form.IssueYear.options[0].selected == false))
	{
		alert('Please select start month');  
		form.ExpMonth.focus();
		return false;
	}

	if ((form.IssueMonth.options[0].selected == false) && (form.IssueYear.options[0].selected))
	{
		alert('Please select start year');  
		form.ExpMonth.focus();
		return false;
	}

	if ((form.IssueMonth.options[0].selected == false) && (form.IssueYear.options[0].selected == false))
	{
		if(start_date > today)
		{
			alert('Please enter the correct start date for the card');
			form.IssueYear.focus();
			return false;
		}
	}

	//########## CHECK EXPIRY MONTH ENTERED ##########
	if (form.ExpMonth.options[0].selected)
	{
		alert('Please select expiry month');  
		form.ExpMonth.focus();
		return false;
	}

	//########## CHECK EXPIRY YEAR ENTERED ##########
	if (form.ExpYear.options[0].selected)
	{
		alert('Please select expiry year');  
		form.ExpYear.focus();
		return false;
	}
	
	//########## CHECK EXPIRY DATE ##########	
	if(expiry_date < today)
	{
		alert('Please enter the correct expiry date for the card');
		return false;
	}

	if ((form.CardType.value != 'SWITCH') && (form.CardType.value != 'SOLO') && (form.CardType.value != 'DELTA') && (form.IssueNo.value != ''))
	{
		alert('Issue No is not appropriate to this type of card. Please delete the Issue No field');  
		form.IssueNo.focus();
		return false;
	}

	return true;
}

function checkcarddetails2_old(form) {
	var letter = /^[a-zA-Z\s]+$/;
	var today = new Date();
	var start_date = new Date(2000 + parseInt(form.IssueYear.options[form.IssueYear.selectedIndex].value), form.IssueMonth.options[form.IssueMonth.selectedIndex].value-1);
	var expiry_date = new Date(2000 + parseInt(form.ExpYear.options[form.ExpYear.selectedIndex].value), form.ExpMonth.options[form.ExpMonth.selectedIndex].value);
	var ccno = form.CardNumber.value; //Card number
	var ccno = ccno.replace(/ /g, "");
	var msg = 'The credit card number you entered could not be\n validated. Please check the number and try again.';

	//########## Check Card Type ##########
	if (form.CardType.options[0].selected)
	{
		alert('Please select card type');  
		form.CardType.focus();
		return false;
	}

	vlengthgood=0;
	ccsum=0;
	cclen=ccno.length;
	if (cclen<13)
	{
		alert("Card number must have at least 13 digits.");
		return false;
	}
	else
	{
		for (i=1; i<cclen; i++)
		{
			ccdig=parseInt(ccno.charAt(cclen-(i+1)));
			if (i%2==1)
			{
				ccdig*=2;
				if (ccdig.toString().length==2)
				{
					ccdig=(parseInt(ccdig.toString().charAt(0))+parseInt(ccdig.toString().charAt(1)));
				} 
			}
			ccsum+=ccdig;
		}
		ccsum+=parseInt(ccno.charAt(cclen-1));
		if (ccsum%10!=0)
		{
			alert('Incorrect Card Number - Please re-enter');
			return false;
		}
	}	
	return true;
}
//--></SCRIPT>