
// from http://www.faqts.com/knowledge_base/view.phtml/aid/1939/fid/128 - How to read the styles of a style class?
function GetStyleClass (className) {

  var re = new RegExp("\\." + className + "$", "gi");
  
  if (document.all) {
  
    for (var s = 0; s < document.styleSheets.length; s++) {
      for (var r = 0; r < document.styleSheets[s].rules.length; r++) {
        if (document.styleSheets[s].rules[r].selectorText.search(re) != -1) {
          return document.styleSheets[s].rules[r].style;
        }
      }
    }
    
  } else if (document.getElementById) {
  
    for (var s = 0; s < document.styleSheets.length; s++) {
      for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) {
        if (document.styleSheets[s].cssRules[r].selectorText.search (re) != -1) {
          document.styleSheets[s].cssRules[r].sheetIndex = s;
          document.styleSheets[s].cssRules[r].ruleIndex = s;
          return document.styleSheets[s].cssRules[r].style;
        }
      }
    }
    
  } else if (document.layers) {
  
    return document.classes[className].all;
    
  }
  
  return null;
}


// from http://www.faqts.com/knowledge_base/view.phtml/aid/1939/fid/128 - How to read the styles of a style class?
function GetStyleClassProperty (className, propertyName) {
  var styleClass = GetStyleClass(className);
  if (styleClass)
    return styleClass[propertyName];
  else 
    return null;
}



function PopUpWindow(url)
{
	win = window.open(url, "POPUP", "width=800,height=600,left=0,top=0,scrollbars=yes");
	win.focus();
	return false;
}



function SubmitForm(senderId, value)
{
	theform = document.forms[0];
	theform.__EVENTTARGET.value = document.getElementById (senderId).name;
	theform.__EVENTARGUMENT.value = value;
	theform.submit();
}



// ImageListBox Handling

// Multiselect listbox with some unselectable items, some items with images.
// There can be an "ALL" valued item.
// There can be several special "ALLxxxx" items.
// And there can be several "SEPARATOR" items.
// Moreover the selectbox can be swithed by selecting images.*
// * Modified to click the search button.

/* Sample usage

	<option value="ALL">[Alle]</option>
	<option value="SEPARATOR">-----</option>
	<option value="ALLVOL">[Alle Bezirke in Vorarlberg]</option>
	<option value="196616">Bludenz</option>
	<option value="196617">Bregenz</option>
	<option value="196623">Dornbirn</option>
	<option value="196624">Feldkirch</option>
	<option value="SEPARATOR">-----</option>
	<option value="RESTOFAU">Rest of Austria</option>
	<option value="65546">Deutschland</option>
	<option value="65547">Schweiz</option>
	<option value="65548">Lichenstein</option>
*/


var ImageListBox_LISTBOXBUTTON;			// id of the submit button
var ImageListBox_LISTBOXDIV;				// id of the listbox control
var ImageListBox_HIGH;							// id pre-tag of the highlight images
var ImageListBox_SEL;								// id pre-tag of the selected images

var ImageListBoxItem_Selectable;		// item is selectable or not
var ImageListBoxItem_SelectedSave;	// save of previous listbox selection

var goin;                           // hover in 
var goout;                          // hover out
var goopt;                          // getoptions


function ImageListBox_Init (listboxbutton, listboxdiv, highlight, select)
{
	ImageListBox_LISTBOXBUTTON = listboxbutton;
	ImageListBox_LISTBOXDIV = listboxdiv;
  
	ImageListBox_HIGH = highlight;
	ImageListBox_SEL = select;
	
	ImageListBoxItem_Selectable = new Array();
	ImageListBoxItem_SelectedSave = new Array();
}


function ImageListBox_Item (id, selectable, selected)
{
	ImageListBoxItem_Selectable[id] = selectable;
	ImageListBoxItem_SelectedSave[id] = selected
}


function ImageListBox_Start ()
{
	for (id = 0; id < ImageListBox_GetOptions().length; id++)
	{
		if (ImageListBoxItem_SelectedSave[id])
		{
			ImageListBox_GetOption(id).selected = true;
		}
	}

	ImageListBox_DoSelect ();
}


