/*
	-------------------------------------------------------------------------
	-------------------------------------------------------------------------
	PARKER/WATERMAN request popin management
	-------------------------------------------------------------------------
	-------------------------------------------------------------------------
 */


// -- local variables
// -------------------------------------------------------------------------
//var lang = 'de'; // current language

var pathname = document.location.pathname.substring(1);
var parts = pathname.split(/\//);
var lang = parts[0];
if(lang == '' || lang=="index.php"){
	// is homepage /
	lang = "en";	
}

var popin_id = 'req_popin'; // popin div id value
var popin_pos_from_bottom = '40px'; // popin position from bottom
var popin_pos_from_right = '5px'; // popin position from right
var bg_picture_path = '/img/survey/survey_' + lang + '.png'; // popin background picture path


var redirect_url_en = "http://croiseur.socio.fr/quest/WP/ROTRING_UK.asp";
var redirect_url_us = "http://croiseur.socio.fr/quest/WP/ROTRING_US.asp";
var redirect_url_de = "http://croiseur.socio.fr/quest/WP/ROTRING_DE.asp";
var redirect_url_tr = "http://croiseur.socio.fr/quest/wp/ROTRING_TK.asp";


var coords_openEn_en = "67,196,21";
var coords_openUs_en = "118,195,21";
var coords_close_en = "236,195,21";

var coords_open_de = "88,202,21";
var coords_close_de = "236,201,21";

var coords_open_tr = coords_open_de;
var coords_close_tr = coords_close_de;



var cookie_name = "rotring_survey"; // cookie name
var ttl_cookie = 96; // 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="#parker_' + lang + '" />';
		popin += '<map name="parker_' + lang + '">';
		
		if(lang == "en"){
			popin += '<area shape="circle" coords="' + coords_openEn_en + '" href="' + redirect_url_en + '" target="_blank" onclick="close_popin(\'' + popin_id + '\')" />';
			popin += '<area shape="circle" coords="' + coords_openUs_en + '" href="' + redirect_url_us + '" target="_blank" onclick="close_popin(\'' + popin_id + '\')" />';
			popin += '<area shape="circle" coords="' + coords_close_en + '" href="javascript:close_popin(\'' + popin_id + '\');" />';
		
		}else if(lang == "de"){
			popin += '<area shape="circle" coords="' + coords_open_de + '" href="' + redirect_url_de + '" target="_blank" onclick="close_popin(\'' + popin_id + '\')" />';
			popin += '<area shape="circle" coords="' + coords_close_de + '" href="javascript:close_popin(\'' + popin_id + '\');" />';
			
		}else if(lang == "tr"){
			popin += '<area shape="circle" coords="' + coords_open_tr + '" href="' + redirect_url_tr + '" target="_blank" onclick="close_popin(\'' + popin_id + '\')" />';
			popin += '<area shape="circle" coords="' + coords_close_tr + '" 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 = 'absolute';
		popin_div.style.bottom = popin_pos_from_bottom;
		popin_div.style.right = popin_pos_from_right;
		popin_div.style.zIndex = '99999999';

		// -- 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 on pop-in close
	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).ready(function() {
	document.body.onLoad = build_popin();	
});
 
 
 

