// JavaScript Document
//SCRIPT POUR LE ROLLOVER DU SOUS MENU

var chrono = null;
function initEvent(idConteneur)
{
  var elements = document.getElementById(idConteneur).getElementsByTagName("*");
  var i;
  var n = elements.length;
  
  for (i=0; i<n; i++)
  {
    elements[i].onmouseover = function(){stopTempo()}
  }
  
}

function stopTempo()
{
  if (chrono!=null)
    clearTimeout(chrono);
  chrono = null;
}

function demarreTempo()
{
  if (chrono==null)
    chrono = setTimeout("mouseOut()","20");
}

function mouseOut()
{
  document.getElementById('candidats').style.display='none';
    document.getElementById('recruteurs').style.display='none';
  chrono = null;
}

//SCRIPT POUR LE ROLLOVER DE LA CARTE DE FRANCE
if (document.images)
{
	preload = false;

	url = new Array();
	url[0] = "../images/carte00.png";
	url[1] = "../images/carteidf.png";
	url[2] = "../images/carteparisest.png";
	url[3] = "../images/cartenord.png";
	url[4] = "../images/cartelyon.png";
	url[5] = "../images/cartepaca.png";
	url[6] = "../images/cartelanguedoc.png";
	url[7] = "../images/carteparisnord.png";

	var i = 0;
	for(i=0; i<6; i++)
	{
		tmp = new Image(510, 485)
		tmp.src = url[i];
	}
	preload = true;
}

function changeImage(img_index) {
	if (document.images && (preload == true)) {
		document.getElementById('carte2').src = url[img_index];
	}
}

//SCRIPT POUR LE ROLLOVER DE LA CARTE DE L'ILE FRANCE
if (document.images)
{
	preload = false;

	url2 = new Array();
	url2[0] = "../images/paris00.png";
	url2[1] = "../images/parisboulogne.png";
	url2[2] = "../images/paris00.png"; //En remplacement de Creteil
	url2[3] = "../images/parisidf.png";
	url2[4] = "../images/parisstdenis.png";
	

	var i = 0;
	for(i=0; i<3; i++)
	{
		tmp = new Image(510, 485)
		tmp.src = url2[i];
	}
	preload = true;
}

function changeImageIdf(img_index) {
	if (document.images && (preload == true)) {
		document.getElementById('carte3').src = url2[img_index];
	}
}

//SCRIPT POUR OUVRIR LA FENETRE DE PLAN DETAILLE
function ouvre_plan(plan){
window.open("plan_"+plan+".html", "", "width=720,height=700, screenX=800,screenY=800, top=100,left=200, scrollbars=yes");
}

//SCRIPT POUR OUVRIR LA FENETRE DES MENTIONS
function ouvre_mention(adrMention)
{
    window.open(adrMention,"test","width=720,height=700,top=100,left=200, scrollbars=yes")
}

//SCRIPT POUR MONTRER CACHER LES REPONSES DE LA FAQ
function cacher(a)
{
	if(document.getElementById(a) != null)
	{
	var styl =document.getElementById(a).style;
 styl.display=styl.display=="block"?"none":"block";
	}	;
	
};

//SCRIPT POUR TREEVIEW
function OnTreeClick(evt)
{
 var src = window.event != window.undefined ? window.event.srcElement : evt.target;
 var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
 if(isChkBoxClick)
 {
     var parentTable = GetParentByTagName("table", src);
     var nxtSibling = parentTable.nextSibling;
     //check if nxt sibling is not null & is an element node
      if(nxtSibling && nxtSibling.nodeType == 1)
     {
         if(nxtSibling.tagName.toLowerCase() == "div") //if node has children
         {
             //check or uncheck children at all levels
             CheckUncheckChildren(parentTable.nextSibling, src.checked);
         }
     }
 //check or uncheck parents at all levels
 CheckUncheckParents(src, src.checked);
 }
}

 function CheckUncheckChildren(childContainer, check)
{
 var childChkBoxes = childContainer.getElementsByTagName("input");
 var childChkBoxCount = childChkBoxes.length;
 for(var i=0;i<childChkBoxCount;i++)
 {
     childChkBoxes[i].checked = check;
 }
}

