// popupshit
function popUp(URL) { eval("page" + " = window.open(URL,'popup', 'toolbar=0,scrollbars=0,location=0,menubar=0,resizable=0,statusbar=0,width=640,height=480');"); }

// requestengine
function do_request(url,callback) {
 var httpRequest = false;

 if (window.XMLHttpRequest) {
  httpRequest = new XMLHttpRequest();
  if (httpRequest.overrideMimeType) {
   httpRequest.overrideMimeType('text/xml');
  }
 }
 else if (window.ActiveXObject) {
  try {
   httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
   try {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch(e) {
   }
  }
 }

 if(!httpRequest) {
  alert('Kan ikke opprette en XMLHTTP-økt.');
  return false;
 }

 httpRequest.onreadystatechange = function() {
  if(httpRequest.readyState == 4) {
   if (httpRequest.status == 200)
    callback(url,httpRequest);
   else
    callback(url,false);
  }
 };

 httpRequest.open('GET',url,true);
 httpRequest.send(null);
}

function callback_c(url,httpRequest) {
 if("ccol" !== "")
  document.getElementById("ccol").innerHTML = httpRequest.responseText;
}

function callback_l(url,httpRequest) {
 if("loginbox" !== "")
  document.getElementById("loginbox").innerHTML = httpRequest.responseText;
}

function quest(req) {
 document.getElementById("ccol").innerHTML = '<div align=center><img src="images/loading.gif" alt="Laster inn data.." /></div>';
 do_request("req/?p="+req,callback_c)
}

function show(id) {
	var element = document.getElementById(id);
	element.style.display = "";
}

function hide(id) {
	var element = document.getElementById(id);
	element.style.display = "none";
}

function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

