// JS Stuff - Cross-browser compatible
// Last modified: 17.12.2004

// Emulate 'disable' function for incompatible browsers
// Browser, from version(major&minor), up to version(excl.)
// Netscape from 4.0 up to 7.0, Opera from 5.0 up to 7.0,
// Opera from 7.1 up to 7.6, Internet Explorer from 4.0 up to 7.0

var emu_disable = new Array('ns',40,70,'op',50,70,'op',71,76,'ie',40,70);

// Recogize current browser type/version
function CBrowser()
{
 var b=navigator.appName;
 var bw = this;
 if (b.indexOf('Netscape')!=-1) bw.b="ns";
 else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) bw.b = "op";
 else if (b=="Microsoft Internet Explorer") bw.b="ie";
 bw.version=navigator.appVersion;
 bw.v=parseInt(bw.version);
 bw.ns=(bw.b=="ns" && bw.v>=4);
 bw.ns4=(bw.b=="ns" && bw.v==4);
 bw.ns6=(bw.b=="ns" && bw.v==5);
 bw.ie=(bw.b=="ie" && bw.v>=4);
 if (bw.ns6 && navigator.userAgent.indexOf("Netscape") == -1) { bw.b = "mz"; bw.mz = true; }
 bw.ie4=(bw.version.indexOf('MSIE 4')>0);
 if(bw.ie)
  {
   var regex = new RegExp("MSIE (\\d)\\.(\\d)");
   var resarr = regex.exec(bw.version);
   bw.ie_version = parseInt(RegExp.$1)*10+parseInt(RegExp.$2);
   bw.version = bw.ie_version;
  }
 bw.opera=(bw.b=="op" && (navigator.userAgent.indexOf('Opera ')>0)?true:false);
 if(bw.opera)
  {
   var regex = new RegExp("Opera (\\d)\\.(\\d)");
   var resarr = regex.exec(navigator.userAgent);
   bw.op_version = parseInt(RegExp.$1)*10+parseInt(RegExp.$2);
   bw.version = bw.op_version;
 }
 if(bw.ns6 && !bw.mz)
  {
   var regex = new RegExp("Netscape\\d?\/(\\d)\\.(\\d)");
   var resarr = regex.exec(navigator.userAgent);
   bw.ns_version = parseInt(RegExp.$1)*10+parseInt(RegExp.$2);
   bw.version = bw.ns_version;
  }
 if(bw.ns4)
  {
   var regex = new RegExp("(\\d)\\.(\\d)");
   var resarr = regex.exec(bw.version);
   bw.ns_version = parseInt(RegExp.$1)*10+parseInt(RegExp.$2);
   bw.version = bw.ns_version;
  }
 if(bw.mz)
  {
   var regex = new RegExp("Mozilla(.*)rv:(\\d)\\.(\\d)");
   var resarr = regex.exec(navigator.userAgent);
   bw.mz_version = parseInt(RegExp.$2)*10+parseInt(RegExp.$3);
   bw.version = bw.mz_version;
  }
 bw.dom=(document.getElementById)?true:false;
 var ua=navigator.userAgent.toLowerCase();
 if (ua.indexOf("win")>-1) bw.platform="win32";
 else if (ua.indexOf("mac")>-1) bw.platform="mac";
 else bw.platform="other";
 bw.emu_flag = -1;
 return(true);
};
CBrowser.prototype.CBrowser = CBrowser;

// Make a simple object with browser's properties
MyBrowser = new CBrowser();

// Check up emu status for current browser
function GetEmuStatus()
{
 if(MyBrowser.emu_flag != -1) return MyBrowser.emu_flag;
 var i;
 for(i=0;i<emu_disable.length;i+=3)
  {
   if(emu_disable[i] == MyBrowser.b)
    {
     if(parseInt(emu_disable[i+1]) <= parseInt(MyBrowser.version) && emu_disable[i+2] > MyBrowser.version)
      {
       MyBrowser.emu_flag = true;
       return(true);
      }
    }
  }
 MyBrowser.emu_flag = false;
 return(false);
}

