function fnNoThanksClick(intUpSellNo)
{
	var arrCookieOptions = { path: '/', expires: -2 };
	// set cookie for 1000 days
	jQuery.cookie("Shown_upsell_"+intUpSellNo, "0", arrCookieOptions);
	var arrCookieOptions = { path: '/', expires: 7 };
	// set cookie for 1000 days
	jQuery.cookie("upsell_Nothanks_"+intUpSellNo, "1", arrCookieOptions);
	jQuery('#divUpSells').hide('slow');
	unblockWindow();
}
var flgFound = false;
var totalPrice = 0;
var couponAdded = false;
var flgUpsell_1_added_check = false;
jQuery(document).ready(function(){
  jQuery('b').each(function(i, objEle){
	if(!totalPrice && objEle.innerHTML.match(/Subtotal:/))
	{
		//alert(jQuery(objEle).parents("td").next().children("font:last").children("b").children("font:last").html());
		//totalPrice = jQuery(objEle).parents("td").next().children("font:last").children("b").children("font:last").html().replace(/[^0-9\.]/g,"");
		totalPrice = jQuery(objEle).parents("td").next().children("font:last").children("b").html().replace(/[^0-9\.]/g,"");
		//return;
	}
	//
	//if(objEle.innerHTML.match(/100% off on upsell 1 \[ClenTest123\]/i))
	if(objEle.innerHTML.match(/100% off on upsell 1 \[PGH\-Test123\]/i))
	{
		jQuery(objEle).parents("td").css("height","36px");
		jQuery(objEle).css("height","36px");
		//jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE Clen - A VALUE OF $70</b></span>");
		jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE pGH spend $100+ - A VALUE OF $179</b></span>");
	}
	if(objEle.innerHTML.match(/100% off on upsell 2 \[PGH\-Test122\]/i))
	{
		jQuery(objEle).parents("td").css("height","36px");
		jQuery(objEle).css("height","36px");
		jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE pGH spend $210+ - A VALUE OF $179</b></span>");
	}
  });
  
  var strLocation = ""+window.location+"";
  var totalTax = 0.0;
  var upsell_1_price = 100;
  var upsell_2_price = 210;
  var flgTaxChecked = false;
  var flgTotalChecked = false;
  var flgUpsell_1_processing = false;
  var flgUpsell_2_processing = false;
  var flgUpsell_1_added = false;
  var flgUpsell_2_added = false;
	if(strLocation.match(/one-page-checkout/i))
	{
	  jQuery('#span_Shopping_Cart_UnEditable table').css("width","100%");
	  jQuery('#span_Shopping_Cart_UnEditable td').each(function(i, objEle){
		//
		if(objEle.innerHTML.match(/^100% off on upsell 1 \[PGH\-Test123\]/i))
		{
			jQuery(objEle).css("height","36px");
			//jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE Clen - A VALUE OF $70</b></span>");
			flgUpsell_1_added=true;
			jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE pGH spend $100+ - A VALUE OF $179</b></span>");
		}
		if(objEle.innerHTML.match(/^100% off on upsell 2 \[PGH\-Test122\]/i))
		{
			jQuery(objEle).css("height","36px");
			flgUpsell_2_added=true;
			jQuery(objEle).html("<span style='color:#DE3232;border:1px solid #FF0000;padding:2px 1px 2px 1px;font-size:12px;'><b>Congratulations, you just qualified for a FREE pGH spend $210+ - A VALUE OF $179</b></span>");
		}
	  });
	  totalPrice = parseFloat(totalPrice.replace(/[\$,]/g,""));
	  if(totalPrice <= upsell_1_price && 1!=jQuery.cookie("upsell_Nothanks_1"))
	  {
		  
		var arrCookieOptions = { path: '/', expires: 365 };
		// set cookie for 1000 days
		jQuery.cookie("Shown_upsell_1", "1", arrCookieOptions);
		//show winner window
		
		jQuery('#divUpSells').css('position','absolute');
		jQuery('#divUpSells').css('border','3px solid #FF0000');
		jQuery('#divUpSells').css('z-index','9999');
		jQuery('#divUpSells').css("height",'525px');
		jQuery('#divUpSells').css('width','656px');
		jQuery("#divUpSells").load("/v/vspfiles/templates/buysteroids/upsell_1.html");
		jQuery('#divUpSells').show('slow');
		jQuery('#divUpSells').css("top", ( 10 + jQuery(window).scrollTop() + "px"));
		jQuery('#divUpSells').css("left", (200 +jQuery(window).scrollLeft() + "px"));
		blockWindow();
		//alert("TotalPrice: "+totalPrice);
	  }
	  else if(totalPrice >= upsell_1_price && totalPrice <= upsell_2_price  && 1!=jQuery.cookie("upsell_Nothanks_1"))
	  {
		  
		var arrCookieOptions = { path: '/', expires: 365 };
		// set cookie for 1000 days
		jQuery.cookie("Shown_upsell_2", "1", arrCookieOptions);
		//show winner window
		blockWindow();
		jQuery('#divUpSells').css('height','552px');
		jQuery('#divUpSells').css('width','656px');
		jQuery('#divUpSells').css('z-index','9999');
		jQuery("#divUpSells").load("/v/vspfiles/templates/buysteroids/upsell_2.html");
		jQuery('#divUpSells').css("top", ( 10 + jQuery(window).scrollTop() + "px"));
		jQuery('#divUpSells').css("left", ( 200 +jQuery(window).scrollLeft() + "px"));
		jQuery('#divUpSells').show('slow');
		blockWindow();
	  }
	  	if(1 == jQuery.cookie("Shown_upsell_1") && totalPrice>upsell_1_price)
		{
			blockWindow();
			flgUpsell_1_processing = true;
			jQuery.ajax({
			  //url: '/ShoppingCart.asp?ProductCode=ClenTest123',
			  url: '/ShoppingCart.asp?ProductCode=PGH-Test123',
			  success: function(data) {
					var arrCookieOptions = { path: '/'};
					jQuery.cookie("Upsell1Added", "1", arrCookieOptions);
				  	jQuery('input[name=CouponCode]').css("color","#CCCCCC");
					jQuery('input[name=CouponCode]').val('off100upsell1');
					jQuery.cookie("Shown_upsell_1", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
			  }
			});
			return true;
		}
		if(1 == jQuery.cookie("Shown_upsell_2") && totalPrice>upsell_2_price)
		{
			blockWindow();
			if("1" == jQuery.cookie("Upsell1Added"))
			{
				jQuery("a[href*=RemoveCouponCode]").each(function(k,v){
					jQuery.url.setUrl(v);
					if("off100upsell1" == jQuery.url.param('RemoveCouponCode'))
					{
						flgUpsell_1_added_check = true;
					}
				});
				if(!flgUpsell_1_added_check)
				{
					jQuery('input[name=CouponCode]').val('off100upsell1');
					jQuery.cookie("Shown_upsell_1", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
				}
			}
			flgUpsell_2_processing = true;
			jQuery.ajax({
			  url: '/ShoppingCart.asp?ProductCode=PGH-Test122',
			  success: function(data) {
				  unblockWindow();
				  return false;
					jQuery('input[name=CouponCode]').css("color","#CCCCCC");
					jQuery('input[name=CouponCode]').val('oralup2');
					jQuery.cookie("Shown_upsell_2", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
			  }
			});
			return true;
		}
		if(!(flgUpsell_1_processing || flgUpsell_2_processing))
		{
			if(((totalPrice) < upsell_1_price) || !flgUpsell_1_added)
			{
				jQuery("td").each(function(i, objEle){
					if(objEle.innerHTML.match(/FREE BOTTLE of pGH spend over \$100/))
					{
						if(strInputQtyName = jQuery(objEle).parents("table").parents("td").next().next().find("input").attr("id"))
						{
							document.getElementById('span_Shopping_Cart_UnEditable').style.display='none'; document.getElementById('span_Shopping_Cart_Editable').style.display='';
							document.getElementById(strInputQtyName).value='0';
							var arrCookieOptions = { path: '/'};
							jQuery.cookie("Upsell1Added", "0", arrCookieOptions);
							jQuery(objEle).parents("table").parents("td").next().next().find("input").focus();
							jQuery("form[name=OnePageCheckoutForm]").append('<input type="hidden" name="btnRecalculate.x" value="52" />');
							jQuery("form[name=OnePageCheckoutForm]").append('<input type="hidden" name="btnRecalculate.y" value="9" />');
							jQuery("form[name=OnePageCheckoutForm]").submit();
						}
						//flgTotalChecked = true;
					}
				});
			}
			if(((totalPrice) < upsell_2_price) || !flgUpsell_2_added)
			{
				jQuery("td").each(function(i, objEle){
					if(objEle.innerHTML.match(/FREE BOTTLE of pGH spend over \$210/))
					{
						if(strInputQtyName = jQuery(objEle).parents("table").parents("td").next().next().find("input").attr("id"))
						{
							document.getElementById('span_Shopping_Cart_UnEditable').style.display='none'; document.getElementById('span_Shopping_Cart_Editable').style.display='';
							document.getElementById(strInputQtyName).value='0';
							var arrCookieOptions = { path: '/'};
							jQuery.cookie("Upsell2Added", "0", arrCookieOptions);
							jQuery(objEle).parents("table").parents("td").next().next().find("input").focus();
							jQuery("form[name=OnePageCheckoutForm]").append('<input type="hidden" name="btnRecalculate.x" value="52" />');
							jQuery("form[name=OnePageCheckoutForm]").append('<input type="hidden" name="btnRecalculate.y" value="9" />');
							jQuery("form[name=OnePageCheckoutForm]").submit();
							//flgTotalChecked = true;
						}
					}
				});
			}
		}
	}
	else if(strLocation.match(/ShoppingCart/i))
	{
		jQuery('b').each(function(i, objEle){
			if(objEle.innerHTML.match(/Total:/))
			{
				//alert("Total: "+jQuery(objEle).parents("td").next().next().find("b").html().replace(/[^0-9\.]/g,""));
				totalPrice = jQuery(objEle).parents("td").next().next().find("b").html().replace(/[^0-9\.]/g,"");
				flgTotalChecked = true;
				if(flgTaxChecked)
					return;
			}
			if(objEle.innerHTML.match(/Tax:/))
			{
				//alert("Taxx: "+jQuery(objEle).parents("td").next().next().find("b").html().replace(/[^0-9\.]/g,""));
				totalTax = jQuery(objEle).parents("td").next().next().find("b").html().replace(/[^0-9\.]/g,"");
				flgTaxChecked = true;
				if(flgTotalChecked)
					return;
			}
		  });
		totalPrice = totalPrice - totalTax;
		if(1 == jQuery.cookie("Shown_upsell_1") && totalPrice>upsell_1_price)
		{
			blockWindow();
			flgUpsell_1_processing = true;
			jQuery.ajax({
			  //url: '/ShoppingCart.asp?ProductCode=ClenTest123',
			  url: '/ShoppingCart.asp?ProductCode=PGH-Test123',
			  success: function(data) {
				  var arrCookieOptions = { path: '/'};
					jQuery.cookie("Upsell1Added", "1", arrCookieOptions);
					jQuery('input[name=CouponCode]').val('off100upsell1');
					jQuery.cookie("Shown_upsell_1", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
			  }
			});
			return true;
		}
		if(1 == jQuery.cookie("Shown_upsell_2") && totalPrice>upsell_2_price)
		{
			blockWindow();
			if("1" == jQuery.cookie("Upsell1Added") && (totalPrice > 280))
			{
				jQuery("a[href*=RemoveCouponCode]").each(function(k,v){
					jQuery.url.setUrl(v);
					if("off100upsell1" == jQuery.url.param('RemoveCouponCode'))
					{
						flgUpsell_1_added_check = true;
					}
				});
				if(!flgUpsell_1_added_check)
				{
					jQuery('input[name=CouponCode]').val('off100upsell1');
					jQuery.cookie("Shown_upsell_1", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
				}
			}
			flgUpsell_2_processing = true;
			jQuery.ajax({
			  url: '/ShoppingCart.asp?ProductCode=PGH-Test122',
			  success: function(data) {
					var arrCookieOptions = { path: '/'};
					jQuery.cookie("Upsell2Added", "1", arrCookieOptions);
					jQuery('input[name=CouponCode]').val('oralup2');
					jQuery.cookie("Shown_upsell_2", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
			  }
			});
			return true;
		}
		if(!(flgUpsell_1_processing || flgUpsell_2_processing))
		{
			//"ShoppingCart.asp?RemoveCouponCode=off100upsell1
			if("1" == jQuery.cookie("Upsell1Added") && (totalPrice > 280))
			{
				jQuery("a[href*=RemoveCouponCode]").each(function(k,v){
					jQuery.url.setUrl(v);
					if("off100upsell1" == jQuery.url.param('RemoveCouponCode'))
					{
						flgUpsell_1_added_check = true;
					}
				});
				if(!flgUpsell_1_added_check)
				{
					jQuery('input[name=CouponCode]').val('off100upsell1');
					jQuery.cookie("Shown_upsell_1", "0", arrCookieOptions);
					jQuery('input[name=CouponCode]').focus();
					document.forms['form'].submit();
					return true;
				}
			}
			jQuery("a[href*=RemoveCouponCode]").each(function(k,v){
				jQuery.url.setUrl(v);
				if("off100upsell1" == jQuery.url.param('RemoveCouponCode'))
				{
					flgUpsell_1_added = true;
				}
				if("oralup2" == jQuery.url.param('RemoveCouponCode'))
				{
					flgUpsell_2_added = true;
				}
			});
			if(((totalPrice) <= 100) || !flgUpsell_1_added)
			{
				jQuery("a[href*=ProductCode]").each(function(k,v){
					//alert(v); ClenTest123&CartID=1
					jQuery.url.setUrl(v);
					//if("ClenTest123" == jQuery.url.param('ProductCode'))
					if("PGH-Test123" == jQuery.url.param('ProductCode'))
					{
						blockWindow();
						intCartId=jQuery.url.param('CartID');
						var arrCookieOptions = { path: '/'};
						jQuery.cookie("Upsell1Added", "0", arrCookieOptions);
						window.location = "/ShoppingCart.asp?remove="+intCartId;
						return true;
						//jQuery.ajax({
						  //url: "/ShoppingCart.asp?remove="+intCartId,
						  //success: function(data) {
						//		window.reload(true);
						 // }
						//});
					}
				});
			}
			if(((totalPrice) < 210) || !flgUpsell_2_added)
			{
				jQuery("a[href*=ProductCode]").each(function(k,v){
					//alert(v); ClenTest123&CartID=1
					jQuery.url.setUrl(v);
					if("PGH-Test122" == jQuery.url.param('ProductCode'))
					{
						blockWindow();
						intCartId=jQuery.url.param('CartID');
						var arrCookieOptions = { path: '/'};
						jQuery.cookie("Upsell2Added", "0", arrCookieOptions);
						window.location = "/ShoppingCart.asp?remove="+intCartId;
						return true;
						//jQuery.ajax({
						  //url: "/ShoppingCart.asp?remove="+intCartId,
						  //success: function(data) {
							//window.reload(true);
						  //}
						//});
					}
				});
			}
		}
	}
});
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( jQuery(window).height() - this.height() ) / 2+jQuery(window).scrollTop() + "px");
    this.css("left", ( jQuery(window).width() - this.width() ) / 2+jQuery(window).scrollLeft() + "px");
    return this;
}
function blockWindow()
{
	jQuery("body").css("overflow","hidden");
	jQuery("html").css("overflow","hidden");
	jQuery('<div id="termsAndConditionsOverlay" style="display:none;"><div id="divLoading1" style="text-align:center;"><img src="/v/vspfiles/templates/roidstore/ajax-loader.gif"><br>Please wait...<div></div>').appendTo('body');
	//jQuery('<div id="divLoading" style="text-align:center;background-color:#FFFFFF;"><img src="/v/vspfiles/templates/roidstore/ajax-loader.gif"><br><b>Please wait...</b><div>').appendTo('body');

	jQuery('#termsAndConditionsOverlay').css("position","absolute");
	jQuery('#termsAndConditionsOverlay').css("background-color","#000");
	jQuery('#termsAndConditionsOverlay').css("top",'0px');
	jQuery('#termsAndConditionsOverlay').css("left",'0px');
	jQuery('#termsAndConditionsOverlay').css("height",jQuery("body").height()+'px');
	jQuery('#termsAndConditionsOverlay').css("width",jQuery("body").width()+'px');
	jQuery('#termsAndConditionsOverlay').css("opacity","0.5");
	jQuery('#termsAndConditionsOverlay').css("z-index","999");
	jQuery('#divLoading').css("position","absolute");
	jQuery('#divLoading').center();
	jQuery('#divLoading').css("opacity","1");
	jQuery('#termsAndConditionsOverlay').show();
}
function unblockWindow()
{
	jQuery("body").css("overflow","auto");
	jQuery("html").css("overflow","auto");
	jQuery('#termsAndConditionsOverlay').hide();
	//jQuery('#divLoading').hide();
	document.getElementById("divLoading1").style.display='none';
	jQuery('#divLoading1').hide();
}
