/*
---------------------------------------
- GLOBALT
---------------------------------------
*/
var loader = "<div class=\"loading-box\"><img src=\"pics/loading.gif\" alt=\"loading-animation\" style=\"width: 32px; height: 32px;\" /></div>";

function setheight(obj){
	var obj = getElemRefs(obj);
	if (parseInt(navigator.appVersion) >= 3){
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)<5){
			var tools = new Packages.java.awt.Toolkit.getDefaultToolkit();
			screen=tools.getScreenSize();
		}
		y = screen.height;
	}
//	alert(y); return false;
	if(obj && obj.css) obj.css.height = y - (275 - 16) + "px";
}
function setabsmiddle(obj, w, h){
	var obj = getElemRefs(obj);
	if(obj && obj.css){
		obj.css.width = w + "px";
		obj.css.height = h + "px";
		obj.css.marginTop = "-" + h/2 + "px";
		obj.css.marginLeft = "-" + w/2 + "px";
	}
}

/*
-------------------------------------------------------------------
- DHTML / AJAX RELATED
-------------------------------------------------------------------
*/
/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// onresize for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

/*
---------------------------------------
- METHOD TO USE TARGET _BLANK IN XHTML
---------------------------------------
Script written by Drew Noakes -- http://drewnoakes.com
*/

function initLinks() {
  for (i in document.links) {
    link = document.links[i];
    if (link.rel && link.rel.indexOf('external')!=-1) {
      link.onclick = onExternalLinkActivate;
      link.onkeypress = onExternalLinkActivate;
    }
  }
}

function onExternalLinkActivate() {
  window.open(this.href);
  return false;
}

window.onload = initLinks;

/*
---------------------------------------
- COUNT CHARS IN A TEXTAREA / FIELD
---------------------------------------
/* Detta script finns att hämta på http://www.jojoxx.net och
   får användas fritt så länge som dessa rader står kvar. */

function checkLength(obj,dispobj,mlength){
	if(obj.value.length>mlength){
		obj.value = obj.value.substr(0,mlength);
		alert('Detta fält maximalt innehålla '+mlength+' tecken.');
		obj.focus();
	}
	dispobj.value=mlength-obj.value.length;
}

/*
---------------------------------------
- COUNT CHARS IN A TEXTAREA / FIELD
---------------------------------------
 "Show/hide functions" by Sean M. Burke, sburke@cpan.org, 2005

 You can use, modify, and redistribute this only under the terms of the
 Perl Artistic License: 
  http://www.perl.com/pub/a/language/misc/Artistic.html

*/

function toggle (switcher) { // followed by list of IDs of elements to toggle

  if(! document.getElementById)
    throw complainting("Your browser's JavaScript system is too old.  ",
       "Upgrade at getfirefox.com !");

  for(var i = 1; i < arguments.length; i++) {
    var element
    var el = document.getElementById( arguments[i] );
    if(!el) throw complaining("Failed to find element with id='"
     + arguments[i] + "' in " + document.location );

    var behidden;
    if(   (el.style.display || 'block') == 'block')
         { el.style.display =  'none' ; behidden = true ;  }
    else { el.style.display =  'block'; behidden = false;  }
  }
/*
  if(switcher) {
    status_switcher_classchange(switcher, behidden);
    if( switcher.childNodes[0].nodeType == document.TEXT_NODE)
     switcher.childNodes[0].data = behidden ? "" : "";
  }
*/
  return false;
}

function status_switcher_classchange (targetnode, behidden) {
  var class_to_add = behidden ? "toggleWillShow" : "toggleWillHide";

  var c = targetnode.className || '';
  var c_new =  c.replace( /\btoggleWill(Show|Hide)\b/, class_to_add );
  if( c_new == c)  { c_new = c + " " + class_to_add }
  targetnode.className = c_new;
  return;
}

function complaining () {
  var _ = [];
  for(var i = 0; i < arguments.length; i++) { _.push(arguments[i]) }
  _ = _.join("");
  if(! _.length) out = "Unknown error!?!";
  void alert(_);
  return new Error(_,_);
}

/*
---------------------------------------
- SET VALUE IN A COMBOBOX
---------------------------------------
*/
function setSelect(sel, val){
	var sel = getElemRefs(sel);
	for (var i = 0; i < sel.options.length; i++){
	if (val == sel.options[i].value)
		sel.options[i].selected = true;		
	}
}
