
var undefined;
var isIExplorer = false;
var ingeniousUrl="http://formation.ingenious.fr/";
var templatePath="http://formation.ingenious.fr/";
var currentPanelEmoticon = null;

function onload_event(){
	protect_web();
	
			var idObj = document.getElementById("altContent");
			if(idObj!=null){
				var flashvars = false;
				var attributes = {};
				var params = {scale: "exactFit",menu: "false",wmode: "transparent",base: "http://www.ingenious.fr/private/bandeaux/"};
				swfobject.embedSWF("http://www.ingenious.fr/private/bandeaux/b1.jpg", "altContent", "100%", "200px", "9.0.0", "http://www.ingenious.fr/private/bandeaux/b1.jpg",flashvars,params,attributes);
			}
		
get_login_panel();



}

var Konami=function(){var a={addEvent:function(e,c,b,d){if(e.addEventListener){e.addEventListener(c,b,false)}else{if(e.attachEvent){e["e"+c+b]=b;e[c+b]=function(){e["e"+c+b](window.event,d)};e.attachEvent("on"+c,e[c+b])}}},input:"",pattern:"3838404037393739666513",load:function(b){this.addEvent(document,"keydown",function(d,c){if(c){a=c}a.input+=d?d.keyCode:event.keyCode;if(a.input.indexOf(a.pattern)!=-1){a.code(b);a.input="";return}},this);this.iphone.load(b)},code:function(b){window.location=b},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:false,capture:false,keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(b){window.location=b},load:function(b){a.addEvent(document,"touchmove",function(c){if(c.touches.length==1&&a.iphone.capture==true){var d=c.touches[0];a.iphone.stop_x=d.pageX;a.iphone.stop_y=d.pageY;a.iphone.tap=false;a.iphone.capture=false;a.iphone.check_direction()}});a.addEvent(document,"touchend",function(c){if(a.iphone.tap==true){a.iphone.check_direction()}},false);a.addEvent(document,"touchstart",function(c){a.iphone.start_x=c.changedTouches[0].pageX;a.iphone.start_y=c.changedTouches[0].pageY;a.iphone.tap=true;a.iphone.capture=true})},check_direction:function(){x_magnitude=Math.abs(this.start_x-this.stop_x);y_magnitude=Math.abs(this.start_y-this.stop_y);x=((this.start_x-this.stop_x)<0)?"RIGHT":"LEFT";y=((this.start_y-this.stop_y)<0)?"DOWN":"UP";result=(x_magnitude>y_magnitude)?x:y;result=(this.tap==true)?"TAP":result;if(result==this.keys[0]){this.keys=this.keys.slice(1,this.keys.length)}if(this.keys.length==0){this.code(this.link)}}}};return a};

// function de premiere protection sur la page
function protect_web(){
	document.onmousedown = new Function("return selectRight()");
	if(isIExplorer){firefox_popup();}
  document.oncontextmenu = new Function("return selectRight();");
}

// Sert a inclure un fichier js
function includeJS(url){
  var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = url;

	var head = document.getElementsByTagName("head")[0];
	head.appendChild(script);
}

// Recherche dans un tableau
function in_array(arr,obj){
  for(objId in arr){if(arr[objId]==obj){return true;}}
}

// fonction qui permet d'obtenir la position d'un element
function fDomOffset(oObj, sProp){
  typeScroll="scrollLeft"
	if(sProp=="offsetTop"){typeScroll="scrollTop"}

	var iVal = 0;
	while (oObj && oObj.tagName != "BODY") {
		eval("iVal += oObj." + sProp + " - oObj."+typeScroll+";");
		oObj = oObj.offsetParent;
	}
	return iVal;
}

// Affichage d'une icone d'attente
function setDivWait(divName,message){
	if(undefined==message){message="";}
	iconWait = '<img src="http://formation.ingenious.fr/templates/pack/defaut/wait.gif" alt="wait.gif">';
  document.getElementById(divName).innerHTML="<center>"+iconWait+"<BR>"+message+"</center>";
}

// Affichage d'une bulle d'attente
function bubbleWait(){
	divWait = document.createElement("DIV");
	divWait.id = "divWait";
	divWait.innerHTML="Envoi des données en cours...";
	getBubble(divWait);
}

