// Voici les 3 fonctions de gestions des cookies
////////////////////////////////////////////////
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) {
	// un cookie a besoin d'un nom, d'une valeur, d'un nom de domaine, d'une
	// date d'expiration
	// 
	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 MM_jumpMenu(targ, selObj, restore) { // v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value
			+ "'");
	if (restore)
		selObj.selectedIndex = 0;
}

function MM_openBrWindow(theURL, winName, features) { // v2.0
	window.open(theURL, winName, features);
}

function checkAll(theForm, prefix) {
	for (i = 0, n = theForm.elements.length; i < n; i++)
		if (theForm.elements[i].name.indexOf(prefix) != -1)
			theForm.elements[i].checked = true;
}

function unCheckAll(theForm, prefix) {
	for (i = 0, n = theForm.elements.length; i < n; i++)
		if (theForm.elements[i].name.indexOf(prefix) != -1)
			theForm.elements[i].checked = false;
}

$(document)
		.ready(
				function() {
					user_id = GetCookie("user_ident");

					if (!isNaN(user_id) && user_id > 0) {
						user_firstname = GetCookie("user_firstname");
						user_lastname = GetCookie("user_lastname");
						htmlContent = user_firstname + " " + user_lastname + "\n";
						htmlContent += '<a href="out.php"><font size="1">logout</font></a>' + "\n";
						htmlContent += '<a href="index.php?module=user&page=profile">My reports</a>' + "\n";
						htmlContent += '<span id="basket">' + "\n";
						htmlContent += '  <a href="index.php?module=ddd&page=basket">' + "\n";
						htmlContent += '    <img src="images/stockholm_icons/16x16/shopping_cart.gif" alt="Cart">' + "\n";
						htmlContent += '  </a>' + "\n";
						htmlContent += '  <a href="index.php?module=ddd&page=basket">' + "\n";
						htmlContent += '      </a>' + "\n";
						htmlContent += '  </span>' + "\n";
					} else {
						htmlContent = '<form method="post" action="in.php">' + "\n";
						htmlContent += '<label for="username">Email:</label>' + "\n";
						htmlContent += '<input type="text" name="username" id="username" size="8"/>' + "\n";
						htmlContent += '<label for="password">Password:</label>' + "\n";
						htmlContent += '<input type="password" name="password" id="password" size="8"/>' + "\n";
						htmlContent += '<input type="submit" value="Login" name="eventSubmit_doLogin"/>' + "\n";
						htmlContent += '</form>' + "\n";
						htmlContent += '<span id="basket">' + "\n";
						htmlContent += '  <a href="index.php?module=ddd&page=basket">' + "\n";
						htmlContent += '    <img src="images/stockholm_icons/16x16/shopping_cart.gif" alt="Cart">' + "\n";
						htmlContent += '  </a>' + "\n";
						htmlContent += '  <a href="index.php?module=ddd&page=basket">' + "\n";
						htmlContent += '      </a>' + "\n";
						htmlContent += '  </span>' + "\n";
					}
					$("#login").html(htmlContent);
				});