/*
**	DOOZ TECHNOLOGIES INC.
**
**	default.js
**	Set of JavaScript files included by default with infuse
**
**	author : Bruno Morency
**	(c) 2001 - 2002  Dooz Technologies Inc. (www.dooz.ca)
**
*/

function SetFocus() {

	if (document.loginForm != null) {
		document.loginForm.login_uname.focus();
	}

	if (document.QuickSearchForm != null) {				 
		document.QuickSearchForm.quicksearchstr.focus();
	}

/*	if (document.sectionSearch != null) {				 
		document.sectionSearch.elements[0].focus();
	}
*/
}

// if page opened in a frameset, this function called on body onLoad() event will free the page from the framset
function BreakOut() {
	//alert('atempting breakout');
	if(window.parent.location!=location){
		window.parent.location=location;
	}
}

function OnBodyLoad() {
	BreakOut();
//	SetFocus();

	//setOpacTimeOut();
	ResetUserTimeout();
	return true;
}
//var userTimeoutValue = 30000;
//var userTimeoutValue = 900000;
//var userTimeout;

function setOpacTimeOut(){
	userTimeoutSV = setTimeout('refresh()',userTimeoutValue);
}

function ResetUserTimeout()
{
	clearTimeout(userTimeoutSV);
	setOpacTimeOut();
}

function refresh(){
    document.location.href='/index.php?acode=logout&toacode='+defaultStartAcode+'&clearOPAC=1Source=000';
}

function swapRowState(item,origClass) {
	ie = (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4) ? true : false;
	dom = (document.createElement && document.appendChild && document.getElementsByTagName) ? true : false;

	// retrace origin table row tag for the item
	elm = item;
	i = 0;
	if (ie) {
		while (elm.tagName!='TR' && i<10) {
			elm=elm.parentElement;
			i++;
		}
	}
	else if (dom) {
		while (elm.tagName!='TR' && i<10) {
//			alert(elm.tagName);
			elm=elm.parentNode;
			i++;
		}
	}						

	if (item.checked) elm.className = 'selected';
	else elm.className = origClass;
//	alert(elm.className+\"\\n\"+i);

}


function actionPopup(acode,id,page)  {
	gotofile = page+'?acode='+acode+'&itemid='+id;

	// open pop up window
	if (acode.search('lpr') != -1)
		doozactpop = window.open(gotofile,'action','height=600,width=650,menubar=yes,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=100,screenY=100,dependent=no');
	else 
		doozactpop = window.open(gotofile,'action','height=400,width=450,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=100,screenY=100,dependent=no');

	// give focus to the popup window
	doozactpop.focus();
}


function openFile(aid,fid,page)  {
	gotofile = page+'?acode=getfile&mode=open&aid='+aid+'&fid='+fid;
	window.open(gotofile,'filewindow','height=700,width=650,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=100,screenY=100,dependent=no');
}


function openFileVersionHistory(aid,fid,page)  {
	gotofile = page+'?acode=fileversionhist&aid='+aid+'&fid='+fid;
	window.open(gotofile,'action','height=400,width=450,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=100,screenY=100,dependent=no');
}


function CloseCommentComposer(aid,page,acode) {
	newUrl = page+"?acode="+acode+"&itemid="+aid+"&expcm=0";
	window.opener.location.href = newUrl;
	window.close();
}

function commentReply(aid,cid,page,acode)  {
	gotofile = page+'?acode='+acode+'&itemid='+aid+'&cmparent='+cid;
	
	// open pop up window
	doozactpop = window.open(gotofile,'action','height=400,width=450,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=200,screenY=100,dependent=no');
	
	// give focus to the popup window
	doozactpop.focus();
}

function uploadInProgress(formObj)  {

	// loop through all formObj elements to make sure at least one file upload field isn't empty
	var hasFile = false;
	var i = 0;
	countEmls = formObj.elements.length;
	while (i < countEmls && !hasFile) {
		if (formObj.elements[i].type == 'file' && formObj.elements[i].value.length != 0) {
			hasFile = true;
		}
		else i++;
	}

	if (hasFile) {
		// instantiate  objlayer object for div with upload in progress warning
		// IMPORTANT we assume the div with the upload warning has "uploadInProgDiv" as its id
		warnDiv = new objLayer('uploadInProgDiv');
		// show the warning div
		warnDiv.show();
		/*if (browser.ie) {
			document.images['uploadSablier'].src = "/images/uploadSablier.gif";
		}*/
	}
}