// Ouverture de la page des images
var currentObjImage = null;
function open_image_panel(objName){
	currentObjImage = objName;
  return window.open("http://formation.ingenious.fr/explorer/","image_panel","width=620,height=500,resizable=1,scrollbars=yes");
}

function set_image_panel(url){
	// Fonction utilisé pour autre que richtext
	if(window.getObjectEditor){
		var objEditor = getObjectEditor(currentObjImage);
		if(objEditor!=null){
      var urlExt = url.toLowerCase().substring(url.lastIndexOf(".")+1,url.length);
      var arrImg = new Array("jpg","jpeg","gif","png");

      if(in_array(arrImg,urlExt)){
        objEditor.add_image(url);
      }
      else{
        var urlBase = url.toLowerCase().substring(url.lastIndexOf("/")+1,url.length);
        var objLink = objEditor.document.createElement("A");
        objLink.setAttribute("href",url);
        objLink.innerHTML = urlBase;
        objEditor.insert_element(objLink);
      }
		}
	}

	var objImg = document.getElementById("img_"+currentObjImage);
	if(objImg!=null){objImg.src=url;}

	var objInput = document.getElementById("txt_"+currentObjImage);
	if(objInput!=null){objInput.value=url;}

	currentObjImage = null;
}

// ouverture d'une conversation
function openConversation(idUser){
  if(idUser==undefined){
    var hidden_user = document.getElementById("hidden_user");
    if(hidden_user!=null){idUser=hidden_user.value;}
  }

  if(idUser.length==0){idUser=0;}
  if(idUser==0){alert("Veuillez choisir un destinataire dans la liste");return;}

  var thisWin = window.open("http://formation.ingenious.fr/irc/"+idUser,"convers_"+idUser,"menubar=no, status=no, scrollbars=no, menubar=no, width=550, height=530");
  if(thisWin!=null){thisWin.focus();}
  else{alert("Veuillez désactivé votre bloqueur de fenêtre pour pouvoir discuter.");}
}

function openMemberCard(userId){
  var mySrc = "http://formation.ingenious.fr/tools/membercard.php?index="+userId;
  window.open(mySrc,"membercard","width=480,height=230");
}

function goMoteur(){
  ssearch = document.getElementById("sengine").value;
  document.location.href="http://formation.ingenious.fr/search/"+escape(ssearch);
  return false;
}

// mise a jour du moteur de recherche
function setMoteur(objMoteur){
  if(objMoteur.value==""){objMoteur.value=objMoteur.alt;}
  else{if(objMoteur.value==objMoteur.alt){objMoteur.value="";}}
}

// Destruction de la bulle
function killBubble(force){
  if(!force){
    if(window.event==null){return;}
    if(window.event.srcElement==null){return;}
    if(isChild(window.event.srcElement,"globalBubble")){return;}
  }

  var globalBubble = document.getElementById("globalBubble");
  if(globalBubble!=null){globalBubble.style.display="none";}

  document.detachEvent("onmouseup",killBubble);
}

// Fonction de bulle d'aide
function getBubble(obj,pos){
  if(typeof pos != "string"){pos="down";}
  if(typeof obj == "string"){obj = document.getElementById(obj);}
  if(typeof obj != "object"){return;}

  if(!window.event){return;}
  var eventSrc = window.event.srcElement;
  if(typeof eventSrc != "object"){return;}

  var globalBubble = document.getElementById("globalBubble");
  if(globalBubble==null){
    globalBubble = document.createElement("DIV");
    globalBubble.id = "globalBubble";
    globalBubble.style.padding=5;
    globalBubble.style.display="none";
    globalBubble.style.border="4px solid #C3D9FF";
    globalBubble.style.backgroundColor="#FFFFFF";
    globalBubble.style.color="#000000";
    globalBubble.style.position="absolute";
    globalBubble.style.zIndex=3;
    document.body.appendChild(globalBubble);
    insereCSS("#globalBubble a","color:#888888;")
    insereCSS("#globalBubble a:hover","color:#888888;")
  }

  globalBubble.style.width="auto";
  globalBubble.innerHTML=obj.innerHTML;

  switch(pos){
    case "down":
      globalBubble.style.left=fDomOffset(eventSrc,"offsetLeft");
      globalBubble.style.top=fDomOffset(eventSrc,"offsetTop")+eventSrc.offsetHeight+5;
      globalBubble.style.display="block";
      break;
    case "left":
      globalBubble.style.left=fDomOffset(eventSrc,"offsetLeft")+eventSrc.offsetWidth+5;
      globalBubble.style.top=fDomOffset(eventSrc,"offsetTop")-5;
      globalBubble.style.display="block";
      break;
  }

  if(globalBubble.offsetWidth>400){globalBubble.style.width=400;}
  if(globalBubble.offsetWidth<100){globalBubble.style.width=100;}

	var winX = (document.body)?(document.body.clientWidth):(window.innerWidth);
  if(fDomOffset(globalBubble,"offsetLeft")+globalBubble.offsetWidth>winX){
		globalBubble.style.left=winX-globalBubble.offsetWidth;
	}

  document.attachEvent("onmouseup",killBubble);
}