function ImageListBox_AreaOver (id)
{
	goin = document.getElementById (ImageListBox_HIGH + id);
  if (goin)
    goin.style.visibility = "visible";
}


function ImageListBox_AreaOut (id)
{
	goout = document.getElementById (ImageListBox_HIGH + id);
  if (goout)
    goout.style.visibility = "hidden";
}


function ImageListBox_AreaClick (clickid)
{
	for (id = 0; id < ImageListBox_GetOptions().length; id++)
	{
		ImageListBox_GetOption(id).selected = (id == clickid);
	}
	
	ImageListBox_DoSelect ();
	
	ImageListBox_Submit ();
}


function ImageListBox_ListboxChange ()
{
	var id;

	var nonSelectableSelected = false;
	for (id = 0; id < ImageListBox_GetOptions().length; id++)
	{
		if (!ImageListBoxItem_Selectable[id] && ImageListBox_GetOption(id).selected)
		{
			nonSelectableSelected = true;
			break;
		}
	}
	
	if (nonSelectableSelected) // restore saved state
	{
		for (id = 0; id < ImageListBox_GetOptions().length; id++)
		{
			ImageListBox_GetOption(id).selected = ImageListBoxItem_SelectedSave[id];
		}
	}

	ImageListBox_DoSelect ();
}


function ImageListBox_DoSelect ()
{
	var id, value, selected;
	var all = false;
	var allspec = false;
	for (id = 0; id < ImageListBox_GetOptions().length; id++)
	{
		selected = ImageListBox_GetOption(id).selected;
		value = ImageListBox_GetOption(id).value;
		
		if (value == "ALL" && selected)
		{
			all = true;
		}
		else if (value.substr(0, 3) == "ALL")
		{
			allspec = selected;
			if (all)
			{
				ImageListBox_GetOption(id).selected = false;	// deselect item
				selected = false;
			}
		}
		else if (value == "SEPARATOR")
		{
			allspec = false;
		}
		else
		{
			if (all || allspec)
			{
				ImageListBox_GetOption(id).selected = false;	// deselect item
				selected = false;
			}
		}

		ImageListBoxItem_SelectedSave[id] = selected;
		
		if (document.getElementById (ImageListBox_SEL + id) != null)
		{
			if (all || allspec || selected)
			{
				document.getElementById (ImageListBox_SEL + id).style.visibility = "visible";
			}
			else
			{
				document.getElementById (ImageListBox_SEL + id).style.visibility = "hidden";
			}
		}
	}
}


function ImageListBox_GetOptions ()
{
  goopt = document.getElementById (ImageListBox_LISTBOXDIV);
  if (goopt) 
	  return goopt.options;
  else
    return new Array();
}


function ImageListBox_GetOption (value)
{
	var options = ImageListBox_GetOptions();
	
	if (!parseInt(value, 10) && value != 0)
	{
		var id;
		for (id = 0; id < options.length; id++)
		{
			if (options[id].value == value)
			{
				return options[id];
			}
		}
		return null;
	}
	else
	{
		return options[value];
	}
}

function ImageListBox_Submit ()
{
	theform = document.forms[0];
	theform.submit();
}

// daniel rudigier

function init_imagelist(seltype, selbez)
{
  ImageListBox_Init ('regio_search', 'select_regio', 'Search1_HIGH', 'Search1_SEL');
  ImageListBox_Item (0, true, false);
  ImageListBox_Item (1, true, false);
  ImageListBox_Item (2, true, false);
  ImageListBox_Item (3, true, false);
  ImageListBox_Item (4, true, false);
  ImageListBox_Item (5, true, false);
  ImageListBox_Item (6, true, false);
  ImageListBox_Item (7, true, false);
  ImageListBox_Item (8, true, false);
  ImageListBox_Item (9, true, false);
  ImageListBox_Item (10, true, false);
  ImageListBox_Item (11, true, false);
  ImageListBox_Start ();

  for (var id = 0; id < ImageListBox_GetOptions().length; id++)
  {
	  ImageListBox_GetOption(id).selected = (id == selbez);          
	}
	
 ImageListBox_DoSelect ();
}