function ArticleBrowser(fieldId, isMulti, index, allowedTms, title) {
/*
** Opens a popup used to select an article for fields of type article and multiarticle
*/

	file = index+'?acode=artbrowser&tms='+allowedTms+'&datafield='+fieldId+'&multi='+isMulti+'&title='+title;

	if (isMulti) {
		hiddenSelField = document.getElementById(fieldId);
		if (hiddenSelField.value != '') file = file+'&currentSel='+hiddenSelField.value;
	}

	// open article browser pop up window
	doozpopup = window.open(file,'articleBrowser','height=500,width=650,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=20,screenY=20,dependent=no');

	// give focus to the popup window
	doozpopup.focus();

}


function CloseArticleBrowser(dataFieldId,isMulti,lang,listCount) {

	if (isMulti == 0) {

		noSelMsg = new Array("You must make a selection.","Vous devez choisir un des items.");

		// find the selected radio button
		selectedArt = 0;

		// if ther list contains only one element, document.articleBrowserForm.elmList
		// won't be an array
		if (document.articleBrowserForm.elmList.checked) {
			selectedArt = document.articleBrowserForm.elmList.value;
		}
		else {
			for(i = 0; i < document.articleBrowserForm.elmList.length; i++) {
				dummy = document.articleBrowserForm.elmList[i];
				if (dummy.checked) {
					selectedArt = dummy.value;
					break;
				}
			}
		}

		if (selectedArt == 0) {
			// no article selected
			alert(noSelMsg[lang]);
		}
		else {
			// get the article title for the selected article
			dummy = document.getElementById('label_'+selectedArt);
			selectedArt_label = dummy.value;

			// write selected article_id and title in opener
			// set selected category id in hidden field
			elm = window.opener.document.getElementById(dataFieldId);
			elmLabel = window.opener.document.getElementById(dataFieldId+'_label');

			elm.value = selectedArt;
			elmLabel.value = selectedArt_label;

			window.close();
		}
	}

	else if (isMulti == 1) {

		//noSelMsg = new Array("You haven't selected any articles.","Vous n'avez choisi aucun article.");

		// get the buffer select box object
		bufferFormElm = window.document.getElementById(dataFieldId);

		selectedArt = new Array();
		selectedArtLabel = new Array();

		// collect article_ids and subjects from select buffer
		for(i = 0; i < bufferFormElm.options.length; i++) {
			dummy = bufferFormElm.options[i];
			index = selectedArt.length;
			selectedArt[index] = dummy.value;
			selectedArtLabel[index] = dummy.text;
		}

		// write collected values in caller field
		callerFormElm = window.opener.document.getElementById(dataFieldId);
		callerFormElmLabel = window.opener.document.getElementById(dataFieldId+'_label');

		callerFormElm.value = selectedArt.join('-');
		callerFormElmLabel.value = selectedArtLabel.join('\n');

		window.close();

	}
}





