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];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}
//----------------------------------------------------------------------------------------------------
var total;
var totalValue=0;
var noPost = 0;
var Apost = 0;
var postage = 0;
var postR = 0;
var nextD = 0;
var PostA = 2.00;     // post accessories
var PostAND = 8.50;	  // post accessories next day
var PostRep = 6.50;     // post repair
var PostRepND = 17.50;	  // post repair next day
var PostNorm = 0.00;  // post normal 
var PostNormND = 17.50;  // post normal next day
var PostANI = 3.50;     // post accessories NI
var PostANIND = 11.75;	// post accessories NI next day
var PostNormNI = 9.50;  // post normal NI	
var PostNormNIND = 35.50; // post normal NI next day
var PostRepNI = 9.50;	  // post repair NI
var PostRepNIND = 35.50;	  // post repair NI next day
var PostAOS = 10.50;		// post acessories OS
var PostNormOS = 28.50;	// post normal OS
var PostRepOS = 28.50;	  // post repair OS
//      - - - - - - - - Get total in basket- - - - - - - -      
function GetTotal (name) 
{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) 
		{
        		var j = i + alen;
                if (document.cookie.substring(i, j) == arg) {  return getCookieVal (j); }
		        i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break; 
        }
return null;
}
function getCookieVal (offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1) {  endstr = document.cookie.length; }
        return unescape(document.cookie.substring(offset, endstr));
}
// -------------------------------------- set the cookie
function setCookie_arr (name, value, expires) 
{
    if (!expires) expires = new Date();
	document.cookie = name + "=" + escape (value) + 
	"; expires=" + expires.toGMTString() +  "; path=/";
}
//----------------------------------------------------------------------------------------------------
var expdate = new Date();
expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 1));  
var Apost = 0;
var postArray;
var basketArray;
var checkoutArray = new Array();
//----------------------------------------------------------------------------------------------------
function GetLine(line)
{
	if((line <= total)&&(total > 0))
	 {
		var basket_str = GetTotal("basket"+line+"_");
		checkoutArray[line] = basket_str;		
		basketArray = basket_str.split("!");
		var xxx = basketArray[5];
		var yyy = xxx.substring(1,xxx.length);
		totalValue = parseFloat(totalValue) + parseFloat(yyy);
		if((Apost == 0) || (Apost == 1) || (Apost == "undefined"))
		 { Apost = basketArray[6]; }
	 }
//alert(total);
//alert(checkoutArray[line]);
//alert(basketArray[5]);
//alert(Apost);
}
//----------------------------------------------------------------------------------------------------
function remove_it(name)
{
 	var i = name;
	while(i < total)
	 {
	 	var j = i; j++;
		var tmp_str = GetTotal("basket"+j+"_");
		setCookie_arr("basket"+i+"_",tmp_str,expdate);
		i++;
	 }
	setCookie_arr("basket"+total+"_","",expdate);
	total--;
	setCookie_arr("tot_basket",total,expdate);
	window.history.go(0);
}
//----------------------------------------------------------------------------------------------------
function GotoCheckout()
{
var valid = validateIt();  if(valid == false) { return false; }
//alert("going to checkout3");	
	setCookie_arr("postage_",postage,expdate);
	browsername=navigator.appName;
	if (browsername.indexOf("Netscape")!=-1) {browsername="NS"}
	else {if (browsername.indexOf("Microsoft")!=-1) {browsername="MSIE"}
	else {browsername="N/A"}};
var resultWnd
	if(browsername=="MSIE")
	{
			resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
//		resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
		"toolbar=no,menubar=no,width=800,height=550,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes");
	}
	else if(browsername=="NS")
	{
		resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
//		resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
		"toolbar=no,menubar=no,innerWidth=800,innerHeight=550,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes");
	}
	else
	{
		resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
//		resultWnd = window.open("http://www.leatherup.co.uk/checkout.php",null, 
		"toolbar=no,menubar=no,width=800,height=550,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes");
	}
