/* 
  ------------------------------------------------
  JETENGINE Image & Meta Data Script
  C0D3D by Gunnar Leffler
  http://www.leftech.com
  Get your site revvin like a 747 jet engine
  (c) 2008 Gunnar Leffler - If you're not me, 
  you can't use this.
  ------------------------------------------------
*/

//START GLOBAL VARIABLES
var theBigPictureURL ="";
var lastNavPicture =  "img/portraits.jpg";
var curpic = "";
var ndx =0;

var slides;



var imgs = new Array();
var cf_indexer = 0;

var t,t1,t2;

var slideShowSpeed = 5000;
var crossFadeDuration = 3;//in seconds
var Pic = new Array();


//END GLOBAL VARIABLES

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START SHOPPING CART CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

prodArray = new Array();

cartArray = new Array();

custInfo = new Array();

inputBlock = new Array();

function InitCart () //call this on each page
{

prodArray = new Array(
["Catagory 0","Product 1","Sub Product 2","Price 3","Description 4","Details Url 5","Sku 6","image 7"],
["Shampoo","Bucket O' Oats Oat Treatment","8oz","10","Demonstrates excellent antioxidant properties which help soothe hot spots and itchy conditions while adding protein and lipids to the coat. Dilute 7:1; Leave in coat 5 minutes.","NO DETAILS","NO SKU","product/Bucket O Oatsz.jpg"],
["Shampoo","Bucket O' Oats Oat Treatment","16oz","15"," ","NO DETAILS","NO SKU","product/Bucket O Oatsz.jpg"],
["Shampoo","Bucket O' Oats Oat Treatment","32oz","22"," ","NO DETAILS","NO SKU","product/Bucket O Oatsz.jpg"],
["Shampoo","Bucket O' Oats Oat Treatment","Gallon","45"," ","NO DETAILS","NO SKU","product/Bucket O Oatsz.jpg"],
["Shampoo","Cedar Shield with Aloe","8oz","10","Cedar, Eucalyptus and citronella essence aid in repelling insects in this high quality, gentle shampoo. Leaves coat shiny and lustrous and is safe and mild. Dilute 4:1","NO DETAILS","NO SKU","product/Cedar Shieldz.jpg"],
["Shampoo","Cedar Shield with Aloe","16oz","15"," ","NO DETAILS","NO SKU","product/Cedar Shieldz.jpg"],
["Shampoo","Cedar Shield with Aloe","32oz","22"," ","NO DETAILS","NO SKU","product/Cedar Shieldz.jpg"],
["Shampoo","Cedar Shield with Aloe","Gallon","45"," ","NO DETAILS","NO SKU","product/Cedar Shieldz.jpg"],
["Shampoo","Chiffon Silk","8oz","10","A luxurious shampoo containing silk protein and natural lipids. Adds shine and conditions coat. Excellent on any breed, especially long coated breeds, Dilute 10:1","NO DETAILS","NO SKU","product/Chiffon Silkz.jpg"],
["Shampoo","Chiffon Silk","16oz","15"," ","NO DETAILS","NO SKU","product/Chiffon Silkz.jpg"],
["Shampoo","Chiffon Silk","32oz","22"," ","NO DETAILS","NO SKU","product/Chiffon Silkz.jpg"],
["Shampoo","Chiffon Silk","Gallon","45"," ","NO DETAILS","NO SKU","product/Chiffon Silkz.jpg"],
["Shampoo","Coconut Breeze with Vitamin E","8oz","10","A high quality Vitamin E shampoo. Helps return luster to damaged coats and restores natural oils to skin and coat. Dilute 10:1","NO DETAILS","NO SKU","product/Coconut Breezez.jpg"],
["Shampoo","Coconut Breeze with Vitamin E","16oz","15"," ","NO DETAILS","NO SKU","product/Coconut Breezez.jpg"],
["Shampoo","Coconut Breeze with Vitamin E","32oz","22"," ","NO DETAILS","NO SKU","product/Coconut Breezez.jpg"],
["Shampoo","Coconut Breeze with Vitamin E","Gallon","45"," ","NO DETAILS","NO SKU","product/Coconut Breezez.jpg"],
["Shampoo","Crowning Glory with Aloe","8oz","10","A high quality, gentle shampoo, aloe-vitamin based. Reduces rinsing time, enhances any coat color and does not alter the coat’s natural texture. Promotes healthy skin. Dilute 12:1","NO DETAILS","NO SKU","product/Crowning Gloryz.jpg"],
["Shampoo","Crowning Glory with Aloe","16oz","15"," ","NO DETAILS","NO SKU","product/Crowning Gloryz.jpg"],
["Shampoo","Crowning Glory with Aloe","32oz","22"," ","NO DETAILS","NO SKU","product/Crowning Gloryz.jpg"],
["Shampoo","Crowning Glory with Aloe","Gallon","45"," ","NO DETAILS","NO SKU","product/Crowning Gloryz.jpg"],
["Shampoo","Lavender White Brightening","8oz","10","Gentle whitening/brightening shampoo. This product will leave the coat shiny and lustrous. Enhances all coat colors with the use of optical brighteners and ultraviolet. Safe and mild. Dilute 8:1","NO DETAILS","NO SKU","product/Lavender Whitez.jpg"],
["Shampoo","Lavender White Brightening","16oz","15"," ","NO DETAILS","NO SKU","product/Lavender Whitez.jpg"],
["Shampoo","Lavender White Brightening","32oz","22"," ","NO DETAILS","NO SKU","product/Lavender Whitez.jpg"],
["Shampoo","Lavender White Brightening","Gallon","45"," ","NO DETAILS","NO SKU","product/Lavender Whitez.jpg"],
["Shampoo","Melaleuca Medicated","8oz","10","A naturally medicated shampoo containing tee tree oil. Helps in the treatment of dry flaky skin. Dilute 4:1","NO DETAILS","NO SKU","product/Melaleucaz.jpg"],
["Shampoo","Melaleuca Medicated","16oz","15"," ","NO DETAILS","NO SKU","product/Melaleucaz.jpg"],
["Shampoo","Melaleuca Medicated","32oz","22"," ","NO DETAILS","NO SKU","product/Melaleucaz.jpg"],
["Shampoo","Melaleuca Medicated","Gallon","45"," ","NO DETAILS","NO SKU","product/Melaleucaz.jpg"],
["Shampoo","Pear Blossom","8oz","10","Prickly pear cactus, a naturally-occurring insect repellant is the active ingredient, enabling this shampoo to provide effective protection from insects; deep cleaning without stripping the natural oils from the coat. Pear Blossom moisturizes and conditions the coat and skin and will soothe and heal flea bite dermatitis, hotspots and various other forms of irritated skin. Dilute 15:1","NO DETAILS","NO SKU","product/Pear Blossomz.jpg"],
["Shampoo","Pear Blossom","16oz","15"," ","NO DETAILS","NO SKU","product/Pear Blossomz.jpg"],
["Shampoo","Pear Blossom","32oz","22"," ","NO DETAILS","NO SKU","product/Pear Blossomz.jpg"],
["Shampoo","Pear Blossom","Gallon","45"," ","NO DETAILS","NO SKU","product/Pear Blossomz.jpg"],
["Shampoo","Pearl Shampoo","8oz","10","Ultra Cleansing Premium Shampoo. Provides luster to coat and is TEARLESS as well as HYPOALLERGENIC. Effective on extremely dirty coats. Dilute 20-1.","NO DETAILS","NO SKU","product/Pearlz.jpg"],
["Shampoo","Pearl Shampoo","16oz","15","","NO DETAILS","NO SKU","product/Pearlz.jpg"],
["Shampoo","Pearl Shampoo","32oz","22"," ","NO DETAILS","NO SKU","product/Pearlz.jpg"],
["Shampoo","Pearl Shampoo","Gallon","45"," ","NO DETAILS","NO SKU","product/Pearlz.jpg"],
["Shampoo","White Cloud Thermogenic","8oz","13","A natural Enzyme product enhanced with a whitening agent resulting in a bright coat. This is a heat activated product. White Cloud will remove stubborn stains and can reactivate with a blowdryer. Dilute 7:1 – Use very warm water. Leave in coat 5 minutes. For tough stains – Do not dilute. Warm shampoo before applying to stain. Leave in coat 5-10 minutes.","NO DETAILS","NO SKU","product/White Cloudz.jpg"],
["Shampoo","White Cloud Thermogenic","16oz","20"," ","NO DETAILS","NO SKU","product/White Cloudz.jpg"],
["Shampoo","White Cloud Thermogenic","32oz","30"," ","NO DETAILS","NO SKU","product/White Cloudz.jpg"],
["Shampoo","White Cloud Thermogenic","Gallon","55"," ","NO DETAILS","NO SKU","product/White Cloudz.jpg"],
["Condtioners","Cactus Flower","8oz","10","A specialized conditioner that restores damaged coats to a rich luster while moisturizing and soothing dry, irritated skin. The active ingredient, extracted from the prickly pear cactus, is a natural insect repellant and a healing agent; excellent for relieving flea bite dermatitis, hot spots, wounds and other skin conditions. Dilute 10:1; spray 30:1 – Dilute with distilled water to leave in coat.","NO DETAILS","NO SKU","product/Cactus Flowerz.jpg"],
["Condtioners","Cactus Flower","16oz","15"," ","NO DETAILS","NO SKU","product/Cactus Flowerz.jpg"],
["Condtioners","Cactus Flower","32oz","22"," ","NO DETAILS","NO SKU","product/Cactus Flowerz.jpg"],
["Condtioners","Cactus Flower","Gallon","45"," ","NO DETAILS","NO SKU","product/Cactus Flowerz.jpg"],
["Condtioners","Cloud Light","8oz","10","A high quality, light conditioner. Helps to re-hydrate skin and coat. Dilute 3:1 for conditioner; Dilute 15:1 for harsh coats; Dilute 30:1 for finishing spray. Dilute with distilled water to leave in coat.","NO DETAILS","NO SKU","product/Cloud Lightz.jpg"],
["Condtioners","Cloud Light","16oz","15"," ","NO DETAILS","NO SKU","product/Cloud Lightz.jpg"],
["Condtioners","Cloud Light","32oz","22"," ","NO DETAILS","NO SKU","product/Cloud Lightz.jpg"],
["Condtioners","Cloud Light","Gallon","45"," ","NO DETAILS","NO SKU","product/Cloud Lightz.jpg"],
["Condtioners","Silk ‘N Satin","8oz","10","Silk conditioner formulated to control static. Excellent at removing mats. Makes brushing easier and reduces drying time. Adds body and sheen. Dilute 12:1; Daily grooming spray dilute 30:1. Dilute with distilled water to leave in coat.","NO DETAILS","NO SKU","product/Silk N Satinz.jpg"],
["Condtioners","Silk ‘N Satin","16oz","15"," ","NO DETAILS","NO SKU","product/Silk N Satinz.jpg"],
["Condtioners","Silk ‘N Satin","32oz","32"," ","NO DETAILS","NO SKU","product/Silk N Satinz.jpg"],
["Condtioners","Silk ‘N Satin","Gallon","45"," ","NO DETAILS","NO SKU","product/Silk N Satinz.jpg"],
["Condtioners","Ultra Phix Damaged Coat Repair","8oz","20","The Ultimate in coat repair and protection. Repairs damaged coat. May be left in the coat when diluted with distilled water. Dilute 15:1.","NO DETAILS","NO SKU","product/Ultra Phixz.jpg"],
["Condtioners","Ultra Phix Damaged Coat Repair","16oz","32","The Ultimate in coat repair and protection. Repairs damaged coat. May be left in the coat when diluted with distilled water. Dilute 15:1.","NO DETAILS","NO SKU","product/Ultra Phixz.jpg"],
["Condtioners","Ultra Phix Damaged Coat Repair","32oz","49","The Ultimate in coat repair and protection. Repairs damaged coat. May be left in the coat when diluted with distilled water. Dilute 15:1.","NO DETAILS","NO SKU","product/Ultra Phixz.jpg"],
["Condtioners","Velvet Touch","8oz","13"," Conditions the coat to its optimum potential. Will leave the coat shiny and lustrous. Dilute 32:1. Dilute with DISTILLED WATER to leave in coat.","NO DETAILS","NO SKU","product/Velvet Touchz.jpg"],
["Condtioners","Velvet Touch","16oz","21"," Conditions the coat to its optimum potential. Will leave the coat shiny and lustrous. Dilute 32:1. Dilute with DISTILLED WATER to leave in coat.","NO DETAILS","NO SKU","product/Velvet Touchz.jpg"],
["Condtioners","Velvet Touch","32oz","34"," Conditions the coat to its optimum potential. Will leave the coat shiny and lustrous. Dilute 32:1. Dilute with DISTILLED WATER to leave in coat.","NO DETAILS","NO SKU","product/Velvet Touchz.jpg"],
["Condtioners","Velvet Touch","1 gal.","80"," Conditions the coat to its optimum potential. Will leave the coat shiny and lustrous. Dilute 32:1. Dilute with DISTILLED WATER to leave in coat.","NO DETAILS","NO SKU","product/Velvet Touchz.jpg"],
["Natural","Organic Finishing Rinse","8oz","22","A gentle organic rinse comprised of four natural oils that are insect repellants. Repels flies, fleas, ticks and mosquitoes. Use on yourself as well! Dilute 3 ounces to 1 gallon distilled water.","NO DETAILS","NO SKU","product/Organic Finishing Rinsez.jpg"],
["Natural","Organic Finishing Rinse","16oz","36","A gentle organic rinse comprised of four natural oils that are insect repellants. Repels flies, fleas, ticks and mosquitoes. Use on yourself as well! Dilute 3 ounces to 1 gallon distilled water.","NO DETAILS","NO SKU","product/Organic Finishing Rinsez.jpg"],
["Natural","Soothing Splash Tea Tree Spray","8oz","12","Soothing Splash Tea Tree Oil Spray is a combination of tea tree oil and other soothing ingredients, which aids in the treatment of hot spots, cuts, bites, itchy skin and fungus. It has an unpleasant taste to reduce licking and chewing. Soothing Splash is excellent to use as an ear cleaner.","NO DETAILS","NO SKU","product/Soothing Splash Tea Tree Sprayz.jpg"],
["Natural","Soothing Splash Tea Tree Spray","16oz","15","Soothing Splash Tea Tree Oil Spray is a combination of tea tree oil and other soothing ingredients, which aids in the treatment of hot spots, cuts, bites, itchy skin and fungus. It has an unpleasant taste to reduce licking and chewing. Soothing Splash is excellent to use as an ear cleaner.","NO DETAILS","NO SKU","product/Soothing Splash Tea Tree Sprayz.jpg"],
["Natural","Soothing Splash Tea Tree Spray","32oz","22","Soothing Splash Tea Tree Oil Spray is a combination of tea tree oil and other soothing ingredients, which aids in the treatment of hot spots, cuts, bites, itchy skin and fungus. It has an unpleasant taste to reduce licking and chewing. Soothing Splash is excellent to use as an ear cleaner.","NO DETAILS","NO SKU","product/Soothing Splash Tea Tree Sprayz.jpg"],
["Natural","Wonder Ear"," ","17","Has your dog been scratching at those ears lately. Then you need to get WONDER EAR! WONDER EAR has a profound effect on the problems associated with a moist ear.  Cleans up infections in just a couple of treatments. As we know, most all of the ear problems we encounter in the dogs start with a moist ear. WONDER EAR is clean smelling, stops infections and keeps the ears clean with periodic maintenance.","NO DETAILS","NO SKU","product/Wonder Earz.jpg"],
["Showstopper","SHOWSTOPPER","4lb","36.49","All-In-One Coat and Body Optimizer. For Your Valuable Show Dogs and Your Cherished Pets. Stunning looks reflect inside health.  A gorgeous coat, solid physique, rock solid joints and the energy are so striking it literally stops the show.","NO DETAILS","NO SKU","product/showstopperz.jpg"],
["Showstopper","SHOWSTOPPER","7lb","52.49","All-In-One Coat and Body Optimizer. For Your Valuable Show Dogs and Your Cherished Pets. Stunning looks reflect inside health.  A gorgeous coat, solid physique, rock solid joints and the energy are so striking it literally stops the show.","NO DETAILS","NO SKU","product/showstopperz.jpg"],
["Showstopper","SHOWSTOPPER","15lb","103.49","All-In-One Coat and Body Optimizer. For Your Valuable Show Dogs and Your Cherished Pets. Stunning looks reflect inside health.  A gorgeous coat, solid physique, rock solid joints and the energy are so striking it literally stops the show.","NO DETAILS","NO SKU","product/showstopperz.jpg"]
);

}

