//<!--
/* *******************************************
Code      : onsite.base.js
Copyright :	OnSite ANS, 1999
Author    : Nils Chr. Hofgaard Dahl
Email     : nils@onsite.no
Date      : 05.04.2002
Comments  :	Defining various default vars, as browser detectetion
Change    :
SampleURI :   
Version   : 1.0
******************************************* */
/*
Gobal vars
This tells you about users browers
IE4 : Internet Explorer 4.x
IE5 : Internet Explorer 5.x
NS4 : Netscape 4.x
NS6 : Netscape 6.x
NS7 : Netscape 7.x
MAC : Mac browser, hrmf;-(
MAC_IE5 : Need to say more
MAC_NS7 : Need to say more
*/
var IE4 = (document.all && !document.getlementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;
var NS7 = (navigator.userAgent.indexOf("Netscape/7") != -1); 
var MAC = (navigator.userAgent.indexOf("Mac") != -1); 
var MAC_IE5=false;
var MAC_NS7=false;
var IE50 = false;
if(MAC) {
 MAC_IE5 = (navigator.userAgent.indexOf("MSIE 5") != -1); 
 MAC_NS7 = (navigator.userAgent.indexOf("Netscape/7") != -1);
 NS7=false;
 IE4=false;
 IE5=false;
}
//********************************************/
if(IE5) {
  IE50 = (navigator.userAgent.indexOf("MSIE 5.0") != -1); 
  IE4  = false;
}

//********************************************
//Internal vars
//********************************************/
var _libUrl = '../../JS/OSASJS.HTM';
var _loadLib = new Array();
//********************************************/

/********************************************
Function   : getBrowserKeyName
Return     : String 
Comments   : Return browserkeyname
Parameters : none
********************************************/
/*
function getBrowserKeyName() {
	return _BROWSERKEY;
}
*/
/********************************************
Function   : getBrowserName
Return     : String 
Comments   : Gives user browser data
Parameters : none
********************************************/

function getBrowserName() {
  return navigator.appName+'; '+ navigator.userAgent;
  //  var agnt= navigator.userAgent.toLowerCase();
  // otherwize the uA is made lower case for comparisons
}

/*  *******************************************
Function   : useLib
Return     : none 
Comments   : Used to load other JSDo(O)m lib's
             eg. useLib(onsite/util/util)
Parameters : none
******************************************* */
function useLib(libname) {
  if(_loadLib[libname]) return true;
  _loadLib[libname]=true;
  document.writeln('<script language="java'+'script" src="'+_libUrl+'/'+libname+'.js"></script>\n');
}

function errReport() {
 alert("error");
}

/* *******************************************
Function   : setStatus
Return     : none 
Comments   : Used to set string to the browser statusbar
Parameters : String text required, String frame name optionally
******************************************* */
function setStatus(str, frame) {
  if(!frame) window.status=str;
  else {
	var obj = eval(frame);
	obj.status=str;
  }
  setTimeout('resetStatus();',5000);
}

function appendStatus(str,frame) {
  if(!frame) window.status+=str;
  else {
	var obj = eval(frame);
	obj.status+=str;
  }
}
function resetStatus(frame) { setStatus('',frame); }

function getReferrer() {   return document.referrer}

function getTitle(frame) { 
  if(frame) {
   var obj = eval(frame);
   return frame.document.title;
  }
   return document.title;
}

/* *******************************************
Function   : subst
Return     : Finished results are returned
Comments   : Used to replace ##-tags
Parameters : (text, [replacers])
Usage      : var content = subst('##NAME## - ##TITLE##', ['NAME', 'My Name', 'TITLE', 'My Title']);
******************************************* */

function subst (content, substs) {
  var idx=0;
  for (var i=0; i<substs.length; i+=2) {
    if (substs[i]=='.*') {content=content.replace(/##[^#]+##/g, '')}
    else {
      idx=content.indexOf('##'+substs[i]+'##',0);
      while (idx!=-1 && idx<content.length) {
        content=content.substring(0,idx)+substs[i+1]+content.substring(idx+(substs[i].length+4));
        idx=content.indexOf('##'+substs[i]+'##',idx);
      }
    }
  }
  
  return content;
}


function getBgColor(frame) {
  var obj=(frame?eval(frame):this.document);
  var bgColor=(obj.bgColor||'#FFFFFF');
  return bgColor.substring(1,7);

}
function setTitle(str,frame) { 
  if(frame) {
   var obj = eval(frame);
   frame.document.title=str;
  } else {document.title=str;}
}

if (NS4) {
  var widthCheck = window.innerWidth
  var heightCheck = window.innerHeight
  window.onResize = resizeFix
}

function resizeFix() {
	if (widthCheck != window.innerWidth || heightCheck != window.innerHeight)
	document.location.href = document.location.href
}

function getCookie(Name) {          
 var search = Name + "="          
         if (document.cookie.length > 0) { // if there are any cookies                   
              offset = document.cookie.indexOf(search)                    
               if (offset != -1) { // if cookie exists
                       offset += search.length // set index of beginning of value
                              end = document.cookie.indexOf(";", offset)           // set index of end of cookie value
                              if (end == -1)
                                         end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))                    
                  }           
          }
}       


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

// Trim - Stips leading,continues,trailing spaces in a string
// eg. ' nils  Dahl    ' => 'nils Dahl'
function trim(instr) {
  var regexp= /\s{2,}/g;
  instr =instr.replace(regexp, " ");
  regexp= /^\s*(.*)/;
  instr =instr.replace(regexp, "$1");
  regexp= /^(.*)\s$/;
  instr =instr.replace(regexp, "$1");
  return instr;
}

// join - as perl join
// eg. join(";", ['nils','dahl']; -> nils;dahl
function join(delim,joindata) {
	if(delim==null||joindata==null || joindata.length<=0) return '';
	var joinres=joindata[0];
	for(var i=1; i<joindata.length;i++) {	joinres+=delim+joindata[i];	}
	return joinres;
}

//
//-->
