
// Settings
var helpSteps = 12;
var helpStepHeight = 8;
var helpDefault = '';

var helpCounter = 0;
var helpSpeed = 20;
var helpLeft = 0;
var helpOnScreen = false;
var helpTimerID = null;

var viewportwidth;
var viewportheight;

var scrOfX = 0, scrOfY = 0;

function getScrollXY() { 
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
}

function getViewPortSize()
{
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
			'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
 
	// older versions of IE
 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
}

function findObj(n, d) { 
  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=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function setHelp(item)
{
	var helpContents = findObj("helpContents");

	if (helpOnScreen == true)
	{
		if (item != null && helpArray[item] != null)
			helpContents.innerHTML = unescape(helpArray[item]);
		else
			helpContents.innerHTML = helpDefault;			
	}
}



/*********************************************************/
/* Toggle the help popup                                 */
/*********************************************************/

function toggleHelp()
{
	//alert(document.body.clientWidth);
	if (helpOnScreen == false)
		displayHelp();
	else
		hideHelp();
}





/*********************************************************/
/* Display the help popup                                */
/*********************************************************/

function displayHelp()
{
	getViewPortSize();
	var helpLayer = findObj("helpLayer");
	if (helpLayer.style) helpLayer = helpLayer.style;
	if (document.all && !window.innerHeight) { 
		helpLayer.pixelWidth = viewportwidth - helpLeft;
		helpLayer.pixelHeight = helpStepHeight;
		helpLayer.pixelTop = viewportheight + document.body.scrollTop - helpStepHeight;
		
	} else 	{
		helpLayer.width = viewportwidth - helpLeft;
		helpLayer.height = helpStepHeight;
		helpLayer.top = viewportheight + window.pageYOffset - helpStepHeight;
	}
	helpLayer.visibility = 'visible';

	helpCounter = 1;
	setTimeout('growHelp()', helpSpeed);
	
	var helpContents = findObj("helpContents");
	helpDefault = helpContents.innerHTML;
}

function growHelp()
{
	helpCounter++;

	var helpLayer = findObj("helpLayer");
	if (helpLayer.style) helpLayer = helpLayer.style;

	if (document.all && !window.innerHeight) {
		//alert("aici2");
		helpLayer.pixelHeight = helpCounter * helpStepHeight;
		helpLayer.pixelTop = viewportheight + document.body.scrollTop - (helpCounter * helpStepHeight);
	} else {
		//alert("aici3");
		helpLayer.height = helpCounter * helpStepHeight;
		helpLayer.top = viewportheight + window.pageYOffset - (helpCounter * helpStepHeight);
		if (helpTimerID == null) helpTimerID = setInterval('resizeHelp()', 100);
	}
	
	if (helpCounter < helpSteps)
		setTimeout('growHelp()', helpSpeed);
	else
		helpOnScreen = true;
}



/*********************************************************/
/* Hide the help popup                                   */
/*********************************************************/

function hideHelp()
{
	helpOnScreen = false;
	helpCounter = helpSteps;		
	setTimeout('helpShrink()', helpSpeed);
}

function helpShrink()
{
	var helpLayer = findObj("helpLayer");
	if (helpLayer.style) helpLayer = helpLayer.style;

	helpCounter--;
	
	if (helpCounter >= 0) 
	{
		if (document.all && !window.innerHeight) {
			helpLayer.pixelHeight = helpCounter * helpStepHeight;
			helpLayer.pixelTop = viewportheight + document.body.scrollTop - (helpCounter * helpStepHeight);
		} else {
			helpLayer.height = helpCounter * helpStepHeight;
			helpLayer.top = viewportheight + window.pageYOffset - (helpCounter * helpStepHeight);
		}
		setTimeout('helpShrink()', helpSpeed);
	} 
	else 
	{
		if (document.all && !window.innerHeight) {
			helpLayer.pixelHeight = 1;
			helpLayer.pixelTop = viewportheight + document.body.scrollTop - 1;
		} else {
			helpLayer.height = 1;
			helpLayer.top = viewportheight + window.pageYOffset - 1;
		}
		helpLayer.visibility = 'hidden';
		
		var helpContents = findObj("helpContents");
		helpContents.innerHTML = helpDefault;
	}
}



/*********************************************************/
/* Resize the help popup                                 */
/*********************************************************/

function resizeHelp()
{	
	//alert(document.body.scrollTop);
	getScrollXY();
	//alert(scrOfY);
	if (scrOfY<709)
	{if (helpOnScreen == true) 
	{
		var helpLayer = findObj("helpLayer");
		if (helpLayer.style) helpLayer = helpLayer.style;
		
		if (document.all && !window.innerHeight) {
			helpLayer.pixelHeight = helpSteps * helpStepHeight;
			helpLayer.pixelWidth = viewportwidth - helpLeft;
			helpLayer.pixelTop = viewportheight + scrOfY - (helpSteps * helpStepHeight);
			//alert(scrOfY);
			//alert(helpLayer.pixelTop);
			if (helpLayer.pixelTop<810 && scrOfY<82) helpLayer.pixelTop=viewportheight-helpLayer.pixelHeight;
			//alert(helpLayer.pixelTop);
		} else {
			helpLayer.height = helpSteps * helpStepHeight;
			helpLayer.width = viewportwidth - helpLeft;
			helpLayer.top = viewportheight + scrOfY - (helpSteps * helpStepHeight);
		}
	}
	}
}