function AddToArticleBrowserBuffer(dataFieldId,lang,listCount) {

	noSelMsg = new Array("You must make a selection.","Vous devez choisir un des items.");

	// find the checkboxes that are selected
	selectedArt = new Array();
	for(j = 1; j <= listCount; j++) {
		eval("dummy = document.articleBrowserForm.elmList_"+j+";");
		if (dummy.checked) {
			index = selectedArt.length;
			selectedArt[index] = dummy.value;
			// uncheck the article
			dummy.checked = false;
			originalClass = ((j % 2) == 0) ? 'even' : 'odd';
			swapRowState(dummy,originalClass);
		}
	}

	if (selectedArt.length == 0) {
		// no article selected
		alert(noSelMsg[lang]);
	}
	else {
		// get the buffer select box object
		formElm = window.document.getElementById(dataFieldId);

		// get the title of selected articles
		for (i=0; i < selectedArt.length; i++) {
			dummy = document.getElementById('label_'+selectedArt[i]);
			optIndex = formElm.options.length;
			// add the selected article in the buffer select field
			formElm.options[optIndex] = new Option(dummy.value, selectedArt[i]);
		}

	}

	// add these new articles in currentSel parameter of listNavForm for persistence
	// of buffer select box across list views
	if (typeof document.listNavForm != 'undefined') {
		currentSelObj = document.listNavForm.currentSel;

		// merge currently selected articles to new articles added
		if (currentSelObj.value != '') {
			currentSelArray = currentSelObj.value.split('-');
			selectedArt = currentSelArray.concat(selectedArt);
		}
	
		document.listNavForm.currentSel.value = selectedArt.join('-');
	}
}





function ArticleBrowserBufferRemoveSel(dataFieldId) {

	// get the buffer select box object
	formElm = window.document.getElementById(dataFieldId);

	// traverse options in buffer select box input and remove those selected
	// get the title of selected articles

	for (i=0; i < formElm.options.length; i++) {
		if (formElm.options[i].selected) {
			// setting an option to null remoevs it and shifts all 
			// further options down one index so must decrement i
			formElm.options[i] = null;
			i -= 1;
		}
	}

	newBufferIds = new Array();
	for (i=0; i < formElm.options.length; i++) {
		newBufferIds[newBufferIds.length] = formElm.options[i].value;
	}


	// remove these articles from currentSel parameter of listNavForm for persistence
	// of buffer select box across list views
	document.listNavForm.currentSel.value = newBufferIds.join('-');

}



function launchIsacsoftReader(ofFieldId,roamId,address,contentServerUrl) {

	html = "<object id=\"PluginHostCtrl\" classid=\"CLSID:DBB2DE32-61F1-4F7F-BEB8-A37F5BC24EE2\" width=\"1\" height=\"1\">\n";
	html += "  <param name=\"type\" value=\"application/alreader-plugin\">\n";
	html += "  <param name=\"userid\" value=\"XXX\">\n";
	html += "  <param name=\"roamid\" value=\""+roamId+"\">\n";
	html += "  <param name=\"address\" value=\""+address+"\">\n";
	html += "  <param name=\"contentserverurl\" value=\""+contentServerUrl+"\">\n";
	html += "  <param name=\"sessionid\" value=\"User=agooduser;Group=anicegroup;\">\n";
	html += "  <param name=\"sessionname\" value=\"ASPSESSID\">\n";
	html += "  <embed type=\"application/alreader-plugin\" width=\"1\" height=\"1\" sessionname=\"ASPSESSID\" sessionid=\"User=agooduser;Group=anicegroup;\" userid=\"XXX\" roamid=\""+roamId+"\" address=\""+address+"\" contentserverurl=\""+contentServerUrl+"\">\n";
	html += "</object>\n";
		
	theLauncher = document.getElementById('readerLauncher'+ofFieldId);
	theLauncher.innerHTML = html;
}


/* =================================================================================================
** the following 2 functions are used in find section splash and 
** user creation when we want the radio button to highlight the cell
** of the corresponding text
*/

function SetSectionOn (formObj, radioName, selValue, onClass, offClass) {
	for (i=0; i<formObj.elements.length; i++) {
		if (formObj.elements[i].name == radioName && formObj.elements[i].type == 'radio') {
			//alert(formObj.elements[i].value);
			if (formObj.elements[i].value == selValue) {
				formObj.elements[i].checked = true;
				setCellClass(formObj.elements[i],onClass);
			}
			else {
				formObj.elements[i].checked = false;
				setCellClass(formObj.elements[i],offClass);
			}
		}
	}
}



