
// 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


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)
{
	document.getElementById (ImageListBox_HIGH + id).style.visibility = "visible";
}


function ImageListBox_AreaOut (id)
{
	document.getElementById (ImageListBox_HIGH + id).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 ()
{
	return document.getElementById (ImageListBox_LISTBOXDIV).options;
}


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.__EVENTTARGET.value = document.getElementById (ImageListBox_LISTBOXBUTTON).name;
	theform.__EVENTARGUMENT.value = '';
	theform.submit();
}

//script for contextual help
			var posX=25;
			var posY=60;	//-13;
			if (document.all)
			{//for IE
				posY=11;
			}		
			var myWidth = 0, myHeight = 0;
			var allSupport = (document.all!=null || window.sidebar!=null);

			 function getOffset(el, which) {
				var amount = el["offset"+which] 
				if (which=="Top")
					amount+=el.offsetHeight
				el = el.offsetParent
				while (el!=null) {
					amount+=el["offset"+which]
					el = el.offsetParent
				}
				return amount
			}
			function setPosition(el, src) {
				// Set the position of an element
				//src = window.event.srcElement
				var top;
				var left;
				var elWidth;
				var elHeight;
				if (allSupport) {
					top = getOffset(src, "Top") + posY
					left =  getOffset(src, "Left") + posX
					elWidth = el.offsetWidth;
					elHeight = el.offsetHeight
					/*alert(left);
					alert(top);
					alert(myWidth);
					alert(elWidth);
					alert(myHeight);
					alert(elHeight);*/
					
					if (myWidth - elWidth > left)
					{					
						el.style.pixelLeft = left
						el.style.left = left + "px";
						//alert("1");
					}
					else
					{						 
						el.style.pixelLeft = left - elWidth;
						el.style.left = (left - elWidth) + "px";
						//alert("2");
					}
					
					if (myHeight - elHeight > top)
					{					
						el.style.pixelTop = top
						el.style.top = top + "px";
						//alert("3");
					}
					else
					{						 
						el.style.pixelTop = top - elHeight
						el.style.top = (top - elHeight) + "px";
						//alert("4");
					}					
					//alert(el.style.pixelTop);					
					//alert(el.style.top);
				} else
				{
					el.top = src.y + 20 + posY
					el.left = src.x + posX
					//alert("5");
					//alert(el.top);
				}
			}
      
			function setVisibility(el, bDisplay) {
				// Hide or show to tip
				if (bDisplay)
				if (allSupport)
					el.style.visibility = "visible" 
				else
					el.visibility = "show";
				else
				if (allSupport)
					el.style.visibility = "hidden"
				else
					el.visibility = "hidden"
			}
			function displayContents(srcObj, code) {
				// Display the tooltip. 
				var name = "iHelp" + code;
				var el = document.getElementById(name);
				setPosition(el, srcObj);
				setVisibility(el, true);
			}
			function ShowTip(srcObj, code) {
					GetSize();
					displayContents(srcObj, code); 
			}
  
			function HideTip(code) {
					var name = "iHelp" + code;
					setVisibility(document.getElementById(name), false);
			}
			function GetSize() {		
					if( typeof( window.innerWidth ) == 'number' ) {
						//Non-IE
						myWidth = window.innerWidth;
						myHeight = window.innerHeight;
					} 
					else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						//IE 6+ in 'standards compliant mode'
						myWidth = document.documentElement.clientWidth;
						myHeight = document.documentElement.clientHeight;
					} 
					else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						//IE 4 compatible
						myWidth = document.body.clientWidth;
						myHeight = document.body.clientHeight;
					}					
				}				
//end script for contextual help




WEBAUDIT=function() {
    
  this.WACID=null;
  this.WACIDName="WACID";
  
  
  this.getCookie=function(name)  {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }
  
  this.setCookie=function(name,value,topDomain) {
    var date = new Date(2020,12,31,23,59,59);
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/; domain=" + topDomain;  
  }
  
  this.generateID=function(splitter) {
    var sp=(splitter) ? splitter : 'A';
    var now=new Date();
    return Date.parse(now.toGMTString()) + sp + Math.floor(Math.random()*1000000000);
  }
  
  this.getTopDomain=function(fullDomain) {
    var darabok=fullDomain.split('.');
    return darabok[(darabok.length-2)] + '.' + darabok[(darabok.length-1)];
  }
  
  this.getDomain=function(url) {
    var urlDarabok=url.split('/');
    return urlDarabok[2];
  }
  
  this.WACID=this.getCookie(this.WACIDName);
}

var wa=new WEBAUDIT();
var felbontas = "";
var same =  Math.floor(Math.random()*1000000);

if(wa.WACID==null)
{
  wa.WACID=wa.generateID('A');
  wa.setCookie(wa.WACIDName,wa.WACID,wa.getTopDomain(wa.getDomain(document.URL)));
}

same = same + "@welid=" + wa.WACID;
if(screen) felbontas='@felbontas='+screen.width+'x'+screen.height;
same = same + felbontas;


 

//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////THIS FUNCTIONS ARE USED IN LEGISLATION MODULE////////////////////
function loadLawDetails(span, url){
    var element = document.getElementById(span);
    var hspan = document.getElementById('h'+span);
    
    if (element.style.visibility == 'visible')
    {
        hideLaw(span);
    }
    else
    {
        var htmlcode = "<iframe class='lawMapIfr' src='"+url+"'></iframe>";    
        element.style.visibility = 'visible';
        hspan.style.visibility = 'visible';
	    element.innerHTML = htmlcode;
	}
}

function hideLaw(span){
    document.getElementById(span).innerHTML= '';
    document.getElementById(span).style.visibility= 'hidden';
    document.getElementById('h'+span).style.visibility= 'hidden';
}
//////////////////////////////////////////////////////////////////////////////////////////