// Disable/Enable cross-browser function
// Input: (s,i,b) = (select object, index of selected option, bool/disabled?)
function SetOptionStatus(s,i,b)
{
 if(typeof(s.options[i]) != "undefined")
  {
   var so = s.options[i];
   if(GetEmuStatus())
    {
     if(typeof(so.style) != "undefined")
      {
       if(!b)
        {
         so.style.color = 'black';
        }
       else
        {
         so.style.color = 'gray';
        }
      }
    }
   
   if(!b)
    {
     if(!GetEmuStatus()) so.disabled = b;
     if(typeof(so.innerHTML) != "undefined" && so.innerHTML.length > 0 && so.disabled_flag)
      {
       if(typeof(so.o_innerHTML) != "undefined") so.innerHTML = so.o_innerHTML;
      }
    }
   else
    {
     if(typeof(so.innerHTML) != "undefined" && so.innerHTML.length > 0 && !so.disabled_flag)
      {
       so.o_innerHTML = so.innerHTML;
       so.innerHTML = "&nbsp;&nbsp;&nbsp;"+so.innerHTML+' (n/a)';
      }
     if(!GetEmuStatus()) so.disabled = b;
    }
   so.disabled_flag = b;
  }
}

// Raise error when user select incompatible option
// Input: (s,n) = (select object, name of select)
function WrongOption(s,n)
{
 if(typeof(s) != "undefined")
  {
   if(s.selectedIndex > 0 && s.options[s.selectedIndex].disabled_flag)
    {
     alert("Sorry, no data available for that category.\nPlease select another "+n);
     s.selectedIndex = 0;
    }
   else return(false);
  }
 return(true);
}

// Search specified area of database

function setFilter(mform) {

	if (mform.Subject.selectedIndex > 0) {
		filter_subj = mform.Subject.options[mform.Subject.selectedIndex].value;
	} else {
		filter_subj = '[a-zA-Z0-9]*';
	}

	if (mform.aType.selectedIndex > 0) {
		filter_atype = mform.aType.options[mform.aType.selectedIndex].value;
	} else {
		filter_atype = '[a-zA-Z0-9]*';
	} 

	if (mform.Country.selectedIndex > 0) {
		filter_country = mform.Country.options[mform.Country.selectedIndex].value;
	} else {
		filter_country = '[a-zA-Z0-9]*';
	}

	my_filter = '\/' + filter_country + '\/' + filter_subj + '\/' + filter_atype + '\/';
	mform.filter.value = my_filter;
}



//Problem - user might reorder OPTIONS array
// user might also have less options in the form than we have logically
// look up "real" id by value
// option 0 is always 'ANY'
function OptionsbyID(mform) {

	NUM_COPTS = mform.Country.options.length;
	NUM_SOPTS = mform.Subject.options.length;
	NUM_TOPTS = mform.aType.options.length;

	if ((NUM_COPTS > NUM_COUNTRIES) || (NUM_SOPTS > NUM_SUBJECTS) || (NUM_TOPTS > NUM_TYPES)) {
		alert("Error on form - number of options cannot be greater than available.  Please contact National Law Center to report this error.") ;
		alert(NUM_COPTS + ":" + NUM_COUNTRIES + " " + NUM_SOPTS + ":" + NUM_SUBJECTS + " " + NUM_TOPTS + ":" + NUM_TYPES);
	}

	copts = new Array(NUM_COUNTRIES);
	sopts = new Array(NUM_SUBJECTS);
	topts = new Array(NUM_TYPES);

	for (j=1; j<NUM_COUNTRIES; j++) {
		copts[j] = -1;
	}
	for (j=1; j<NUM_SUBJECTS; j++) {
		sopts[j] = -1;
	}
	for (j=1; j<NUM_TYPES; j++) {
		topts[j] = -1;
	}


	for (sopt=1; sopt<NUM_SOPTS; sopt++) {
	     my_sid = subject[mform.Subject.options[sopt].value];
	     sopts[my_sid] = sopt;
	}
		
	for (topt=1; topt<NUM_TOPTS; topt++) {
	     my_tid = atype[mform.aType.options[topt].value];
	     topts[my_tid] = topt;
	}

	for (copt=1; copt<NUM_COPTS; copt++) {
	     my_cid = country[mform.Country.options[copt].value];
	     copts[my_cid] = copt;
	}
	LoadedOptions = 1;
}


function AdjustSubjects(mform, tid, mask, usemask) {

	// Adjust Subjects array
	for (j=0; j<NUM_SUBJECTS; j++) {

		if (usemask > 0) {
			result = a[tid][j] & mask;
		} else {
			result = a[tid][j];
		}

		if (sopts[j] > 0) {
			if (result > 0) {
				//mform.Subject.options[sopts[j]].disabled = false;
				SetOptionStatus(mform.Subject,sopts[j],false);
			} else {
				//mform.Subject.options[sopts[j]].disabled = true;
				SetOptionStatus(mform.Subject,sopts[j],true);
			}
		}
	}
}