//	window.location.href="didyou.htm";
}
// -------------------------------------- set postage
function UpgradePost() 
{
	if(nextD == 1) { DowngradePost(); }
	else 
	 {	
if(confirm("!!! This option can only be used if pre-arranged with leatherup.co.uk !!!\n    as your LeatherUp item must be available off-the-rail"))
		{
		nextD = 1; 
		if(postR == 1)	{	if(Apost == 2) { postage = PostAND; } else { postage = PostNormND; } }
		else if(postR == 2)	{	if(Apost == 2) { postage = PostANIND; } else { postage = PostNormNIND;	} }
		else if(postR == 3)	{	alert("Not available on overseas shipments"); nextD = 0; }
		setCookie_arr("postage_","!"+postage+"!"+postR+"!"+nextD+"!",expdate);
		window.history.go(0);
		}
	 }
}		
function DowngradePost() 
{
	nextD = 0;
	SetPostageRegion();
}
//----------------------------------------------------------------------------------------------------
function SetupPost() 
{
	 SetPostageRegion();
}
//function SetPostageRegionXX()
//{
//var postsel = document.postalR.selectP.value;
//if(postsel == "UK") { postR = 1; }
//else if(postsel == "NI") { postR = 2; }
//else if(postsel == "XX") { postR = 3; }
//else { postR = 0; }
//alert(postsel);
//SetPostageRegion();
//}
//----------------------------------------------------------------------------------------------------
function SetPostageRegion()
{
noPost = GetTotal("nopost");
//alert(noPost);
//alert(postR);
if( (noPost == 0) || (noPost == null) || (noPost == "undefined") )
 {	
	if( (postR == 0) || (postR == null) || (postR == "undefined") )
	 { alert("Please select your region"); document.forms['postalR'].selectP.selectedIndex=0; document.postalR.select.focus(); }
	else if(postR == 1)
	 { 
		if(Apost == 1)  { postage = PostA; if(nextD == 1) { postage = PostAND; } }
		else if (Apost == 2) { postage = PostNorm; if(nextD == 1) { postage = PostNormND; } }
		else if (Apost == 3) { postage = PostRep; if(nextD == 1) { postage = PostRepND; } }
		setCookie_arr("postage_","!"+postage+"!"+postR+"!"+nextD+"!",expdate);
document.forms['postalR'].selectP.selectedIndex=1;
		window.history.go(0);
	 }
	else if(postR == 2) 
	 { 
//alert("NI"); 
		if(Apost == 1)  { postage = PostANI; if(nextD == 1) { postage = PostANIND; } }
		else if (Apost == 2) { postage = PostNormNI;  if(nextD == 1) { postage = PostNormNIND; } }
		else if (Apost == 3) { postage = PostRepNI; if(nextD == 1) { postage = PostRepNIND; } }
		setCookie_arr("postage_","!"+postage+"!"+postR+"!"+nextD+"!",expdate);
document.forms['postalR'].selectP.selectedIndex=2;
		window.history.go(0);
	 }
	else if(postR == 3) 
	 { 
//alert("!UK"); 
		if(Apost == 1)  { postage = PostAOS; } 
		else if (Apost == 2) { postage = PostNormOS;  }
		else if (Apost == 3) { postage = PostRepOS; }
		if(nextD == 1) { alert("Next day option is not available on overseas shipments"); nextD = 0; }
		setCookie_arr("postage_","!"+postage+"!"+postR+"!"+nextD+"!",expdate);
document.forms['postalR'].selectP.selectedIndex=3;
		window.history.go(0);
	}
 }
}
function SetPostageRegionIndx()
{
    noPost = GetTotal("nopost");
	if(noPost == 1) { postR = 0; }
	 document.forms['postalR'].selectP.selectedIndex=postR;
}
//----------------------------------------------------------------------------------------------------
function GetLinePost()
{
		var post_str = GetTotal("postage_");
		postArray = post_str.split("!");
//for(var i = 0; i < 5;i++){alert(postArray[i]);}
		postage = postArray[1];
		postR = postArray[2];
		nextD = postArray[3];
}
//----------------------------------------------------------------------------------------------------
function formatCurrency(num) {
num = num.toString().replace(/\£|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
pence = num%100;
num = Math.floor(num/100).toString();
if(pence<10)
pence = "0" + pence;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '£' + num + '.' + pence);
}
//----------------------------------------------------------------------------------------------------
function LoadUp()	
{	
	total = GetTotal("tot_basket");
}
//----------------------------------------------------------------------------------------------------
function goPaypal()
{	
	document.write("<div align='center'>");
	document.write("<form onsubmit='return formvalidation()' name='paypalit' action='https://www.paypal.com/cgi-bin/webscr' method='post'>");
	document.write("<input type='hidden' name='cmd' 			value='_cart'>");
	document.write("<input type='hidden' name='upload' 			value='1'>");
	document.write("<input type='hidden' name='business'  		value='orders@leatherup.co.uk'>");
	document.write("<input type='hidden' name='currency_code'	value='GBP'>");
//	document.write("<input type='hidden' name='on0'				value='Telephone'>");
	document.write("<input.type='hidden' name='return' 					value='http://www.leatherup.co.uk/thankyou.htm'>");
	document.write("<input.type='hidden' name='image_url'  value='http%3A//www.leatherup.co.uk/leatherup_logo.gif'>");
//  fill in the items--------------------------------------------------------------------------
// basket array = Size, measurements, colour, style, price, apost
	total = GetTotal("tot_basket");
	for(var i = 0; i < total;i++)
	 {
 	 	var x = i; x++;
        GetLine(x);
		var cost = basketArray[5].substring(1,basketArray[5].length);
 	 	document.write("<input type='hidden' name='item_name_"+x+"' 	value='"+basketArray[1]+"  "+basketArray[2]+"  "+basketArray[3]+"  "+basketArray[4]+"'>");
		document.write("<input type='hidden' name='amount_"+x+"' 		value='"+cost+"'>");
// 	 	alert("<input type='hidden' name='item_name_"+x+"' 	value='"+basketArray[1]+"  "+basketArray[2]+"  "+basketArray[3]+"  "+basketArray[4]+"'>");
//		alert("<input type='hidden' name='amount_"+x+"' 		value='"+cost+"'>");
	 }
//	var totalLines =  total;   totalLines++;
 	 	document.write("<input type='hidden' name='shipping_1'		value='"+postage+"'>");
//		alert("<input type='hidden' name='shipping_1' 		value='"+postage+"'>");
// -----------------------------------------------------------	
	document.write("<input type='submit' align='BOTTOM' value='PayPal'>");
	document.write("</form>");
    document.write("</div>");
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
function formvalidation()
{
			return(validateIt());
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
function validateIt()
{
//alert("here");
noPost = GetTotal("nopost");
//alert(postR); 
	if( ((postR == 0)  || (postR == null) || (postR == "undefined"))
	 && ((noPost == 0) || (noPost == null) || (noPost == "undefined")) )
	 { 
	 alert("Please select your region"); 
//	 document.forms['postalR'].selectP.selectedIndex=0; document.postalR.select.focus(); 
	 return false; 
	 }
//alert("going to checkout2");	
var ok = document.formTerms.terms.checked;	
//alert(ok);	
	if(!ok) 
	 { 
	 	alert("Please read our terms of supply, and check the box to say that you have read and understand them in full");   
		ok = 0; 
		return false; 
	}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
function showSpeed()
{
		   total = GetTotal("tot_basket");
		   if(total>0)
		   {
		    GetLinePost();
		  	if(nextD == 0) { document.write("<font size='2'>Upgrade to urgent delivery(pre-arranged only)</font>"); }
		  	else if(nextD == 1)  { document.write("<font size='2'>Downgrade to normal delivery</font>");  }
		   }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------

