function hover(obj)
{
	if(document.all)
	{
		UL = obj.getElementsByTagName('ul');
		if(UL.length > 0)
		{
			sousMenu = UL[0].style;
			if(sousMenu .display == 'none' || sousMenu.display == '')
			{
				sousMenu.display = 'block';
			}
			else
			{
				sousMenu.display = 'none';
			}
		}
	}
}
function setHover()
{
	LI = document.getElementById('menu').getElementsByTagName('li');
	nLI = LI.length;
	for(i=0; i < nLI; i++)
	{
		LI[i].onclick = function(){hover(this);}
	}
}
function showOrnotElement (ElementName)
{
	if (document.getElementById(ElementName).style.display == 'none')
		document.getElementById(ElementName).style.display='block';
	else
		document.getElementById(ElementName).style.display='none';
}
function up()
{

	var selectBox = window.document.getElementById('contactReasonList');
	var index = selectBox.selectedIndex;
	
	if (index != 0){
		var tmp = selectBox.options[index].value;
		var tmpHTML = selectBox.options[index].innerHTML;
		
		selectBox.options[index].value = selectBox.options[index-1].value;
		selectBox.options[index].innerHTML = selectBox.options[index-1].innerHTML;
		
		selectBox.options[index-1].value = tmp;
		selectBox.options[index-1].innerHTML = tmpHTML;
		
		selectBox.selectedIndex = selectBox.selectedIndex - 1;
		
		var selectHidden = window.document.getElementById('contactReasonHidden');
		selectHidden.value= "";
		for (var i=0; i<selectBox.options.length; i++)
		{
			selectHidden.value += selectBox.options[i].innerHTML+";";
			
		}

	}
}

function down()
{
	var selectBox = window.document.getElementById('contactReasonList');
	var index = selectBox.selectedIndex;
	
	if (index != selectBox.options.length-1){
		var tmp = selectBox.options[index].value;
		var tmpHTML = selectBox.options[index].innerHTML;
		
		selectBox.options[index].value = selectBox.options[index+1].value;
		selectBox.options[index].innerHTML = selectBox.options[index+1].innerHTML;
		
		selectBox.options[index+1].value = tmp;
		selectBox.options[index+1].innerHTML = tmpHTML;
		
		selectBox.selectedIndex = selectBox.selectedIndex + 1;
		
		var selectHidden = window.document.getElementById('contactReasonHidden');
		selectHidden.value= "";
		for (var i=0; i<selectBox.options.length; i++)
		{
			selectHidden.value += selectBox.options[i].innerHTML+";";
		}
	}
}

function SwitchVisibility(panel)
{
	var doc = document.getElementById(panel);
	if (doc.style.display=="block") {
		doc.style.display="none";
	} else {
		doc.style.display="block";
	}
}

function SetVisible(panel) {
	document.getElementById(panel).style.display="block";
}													
function SetInvisible(panel) {
	document.getElementById(panel).style.display="none";
}													

/*********************************************/
/* fonction de gestion des listes de produit */
/*********************************************/

