

var log = function(){};

if(debugMode)
	writeScript("http://api.vuegate.net/combo?debug");

if(document.all){
	/*log = function(a){
		//document.title = String(document.title+" || "+a).substr(75);
	}*/
}
function loadJS(url){
	var e = document.createElement("script");
	e.type="text/javascript";e.src = url;
	document.body.appendChild(e);
}

function ajaxLoad(url){
	log(url);
	 $('.menutSel').removeClass('menutSel');
	 $('#refLm').addClass('menutSel');
	p = location.pathname.substr(1).split('/');
	$('#pSubC').load(url+"?format=txt",{},function(){});
	return false;
}


function writeScript(s){
	document.write('<script src="'+s+'" type="text/javascript"><\/script>');
}

function cancelEvent(a){if(a.stopPropagation){a.stopPropagation();a.preventDefault()}else{if(a.cancelBubble){a.cancelBubble=true;a.returnValue=false}}}
function getCookie(d){var c=document.cookie,g=d+"=",a=c.indexOf("; "+g),f;if(a==-1){if((a=c.indexOf(g))!=0){return null}}else{a+=2}if((f=c.indexOf(";",a))==-1){f=c.length}return unescape(c.substring(a+g.length,f))}
function setCookie(b,d,a,f,c,e){document.cookie=b+"="+escape(d)+((a)?"; expires="+a.toGMTString():"")+((f)?"; path="+f:"")+((c)?"; domain="+c:"")+((e)?"; secure":"")}
function deleteCookie(a,c,b){if(getCookie(a)){document.cookie=a+"="+((c)?"; path="+c:"")+((b)?"; domain="+b:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT"}};

alertBox = alert;


var _odw = document.write;
var _odwln = document.writeln;


function safeWrite(){
	document.write = function(txt){
		var d=this.createElement("div");
		d.innerHTML = txt;
		document.body.appendChild(d);
	}
	document.writeln=function(txt){
		document.write(Array.prototype.join.call(arguments,"")+"\n");
	}
}

//########################################################
var tinyMCEconf = {
	mode : "textareas",
	theme : "advanced",
	verify_html : true,
	convert_urls : false,
	theme_advanced_buttons2 : "pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	content_css : ROOT_URL+"css/style.css",
	editor_selector : "mceEditor",
	editor_deselector : "mceNoEditor",
	oninit : "tinyMCEOnload"
};

var tinyMCEOnload = function(){log("tinyMCE loaded.");};

//########################################################
//########################################################

var site = {
su:0,

init:function(){
	var e,i,s,p,ma;
	$('#entreprise').slideshow(slideshow_param);

	this.url_parts = p = location.pathname.substr(1).split('/');

	ma = p[0]+"/"+p[1];
	this.su = parseInt(getCookie("adminLogged"));
	if(this.su){
		writeScript("/js/tiny_mce/tiny_mce.js");
		writeScript("/js/codepress/codepress.js");
	}
	this.initSearch();
	if(p[1]!=('profil_modif' && 'bdd_jlo_inscription_fin')){
		this.init_espaceEmploi();
	}
	if(ma=="quisommesnous/equipe-organigramme"){
		this.onload_organigramme();
	}
	if(ma+'/'+p[2]=="expertises/diversite/Diversite-Negociations"){
		this.onload_Negociations();
	}

	if(typeof this["onload_"+p[0]] == "function")
			this["onload_"+p[0]]();

	if(p[0]=='emploi'){
		if(p[1]=='offre'){
				if(p[2]==undefined){
					p[2]='public';
				}
				this.offreType=p[2];
				window.onload=this.onload_offre;
		}
		else{
			 window.onload = this.onload_emploi;
		}
	}

	if(window.staticContentData){
	   this.initStaticContent(staticContentData);
	}

	try{
		if(document.execCommand){
			document.execCommand('BackgroundImageCache', false, true);
		}
	}catch(e) {}

	this.menuLoad();
	var imgs = ["/img/grislh.gif","/img/grisrh.gif","/img/grisch.gif"];
	for(i=imgs.length-1;i>=0;i--){
		(new Image).src =  imgs[i];
	}
},

onload_offre:function(){
	$('#region,#secteur').change(
		function(){
			var post={
				region:$('#region').val(),
				secteur:$('#secteur').val()
				//,titre:$('#titre').val()
			};
			$.post('/emploi/ajaxRefresh/'+site.offreType,post,function(data){
				data = eval('('+data+')');

				$('#nbOffres').html(data.nb);
				//$('#secteur').html(data.secteur);
				$('#titre').html(data.intitule.res);
				$('#nbIntitule').html(data.intitule.i);

			});
		}
	);
	//$('#region').change();
},
onload_emploi:function(){
	$.datepicker.regional['fr'] = {
		closeText: 			'Fermer',
		prevText: 			'&#x3c;Préc',
		nextText: 			'Suiv&#x3e;',
		currentText: 		'Courant',
		monthNames: 		['Janvier','Février','Mars','Avril','Mai','Juin',
							'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: 	['Jan','Fév','Mar','Avr','Mai','Jun',
							'Jul','Aoû','Sep','Oct','Nov','Déc'],
		dayNames: 			['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: 		['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: 		['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dateFormat: 		'dd/mm/yy', firstDay: 1,
		isRTL: 				false,
		showButtonPanel: 	false
	};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
	/*
	$(".dateTime").datepicker({
			changeMonth: true,
			changeYear: true,
			minDate: '-70Y', maxDate: '-3Y'
	});
	*/

},

onload_contact:function(){
	log("contact");
	$("form#contact").bind("submit",function(){
			if(!($("*[name=civilite]").val() && $("*[name=nom]").val() &&
				$("*[name=message]").val())	&& $("*[name=email]").val()){
				alert("Veuillez remplir correctement le formulaire.");

				return false;
			}
		});
},
get:function(e){
	return document.getElementById(e);
},


searchContentText:"Rechercher",
initSearch:function(){
	var e,i,s;
	s = document.getElementById("search");
	this.elInputSearch = e = s.getElementsByTagName("input")[0];
	e.onfocus = this.onfocusMainSearchField;
	e.value = this.searchContentText;
	document.getElementById('mainSearch').onsubmit = function(){
			if(e.value=='' || e.value=='Rechercher'){
				e.value='';
				document.getElementById('searchAlert').innerHTML='<p class="alerts">saisissez un ou plusieurs mot-clés</p>';
				e.focus();
				return false;
			}
	}
},

onfocusMainSearchField:function(){
	var e,i,s;
	if(this.value == site.searchContentText){
		this.value='';
	}
},
init_espaceEmploi:function(){
	var e,ee,i,s;
	this.elFormee = ee = document.getElementById("espaceEmploi");
	if(ee!=null){
	this.eleeFields = ee.getElementsByTagName("input");
	ee.onsubmit = this.onsubmit_espaceEmploi;
	}
},

onsubmit_espaceEmploi:function(ev){
	var f = site.eleeFields;
	ev = ev || window.event;
	if(f[0].value == "" ||
		f[1].value == ""
		){
		alertBox("Veuillez remplir les champs Identifiant et Mot de passe.");
		cancelEvent(ev);
		return false;
	}else{
		return true;
	}
},

init_organigramme:function(){
	//window.onload = this.onload_organigramme;
	//writeScript("/js/libscroll.js");
},

onload_organigramme:function(){
	$('.equipe').hide();
	$('#notreEquipe h3[class=noClickAction]').css(
			{
				fontSize:		'1.1em',
				marginTop:		'0',
				paddingBottom:	'5px'
			});

	$('#notreEquipe h3[class!=noClickAction]').css(
			{
				fontSize:		'1.1em',
				borderBottom:	'1px solid #ddd',
				cursor:			'pointer',
				marginTop:		'0',
				paddingBottom:	'10px'
				,
				background:		'url(/img/fleche_bas.gif) no-repeat right'
			}
		).click(
			function(){
				$('#notreEquipe h3[class!=noClickAction]').css({borderBottom:	'1px solid #ddd'});
				$('.equipe').hide();
				$(this).css({borderBottom:	'none'}).attr('id','jumpTo').next().toggle(1000);
				//$.scrollTo( '#jumpTo', 800);
				$(this).removeAttr('id');
			}
		).hover(
			function(){
				$(this).css('color','#5c0e5b');
			},
			function(){
				$(this).css('color','#000');
			}
		);

	$("#dialog").dialog(
		{
			autoOpen: false,
			resizable: false,
			width:880,
			height:300,
			modal: true,
			close: function() {},
			show: 'slide'
		}
	);
	$('#dialLink').click(function(){
		$("#dialog").dialog('open');
		return false;
	});
},

onload_Negociations:function(){

    $(".dialHide").hide();

  	$('.dialLink').click(function(){
  	  $('#staticContent').append('<div id="dialogue"></div>');
  	  $("#dialogue").dialog(
        {
    			autoOpen: false,
    			resizable: false,
    			width:800,
    			modal: true,
    			close: function() {},
    			show: 'slide'
    		}
      );
  	  var id = this.id.replace('link_','');
  	  $("#dialogue").html($("#"+id).html());
  	  $("#dialogue").dialog('open');

  		return false;
  	});
},
initStaticContent:function(d){
	//popup
	$('.popinLink').click(function(){
		if(!document.getElementById('dialogue')){
			$('#staticContent').append('<div id="dialogue"></div>');
			$("#dialogue").dialog(
				{
						autoOpen: false,
						resizable: false,
						width:800,
						modal: true,
						close: function() {},
						show: 'slide'
					}
			 );
		}
		var id=	'#'+this.id+'_pc';
		 $("#dialogue").html($(id).html());
		 $("#dialogue").dialog('open');
		return false;
	});

	var e,i,s,id,that = this;
	var sc = this.elStaticContent = document.getElementById("staticContent");
	if(d[0][0]=="expertises"){
		var top		=$('#scrollable').offset().top;
		var besoin = $('h2:eq(0)').offset().top;
		var reponse= $('h2:eq(1)').offset().top;
		var livrable=$('h2:eq(2)').offset().top;

		//$('#menuIntern a:eq(0)').addClass('selected');
		$('#menuIntern a:eq(0)').click(
			function(){
				$('#scrollable').animate({top:-(besoin-top)},{duration:500});
				$('#menuIntern a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}
		);
		$('#menuIntern a:eq(1)').click(
			function(){
				$('#scrollable').animate({top:-(reponse-top)},{duration:500});
				$('#menuIntern a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}
		);
		$('#menuIntern a:eq(2)').click(
			function(){
				$('#scrollable').animate({top:-(livrable-top)},{duration:500});
				$('#menuIntern a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}
		);
		$('.toppage').click(
			function(){
				$('#scrollable').animate({top:0},{duration:500});
				$('#menuIntern a').removeClass('selected');
				//return false;
			}
		);
	}
	d = window.staticContentData;
	if(!this.su)
		return;
	id = d[1];
	this.elContEditBtn = e = document.createElement("div");
	s = e.style;
	s.position="fixed";
	s.cursor="pointer";
	s._cursor="hand";
	s.left = s.top = 0;
	e.innerHTML = '<span style="display:block;float:left;width:20px;height:20px;background:transparent url('+ROOT_URL+
	'js/tiny_mce/themes/advanced/img/icons.gif) no-repeat scroll 20px 20px;background-position:-260px 0;"></span>'+
	'<img src="'+ROOT_URL +'img/edit.png"/>';
	document.body.appendChild(e);
	this.elStaticContent.ondblclick =
	e.onclick = function(ev){
			that.editStaticContent(id,ev||window.event);
		};
},

initSmoothScroll:function(){
	  writeScript(ROOT_URL+"js/libscroll.js");
	  //Bug pour la dialog ????
		writeScript(ROOT_URL+"js/jquery-ui.js");
},

editStaticContent:function(id,ev){
	var e,i,s,tg;
	ev = ev || window.event;
	tg = ev.target || ev.srcElement;
	this.createEditInPlace(tg.tagName.toLowerCase()=="span");
},

createEditInPlace:function(html){
	var e,i,s,that=this;
	if(this.elEditInPlace){
		return;
	}
	this.h = this.elStaticContent.offsetHeight;
	this.elContEditBtn.style.display="none";
	this.elEditInPlace = e = document.createElement("div");
	e.id = "editInPlace";
	e.innerHTML='<form method="post" action="'+ROOT_URL+'/admin/static.php?method=editStaticPage&rd=/'+
	window.staticContentData[0][0]+'/'+window.staticContentData[0][1]+'/'+window.staticContentData[0][2]+
	'"><input type="hidden" name="cat" value="'+window.staticContentData[0][0]+'"/>\
	<input type="hidden" name="subCat" value="'+window.staticContentData[0][1]+'"/>\
	<input type="hidden" name="page" value="'+window.staticContentData[0][2]+'"/>\
	<input type="hidden" name="id" value="'+window.staticContentData[1]+'"/>\
	<input type="text" name="titre" size="60" value="'+document.title+'"/><br/>\
	<textarea cols="80" rows="40" id="staticContentEdit" name="contenu" class="mceEditor codepress html linen_umbers-off"></textarea>\
	<div><input type="submit" value="Valider"/>\
		<input type="button" value="Annuler" id="editCancel"/>\
	</div>\
	</form>';
	this.elStaticContent.parentNode.insertBefore(e,this.elStaticContent);
	this.elta = e.getElementsByTagName("textarea")[0];
	this.elta.value = window.staticContentData[2];
	this.elta.style.height = this.h+"px";
	this.elStaticContent.style.display="none";
	this.elEditCancel = document.getElementById("editCancel");
	this.elEditCancel.onclick = function(){
			that.elStaticContent.style.display="";
			that.elEditInPlace.style.display="none";
			location.reload();
		}
	if(html){
		CodePress.run();
	}else{
		tinyMCE.init(tinyMCEconf);
	}
},

menuLoad:function(){
		$('#menuPrincipal>a,#menuPrincipal>.mpr,#menuPrincipal>.mpl').hover(function(){
				var r,c = $(this).attr('class');
				c=c.substr(2,1);
				var r='no-repeat';

				if(c=='e'){
					this.previousSibling.style.background='transparent url(/img/grislh.gif) no-repeat scroll right top';
					this.nextSibling.style.background='transparent url(/img/grisrh.gif) no-repeat right top';
					c='c';
					r='repeat-x';
				}
				if(c=='l'){
					this.nextSibling.style.background='transparent url(/img/grisch.gif) repeat-x scroll right top';
					this.nextSibling.nextSibling.style.background='transparent url(/img/grisrh.gif) no-repeat right top';
				}
				if(c=='r'){
					this.previousSibling.style.background='transparent url(/img/grisch.gif) repeat-x scroll right top';
					this.previousSibling.previousSibling.style.background='transparent url(/img/grislh.gif) no-repeat right top';
				}

				this.style.background='transparent url(/img/gris'+c+'h.gif) '+r+' right top';
		},
		function(){
				var r,c = $(this).attr('class');
				c=c.substr(2,1);
				var r='no-repeat';

				if(c=='e'){
					this.previousSibling.style.background='transparent url(/img/grisl.gif) no-repeat right top';
					this.nextSibling.style.background='transparent url(/img/grisr.gif) no-repeat right top';
					c='c';
					r='repeat-x';
				}
				if(c=='l'){
					this.nextSibling.style.background='transparent url(/img/grisc.gif) repeat-x right top';
					this.nextSibling.nextSibling.style.background='transparent url(/img/grisr.gif) no-repeat right top';
				}
				if(c=='r'){
					this.previousSibling.style.background='transparent url(/img/grisc.gif) repeat-x right top';
					this.previousSibling.previousSibling.style.background='transparent url(/img/grisl.gif) no-repeat right top';
				}

				this.style.background='transparent url(/img/gris'+c+'.gif) '+r+' right top';
		}
	);

}

};



site.init();
