
function checkChangeSP()
{
	if(document.form1.companySP.value != document.form1.old_sp_id.value && document.form1.count_order.value > 0)
	{
		if (!confirm("Shopping cart is not empty.\nIf you switch company you will loose your order.\nDo you want to proceed?"))	
			return false;
		else 
			return true;
	}
}

function checkName(f, name) {
   if (f != null && (f.name == name)) {
      if (f.value < '0' || f.value.length < 1 || f.value.length > 100000) {
          alert(' A Valid value for "' + name + '" is required!\n');
          f.focus();
          f.select();
          return false;
      }
   }
   return true;
}

function checkEmail(f, name) {
    if (f != null && (f.name == name)) {
        var theStr = new String(f.value);
        var index = theStr.indexOf("@");
        if (index > 0) {
            var pindex = theStr.indexOf(".", index);
            if ((pindex > index+1) && (theStr.length > pindex+1))
                return true;
        }
        alert(' A Valid value for "' + name + '" is required!\n');
        f.focus();
        f.select();
        return false;
    }
    return true;
}
function checkProofForm(form) {
   for (i = 0; i < form.elements.length; i++) {
       var f = form.elements[i]; 
       if (!checkName(f, "companyName")) return false;
       if (!checkName(f, "companyAddress")) return false;
	   if (!checkName(f, "city")) return false;
	   if (!checkName(f, "state")) return false;
	   if (!checkName(f, "zipCode")) return false;
	   if (!checkName(f, "name")) return false;
       if (!checkName(f, "email") || !checkEmail(f, "email") ) return false;
       if (!checkName(f, "fax")) return false;
	   if (!checkName(f, "login_password")) return false;
	   if (!checkName(f, "company_ref1")) return false;
	   if (!checkName(f, "company_ref2")) return false;
	   if (!checkName(f, "company_ref3")) return false;
	   if (!checkName(f, "bank_ref")) return false;
   }
   return true;
}

