// *************************************************************
// fonctions interface
// *************************************************************

function showRelatedDiv(idclic,idshow,pos,dx,dy,heritance)
{
		var offset_X = 0 ;
		var offset_Y = 0 ;
		if (dx) offset_X = dx ;
		if (dy) offset_Y = dy ;
		
		switch (pos)
		{
			case "topleft" :
				offset_Y += -$(idshow).getHeight() ;
			break;
			case "bottomright" :
				offset_X += $(idclic).getWidth() ;
				offset_Y += $(idclic).getHeight() - $(idshow).getHeight() ;
			break;
			case "bottomleft" :
				offset_Y += -$(idclic).getHeight() ;
			break;
			case "over" :
			break;
		}
		
		$( idshow ).clonePosition( $( idclic ),
		{
			setLeft:true,
			setTop:true,
			setWidth:false,
			setHeight:false,
			offsetLeft:offset_X,
			offsetTop:offset_Y
		});
		
		if (!heritance) $(idshow).toggle();
		else $(idshow).show();
}


// Onglets

function Onglets() {
	this.settings = new Array();
};

Onglets.prototype.init = function(settings) {
	this.settings = settings;
};

Onglets.prototype.getParam = function(name, default_value) {
	var value = null;

	value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];

	// Fix bool values
	if (value == "true" || value == "false")
		return (value == "true");

	return value;
};

Onglets.prototype.Show = function(tab_id, panel_id) {
	var panelElm = document.getElementById(panel_id);
	var panelContainerElm = panelElm ? panelElm.parentNode : null;
	var tabElm = document.getElementById(tab_id);
	var tabContainerElm = tabElm ? tabElm.parentNode : null;
	var selectionClass = this.getParam('selection_class', 'current');

	if (tabElm && tabContainerElm) {
		var nodes = tabContainerElm.childNodes;

		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "LI")
				nodes[i].className = '';
		}

		tabElm.className = 'current';
	}

	if (panelElm && panelContainerElm) {
		var nodes = panelContainerElm.childNodes;

		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "DIV")
				nodes[i].className = 'panel';
		}

		panelElm.className = 'current';
	}
};

Onglets.prototype.getAnchor = function() {
	var pos, url = document.location.href;

	if ((pos = url.lastIndexOf('#')) != -1)
		return url.substring(pos + 1);

	return "";
};

var Onglets = new Onglets();

function expandDiv(whichEl,etat)
{
	if (etat == null) $(whichEl).toggle();
	else ( etat == "" ? $(whichEl).hide() : $(whichEl).show() ) ;
}

function switchDivs(e1,e2)
{
	$(e1).toggle();
	$(e2).toggle();
}


function openZoomWindow( dest, h, w, n )
{
	var hauteur,largeur ;
	if ( !h )
		hauteur = 510 ;
	else
		hauteur = h ;
	if ( !w )
		largeur = 700 ;
	else
		largeur = w ;
	if ( !n )
		nom = 'fenetre' ;
	else
		nom = n ;
	var _w = window.open( dest, nom, 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+largeur+',height='+hauteur ) ;
	_w.focus() ;	
}

function openVideoWindow( dest, h, w, n )
{
	var hauteur,largeur ;
	if ( !h )
		hauteur = 510 ;
	else
		hauteur = h ;
	if ( !w )
		largeur = 700 ;
	else
		largeur = w ;
	if ( !n )
		nom = 'fenetre' ;
	else
		nom = n ;
	var _w = window.open( dest, nom, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+largeur+',height='+hauteur ) ;
	_w.focus() ;	
}

function closeWindow()
{
      top.close();
}

/* dropdown menus */

// PARAMS

BACKGROUND_CHECKBOX_ON = "url(../images/searchmenu/checkbox_on.gif) 5px 2px no-repeat;"
BACKGROUND_CHECKBOX_OFF = "url(../images/searchmenu/checkbox_off.gif) 5px 2px no-repeat;"
var	global_NbResults = 0 ;