function CheckUncheckParents(srcChild, check)
{
 var parentDiv = GetParentByTagName("div", srcChild);
 var parentNodeTable = parentDiv.previousSibling;
 if(parentNodeTable)
 {
     var checkUncheckSwitch;
     if(check) //checkbox checked
     {
         var isAllSiblingsChecked = AreAllSiblingsChecked(srcChild);
         if (isAllSiblingsChecked)
             checkUncheckSwitch = true;
         else {
             return; //do not need to check parent if any(one or more) child not checked
         }
     }
     else //checkbox unchecked
     {
         checkUncheckSwitch = false;
     }
   
     var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");
     if(inpElemsInParentTable.length > 0)
     {
         var parentNodeChkBox = inpElemsInParentTable[0];
         parentNodeChkBox.checked = checkUncheckSwitch;
         //do the same recursively
        CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
     }
 }
}

function AreAllSiblingsChecked(chkBox)
{
 var parentDiv = GetParentByTagName("div", chkBox);
 var childCount = parentDiv.childNodes.length;
 for(var i=0;i<childCount;i++)
 {
     if(parentDiv.childNodes[i].nodeType == 1)
     {
         //check if the child node is an element node
         if(parentDiv.childNodes[i].tagName.toLowerCase() == "table")
         {
             var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
             //if any of sibling nodes are not checked, return false
             if(!prevChkBox.checked)
             {
                 return false;
             }
         }
     }
 }
 return true;
}

//utility function to get the container of an element by tagname
function GetParentByTagName(parentTagName, childElementObj)
{
 var parent = childElementObj.parentNode;
 while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
     {
         parent = parent.parentNode;
     }
 return parent;
}

// FIN SCRIPT POUR TREEVIEW

//DEBUT SCRIPT IMPRESSION

function imprime_zone(titre, obj, css) 
{
// Définie la zone à imprimer
var zi = document.getElementById(css).innerHTML;
zi += document.getElementById(obj).innerHTML;

// Ouvre une nouvelle fenetre
var f = window.open("", "ZoneImpr", "height=500, width=600, toolbar=0, menubar=0, scrollbars=1, resizable=1,status=0, location=0, left=10, top=10");

// Définit le Style de la page
f.document.body.style.color = '#000000';
f.document.body.style.backgroundColor = '#FFFFFF';
f.document.body.style.padding = "10px";

// Ajoute les Données
f.document.title = titre;
f.document.body.innerHTML += zi;

// Imprime et ferme la fenetre
f.window.print();
f.window.close();
return true;
} 

//FIN IMPRESSION

 function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }
//SCRIPT POPUP

function popup(fenetre){
        window.open(fenetre.value, '', '');
}

// DETECTION DE LA TOUCHE ENTREE
function  DetecteTouche(e, touche)
{
    var EnterKey
    if(e && e.which)
    {           // pour non IE
        e = e
        EntrerKey = e.which
    }
    else
    {
        e = event
        EnterKey = e.keyCode // IE specific code
    }
    return  (EnterKey == touche) 
}

//Focus effece la cuurent value
function WebDropDownOnFocusMetier(sender,e)
{   
    var value = sender.get_currentValue();
    
    var testMetier = 'S\351lectionner un M\351tier';
    
    if (value == testMetier)
    {
        sender.set_currentValue("",true);
    }  
}

function WebDropDownOnFocusRegion(sender,e)
{   
    var value = sender.get_currentValue();
    
    var testRegion = 'S\351lectionner une r\351gion';
    
    if (value == testRegion)
    {
        sender.set_currentValue("",true);
    }
}

function WebDropDownOnBlurMetier(sender,e)
{
    var value = sender.get_currentValue();
    
    var testMetier = 'S\351lectionner un M\351tier';
    
    if (value == '')
    {
        sender.set_currentValue(testMetier,true);
    }  
}

function WebDropDownOnBlurRegion(sender,e)
{
//    var value = sender.get_currentValue();
//    
//    var testRegion = 'S\351lectionner une r\351gion';
//    
//    if (value == '')
//    {
//        sender.set_currentValue(testRegion,true);
//    }
}
