/*******************************************************************************
*
* © 2008 Copyright A-Vision
*
* File description :       HR Package :: Common functions
* 
* Created by       :       Arnold Velzel
* Created on       :       08/07/2008
*
* Last changed by  :       Arnold Velzel
* Last changed on  :       <LastChanged>
* 
*******************************************************************************/

function justCloseTheWindow()
{
 top.opener='X'; 
 top.open('','_parent',''); 
 top.close();
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function notify( obj, e)
{
 if ( !obj.getAttribute('notification')) return;

 if ( !e) e = window.event;
// alert(e.x);

 div = document.createElement( 'DIV');
 div.style.position = "absolute";
 t = eval( positionTop( obj) + obj.offsetHeight + 10);
 div.style.top = t+"px";
 l = eval( positionLeft( obj) + 5);
// div.style.left = l+"px";
  div.style.left = eval(e.clientX+10)+"px";
 div.style.padding = "3px";
 div.style.border = "1px solid navy";
 div.style.backgroundColor = "rgb(255,255,200)";
 div.style.lineHeight = "12px";
 div.style.fontSize = "10px";
 div.style.fontFamily = "sans-serif";
 div.style.zIndex = 9999;
 div.style.textAlign = "justify";
 div.opacity = 0.9;
 div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=98)";
 div.innerHTML = obj.getAttribute('notification');
 div.setAttribute('notificationbox',true);
 document.body.appendChild( div);

 if ( div.offsetWidth > 200) {
  div.style.width = "200px";
 }
 obj.noteObject = div;
 obj.onmouseout = function() {
  if ( this.noteObject) {
   try {
    document.body.removeChild( this.noteObject);
   }
   catch (e) {
   }
   this.noteObject = null;
  }
 }
}
function removenotifies()
{
 divs = document.getElementsByTagName('DIV');
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notificationbox')) {
   document.body.removeChild( divs[i]);
  }
 }
}

function setnotifications()
{
 divs = document.getElementsByTagName('*');
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notification')) {
//   alert(divs[i].getAttribute('notification'));
 	 divs[i].onmouseover = function() {
 	  notify( this);
 	 }
 	 divs[i].onmouseoout = function() {
 	  removenotifies();
 	 }
  }
 }
}

function selectNode(node) { 
 var selection, range, doc, win; 
 if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof win.getSelection != 'undefined' && typeof doc.createRange != 'undefined' && (selection = window.getSelection()) && typeof selection.removeAllRanges != 'undefined') { 
  range = doc.createRange(); 
  range.selectNode(node); 
  selection.removeAllRanges(); 
  selection.addRange(range); 
 } 
 else if (document.body && typeof document.body.createTextRange != 'undefined' && (range = document.body.createTextRange())) { 
  range.moveToElementText(node); 
  range.select(); 
 } 
}
function clearSelection() {
 var sel ;
 if ( document.selection && document.selection.empty) {
  document.selection.empty() ;
 } else if( window.getSelection) {
  sel = window.getSelection();
  if ( sel && sel.removeAllRanges) sel.removeAllRanges();
 }
}
function stripEmptyNodes( blk)
{
 var i;
 for (i=0;i<blk.childNodes.length;i++) {
  if ( blk.childNodes[i].nodeName == "#text") {
   text = blk.childNodes[i].innerText?blk.childNodes[i].innerText:blk.childNodes[i].textContent;
   if ( text && text.trim()=="") {
    blk.removeChild(blk.childNodes[i]);
    i--;
   }
  } else {
   if ( blk.hasChildNodes()) {
    stripEmptyNodes( blk.childNodes[i]);
   }
  }
 }
}

var w;
function openLink( lnk)
{
 window.name = "_dashboard";
 url = lnk.getAttribute("href");
 name = lnk.getAttribute("target");
 if ( w && !w.closed) {
  w.focus();
  w.close();
  w.location = url;
  w = null;
 } else {
 }
 w = window.open(url,name+"_");
 w.focus();
 return( false);
}

