/*function gettext( strname ) {
  var strarray = new Object();

  if( typeof strarray[ strname ] == "undefined" ) {
    return strname;
  } else {
    return strarray [ strname ];
  }
}*/


function logout() {
  //document.location.href = "sd.php";
  document.form.action_performed.value = 'App_logout';
  document.form.submit();
}


function submit_form() {
  if (window.jsrsContextProp) {
    // Look for unfinnished jobs in the queue
    unfinished_jobs = 0;
    for (var i=1; i <= jsrsContextProp.poolSize; i++){
      if (jsrsContextProp.pool['jsrs' + i] && jsrsContextProp.pool['jsrs' + i].busy) {
	unfinished_jobs++;
      }
    }

    if (unfinished_jobs) {
      var txt;

      txt = gettext('UOCG_JS_THERE_ARE') + ' ' + unfinished_jobs + ((unfinished_jobs>1) ? ' ' + gettext('UOCG_JS_UNFINISHED_JOBS') : ' ' + gettext('UOCG_JS_UNFINISHED_JOB') ) +
	  '. ' + gettext('UOCG_JS_DO_YOU_WANT_TO_CANCEL') + ' ' + ((unfinished_jobs>1) ? gettext('UOCG_JS_THEM') : gettext('UOCG_JS_IT') ) + '?';

      if(!confirm(txt)) {
	return false;
      }
    }
  }

  /* validate dates in searchfield, if present: */
  if (typeof SF_validate_dates != 'undefined')
    SF_validate_dates();
  /* validate date in mail, if present: */
  if (typeof M_validate_date != 'undefined')
    M_validate_date();

  document.form.action_count.value = parseInt(document.form.action_count.value) + 1;
  document.form.submit();
}


function updateForm(field, caller) {
  var data = document.SF_form.SF_f_regex.value;
  document.SF_form.SF_f_regex.value = field + " " + data;
  caller.options[0].selected=true;
}

//used by RL adn SS:
var win_ref = null;
function open_url(url, target) {
  win_ref = window.open(url,target);
}

function valid_email(email) {
  if (email!='') {
    // define regex
    var pattern = new RegExp("^[0-9a-zA-ZæøåÆØÅ]([-_.]?[0-9a-zA-ZæøåÆØÅ])*@[0-9a-zA-Z]([-.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$","i");

    // test for pattern
    if(pattern.test(email))
      return true;
  }
  return false;
}

function openWin(url) {
  window.open(url,'_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,left=100,top=100,width=500,height=600');
}

function show_status(txt) {
  window.status = txt;
}

function browse_help(topic) {
  if (topic != '') topic = 'toc';
  window.open('help.php?session_name='+SESSION_NAME+'&action_performed=HR_browse&HR_topic='+topic,'OpointHelp','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=500,height=600');
}

function set_lang(lang) {
  if (lang) {
    document.form.action_performed.value = 'App_lang';
    document.form.App_lang.value = lang;
    submit_form();
  }
}

var mouse_x = -1;
var mouse_y = -1;
function set_mouse_pos(x,y) {
  mouse_x = x;
  mouse_y = y;
}

function addEvent(el, evname, func) {
  if (el.attachEvent) { // IE
    el.attachEvent("on" + evname, func);
  } else if (el.addEventListener) { // Gecko / W3C
    el.addEventListener(evname, func, true);
  } else {
    el["on" + evname] = func;
  }
}

function removeEvent(el, evname, func) {
  if (el.detachEvent) { // IE
    el.detachEvent("on" + evname, func);
  } else if (el.removeEventListener) { // Gecko / W3C
    el.removeEventListener(evname, func, true);
  } else {
    el["on" + evname] = null;
  }
}

function set_size() {
  document.form.app_height.value = document.body.offsetHeight;
  document.form.app_width.value  = document.body.offsetWidth;
}

function trim(value) {
   var temp = value;
   var obj = new RegExp("^(\s*)([\W\w]*)(\b\s*$)");
   if (obj.test(temp)) {
     temp = temp.replace(obj, '$2');
   }
   var obj = new RegExp(" +","g");
   temp = temp.replace(obj, " ");
   if (temp == " ") temp = "";
   return temp;
}




