// CEFI 2009 JavaScript Document

function w3cDebug(el) {
	
	if(el == 1) {
		var embedflash = '<EMBED '
		+' SRC="flash/cefi-header.swf" ' 
		+ 'WIDTH="920" HEIGHT="319" PLAY="true" LOOP="false" QUALITY="high" WMODE="transparent" MENU="false" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' 
		+ '</EMBED>' 
		document.write(embedflash);
	} else {
		var embedflash = '<EMBED '
		+' SRC="flash/cefi-header-bis.swf" ' 
		+ 'WIDTH="920" HEIGHT="319" PLAY="true" LOOP="false" QUALITY="high" WMODE="transparent" MENU="false" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' 
		+ '</EMBED>' 
		document.write(embedflash);
	
	}


i1 = new Image();
i1.src = "img/aj_loading.gif";

i2 = new Image();
i2.src = "img/popbar.png";

i3 = new Image();
i3.src = "img/pdfDl2.png";

i4 = new Image();
i4.src = "img/btn_popclose.png";

i4 = new Image();
i4.src = "img/bgFader.png";

}

// FALSEPOPUP -  DEFINITE HEIGHT MIDDLE

/* SCROLL BAR */

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
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;
}



var collapsePrevious = "";

function collapse(el)
{
	
	if(collapsePrevious != "") $('#'+collapsePrevious).slideUp("fast");
	
	src = document.getElementById(el);

	if(src.style.display == 'block')
		$('#'+el).slideUp("normal");
	else
		$('#'+el).slideDown("normal");
		
	collapsePrevious = el;
}

function openWindowPop(el,url_content)
{
	
	src = document.getElementById(el);
	//alert(document.getElementById('popAjaxFader'));
	if(src.style.display == 'block') {
		
		//document.getElementById('popAjaxFader').style.display = 'none'; // bgFader
		$('#'+el).slideUp("normal");

		
	} else {
		//document.getElementById('popAjaxFader').style.display = 'block'; // bgFader
		document.getElementById(el).style.top = (f_clientHeight() / 2) - (-f_scrollTop())+ 'px';
		$('#'+el).slideDown("normal");
		
		$.ajax({
		type: "GET",
	    url: url_content,
	    error:function(msg){
		alert( "error AJX : " + msg );
	    },
	   	success:function(data){
		// container
		alert(data);
		$('#aj_pop_container').html(data);
		}});
		
	}
}



function openAjax(el,url_content,var_top) {
	
	//alert(el+','+url_content+','+var_top);
	//var setWidthDebug = var_width - (-22);
	
	if((!url_content) && (!var_top)) {
		
		$('#'+el).slideUp("fast");
		document.getElementById('aj_pop_fader').style.display = 'none'; // bgFader
		//document.getElementById('aj_pop_loader').style.display = 'block'; // pop_loader
		
	} else {
		
	document.getElementById(el).style.top = (f_clientHeight() / 2) + f_scrollTop() - var_top + 'px';
	
	
	$('#'+el+'_container').html('<div id="aj_pop_bar"></div><br /><br /><img src="img/aj_loading.gif" border="0" alt="loading" /><br /><br /><br />');
	document.getElementById('aj_pop_fader').style.display = 'block'; // bgFader
	
	
	$('#'+el).ajaxStart(function(){ $('#'+el).slideDown("normal"); });
	
	$.ajax({
		type: "GET",
	    url: url_content,
		dataType:"html",
	    error:function(msg){
	    },

	   	success:function(data){
		//alert(data);
		//document.getElementById('aj_pop_loader').style.display = 'none'; // pop_loader
		$('#'+el+'_container').html(data);
		
	}});
	
	}
	//document.getElementById(ele).style.width = setWidthDebug + 'px';

	
}


function openPop(el,var_top) {
	
	//alert(ele+','+urlfile+','+var_top+','+var_width);
	//var setWidthDebug = var_width - (-22);
	
	if(!var_top) {
		
		$('#'+el).slideUp("fast");
		document.getElementById('aj_pop_fader').style.display = 'none'; // bgFader
		
	} else {
		
	document.getElementById(el).style.top = (f_clientHeight() / 2) + f_scrollTop() - var_top + 'px';
	$('#'+el).slideDown("normal");
	document.getElementById('aj_pop_fader').style.display = 'block'; // bgFader
	
	}
	
}


function onSubmit() {

	if(document.getElementById('dpt').value == 'undefined') {
		
		alert("Vous n\'avez pas séléctionné de département.");
		return false;
		
	} else {
		return true;
	}
};


function open_cqp() {

	if(document.forms['searchform'].elements['q'].checked == true)
		document.getElementById('search_cqp').style.display = 'block';
	else
		document.getElementById('search_cqp').style.display = 'none';

};


function checkForm(){

	erreur 		= 0;
	msgError	= 'Des erreurs ont été détéctées dans la saisie des informations:\n\n';
	emailOK 	= false;
	src			= document.forms["contactForm"];
	
	a = src.elements["id_email"].value;
	for (var j=1 ; j<(a.length) ; j++) {

  	if (a.charAt(j)=='@') {
		if (j<(a.length-4)){
			for (var k=j ; k<(a.length-2) ; k++) {
     			if (a.charAt(k)=='.') emailOK = true;

			}
		}
	}
	}
	
	if((src.elements["id_name"].value == '') || (src.elements["id_name"].value == ' ') || (src.elements["id_name"].value == 'votre nom'))
	{
		erreur=1;
		msgError = msgError+"La saisie de votre nom est manquante.\n";
	}
	
	if (emailOK == false) { 
		erreur=1; 
		msgError = msgError+"La syntaxe de votre adresse email est erronée.\n";
	}
	
	
	if((src.elements["id_content"].value == '') || (src.elements["id_content"].value == ' ') || (src.elements["id_content"].value == 'votre message'))
	{
		erreur=1;
		msgError = msgError+"Vous n'avez pas saisi votre message.\n";
	}
	
	if(erreur == 1) {
		alert(msgError);
		return false;
	} else {
		src.security.value = "sendOK";
		src.submit()
		return true;
	}
}

