
var isIE=document.all;
var isNN=!document.all&&document.getElementById;
var isN4=document.layers;
	
	
function $__(id)
{ 
	return document.getElementById(id); 
}

function getEventObj(e)
{
	if(window.event)
	{
		e = window.event;
		e.target=window.event.srcElement;
	}
	return e;
}
	
function randomPassword(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}

function ReadCookie(cookieName) 
{
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue,nDays)
{
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function isObject(a)
{
   return (typeof a == 'object' && !!a);
}

function debugArray(obj)
{
	val = '';
	
	for(var a in obj)
	{
		if(isObject(obj[a]))
			debugArray(obj[a]);
		else
			val+=("array["+a+"] = "+ obj[a]+'<br/>')
	}
	debug(val);
}

function debugObj(obj)
{
	val = '';
	val = obj.constructor.toString()+'<br/>';
	
	for(var a in obj)
	{
		if(isObject(obj[a]))
			debugObj(obj[a]);
		else
			val+=(a + ": "+ obj[a]+'<br/>')
	}
	debug(val);
}

function debug(txt)
{
	divDebug = document.getElementById('debug');
	
	if(!divDebug)
	{
		var divDebug =document.createElement('div');		
		divDebug.id = 'debug';
		document.body.appendChild(divDebug);
		
	  divDebug.style.display='block';
	  divDebug.style.height="100px";
	  divDebug.style.width="100%";
	  divDebug.style.overflow='scroll';
	  divDebug.style.border='1px solid #000000';
    divDebug.ondblclick = function(){this.style.display='none';};
  } 
	
	divDebug.style.display='block';
	divDebug.innerHTML =  txt + '<br/>'+ divDebug.innerHTML ;
	
}

function printPage(url) 
{
	window.open(url, "", "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=600,height=400");
}

function openLink(url)
{
	window.open(url,'window');
}

function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_swapImgRestore() 
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() 
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() 
{ //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function changeImage(obj,img)
{
 var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	if(rslt)
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale')";
	else
		obj.style.backgroundImage = "url("+img+")";
}

function getDocumentSize()
{
		if(document.documentElement && document.documentElement.clientWidth){
			width = document.documentElement.clientWidth;
			height = document.documentElement.clientHeight;
		} else if(document.body && document.body.clientWidth){
			width = document.body.clientWidth;
			height = document.body.clientHeight;
		}
		
		return {width : width, height : height}
}

	function getViewport()
	{
		var width = 0;
		var height = 0;
		var x = 0;
		var y = 0;

		if(document.body && document.body.clientWidth)
		{
			width = document.body.clientWidth;
			height = document.body.clientHeight;
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}


		return {width : width, height : height, x : x, y : y };
	}
	
	function getViewport2()
	{
		var width = 0;
		var height = 0;
		var x = 0;
		var y = 0;

		if(document.documentElement && document.documentElement.clientWidth){
			width = document.documentElement.clientWidth;
			height = document.documentElement.clientHeight;
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		} else if(document.body && document.body.clientWidth){
			width = document.body.clientWidth;
			height = document.body.clientHeight;
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		// we don't use an else if here, since Opera 7 tends to get the height on the documentElement wrong
		if(window.innerWidth)
		{
			width = window.innerWidth - 18;
			height = window.innerHeight - 18;
		}

		
		if(window.pageXOffset)
		{
			x = window.pageXOffset;
			y = window.pageYOffset;
		} 
		else if(window.scrollX)
		{
			x = window.scrollX;
			y = window.scrollY;
		}

		return {width : width, height : height, x : x, y : y };
	}
	
	function getPosition(e, oNode){
		var oViewport = getViewport();
		var oCoords;
		var commonEventInterface = window.event ? window.event : e;

		if(commonEventInterface.type == "focus"){
			oCoords = getNodePosition(oNode);
			oCoords.x += nMarginX;
			oCoords.y += nMarginY;
		} else {
			oCoords = { x : commonEventInterface.clientX + oViewport.x + nMarginX, y : commonEventInterface.clientY + oViewport.y + nMarginY};
		}

		oContainer.style.visiblity = "hidden"; // oContainer needs to be displayed before width and height can be retrieved
		oContainer.style.display =  "block";
		var containerWidth = oContainer.offsetWidth;
		var containerHeight = oContainer.offsetHeight;
		oContainer.style.display = "none"; // hide it again
		oContainer.style.visiblity = "visible";

		if(oCoords.x + containerWidth + 10 >= oViewport.width + oViewport.x){
			oCoords.x = oViewport.width + oViewport.x - containerWidth - 10;
		}
		if(oCoords.y + containerHeight + 10 >= oViewport.height + oViewport.y){
			oCoords.y = oViewport.height + oViewport.y - containerHeight - oNode.offsetHeight - 30;
		}

		//oCoords.y = oCoords.y + oViewport.y  - oNode.offsetHeight;

		oCoords.x = oViewport.width -(270+ containerWidth + 10);

		oCoords.x += "px";
		oCoords.y += "px";

		return oCoords;
	}
	
		function getNodePosition(oNode){
		var x = 0;
		var y = 0;

		do {
			if(oNode.offsetLeft){ x += oNode.offsetLeft }
			if(oNode.offsetTop){ y += oNode.offsetTop }
		}	while((oNode = oNode.offsetParent)) // IE gets the offset 'right' from the start

		return {x : x, y : y}
	}