function populateShoppingArea (category,spanID)
{

 var product = ""
 var nomen = ""; //nomenclature that goes into select options
 var txt = ""
 var i = 0;
 var pidx = 0; //indexer that tracks where to grab values
 for (i = 0; i < prodArray.length;i++)
 {
  if (prodArray[i][0] == category) 
  {
    if (prodArray[i][1] != product)
    {
     if (product != "") 
     {
      txt += '</select>&nbsp;&nbsp;Qty: <input name="Name" size="4" type="text" value = "1" id = "q'+pidx+'"></td><td><img src = "img/addtocart.png" style="cursor: pointer;" onclick = "addToCart(\'k'+pidx+'\',\'q'+pidx+'\');cartSynopsis();"></td></tr></table><br>';
      pidx++;
     }
     product = prodArray[i][1];
     nomen = prodArray[i][2]+" $"+prodArray[i][3];
     txt += '<center><img src = "img/hrule.png"></center><br><table align = "center" border = "0" cellspacing = "0" cellpadding = "0">';
     txt += '<tr><td rowspan = 2 valign = "top"><img src = "'+prodArray[i][7]+'"></td><td width = "20"></td><td colspan = 2> <span style = "font-size: 12pt;font-family: arial, helvetica,sans-serif;color: #000000; font-weight: bold;">'+prodArray[i][1]+'</span><br>';
     txt += '<span class = "font-size: 10pt;font-family: arial, helvetica,sans-serif;color: #44494d;">'+prodArray[i][4]+'</span><br><br></td></tr>';
     txt += '<tr><td> </td><td> <select name="'+product+'" id="k'+pidx+'"><option value = "'+product+' '+nomen+ '" selected = "selected">'+nomen+'</option>';
    } else
    {
     nomen = prodArray[i][2]+" $"+prodArray[i][3];
     txt += '<option value = "'+product+' '+nomen+ '">'+nomen+'</option>';
    }
  }
 }
     if (product != "") 
     {
      txt += '</select>&nbsp;&nbsp;Qty: <input name="Name" size="4" type="text" value = "1" id = "q'+pidx+'"></td><td><img src = "img/addtocart.png" style="cursor: pointer;" onclick = "addToCart(\'k'+pidx+'\',\'q'+pidx+'\');cartSynopsis();"></td></tr></table><br>';
      pidx++;
     }

 document.getElementById(spanID).innerHTML = txt;

}

