function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",10);
}

function AddToWishList(idItem)
{
	if("<%=getCurrentAttribute('customer','email')%>" == "")
	{
		createCookie('idItem', idItem, 10);
		window.location.href = 'https://checkout.netsuite.com/s.nl?c=1058147&sc=1&login=T&reset=T&redirect_count=1&did_javascript_redirect=T';
	}
	else
	{
		var idCustomer = "<%=getCurrentAttribute('customer','internalid')%>";
		var url = window.location.href;
		while(url.indexOf("&") != -1)
		{
			url = url.replace("&", "*");
		}
		
		window.location.href = 'https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=1&deploy=1&compid=1058147&h=5feadfe6c55880f62083&idCustomer=' + idCustomer + '&idItem=' + idItem + '&url=' + url;   
		
		window.alert('The item has been added to your WishList.');
	}
}

function formatStars(rating, isCat) {
	var parts = rating.split(".");
	var whole = parts[0];
	var partial = parts[1];
	for (i=0;i<whole;i++) {
		document.write('<img src="/images/starWhole.gif" alt="Whole Star" valign="middle" border="0">');
	}
	if (partial > 7) {
		document.write('<img src="/images/star.8.gif" alt=".8 Star" valign="middle" border="0">');
	} else if (partial > 5) {
		document.write('<img src="/images/star.6.gif" alt=".6 Star" valign="middle" border="0">');
	} else if (partial == 5) {
		document.write('<img src="/images/star.5.gif" alt=".5 Star" valign="middle" border="0">');
	} else if (partial > 3) {
		document.write('<img src="/images/star.4.gif" alt=".4 Star" valign="middle" border="0">');
	} else if (partial > 1) {
		document.write('<img src="/images/star.2.gif" alt=".2 Star" valign="middle" border="0">');
	}
	if (whole != "5") {
		for (i=whole;i<5;i++) {
			if(partial > 1){ i++; }
				document.write('<img src="/images/starEmpty.gif" alt="Empty Star" valign="middle" border="0">');
		}
	}
	if (isCat == 1) {
		if (rating == '0') {
			document.write('Not yet rated');
		} else {
			document.write(rating + ' of 5');
		}
	}
}
function stockStatus(available) {
	if (available > 0) {
		document.write('<div class="instock">In-stock and ready to ship!</div>');
	} else {
		document.write('<div class="oostock"></div>');
	}
}

function showProductReviewPopup(id) {
	var productId = escape(id);
	var formurl = "https://forms.netsuite.com/app/site/crm/externalcustrecordpage.nl?compid=1058147&formid=2&h=b912ecd4a8f4ab7efb40";
	window.open(formurl + "&productId=" + productId, "productReview", "toolbar=0, status=1, menubar=0, location=0, scrollbars=1, resizable=1,width=600,height=400");
	return false;
}

