//<script LANGUAGE="JavaScript">
var j;

function st(k, l, m) {
	ix++;
	document.forms[ix].itm = k;
	document.forms[ix].max = l;
	document.forms[ix].prc = m; 
	}

function wi() {document.write(document.forms[ix].itm);
	}

function wm() {document.write(document.forms[ix].max);
	}

function wp() {document.write(document.forms[ix].prc);
	}

function Chck(q,max) {
	q=Vald(q);
	n=max-q;
	if((n<0)||(n>max)) {
		alert("Quantity can be only 0 to " + max); return 0;
		}
	else return q;
	}

// Check that entered field contains only digits (not "+", "-", ".", ",")
function Vald(v) {
	var S=v;
	for(i=0;i<S.length;i++) {
		c=S.charAt(i);
		if(c<"0"||c>"9") {
			alert("Enter only digits"); return 0;
			}
		}
	return v;
	}

function CheckCookie() {
	var cookiename = document.value; var cookievalue = GetCookie(cookiename); var infostart = j; var count = 1;
	if(cookievalue != null)
		for (i=infostart; i<clen+1;i++)
			if(unescape(document.cookie.substring(i-3,i)) == "!") {
				var info = unescape(document.cookie.substring(infostart,i-3));
				if(count == 1) var item = info;
				if(count == 2)
					for(q=0;q<document.forms.length;q++)
						if(document.forms[q].itm == item) document.forms[q].Amount.value = info;
				if(count == 3) count = 0;
				count++; infostart = i;
				}
	}

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 + "="; alen = arg.length; clen = document.cookie.length; var i = 0;
	while (i < clen) {
		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 setup(file) {
	lo_f =  window.parent.frames[1];
	if(lo_f.inv_page == 1) {
//		cookieval = getto(lo_f.document.forms.length);
//		document.cookie = lo_f.document.value + "=" + escape (cookieval) + "; path=/";
		}
	if (file.length > 0) {
		if (file == 'index.htm') {
			window.parent.location = file;
			}
		else if (file.charAt(0) == '#') {
			lo_f.location = lo_f.location + file
			}
		else {
			lo_f.location = file;
			}
		}
	}

function getto(maxlmts)	{
	window.value = maxlmts; forcookie = "";	j = 0;
//alert(maxlmts);
	for (i=0;i<maxlmts;i++)
		if (lo_f.document.forms[i].Amount && lo_f.document.forms[i].Amount.value != 0) {
			forcookie = (forcookie + lo_f.document.forms[i].itm + "!" + lo_f.document.forms[i].Amount.value + "!" + lo_f.document.forms[i].prc + "!");
			j++;
			}
	window.parent.frames[1].value=j;
	return (forcookie);
	}


function BuyItem(vId, vQty, vPrice, vPageId) {
 var frmObj = document.getElementById(vId);	//form object: alter appearance
 AddItemToCookie(vId, vQty, vPrice, vPageId);
 }




function AddItemToCookie(vId, vQty, vPrice, vPageId) {

 //adjust qty to drop to minimum
 if (vPageId == "invsipol") {
  if (vQty > 25) vQty = "25";
  }
 else {
  //price break items have "-" in name
  //for non-invsipol items with no pricebreak, minimum = 1
  if (vId.indexOf("-") == -1) {
   vQty = 1;
   }
  }

 
//prepare cookie item
 var vCookieItem = vId + "!" + vQty + "!" + vPrice + "!";
 
//check if item exists in Cookie
 var vCurrentCookieValue = FindCookie(vPageId);
 
//overwrite temp shoppingcart cookie with new value if null
 if (vCurrentCookieValue == null)
  vCurrentCookieValue = "";	//make non-null
//vCookieItem;
 
 var vNewCookieValue = vCurrentCookieValue;
 var aCrumbs = vCurrentCookieValue.split("!");
//every third value has item #
 var iX = 0;
 var iMatch = 0;
 while (iX < aCrumbs.length - 1) {
  if (aCrumbs[iX] == vId)
   iMatch = 1;
  iX = iX + 3;
  }
//do not add this new item if there was a match
 if (iMatch != 1) {
  iX = iX + 3;
  vNewCookieValue = vNewCookieValue + vCookieItem;
  alert("Adding " + vQty + " pieces of item #" + vId + " to your shopping cart");
  }
 else {
  alert("item #" + vId + " is already in your shopping cart");
  }
 
//overwrite cookie
 document.cookie = vPageId + "=" + escape (vNewCookieValue) + "; path=/";
 
//since we potentially added an item, update the shopping cart link in top-right corner of page
 ShowShoppingCartTally();
 
 }


function FindCookie(name) {
 var curCookie = document.cookie.split("; ");
 for (var iX=0; iX < curCookie.length; iX++) {
  var aCrumb = curCookie[iX].split("=");
  if (name == aCrumb[0]) 
   return unescape(aCrumb[1]);
  }
 return null;
 }


function BuyItem_Dynamic(vId, vQty) {
 var frmObj = document.getElementById(vId);	//form object: alter appearance
 AddItemToCookie_Dynamic(vId, vQty);
 }


function AddItemToCookie_Dynamic(vId, vQty) {
 
//prepare for case where ctlMaterial DNE
if (document.getElementById("ctlMaterial") != null) {
 //adjust qty to drop to minimum
 varMatObj = document.getElementById("ctlMaterial");
 if (varMatObj.options[varMatObj.selectedIndex].value == "Silicon") {
  if (vQty > 25) {
   vQty = 25;
   }
  }
 else {
  //price break items have "-" in name
  //for non-invsipol items with no pricebreak, minimum = 1
  if (vId.indexOf("-") == -1) {
   vQty = 1;
   }
  }
 }
else {
//ctlMaterial DNE
 if (vQty > 25) {
  vQty=25;
  }
 }
 
 //new info for cookie
 var newCookieItem = vId + "!" + vQty + "!";
 
 //check if item exists in Cookie
 var vCookieValue = FindCookie('shoppingcart');
 
 //overwrite temp shoppingcart cookie with new value if null
 if (vCookieValue == null)
  vCookieValue = "";//  vCookieValue = newCookieItem;
 
 var vNewCookieValue = vCookieValue;
 var aCrumbs = vCookieValue.split("!");
 //every second value has item #
 var iX = 0;
 var iMatch = 0;
 while (iX < aCrumbs.length - 1) {
  if (aCrumbs[iX] == vId)
   iMatch = 1;
  iX = iX + 2;
  }
//do not add this new item if there was a match
 if (iMatch != 1) {
  iX = iX + 2;
  vNewCookieValue = vNewCookieValue + newCookieItem;
  alert("Adding " + vQty + " pieces of item #" + vId + " to your shopping cart");
  }
 else {
  alert("item #" + vId + " is already in your shopping cart");
  }
 
 //overwrite cookie
 document.cookie = "shoppingcart=" + escape (vNewCookieValue) + "; path=/";
 
 //since we potentially added an item, update the shopping cart link in top-right corner of page
 ShowShoppingCartTally();
 
 }

function FindCookie(name) {
 var curCookie = document.cookie.split("; ");
 for (var iX=0; iX < curCookie.length; iX++) {
  var aCrumb = curCookie[iX].split("=");
  if (name == aCrumb[0]) 
   return unescape(aCrumb[1]);
  }
 return null;
 }

function ShowShoppingCartTally() {
 var vCookieValue = FindCookie('shoppingcart');
 if (vCookieValue == null) vCookieValue = "";
 var aCrumbs = vCookieValue.split("!");
 var iTally = (aCrumbs.length - 1) / 2;
 var vText = "Shopping Cart";
 if (iTally > 0)
  vText = vText + "<br/> (" + iTally + " items)";
 document.getElementById('ShoppingCart').innerHTML = vText;
 }