/* cette fonction ajoute un "selecteur" a la liste des plus produit */
function AddPlusProduit(listProduit, panel_id, count_id, selectLabel, removeLabel, saver_id, max) {	
	if (CountPlusProduit(panel_id) <= max) {
		var ni = document.getElementById(panel_id);
		var numi = document.getElementById(count_id);
		var num = (document.getElementById(count_id).value -1)+ 2;
		numi.value = num;
		var newdiv = document.createElement('div');
		var divIdName = 'DMore'+num;
		newdiv.setAttribute('id',divIdName);
		var innerHTML = selectLabel + " <select id='LMore#id#' onchange='SetPlusProduit(\"" + panel_id + "\", \"" + saver_id + "\")'>" +listProduit+"</select><INPUT id='RMore#id#' type='button' value='" + removeLabel + "' name='Remove' onclick=\"RemovePlusProduit('#id#', '" + panel_id + "', '" + saver_id + "')\">"
		newdiv.innerHTML = innerHTML.replace(/#id#/g, num);
		ni.appendChild(newdiv);
		SetPlusProduit(	panel_id, saver_id);
	} 	
}
															
function RemovePlusProduit(divNum, panel_id, saver_id) {	
	var d = document.getElementById(panel_id);
	var olddiv = document.getElementById('DMore' + divNum);
	d.removeChild(olddiv);	
	SetPlusProduit(	panel_id, saver_id)		
}	

function SetPlusProduit	(panel_id, saver_id) {
	var d = document.getElementById(panel_id);
	var container = d.firstChild;
	var retour = new Array();
	while(container != null)
	{
		try {
		var num = container.getAttribute("ID").substring(5,container.getAttribute("ID").lenght);
		var ddl = document.getElementById('LMore'+ num);
		retour.push(ddl.options[ddl.selectedIndex].value);	
		} catch (e) {}
		container = container.nextSibling;
	}
	
	document.getElementById(saver_id).value = retour.join(";");
}

function CountPlusProduit(panel_id) {
	var d = document.getElementById(panel_id);
	var container = d.firstChild;
	var retour = 0;
	while(container != null)
	{
		try {
			var num = container.getAttribute("ID").substring(5,container.getAttribute("ID").lenght);
			var ddl = document.getElementById('LMore'+ num);
			retour = retour + 1;
		} catch (e) {}
		container = container.nextSibling;
	}
	return retour;
}


/////////////////////////////////////////////////////////////////
//fillGrid
//This Function Takes three parameters
//first parameter is the id of a DIV tag to which you want 
//to populate the Grid
//Second Paramaeter is the Sql String
//Third Parameter is the selected page index
/////////////////////////////////////////////////////////////////
var xmlhttp;
var ph;
function fillDivWithPh(myPH,url){

	//ouverture sans ajax
	//window.open(url, '', 'resizable=no, location=no, width=400, height=400, menubar=no, status=no, scrollbars=no, menubar=no');


      ph = document.getElementById(myPH);
      if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=fillDivWithPh_Change;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    //code for IE
    else if (window.ActiveXObject)
        {
        try
            {
				xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch(e)
            {
            try
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){}
        }

        if(xmlhttp)
        {
            try
            {
            xmlhttp.onreadystatechange=fillDivWithPh_Change;
            xmlhttp.open("GET",url,false);
            xmlhttp.send();
            }
            catch(e){}
        }
    } 
}
/////////////////////////////////////////////////////////////
//fillGrid_Change
/////////////////////////////////////////////////////////////
function fillDivWithPh_Change()
{
      if(xmlhttp.readyState==4&&xmlhttp.status==200)
      {
			var begin = xmlhttp.responseText.search(/#BeginPopupPan#/) + 15;
			var end = xmlhttp.responseText.search(/#EndPopupPan#/);
			ph.innerHTML = xmlhttp.responseText.substring(begin,end);
			SetVisible(ph.getAttribute('id'));
      }
}

function setDivHtml(divId,html)
{
	var div;
	div = document.getElementById(divId);
	div.innerHTML = html;
}

//Generateur manuel de GUID
function newGuid()
{
    var g = "{";
    for(var i = 0; i < 32; i++)
    g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "")
    return g + "}";
}

//Generateur de Guid 
function GUIDGen() 
{
    try
    {
        var x = new ActiveXObject("Scriptlet.TypeLib");
		return (x.GUID).substr(0, 38);
    }
    catch (e)
    {
		return (newGuid());
    }
}

/*********************************************************/
/* fonction de gestion des ajout d'un item  */
/*********************************************************/

function addTableItem(tableId, name,value, saver_id, lblremove, lblup, lbldown,lblupdate, maxItems, boolUpdate) {
	
	if (maxItems <= countTableItems(tableId)) return;

	var table = document.getElementById(tableId);

	var newTr = document.createElement('tr');

	var newTd1 = document.createElement('td');

	var newTd2 = document.createElement('td');		
	if(boolUpdate == true)
		newTd2.innerText = value;
	else
		newTd2.innerText = name;
		
	//Utilisé dans le cas de l'update
	var newTd2bis = document.createElement('td');
	
	var newTd3 = document.createElement('td');
	
	var newTd4 = document.createElement('td');
	
	var newTd5 = document.createElement('td');
	
	var newHChar = document.createElement('input');
	newHChar.setAttribute("type","hidden");
	newHChar.setAttribute("name","HChar");
	var key = GUIDGen();
	if(boolUpdate == true)
		newHChar.setAttribute("value",key);
	else
		newHChar.setAttribute("value",value);
	

	//Utilisé dans le cas de l'update
	var newUpdateButton = document.createElement('input');
	newUpdateButton.setAttribute("type","button");			
	newUpdateButton.setAttribute("value",lblupdate);
	newUpdateButton.setAttribute("name","UpdateButton");
	newUpdateButton.onclick = function() {updateTableItem(newUpdateButton, tableId, saver_id);};
	
	var newRChar = document.createElement('input');
	newRChar.setAttribute("type","button");			
	newRChar.setAttribute("value",lblremove);
	newRChar.setAttribute("name","RChar");
	newRChar.onclick = function() {removeTableItem(newRChar, tableId, saver_id);};

	var newUpButton = document.createElement('input');
	newUpButton.setAttribute("type","button");			
	newUpButton.setAttribute("value",lblup);
	newUpButton.setAttribute("name","UpButton");
	newUpButton.onclick = function() {upTableItem(newUpButton, tableId, saver_id);};
	
	var newDownButton = document.createElement('input');
	newDownButton.setAttribute("type","button");			
	newDownButton.setAttribute("value",lbldown);
	newDownButton.setAttribute("name","DownButton");
	newDownButton.onclick = function() {downTableItem(newDownButton, tableId, saver_id);};
	
	newTd1.appendChild(newHChar);		
	if(boolUpdate == true)
		newTd2bis.appendChild(newUpdateButton);
	newTd3.appendChild(newRChar);
	newTd4.appendChild(newUpButton);
	newTd5.appendChild(newDownButton);
	
	
	newTr.appendChild(newTd1);
	newTr.appendChild(newTd2);
	if(boolUpdate == true)
		newTr.appendChild(newTd2bis);
	newTr.appendChild(newTd3);
	newTr.appendChild(newTd4);
	newTr.appendChild(newTd5);
	table.firstChild.appendChild(newTr);
	
	saveTableItems(tableId, saver_id, boolUpdate);
}	

function updateTableItem(obj,tableId, saver_id, boolUpdate)
{	
	//obj.parentNode.previousSibling.previousSibling.firstChild.value = obj.parentNode.previousSibling.firstChild.value;
	//obj.parentNode.previousSibling.innerText = obj.parentNode.previousSibling.firstChild.value;
	obj.setAttribute("value","Save");
	obj.onclick = function() {saveUpdateTableItem(obj, tableId, saver_id);};
	
	//Création d'un input text pour effectuer l'update
	var newIChar = document.createElement('input');
	newIChar.setAttribute("type","text");
	newIChar.setAttribute("name","IChar");
	newIChar.setAttribute("value",obj.parentNode.previousSibling.innerText);
	
	//On enlève l'innerText et on ajoute l'input
	obj.parentNode.previousSibling.innerText = "";	
	obj.parentNode.previousSibling.appendChild(newIChar);	
}

function saveUpdateTableItem(obj,tableId, saver_id, boolUpdate) {
	obj.setAttribute("value","Update");
	obj.parentNode.previousSibling.innerText = obj.parentNode.previousSibling.firstChild.value;
	obj.onclick = function() {updateTableItem(obj, tableId, saver_id);};
	saveTableItems(tableId, saver_id);
}

function removeTableItem(obj,tableId, saver_id)
{	
	obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	saveTableItems(tableId, saver_id);
}

function upTableItem(obj,tableId, saver_id)
{	
	var line = obj.parentNode.parentNode;
	if (line.previousSibling != null){
		var prevLine = line.previousSibling;
		var table = line.parentNode;
	
		table.removeChild(line);
		table.insertBefore(line, prevLine);
	}
	saveTableItems(tableId, saver_id);
}	

function downTableItem(obj,tableId, saver_id)
{	
	var line = obj.parentNode.parentNode;
	if (line.nextSibling != null){
		var nextLine = line.nextSibling;
		var table = line.parentNode;

		table.removeChild(nextLine);
		table.insertBefore(nextLine, line);
	}
	saveTableItems(tableId, saver_id);
}		

function saveTableItems(tableId, saver_id) {
	var d = document.getElementById(tableId);
	var container = d.firstChild.firstChild;
	var retourValue = new Array();
	var retourName = new Array();
	while(container != null)
	{
		try {
			retourValue.push(container.childNodes[0].firstChild.value);
			retourName.push(container.childNodes[1].innerText);	
		} catch (e) {}
		container = container.nextSibling;
	}
	document.getElementById(saver_id).value = retourName.join(";")+"|"+retourValue.join(";");
}

/*
function saveTableItems(tableId, saver_id, updatedNode) {
	var d = document.getElementById(tableId);
	var container = d.firstChild.firstChild;
	var retourValue = new Array();
	var retourName = new Array();
	while(container != null)
	{
		try {
			//retourValue.push(container.childNodes[0].firstChild.value);
			if (updatedNode == null)
			{				
				retourName.push(container.childNodes[1].innerText);//celui la	pour updte
				retourValue.push(container.childNodes[0].firstChild.value);
				//obj.parentNode.previousSibling.firstChild.value;
			}
			else
			{
				retourName.push(container.childNodes[1].innerText);
				retourValue.push(updatedNode);
			}
				
		} catch (e) {}
		container = container.nextSibling;
	}
	document.getElementById(saver_id).value = retourName.join(";")+"|"+retourValue.join(";");
}	
*/
function countTableItems(tableId) {
	var d = document.getElementById(tableId);
	var container = d.firstChild.firstChild;
	var retour = 0;
	while(container != null)
	{
		retour++;

		container = container.nextSibling;
	}
	return retour;
}

// function used in the internationalContactDisplay template to display internationalContact information

function showInternationalContact(obj)
{

	var resultDivDisplay = obj.nextSibling;
	var resultDiv = resultDivDisplay.nextSibling;
	
	resultDivDisplay.innerHTML = "";

	if (obj.selectedIndex != 0)
	{
		resultDivDisplay.innerHTML = document.getElementById(obj.value).innerHTML;
	}
}

var tabColor = new Array();

function switchColor(id, prevColor, newColor) {
	if (tabColor[id] == newColor) return;
	
	var d = document.getElementById(id);
	var re = new RegExp(prevColor, "g");
	d.innerHTML = d.innerHTML.replace(re, newColor);
	tabColor[id] = newColor;
}
function popLexique(page,largeur,hauteur,options)
{
var top=(screen.height-hauteur)/2;
var left=(screen.width-largeur)/2;
window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
