window.onload = function () { 
	setQuantity();
	//var int=self.setInterval("refreshPage()",4000);
	document.getElementById("promoCode").focus();
}

function itemFragment(promoCode, index, name, number, price, quantity, shipping1, shipping2) {
		if (quantity>2  && (promoCode == "fbfs10" || promoCode == "FBFS10")){
			return "&item_name_" +index + "=" + escape(name) + "&item_number_" + index + "=" + number + "&amount_" + index + "=" + price+ "&quantity_" + index + "=" + quantity + "&shipping_" + index + "=" +0;
		}else{
			return "&item_name_" +index + "=" + escape(name) + "&item_number_" + index + "=" + number + "&amount_" + index + "=" + price+ "&quantity_" + index + "=" + quantity + "&shipping_" + index + "=" +shipping1 + "&shipping2_" + index + "=" +shipping2;
		}
	}
	
function paymentURL() {
		var i = 1;
		var items = "";
		if (document.getElementById("item0").value > 0){
			items = items + itemFragment(document.getElementById("promoCode").value, i++, "The Original Kicking Tee Holster", "1001", "30.00", document.getElementById("item0").value, "8", "1");
			}
		/*if (document.getElementById("item1").value > 0){
			items = items + itemFragment(i++, "Kicking Tee - Standard 3 Point", "1011", "20.00", document.getElementById("item1").value, "2", "1");
			}
		if (document.getElementById("item2").value > 0){
			items = items + itemFragment(i++, "Kicking Tee - Platform", "1012", "20.00", document.getElementById("item2").value, "2", "1");
			}
	   */
		//alert (items);
		if(items){
			
			return "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business=craig@lanegainer.com&no_shipping=2&page_style=KickingTeeHolster&cancel_return=http://www.KickingTeeHolster.com&return=http://www.KickingTeeHolster.com" + items;
		}else{
			return "index.html";
		}
	}
function writeSessionCookie (cookieName, cookieValue) {
	  if (testSessionCookie()) {
		document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		return true;
	  }
	  else return false;
	}

function testSessionCookie () {
	  document.cookie ="testSessionCookie=Enabled";
	  if (getCookieValue ("testSessionCookie")=="Enabled")
		return true 
	  else
		return false;
	}
function upDateCookies(){
	writeSessionCookie("item_quantity", document.getElementById("item0").value);
	writeSessionCookie("promo_code", document.getElementById("promoCode").value);
	return true;
	
	}
function refreshPage (){
	if(document.getElementById("item0").value != getCookieValue("item_quantity") || document.getElementById("promoCode").value != getCookieValue("promo_code")){
		if (upDateCookies()){
			window.location.reload();
			
			}
		}
	return true;
	}
function setQuantity(){
	if(getCookieValue("item_quantity")){
		document.getElementById("item0").value = getCookieValue("item_quantity");
		return parseInt(getCookieValue("item_quantity"));
	}else{
		writeSessionCookie("item_quantity",1)
		return 1;
		}
	}
function shippingCost(){
	if(setQuantity()>2 && (getCookieValue("promo_code") == "fbfs10" || getCookieValue("promo_code") == "FBFS10")){
		return 0;
	}else{
		return setQuantity() + 7;
		}
	}
	
function getCookieValue (cookieName) {
	var exp = new RegExp (escape(cookieName) + "=([^;]+)");
	  if (exp.test (document.cookie + ";")) {
		exp.exec (document.cookie + ";");
		return unescape(RegExp.$1);
	  }
		else return false;
	}
					
function printQuote() {
		if(refreshPage()){
			window.print();
		}
	}				