function parseQTY (q)
{
 var retval = 1;
 try
  {
   retval = parseInt (q);
  }
  catch(err)
  {
    retval = 1
  }
 if (retval < 0 ) retval = 1;
 if (isNaN(retval)) retval = 1;
 return retval;
}

function addToCart (pID,qID)
{
   var item = document.getElementById(pID).value;
   var addQTY = parseQTY (document.getElementById(qID).value);
   loadCart();
   var added = 0;
   var tempArray = item.split("$");
   var nomen = tempArray[0];
   var qty = 0;
   for (i = 0; i < cartArray.length;i++) //check to see if item is in cart;
   {
   if (cartArray[i].length > 4)
   {
     tempArray = cartArray[i].split("$");
     if (tempArray[0] == nomen)
     {
       qty = parseInt(tempArray[2]);
       qty += addQTY;
       tempArray[2] = qty;
       cartArray[i] = tempArray[0]+"$"+tempArray[1]+"$"+tempArray[2]; //The cart is separated by $
       added = 1;
     }
  }
 } 

  if (added == 0) cartArray.push(item+"$"+addQTY);
  saveCart();
  showCart();
}

function loadCart()
{
 var cke = readCookie("cart");
 if (cke != null)
 {
  cartArray = cke.split('^');
 } else cartArray = ["NULL"];
 
}

