//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design.  You must keep this comment unchanged in  ||
// your code.  For more information contact FreeCart@NopDesign.com.    ||
//                                                                     ||
// JavaScript Shop Module, V.4.4.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Global Options                                ||
//                      ----------------                               ||
// Shopping Cart Options, you can modify these options to change the   ||
// the way the cart functions.                                         ||
//                                                                     ||
// Language Packs                                                      ||
// ==============                                                      ||
// You may include any language pack before nopcart.js in your HTML    ||
// pages to change the language.  Simply include a language pack with  ||
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.          ||
//  For example: <SCRIPT SRC="language-en.js"></SCRIPT>                ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * DisplayShippingColumn: true/false, controls whether the managecart||
//   and checkout pages display shipping cost column.                  ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping cost total row.               ||
// * DisplayTaxRow: true/false, controls whether the managecart        ||
//   and checkout pages display tax cost total row.                    ||
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable when TaxByRegion is set to true.            ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.  If TaxByRegion is set to false, this ||
//   has no effect. Example: 'Arizona Residents'                       ||
// * NonTaxablePrompt: string, same as above, but the choice for non-  ||
//   taxable people.  Example: 'Other States'                          ||
// * MinimumOrder: number, the minium dollar amount that must be       ||
//   purchased before a user is allowed to checkout.  Set to 0.00      ||
//   to disable.                                                       ||
// * MinimumOrderPrompt: string, Message to prompt users with when     ||
//   they have not met the minimum order amount.                       ||
// * MaxLightboxSize: number, the maximum number of images that can    ||
//   added to the lightbox.                                            ||
// * ReduceThumbnail: number, the divisor of the width and height of   ||
//   thumbnail image.                                                  ||
// * DirectoryRoot: path to root directory of online or offline use.    ||
//                                                                     ||
// Payment Processor Options:                                          ||
// ==========================                                          ||
// * PaymentProcessor: string, the two digit payment processor code    ||
//   for support payment processor gateways.  Setting this field to    ||
//   anything other than an empty string will override your OutputItem ||
//   settings -- so please be careful when receiving any form data.    ||
//   Support payment processor gateways are:                           ||
//    * Authorize.net (an)                                             ||
//    * Worldpay      (wp)                                             ||
//    * LinkPoint     (lp)                                             ||
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//Options for Everyone:
MonetarySymbol        = '$';
DisplayNotice         = true;
DisplayShippingColumn = false;
DisplayShippingRow    = false;
DisplayTaxRow         = false;
TaxRate               = 0.07;
TaxByRegion           = false;
TaxPrompt             = 'For tax purposes, please select if you are an Arizona resident before continuing';
TaxablePrompt         = 'Arizona Residents';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 0.00;
MinimumOrderPrompt    = 'Your order is below our minimum order, please order more before checking out.';
MaxLightboxSize       = 25;
MaxPurchase			  = 10000; // US dollars, remember to change the MaxPurchase in the ashop.config file
ReduceThumbnail       = 1.6;
DirectoryRootOffline  ='file:///E|/Websites/EricFrisbee/';
DirectoryRootOnline   ='/'; 

//Payment Processor Options:
PaymentProcessor      = '';

//Options for Programmers:
OutputItemId          = 'ID_';
OutputItemQuantity    = 'QUANTITY_';
OutputItemPrice       = 'PRICE_';
OutputItemName        = 'NAME_';
OutputItemShipping    = 'SHIPPING_';
OutputItemAddtlInfo   = 'ADDTLINFO_';
OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'SHIPPING';
OutputOrderTax        = 'TAX';
OutputOrderTotal      = 'TOTAL';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = false;