function getPanelIcone(objIcon, nb_img){
  var panelEmoticon = document.getElementById("panelEmoticon");
  if(panelEmoticon==null){
    panelEmoticon = document.createElement("SPAN");
    panelEmoticon.id = "panelEmoticon";
    panelEmoticon.style.display="none";

    for(i=0;i<nb_img;i++){
      var link = document.createElement("A");
      link.href = "javascript:setPanelIcone('"+objIcon.id.replace("img_","")+"',"+i+");";
      panelEmoticon.appendChild(link);

      var img = document.createElement("IMG");
      img.src = "http://formation.ingenious.fr/templates/image/emoticon/"+i+".png";
      img.id = "emot_"+i;
      link.appendChild(img);
    }

  }
  getBubble(panelEmoticon);
}

// Panel icone
function setPanelIcone(currentPanelEmoticon,id){
  document.getElementById(currentPanelEmoticon).value=id;
  document.getElementById("img_"+currentPanelEmoticon).src=document.getElementById("emot_"+id).src;
  killBubble(true);
}

// Recuperer la taille de la fenetre
function getWindowHeight(){
  var windowHeight=0;
  if (typeof(window.innerHeight)=="number") {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

// insère une règle avec son nom
function insereCSS(nom,regle){
  if(document.styleSheets) {
    var I=document.styleSheets[0];
    if(I.addRule){I.addRule(nom,regle)} // méthode IE
    else if(I.insertRule){I.insertRule(nom+" { "+regle+" }",I.cssRules.length)} // méthode DOM
  }
}

// Empeche le cache sur un objet ajax
function ajaxNoCache(ajaxObj){
  try{
  	ajaxObj.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
  	ajaxObj.setRequestHeader("Pragma","no-cache");
  	ajaxObj.setRequestHeader("Expire","-1");
  	ajaxObj.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
  }
  catch(e){}
}

// Recupération du contenu d'une page
function getHttpContent(url, eval_function, post){
  if(url==""){return null;}
  
  if(post==undefined){post=null;}
	
	method = "GET";
  if(post!=null){method = "POST";}
  
  if(!url.indexOf("http://formation.ingenious.fr/")!=1){url="http://formation.ingenious.fr/"+url;}

  var http_ajax = createRequestObject();
  ajaxNoCache(http_ajax);
  if(typeof eval_function == "function"){
  	try{srcElem = window.event.srcElement;}
  	catch(e){srcElem = null};

    http_ajax.onreadystatechange = function() {
      if(http_ajax.readyState != 4){return;}
      eval_function(http_ajax,srcElem);
    }

    http_ajax.open(method, url, true);
    send_ajax_post(http_ajax,post);
    http_ajax.send(post);
    return http_ajax;
  }
  else{
    http_ajax.open(method, url, false);
    send_ajax_post(http_ajax,post);
    http_ajax.send(post);
    return http_ajax.responseText;
  }

}

function send_ajax_post(http_request, parameters){
	if(parameters==null){return;}
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
}

// Création d'un ajax
function createRequestObject(){
  var ro=null;
  if(window.XMLHttpRequest){
    ro = new XMLHttpRequest();
  }
  else{
		var ieversions = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0"];
		for(var i=0; !ro && i<ieversions.length; i++){
			try{ro = new ActiveXObject(ieversions[i]);}
			catch(e){ro = null;}
		}
  }

	return ro;
}

// Function permettant de selectionner seulement dans les input
function selectRight(){
	try{myElem=event.srcElement.tagName;}catch(e){myElem = "INPUT"; }
  return (myElem=="INPUT"||myElem=="TEXTAREA");
}

// fonction verifiant qu'un node est enfant d'un autre
function isChild(n1,n2){
  if(typeof n1 != "object"){n1=document.getElementById(n1);}
  if(typeof n2 != "object"){n2=document.getElementById(n2);}

  if(n1==null){return false;}
  if(n2==null){return false;}
  if(n1.id==n2.id){return true;}

  parentElem = n1.parentElement;
  while(parentElem!=null){
    if(parentElem.id==n2.id){return true;}
    parentElem = parentElem.parentElement;
  }

  return false;
}

// Encodes an ISO-8859-1 string to UTF-8  
function utf8_encode(argString){
  var utftext = "";
  var start, end;
  var stringl = 0; 
  start = end = 0;
  stringl = argString.length;
  for (var n = 0; n < stringl; n++) {
    var c1 = argString.charCodeAt(n);
		var enc = null;
    if(c1 < 128){end++;}
		else if(c1 > 127 && c1 < 2048) {enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);}
		else{enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);}
    if(enc !== null) {
			if(end > start) {utftext += argString.substring(start, end);}
	    utftext += enc;
	    start = end = n+1;
		}
  }

  if(end > start){utftext += argString.substring(start, argString.length);}
  return utftext;
}