function showCart()
{
  window.open('cart.htm','mywindow','width=600,height=600,toolbar=no, location=yes,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes');
}



function saveCart()
{
 var cart = "";
 var i = 0;
 for (i = 0;i < cartArray.length;i++)
 {
  cart += cartArray[i] +"^";
 }
 
 createCookie ("cart",cart,365);
 
}

function clearCart()
{
 cartArray = ["NULL"];
 saveCart();
}

function viewCart (spanID)
{
 var tempArray;
 loadCart();
 var total = 0.00;
 var shipping = 0.00;
 var grandtotal = 0.00;
 var amt = 0;
 var txt = '<table align = "center" border = "0" cellspacing = "0" cellpadding = "0">';
     txt += '<tr><td></td><td><b><u>ITEM</b></u></td><td width = "20"></td><td><b><u>PRICE</b></u></td><td width = "20"></td><td><b><u>QTY</b></u></td><td width = "20"></td><td><b><u>AMOUNT</b></u></td></tr>';
 var i = 0;
 for (i = 0; i < cartArray.length;i++)
 {
  if (cartArray[i].length > 4)
  {
   tempArray = cartArray[i].split("$");
   amt = parseFloat(tempArray[1])*parseFloat(tempArray[2]);
   total += amt;
   txt += '<tr><td width = 20><img src = "img/remove.png" onclick = "removeItem('+i+');viewCart(\''+spanID+'\');" style="cursor: pointer;" title = "Remove"></td><td>'+tempArray[0]+'</td><td width = "20"></td><td>$'+tempArray[1]+'</td><td width = "20"></td><td>'+tempArray[2]+'</td><td width = "20"></td><td>$'+amt+'</td></tr>';
  }
 }
 shipping = calculateShipping(total);
 grandtotal = total+shipping;
 txt += '<tr><td></td><td>&nbsp;</td><td width = "20"></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td></td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td>SUBTOTAL:</td><td width = "20"></td><td>$'+CurrencyFormatted(total)+'</td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td>S&H:</td><td width = "20"></td><td>$'+CurrencyFormatted(shipping)+'</td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td><b>TOTAL:</b></td><td width = "20"></td><td><b>$'+CurrencyFormatted(grandtotal)+'</b></td></tr>';
 txt += '</table>';
 document.getElementById(spanID).innerHTML = txt;
}

function viewCart2 (spanID)
{
 var tempArray;
 loadCart();
 var total = 0.00;
 var shipping = 0.00;
 var grandtotal = 0.00;
 var amt = 0;
 var txt = '<table align = "center" border = "0" cellspacing = "0" cellpadding = "0">';
     txt += '<tr><td></td><td><b><u>ITEM</b></u></td><td width = "20"></td><td><b><u>PRICE</b></u></td><td width = "20"></td><td><b><u>QTY</b></u></td><td width = "20"></td><td><b><u>AMOUNT</b></u></td></tr>';
 var i = 0;
 for (i = 0; i < cartArray.length;i++)
 {
  if (cartArray[i].length > 4)
  {
   tempArray = cartArray[i].split("$");
   amt = parseFloat(tempArray[1])*parseFloat(tempArray[2]);
   total += amt;
   txt += '<tr><td width = 20></td><td>'+tempArray[0]+'</td><td width = "20"></td><td>$'+tempArray[1]+'</td><td width = "20"></td><td>'+tempArray[2]+'</td><td width = "20"></td><td>$'+amt+'</td></tr>';
  }
 }
 shipping = calculateShipping(total);
 grandtotal = total+shipping;
 txt += '<tr><td></td><td>&nbsp;</td><td width = "20"></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td></td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td>SUBTOTAL:</td><td width = "20"></td><td>$'+CurrencyFormatted(total)+'</td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td>S&H:</td><td width = "20"></td><td>$'+CurrencyFormatted(shipping)+'</td></tr>';
 txt += '<tr><td></td><td></td><td width = "20"></td><td></td><td width = "20"></td><td><b>TOTAL:</b></td><td width = "20"></td><td><b>$'+CurrencyFormatted(grandtotal)+'</b></td></tr>';
 txt += '</table>';
 document.getElementById(spanID).innerHTML = txt;
}


