
// alumni
var currentAlumni = 0;
var stepHideAlumni = 10;
var stepShowAlumni = 5;
var delayAlumni = 2;

function showdivalumni(status) {
    if (document.getElementById('form_status_retained')) {
        if ((status=='retained') && (document.getElementById('form_status_retained_content')))
            document.getElementById('form_status_retained').style.height = document.getElementById('form_status_retained_content').offsetHeight+'px';
        else
            document.getElementById('form_status_retained').style.height = '0px';
    }
}

function showAlumniDetails(id,rsrc,rwidth,rheight,csrc,cwidth,cheight) {
  if (document.images['alph'+id]) {
    if (document.images['alph'+id].src==rsrc) {
      document.images['alph'+id].src=csrc;
      document.images['alph'+id].width=cwidth;
      document.images['alph'+id].height=cheight;
    }
    else {
      document.images['alph'+id].src=rsrc;
      document.images['alph'+id].width=rwidth;
      document.images['alph'+id].height=rheight;
    }
  }
}

function processAlumni(id,resizeStr,resizeWidth,resizeHeight,cropStr,cropWidth,cropHeight) {
  if (currentAlumni != id) {

    var arrDivs=document.getElementsByTagName('DIV');

    for (i=0; i<arrDivs.length; i++){
      if (arrDivs[i].id) {
        if (arrDivs[i].id.substring(0,14) == 'alumnidetails-') {
          iddiv = arrDivs[i].id.substring(14);
          if (iddiv != id) hideAlumni(iddiv);
        }
      }
    }
    currentAlumni = id;
    showAlumni(id);
  }
  else {
    currentAlumni = 0;
    hideAlumni(id);
  }

//  if (resizeStr!="" && cropStr!="") showAlumniDetails(id,resizeStr,resizeWidth,resizeHeight,cropStr,cropWidth,cropHeight);

}

function hideAlumni(id) {
  var reg = new RegExp("(px)", "g");

  myDiv = 'alumnidetails-' + id;
  if (document.getElementById(myDiv)) {
    myHeightStr = document.getElementById(myDiv).style.height;
    myHeight = parseInt(myHeightStr.replace(reg,""));
    myHeight-= stepHideAlumni;
    if (myHeight < 0) myHeight = 0;
    myHeightStr = myHeight + 'px';
    document.getElementById(myDiv).style.height = myHeightStr;
    if (myHeight > 0) setTimeout('hideAlumni('+id+')',delayAlumni);
  }
}

function showAlumni(id) {
  var reg = new RegExp("(px)", "g");

  myContent = 'alumnidetailscontent-' + id;
  myMax = document.getElementById(myContent).offsetHeight;

  myDiv = 'alumnidetails-' + id;
  myHeightStr = document.getElementById(myDiv).style.height;
  myHeight = parseInt(myHeightStr.replace(reg,""));
  myHeight+=stepShowAlumni;
  if (myHeight > myMax) myHeight = myMax;
  myHeightStr = myHeight + 'px';

  document.getElementById(myDiv).style.height = myHeightStr;
  if (myHeight < myMax) {
    if (currentAlumni == id)
      setTimeout('showAlumni('+id+')',delayAlumni);
    else
      hideAlumni(id);
  }
}

function previewPicto(setcolor) {
  var imgFile=document.forms["badd"].elements["picto"].value;
  if (imgFile!="") {
    document['prevpicto'].src="ressource.php?fct=picto&f="+imgFile;
    if (setcolor) {
      var lfile=imgFile.toLowerCase();
      color="";
      if (lfile.indexOf("yellow")>0) color="FECB00";
      else if (lfile.indexOf("mustard")>0) color="EAAB00";
      else if (lfile.indexOf("orange")>0) color="FF7900";
      else if (lfile.indexOf("terracotta")>0) color="C75B12";
      else if (lfile.indexOf("red")>0) color="C30045";
      else if (lfile.indexOf("burgundy")>0) color="882345";
      else if (lfile.indexOf("fuchsia")>0) color="B1059D";
      else if (lfile.indexOf("blue")>0) color="0046AD";
      else if (lfile.indexOf("silver")>0) color="747678";
      else if (lfile.indexOf("purple")>0) color="824BB0";
      else if (lfile.indexOf("violet")>0) color="4F2D7F";
      else if (lfile.indexOf("green")>0) color="009B76";
      else if (lfile.indexOf("emerald")>0) color="006D55";
      else if (lfile.indexOf("lime")>0) color="7AB800";
      else if (lfile.indexOf("olive")>0) color="8E9300";

      else color="BEBEBE";

      if (color!="") {
        document.forms["badd"].elements["NB_COLOR"].value = color;
        previewColor(color);
      }
    }
  }
}

function previewColor(color) {
  document.getElementById("prevcolor").style.backgroundColor='#'+color;
}

function setColor(color) {
    document.forms["badd"].elements["NB_COLOR"].value = color;
    previewColor(color);
}

// hs rh
var stepHide = 10;
var stepShow = 5;
var delay = 2;
var reg = new RegExp("(px)", "g");

