var SEP = '$$'; var WEB_SEP = '$'; function deleteOption(object,index) {    object.options[index] = null;}function addOption(object,text,value, flagselected) {    var defaultSelected = false;    var selected = false;    var optionName = new Option(text, value, defaultSelected, selected)    object.options[object.length] = optionName;    object.options[object.length-1].selected =flagselected;    }function clearOptions (what){ for (var i=what.options.length-1;i>-1;i--)        deleteOption(what,i);}function compareText (option1, option2) {  return option1.text < option2.text ? -1 :    option1.text > option2.text ? 1 : 0;}function compareValue (option1, option2) {  return option1.value < option2.value ? -1 :    option1.value > option2.value ? 1 : 0;}function compareTextAsFloat (option1, option2) {  var value1 = parseFloat(option1.text);  var value2 = parseFloat(option2.text);  return value1 < value2 ? -1 :    value1 > value2 ? 1 : 0;}function compareValueAsFloat (option1, option2) {  var value1 = parseFloat(option1.value);  var value2 = parseFloat(option2.value);  return value1 < value2 ? -1 :    value1 > value2 ? 1 : 0;}

function compareTextAsFloatDesc (option1, option2) {  var value1 = parseFloat(option1.value);  var value2 = parseFloat(option2.value);  return value1 > value2 ? -1 :    value1 < value2 ? 1 : 0;}function sortSelect (select, compareFunction) {  if (!compareFunction)    compareFunction = compareText;  var options = new Array (select.options.length);  for (var i = 0; i < options.length; i++)    options[i] =       new Option (        select.options[i].text,        select.options[i].value,        select.options[i].defaultSelected,        select.options[i].selected      );  options.sort(compareFunction);  select.options.length = 0;  for (var i = 0; i <= options.length; i++) {	//alert('loop' + i);	if (options[i] != null ) {		select.options[i] = options[i];	}	}}function middleString(fullString, startString, endString) {   if (fullString.indexOf(startString) == -1) {      return "";   } else {      var sub = fullString.substring(fullString.indexOf(startString)+startString.length, fullString.length);           if (sub.indexOf(endString) == -1) {         return sub;      } else {         return (sub.substring(0, sub.indexOf(endString)));      }   }}function refreshTrail(){   var divcriteria = document.getElementById ( "searchcriteria");   text = '<div class="trailer">' ;text += '&#160;<a href="javascript:downloadHome()">' + topmsg +  "</a>&#160;&#187;"; for ( i=0 ; i < arrchoices.length ; i++ )   {     text += '&#160;<a href="javascript:previousCateg('+  i + ')">' + arrchoices[i]+ "</a>&#160;&#187;";   }text += "</div>";text += '<div class="toto1" align="left">';text += '&#160;<select name="download_search_categ" class="select_down" id="download_search_categ" onchange="nextCateg () ;"></select>'; text +='&#160;<input type="button" name="launchbut" value="Launch" class="launch" onclick="dosearch();" />'; text += "</div>";  divcriteria.innerHTML= text;}// This function is called as far as the javascript that contains the categories is loadedfunction initSearchCateg(){    while ( loadedjs ==false)    { setTimeout("initSearchCateg();" , 100);}   firstcateg="";      arrchoices = new Array();    refreshTrail ();        refreshCategOptions ();          toggle('pleasewait') ;   toggle('searchtool') ; }function toggle(id) {    var element = document.getElementById(id);   // alert ("" + id + " --> " + document);    with (element.style) {        if ( display == "none" ){            display = ""        } else{            display = "none"        }    }}    function previousCateg ( pos ) {	toggle('pleasewait') ;	 toggle('searchtool') ; 	// firstcateg=arrchoices[arrchoices.length-1] ;	while ( arrchoices.length > pos )	{	  arrchoices.pop();	  }	 refreshTrail ();     	 refreshCategOptions ();               toggle('searchtool') ; 	 toggle('pleasewait') ;	 	}function nextCateg () {	toggle('pleasewait') ;	toggle('searchtool') ; 	 field_select_categ = document.getElementById('download_search_categ');    for (var i=field_select_categ.options.length-1;i>-1;i--)    {        if (field_select_categ.options[i].selected)        {            if ( field_select_categ.options[i].value != "$ALL$" )            {           	//	firstcateg= field_select_categ.options[i].value + SEP;		        arrchoices.push(field_select_categ.options[i].value);        	  }           break;        }    }        refreshTrail ();         refreshCategOptions ();      toggle('searchtool') ;     toggle('pleasewait') ;      }function refreshCategOptions (){     field_select_categ = document.getElementById('download_search_categ');     var  arrFirstCateg = new Array ();     var hashtableCateg = new Array();     var j = 0 ;     firstcateg = '';     for (  i= 0 ; i < arrchoices.length ; i++)     {       if ( arrchoices[i] != '')       {         firstcateg += arrchoices[i] + SEP;       }     }//     firstcateg = arrchoices.concat (SEP);	for (  i=0 ; i < arrcateg.length ; i++ )	{              	            categtemp  = middleString( arrcateg[i] , firstcateg, SEP) ; //            alert ( arrcateg[i] + " == " + "**" +  categtemp + "**");             					if ( hashtableCateg[categtemp] == null) 		{			arrFirstCateg [ j ]  = categtemp ; 			hashtableCateg[categtemp] = categtemp;			j++;		} 			        	} 	clearOptions (field_select_categ);  	cptopt = 0 ;//       addOption(field_select_categ, '<i18n:text i18n:key="downloadcenter.categ.all">-All-</i18n:text>','$ALL$')	;	    
	typedata= "";
	sortfn = compareText;	for (j=0 ; j < arrFirstCateg.length ; j++ )	{	   if ( arrFirstCateg[j] != '') 	   {
	    label =arrFirstCateg[j];
		value = arrFirstCateg[j];
		
			if (label.match(/^[\d\.]+$/) ) sortfn =compareTextAsFloatDesc;
			else sortfn= compareText;		 addOption(field_select_categ,label,value, false)	;			 cptopt ++;		 }				 	 }	   	sortSelect(field_select_categ, sortfn);
	addOption(field_select_categ, '-All-','$ALL$' , true)	;	    (cptopt== 0 ) ? field_select_categ.style.display='none': field_select_categ.style.display='inline';}  function resetsearch()     {		lang = document.forms[0].download_search_lang.value;        mod = document.forms[0].download_search_mod.value;
		
		
	   if (lang=='' || mod=='') 
	   {
	    // alert (error_select_msg);
		  return;
	   }
	           url = pathdown+ "/preparesearch?mod="+ mod + "&lang="+ lang ;   
		        arrchoices= new Array();             document.location = url;     }            function dosearch()     {
	       lang = document.forms[0].download_search_lang.value;       mod = document.forms[0].download_search_mod.value;
	          if (lang=='' || mod=='') 
	   {
	    //  alert (error_select_msg);
		  return ;
	   }
	   
	          categ = "";       for ( i=0 ; i < arrchoices.length ; i++ )       {               categ += arrchoices[i] + WEB_SEP ;        }             document.forms[0].download_search_choices.value =  categ ;              url = pathdown+ "/dosearch/@isnew/desc" + "?mod="+ mod + "&lang="+ lang + "&categories="+ categ  ; 
	   
	  // alert (url);//        document.location = url;          document.forms[0].action= url ;          document.forms[0].method="POST";	      document.forms[0].submit();	           }