//->
//-> phpCart Shopping Cart System Version 1.0 (C) Copyright 2000 WEBMASTERS.COM. All rights reserved.
//-> For licensing information, please contact WEBMASTERS.COM at 1-877-565-5555 or visit our website.
//-> This program code and other components of this software application are registered with the U.S. Copyright Office and can not be duplicated, modified, or used without the express written permission of WEBMASTERS.COM.
//-> Removal of this copyright notice constitutes a violation of your license agreement.
//->

if (top==self) top.location="/";
function getCookieVal(offset) {
   var endstr=document.cookie.indexOf(";", offset);
   if (endstr==-1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset,endstr)); }

function GetCookie(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 SetCookie(name,value) {
   var argv=SetCookie.arguments;
   var argc=SetCookie.arguments.length;
   var expires=(argc>2) ? argv[2]:null;
   var path=(argc>3) ? argv[3]:null;
   var domain=(argc>4) ? argv[4]:null;
   var secure=(argc>5) ? argv[5]:false;
   document.cookie=name+"="+escape(value)+((expires==null) ? "" : ("; expires="+expires.toGMTString()))+((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))+((secure==true) ? "; secure" : ""); }

function DeleteCookie(name,path,domain) {
  if (GetCookie(name)) {
    document.cookie=name+"="+((path) ? "; path="+path:"")+((domain) ? "; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT"; }}

var load;
var Num=GetCookie("number");
var Item_List=new String(GetCookie("items"));
var I=Item_List.split("!!");
var Price_List=new String(GetCookie("prices"));
var P=Price_List.split("!!");
var Q_List=new String(GetCookie("quantity"));
var Q=Q_List.split("!!");
var S_List=new String(GetCookie("shipping"));
var S=S_List.split("!!");
var Url_List=new String(GetCookie("urls"));
var U=Url_List.split("!!");
var expdate=new Date();
expdate.setTime(expdate.getTime()+(24*60*60*1000));

function Decimal(n) {
   ns=new String(n);
   nsi=ns.indexOf('.');
   if (nsi!=-1) {
      nsil=nsi+3;
      l=ns.charAt(nsil);
      ln=new Number(l);
      if (ln>=5) n=n+.001;
      nr=new String(n);
      n=nr.substring(0,nsil);
      if (n.length<nsil) n+="0"; }
   else {
      n=ns+".00"; }
   return n; }

function getItems() {
   document.write('<select name="Items" size="1" ID="f">');
   if ((Num==null) || (Num<0)) {
      document.write('<option value="Null">Your Shopping Cart Is Empty</option>'); }
   else {
      var IL=new Array();
      for (var i=0; i<=Num; i++) {
         if ((I[i]!="undefined") && (I[i]!="")) {
         P[i]=new Number(P[i])*new Number(Q[i]);
         P[i]=Decimal(P[i]);
         Q[i]=Decimal(Q[i]);
         if (I[i].length>40) {
            IL[i]=I[i].substring(0,32)+"..."; }
         else {
            IL[i]=I[i]; }
         document.write('<option value='+U[i]+'>'+IL[i]+' - '+Q[i]+' - $'+P[i]+'</option>'); }}}
   document.write('<option value="Null">_______________________________________________</option></span></select>'); }

function getInput() {
   if ((Num!=null) && (Num>=0)) {
      for (var i=0; i<=Num; i++) {
         var ST=new Array(Num)
         S[i]=new Number(S[i])*new Number(Q[i]);
         S[i]=Decimal(S[i]);
         ST[i]=new Number(P[i])+new Number(S[i]);
         ST[i]=Decimal(ST[i]);
         document.write('<input type="hidden" name="I[]" value="'+I[i]+'">\n');
         document.write('<input type="hidden" name="Q[]" value="'+Q[i]+'">\n');
         document.write('<input type="hidden" name="P[]" value="'+P[i]+'">\n');
         document.write('<input type="hidden" name="S[]" value="'+S[i]+'">\n');
         document.write('<input type="hidden" name="ST[]" value="'+ST[i]+'">\n'); }
      var SHT=0;
      for (var i=0; i<=Num; i++) {
         SHT=SHT+new Number(S[i]); }
      SHT=Decimal(SHT);
      document.write('<input type="hidden" name="SHT" value="'+SHT+'">');
      var SHST=0;
      for (var i=0; i<=Num; i++) {
         if (new Number(S[i])==0) SHST=SHST+new Number(P[i]); }
      SHST=Decimal(SHST);
      document.write('<input type="hidden" name="SHST" value="'+SHST+'">'); }}

function Load() {
   if ((Num==null) || (Num<0)) {
      document.phpCart.Total.value="0.00"; }
   else {
      var T=new Array(Num)
      for (var i=0; i<=Num; i++) {
         T[i]=new Number(P[i])+new Number(S[i]); }
      var Total=0;
      for (var i=0; i<=Num; i++) {
         Total+=T[i]; }
      Total=Decimal(Total);
      document.phpCart.Total.value=Total; }
   I1on=new Image();
   I1on.src="images/checkout1.gif";
   I1off=new Image();
   I1off.src="images/checkout.gif";
   I2on=new Image();
   I2on.src="images/new1.gif";
   I2off=new Image();
   I2off.src="images/new.gif";
   I3on=new Image();
   I3on.src="images/view1.gif";
   I3off=new Image();
   I3off.src="images/view.gif";
   I4on=new Image();
   I4on.src="images/remove1.gif";
   I4off=new Image();
   I4off.src="images/remove.gif";
   load=1; }

function turnOn(button) {
   if (load==1) {
      document[button].src=eval(button+"on.src"); }}

function turnOff(button) {
   if (load==1) {
      document[button].src=eval(button+"off.src"); }}

function Remove() {
   P=Price_List.split("!!");
   Q=Q_List.split("!!");
   S=S_List.split("!!");
   var val=(document.phpCart.Items.options[document.phpCart.Items.selectedIndex].value);
   if (val=="Null") {
      alert("Sorry, your selection is invalid and cannot be removed!"); }
   else {
      var item=(document.phpCart.Items.options[document.phpCart.Items.selectedIndex].text);
      if (confirm("Are you sure you want to remove "+item+" from your shopping cart?")) {
         var ix=document.phpCart.Items.selectedIndex;
         var ni=Num-1;
         for (var j=ix; j<=ni; j++) {
            I[j]=I[j+1]; }
         I[ni+1]="";
         var ei=I.join("!!");
         ri=/!!!!/
         var Items=ei.replace(ri,"!!");
         SetCookie("items",Items,expdate);
         for (var j=ix; j<=ni; j++) {
            P[j]=P[j+1]; }
         P[ni+1]="";
         var ep=P.join("!!");
         rp=/!!!!/
         var Prices=ep.replace(rp,"!!");
         SetCookie("prices",Prices,expdate);
         for (var j=ix; j<=ni; j++) {
            Q[j]=Q[j+1]; }
         Q[ni+1]="";
         var eq=Q.join("!!");
         rq=/!!!!/
         var Quantity=eq.replace(rq,"!!");
         SetCookie("quantity",Quantity,expdate);
         for (var j=ix; j<=ni; j++) {
            S[j]=S[j+1]; }
         S[ni+1]="";
         var es=S.join("!!");
         rs=/!!!!/
         var Shipping=es.replace(ri,"!!");
         SetCookie("shipping",Shipping,expdate);
         for (var j=ix; j<=ni; j++) {
            U[j]=U[j+1]; }
         U[ni+1]="";
         var eu=U.join("!!");
         ru=/!!!!/
         var Urls=eu.replace(ru,"!!");
         SetCookie("urls",Urls,expdate);
         var newNum=--Num;
         SetCookie("number",newNum,expdate);
         window.location="phpcart.html"; }}}

function View() {
   var loc=(document.phpCart.Items.options[document.phpCart.Items.selectedIndex].value);
   if (loc=="Null") {
      alert("Sorry, your selection is invalid and cannot be viewed!"); }
   else {
      parent.display.location=loc; }}

function Empty() {
   if ((Num==null) || (Num<0)) {
      alert("Sorry, your shopping cart is already empty!"); }
   else {
      if(confirm("Are you sure you want to delete all items from your shopping cart?")) {
         DeleteCookie("number");
         DeleteCookie("items");
         DeleteCookie("prices");
         DeleteCookie("quantity");
         DeleteCookie("shipping");
         DeleteCookie("urls");
         window.location="phpcart.html"; }}}

function Add(id,item,price,ship,loc) {
   if (parent.display.document.forms[1]) {
      var q=parent.display.document.forms[1][id].value; }
   else {
      var q=parent.display.document.forms[0][id].value; }
   qCheck=parseInt(q, 10);
   if ((qCheck<=0) || (isNaN(qCheck)) || (q=="")) q=1;
   Num=GetCookie("number");
   var Items=GetCookie("items");
   var Prices=GetCookie("prices");
   var Quantity=GetCookie("quantity");
   var Shipping=GetCookie("shipping");
   var Urls=GetCookie("urls");
   if (Num==null) {
      SetCookie("number",0,expdate);
      SetCookie("items",item+"!!",expdate);
      SetCookie("prices",price+"!!",expdate);
      SetCookie("quantity",q+"!!",expdate);
      SetCookie("shipping",ship+"!!",expdate);
      SetCookie("urls",loc+"#"+id+"!!",expdate); }
   else {
	var ix="f";
	I=Items.split("!!");
      for (var j=0; j<=Num; j++) {
	   if (I[j]==item) var ix=j; }
	if (ix!="f") {
	   Q=Quantity.split("!!");
	   Q[ix]=new Number(Q[ix])+new Number(q);
         var eq=Q.join("!!");
         rq=/!!!!/
         var Quantity=eq.replace(rq,"!!");
         SetCookie("quantity",Quantity,expdate); }
	else {
	   var newN=++Num;
         SetCookie("number",newN,expdate);
         SetCookie("items",item+"!!"+Items,expdate);
         SetCookie("prices",price+"!!"+Prices,expdate);
         SetCookie("quantity",q+"!!"+Quantity,expdate);
         SetCookie("shipping",ship+"!!"+Shipping,expdate);
         SetCookie("urls",loc+"#"+id+"!!"+Urls,expdate); }}
  alert("Item "+item+" added!\n\nQuantity: "+q);
  window.location="phpcart.html"; }

function Check_Out() {
   if ((Num==null) || (Num<0)) {
      alert("Sorry, you do not have any items in your shopping cart!"); }
   else {
      document.phpCart.action.value="Order";
      document.phpCart.submit(); }}

//© This code is a copyright of WEBMASTERS.COM. All rights reserved. Unauthorized use is strictly prohibited.