function getTotal()
{
 loadCart();
 var tempArray;
 var total = 0.00;
 var count = 0;
 for (i = 0; i < cartArray.length;i++)
 {
  if (cartArray[i].length > 4)
  {
   tempArray = cartArray[i].split("$");
   total += parseFloat(tempArray[1])*parseFloat(tempArray[2]);
   count += parseInt(tempArray[2]);
  }
 }

 return total;
}

function cartSynopsis ()
{
 loadCart();
 var tempArray;
 var total = 0.00;
 var count = 0;
 for (i = 0; i < cartArray.length;i++)
 {
  if (cartArray[i].length > 4)
  {
   tempArray = cartArray[i].split("$");
   total += parseFloat(tempArray[1])*parseFloat(tempArray[2]);
   count += parseInt(tempArray[2]);
  }
 }
 var txt = "";
 txt += "<b>"+count+" Item(s): $"+CurrencyFormatted(total)+"</b>"
 document.getElementById('Synopsis').innerHTML = txt;
}


function calculateShipping (total)
{
 var retval = 0;
 if (total >= 40) retval = total*0.288; else
 if (total > 2) retval = 7.95;
 return retval;
}

function removeItem (indexer) //removes item at index
{
 loadCart();
 cartArray.splice(indexer, 1);
 saveCart();
}


//=-=-=-=-=-=-=-=-=-=-=-=- Shopping cart customer Info Code-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



function findCustInfoIndex (field) //this finds the index of a certain field identifier in CustInfo array
{
 var found = -1; //this variable tells us if it's found in the CustInfo Array -1 = false else position in array
 var i;
 if (custInfo.length > 0)
 {
   for (i =0; i < custInfo.length; i++)
   {
    if (custInfo[i][0] == field) found = i;
   }
 }
 return found;
}


function addCustInfo (field,value)
{
 var indexer = findCustInfoIndex(field);
 if (indexer > -1)
 {
  custInfo[indexer][1] = value;
 }
 else
 {
  indexer = custInfo.length;
  custInfo[indexer] = new Array (2);
  custInfo[indexer][0] = field;
  custInfo[indexer][1] = value;
 }
}

function getCustInfo (field)
{
 var indexer = findCustInfoIndex(field);
 var retval = ""; 
 if (indexer > -1)
 {
  retval = custInfo[indexer][1];
 }
 return retval;
}

function loadCustInfo()
{
 var cke = readCookie("cust");
 var temp = new Array();
 custInfo = new Array();
 var indexer;
 var i;
 if (cke != null)
 {
  temp = cke.split('^');
  for (i = 0; i < temp.length; i += 2)
  {
    if (temp[i] != "") 
    {
      indexer = custInfo.length;
      custInfo[indexer] = new Array (2);
      custInfo[indexer][0] = temp[i];
      custInfo[indexer][1] = temp[i+1];
    }
  }
 } 
 
}

function saveCustInfo()
{
 var temp = "";
 var i = 0;
 for (i = 0;i < custInfo.length;i++)
 {
  temp += custInfo[i][0] +"^" + custInfo[i][1] + "^";
 }
 
 createCookie ("cust",temp,365);
 
}

function clearCustInfo()
{
 custInfo = new Array();
 saveCustInfo();
}

//=-=-=-=-=-=-=-=-=-=-=-=- Shopping cart Customer Information IO-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



function populateInputBlock (Ident)
{
 if (Ident == "Billing")
 {
  inputBlock = new Array(
  ["Billing Address","fieldname","size","required 1 or 0"],
  ["First Name","First","30","1"],
  ["Last Name","Last","35","1"],
  ["Address","Address","35","1"],
  ["City","City","35","1"],
  ["State","State","10","1"],
  ["Postal Code (ZIP)","Zip","10","1"],
  ["Country","Country","30","0"],
  ["Phone","Phone","30","1"],
  ["E-mail Address","Email","30","0"]);
 }

 if (Ident == "Shipping")
 {
  inputBlock = new Array(
  ["Shipping Address","fieldname","size","required 1 or 0"],
  ["Ship to First Name","First2","30","0"],
  ["Ship to Last Name","Last2","35","0"],
  ["Ship to Address","Address2","35","0"],
  ["Ship to City","City2","35","0"],
  ["Ship to State","State2","10","0"],
  ["Ship to Postal Code (ZIP)","Zip2","30","0"],
  ["Ship to Country","Country2","30","0"],
  ["Ship to Phone:","Phone2","30","0"]);

 }

 if (Ident == "Payment")
 {
  inputBlock = new Array(
  ["Payment Section","fieldname","size","required 1 or 0"],
  ["Credit Card Number","Cardnum","30","1"],
  ["Expiration Date(MMYY)","Exp","10","1"],
  ["CVV2 <img src = \"cart/what.png\" onclick = \" CVV2Img() \" style=\"cursor: pointer;\">","CVV2","10","1"]
  );
 }


}

function CVV2Img ()
{
 if ( document.getElementById('err').innerHTML != '<img src="cart/cvv2.png">')
 {
  document.getElementById('err').innerHTML = '<img src="cart/cvv2.png">';
 } else document.getElementById('err').innerHTML = "";
}

function saveInputBlock () //Saves Block of User Input
{
 var i;
 var id;
 var tempstr;
 loadCustInfo();
 for (i = 1;i < inputBlock.length;i++)
 {
   id = inputBlock[i][1];
   
   tempstr = document.getElementById(id).value;
   tempstr = removeChar (tempstr,"\\");
   tempstr = removeChar (tempstr,"/");
   addCustInfo(id,tempstr);
 }
 saveCustInfo();
}

function billingBlock(ident)
{
populateInputBlock(ident);
var txt = '<center>';
var i = 0;
txt += '<form name = "inputform">';
txt += '<table align = "center" border = "0" cellspacing = "3" cellpadding = "0"><th colspan = "2" class = "header1">'+inputBlock[0][0]+'</th>';

for (i = 1;i < inputBlock.length;i++)
{
  txt+= '<tr><td>'+inputBlock[i][0]+':</td>';
  txt+= '<td><input type="text" name="'+inputBlock[i][1]+'" id = "'+inputBlock[i][1]+'" value = "'+getCustInfo(inputBlock[i][1])+'"';
  txt+= 'size = "'+inputBlock[i][2]+'">';
  if (inputBlock[i][3] == "1") txt += '&nbsp;<span class = "red12">*</span>';
  txt+= '</td></tr>';
  
}
txt += '</table></form><span id = "err" class = "red12"></span></center>';
return txt;
}