function openNewWindow(URLtoOpen, windowName, windowFeatures)
{
	newWindow = window.open(URLtoOpen, windowName, windowFeatures);
}
function popUpW2(part)
{
	var intScrWidth = (window.screen.width/3) - (20 + 10);
	var intScrHeight = (window.screen.height/3) - (5 + 10);
	var win2 = window.open(part,"winname","width=750,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,left=" + intScrWidth + ",top=" + intScrHeight + ",screenX=" + intScrWidth +",screenY=" + intScrHeight);
	//bring the newly opened window into focus(front of the screen)
	win2.focus();
}
function newImage(arg)
{
	if(document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImages()
{
	for(var i=0; i<changeImages.arguments.length; i+=2)
	{
		tmp1 = newImage(changeImages.arguments[i+1]);
		document.images[changeImages.arguments[i]].src = changeImages.arguments[i+1];
	}
}

var preloadFlag = false;
function preloadImages()
{

}


function Get_Cookie(name)
{ 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 

function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 

function isNum(str) {
 for (var i = 0; i < str.length; i++) {
  var ch = str.substring(i, i + 1)
 if (ch < "0" || "9" < ch) {
   alert("You must enter a whole number in the Quantity field.")
   return false
  }
 }
 return true
}

var itemNumber=null;
var oldNumber=null;

function alterError(value)
{
newPounds = parseInt(value);
newPence = parseInt((value+.0008 - parseInt(value))* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
	newString = newPounds + '.' + newPence;
 	return (newString);
}

var fulllist;

function showItems2()
{
	var cookieList = document.cookie.split("; ");
	fulllist = ".";
	for (var i = 0; i < cookieList.length; i++)
	{
		var cookname2 = cookieList[i].split("=");
		if(unescape(cookname2[0])=="TheBasket"){ fulllist = unescape(cookname2[1]);}
	}
	totprice = 0;
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++)
	{
		if (fulllist.substring(i,i+1) == '['){ itemstart = i+1;}
		else if (fulllist.substring(i,i+1) == ']')
		{
			itemend = i;
			thequantity = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;
			document.writeln('<tr><td><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+theitem+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+thequantity+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+theprice+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+alterError(itemtotal)+'</font></td></tr>');
		}
		else if (fulllist.substring(i,i+1) == ',')
		{
			theitem = fulllist.substring(itemstart, i);
			itemstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '#')
		{
			theprice = fulllist.substring(itemstart, i);
			itemstart = i+1;
		}
	}
	document.writeln('<tr><td colspan=3 align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black"><b>Sub-Total (sans shipping &amp; handling)</b></font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black"><b>'+alterError(totprice)+'</b></font></td></tr>');
}

function showItems()
{
	var cookieList = document.cookie.split("; ");
	fulllist = ".";
	for (var i = 0; i < cookieList.length; i++)
	{
		var cookname2 = cookieList[i].split("=");
		if(unescape(cookname2[0])=="TheBasket"){ fulllist = unescape(cookname2[1]);}
	}
	totprice = 0;
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++)
	{
		if (fulllist.substring(i,i+1) == '['){ itemstart = i+1;}
		else if (fulllist.substring(i,i+1) == ']')
		{
			itemend = i;
			thequantity = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;
			document.writeln('<tr><td><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+theitem+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+thequantity+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+theprice+'</font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black">'+alterError(itemtotal)+'</font></td>'+'<td><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black"><A CLASS="item" HREF="javascript:removeItem('+itemlist+')">Remove</a></font></td></tr>');
		}
		else if (fulllist.substring(i,i+1) == ',')
		{
			theitem = fulllist.substring(itemstart, i);
			itemstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '#')
		{
			theprice = fulllist.substring(itemstart, i);
			itemstart = i+1;
		}
	}
	document.writeln('<tr><td colspan=3 align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black"><b>Sub-Total (sans shipping &amp; handling)</b></font></td>'+'<td align=right><FONT FACE="MS Sans Serif,Geneva,Arial,Helvetica,Swiss" SIZE="2" COLOR="black"><b>'+alterError(totprice)+'</b></font></td><td></td></tr>');
}

function removeItem(itemno)
{
	newItemList = null;
	itemlist = 0;
	//alert(fulllist);
	for (var i = 0; i <= fulllist.length; i++)
	{
		if (fulllist.substring(i,i+1) == '[')
		{
			itemstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == ']')
		{
			itemend = i;
			theitem = fulllist.substring(itemstart, itemend);
			itemlist=itemlist+1;
			if (itemlist != itemno)
			{
				newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
			}
		}
	}
	//index = document.cookie.indexOf("TheBasket");
	//alert(newItemList);
	document.cookie="TheBasket="+newItemList+"; path=/;";
	document.location.href = document.location.href;
}

function clearBasket()
{
if (confirm('Are you sure you wish to clear your shopping basket?'))
	{
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.; path=/;";
		document.location = "/basket/1/";
	}
}

function showFee(){
	var Fee='0.00';
	var finalTotal = (parseInt(alterError(totprice))+parseInt(Fee));
	document.orderform.dispFee.value = Fee+'.00';
	document.orderform.dispTotal.value = finalTotal+'.00';
	return;
}

function shipFee(Fee){
if (Fee != 0)
	(finalTotal = (parseInt(alterError(totprice))+parseInt(Fee)));
	this.document.orderform.dispFee.value=Fee+'.00';
	this.document.orderform.dispTotal.value=finalTotal+'.00';
	return;
}

function MakeArray(n)
{
   this.length = n;
   for (var i = 1; i <= n; i++)
     { 
     this[i] = 0 
     }
   return this;
}

var orderFirstName="null"
var orderLastName="null"

function checkdata()
{
if (
   (this.document.orderform.FirstName.value.length != 0) &&
   (this.document.orderform.LastName.value.length != 0) &&
   (this.document.orderform.Address.value.length != 0) &&
   (this.document.orderform.Towncity.value.length != 0) &&
   (this.document.orderform.State.value.length != 0) &&
   (this.document.orderform.Zip.value.length != 0) &&
   (this.document.orderform.Country.value.length != 0) &&
   (this.document.orderform.Telephone.value.length != 0) &&
   (this.document.orderform.Email.value.length != 0)
   )
	{
    checkeMail()
	}
else 
   alert ("Required fields have not been filled in. Please go back to Step 3 enter the data.");
   return;
}

//Start of phony checkCC() for MSIE
function checkeMail()
{
	var inputString=document.orderform.Email.value;
	if (inputString.indexOf('@',0)==-1)
	{
		alert('Please enter a valid E-mail address in Step 3.');
		document.orderform.Email.focus();
		return;
	}
	this.document.orderform.submit();
}

//Start of checkFee()

function checkFee_1()
{
	if(document.orderform.dispFee.value==0 || document.orderform.dispTotal.value==0)
	{
		alert('You must select a shipping method in Step 2.');
		return false;
	}
  	return true;
}

function checkFee()
{
	if(document.orderform.dispFee.value != 0 && document.orderform.dispTotal.value!=0)
	{
	    checkdata();
	}
	else alert('You must select a shipping method in Step 2.');
  	return;
}