//=====================================================================||
//---------------------------------------------------------------------||
//    YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE        ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
//                      Language Strings                               ||
//                     ------------------                              ||
// These strings will not be used unless you have not included a       ||
// language pack already.  You should NOT modify these, but instead    ||
// modify the strings in language-**.js where ** is the language pack  ||
// you are using.                                                      ||
//---------------------------------------------------------------------||

   strMaxPurchase = "I'm sorry, you have reached our maximum purchase amount.";
   strSorry  = "I'm sorry, your lightbox is full.";
   strAdded  = " has been added to your lightbox.\n\nPlease click the Lightbox link to review all of your selections.";
   strRemove = "Click 'Ok' to remove this image from your lightbox.";
   strILabel = "Lightbox for Photo Licensing";
   strDLabel = "Title";
   strQLabel = "ID";
   strPLabel = "Price";
   strSLabel = "Shipping";
   strRLabel = "";
   strRButton= "Remove";
   strBuyButton   = "Buy Now";
   strPriceButton = "Find Price";
   strSUB    = "SUBTOTAL";
   strSHIP   = "SHIPPING";
   strTAX    = "TAX";
   strTOT    = "TOTAL";
   strErrQty = "Invalid Quantity.";
   strNewQty = 'Please enter new quantity:';
   bLanguageDefined = true;

//---------------------------------------------------------------------||
// FUNCTION:    LightboxHilight                                        ||
// PARAMETERS:  refID                                                  ||
// RETURNS:     Nothing or writes link to document                     ||
// PURPOSE:     If image is in lightbox, use colored icon.             ||
//---------------------------------------------------------------------||
function LightboxHilight(refID, alpha) {
   var iNumberOrdered = 0;     //Number of products ordered
   var strOutput      = "";    //String to be written to page
   var inLightbox     = false; //Flag when searching cookie

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
   
   if ( iNumberOrdered > 0 ) {
      Lb = GetCookie("Lightbox");
      LbArray = Lb.split(":::");
      for ( i = 0; i < iNumberOrdered; i++ ) {
         OrderArray = LbArray[i].split("|");                                                       
         if (OrderArray[0] == refID)    // Image ID Number found in cookie
            inLightbox = true;
      }
   }
 
   refID = refID + alpha;

   if ( inLightbox ) 
      document.images[refID].src = "/lboxg.gif" ;   
   else 
      document.images[refID].src = "/lbox.gif" ;

}

//---------------------------------------------------------------------||
// FUNCTION:    LightboxStatus                                         ||
// PARAMETERS:  Null or mode                                           ||
// RETURNS:     Nothing or writes link to document                     ||
// PURPOSE:     If lightbox has something in it, then write link       ||
//---------------------------------------------------------------------||
function LightboxStatus(mode) {
   var iNumberOrdered = 0;    //Number of products ordered
   var strOutput      = "";   //String to be written to page
   var tmp  =location.href;   //url of current page

   if(tmp.indexOf('file:')>-1||tmp.charAt(1)==':') 
      path=DirectoryRootOffline; 
   else 
      path=DirectoryRootOnline;

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
   
   if ( iNumberOrdered > 0) {
      var thisLocation = document.location.href;
      if ( mode == 22 )  {
         strOutput = " | <A HREF=\"" + path + "lightbox.php?rtrn=" + thisLocation + "\" ALT=\"View Lightbox\">View Lightbox</A>";
         return strOutput;
      }
      else {
         strOutput = "<A HREF=\"" + path + "lightbox.php?rtrn=" + thisLocation + "\" ALT=\"View Lightbox\">[ View Lightbox ]</A>";
         document.write(strOutput);
         return;
      }
   }

   if (mode == 22)
      return strOutput;
   else
      document.write(strOutput);
   
}

//---------------------------------------------------------------------||
// FUNCTION:    LightboxVar                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     returns the lightbox link if any string                ||
// PURPOSE:     If lightbox has something in it, then write link       ||
//---------------------------------------------------------------------||
function LightboxVar( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var strOutput      = "";   //String to be written to page
   var tmp  =location.href;   //url of current page

   if(tmp.indexOf('file:')>-1||tmp.charAt(1)==':') 
      path=DirectoryRootOffline; 
   else 
      path=DirectoryRootOnline;

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
   
   if ( iNumberOrdered > 0)  {
      var thisLocation = document.location.href;
      strOutput = "<A HREF=\"" + path + "lightbox.php?rtrn=" + thisLocation + "\" ALT=\"View Lightbox\">[ View Lightbox ]</A>";
   }

   return strOutput;
}