function checkInputBlock()
{
 var retval = "OK"
 var i;
 for (i = 1;i < inputBlock.length;i++)
 {
   if (inputBlock[i][3] == "1")
   {
    if (document.getElementById(inputBlock[i][1]).value.length < 2) 
    { 
     retval = inputBlock[i][0]+" is required";
    }
   }
 }
 return retval;
}


function getInvoiceNumber ()
{
var d=new Date();
return "BR"+d.getYear()+d.getMonth()+d.getDate()+d.getHours()+d.getMinutes()+d.getSeconds();

}

function checkout()
{
popup ('checkout.htm');
}

function popup (url)
{
window.open(url,'mywindow','width=600,height=600,toolbar=no, location=yes,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes');

}

function showCheckOut (spanID)
{
 clearCustInfo(); 
 var total = getTotal();
 var txt;
 if (total != 0)
 {
   txt = billingBlock("Billing");//createCheckoutForm(total,inv);
   txt += '<br><br><img src = "cart/continue.png" onclick = "checkoutPart2(\''+spanID+'\');" style="cursor: pointer;">&nbsp;&nbsp;&nbsp;<img src = "cart/cancel.png" onclick = "window.close()" style="cursor: pointer;">';
 } else 
 {
  txt = "<h1>No Items In Cart!</h1>";
 }
 document.getElementById(spanID).innerHTML = txt;  
 loadCustInfo();
 FillBilling();
}

function checkoutPart2 (spanID)
{
 var temp = checkInputBlock();
 var txt = "";
 if (temp == "OK")
 {
   saveInputBlock(); //This saves values entered
   txt = billingBlock("Shipping");//createCheckoutForm(total,inv);
   txt += '<br><br><img src = "cart/continue.png" onclick = "checkoutPart3(\''+spanID+'\');" style="cursor: pointer;">&nbsp;&nbsp;&nbsp;<img src = "cart/same.png" onclick = "sameAsBilling();" style="cursor: pointer;">&nbsp;&nbsp;&nbsp;<img src = "cart/cancel.png" onclick = "window.close()" style="cursor: pointer;">';
   document.getElementById(spanID).innerHTML = txt;  
 } else
 {
   document.getElementById('err').innerHTML = temp;
 }
}

function checkoutPart3 (spanID)
{
 var txt = "";
 saveInputBlock(); //This saves values entered
 txt = billingBlock("Payment")//createCheckoutForm(total,inv);
 txt += '<br><br><img src = "cart/continue.png" onclick = "checkoutPart4(\''+spanID+'\');" style="cursor: pointer;">&nbsp;&nbsp;&nbsp;<img src = "cart/cancel.png" onclick = "window.close()" style="cursor: pointer;">';
 document.getElementById(spanID).innerHTML = txt;  
}


function checkoutPart4(spanID)
{
 var temp = checkInputBlock();
 var total = getTotal();
 var ship = calculateShipping (total);
 var txt = "";
 if (temp == "OK")
 {
   addCustInfo ("Invoice",getInvoiceNumber ());
   addCustInfo ("Sub-Total",CurrencyFormatted(total));
   addCustInfo ("Shipping and Handling",CurrencyFormatted(ship));
   addCustInfo ("Total",CurrencyFormatted(total+ship));
   saveCustInfo();
   saveInputBlock();
   document.getElementById(spanID).innerHTML = createCheckoutForm();
   document.ccform.submit();
 } else
 {
   document.getElementById('err').innerHTML = temp;
 }
}

function showInvoice (spanID)
{
 loadCustInfo(); loadCart();
 var txt = "";
 var Inv = getCustInfo("Invoice");
 var d1 = getCustInfo("ssl_txn_time");
 var d2 = d1.split("%");
 if ((Inv == "") || (getCustInfo("ssl_txn_id") == ""))
 {
   txt = "<h1>Nothing to invoice!</h1> ";
 } else
 {
   txt += '<center>';
   txt += '<table align = "center" border = "0" cellspacing = "3" cellpadding = "0">';
   txt += '<tr>';
   txt += '<td width = "50%">';
   txt += '<center><img src = "cart/logo.png"></center>';
   txt += '<H2> Ballyridge, Inc.</h2>';
   txt += 'Email: BallyRidgeInc@aol.com<br>';
   txt += 'Phone: 541-740-7447<br>';
   txt += '</td><td></td>';
   txt += '<td>';
   txt += '<center><h1>INVOICE</H1></center>';
   txt += '<p class = "Black12Bold">INVOICE #:'+Inv+'</p>';
   txt += '';
   txt += '<p class = "Black12Bold">DATE:'+d2[0]+'</p>';
   txt += '</td>';
   txt += '</tr><tr><td>';
   txt += '<table align = "center" border = "0" cellspacing = "3" cellpadding = "0" width = "90%">';
   txt += '<th colspan = "2" class = "header1">BILL TO:</th>';
   txt += '<tr><td>'+getCustInfo ("First")+' '+getCustInfo("Last")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Address")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("City")+' '+getCustInfo ("State")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Country")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Zip")+'</td></tr>';
   txt += '</table><br><br>';
   txt += '</td><td width = 30></td><td valign = "top">';
   txt += '<table align = "center" border = "0" cellspacing = "3" cellpadding = "0" width = "90%">';
   txt += '<th colspan = "2" class = "header1">SHIP TO:</th>';
   txt += '<tr><td>'+getCustInfo ("First2")+' '+getCustInfo("Last2")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Address2")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("City2")+' '+getCustInfo ("State2")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Country2")+'</td></tr>';
   txt += '<tr><td>'+getCustInfo ("Zip2")+'</td></tr>';
   txt += '</table>';
   txt += '</td></tr></table>';
   txt += '</center>';
   viewCart2('invBody');
   clearCart();
   clearCustInfo();
 }
 document.getElementById(spanID).innerHTML = txt; 

}

