var newWin = null;
var WinPanier = null;  

// this function gets the cookie, if it exists
function GetCookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
function WriteCookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
// Pop-up normaux -----------------
function closePopUp()
{
	if (newWin != null)
	{
//alert('NONNULL');
		if(!newWin.closed)
		{
			newWin.close();
//alert('close');
		}
	}
}
function popUp(strURL,strType,strHeight,strWidth) 
{
	closePopUp();
	var strOptions="";
	if (strType=="console") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}
// Pop-up normaux -----------------
function closePanier()
{
	if (WinPanier != null)
	{
		if(!WinPanier.closed)
		{
			WinPanier.close();
		}
	}
}
function popUpPanier (strURL,strType,strHeight,strWidth, messoncook) 
{
	closePanier();

	if ( !  GetCookie ('Id_Com') )
	{
		WriteCookie ( 'Id_Com', '0', '30', '/' );
//		NewWin.location=strURL;
		if ( !  GetCookie ('Id_Com') )
		{
			alert(messnocook);
			closePanier ();
		}
	}
	var strOptions="";
	if (strType=="console") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	WinPanier = window.open(strURL, 'WinPanier', strOptions);
	WinPanier.focus();
}
// --------- Delete commande .........
function delete2 (strURL, messa, messb, titrelivre, all, backurl, TypeDel)
{
// Type del: 0=panier, 1=Commande.
// alert(TypeDel);
	if (all==0) 
	{ 
		var mess='Retirer '+titrelivre+' de la commande ?';
		var mess1=titrelivre+ ' '+messa;
	}
	else 
	{ 
		var mess='Voulez vous vraiment supprimer toute la commande ?';
		var mess1=messb;
	}
	if (confirm (mess))
	{
		popUp(strURL,'fixed',40,300);

		if (TypeDel==0)
		{
			setTimeout("reloadPanier()", 350);
		}
		else if (TypeDel==1)
		{
			window.location=backurl;
//			setTimeout("reloadCommande( backurl' )", 350);
		}
	}
}
function reloadPanier ()
{
	popUpPanier ("commande_panier.php?Code=reload","console",400,650);
	closePopUp();
}
function reloadCommande ( UrlCom )
{
//	window.document.location.reload(true);
	window.location=UrlCom;
	closePopUp();
}

/*
Pour appeler la fonction, il faut utiliser le code suivant :

<head>
<script type="text/javascript" src="pop.js"></script>
</head>
<body>
<a href="ma_fenetre.htm"
onclick="popUp(this.href,'console',400,200);return false;">Lien vers une nouvelle fenêtre</a>
</body> 
*/