//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageCart( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal       = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var iLic           = 0;    //Number of images with valid licenses and associated price
   var priceStr       = "";   //Concat price string for multiple purchase
   var itemStr        = "";   //Concat item string for ashop multiple purchase
   var priceTotal	  = 0;

   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null ) {
      iNumberOrdered = 0;
   }

   if ( bDisplay )
      strOutput = "<TABLE border=0 CELLSPACING=\"0\" CELLPADDING=\"3\">" +
                  "<TR><TD CLASS=\"nopcart\" >" +
                  "<TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" +
                  "<TR>" +
                  "<TD COLSPAN=\"5\" CLASS=\"nopheader\"><B>"+strILabel+"</B></TD></TR>" ;

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR><TD COLSPAN=6 CLASS=\"nopentry\"><CENTER><BR><B>Your lightbox is empty.</B><P></P>";
      strOutput += "Please click the add to lightbox icon &nbsp <IMG SRC=\"lbox.gif\"> next to the image of interest. <BR></CENTER></TD></TR>";
      strOutput += "<TR><TD COLSPAN=\"4\" CLASS=\"nopcart\" HEIGHT=\"3\"></TD></TR>";
   }
   else if ( iNumberOrdered > 0 ) {
      //Lb = GetCookie("Lightbox");
      //LbArray = Lb.split(":::");
  
   for ( i = 0; i < iNumberOrdered; i++ ) {
      fields = LbArray[i].split("|");
      
      // fields[0] Image ID Number                       
      // fields[1] Thumbnail filename with extension     
      // fields[2] Thumbnail Directory                   
      // fields[3] Thumbnail Width                       
      // fields[4] Thumbnail Height                      
      // fields[5] Image Description                     
      // fields[6] URL to large image link     
	  // fields[7] Gallery ID number          

      if ( bDisplay ) {
    
         LicMaster = GetCookie("License");
         LicNum    = GetCookie("iNumberLicense");
         if (LicNum == null)
            LicNum = 0;

         if (LicMaster != null && LicNum != 0) {
            LicSub = LicMaster.split(":::");
            for ( j = 0; j < LicNum; j++ ) {
               arr = LicSub[j].split("|");
               lic = new Array;
               if ( arr[0] == fields[0] ) {
                  lic = LicSub[j].split("|");
                  break;
               }
            }
         }
         else
            lic = new Array;

               // lic[0]  =  image id
               // lic[1]  =  licensed price
               // lic[2]  =  license start month
               // lic[3]  =  license start day
               // lic[4]  =  license start year
               // lic[5]  =  license type (nonexclusive)
               // lic[6]  =  index start month
               // lic[7]  =  index start day
               // lic[8]  =  index start year
               // lic[9]  =  usage category index
               // lic[10] =  usage details (subcat) index
               // lic[11] =  usage column index
               // lic[12] =  usage row index
               // lic[13] =  industry index
               // lic[14] =  country count
               // lic[15] =  country index(s)
               // lic[16] =  base price before multipliers
               // lic[17] =  lightbox index id
               
         strOutput += "<TR><TD CLASS=\"nopentry\" ALIGN=\"center\">";
			strOutput += "<a href=\"./" + fields[6] + "\"><img src=\"./" + fields[2] + "/" + fields[1] + "\" width=\"" + (fields[3]/ReduceThumbnail) + "\" height=\"" + (fields[4]/ReduceThumbnail) + "\" class=\"fotgal\" border=\"1\"></a> </TD>";
         strOutput += "<TD CLASS=\"nopentry\"><a href=\"./" + fields[6] + "\">" + fields[0] + "<br>" + fields[5] + "</a>";
         if ( (lic[1]!="") && (lic[1]>0) ) {  
            strOutput += "<br>License Fee: <font color=darkgreen>$" + lic[1] + "</font><br>";
            strOutput += "<div style=\"font-size: 10px; margin-top: 20px;\"> ";
            strOutput += "<a href=\"#\" onclick=\"rpwindow('http://www.ericfrisbee.com/form/rpmail.php?oneitem=" + fields[0] + "')\">Need Exclusive Rights?</a></div> </TD>";
            iLic++;
            priceStr += lic[1] + 'a';
            itemStr  += fields[0] + 'a';
			priceTotal = priceTotal + parseInt(lic[1]);
         }
         else
            strOutput += "<br>License Fee: <font color=darkgreen>$--</font></TD>";

         strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER>";

         if ( (lic[1]!="") && (lic[1]>0) ) {
            strOutput += "<FORM ACTION=\"\" NAME=\"form\" METHOD=\"GET\"><input type=button value=\"Change License\" onClick=\"gowindow('PriceCalc/tabs.php/"+fields[0]+"/"+fields[7]+"',"+i+")\" class=\"nopbutton\"></FORM></TD>";
         }
         else
            strOutput += "<FORM ACTION=\"\" NAME=\"form\" METHOD=\"GET\"><input type=button value=\" "+strPriceButton+" \" onClick=\"gowindow('PriceCalc/tabs.php/"+fields[0]+"/"+fields[7]+"',"+i+")\" class=\"nopbutton\"></FORM></TD>";
         
 
         strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER>";

         // -- Checkout for single item purchase
         strOutput += "<form name=\"frm" + fields[0] + "\" method=\"post\" action=\"http://www.ericfrisbee.com/license.php\" onSubmit=\"return PriceCheck(this);\"> ";
         strOutput += "<input type=\"hidden\" name=\"basket\" value=\"" +fields[0]+ "a\"> ";
		 strOutput += "<input type=\"hidden\" name=\"pricepass\" value=\"" +lic[1]+ "\"> ";
		 strOutput += "<input type=\"hidden\" name=\"priceTotal\" value=\"" +priceTotal+ "\"> ";
         
         strOutput += "<input type=submit value=\" "+strBuyButton+" \" class=\"nopbutton\"></FORM></TD>";
         strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER>";
         strOutput += "<FORM ACTION=\"\" NAME=\"form\" METHOD=\"GET\"><input type=image src=\"trashcan.gif\" alt=\"Remove\" onClick=\"RemoveFromCart("+i+","+fields[0]+")\"></FORM></TD></TR>";
          
      }

      if (bDisplay && (i<iNumberOrdered)) {
         strOutput += "<TR><TD COLSPAN=\"4\" CLASS=\"noplinefill\" HEIGHT=\"3\"></TD></TR>";
      }

      if ( AppendItemNumToOutput ) 
         strFooter = i;
      else 
         strFooter = "";
   }
   }

   if ( bDisplay ) {
      strOutput += "</TABLE>";      
      strOutput += "</TD></TR></TABLE>";
      if (iNumberOrdered > 0) {
         strOutput += "<p></p><center><img alt=\"\" src=\"p.gif\" height=\"5\">";
         strOutput += "<FORM name=\"frmBuyAll" + fields[0] + "\" method=\"post\" action=\"http://www.ericfrisbee.com/license.php\" onSubmit=\"return CheckMulitplePurchase("+iLic+","+iNumberOrdered+","+priceTotal+");\"> ";
         strOutput += "<input type=\"hidden\" name=\"basket\" value=\"" +itemStr+ "\"> ";
         strOutput += "<input type=\"hidden\" name=\"pricepass\" value=\"" +priceStr+ "\"> ";
		 strOutput += "<input type=\"hidden\" name=\"priceTotal\" value=\"" +priceTotal+ "\"> ";
         strOutput += "<input type=submit value=\"Purchase All Lightbox Images\" class=\"nopbutton\"></FORM> </center>";     
      }
   }

   //alert (strOutput);
   document.write(strOutput);
   document.close();
}