function sendInvoice (spanID)
{
 loadCustInfo();
 loadCart();
 var count = 0;
 var Inv = getCustInfo("Invoice");
 var Total =  getCustInfo("Total");
 var tempArray;
 addCustInfo ("ssl_card_number", gup ("ssl_card_number"));
 addCustInfo ("ssl_result_message", gup ("ssl_result_message"));
 addCustInfo ("ssl_txn_id", gup ("ssl_txn_id"));
 addCustInfo ("ssl_approval_code", gup ("ssl_approval_code"));
 addCustInfo ("ssl_cvv2_response", gup ("ssl_cvv2_response"));
 addCustInfo ("ssl_txn_time", gup ("ssl_txn_time"));
 saveCustInfo();
 var txt = "";
 if ((Inv == "") || (getCustInfo("ssl_txn_id") == ""))
 {
   txt = "<h1>Nothing to invoice!</h1> ";
 } else
 {
  txt += '<FORM NAME="mailInvoice" ACTION="/cgi-sys/formmail.pl" METHOD="POST">';
  txt += '<INPUT TYPE="hidden" NAME="recipient" VALUE="sales@traleigh-ballyridge.com">';
  txt += '<INPUT TYPE="hidden" NAME="subject" VALUE="ORDER">';
  txt += '<INPUT TYPE="hidden" NAME="redirect" VALUE="https://traleigh-ballyridge.com/invoice.htm">';
   for (i =0; i < custInfo.length; i++) //Customer Info
   {
    if (custInfo[i][0] != "Cardnum") txt += '<INPUT TYPE="hidden" NAME="'+custInfo[i][0]+'" VALUE = "'+custInfo[i][1]+'">';
   }
  
   for (i = 0; i < cartArray.length;i++) //Items Bought
   {
    if (cartArray[i].length > 4)
    {
     count++;
     tempArray = cartArray[i].split("$");
     txt += '<INPUT TYPE="hidden" NAME="ITEM'+parseInt(count)+'" VALUE = "NAME:'+tempArray[0]+' QTY:'+tempArray[2]+'">';
    }
   }

  txt += '</FORM>';
 }
 document.getElementById(spanID).innerHTML = txt; 
 document.mailInvoice.submit(); 
}



function createCheckoutForm()
{
    var total = getCustInfo("Total");
    var sequence = generatesequence();
    var time = generatetimestamp();
    var hash = generatefingerprint("88apz9KP4728m8TY", "84Ykta7wLV8", total, sequence, time)
var txt = '';
txt += '<form action="https://secure.authorize.net/gateway/transact.dll" name="ccform" method="POST">';
txt += '<input type="hidden" name="x_amount" value="'+getCustInfo ("Total")+'"> <br/>';
txt += '<input type="hidden" name="x_login" value="84Ykta7wLV8">';
//txt += '<input type="hidden" name="ssl_user_id" value="Ballyweb">';
//txt += '<input type="hidden" name="ssl_pin" value="WFP8NG">';
txt += '<input type="hidden" name="x_method" value="CC">';
//txt += '<input type="hidden" name="ssl_show_form" value="FALSE">';
txt += '<input type="hidden" name="x_invoice_num" value="'+getCustInfo ("Invoice")+'">';
//txt += '<input type="hidden" name="ssl_email" value="'+getCustInfo ("Email")+'">';
//txt += '<input type="hidden" name="ssl_avs_address" value="'+getCustInfo ("Address")+'">';
//txt += '<input type="hidden" name="ssl_avs_zip" value="'+getCustInfo ("Zip")+'">';
txt += '<input type="hidden" name="x_card_num" value = "'+getCustInfo ("Cardnum")+'"> <br/>';
txt += '<input type="hidden" name="x_exp_date" value = "'+getCustInfo ("Exp")+'">';
//txt += '<input type="hidden" name="ssl_cvv2cvc2" value = "'+getCustInfo ("CVV2")+'">';
//txt += '<input type="hidden" name="ssl_cvv2cvc2_indicator" value = "1">';
txt += '<input type="hidden" name="x_test_request" value="false">';
txt += '<input type="hidden" name="x_fp_sequence" value="'+ sequence +'">';
txt += '<input type="hidden" name="x_fp_timestamp" value="' + time +'">';
txt += '<input type="hidden" name="x_fp_hash" value="' + hash + '">';
txt += '<input type="hidden" name="x_relay_url" value="https://traleigh-ballyridge.com/relay.php">';
txt += '<input type="hidden" name="x_relay_response" value="TRUE">';
//txt += '<input type="hidden" name="ssl_receipt_apprvl_get_url" value="https://traleigh-ballyridge.com/approved.htm">';
txt += '<input type="hidden" name="x_type" value="AUTH_CAPTURE">';
txt += '</form>';
return txt;}

function sameAsBilling()
{
 var id; 
 for (i = 1;i < inputBlock.length;i++)
 {
   id = inputBlock[i][1];
   try
   {
   document.getElementById(id).value = getCustInfo (removeChar(id,"2"));
   }
   catch (err)
   { 
   }
 }
}