// Mode graphique
function edit_mode(){
  getHttpContent("http://formation.ingenious.fr/response/desk.php?appel=graphmod");
  document.location.href=document.location.href;
}

function set_input_wrap(form_name){
  var objForm = document.getElementById(form_name);
  if(objForm==null){return;}
  
  var allInput = objForm.getElementsByTagName("INPUT");
	for(i=0;i<allInput.length;i++){
    set_wrap_ask(allInput[i]);
    allInput[i].attachEvent("onblur",set_wrap_ask);
  }

  var allInput = objForm.getElementsByTagName("TEXTAREA");
  for(i=0;i<allInput.length;i++){
    set_wrap_ask(allInput[i]);
    allInput[i].attachEvent("onblur",set_wrap_ask);
  }
}

function cleanWrap(form_name){
  var objForm = document.getElementById(form_name);

  var allInput = objForm.getElementsByTagName("INPUT");
  for(i=0;i<allInput.length;i++){
    set_wrap_off(allInput[i]);
    allInput[i].detachEvent("onblur",set_wrap_ask);
  }

  var allInput = objForm.getElementsByTagName("TEXTAREA");
  for(i=0;i<allInput.length;i++){
    set_wrap_off(allInput[i]);
    allInput[i].detachEvent("onblur",set_wrap_ask);
  }
}

function set_wrap_ask(e){
  if((typeof e).toUpperCase() != "OBJECT"){e = window.event.srcElement;}
  if((typeof e).toUpperCase() != "OBJECT"){return;}
  if(e.title==""){return;}
  if(e.value!=""){return;}
  e.className="wrap_activ";
  e.value=e.title;
  e.attachEvent("onfocus",set_wrap_off);
}

function set_wrap_off(e){
  if((typeof e).toUpperCase() != "OBJECT"){e = window.event.srcElement;}
  if((typeof e).toUpperCase() != "OBJECT"){return;}
  if(e.value!=e.title){return;}

  e.value="";
  e.className="wrap_passiv";
  e.detachEvent("onfocus",set_wrap_off);
}

function firefox_popup(){
	ffpop = document.createElement("DIV");
	ffpop.id="ff_pop";
	ffpop.style.background="#FFFFFF";
	ffpop.style.border="1px solid #999999";
	ffpop.style.color="#000000";
	ffpop.style.fontSize="10px";
	ffpop.style.width="200px";

	imgpop = document.createElement("IMG");
	imgpop.src = "https://addons.mozilla.org/media//img/amo2009/app-icons/small/firefox.png";
	imgpop.style.height = "40px";
	imgpop.style.width = "auto";
	imgpop.align = "left";
	ffpop.appendChild(imgpop);

	linkpop = document.createElement("A");
	linkpop.innerHTML = "<cite>Votre navigateur ne respecte pas les normes Internet W3C. Cliquez ici pour installer un navigateur web performant.<BR>Bonne visite sur notre site.</cite>";
	linkpop.style.fontSize="10px";
	linkpop.href = "http://www.mozilla-europe.org/fr/firefox/";
	ffpop.appendChild(linkpop);

	linkpopclose = document.createElement("A");
	linkpopclose.innerHTML = "Fermer";
	linkpopclose.style.textAlign = "right";
	linkpopclose.style.width = "100%";
	linkpopclose.href = "javascript:firefox_hide();";
	ffpop.appendChild(linkpopclose);

	ffpop.style.position="absolute";
	document.body.appendChild(ffpop);

	firefox_hide();
	firefox_slide();
}