function init_dropdowns()
{
	if ( $( "jobsearch" ) )
	{
		init_dropdown($("countries")) ;
		init_dropdown($("categories")) ;	
		init_dropdown($("contract")) ;
		init_dropdown($("topics")) ;
		init_dropdown($("levels")) ;
		init_dropdown($("domaines")) ;
		$$('a.cb_on').each( function(e) {
			updateCheckBoxFromA(e);
		});
		$$('a.cb_off').each( function(e) {
			updateCheckBoxFromA(e);
		});
		$$('span.expander').each( function(e) {
			e.observe('click', function() { 
				var myLi = this.up() ;
				var myUl = myLi.select('ul').first() ;
				if ( this.hasClassName('expanderopen')	)
				{
					myUl.hide();
					this.removeClassName('expanderopen');
				}
				else
				{
					myUl.show();
					this.addClassName('expanderopen');
					closeExpander(myLi);
				}
			});
		});
		if ($("searchbutton_popup") && !$('ajaxJobList'))
		{
			buildSearchRequest( $( "jobsearchform" ) );
			$("searchbutton_popup").show() ;
		}
	}		
}

function closeExpander(myLi)
{
	myLi.siblings().each(  function(e){
	if ( e.select('span.expander').first().hasClassName('expanderopen') )
	{
//	console.log('yy');
		e.select('ul').first().hide();
		e.select('span.expander').first().removeClassName('expanderopen');							
	}
	});
}

function init_dropdown(thisTab)
{
	if (thisTab)
	{
		var dropMenu = null ;
		thisTab.observe('mouseover', showDropMenu.bindAsEventListener(thisTab) ); 
		thisTab.observe('focus', fixDropMenu.bindAsEventListener(thisTab) ); 
		thisTab.observe('mouseout', hideDropMenu.bindAsEventListener(thisTab) ); 
		var nbchk = getNbChecked(thisTab.id) ;
	}
}

function showDropMenu(e)
{
	this.select('div.uppertab').first().addClassName('uppertab_over') ;
	this.select('div.dropmenu').each( function(d) { d.removeClassName("dropmenuhidden")});
}

function fixDropMenu(e)
{
	hideAllDropMenus();
	this.select('div.uppertab').first().addClassName('uppertab_over') ;
	this.select('div.dropmenu').each( function(d) { d.removeClassName("dropmenuhidden")});
}

function hideDropMenu(e)
{
	this.select('div.uppertab').first().removeClassName('uppertab_over') ;
	this.select('div.dropmenu').each( function(d) { d.addClassName("dropmenuhidden")});
}

function hideAllDropMenus()
{
		$("jobsearch").select("div.droptab").each( function(d) {
		d.select('div.uppertab').first().removeClassName('uppertab_over') ;
		d.select('div.dropmenu').each( function(d) { d.addClassName("dropmenuhidden")});
	});
}

function init_filterregion()
{
	if ( $("filterregion") )
	{
		if ( $("jobfilters") )
		{
			$("filterregion").show();
			showRelatedDiv("jobfilters","filterregion","over",0,-10,true)	;	
		}
	}
}

function init_filtertype2()
{
	if ( $("filtertype2") )
	{
		if ( $("jobfilters") )
		{
			$("filterregion");
			showRelatedDiv("jobfilters","filtertype2","over",300,-10,true)	;	
		}
	}
}

function getChildElementByTag(e,tag)
{
	var childElts = e.getElementsByTagName(tag);		
	if ( childElts.length > 0 ) 
	return  ( childElts[0] ) ;
	else return null;
}

function unclickSingleCheckBox(e)
{
	var myCheckBox = e.select('input').first() ;
	if ( ( myCheckBox ) && ( myCheckBox.checked ) )
	{
		e.select('a').first().className = "cb_off";
		myCheckBox.click();
	}
}

function cleanChecks(id)
{
	$(id).select('li').each( function(element) { unclickSingleCheckBox(element) });
	$(id).hide();
}

function updateCheckFromA(e)
{
	var myLi = e.up() ;
	var myCheck = myLi.select('input').first() ;
	e.className = "cb" + (myCheck.checked ? "_on" : "_off") ;
}

function updateRadio(e)
{
	var ul = e.up("ul") ;
	ul.select('input').each( function(element) {
		element.checked = false ;
	});
	ul.select('a').each( function(element) {
		element.className = "cb_off" ; 
	});
	updateCheck(e) ;
}