function AdjustTypes (mform, sid, mask, usemask) {

       	// Adjust Types array
	for (j=0; j<NUM_TYPES; j++) {
		if (usemask > 0) {
			result = a[j][sid] & mask;
                                                                                              
		} else {
			result = a[j][sid];
		}
		
		if(topts[j] >0 ) {
			if (result > 0) {
				//mform.aType.options[topts[j]].disabled = false;
				SetOptionStatus(mform.aType,topts[j],false);
			} else {
				//mform.aType.options[topts[j]].disabled = true;
				SetOptionStatus(mform.aType,topts[j],true);
			}
		}
	}

}

function AdjustCountries (mform,tid,sid) {

	// Adjust Country array
	mask = 1;
	for (i=0; i<NUM_COUNTRIES; i++) {
	
		if (copts[i] > 0) {
			if ( (a[tid][sid] & mask) > 0) {
				//mform.Country.options[copts[i]].disabled = false;
				SetOptionStatus(mform.Country,copts[i],false);
			} else {
				//mform.Country.options[copts[i]].disabled = true;
				SetOptionStatus(mform.Country,copts[i],true);
			}
		}
		mask *= 2;
	}
}

function AdjustCountriesbySubject (mform,sid) {
	// Adjust Country array - if possible for any type, turn on option
	mask = 1;
	for (i=0; i<NUM_COPTS; i++) {
	
		if (copts[i] > 0) {
			//mform.Country.options[copts[i]].disabled = true;
			SetOptionStatus(mform.Country,copts[i],true);

			for (k=0; k<NUM_TYPES; k++) {
		
				if ( (a[k][sid] & mask) > 0) {
					//mform.Country.options[copts[i]].disabled = false;
					SetOptionStatus(mform.Country,copts[i],false);
				}
			}
		}
		mask *= 2;
	}
}

function AdjustCountriesbyType (mform,tid) {
	// Adjust Country array - if possible for any subject, turn on option
	
	mask = 1;
	for (i=0; i<NUM_COUNTRIES; i++) {
	
		if (copts[i] > 0) {
			//mform.Country.options[copts[i]].disabled = true;
			SetOptionStatus(mform.Country,copts[i],true);

			for (j=0; j<NUM_SUBJECTS; j++) {

				if ( (a[tid][j] & mask) > 0) {
			
					//mform.Country.options[copts[i]].disabled = false;
					SetOptionStatus(mform.Country,copts[i],false);
					// next i
				}
			}
		}
		mask *= 2;
	}
}

function AdjustTypesbyCountry (mform, cid) {
	mask = 1;
	for (j=0; j<cid; j++) { mask *= 2; }

	for (k=0; k<NUM_TYPES; k++) {
	
		if (topts[k] > 0) {
			//mform.aType.options[topts[k]].disabled = true;
			SetOptionStatus(mform.aType,topts[k],true);
		
			for (j=0; j<NUM_SUBJECTS; j++) {
				if ( (a[k][j] & mask) > 0) {
					//mform.aType.options[topts[k]].disabled = false;
					SetOptionStatus(mform.aType,topts[k],false);
				}
			}
		}
	}	
}

function AdjustSubjectsbyCountry (mform, cid) {
	mask = 1;
	for (j=0; j<cid; j++) { mask *= 2; }
	for (j=0; j<NUM_SUBJECTS; j++) {
		if (sopts[j] > 0) {
			//mform.Subject.options[sopts[j]].disabled = true;
			SetOptionStatus(mform.Subject,sopts[j],true);
			
			for (k=0; k<NUM_TYPES; k++) {
				if ((a[k][j] & mask) > 0) {
					//mform.Subject.options[sopts[j]].disabled = false;
					SetOptionStatus(mform.Subject,sopts[j],false);
				}
			}
		}
	}	
}

// There is always one more option - 'ANY' - than we have actual choices
// We shouldn't need to enable ANY because it never should be disabled, but just in case
function AllTypes (mform) {
	for (j=0; j<NUM_TOPTS; j++) {
		//mform.aType.options[j].disabled = false;
		SetOptionStatus(mform.aType,j,false);
	}
}

function AllSubjects (mform) {
	for (j=0; j<NUM_SOPTS; j++) {
		//mform.Subject.options[j].disabled = false;
		SetOptionStatus(mform.Subject,j,false);
	}
}

