//---------------------------------------------------------------------------------------------------------------------------
//
// COMMON.JS
// File contains common javascript functions to use anywhere in AOAPrivate
//---------------------------------------------------------------------------------------------------------------------------
//
// Version             0.06
// Created on          xx.xx.xxxx
// Last updated on     02.12.2004
//
//---------------------------------------------------------------------------------------------------------------------------
//
// Version  Date        Modifier  Reason
// 0.01     08.10.2003  TP        Created this file and added function ChangeCursorToHourGlass
//---------------------------------------------------------------------------------------------------------------------------

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse	= [10,0];	//image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration	= 0;		//duration in seconds image should remain visible. 0 for always.

if (document.getElementById || document.all)
{
	document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:0px;width:1px;height:1px"><img src="images/waitcursor.gif" border="0"></div>');
}

function gettrailobj()
{
	if (document.getElementById)
	{
		document.getElementById("trailimageid").style.visibility="visible";
		return document.getElementById("trailimageid").style;
	}
	else if (document.all)
	{
		document.getElementById("trailimageid").style.visibility="visible";
		return document.all.trailimagid.style;
	}
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function hidetrail()
{
	gettrailobj().visibility="hidden";
	document.onmousemove="";
}

function followmouse(e)
{
	
	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];
	
	if (typeof (e) != "undefined")
	{
		xcoord+=e.pageX;
		ycoord+=e.pageY;
	}
	else if (typeof window.event !="undefined")
	{
		xcoord+=truebody().scrollLeft+event.clientX;
		ycoord+=truebody().scrollTop+event.clientY;
	}
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	
	if (xcoord>docwidth || ycoord> docheight)
	{
		gettrailobj().display="none";
	}
	else 
	{
		gettrailobj().display="";
		gettrailobj().left=xcoord+"px";
		gettrailobj().top=ycoord+"px";
	}
}

function ChangeCursorToHourGlass(bParamValue)
{

	document.onmousemove = followmouse;

	if ( displayduration > 0 )
	{
		setTimeout("hidetrail()", displayduration*1000);
	}


	//Change visibility of progressbar to visible
	if ( document.getElementById( 'tdProgressbar' ) != null )
	{
		document.getElementById( 'tdProgressbar' ).style.visibility = "visible";
		document.getElementById( 'tdProgressbar' ).innerHTML = "<img src='images/progressbar.gif'>";

	}

	//Parameter values
	//false			= Disable only navibar
	//true			= Disable navibar and all formfields
	//buttons		= Disable navibar and all buttons
	//ObjectsName	= Disable navibar and buttons, but not this object
	
	if (document.body)
	{
		document.body.style.cursor="wait";
	}
			
	var ix,bTypeIsButton;	
	
	if (document.forms[0].elements)
	{	
		//Loop form elements	
		for (ix=0;ix<document.forms[0].elements.length;ix++) 
		{
			if (document.forms[0].elements[ix].style)
			{
				document.forms[0].elements[ix].style.cursor="wait";	
			}	
			if (bParamValue!='false')
			{			
				//Do not do anything with hidden fields
				
				
				if (document.forms[0].elements[ix].type!='hidden')
				{

					switch (bParamValue) 
					{
						// Disable navibar and all formfields
						case 'true':
							document.forms[0].elements[ix].disabled=true;
						break;
						
						// Disable navibar and all buttons
						case 'buttons':
							bTypeIsButton = bIsButton(document.forms[0].elements[ix].type);
			
							if (bTypeIsButton)
							{
								document.forms[0].elements[ix].disabled=true;
							}
						break;

						// Disable navibar and buttons, but not this object
						default:
						bTypeIsButton = bIsButton(document.forms[0].elements[ix].type);
						
						if (bTypeIsButton && document.forms[0].elements[ix].name!=bParamValue)
						{
							document.forms[0].elements[ix].disabled=true;
						}
						break;
					}
				}
			}
		}
	}					
	//Disable images
	if (document.images)
	{
		for (ix=0;ix<document.images.length;ix++)
		{
			document.images[ix].onclick			= '';
			if (document.images[ix].style)
			{
				document.images[ix].style.cursor	= "wait"
			}
		}
	}
							
	//Disable links
	if (document.links)
	{
		for (ix=0;ix<document.links.length;ix++)
		{
			document.links[ix].href		= '#';
			document.links[ix].target	= '';
			document.links[ix].onclick	= '';
		}
	}
}

//TP 08.10.2003
//Function that check if object's type was button
function bIsButton (sType)
{
	if (sType=='button' || sType=='submit' || sType=='reset')
	{
		return true;
	}
	//Else
	return false;
}

//TP 09.10.2003
//Function to submit form
function submitForm ()
{
	document.forms[0].submit();
}

function body_onload()
{
	document.forms[0].elements['targetstep'].value='';
}

function gotostep(stepname)
{
	document.forms[0].elements['targetstep'].value=stepname;
	document.forms[0].submit();
	ChangeCursorToHourGlass('true');
	return false;
}


function popImageZoom(imageURL,imageTitle,imyImageWidth,imyImageHeight)
{
	imageURL   = escape(imageURL);
	imageTitle = escape(imageTitle);
	
	var imgWin = window.open("popupimage.asp?imageURL="+imageURL+"&imageTitle="+imageTitle, "", "resizable=0,height=" + imyImageHeight + ",width=" + imyImageWidth);
	if( !imgWin.focus ) { imgWin.focus(); }
	imgWin.close;
}
			
function selectMe (sIdForRadio)
{

	if (document.forms[0].elements)
		{
			var i;
			for (i=0;i<document.forms[0].elements.length;i++)
			{
				var oElement = document.forms[0].elements[i];
				
					if (oElement.type=='radio') 
					{
						if (oElement.value==sIdForRadio)
						{
							oElement.checked=true;
						}	
					}
			}

		}
}