function FillBilling()
{
 var id; 
 for (i = 1;i < inputBlock.length;i++)
 {
   id = inputBlock[i][1];
   try
   {
   document.getElementById(id).value = getCustInfo (id);
   }
   catch (err)
   { 
   }
 }
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END SHOPPING CART CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START NAVIGATION CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

var navArray = new Array();
var mainNavURL = "";
var mainNavId = "";

function goSecure ()
{
 //alert (location.hostname); 
 var newURL;
 if (( location.protocol == "http:" ) || ( location.protocol == "http" ))
 {
   newURL = "https://"+location.hostname+location.pathname;
   window.location.href = newURL;
 }
}

function InitNav (nid)
{
navArray = new Array(
["N1","img/main1.png","img/main2.png"],
["N2","img/shamp1.png","img/shamp2.png"],
["N3","img/cond1.png","img/cond2.png"],
["N4","img/natu1.png","img/natu2.png"],
["N5","img/show1.png","img/show2.png"],
["N6","img/cont1.png","img/cont2.png"]
);

for (i = 0; i < navArray.length; i++)
  {
	  if (navArray[i][0] == nid) 
	  {
		mainNavURL = navArray[i][2];
		document.getElementById(navArray[i][0]).src = navArray[i][2];
		mainNavId = nid;
	  }
  }

}

function HiLite (nid)
{

 for (i = 0; i < navArray.length; i++)
  {
	  if (navArray[i][0] == nid) 
	  {
		document.getElementById(navArray[i][0]).src = navArray[i][2];
	  }
  }
}

function unHiLite (nid)
{

 for (i = 0; i < navArray.length; i++)
  {
	  if (navArray[i][0] == nid) 
	  {
		document.getElementById(navArray[i][0]).src = navArray[i][1];
	  }
  }
  if (mainNavId != "") document.getElementById(mainNavId).src = mainNavURL;
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END NAVIGATION CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START SLIDESHOW VARS AND CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


var j = 0; // counter for slide show
var p; // 

function XfadeInit () 
{

Pic[0] = 'img/show1.jpg';
Pic[1] = 'img/show2.jpg';
Pic[2] = 'img/show3.jpg';
Pic[3] = 'img/show4.jpg';

p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
}

function Xfade()
{
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src = Pic[j];
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t1 = setTimeout('Xfade()', slideShowSpeed);

}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END SLIDESHOW VARS AND CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START DIVSCROLLER VARS AND CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


function scrollDivLeft(id,step){
t  = 0;
document.getElementById(id).scrollLeft-=step
step--;
if (step > 0) t=setTimeout("scrollDivLeft('"+id+"',"+step+")",2); else document.getElementById(id).scrollLeft-=1;

}

function scrollDivRight(id,step){
t  = 0;
document.getElementById(id).scrollLeft+=step
step--;
if (step > 0) t=setTimeout("scrollDivRight('"+id+"',"+step+")",2); else document.getElementById(id).scrollLeft+=1;

}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START DIVSCROLLER VARS AND CODE=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START STRING UTILITIES=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function removeT (s)
{
  var i;
  var retval = "";
  for (i = 0; i < s.length; i++)
  {
	  if (s.charAt(i) != "t") retval += s.charAt(i);//s[i];
  }
 return retval;
}


function replaceT (s)
{
  var i;
  var retval = "";
  for (i = 0; i < s.length; i++)
  {
	  if (s.charAt(i) != "t") retval += s.charAt(i); else retval += "a";
  }
 return retval;
}

function removeChar (s,c)
{
  var i;
  var retval = "";
  for (i = 0; i < s.length; i++)
  {
	  if (s.charAt(i) != c) retval += s.charAt(i);//s[i];
  }
 return retval;
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function gup( name ) //grab URL Parameters
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END STRING UTILITIES=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-START COOKIE UTILITIES=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END COOKIE UTILITIES=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


//******************************Start Crypto Untilities*****************************








//*******************************FingerPrint**********************************************
function generatefingerprint(transactionKey, login, amount,  sequence, timeStamp){
    var KeyString = login + "^" + sequence + "^" + timeStamp + "^" + amount + "^";
    var Result = hex_hmac_md5(transactionKey, KeyString);
    return Result;
}

//*********************************TimeStamp*****************************************
function generatetimestamp() {
    var d = new Date();
    var decimal = (d.getTime() / 1000);
    var int = Math.round(decimal);
    return int
}

//*********************************Sequence*****************************************

function generatesequence() {
    var decimal = Math.random() * 1000;
    var int = Math.round(decimal);
    return int;
}


//*************************MD5 Hash*******************************************************
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/

var hexcase = 0;
var b64pad = "";
var chrsz = 8;

function hex_md5(s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }
function b64_md5(s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }
function str_md5(s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

function md5_vm_test() {
    return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

function core_md5(x, len) {
    x[len >> 5] |= 0x80 << ((len) % 32);
    x[(((len + 64) >>> 9) << 4) + 14] = len;

    var a = 1732584193;
    var b = -271733879;
    var c = -1732584194;
    var d = 271733878;

    for (var i = 0; i < x.length; i += 16) {
        var olda = a;
        var oldb = b;
        var oldc = c;
        var oldd = d;

        a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
        d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
        c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
        b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
        a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
        d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
        c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
        b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
        a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
        d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
        c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
        b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
        a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
        d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
        c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
        b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);

        a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
        d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
        c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
        b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
        a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
        d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
        c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
        b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
        a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
        d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
        c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
        b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
        a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
        d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
        c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
        b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);

        a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
        d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
        c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
        b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
        a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
        d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
        c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
        b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
        a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
        d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
        c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
        b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
        a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
        d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
        c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
        b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);

        a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
        d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
        c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
        b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
        a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
        d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
        c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
        b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
        a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
        d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
        c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
        b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
        a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
        d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
        c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
        b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);

        a = safe_add(a, olda);
        b = safe_add(b, oldb);
        c = safe_add(c, oldc);
        d = safe_add(d, oldd);
    }
    return Array(a, b, c, d);

}

function md5_cmn(q, a, b, x, s, t) {
    return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
}
function md5_ff(a, b, c, d, x, s, t) {
    return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t) {
    return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t) {
    return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t) {
    return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function core_hmac_md5(key, data) {
    var bkey = str2binl(key);
    if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

    var ipad = Array(16), opad = Array(16);
    for (var i = 0; i < 16; i++) {
        ipad[i] = bkey[i] ^ 0x36363636;
        opad[i] = bkey[i] ^ 0x5C5C5C5C;
    }

    var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
    return core_md5(opad.concat(hash), 512 + 128);
}

function safe_add(x, y) {
    var lsw = (x & 0xFFFF) + (y & 0xFFFF);
    var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
    return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt) {
    return (num << cnt) | (num >>> (32 - cnt));
}

function str2binl(str) {
    var bin = Array();
    var mask = (1 << chrsz) - 1;
    for (var i = 0; i < str.length * chrsz; i += chrsz)
        bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
    return bin;
}

function binl2str(bin) {
    var str = "";
    var mask = (1 << chrsz) - 1;
    for (var i = 0; i < bin.length * 32; i += chrsz)
        str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
    return str;
}

function binl2hex(binarray) {
    var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    var str = "";
    for (var i = 0; i < binarray.length * 4; i++) {
        str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
           hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
    }
    return str;
}

function binl2b64(binarray) {
    var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var str = "";
    for (var i = 0; i < binarray.length * 4; i += 3) {
        var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16)
                | (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8)
                | ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
        for (var j = 0; j < 4; j++) {
            if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
            else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
        }
    }
    return str;
}

//******************************End Crypto Untilities*****************************