function firefox_slide(){
	ffpop = document.getElementById("ff_pop");
	ffpop.style.display="block";
	if(parseInt(ffpop.offsetTop)>0){return;}
	ffpop.style.top=ffpop.offsetTop+1;
	window.setTimeout("firefox_slide()",5);
}

function firefox_hide(){
	ffpop = document.getElementById("ff_pop");
	ffpop.style.left=0;
	ffpop.style.top=-ffpop.offsetHeight;
	ffpop.style.display="none";
}

/** Calendrier **/

		  // Calendrier
      var curCalendarObj = null;
      
      function loadCalendar(obj){
        curCalendarObj=obj;
        defdate = "08/02/2012";
        dateToParse = obj.value;
        if(dateToParse.length==0){dateToParse = defdate;}
        dateArr = dateToParse.split("/");
        if(dateArr.length!=3){dateArr = defdate.split("/");}
        calendar_go(dateArr[2],dateArr[1]);
        divCal = document.getElementById("calendar");
        objDiv = document.createElement("DIV");
        objDiv.appendChild(divCal);
        getBubble(objDiv,"left");
        return false;
      }
      
      function calendar_set(y,m,d){
        if(curCalendarObj!=null){curCalendarObj.value=d+"/"+m+"/"+y;}
        killBubble(true);
      }

      function calendar_go(y,m){
        divCal = document.getElementById("calendar");
        if(divCal==null){
          divCal = document.createElement("DIV");
          divCal.id = "calendar";
          document.body.appendChild(divCal);
        }

        url = "http://formation.ingenious.fr/tools/calendar.php?index="+y+"&page="+m;
        divCal.innerHTML = getHttpContent(url);
      }
    

/** Gadgets**/

      function set_login(){
				var user = document.getElementById("fld_user").value;
				var passwd = document.getElementById("fld_passwrd").value;
				var code = Base64.encode(user+"|"+passwd);
				widg_connect_order("login&code="+code);
			}
			
			function send_forget_mail(){
				var email = document.getElementById("id_conn_log").value;
				widg_connect_order("mail_forget&code="+Base64.encode(email));
			}
			
			function set_logout(){widg_connect_order("logout");}
			function get_panel_pass(){widg_connect_order("panel_pass");}
			
			function widg_connect_order(url){
				txt = log_order(url);
				var logmessobj = document.getElementById("logmess");
				if(txt.length>0){logmessobj.style.display="block";logmessobj.innerHTML = txt;}
        else{logmessobj.style.display="none";document.location.href="http://formation.ingenious.fr/";}
        set_input_wrap("logmess");
			}
			
			function log_order(url){
				return getHttpContent("http://formation.ingenious.fr/response/mod.php?appel=login&action="+url); 
			}
			
			function get_login_panel(){
				logPanelObj = document.getElementById("log_panel");
				if(logPanelObj==null){return;}
				logPanelObj.innerHTML=log_order("inge_login_form");
				set_input_wrap("table_login");
			}

			function get_logout_panel(){
				logPanelObj = document.getElementById("log_panel");
				if(logPanelObj==null){return;}
				logPanelObj.innerHTML=log_order("inge_logout_form");
			}
		


			function setSearchLink(){
				var objS = document.getElementById("sengine");
				if(objS==null){return;}
				url = "http://formation.ingenious.fr/search/"+escape(objS.value);
				var link = document.getElementById("linksearch");
				link.href=url;
			}
		

			function montreMenu(id){
			  var srcElem=document.getElementById("tab_"+id);
			  if(srcElem!=null){
				  srcElem.style.display=(srcElem.style.display=="block")?"none":"block";
				}

			  var srcElem=document.getElementById("link_"+id);
			  if(srcElem!=null){
				  srcElem.style.fontStyle=(srcElem.style.fontStyle!="italic")?"italic":"normal";
				  srcElem.style.fontSize=(srcElem.style.fontSize!="1em")?"1em":"0.9em";
				}
			}
		


