// Wish List Cart Functions
var addToWishListUrl = "https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=16&deploy=1&compid=851077&h=6063adbb0360d9678025";
var catalogue = getTestDriveNum();


function AddItem()
{
	var idItem = readCookie('idItem');
	if(idItem != null && idItem != "")
	{
		eraseCookie('idItem');

		var idCustomer = getCustomerID();
		var url = window.location.href;
		while(url.indexOf("&") != -1)
		{
			url = url.replace("&", "*");
		}
		
		window.location.href = addToWishListUrl + '&idCustomer=' + idCustomer + '&idItem=' + idItem + '&url=' + url;   
		
		window.alert('The item has been added to your WishList.');
	}
}

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,price)
{
	if(confirmLogin() == "")
	{
		createCookie('idItem', idItem, 10);
		window.location.href = 'https://checkout.netsuite.com/s.nl?c='+catalogue+'&sc=17&login=T&reset=T&redirect_count=1&did_javascript_redirect=T';
	}
	else
	{
		var idCustomer = getCustomerID();
		var url = window.location.href;
		while(url.indexOf("&") != -1)
		{
			url = url.replace("&", "*");
		}
		
		window.location.href = addToWishListUrl + '&idCustomer=' + idCustomer + '&idItem=' + idItem + '&url=' + url;   
		
		window.alert('The item has been added to your WishList.');
	}
}

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=/";
}
