/*
-------------------------------------------------------------------------
-------------------------------------------------------------------------
PARKER/WATERMAN request popin management
-------------------------------------------------------------------------
-------------------------------------------------------------------------
 */

//-- local variables
//-------------------------------------------------------------------------
var lang = 'de'; // current language
var popin_id = 'req_popin'; // popin div id value
var popin_pos_from_top = '180px'; // popin position from bottom
var popin_pos_from_right = '150px'; // popin position from right
var bg_picture_path = '/popin/waterman_' + lang + '.jpg'; // popin background
// picture path
var redirect_url_1 = "http://croiseur.socio.fr/quest/WP/WP_DE.asp?mrq=2"; // first
// possible
// redirect
// url

var cookie_name = "checkseen"; // cookie name
var ttl_cookie = 24*30; // time to live for the cookie (in hours)

// -------------------------------------------------------------------------
// -- build the request popin
// -------------------------------------------------------------------------
function build_popin() {
	if (getCookie(cookie_name) != "1") {
		// -- create popin content
		var popin = '<img src="' + bg_picture_path
				+ '" border="0" usemap="#waterman_' + lang + '" />';
		popin += '<map name="waterman_' + lang + '">';
		popin += '<area shape="rect" coords="73,166,107,201" href="' + redirect_url_1 + '" target="_blank" />';
		popin += '<area shape="rect" coords="176,167,211,201" href="javascript:close_popin(\'' + popin_id + '\');" />';
		popin += '</map>';

		// -- create div
		var popin_div = document.createElement("div");
		popin_div.id = popin_id;
		popin_div.style.position = 'fixed';
		popin_div.style.top = popin_pos_from_top;
		popin_div.style.right = popin_pos_from_right;
		popin_div.style.zIndex = '100';

		// -- fill with popin content
		popin_div.innerHTML = popin;

		// -- add popin div to the stage
		document.body.appendChild(popin_div);
	}
}

// -------------------------------------------------------------------------
// -- close (hide) the request popin
// -------------------------------------------------------------------------
function close_popin(id) {
	if (document.getElementById) {
		document.getElementById(id).style.visibility = 'hidden';
	} else if (document.all) {
		document.all[id].style.visibility = 'hidden';
	} else if (document.layers) {
		document.layers[id].visibility = 'hide';
	}

	// -- set cookie
	setCookie(cookie_name, "1", ttl_cookie);
}

// -------------------------------------------------------------------------
// -- write a Cookie to store some datas
// -------------------------------------------------------------------------
// -- cookie_name: the cookie name
// -- cookie_value: the data(s) you want to store in
// -- duration: TTL in hours
// -------------------------------------------------------------------------
function setCookie(cookie_name, cookie_value, duration) {
	var expiration_date = "";

	if (duration != null) {
		expiration_date = new Date((new Date()).getTime() + duration * 3600000);
		expiration_date = "; expires=" + expiration_date.toGMTString();
	}

	document.cookie = cookie_name + "=" + escape(cookie_value)
			+ expiration_date + ";path=/;";
}

// -------------------------------------------------------------------------
// -- open and read a Cookie to get its data(s)
// -------------------------------------------------------------------------
// -- cookie_name: the cookie name
// -------------------------------------------------------------------------
function getCookie(cookie_name) {
	var cookie_value = "";
	var cookie_search = cookie_name + "=";

	if (document.cookie.length > 0) {
		var offset = document.cookie.indexOf(cookie_search);

		if (offset != -1) {
			offset += cookie_search.length;

			var end = document.cookie.indexOf(";", offset);

			if (end == -1)
				end = document.cookie.length;

			cookie_value = unescape(document.cookie.substring(offset, end));
		}
	}
	return cookie_value;
}

// -------------------------------------------------------------------------
// -- create popin on body load
// -------------------------------------------------------------------------
document.body.onLoad = build_popin();