function hsdetailson(id) {
  myDiv = 'hsdetails'+id;
  myContent = 'hsdetailscontent'+id;
  myLink = 'hsdetailslink'+id;
  if (document.getElementById(myDiv) && document.getElementById(myContent)  && document.getElementById(myLink)) {
    hidediv(myLink);
    slidehsdetailson(myDiv,myContent);
  }
}

function slidehsdetailson(myDiv,myContent) {
  myMax = document.getElementById(myContent).offsetHeight;
  myHeight = document.getElementById(myDiv).offsetHeight;

  myHeight+=stepShow;
  if (myHeight > myMax) myHeight = myMax;
  myHeightStr = myHeight + 'px';

  document.getElementById(myDiv).style.height = myHeightStr;
  if (myHeight < myMax) {
      setTimeout('slidehsdetailson(\''+myDiv+'\',\''+myContent+'\')',delay);
  }
}

function hsdetailsoff(id) {
  myDiv = 'hsdetails'+id;
  myContent = 'hsdetailscontent'+id;
  myLink = 'hsdetailslink'+id;
  if (document.getElementById(myDiv) && document.getElementById(myContent)  && document.getElementById(myLink)) {
    slidehsdetailsoff(myDiv,myContent,myLink);
  }
}

function slidehsdetailsoff(myDiv,myContent,myLink) {
  myMax = document.getElementById(myContent).offsetHeight;
  myHeight = document.getElementById(myDiv).offsetHeight;

  myHeight-=stepHide;
  if (myHeight < 0) myHeight = 0;
  myHeightStr = myHeight + 'px';

  document.getElementById(myDiv).style.height = myHeightStr;
  if (myHeight > 0) {
      setTimeout('slidehsdetailsoff(\''+myDiv+'\',\''+myContent+'\',\''+myLink+'\')',delay);
  }
  else
    showdiv(myLink);
}

function hspopup(ref) {
  window.open('formulaire.html?ref='+ref, '', 'resizable=yes, location=no, width=800, height=630, menubar=no, status=no, scrollbars=yes, menubar=no');
}

function mppopup(url) {
  window.open(url, '', 'resizable=yes, location=no, width=800, height=630, menubar=no, status=no, scrollbars=yes, menubar=no');
}

function fbhs(url) {
  fbSendAjaxFormTargetDiv('formhs',url,'hslist',"Chargement des offres...")
}

function fbmp(url) {
  fbSendAjaxFormTargetDiv('formmp',url,'mplist',"Chargement des offres...")
}

function fbhumansourcingGet(xRequest) {
    if (xRequest.readyState==4) {
      document.getElementById('hslist').innerHTML=xRequest.responseText;
    }
}

function hidediv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
      if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layer[myId].visibility = 'hidden';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'hidden';
        }
    }
}

function showdiv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layers[myId].visibility = 'visible';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'visible';
        }
    }
}

// Ajax - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function fbGetUrlDiv(id,url,innerhtml) {
  if (document.getElementById(id)) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById(id);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDiv(xRequest,anId) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
    }
}

function fbShowWaiting(obj,innerhtml) {
    obj.innerHTML=innerhtml;
}

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) // Firefox
    {
       return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
        {
            return(new ActiveXObject("Msxml2.XMLHTTP"));
        } 
        catch (e)
        {
            try
            {
                return(new ActiveXObject("Microsoft.XMLHTTP"));
            }
            catch (e)
            {
                alert("Your browser does not support XMLHTTPRequest...");
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
       alert("Your browser does not support XMLHTTPRequest...");
    }
}

function fbSendAjaxFormTargetDiv(idForm,baseurl,targetId,innerhtml) {

    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById(idForm);

    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            var type=elmt.nodeName.toLowerCase();
            var ok=true;

            if (type=="input") {
                switch (elmt.type.toLowerCase()) {
                case "radio":
                case "checkbox":
                    if (!elmt.checked) ok=false;
                    break;

                case "submit":
                case "image":
                    ok=false;
                    break;
                }
            }
            else if ((type!="select") && (type!="textarea")) ok=false;
            if (ok) {
                if (first) first=false;
                else url+="&";
                url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
            }
        }
    }

    var obj=document.getElementById(targetId);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);

    xReq.open("POST",baseurl,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,targetId);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function checkFormRequired
// Object : checking if form fields are empty
//          frmName: form name
//          msgError: message to alert if a field is emty
//          arguments 3 and next: fields to be checked
// FASTBOIL                     1.0         15/06/2011
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkFormRequired(frmName,msgError) {
  var msg = "";
  for (var i=2; i<checkFormRequired.arguments.length; i++) {
    if (trim(eval('document.'+frmName+'.'+arguments[i]+'.value'))=="") {
      msg = msgError;
      eval('document.'+frmName+'.'+arguments[i]+'.focus()');
      break;
    }
  }
  if (msg == "")
    return true;
  else  {
    alert(msg);
    return false;
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function trim
// Object :
// FASTBOIL                     1.0         15/06/2011
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function trim(myString) {
  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}


