//--
// Version: 1.0
// Author: A. Radovanovic (admin@radovanovic.com)
// Purpose: various jscript functions

// CenterWindow
// Centers window when called from the window.open:
// window.open ('Pg.html', 'WinName', CenterWindow('menu=no',200,300))

function CenterWindow (sFeatures,w,h)
{

	var winTop = (screen.availHeight - h - 50) / 2; // "magic" number 50: Windows bottom menu
	var WinLeft = (screen.availWidth - w) / 2;
	return ('\'' + sFeatures + ' width=' + w + ', height=' + h + ', top=' + winTop + ', left=' + WinLeft + ' \'');
}


// ToolTips library

//	CreateToolTip: creates a tooltip popup
//	Code example:
//		var loginToolTip = new Object;
//	  CreateToolTip(MyToolTip,220,140,'My toolTipText');

function CreateToolTip (oToolTip,width,height,ToolTipText)
{
	oToolTip.oPopup = window.createPopup();
	oToolTip.width = width;
	oToolTip.height = height;
	oToolTip.TipText = '<div style="background:#ffffcc;border:solid 1px black; font:normal 8pt arial;padding:5px;width:100%;height:100%;">' + ToolTipText + '</div>'
	return oToolTip;	
}

//	ToolTipShow / ToolTipHide: shows and hides the tooltips
//	Code example:
//		<span onmouseover="ToolTipShow(loginToolTip)" onmouseout="ToolTipHide(loginToolTip)"><img src="../Icons/Question.gif"></span>


 
function ToolTipShow(oToolTip)
{
    var lefter = event.offsetY+10;
    var topper = event.offsetX;
    oToolTip.oPopup.document.body.innerHTML = oToolTip.TipText; 
    oToolTip.oPopup.show(topper,lefter, oToolTip.width, oToolTip.height, event.srcElement);
}

function ToolTipHide(oToolTip)
{
	oToolTip.oPopup.hide ();
}

// CalendarOpen
// Purpose: opens a calendar in the file Calendar/ChooseDate.asp
// Input:
//	date1: 'Formname.DateFieldname'
//	Month, Year: 1 - 12 month number (optional, if not specified then display current date)

function CalendarOpen (date1,Month,Year)
{
	window.open('../Calendar/ChooseDate.asp?fieldID=' + date1 + '&Month=' + Month + '&Year=' + Year, 'CalendarWin', CenterWindow('directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no,',200,220));
}

function makeCool(a) {
	a.style.background = "gainsboro";
	a.style.cursor="hand"
}

function makeNormal(a) {
	a.style.background = "#FFFFEF";
}


function buttonPressed(id) {
	id.className = "table.NumbersBox td Pressed";
 }

function buttonReleased(id) {
	id.className = "table.NumbersBox td NotPressed";
 }

// -- Function PickPositions
// pick the number positions within the combination.
// ID = object ID
// nPicked = number clicked within the box
// sSetPositions = string containing positions (e.g. 1001110010)

function PickPositions (ID, nPicked, sSetPositions)
{   
    if (sSetPositions.charAt(nPicked) == "1") 
    {
		sSetPositions = sSetPositions.substring(0,nPicked) + '0' + sSetPositions.substring(nPicked+1,sSetPositions.length)
		buttonReleased(ID);
		return (sSetPositions);
	}
	else
	{
		sSetPositions = sSetPositions.substring(0,nPicked) + '1' + sSetPositions.substring(nPicked+1,sSetPositions.length)
		buttonPressed(ID);
		return (sSetPositions);
	}
}
