var paneStarted=false;
var FloatPaneControlID="FloatContainer";

function scriptError() {return true;}
window.onerror=scriptError;

// check if the object is valid 
function IsValidObject(o) 
{
	var r = true;
	if ( o == null )
	{
		r = false;
	}
	else if ( typeof(o) == "undefined")
	{
		r = false;
	} 
	return r;
}

// Change Control visibility
function ControlVisibleChange (id, visible)
{
	var o;
	var v = (visible) ? "" : "none";
	if (IsNetScape ())
	{
		o = "document.getElementById ('" + id + "').style.display = '" + v + "';";		
	}
	else
	{
		o = id + ".style.display = '" + v + "';";	
	}	
	try{ eval (o); }catch(e){}		
}

// Get Control visibility
function GetControlVisibility (id)
{
	var sStatement;
	var sResult = '';
	
	if (IsNetScape ())
		sStatement = "sResult = document.getElementById ('" + id + "').style.display;";		
	else
		sStatement = "sResult = " + id + ".style.display;";	
		
	try {
		eval (sStatement);
	} catch (e) {}			
	
	return sResult == '';
}

// NetScape browser check
function IsNetScape () 
{
	return !document.all;
}

function check_pane(){
	if (!paneStarted){		
		paneStarted=true;
		InitSystem();		
	}
}

function InitSystem()
{	
	if (FloatPaneControlID != "")
	{
		ControlVisibleChange (FloatPaneControlID, true);
		SetFloatPanePosition();
	}	
}

// set floatpane position
function SetFloatPanePosition () 
{	
	var control = FindControl(FloatPaneControlID);
	control.style.position = "absolute";

	var cHeight, cWidth;
	if (control.style.height.substring(control.style.height.length-2)=='px'){
		//if ended with px - cut them off
		cHeight=Number(control.style.height.substring(0,control.style.height.length-2));
	} else {
		cHeight=Number(control.style.height);
	}

	if (control.style.width.substring(control.style.width.length-2)=='px'){
		//if ended with px - cut them off
		cWidth=Number(control.style.width.substring(0,control.style.width.length-2));
	} else {
		cWidth=Number(control.style.width);
	}

	if (IsNetScape()) {
		yStart = control.style.top;
		xStart = control.style.left;
	} else {
		yStart = control.style.pixelTop;
		xStart = control.style.pixelLeft;	
	}

	if (yStart.length>2) if (yStart.substring(yStart.length-2)=='px') yStart=Number(yStart.substring(0,yStart.length-2));
	if (xStart.length>2) if (xStart.substring(xStart.length-2)=='px') xStart=Number(xStart.substring(0,xStart.length-2));


	if (IsNetScape()) {
		cHeight = Number(cHeight) + 100;
		cWidth = Number(cWidth) + 30;
	
		Ypos = window.pageYOffset + window.innerHeight - cHeight;
		Xpos = window.pageXOffset + window.innerWidth - cWidth;
		

		if (yStart>Ypos){
			//negative side
			var nInc = -Math.log( Math.abs((Math.pow (Ypos - yStart, 3))));
		} else {
			//positive side
			var nInc = Math.log (Math.pow (Ypos - yStart, 3));
		}
		nInc/=1.5;

		if (yStart + nInc >= Ypos)
			yStart = Ypos;
		else if (yStart < Ypos)	
			if (Math.abs(nInc)>1) yStart += nInc;
		else
			yStart = Ypos;		
			
		with (control.style)
		{
			top  = yStart;
			left = Xpos;	
		}	
					
	} else {
		cHeight = Number(cHeight) + 80;
		cWidth = Number(cWidth) + 50 ;	
		
		var Xpos;
		if (control.StartPos != null)
		{
			Xpos = Number(control.StartPos); 
		}
		else
		{
			Xpos = document.body.scrollLeft + window.document.body.clientWidth - cWidth;
		}
		
		Ypos = document.body.scrollTop + (window.document.body.clientHeight - cHeight);	
		//Xpos = document.body.scrollLeft + window.document.body.clientWidth - cWidth;	
		
		var nInc = Math.log (Math.pow (Ypos - yStart, 3));
		if (yStart + nInc >= Ypos)
			yStart = Ypos;
		else if (yStart < Ypos)	
			yStart += nInc;
		else
			yStart = Ypos;		
		with (control.style)
		{
			pixelTop  = yStart;
			pixelLeft = Xpos;	
		}		
	}
	
	setTimeout('SetFloatPanePosition()', 10);
}

// change methods
function ChangeControlText (id, text) 
{       		
	text = text.replace (/\n/g, "<BR>");
	text = text.replace (/\'/g, "\\\'");
			
	FindControl(id).innerHTML = text;
}

// find control
function FindControl(id) 
{
    var r;
	if (document.getElementById){
		r = document.getElementById(id);
	} else {
	    if (!IsNetScape) r = document.all[id]; else r=false;
	}
	
	try {	       	    
		return r;
	} catch (e) {	
	}
}