function updateCheck(e)
{
	var myLi = e.up() ;
	var myCheck = myLi.select('input').first();
	myCheck.click();
	e.className = "cb" + (myCheck.checked ? "_on" : "_off") ;
}

function updateCheckBoxFromA(e)
{
	var myLi = e.up() ;
	var myCheckBox = myLi.select('input').first() ;
	myCheckBox.checked ? e.className = "cb_on" : e.className = "cb_off";
}

function updateCheckBox(e)
{
	var myLi = e.up() ;
	var myCheckBox = myLi.select('input').first();
	myCheckBox.click();


	if ( myCheckBox.checked )
	{
		e.className = "cb_on";
		if ( myCheckBox.name == 'CONT' ) myLi.select('ul').each( function(element) { element.show() });
	}
	else
	{
		e.className = "cb_off";
		if ( myCheckBox.name == 'CONT' ) myLi.select('ul').each( function(element) { element.hide() });
	}
	
	if ( myCheckBox.name == 'CTNT' )
	{
		myLi.down('ul').select('li').each( function(element) { unclickSingleCheckBox(element) });
	}
	else if ( myCheckBox.name == 'CTRY' )
	{
		var licontinent = myLi.up('li.continent') ;
		if ( licontinent == undefined ) 
		{
			var idtable = myLi.up('table').id;
			var ind = idtable.indexOf("_countries") ;
			var continentName = idtable.substring(0, ind);
			licontinent = $(continentName).up('li.continent'); 
		}
		unclickSingleCheckBox( licontinent ) ;
	}

	if ( myCheckBox.name == 'DOMA' )
	{
		myLi.down('ul').select('li').each( function(element) { unclickSingleCheckBox(element) });
	}
	else if ( myCheckBox.name == 'FAMI' )
	{
		unclickSingleCheckBox( myLi.up('li.domaine') ) ;
		myLi.down('ul').select('li').each( function(element) { unclickSingleCheckBox(element) });
	}
	else if ( myCheckBox.name == 'SFAM' )
	{
		unclickSingleCheckBox( myLi.up('li.famille') ) ;
	}
	
	var nbchk = getNbChecked(getParentDropId(myCheckBox)) ;

	if ( $('CTRY_FR') && $('filterregion') )
	{
		var ctryCondition = $('CTRY_FR' ) ;
		var nbchk = getNbChecked('countries');
		if ( ctryCondition.checked && ( nbchk > 1 ) )
		{
			cleanChecks('filterregion') ;
			if ( $('filtertype2') )
				cleanChecks('filtertype2') ;
			$('jobfilters').toggle() ;
		}
		
		else if ( ctryCondition.checked && $('filtertype2') )
		{
			var dropContract = $('contract_drop' ) ;
			var checkContract = dropContract.getElementsByTagName('input') ;
			var checkLength = checkContract.length ;
			var nbchecked = 0 ; 
			var ischecked = false ;
			for ( var i = 0; i < checkLength; i++ )
			{
				if ( ( checkContract[i].name == 'CONT' ) && ( checkContract[i].checked ) )
				{
					nbchecked ++ ;
					if ( checkContract[i].value == 'STU' ) ischecked = true;
				}	
			}
			if ( !ischecked || ( nbchecked > 1 ) )
				cleanChecks('filtertype2') ;
		}
	}

	var searchButtonPopup = null ;	
	if ($("searchbutton_popup"))
	{
		buildSearchRequest( $( "jobsearchform" ) ) ;
//		wH($("searchbutton_popup"),global_NbResults);
		$("searchbutton_popup").show() ;
	}
}




function getParentDropId(_cb)
{
	var _parentDropMenuId = null ;	
	switch (_cb.name)
	{
		case 'CTRY':
		case 'CTNT':
			_parentDropMenuId = "countries" ;
			break;

		case 'CATG':
			_parentDropMenuId = "categories" ;
			break;

		case 'CONT':
		case 'TYPE2':
		case 'HOUR':
			_parentDropMenuId = "contract" ;
			break;
		case 'TOPIC':
			_parentDropMenuId = "topics" ;
			break;
		case 'LEVEL':
			_parentDropMenuId = "levels" ;
			break;
		case 'DOMA':
		case 'FAMI':
		case 'SFAM':
		case 'EMGR':
			_parentDropMenuId = "domaines" ;
			break;
	}
	return (_parentDropMenuId)
}

