﻿//EDIT THESE:

//path to script folder, images should be in an 'images' subfolder. Include trailing slash:
var ccPath = 'http://www.msf.be/fileadmin/';

//link to visit the current MSF site instead of C:C. Keep href="javascript:ccHideDiv('ccPopupDiv')" to have the pop-up disappear without a page load
var ccVisitMSF = 'Cliquez ici pour continuer vers le site<a style="color:#CC0000;border:none;" href="javascript:ccHideDiv(\'ccPopupDiv\');"> MSF Belgique</a>';
var ccVisitCC = 'Cliquez ici pour consulter le dernier chapitre du projet MSF<a style="color:#CC0000;border:none;" href="http://www.condition-critical.org/fr/"> Etat : Critique</a>, les mots de la guerre dans l’Est de Congo';




function DisplayCCSplash ()
{
	var html = '';
	html +='<div style="width:960px;height:560px;background:#FFF url('+ccPath+'images/bkgd_walltexture.jpg) top left no-repeat;font-family: Arial, Helvetica, sans-serif;font-size: 18px;color: #000000;font-weight: bold;float:none;">';
	html +='<div style="float:left;width:50%;height:100%;margin:0;padding:0;text-align:center;">';
	html +='	<!-- LOGO: CONDITION CRITICAL -->';
	html +='	<a href="http://www.condition-critical.org">';
	html +='	<img src="'+ccPath+'images/logo_cc_fr_350x200.gif" alt="Visit Condition:Critical" style="margin-top:120px;width:350px; height:200px; border:0px;" />';
	html +='	</a>';
	html +='<!-- TEXT: CONDITION:CRITICAL LINK -->';
	html +='<p style="width:320px;outline:0px; text-align:center;margin:0px auto;float:none;">'+ccVisitCC+'</p>';
	html +='</div>';
	html +='<div style="float:left;width:50%;height:100%;margin:0;padding:0;text-align:center;">';
	html +='	<!-- LOGO: MSF INTERNATIONAL -->';
	html +='    <a href="javascript:ccHideDiv(\'ccPopupDiv\');">';
	html +='	<img src="'+ccPath+'images/logo_msf_350x200.gif" alt="Visit MSF Canada" style="margin-top:120px;width:350px; height:200px; border:0px;"  />';
	html +='	</a>';
	html +='<!-- TEXT: MSF XXX WEBSITE LINK -->';
	html +='<p style="width:320px; outline:0px; text-align:center;margin:0px auto;float:none;">'+ccVisitMSF+'</p>';
	html +='</div>';
	html +='</div>';
	
	CenterPopup (html);
}	


function ccCheckCookie()
{
	var ccVisited = getCookie('ccPop');
	if (ccVisited == null || ccVisited == "")
	{
		DisplayCCSplash();
	}
	setCookie('ccPop','visited', 7, "", "", "");
}



function setCookie( 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" : "" );
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function ShowDiv (div_name)
{
	if (document.getElementById(div_name))
	{
		if (document.getElementById(div_name).tagName == 'SPAN')
			document.getElementById(div_name).style.display  = "";	
		else
			document.getElementById(div_name).style.display  = "block";		
	}
}

function ccHideDiv (div_name)
{
	if (document.getElementById(div_name))
	{
		document.getElementById(div_name).style.display  = "none";		
	}
}

function CenterPopup (html)
{
	var tmp ='<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr><td align="center" style="background:transparent url(http://www.msf.be/fileadmin/images/black-70.png) repeat fixed top left;">'+html+'</td></tr></table>';

	//var tmp = '<div style="width:100%;height=100%;">'+html+'</div>';
	var newDiv = document.createElement('div');
	newDiv.setAttribute("id","ccPopupDiv");
	newDiv.style.position = 'absolute';
	newDiv.style.width = '100%';
	newDiv.style.height = '100%';
	//z-index:5;position:absolute;width:100%;height:100%;
	var scrollPos = f_scrollTop();
	if (scrollPos)
		newDiv.style.top = (scrollPos)+'px';//document.getElementById(div_name).style.top = (scrollPos)+'px';
	else
		newDiv.style.top = '0px'; //document.getElementById(div_name).style.top = '0px';
	//document.getElementById(div_name).style.left = '0px';
	newDiv.style.left = '0px';
	//document.getElementById(div_name).innerHTML = tmp;
	newDiv.innerHTML = tmp;
	document.body.appendChild(newDiv);
	//ShowDiv(div_name)		

}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
window.onload = ccCheckCookie;