window.onload = Init;

function Init() {

	
	var prod_code = "";
	if(document.cookie == ""){
			outMsg = "There are no cookies here";
		}
		else {
			var thisCookie = document.cookie.split("; ");	
			
			for(var i = 0; i<thisCookie.length; i++) {
				if(thisCookie[i].split("=")[0] == "productcode") {
					prod_code = thisCookie[i].split("=")[1];
				}
			}
		}
}

$().ready(function () {
	//$("#catpitch").appendTo( $(".pages_available_text").last());
	$("#catpitch").prependTo( $("#footer").last());
});

if (location.pathname.indexOf("AccountSettings.asp") != -1) {
	$().ready(function () {
	//$("#catpitch").appendTo( $(".pages_available_text").last());
	
	$("input[name='emailsubscriber']").parent().html("<input name='emailsubscriber' value='Y' size='20' maxlength='20' type='checkbox'>&nbsp;");
	$("input[name='emailsubscriber']").parent().parent().children().last().html("<span style='color:green; font-weight:bold;'>(Recommended)</span>  Check here to receive emailed invoices of your transaction as well as download instructions with product keys (if applicable) to your transaction.  You will also receive discount codes for future transactions as well as other information and offers from DirectDeals.  DirectDeals will automatically send you email that is required by law, regardless of your option.  You may change this option at any time after creating your account.");
    });
}

if (location.pathname.indexOf("checkout.asp") != -1) {
	$().ready(function () {
	//$("#catpitch").appendTo( $(".pages_available_text").last());
	
	$("input[name='emailsubscriber']").parent().html("<input class='co-text' name='emailsubscriber' id='v65-onepage-newsletter-checkbox' value='Y' onclick='javascript:var val='N';if(this.checked){val='Y';};getElementById('EmailSubscriberHidden').value=val;' type='checkbox'>&nbsp;<input id='EmailSubscriberHidden' name='EmailSubscriberHidden' value='Y' type='hidden'>");
    });
}

function AddMakeAnOffer() {
$("input[src='/v/vspfiles/templates/Custom_Blue/images/buttons/btn_addtowishlist.gif']").parent().prepend($("<a href='https://www.directdeals.com/Articles.asp?ID=244' target='_blank' id='makeofferbutton'><img src='https://www.directdeals.com/v/vspfiles/assets/images/btn_makeanoffer.gif'></a><br /><br />"));
//setCookie('productcode',global_Current_ProductCode);
//$(".pricecolor").css("border","solid blue 3px");
//setCookie('productname',$(".productnamecolorLARGE").html().toString());
$('#makeofferbutton').bind("click",function SetCookies()
{
var prodcode = global_Current_ProductCode;
setCookie('productcode',prodcode);
//setCookie('price',$(".colors_productprice").children().first().html().split("$")[1]);
setCookie('price',$(".pricecolor").html().split("$")[1].split("<")[0]);
setCookie('productname',$(".productnamecolorLARGE").html().toString());
var quanty = "QTY." + prodcode;
//setCookie('quantity',$("input[name=quanty").val());
//$([name=quanty]).css("border","solid blue 3px");
setCookie('quantity',quanty);
});
}

function AddMakeAnOfferAcademic() {
$("input[src='/v/vspfiles/templates/Custom_Blue/images/buttons/btn_addtowishlist.gif']").parent().html($($("input[src='/v/vspfiles/templates/Custom_Blue/images/buttons/btn_addtowishlist.gif']").parent().html() + "<a href='https://www.directdeals.com/Articles.asp?ID=244' target='_blank' id='makeofferbutton'><img src='https://www.directdeals.com/v/vspfiles/assets/images/btn_makeanoffer.gif'></a>"));
$('#makeofferbutton').bind("click",function SetCookies()
{
var prodcode = global_Current_ProductCode;
setCookie('productcode',prodcode);
//setCookie('price',$(".colors_productprice").children().first().html().split("$")[1]);
setCookie('price',$(".pricecolor").html().split("$")[1].split("<")[0]);
setCookie('productname',$(".productnamecolorLARGE").html().toString());
var quanty = "QTY." + prodcode;
//setCookie('quantity',$("input[name=quanty").val());
//$([name=quanty]).css("border","solid blue 3px");
setCookie('quantity',quanty);
});
}



function setCookie(c_name,value)
{
//var exdate=new Date();
//exdate.setDate(exdate.getDate() + exdays);
//var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
//document.cookie=c_name + "=" + c_value;
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth() + 6);
	document.cookie = c_name + "=" +value + ";path=/;expires=" + expireDate.toGMTString();
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}


