// JavaScript Document
//requires jQuery

var tutorialTimer= new Array();
var tutorialTime=4;

function showBallon(ctrl, html, toScroll)
{
	var ballon = $$("helpballon");
	var nCtrl = ctrl;
	if(typeof(ctrl)=='string'){ nCtrl = ctrl; ctrl = $$(ctrl);}
	else {nCtrl = ctrl.id;}
	
	if(ctrl)
	{
		var left = getLeftPos(ctrl);
		var top = getTopPos(ctrl);
/*		var width=200;
		if(ctrl.attributes["helpD"])
			width = Number(ctrl.attributes["helpD"].nodeValue);
		else
			width = ExtractNumber(ctrl.style.width);
		if(!width) width=200;
*/
	
		$$("innerBallon").innerHTML = html;
		if(	ballon.style.display == '')
		{
			transformRect("helpballon", top-52, Number(left), 20);
		}
		else
		{
			ballon.style.top = (top-52)+'px';
			ballon.style.left = (Number(left))+'px';
			ballon.style.display = '';
		}
		
		if(toScroll)
		{
			theBody = (window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			theBody.animate({ scrollTop: top-100 }, "slow");
		}
	}
}

function hideBallon()
{
	$$("helpballon").style.display='none';
}

function showHelpOn(ctrl)
{
	if(typeof(ctrl)=='string') ctrl = $$(ctrl);
	if(ctrl.attributes["help"].nodeValue )
	{
		if(!ctrl.value || ctrl.value==null || ctrl.value=='')
		{
			stopTutorial(0);
			tutorialTimer.push( setTimeout("showBallon('"+ctrl.id+"', '"+ctrl.attributes['help'].nodeValue+"' );", getTutorialTime()) );
			tutorialTimer.push( setTimeout("hideBallon();", getTutorialTime()) );
		}
	}
}


function showRequiredOn(ctrl)
{
	if(typeof(ctrl)=='string') ctrl = $$(ctrl);
	if(ctrl.ask)
	{
		stopTutorial();
		showBallon(ctrl, ctrl.ask);
	}
}

function stopTutorial(startAt)
{
	while(timer = tutorialTimer.pop())
	{
		clearTimeout(timer);
	}
	if(typeof(startAt)!='undefined') tutorialTime=startAt;
	else tutorialTime=1;
}


function getTutorialTime()
{
	return 3000*tutorialTime++;
}


function transformRect(c, top, left, steps)
{
	var ctrl=$$(c);
	var fTop = ExtractNumber(ctrl.style.top);
	var fLeft = ExtractNumber(ctrl.style.left);
	
	if(!(top>0) || !isFinite(top)) top=10;
	if(!(left>0) || !isFinite(left)) left=10;
	
	if(top!=null && fTop!=top) ctrl.style.top = (steps==0?top:Math.floor((top-fTop)/steps+fTop))+'px';
	if(left!=null && fLeft!=left) ctrl.style.left = (steps==0?left:Math.floor((left-fLeft)/steps+fLeft))+'px';

	if(steps>1) setTimeout("transformRect('"+c+"', "+top+", "+left+", "+(steps-1)+")", 10);
}