function AllCountries (mform) {
	for (j=0; j<NUM_COPTS; j++) {
		//mform.Country.options[j].disabled = false;
		SetOptionStatus(mform.Country,j,false);
	}
}




function newSubject (mform) {
	WrongOption(mform.Subject,'Subject');
	sid = subject[mform.Subject.options[mform.Subject.selectedIndex].value];
	tid = atype[mform.aType.options[mform.aType.selectedIndex].value];
	cid = country[mform.Country.options[mform.Country.selectedIndex].value];

	if ( LoadedOptions == 0) {
		OptionsbyID(mform);
	}

	mask = 1;
	for (j=0; j<cid; j++) { mask *= 2; }
	
 	if (mform.Subject.selectedIndex > 0) {

		AdjustTypes(mform,sid,mask,mform.Country.selectedIndex);

		if ((tid != null) && (mform.aType.selectedIndex > 0)) {
			AdjustCountries(mform,tid,sid);

		} else {  // We have specific Subject, ANY type - adjust countries

			AdjustCountriesbySubject(mform, sid);
		}
	} else {  // ANY subject

		if ((tid != null) && (mform.aType.selectedIndex > 0)) {  // specific Type

			AdjustCountriesbyType(mform, tid);				

			if (mform.Country.selectedIndex > 0) {  // specific Country
				AdjustTypesbyCountry(mform, cid);
			} else {  // ANY country
				AllTypes(mform);
			}

		} else {  // ANY Type
			AllCountries(mform);
			if (mform.Country.selectedIndex > 0) {  // specific Country
				AdjustTypesbyCountry(mform, cid);
			} else {				// ANY Country
				AllTypes(mform);
			}			
		}

	
	}
}



function newType (mform) {
	WrongOption(mform.aType,'Type');
	sid = subject[mform.Subject.options[mform.Subject.selectedIndex].value];
	tid = atype[mform.aType.options[mform.aType.selectedIndex].value];
	cid = country[mform.Country.options[mform.Country.selectedIndex].value];

	if ( LoadedOptions == 0) {
		OptionsbyID(mform);
	}

	mask = 1;
	for (j=0; j<cid; j++) { mask *= 2; }
	
	if ((tid != null) && (mform.aType.selectedIndex > 0)) {
//alert("tid = "+tid);	
		AdjustSubjects(mform, tid, mask, mform.Country.selectedIndex);

		if (mform.Subject.selectedIndex > 0) {
			AdjustCountries(mform,tid,sid);

		} else {  // We have specific Type, any Subject - adjust countries
			AdjustCountriesbyType(mform, tid);		
		}
	} else {  // ANY Type

		if (mform.Subject.selectedIndex > 0) {  // specific Subject

			AdjustCountriesbySubject(mform, sid);				

			if (mform.Country.selectedIndex > 0) {  // specific Country
				AdjustSubjectsbyCountry(mform, cid);
			} else {  // ANY country
				AllSubjects(mform);
			}

		} else {  // ANY Subject
			AllCountries(mform);
			if (mform.Country.selectedIndex > 0) {  // specific Country
				AdjustSubjectsbyCountry(mform, cid);
			} else {				// ANY Country
				AllSubjects(mform);
			}			
		}
	}
}


function newCountry(mform) {
	WrongOption(mform.Country,'Country');
	sid = subject[mform.Subject.options[mform.Subject.selectedIndex].value];
	tid = atype[mform.aType.options[mform.aType.selectedIndex].value];
	cid = country[mform.Country.options[mform.Country.selectedIndex].value];

	if ( LoadedOptions == 0) {
		OptionsbyID(mform);
	}

	numselected = 0;
	for (j=0; j<NUM_COPTS; j++) {
		if (mform.Country.options[j].selected) {
			numselected++;
		}
	}

	if (numselected == 1) {
		cselected = mform.Country.selectedIndex;
	} else {
		cselected = 0;
	}

	mask = 1;
	for (j=0; j<cid; j++) { mask *= 2; }

	if ((tid != null) && (mform.aType.selectedIndex > 0)) {
		AdjustSubjects(mform, tid, mask, cselected);

		if (mform.Subject.selectedIndex > 0) {

			AdjustTypes(mform, sid, mask, cselected);		
			
		} else { // ANY Subject
		
			if (cselected > 0) {

				AdjustTypesbyCountry(mform, cid);
				
			} else { //ANY Country				
				
				AllTypes(mform);
			}
		}

	} else {  // ANY Type

		if (cselected > 0) {  // specific Country
				AdjustSubjectsbyCountry(mform, cid);
		} else {  // ANY country
				AllSubjects(mform);
		}

		if (mform.Subject.selectedIndex > 0) {

			AdjustTypes(mform, sid, mask, mform.Country.selectedIndex);		
			
		} else { // ANY Subject

			if (cselected > 0) {  // specific Country
				AdjustTypesbyCountry(mform, cid);
			} else {  // ANY country
				AllTypes(mform);
			}
		}

	}
}