//---------------------------------------------------------------------||
// FUNCTION:    CheckMulitplePurchase                                  ||
// PARAMETERS:  license count, and number of items in lightbox         ||
// RETURNS:     bool, and possible alert                               ||
// PURPOSE:     To purchase all items from lightbox                    ||
//---------------------------------------------------------------------||
function CheckMulitplePurchase(LicCnt, BoxCnt, priceTotal) {
   //if (priceTotal > MaxPurchase) {
      //alert (strMaxPurchase);
	  //return false;
   //}	

   if (LicCnt < 1) {
      alert ("To purchase an image, please use the price calculator.    \nThe price calculator allows you to find the license and price.  \nClick the \"Find Price\" button to start the price calculator." );
      return false;
   }
   if (LicCnt != BoxCnt) {
      if ( confirm ("Some images in your lightbox do not have an established license and price. \n\nWould you like to purchase only the image(s) from your lightbox \nwith an established license and price?") )
         return true;
      return false;
   }
   return true;
}

//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else
      strID_NUM    = thisForm.ID_NUM.value;

   if ( thisForm.GALLERY_DB == null )
      strGALLERY_DB = "";
   else
      strGALLERY_DB    = thisForm.GALLERY_DB.value;

   //Is this product already in the cart?  If so, increment quantity instead of adding another.

   Lb = GetCookie("Lightbox");
   if (Lb != null) {
      dbUpdatedOrder = Lb;
      LbArray = Lb.split(":::");
   }
   else
      dbUpdatedOrder = ""; 

   for ( i = 0; i < iNumberOrdered; i++ ) {
      fields = LbArray[i].split("|");

      // fields[0] Image ID Number                       
      // fields[1] Gallery Database ID (catnum)    

      if ( fields[0] == strID_NUM  &&  fields[1] == strGALLERY_DB  ) {
         bAlreadyInCart = true;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > MaxLightboxSize )
         alert( strSorry );
      else {
         dbUpdatedOrder = dbUpdatedOrder +
                          strID_NUM      + "|" +
                          strGALLERY_DB  + ":::" ;

         SetCookie("Lightbox", dbUpdatedOrder, null, "/");    
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
      }
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
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                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
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";
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||

function RemoveFromCart(RemOrder, imageID) {
   if ( confirm( strRemove ) ) {
      NumberOrdered = GetCookie("NumberOrdered");
      Lb = GetCookie("Lightbox");
      LbArray = Lb.split(":::");
      NewLb = "";
      for ( i=0; i < NumberOrdered; i++ ) {
         if ( RemOrder != i ) {
            NewLb = NewLb + LbArray[i] + ":::";
         }
      }
      SetCookie ("Lightbox", NewLb, null, "/");
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");

      LicNum    = GetCookie("iNumberLicense")
      if ( LicNum!=null && LicNum!=0) {
         LicMaster = GetCookie("License");
         NewLic = "";
         LicSub = LicMaster.split(":::");;
         itemp = LicNum;
         for ( i = 0; i < LicNum; i++ ) {
            LicArr = LicSub[i].split("|");
            if ( LicArr[0] == imageID )
               itemp = itemp - 1; 
            else
               NewLic = NewLic + LicSub[i] + ":::"; 
         }
         LicNum = itemp;
         DeleteCookie("License", "/");               
         SetCookie ("License", NewLic, null, "/");
         DeleteCookie("iNumberLicense", "/");
         SetCookie ("iNumberLicense", LicNum, null, "/");
      }
      location.href=location.href;
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    GetFromCart                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//              **DEPRECATED FUNCTION, USE ManageCart or Checkout**    ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
   ManageCart( );
}


//---------------------------------------------------------------------||
// FUNCTION:    RadioChecked                                           ||
// PARAMETERS:  Radio button to check                                  ||
// RETURNS:     True if a radio has been checked                       ||
// PURPOSE:     Form fillin validation                                 ||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }    
   return bChecked;
} 


//---------------------------------------------------------------------||
// FUNCTION:    QueryString                                            ||
// PARAMETERS:  Key to read                                            ||
// RETURNS:     value of key                                           ||
// PURPOSE:     Read data passed in via GET mode                       ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
   var value = null;
   for (var i=0;i<QueryString.keys.length;i++) {
      if (QueryString.keys[i]==key) {
         value = QueryString.values[i];
         break;
      }
   }
   return value;
} 

//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
   var query = window.location.search.substring(1);
   var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
      var pos = pairs[i].indexOf('=');
      if (pos >= 0) {
         var argname = pairs[i].substring(0,pos);
         var value = pairs[i].substring(pos+1);
         QueryString.keys[QueryString.keys.length] = argname;
         QueryString.values[QueryString.values.length] = value;
      }
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {
   if ( TaxByRegion ) {
      if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
         alert( TaxPrompt );
         return false;
      }
   }

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalCost < MinimumOrder ) {
         alert( MinimumOrderPrompt );
         return false;
      }
   }

   return true;
}


//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||



