// JavaScript Document
<!--opens and centers new window automatically

<!-- 

var w = 517, h = 365;

if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

var popW = 517, popH = 365;

var leftPos = (w-popW)/2, topPos = (h-popH)/2;
       
function launchWindow(launchURL, cprodotto, name) {
	if( cprodotto != '' )
	{
	
		aggiungiAlCarrello(cprodotto);
	}
	window.open(launchURL,name,'width=517,height=365,top=' + topPos + ',left=' + leftPos + ',screenX=5,screeny=5,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no');
}
function closewindow()
{
	window.close();
}
function closeCarrelloWindow(redirectURL)
{
	var temp=opener.location.host;
	opener.location.replace("http://"+temp+"/"+"spaziani/"+redirectURL);
	window.location.href = redirectURL;
	window.close();
}

var nomeCookie='carrello';
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break; 
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie(name) {
	var exp = new Date();
	FixCookieDate (exp); 
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie (name);
	if (cval != null)
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function aggiungiAlCarrello(oggetto) {

	var thenewdate = new Date ();
	thenewdate.setTime(thenewdate.getTime() + (365 * 24 * 3600 * 1000));
	var valore = "";

	if( GetCookie(nomeCookie) == null )
	{
		valore = oggetto+"_1";

	}
	else
	{
		valore = GetCookie('carrello');
		if( valore != null && valore.indexOf(oggetto) >= 0 )
		{
			alert('Prodotto già presente nel carrello');
			return;
		}
		else
		{
			valore = GetCookie(nomeCookie)+','+oggetto+"_1";

		}
	}

	SetCookie(nomeCookie,valore,thenewdate); 
	//alert('Prodotto aggiunto al carrello');
	//alert('Prodotto aggiunto al Cookie'+GetCookie(nomeCookie));

}

function settaIlCarrello(oggetto) {
	var thenewdate = new Date ();
	thenewdate.setTime(thenewdate.getTime() + (365 * 24 * 3600 * 1000));
	SetCookie(nomeCookie,oggetto,thenewdate); 
}

//-->

<!-- end open window script -->