var validCombinations = new Array('!any;*;cl', '!any;*;pr', '!any;*;sm');
var selectedCombinations = new Array('!any;any;!any');
var selectedExceptions = new Array('any;any;tr;/interam/any/any/tr/index.htm','any;any;pj;/interam/any/any/pj/index.htm',
																	 'any;any;nv;/interam/any/any/nv/index.htm','mx;any;do;/interam/mx/any/do/index.htm',
																	 '!any;any;tn;/php/translations.php?c=[1]');
function selectionExceptions(arr,mfrm)
{
 var sel = new Array(mfrm.Country,mfrm.Subject,mfrm.aType);
 var i,j;
 for(j=0;j<arr.length;j++)
  {
	 var avc = arr[j].split(';');
	 if((avc[0].indexOf('!') == 0 ? eval('avc[0].substring(1) != sel[0].value') : eval('avc[0] == sel[0].value')) &&
	    (avc[1].indexOf('!') == 0 ? eval('avc[1].substring(1) != sel[1].value') : eval('avc[1] == sel[1].value')) &&
	    (avc[2].indexOf('!') == 0 ? eval('avc[2].substring(1) != sel[2].value') : eval('avc[2] == sel[2].value')))
	  {
	   if(avc[3].indexOf('[1]') >= 0)
	    {
	     var re = /\[1\]/i;
	     return(avc[3].replace(re,sel[0].value));
	    }
	   if(avc[3].indexOf('[2]') >= 0)
	    {
	     var re = /\[1\]/i;
	     return(avc[3].replace(re,sel[1].value));
	    }
	   if(avc[3].indexOf('[3]') >= 0)
	    {
	     var re = /\[1\]/i;
	     return(avc[3].replace(re,sel[2].value));
	    }
	   return(avc[3]);
	  }
	}
 return('');
}
function checkValidCombinations(arr,combs)
{
 for(j=0;j<arr.length;j++)
  {
	 var avc = arr[j].split(';');
	 var i,flag = 0;
	 for(i=0;i<combs.length;i++)
	  {
	   var cavc = avc[i].toLowerCase();
	   var invert = 0;
	   if(cavc.indexOf('!') != -1) { invert=1; cavc = cavc.substring(0,cavc.indexOf('!')) +
	   																								cavc.substring(cavc.indexOf('!')+1); }
	   if(((combs[i].toLowerCase() == cavc) ^ invert) && (cavc != '*')) continue;
	   if((cavc == '*') && !invert) continue;
	   flag=1;
	  }
	 if(!flag) return(true);
	}
 return(false);
}
function adjustSelects (mform) {
	if(typeof(mform) == 'undefined') return(false);
	var sc = mform.Country;
	var ss = mform.Subject;
	var st = mform.aType;
	
	var adj = new Array(sc.selectedIndex,ss.selectedIndex,st.selectedIndex);

	sc.selectedIndex = ss.selectedIndex = st.selectedIndex = 0;
	newType(mform); newSubject(mform); newCountry(mform);
	
	sc.selectedIndex = adj[0];
	newCountry(mform);
	
	ss.selectedIndex = adj[1];
	newSubject(mform);
	
	st.selectedIndex = adj[2];
	newType(mform);
}
function resetSelects (mform) {
	if(typeof(mform) == 'undefined') return(false);
	var sc = mform.Country;
	var ss = mform.Subject;
	var st = mform.aType;

	sc.selectedIndex = ss.selectedIndex = st.selectedIndex = 0;
	newType(mform); newSubject(mform); newCountry(mform);
}
function selectCheck(mfrm)
{
 if(typeof(mfrm) == 'undefined') return(false);
 var selects = new Array(mfrm.Country,mfrm.Subject,mfrm.aType);
 var mURL = selectionExceptions(selectedExceptions,mfrm);
 if(mURL != '')
  {
   document.location.href = mURL;
   return(false);
  }
 var i,mask=0;
 for(i=0;i<selects.length;i++)
  {
   var selected = (selects[i].selectedIndex == 0) ? 0 : 1;
   var ormask			= selected << i;
   mask 					= mask | ormask;
  }
 var flag = 0;
 for(i=selects.length-1;i>=0;i--)
  {
   var ormask			= 1 << i;
   if((mask & ormask) > 0) { flag = 1; }
   else if(flag == 1)
    {
     // Check also special cases before denay combination!
     var combs = new Array(mfrm.Country.value,mfrm.Subject.value,mfrm.aType.value);
	   if(checkValidCombinations(selectedCombinations,combs) && checkValidCombinations(validCombinations,combs))
	    {
	     return(true);
	    }
     alert("Sorry, no data available for that selection.\nPlease select a country first, then optionally subject and type.");
     return(false);
    }
  }
 return(true);
}
function searchOptionByName(select,name)
{
 var i;
 for(i=0;i<select.options.length;i++)
  {
   if(select.options[i].value == name) return(i);
  }
 return(0);
}
function adjustSelectsByURL (mform)
{
 if(typeof(mform) == 'undefined') return(false);
 var selects = new Array(mform.Country,mform.Subject,mform.aType);
 var functs  = new Array(newCountry,newSubject,newType);
 var data    = new Array(country,subject,atype);
 var i;
 for(i=selects.length-1;i>=0;i--)
  {
   selects[i].selectedIndex = 0;
  }

 var regex = new RegExp("\\/interam\\/");
 var href = document.location.href.toLowerCase();
 var resarr = regex.exec(href);
 if(resarr != null && resarr.length > 0)
  {
   resarr = href.substring(resarr.index+resarr[0].length).split("/");
  }

 if(resarr != null && resarr.length > 0)
  {
   for(i=0;i<resarr.length;i++)
    {
     if(resarr[i] != "" && i < selects.length)
      {
       var selection = resarr[i];
       selects[i].selectedIndex = searchOptionByName(selects[i],selection);
       var callfunct = functs[i];
       callfunct(mform);
      }
    }
  }
}
function generateCSTUrl(mform){
  if(typeof(mform) == 'undefined') return(false);
	var url = '/interam/';
	if(mform.Country.value != "" && mform.Country.value != "any")
	 {
	  url = url + mform.Country.value + '/';
	  if(mform.Subject.value != "" && (mform.Subject.value != "any" || mform.aType.value != "any"))
	   {
	    url = url + mform.Subject.value + '/';
	    if(mform.aType.value != "" && mform.aType.value != "any")
	     {
	      url = url + mform.aType.value + '/';
	     }
	   }
	 }
	document.location.href = url;
	return(false);
}

