
item_Description=" ";
item_SKU="0";
item_Promo="0";
item_Price="23.23";
item_Unit="";
item_Taxable="3";
item_Shipping=""
item_Weight="";
item_Model="test3";
//VARIABLES FOR GLOBAL USE

no_of_order_pages = 15; //the number of possible product pages selected for ordering  
//====== Cookie functions =================================
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return 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;
}


//-------- Array function compatible with NS 2.0x, 3.0x and MSIE
function makeArray(n) 
{
   this.length = n;
   for (var i = 1; i <= n; i++)
   { 
     this[i] = 0;
   }
   return this;
}
function addtoCookieArray(cookieName, info)
{
    var tmpString=GetCookie(cookieName);
    if(GetCookie(cookieName) !=null)
    {
      tmpString = GetCookie(cookieName) + info + ",";
      //append to the current cookie values
      document.cookie = cookieName + "=" + tmpString;
    }
    else
    {
      tmpString = info + ",";
      document.cookie = cookieName + "=" + tmpString;
// alert("cookieNo:"+cookieName + "=" + tmpString);
    }
}
/* this defines an array for holding the user configuration
cookie contents when parsed out. Increase the count if you need to store more
but do not forget that the limitation is 4096 bytes */
// this parses the info stored in the config cookie into the array
function parseIt(cookieName, array) 
{
 config=GetCookie(cookieName);
 config+="";           // make it a string if it was not before
 var y = 1;
while(config.indexOf(",") >= 0) 
 {
   var pos = config.indexOf(",");
   if (pos==0)
     array[y]="";
   else
     array[y]=unescape(config.substring(0,pos));
   y++;
   config=config.substring(pos+1,config.length);
 }
 return y-1;
}
// return -1 if total # of elements in array exceed max limit
// return 0 if element is not found in the array
// return array index if element is found in the array
function posInArray(cookieName, element)
{
 var tmp_array = new makeArray(no_of_order_pages);
 total_count=parseIt(cookieName, tmp_array);

 if (total_count >= no_of_order_pages)
   return -1;

 for (i=1; i<=total_count; i++)
 {
  if (tmp_array[i]==element)
   return i;
 }
 return 0;
}
// This modifies the value of the n-th element in the array stored in cookie.
// For integer arrays, it will perform addition to existing value.
// For string arrays, it will perform concatenation.
function addValueInArray(cookieName, index, element)
{
 var tmp_array = new makeArray(no_of_order_pages);
 total_count=parseIt(cookieName, tmp_array);
 tmp_array[index] = eval(tmp_array[index]) + eval(element);
 tmp_array[index] = RoundQty( tmp_array[index] );
 if (tmp_array[index] > 9999.99) return 0;
 // remove existing cookie
 document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
 // convert from array to cookie
 for (i=1; i<=total_count; i++)
     addtoCookieArray(cookieName, tmp_array[i]);
 return tmp_array[index];
}
// check if input is an integer and it is greater than 0
function isInt(elm)
{
    var elmstr = "" + elm;
    if (elmstr == "")
        return false;
    for (var i = 0; i < elmstr.length; i++)
    {
        if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9")
            { return false; }
    }
    return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function RoundQty(elm)
{
    var elmstr = "" + elm;
    if (elmstr == "")
        return 0;
    DotExist=0;
    DigitAfterDecimal=0;
    for (var i = 0; i < elmstr.length; i++)
    {
        if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") { 
            if ((elmstr.charAt(i) == ".")&&(DotExist == 0))
                DotExist = 1;
            else
                return 0; 
        }
        else if (DotExist == 1){
            if (DigitAfterDecimal < 2)
                DigitAfterDecimal = DigitAfterDecimal + 1 ;
            else {
                if (elmstr.charAt(i)>="5"){
     var sTmp100 = elmstr.substring(0, i-3) + elmstr.substring(i-2, i);
     nTmp = Number( sTmp100 ) ;
     nTmp = nTmp + 1;
           var sTmp = "" + nTmp;
     if (sTmp.length < 2)
   sTmp = sTmp.substring(0, sTmp.length - 2) + ".0" + sTmp.substring(sTmp.length - 2, sTmp.length );
     else
   sTmp = sTmp.substring(0, sTmp.length - 2) + "." + sTmp.substring(sTmp.length - 2, sTmp.length );
                   return sTmp ;
                }
                else               
                   return Number( elmstr.substring(0, i) );
            }
        }       
    }
    return elm;
}
// check for valid quantity and prompt user if there is an error
// if valid is okay, update the hidden variable used by the basket buttons.

