//$Id: common.js 1330 2008-02-20 17:20:54Z bjarnij $
//(c) Siminn.is

String.prototype.trim = function() {
// skip leading and trailing whitespace
// and return everything in between
  return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function addLoadEvent(func) {
	try {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
		window.onload = function() {
			if (oldonload) {
			oldonload();
			}
			func();
		}
		}
	} catch (Exception) {
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function styleAbbr() {
var isIE = (document.all) ? true:false;
if( isIE ) {
$$('abbr').each(function(node){
new Insertion.Top(node, '<span class=\"abbr\">');
new Insertion.Bottom(node, '</span>');
});
}
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
	Element.addClassName( element, value );
}




function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("navigation")) return false;
  var nav = document.getElementById("navigation");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "here";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
    }
  }
}

function siminn_popup(link, window_width, window_height) {
  var theTarget = "_blank";
  if ((link.target != null) && (link.target != "")) {
    theTarget = link.target;
  }

  newWin = window.open(link.href, theTarget, "width="+ window_width +", height="+ window_height);
  newWin.focus();
  return false;
}

function contactme(slod)  {
open(slod, "displayWindow", "toolbar=0,location=0, status=0, menubar=0, resizable=0, copyhistory=0, scrollbars=1, width=600,height=620");
}
function kuba(slod)  {
open(slod, "displayWindow", "toolbar=0,location=0, status=0, menubar=0, resizable=0, copyhistory=0, scrollbars=1, width=770,height=650");
}


function setHeight(id){
     single     = id.length <= 1 ? true : false;
     cell     = new Array();

     if (single && document.getElementById( id[0] ) == null) {
     	return;
     }

     id = single ? document.getElementById( id[0] ).childNodes : id;

     for(cellCount=0; cellCount<id.length; cellCount++){
          if(String(id[cellCount].tagName).toLowerCase()=="div" && single)
               cell.push( id[cellCount] );
          else if( !single )
               cell.push( document.getElementById(id[cellCount]) );
     }

     for(checkHeight=0, maxHeight=0; checkHeight<cell.length; checkHeight++) {
          if (cell[checkHeight] != null) {
               maxHeight = cell[checkHeight].offsetHeight>maxHeight ? cell[checkHeight].offsetHeight : maxHeight;
          }
     }

     for(var i=0; i<cell.length; i++) {
          if (cell[i] != null) {
               cell[i].style.height = String(maxHeight)+"px";
          }
     }
}

function changeActionAndSubmit(url,elementID)
{
var form = $( elementID );
   form.action=url;
   form.submit();
}

function alternate_init() {
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("alternate_rows") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
{
	Event.observe( elm, evType, fn, useCapture );
}

function replace(s, t, u) {
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	var tableBodies = table.getElementsByTagName("tbody");
	for (var i = 0; i < tableBodies.length; i++) {
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		for (var j = 0; j < tableRows.length; j++) {
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			}
		}
	}
}

function onLoadTasks() {
	highlightPage();
	alternate_init();
}
addLoadEvent(onLoadTasks);

//ie flash fix - click to actiavte
(function( Eolas_Fixed,
            win, doc,
            getElementsByTagName,
            outerHTML,
            parentNode,
            tags,
            elmsToRemoveOnload,
            x,
            is_ie,
            y,z,elm,childNode,HTML,dummy,eolasfix)
{

  if (win[Eolas_Fixed]) return;
  win[Eolas_Fixed] = 1;

  eolasfix = function ()
  {

    while (tags[++x])
    {

      y = 0;
      while (elm = doc[getElementsByTagName](tags[x])[y++])
      {
        if (is_ie)
        {
          HTML = '>';
          z = 0;


          while (childNode = elm.childNodes[z++])
              HTML += childNode[outerHTML];


          dummy = doc.createElement('i');

          elm[parentNode].insertBefore(dummy, elm);

          dummy[outerHTML] = elm[outerHTML].replace(/>/, HTML);

          y++;
          elm.style.display = 'none';
          elmsToRemoveOnload[elmsToRemoveOnload.length] = elm;
        }
        else
        {
          elm[outerHTML] = elm[outerHTML];
        }
      }
    }
  };

  is_ie && !eolasfix() && win.attachEvent('onload', function(){
    x=0;
    while(elm = elmsToRemoveOnload[x++])
        elm[parentNode].removeChild(elm);
  });

  win.opera && doc.addEventListener('DOMContentLoaded', eolasfix, 0);

})( '__Eolas_Fixed',
    window, document,
    'getElementsByTagName',
    'outerHTML',
    'parentNode',
    ['object','embed','applet'],
    [],
    -1 /*@cc_on,1 @*/
  );


var cookieNameTextSize = "SiminnR4";
var textSizes = "small;medium;big;huge".split(";");

function setTextSizeCookie(size) {
	eraseCookie(cookieNameTextSize);
	createCookie(cookieNameTextSize, size, 365);
}

function doTextSize(textSizeName, textSizeValue) {
	var bodyElement = document.getElementsByTagName('body')[0];
	bodyElement.style.fontSize = textSizeValue;
	setTextSizeCookie(textSizeName);
	markSelectedTextSize(textSizeName);
}


//font-size monster
function hugeText() {
	doTextSize("huge", '4em');
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function bigText() {
	doTextSize("big", '1em');
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function mediumText() {
	doTextSize("medium", '.75em');
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function smallText() {
	doTextSize("small", '.7em');
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function markSelectedTextSize(textSize) {
	for(var i=0; i < textSizes.length; i++) {
		var link = document.getElementById( textSizes[i] + 'Link');
		if (link != null) {
			if (link.className != null) {
				link.className = link.className.replace("selectedTextSize", "");
			}
		}
	}
	var link = document.getElementById( textSize + 'Link');
	if (link != null) {
		if (link.className != null) {
			link.className = " selectedTextSize";
		} else {
			link.className += " selectedTextSize";
		}
	}
}

function textResize() {
	var textSize = readCookie(cookieNameTextSize);
	if (textSize != null) {
		eval(textSize + "Text()");
	}
}

addLoadEvent(textResize);

var tabboxesInPage = {};

function addTabbox(id, parameters) {
	if (parameters == null) {
		parameters = { header: "h3",autosize: true };
	}
	var box = new Tabbox(id, parameters);
	eval("tabboxesInPage." + id + "=box;");
	if (window.location.href.indexOf("#") > 0 ) {
		var tabId = window.location.href.substring(window.location.href.indexOf("#") + 1);
		if (tabId.match(/-tab$/) != null) {
			tabId = tabId.substring(0, tabId.lastIndexOf("-tab"));
		}
		box.selectTab(tabId);
	} else {
		if (box.config == null || box.config.select < 0) {
			box.selectTab(0);
		}
	}
	return box;
}

function formFocus(item){
    item.focus();
}

function selectTab(tabboxId, tabId) {
	if (tabboxesInPage != null && eval("tabboxesInPage." + tabboxId) != null) {
		eval("tabboxesInPage." + tabboxId).selectTab(tabId);
	}
}


function form_submit(form){
    submit_form = document.getElementById("form1");
    submit_form.submit();
}


function close_error(){
	$('dim').style.visibility='hidden';
	$('alert').style.visibility='hidden';
}