// Get selected options (more than one for multiselects)
function getSelectedOptions(s)
{
 var i;
 var results = new Array();
 for(i=0;i<s.options.length;i++)
  {
   if(s.options[i].selected)
    {
     results[results.length] = s.options[i].index;
    }
  }
 return(results);
}

function getIndexesByValue(s,opts)
{
 var results = new Array();
 var z;
 for(z=0;z<opts.length;z++)
  {
   var i;
	 for(i=0;i<s.options.length;i++)
	  {
	   if(s.options[i].value == opts[z])
	    {
	     results[results.length] = s.options[i].index;
	    }
	  }
	}
 return(results);
}

// Clear all options and select those in opts with state
function setSelectedOptions(s,opts,state)
{
 var i;
 for(i=0;i<s.options.length;i++)
  {
   s.options[i].selected = false;
  }
 for(i=0;i<opts.length;i++)
  {
   s.options[opts[i]].selected = state;
  }
}

// Set specific value (true/false) for some optoins.
function selectOptions(s,opts,state)
{
 var i;
 for(i=0;i<opts.length;i++)
  {
   s.options[opts[i]].selected = state;
  }
}

// Remove "All" option in case that there is another selected option (multiselect)!
function removeAllOption(s)
{
 var opts = getSelectedOptions(s);
 var i;
 var allflag = false;
 var notallflag = false;
 for(i=0;i<opts.length;i++)
  {
   if(opts[i] == 0) { allflag = true; }
   if(opts[i] != 0) { notallflag = true; }
  }
 if(allflag && notallflag) { selectOptions(s,new Array('0'),false); }
}