var TRIM_EXP = /^\s+|\s+$/g;
String.prototype.trim = function(){
  return this.replace(TRIM_EXP, "");
};
var WS_MULT_EXP = /\s\s+/g;
String.prototype.normalize = function(){
  return this.trim().replace(WS_MULT_EXP, " ");
};

TokenizedExps = {};
function getTokenizedExp(token, flag){
  var x = TokenizedExps[token];
  if(!x)
    x = TokenizedExps[token] = new RegExp("(^|\\s)"+token+"($|\\s)", flag);
  return x;
}

function hasToken(s, token){
  return getTokenizedExp(token,"").test(s);
}

function addClass(el, name){
  if (el && typeof el.className != 'undefined' && !hasToken(el.className, name))
    el.className += " " + name;
}

function removeClass(el, name){
  if (el && typeof el.className != 'undefined')
    if (name=='')
      el.className = '';
    else
      el.className = el.className.replace(getTokenizedExp(name, "g")," ").normalize();
}




/*Browsercheck object*/
function cm_bwcheck(){
  //In theory we should use object detection, but this script needs work-arounds for almost every browser...
  this.ver=navigator.appVersion;
  this.agent=navigator.userAgent.toLowerCase();
  this.dom=document.getElementById?1:0;
  this.ns4=(!this.dom && document.layers)?1:0;
  this.op=window.opera;
  this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar);
  this.ie=this.agent.indexOf("msie")>-1 && !this.op;
  if(this.op){
    this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
    this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1);
    this.op7=this.dom&&!this.op5&&!this.op6; //So all higher opera versions will use it
  }else if(this.moz) this.ns6 = 1;
  else if(this.ie){
    this.ie4 = !this.dom && document.all;
    this.ie5 = (this.agent.indexOf("msie 5")>-1);
    this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);
    this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55;
  }
  this.mac=(this.agent.indexOf("mac")>-1);
  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7);
  this.usedom= this.ns6||this.op7; //Use dom creation
  this.reuse = this.ie||this.op7||this.usedom; //Reuse layers
  this.px=this.dom&&!this.op5?"px":"";
  this.use_pointer=!this.ie5;
  return this;
}
var bw = new cm_bwcheck();

function get_left_position(element) {
  xPos   = eval(element).offsetLeft;
  tempEl = eval(element).offsetParent;
  while (tempEl != null) {
    xPos += tempEl.offsetLeft;
    tempEl = tempEl.offsetParent;
  }
  return xPos;
}

function get_top_position(element) {
  yPos   = eval(element).offsetTop;
  tempEl = eval(element).offsetParent;
  while (tempEl != null) {
    yPos += tempEl.offsetTop;
    tempEl = tempEl.offsetParent;
  }
  return yPos;
}



//function resetForm() {
//  document.search_form.SF_f_regex.value = "";
//  document.search_form.SF_f_search.value = "";
//  //document.search_form.subject.options[0].selected=true;
//  //document.search_form.language.options[0].selected=true;
//  //document.search_form.country.options[0].selected=true;
//}
//
//function submitForm(page) {
//  document.RL_form.RL_f_page.value = page
//  document.RL_form.RL_f_browser.value = true
//  document.search_form.submit()
//}
//
//
//function showList(list) {
//  document.RL_form.RL_f_list.value = list
//  document.RL_form.submit()
//}
//

////Validate form before submitting it!
//function validate(obj) {
//  var err_msg = '';
//
//  if (obj.name=='SF_f_submit' &&
//      ((document.search_form.SF_f_search &&
//	document.search_form.SF_f_search.value=='') &&
//       (document.search_form.SF_f_regex &&
//	document.search_form.SF_f_regex.value=='')))
//    err_msg = 'You can not leave the search field empty!';
//
//
//  else if (obj.name=='LB_f_save' &&
//	   document.search_form.LB_f_list_name &&
//	   document.search_form.LB_f_list_name.value=='')
//    err_msg = 'You can not leave the list name empty!';
//
//
//  if (err_msg=='')
//    return true;
//
//  alert(err_msg);
//  return false;
//}


var browserName=navigator.appName;
if (browserName=="Netscape") {
function closynoshowsme(){
window.open('','_parent','');
window.close();	
}	
}	
else {
if (browserName=="Microsoft Internet Explorer"){
function closynoshowsme(){
window.opener = "whocares";
window.close();
}	
}	
}		