function setCellClass(itemObj,newClass) {
	//ie = (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4) ? true : false;
	//dom = (document.createElement && document.appendChild && document.getElementsByTagName) ? true : false;

	// the cell to be changed is the second TD outside the form element
	j = 0;
	foundtwo = 0;
	foundone = 0;
	elm = itemObj;

	while (j<10 && !foundtwo) {
		if (elm.tagName == 'TD' && foundone) foundtwo = 1;
		else {
			if (elm.tagName == 'TD') foundone = 1;

			if (elm.parentNode) elm = elm.parentNode;
			else elm = elm.parentElement;

			j++;
		}
	}

	elm.className = newClass;
	//alert(elm.className);
}


function guestLogin(uname,pword) {
    loginForm = document.getElementById('loginForm');
    loginForm.login_uname.value = uname;
    loginForm.login_pword.value = pword;
    loginForm.submit();
}

/* ==================================================================================================================== */

/*
function layerWrite(divid,text,lang) {

	theDoc = window.opener.document;
	ie = (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4) ? true : false;
	dom = (document.createElement && document.appendChild && document.getElementsByTagName) ? true : false;

	browserWarning = new Array("The selected category has been recorded but since you are using a browser which doesn't support W3C DOM standards, your selection will not appear in the form. We recommend using at least Mozilla 1.0, Netscape 6.2 or Internet Explorer 5.5.","Votre sélection a été enregistrée mais comme vous n'utilisez pas un fureteur qui suit les standards DOM du W3C, votre sÃ©lection ne sera pas visible. Nous recommandons l'utilisation de Mozilla 1.0, Netscape 6.2 ou Internet Explorer 5.5.");

	if (ie) theDoc.all[divid].innerHTML = text;

	else if (dom) {

		textnode = theDoc.createTextNode(text);
		thediv = theDoc.getElementById(divid);

		// find existing child node of type text
		foundText = 0; i=0;    			

		while(!foundText) {
			childx = thediv.childNodes.item(i++);
			if (!childx || i > 1000) break; 	// physical max of 1000 childNodes serves as an emergency break for infinite loops
			if (childx.nodeType == 3) foundText = 1;
		}

		if (foundText) thediv.replaceChild(textnode,childx);
		else thediv.appendChild(textnode);

	}

	else {
		alert(browserWarning[lang]);
	}

}
*/





/**************************************************
* code for hierarchical option lists
***************************************************/

// global flag
var isIE = false;

// flag used to avoid calling appendClientAddress() twice on one loadCLientAddress() call
//var newCall;


// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url,requestResponseHandler) {
    // branch for native XMLHttpRequest object
    //newCall = true;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        var self = req;
        req.onreadystatechange = function() {
        	processReqReadyStateChange(self,requestResponseHandler);
        }
        req.open("GET", url, true);
        req.send(null);
//        processReqReadyStateChange();
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
	        var self = req;
	        req.onreadystatechange = function() {
	        	processReqReadyStateChange(self,requestResponseHandler);
	        }
            req.open("GET", url, true);
            req.send();
        }
    }
}


// handle onreadystatechange event of req object
function processReqReadyStateChange(reqObj,requestResponseHandler) {
    // make sure request is complete
    if (reqObj.readyState == 4) {
        // only if "OK"
        if (reqObj.status == 200) {
            //if (newCall) {
                //newCall = false;
                eval(requestResponseHandler+"(reqObj);");
            //}
         } else {
            alert("There was a problem retrieving the data:\n" + reqObj.statusText);
         }
    }
}


// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
        	var retResult = '';
        	for (var i = 0; i < result.childNodes.length; i++) {
        		retResult += result.childNodes[i].nodeValue;
        	}
            return retResult;
        } else {
            return result.firstChild.nodeValue;
        }
    } else {
        return "n/a";
    }
}

// empty select list content
function clearSelect(select) {
    while (select.length > 0) {
        select.remove(0);
    }
}

// add item to select element the less
// elegant, but compatible way.
function appendToSelect(select, value, content) {
    var opt;
    opt = document.createElement("option");
    opt.value = value;
    opt.appendChild(content);
    select.appendChild(opt);
}

// represente le select de l'offield enfant qui doit être remplit
//var selectObj;