function getNbChecked(idrop)
{
	var dm = $(idrop) ;
	var _nbChecked = 0 ;
	if (dm) 
	{
		dm.select('input').each( function(element) {
			if (element.checked ) _nbChecked++ ; 
		});	
		var popup = dm.down('div.float_popup') ;
		if (popup )
		{
			popup.update( _nbChecked ) ;
			( _nbChecked )  > 0 ? popup.show() : popup.hide();
		}
	}
	return _nbChecked ;
}

function openCheckBoxes(e)
{
	var myLi = e.up() ;
	var myOtherCheckboxes =  myLi.select('ul').first();
	var myCheckBox = myLi.select('input').first() ;
	myCheckBox.click();
	if (myOtherCheckboxes) myOtherCheckboxes.toggle() ;
	myCheckBox.checked ? e.className = "cb_on" : e.className = "cb_off";
}

function openTab(idTab)
{
	if ( $("o_"+idTab) && $("p_"+idTab) )
	{
		$("o_"+idTab).show() ;
		Onglets.Show("o_"+idTab,"p_"+idTab) ;
	}
}

function buildSearchRequest(e)
{
  var getstr = "";
  var formFields = e.getElementsByTagName("input");
  for (i=0; i<formFields.length; i++)
  {
		if (formFields[i].type == "text")
		{
			if ( $('searchtextlabel') && ( formFields[i].value == $('searchtextlabel').innerHTML ) )
			{
				getstr += formFields[i].name + "=&";
			}
			else
			{
				getstr += formFields[i].name + "=" + formFields[i].value.toLowerCase() + "&";
			}
		}
		if (formFields[i].type == "checkbox")
		{
		   if (formFields[i].checked) {
			  getstr += formFields[i].name + "=" + formFields[i].value + "&";
		   }
		}
	}
	var url = '/jobs/count.do';
	
	var ajaxRequest = new Ajax.Request(url,{
		method: 'get',
		parameters: getstr,
		onComplete: function(request){
		}.bind(this),
		onSuccess: function(request){
			updateNbJobs(request) ;
		}.bind(this),
		onFailure: function(request){
			noNbJobs();
		}.bind(this),
		onException: function(request,e){
		}.bind(this)
	});
}

function selectList(list) {
	document.getElementById("orangemap").selectCountries(list);
}

// *************************************************************
// fonctions update count jobs / country
// *************************************************************


var isMapinit = false ;

function updateNbJobs(request)
{
	var result = request.responseText;
	var parts = result.split("*");
	$('searchbutton_popup_nb').update(parts[0]);            

	if ( $("orangemap") )
	{
		var countryList = parts[1] ;
		if ( ( countryList != "[]" )  || isMapinit )
		{
			selectList(eval(countryList));
			isMapinit = true;
		}
	}
}

function noNbJobs()
{
	$('searchbutton_popup_nb').update("---");            
}




// *************************************************************
// fonctions appels AJAX basket management
// *************************************************************


function ajaxBasket( url )
{
	new Ajax.Request(url,{
		onSuccess: function(request){
		$('addToBasket').toggle();  
		$('deleteFromBasket').toggle();  
		if ( (window.opener) && (window.opener.updateBasketNumber) )
			window.opener.updateBasketNumber(request.responseText);
		else 
			updateBasketNumber(request.responseText);
		}.bind(this)
	});	
}

function addToBasket( joid )
{
	var urlUpdateBasket = '/jobs/userbasket.do' + "?do=add&id=" + joid ;
	ajaxBasket(urlUpdateBasket);
}

function deleteFromBasket( joid )
{
	var urlUpdateBasket = '/jobs/userbasket.do' + "?do=delete2&id=" + joid ;
	ajaxBasket(urlUpdateBasket);
}

function updateBasketNumber(nb)
{
	if ( $('count_basket') ) 
		$('count_basket').update(nb) ;
}

// *************************************************************
// fonctions appels AJAX maj application
// *************************************************************
 
function storeApplication( jobid )
{
	//var url = "/jobs/userapplications.do?do=store" ;
	var url = "/jobs/storeApplication.do" ;
	new Ajax.Request(url,{
		method: 'get',
		parameters: 'id='+jobid,
		onSuccess: function(request){
		
		}.bind(this)
	});	
}

