

function setShipping()
{
var cartList = document.getElementById('cart_content');
	if (cartList.hasChildNodes())
	{
	document.paypalForm.shipping.value = '0';
	}
	else
	{
	document.paypalForm.shipping.value = '8.50';
	}
}

function clearValue()
{
	var newValue = "";
	document.paypalForm.enterCoupon.value = newValue;
	document.paypalForm.enterCoupon.onfocus = null;
	document.paypalForm.enterCoupon.style["color"] = "#242424"
}

function setFocus()
{
	document.getElementById('addtocartButton').focus();
}

function CheckSpecialCode (SpecialCode,initialPrice) {
var y = SpecialCode.toUpperCase();
switch (y)
	{
	case 'COMB':
	var discountedPrice = initialPrice;
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (Special Combo)";
	document.paypalForm.os0.value = y + " (Special Combo)";
	document.paypalForm.enterCoupon.value = y;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case '':
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "";
	document.paypalForm.amount.value = initialPrice;
	break;
	
	case 'Invalid Coupon':
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "";
	document.paypalForm.amount.value = initialPrice;
	break;
	
	default:
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "Invalid Coupon";
	document.paypalForm.amount.value = initialPrice;
	document.paypalForm.enterCoupon.onfocus = clearValue;
	setTimeout('document.paypalForm.enterCoupon.value = \'\'', 3000);
	document.paypalForm.enterCoupon.style["color"] = "#FF0000";
	break;	
	}
}


function CheckCouponCode (CouponCode,initialPrice) {
var x = CouponCode.toUpperCase();
switch (x)
	{		
	case '$10OFF':
	var discountedPrice = initialPrice - 10;
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " ($10 off)";
	document.paypalForm.os0.value = x + " ($10% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'MEDI':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'REFA':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'GOOD':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'JENN':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'JACK':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);	
	setFocus();
	//set_cookie ( "code", "JACK" );
	break;
	
	case 'WCHA':
	var discountedPrice = initialPrice - (0.2 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (20% off)";
	document.paypalForm.os0.value = x + " (20% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case 'SA10':
	var discountedPrice = initialPrice - (0.1 * initialPrice);
	document.paypalForm.amount_alert.value = "$" + discountedPrice.toFixed(2) + " (10% off)";
	document.paypalForm.os0.value = x + " (10% off)";
	document.paypalForm.enterCoupon.value = x;
	document.paypalForm.amount.value = discountedPrice.toFixed(2);
	setFocus();
	break;
	
	case '':
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "";
	document.paypalForm.amount.value = initialPrice;
	break;
	
	case 'Invalid Coupon':
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "";
	document.paypalForm.amount.value = initialPrice;
	break;
	
	default:
	document.paypalForm.amount_alert.value = "$" + initialPrice;
	document.paypalForm.os0.value = "none";
	document.paypalForm.enterCoupon.value = "Invalid Coupon";
	document.paypalForm.amount.value = initialPrice;
	document.paypalForm.enterCoupon.onfocus = clearValue;
	setTimeout('document.paypalForm.enterCoupon.value = \'\'', 3000);
	document.paypalForm.enterCoupon.style["color"] = "#FF0000";
	break;

	}
}


// window.onload = getVars;

//function getVars ()
//{
//var coupCode = get_cookie("code");
//document.paypalForm.enterCoupon.value = coupCode;
//}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