function PopulateOfFieldOptions(childOfFieldId, selectedOption) {
     if (selectedOption != undefined) {
          // selectObj = childOfFieldId;
         loadXMLDoc('index.php?acode=getoptionschilds&itemid='+selectedOption+'&selectId='+childOfFieldId,'PopulateSelect');
     	 //window.location.href = 'index.php?acode=getoptionschilds&itemid='+selectedOption+'&selectId='+childOfFieldId;
     }
}


// fill Topics select list with items from
// the current XML document
function PopulateSelect(req) {
 //   var select = document.getElementById(selectObj);
 
    var items = req.responseXML.getElementsByTagName("select");   
    select = document.getElementById(getElementTextNS("", "select_id", items[0], 0));
   
    clearSelect(select); 
    // ajout d'un option vide
    // appendToSelect(select, 0, document.createTextNode(" "))
      
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    
    var items = req.responseXML.getElementsByTagName("option");   
    for (var i = 0; i < items.length; i++) {  
        appendToSelect(select, getElementTextNS("", "option_id", items[i], 0),
            document.createTextNode(getElementTextNS("", "label", items[i], 0)));
    }
    
	if (select.onchange != undefined) { 
		onChangeStr = select.onchange.toString();
	    found = onChangeStr.match(/(PopulateOfFieldOptions[(][\"\'][a-zA-Z0-9]*[\"\'])/gi);
	    selectedValue = (select.options[0].value == undefined) ? 0 : select.options[0].value;
	    fctToCall = found + ","+selectedValue+");"
	    eval(fctToCall);
	    select.selectedIndex = 0;
    }
    
}



function openDiv(name,listDivToOpen){
	/*
	** Cette fonction permet ouvrir les blocks passer en paramètre
	** 
	** 01-09-2004 - Phil L. : création
	*/
	
	arrayDivToOpen = listDivToOpen.split(',');
	for(i=0;i<arrayDivToOpen.length;i++){
		if (arrayDivToOpen[i] != "") {
			ToggleDivDisplay(name + arrayDivToOpen[i],'block');
		}
	}
}

// les images des blocks ouvert et fermer
theImgBlockClose = new Image();
theImgBlockClose.src = "/images/tree-rightarrow.gif";

theImgBlockOpen	= new Image();
theImgBlockOpen.src = "/images/tree-downarrow.gif";

function ToggleDivDisplay(divId, setDisplay) {
	/* 
	** Function to toggle display of a div between 'display' and 'none'
	**
	** Brousky - 2004-03-31
	*/

	theDiv = document.getElementById(divId);
	theImg = document.getElementById("img" + divId);
	//window.alert("img" + divId);

	if (setDisplay == 'none') setDisplay = 'block';
	else if (setDisplay == 'block')  setDisplay = 'none';
	else setDisplay = theDiv.style.display;

	if (setDisplay == 'none') {
		theDiv.style.display = 'block';
		theImg.src = theImgBlockOpen.src;
	}
	else if (setDisplay == 'block') {
		theDiv.style.display = 'none';
		theImg.src = theImgBlockClose.src;	
	} 

}

function ToggleDivDisplayWithImages(divId, imgDir, imgModifier) {
	/* 
	** Function to toggle display of a div between 'display' and 'none'
	**
	** Dominik - 2004-12-30
	*/

	var theDiv = document.getElementById(divId);
	var theImgBranch = document.getElementById("imgBranch" + divId);
	var theImgFolder = document.getElementById("imgFolder" + divId);
	
	var imgOpenedBranchSrc = imgDir + '/minus' + imgModifier + '.gif';
	var imgClosedBranchSrc = imgDir + '/plus' + imgModifier + '.gif';
	var imgOpenedFolderSrc = imgDir + '/folder-expanded.gif';
	var imgClosedFolderSrc = imgDir + '/folder.gif';
	
	if (theImgBranch.src.indexOf(imgClosedBranchSrc) != -1) {
		theDiv.style.display = 'block';
		theImgBranch.src = imgOpenedBranchSrc;
		if (theImgFolder != undefined) {
			theImgFolder.src = imgOpenedFolderSrc;
		}
	} else {
		theDiv.style.display = 'none';
		theImgBranch.src = imgClosedBranchSrc;
		if (theImgFolder != undefined) {
			theImgFolder.src = imgClosedFolderSrc;
		}
	}
}


function checkElm(action, elm, checked, id) {
	/*
	** Cette fonction permet d'automatiser la distribution de l'action coché des parents aux enfants
	** 
	** 31-08-2004 : Phil L. - création
	*/

	// on assigne l'action a prendre si aucune action est défini
	if (action == ""){
		if (checked) action = "checkElm";
		else action = "unCheckElm";
	}
	
	// on fait un tableau des éléments parents avec le nom hiérarchique de l'élément courant
	arrayParents = elm.split('-');
	
	// on va chercher l'élément
	objElm = window.document.getElementById("chk" + id + "-" + elm);
	
	// quand l'élement est null on sort de la récursion
	if (objElm == null) return;
	
	if (action == "checkElm" || action == "checkElmChilds"){
		// on check l'élément
		objElm.checked = checked;
	
		// on vérifie si tous les enfants du même niveau hiérarchique sont coché si oui on coche le parent
		if (action == "checkElm") {
			checkElm("checkParents", elm, checked, id);
		}
		
		arrayParents = elm.split('-');
		// on ajoute un element enfant
		arrayParents.push("1");
		
		elmChild = "";
		
		// on construit le nouveau élément enfant
		for(i=0;i<arrayParents.length;i++){
			if (elmChild != "") elmChild += "-";
				elmChild += arrayParents[i];
				
		}
		
		// permet ouvrir le block div de l'élément courant pour afficher ses enfants
		if (document.getElementById('block-'+objElm.value)) ToggleDivDisplay('block-'+objElm.value,'block');

		//on rappel la fonction avec l'élément enfant
		checkElm("checkElmChilds", elmChild, checked, id);

		// on vérifit si l'élément courant est un enfant de l'élément initial
		if (action == "checkElmChilds"){
			
			arrayParents = "";
			
			// on recharge l'élément courant
			arrayParents = elm.split('-');
			
			// on change l'élément courant pour l'élément suivante du même niveau
			arrayParents[arrayParents.length-1] = (parseInt(arrayParents[arrayParents.length-1]) + 1).toString();
			
			// construit l'élément 
			elmBrother ="";
			for(i=0;i<arrayParents.length;i++){
				if (elmBrother != "") elmBrother += "-";
				elmBrother += arrayParents[i];
			}
	
			// on rappel la fonction avec le prochain élément
			checkElm(action, elmBrother, checked, id);	
		}	

	}
	else if (action == "unCheckElm"){
		//
		// on vérifit si toutes les enfants sont cochés, si oui on empêche l'utilisateur
		// de décoché le parent.
		//
		
		// variable qui détermine si toute les enfants sont cochés
		allChildsAreChecks =1;
		compter = 1;
		
		// on va chercher le premier élement enfant
		objElmChild = window.document.getElementById("chk" + id + "-" + elm + "-" + compter);
		
		// on vérifit si le premier élément n'est pas existant, si oui, c'est que l'élément courant 
		// ne possède pas d'enfant, donc on assigne imédiatement la variable qui détermine
		// si toute les enfant sont cochés à non.
		if (objElmChild==null) allChildsAreChecks = 0; 
		else {
			// sinon, on boucle sur les enfants de l'élément courant pour vérifier s'il sont tous cochés
			while(objElmChild!=null && allChildsAreChecks!=0){
				compter++;	

				// on vérifit si l'élément est coché
				if (objElmChild.checked == false){
					allChildsAreChecks = 0;
				}
				// on va cherché l'élément enfant suivant
				else objElmChild = window.document.getElementById("chk" + id + "-" + elm + "-" + compter);	
			}
		}
		
		// si tous les enfants de l'élément courant sont cochés, 
		// on va déchoché tous les enfants et parents de cette branche
		if (allChildsAreChecks==1){
			 	checkElm("checkElm", elm, false, id);
		}
		else {
			// sinon on le décoche et on rappel la même fonction avec l'élément parent de l'élément courant
			// pour vérifier si a son tour il doit être décoché
			objElm.checked = false;
			
			elmParent = "";
			// on construit l'élément parent
			for(i=0;i<arrayParents.length-1;i++){
				if (elmParent != "") elmParent += "-";
				elmParent += arrayParents[i];
			}
			// on rappel la meme fonction avec le parent
			checkElm(action,elmParent,checked,id);	
		}
	}
	else if (action == "checkParents"){
		
		elmParent="";
		
		// on construit l'élément parent à l'élément courant
		for(i=0;i<arrayParents.length-1;i++){
			if (elmParent != "") elmParent += "-";
			elmParent += arrayParents[i];
		}	
		// on charge l'élément parent
		objElmParent = window.document.getElementById("chk" + id + "-" + elmParent);
		
		//si l'élément parent est null on arrête la récursion
		if (objElmParent == null) return;	
		
		elmBrother = "";
		allBrothersAreChecks =1;
		
		// on va cherche le premier élément du niveau hiérarchique courant
		arrayParents[arrayParents.length-1] = "1";
		for(i=0;i<arrayParents.length;i++){
			if (elmBrother != "") elmBrother += "-";
			elmBrother += arrayParents[i];
		}
		
		// on charge le premier élément du niveau courant
		objElmBrother = window.document.getElementById("chk" + id + "-" + elmBrother);
		
		//
		// on boucle sur toute les éléments du niveau de hiérarchie courant
		// pour vérifier s'il sont tous cochés, si oui on devra cocher l'élément parent.
		//
		
		while(objElmBrother!=null && allBrothersAreChecks!=0){
			elmBrother="";
			
			// si l'élément n'est pas coché, alors on indique qu'il y a au moins un élément qui n'est pas coché
			if (objElmBrother.checked == false) allBrothersAreChecks = 0;
			else {
				// sinon on charge l'élément suivant du niveau de hiérarchie courant
				arrayParents[arrayParents.length-1] = (parseInt(arrayParents[arrayParents.length-1]) + 1).toString();
				// on construit l'élément suivant
				for(i=0;i<arrayParents.length;i++){
					if (elmBrother != "") elmBrother += "-";
					elmBrother += arrayParents[i];
				}
				// on charge l'objet
				objElmBrother = window.document.getElementById("chk" + id + "-" + elmBrother);	
						
			}
		}
	
		// si tous les éléments du niveau hiérarchique sont cochés, alors on coche son parent
		// sinon on déchoche
		// et on appel la même fonction avec son parent
		if (allBrothersAreChecks == 1) objElmParent.checked = true;
		else objElmParent.checked = false;
		checkElm(action, elmParent, checked, id);
			
	}


}
	
function getCurrentLocation(acode){
	ie = (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4) ? true : false;
	dom = (document.createElement && document.appendChild && document.getElementsByTagName) ? true : false;
    url = "";
    if (acode == 'osv') {
	    if (!ie){
		    url = encodeURIComponent(document.getElementById('opacsv').src);
	    }
	    else{
			url = encodeURIComponent(document.opacsv.location.href);
	    }
    }else{
		url = encodeURIComponent(document.location.href);
    }
    //alert(url);
    return url;
}

function sendThisPage(acode){
    
    //window.location = "http://10.0.0.21:4270/index.php?acode=osvsend&sourceacode="+acode+"&srcurl="+getCurrentLocation(acode);
    //if (acode != 'osvsend'){
    //    window.location.href = "http://"+window.location.host+"/index.php?acode=osvsend&sourceacode="+acode+"&srcurl="+getCurrentLocation(acode);
    //}
    if (acode != 'osvsend'){
        document.frmSendPage.sourceacode.value = acode;
        document.frmSendPage.srcurl.value = getCurrentLocation(acode);
        document.frmSendPage.submit();
    }

    return false;
}

function testThisPage(acode){
    
			url = encodeURIComponent(document.getElementById('opacsv').location.href);
		    //url = encodeURIComponent(frames['opacsv'].location.href);
		    //alert(url);

    return false;
}

/**************************************************
* end code for hierarchical option lists
***************************************************/