function openWindowApplication( url , id )
{
	openZoomWindow( url , 600 , 900 , 'applywindow' );
//  decommenter pour avoir la fonction ajax d'enregistrement des candidatures
	storeApplication(id);
}


// *************************************************************
// fonctions orange.com
// *************************************************************


var tgs = new Array( 'span','a','h1','div');

var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );

var startSz = 3;

function ts( trgt,inc )
{
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	cEl.style.fontSize = szs[ sz ];
	for ( i = 0 ; i < tgs.length ; i++ )
	{
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


function sites_redirect(field)
{
	_url = field.options[field.options.selectedIndex].value ;	
	if ( _url.indexOf('http') == 0 )
	{
		 var _w = window.open( _url) ;
		 _w.focus();
	}
	else if ( _url.indexOf('/') == 0 )
	{
		window.location = "http://www.orange.com" + _url ;
	}
	return false;
}


// *************************************************************
// fonctions gestion des formulaires
// *************************************************************

function onWordsFocus(obj, text)
{
	if (obj.value == text) obj.value = '';
	obj.focus = true;
}

function submitSearch(formId, theField, theSortType )
{
	var theform = $(formId)
	theform.elements["do"].value = "search";
	if( theField != null )
		theform.elements["sortField"].value = theField;
	if( theSortType != null )
		theform.elements["sortType"].value = theSortType;
	else
		theform.elements["sortType"].value = "up";
	if ( $("searchtext") && ( $("searchtext").value == $("searchtextlabel").innerHTML ) ) 
		$("searchtext").value = ""	;
	theform.submit();
}

function submitEmailAddress( formId, errormessageemail )
{
	var theform = $(formId)
	theform.elements["do"].value = "email";
	if( checkMail( theform.elements["email"].value, false, errormessageemail ) )
	
		theform.submit();
}

function submitFriendEmailAddress( formId, errormessageemail, errormessagefriendemail , errormessageckoictzig )
{
	var theform = $(formId);

	var dosubmit = false;
	if( theform.elements["ckoictzig"] != null )
	{
		var mescaptcha = errormessageckoictzig ;
		var ajaxRequest = new Ajax.Request("/jobs/jsp/captchaSubmit.jsp",{
			method: 'post',
			parameters: "ckoictzig="+theform.elements["ckoictzig"].value,
			onComplete: function(request){
			}.bind(this),
			onSuccess: function(request){
				var response = request.responseText;

				if ( response=="OK")
				{
//					dosubmit = true;

					if( checkMail( theform.elements["bibi"].value, true, errormessageemail ) )
					{
						if( checkMail( theform.elements["monpote"].value, true, errormessagefriendemail ) )
						theform.submit();
					}
					return;

/*					if( checkMail( theform.elements["bibi"].value, true, errormessageemail ) )
					{
						if( checkMail( theform.elements["monpote"].value, true, errormessagefriendemail ) )
					theform.elements["do"].value = "send"							theform.submit();
					}
					return;
*/				}
				else
				{
					mescaptcha += " (" + theform.elements["ckoictzig"].value + ")";
					alert(mescaptcha);
				}
			}.bind(this),
			onFailure: function(request){
				alert(mescaptcha);
			}.bind(this),
			onException: function(request,e){
				alert(mescaptcha);
			}.bind(this)
		});
	}
	else
		dosubmit = true;

	if( dosubmit )
	{
		if( checkMail( theform.elements["bibi"].value, true, errormessageemail ) )
		{
			if( checkMail( theform.elements["monpote"].value, true, errormessagefriendemail ) )
			theform.submit();
		}
//		return;
	}

}

function submitApply( formId )
{
	var indicator = $("waiting");
	var tobehide = $("tobehide");
	if ( tobehide ) tobehide.hide();
	if ( indicator ) indicator.show();
	if ( formValidate( formId ) )
		$(formId).submit();
	else {
		if ( indicator ) indicator.hide();
		if ( tobehide ) tobehide.show();
	}
}

function reloadOpener()
{
	if ( top.opener )
		top.opener.location.reload() ;
//		top.opener.location.href = top.opener.location.href ;
}

function fillProfile()
{
	var urlprofil = "/jobs/userprofile.do?do=list";
	if ( top && top.opener ){
		top.close();
		top.opener.location = urlprofil;
	}
	else self.location = urlprofil;
}

function init_illustration(max)
{
	if ( $("illustration") )
	{
		$("illustration").src = "../images/illustration/img" + ( Math.floor( Math.random() * max ).toString() ) + ".gif";
	}
}

function init_frame_illustration(max)
{
	if ( $("innerFrameIllustration") )
	{
		$("innerFrameIllustration").addClassName("frameIllustration" + ( Math.floor( Math.random() * max ).toString() ) );
	}
}


function checkMail( text, flag, message )
{
 var mail ;
 if ( typeof text == "string" )
     mail = text ;
 else
     mail = text.value ;
 var lg = mail.length ;
 if ( lg == 0 )
 {
     if ( flag )
     {
         alert( message ) ;
         return false ;
     }
     return true ;
 }
 var reg1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
 if ( reg1.test( mail ) )
     return true ;
 alert( message ) ;
 return false ;
}

function simpleCheckMail( text )
{
	var mail ;
	if ( typeof text == "string" )
    	mail = text ;
	else
    	mail = text.value ;
 
	var reg1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
	if ( reg1.test( mail ) )
    	return true ;
 
	return false ;
}

function init_min_height(id,h)
{
	var min = h + 'px';
	if ( $(id) && ( $(id).getHeight() < h ) )
			$(id).setStyle({height:min});
}

function initField(idfield,message)
{
	if ( $(idfield) )
	{
		var myfield = $(idfield);
		myfield.onblur=function(){changeField(this, message,false )};
		myfield.onfocus=function(){changeField(this, message,true )};
		if ( myfield.id == 'searchtext'  )
		{
			if ( myfield.value == '' ) myfield.value = message ;
		}
	}
}

function changeField(elt,message,isfocus)
{
	if ( isfocus && ( elt.id == 'searchtext' ) )
	{
		if ($('searchbutton_popup_nb')) $('searchbutton_popup_nb').update("--- ");
		hideAllDropMenus();
	}
	if (elt.value == message && isfocus )
	{
		elt.value = '';
	}
	else if (elt.value == '' && !isfocus)
	{
		elt.value = message;
	}
	if ( !isfocus && ( elt.id == 'searchtext' ) && $('searchbutton_popup_nb'))
	{
		buildSearchRequest( $( "jobsearchform" ) ) ;            				
	}
}

function showErrorBubble(idmesssage,idfield,idlabel)
{
	showRelatedDiv(idlabel,idmesssage,"bottomright",2,6,true);
	setErrorClear(idfield,idmesssage);
	return true;
}

function hideErrorBubbles()
{
	$$('messageBubble').each( function(e) { e.hide() });
}

function setErrorClear(idfield,idmessage)
{
	if ( $(idfield) && $(idmessage))
	{
		$(idfield).onfocus= function() {$(idmessage).hide()}	;
	}
}

function submitCreateAlert(formId )
{
	var theform = $(formId)
	var _isError = false;
	
	if( theform.elements["email2"] != null )
	{
		if( !simpleCheckMail( theform.elements["email2"].value ) )
			_isError = showErrorBubble("erreur01","email2","email2") ;
	}
	if ( $("searchtext") && ( $("searchtext").value == $("searchtextlabel").innerHTML ) ) 
		$("searchtext").value = ""	;
	if( !_isError )
	{
		theform.elements["do"].value = "createalerte";
		theform.submit();
	}
}

function submitAlertChangeEmail(formId )
{
	var theform = $(formId)
	var _isError = false;
	
	if( !simpleCheckMail( theform.elements["email"].value ) )
		_isError = showErrorBubble("erreur01","email","email") ;
	if( !_isError )
	{
		theform.elements["do"].value = "change";
		theform.submit();
	}
}

function closePanel(id)
{
	$(id).hide();
}

function general_lines_over(idTop,classSelector,classOver,width,height)
{
	var tb = $(idTop);
	tb.select(classSelector).each( function(e) {
		e.observe('mouseover', function() { 
			this.addClassName(classOver); 
		}); 
		e.observe('mouseout', function() { 
			this.removeClassName(classOver); 
		}); 
		e.observe('click', function() { 
			var _links = this.getElementsByTagName('a');
			if ( _links.length > 0  ) 
				if (width) openZoomWindow(_links[0].href,width,height);	
				else self.location=_links[0].href ;
		}); 
	});
}

function switchLang(oldlang,newlang,home)
{
	var OldLang = "lang=" + oldlang ;
	var NewLang = "lang=" + newlang ;
	var TargetUrl = self.location.href ;
	var LangIndex = TargetUrl.indexOf(OldLang);
	if ( LangIndex > -1 )
	{
		TargetUrl = TargetUrl.replace(OldLang, NewLang);
		
	}
	else
	{
		TargetUrl = home ;
	}
	self.location = TargetUrl ;
}

function expandZone(tobeexpand, label, msgOn, msgOff){
	tobeexpand = $(tobeexpand) ;
	label = $(label) ;
	if( tobeexpand && label ) {
		tobeexpand.toggle();
		var tmp = ( tobeexpand.style.display == "" ) ? msgOff : msgOn ;
		var icone = ( tobeexpand.style.display == "" ) ? "icoMinus" : "icoPlus" ;
		label.innerHTML = "<img src='../images/" + icone + ".gif'>" + tmp ;	
	}	
}

function showRecommandation(url)
{
	openTab('recommandation');
}

function postRecommandation(formName){
	new ajaxPostRequest('recommandation', { "formName": formName, "validate":"true", "requestName": "Recommandation", "template": "recommandation" + "Template" });
}

var ajaxPostRequest = Class.create();
ajaxPostRequest.prototype = {
    initialize: function(container,options){
		this.options = Object.extend({
			method : "post",
			action : "insert",
			indicator: "waiting",
			tobehide : ".tobehide",
			params : "",
			url : "/jobs/ajaxRequest.do"
        },options || {});

		this.formName = false ;
		if ( this.options.formName ) {
			this.formName = this.options.formName ;
			this.options.params += $(this.formName).serialize();
		}
		if ( this.options.validate && !formValidate( this.formName ) ) return ;
		
		this.container = container ? $(container) : false ;

		this.indicator = this.options.indicator ? $(this.options.indicator) : false;
		if ( this.indicator ) this.indicator.show();

 		this.tobehide = this.container ? this.container.down(this.options.tobehide) : false;
 		if ( this.tobehide ) this.tobehide.hide();

		this.template = false ;
		var template = $(this.options.template);
		if ( template ) this.template = template.innerHTML ;
		var template0 = $(this.options.template+"0");
		if ( template0 ) this.template0 = template0.innerHTML ;
		this.templateOK = $(this.options.template+"OK");
		this.templateNOK = $(this.options.template+"NOK");
		var self = this;
		new Ajax.Request(
			this.options.url,
			{
				method:this.options.method,
				parameters: this.options.params + "&requestName=" + this.options.requestName + "&do=" + this.options.action,
				onComplete:function(request){
					self.receive(request);
				}
			}
		);
	},
	receive: function(request){
		var responseText = request.responseText;
		var response = responseText.evalJSON() ;
		var status = response.status ;
		if ( this.template && this.container ) {
		}
		else if ( this.templateOK && status == "OK" ) {
			this.templateOK.show();
		}
		else if ( this.templateNOK && status == "NOK" ) {
			this.templateNOK.innerHTML += " (" + response.errorMsg + ")";
			this.templateNOK.show();
		}
		if ( this.indicator ) this.indicator.hide();
	}
}

function formValidate(formName){
	var valid = new Validation(formName, {onSubmit:false, immediate:true});		
	if ( !valid.validate(formName) ) 
	{
		$$('.validation-advice').each( function(e) {
			var spanicon = '<span class="icon"></span>';
			var inner = e.innerHTML;
			if ( inner && inner.indexOf( spanicon ) == -1 )
				e.innerHTML = '<span class="icon"></span>' + inner;
		});
		return false;
	}
	return true;
}

function googleStatInit(code){
	var ga_url = self.location.href ;
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	document.observe("dom:loaded", function() {
		if (typeof(_gat) == 'object') 
		{
			var pageTracker = _gat._getTracker(code);
			pageTracker._initData();
			pageTracker._trackPageview( ga_url );
		}
	});
}

