/***********************************************************\
 Turbo Shop v4  Copyright (c) GMBB LTD 2001

 Description:

 Author: Olivier Ricard
 Date Created: 09/01/00

 Last Modified: 07/12/01 11:07
 Modified by: Pete
 Modification Desc.: signing off
 Level 1. 07/12/01 11:08
\***********************************************************/

function PlusQty(form) {
   // qty is the name of the textbox to add a item
  form.qty.value =parseInt(form.qty.value)+1;
}

 function MinusQty(form) {
   // qty is the name of the textbox to add a item
   if(parseInt(form.qty.value) >1)
   	form.qty.value = parseInt(form.qty.value)-1;
 }
 
 function preserveZeros(val) // make a string - to preserve the zeros at the end
{
	var i;
	val = val + '';
	var decimalPos = val.indexOf('.');
	if (decimalPos == -1)
	{
		val += '.';
		for (i=0; i<2; i++)
		{
			val += '0';
		}
	}
	else
	{
		var actualDecimals = (val.length - 1) - decimalPos;
		var difference = 2 - actualDecimals;
		for (i=0; i<difference; i++)
		{
			val += '0';
		}
	}

	return val;
}


function ts4NumberFormat(val) //pound - pence formating
{
	var factor;
	var i;
	// round to a certain precision (2)
	factor = 1;
	for (i=0; i<2; i++)
	{
		factor *= 10;
	}
	val *= factor;
	val = Math.round(val);
	val /= factor;
	return (preserveZeros(val));
}



 function Currency(curr) {
 	curr = ts4NumberFormat(curr);
   var s = "" + curr;
   pos = s.indexOf('.');
   if(pos==-1) pos=s.length;
   int1 = s.substr(0,pos);
   dec1 = s.substr(pos+1,2);
   if(dec1.length==1) dec1 += '0';
   if(dec1=="") dec1="00";
   result = int1 + "." + dec1;

   return result;
 }

 function Format(obj,nb) {
   var s = "" + obj;
   pos = s.indexOf('.');
   if(pos==-1) return true;
   int1 = s.substr(0,pos);
   dec = s.substr(pos+1,nb);
   result = int1 + "." + dec;
   document.forms[0].qty.value = parseFloat(result);
 }

 function check(obj) {
   if(isNaN(obj.value) || obj.value=="" || obj.value==0) {
   	obj.value = obj.defaultValue;
   	return false;
   }
 }

function Multibuy()
{
	var args=Multibuy.arguments;
	var cost = args[0];
	var id = args[1];
  	var form;
  	form = eval('document.form'+id);
  	if(args.length==3) {
  		var qnty = args[2];
  		if(qnty==0) return 0;
  	}else {
  		var qnty = form.qty.value;
  	}

	var qntyTrig;
	var info = new Array();
	info = form.multibuy.value.split('#');

	var unitcost  = form.unitcost.value;
	// *** 1st parameter : price ; 2nd parameter the nb of items
	var tick = false;
	var discount;

	if(parseFloat(qnty) >= parseFloat(info[1]))
	{

		if( (qnty % info[1])==0)
		{
			qntyTrig = qnty;
		}else
		{
			qntyTrig = (qnty - (qnty % info[1]));
		}
		tick = true;
	}

	if(tick==true)
	{
		discount = parseFloat(qntyTrig * (unitcost - (info[0]/info[1])),2);
		cost = parseFloat(qnty*unitcost-discount,2);
	}else
	{
		cost = parseFloat(qnty*unitcost,2);
	}
	return cost;//Currency(cost);
}






// Javascript code file for Splendour.com
// Commenced DC 02/07/01
// for Digivate Limited

function emailValid(theForm)
{
var y=1;
	if (theForm.value == "")
 		{
 			alert("Please enter your email address.");
 			theForm.focus();
 			y=0;
 		}
 	else
 		{
 		if (emailCheck(theForm) != true)
 			{
 				theForm.focus();
 				y=0;
 			}
 		}
	if (y == 0)
 		{
 			return(false);
 		}
 	else
 		{
 			var v=window.open('draw.htm','draw','scrollbars=no,width=405,height=460,top=25,left=25')
 			return (true);
 		}

}

/**
* setcookie - emulate PHP setcookie function
**/
function SetCookie( cookieName, cookieVal, cookieExp, cookiePath, cookieDom, cookieSecure)
{
  var toSet = cookieName + "=" + cookieVal +
      ((cookieExp) ? "; expires=" + cookieExp : "") +
      ((cookiePath) ? "; path=" + cookiePath : "") +
      ((cookieDom) ? "; domain=" + cookieDom : "") +
      ((cookieSecure) ? "; secure" : "");

  document.cookie = toSet;
}

function tsRefreshBasket() {
	var offset = 'total' + "=";
	var posstr=document.cookie.indexOf (offset);
	if (posstr==-1) 	return "";
	var endstr = document.cookie.indexOf(";",posstr);
	if(endstr==-1) endstr=document.cookie.length;
	var cookieamount = unescape(document.cookie.substring(posstr+offset.length, endstr));
	if (cookieamount == '') cookieamount = '0.00|0.00|£00.00';
	var arr = cookieamount.split('|');
	var amount = arr[2];
	var agt=navigator.userAgent.toLowerCase();
	var plat=navigator.platform.toLowerCase();
	var IE   = (agt.indexOf('ie')!=-1);
	var ver = navigator.appVersion.toLowerCase();
	if(IE==true) {
		document.all.basket_text.value = amount;
	} else {
		document.forms['basket_status'].basket_text.value = amount;
	}
}


/**
	* getPercentageOfAmount returns the amount of percentage in an amount ($amount*$percentage)/100
	* @return float
	* @author pAd Tue Aug 09 18:24:50 BST 2005
	**/
	function getPercentageOfAmount(amount, percentage)	
	{
		var ret = 0.00;
		
		if (percentage>0.00 && amount>0.00)
		{
			ret = (amount*percentage)/100;
		}
		
		return ret;
	}