// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

var cal

function popCal(popLink, inputBoxID) {
	// INSTRUCTIONS:
	//	to implement this, use the following syntax:
	//		popCal(this,<destination control ID>)
	//
	
	var topPos = tempY + 86; //getTopPosition(popLink) + window.screenTop - document.documentElement.scrollTop ;
	var leftPos = tempX; //getLeftPosition(popLink) + 35;
	if(cal) cal.close();
	cal = window.open('CalPopUp.aspx?textbox=' + inputBoxID,'cal','titlebar=no,toolbar=no,menubar=no,width=190,height=172,left=' + leftPos + ',top=' + topPos)
	cal.focus();
}


function getMousePos(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}

	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}

	return true;
}
document.onmousemove = getMousePos;

function getTopPosition(el)
{
	var topPos = 0;
	var parent = el.offsetParent;

	topPos += el.offsetTop
	
	while("BODY" != parent.tagName.toUpperCase())
	{
		topPos += parent.offsetTop;
		parent = parent.offsetParent;				
	}
	
	return topPos;
}

function getLeftPosition(el)
{
	var leftPos = 0;
	var parent = el.offsetParent;

	leftPos += el.offsetLeft
	
	while("BODY" != parent.tagName.toUpperCase())
	{
		leftPos += parent.offsetLeft;
		parent = parent.offsetParent;
	}	
	
	return leftPos;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		SCROLLING FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
	Restores the scroll position
	setPos is called on onsubmit event of the form post and sets the scroll position in a hidden input
	scrollDown is called on the onload event of the page and restores the scroll position

	required DTD:
		<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

	example:
		<body onload="scrollDown();">
		
		<div onclick="setPos(); document.forms[0].submit();">test</div>
*/



function setPos() {
	var yPos = 0;
	
	if (window.innerHeight) yPos = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yPos = document.documentElement.scrollTop;
	else if (document.body) yPos = document.body.scrollTop;
	
	document.forms[0].yPos.value = yPos;
}
function scrollDown() {
	yPos = document.forms[0].yPos.value;
	
	if (yPos > 0) {
		if (document.documentElement) document.documentElement.scrollTop = yPos
		else document.body.scrollTop = yPos;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		POPUP WINDOW FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
	Creates a fully customizable popup window.
	The variables sent in must be lower case.

	variables:
		VARIABLE		VALUE					DESCRIPTION
		--------------- ----------------------- ------------------------------------------------------
		windowName		string					Names the window
		windowUrl		string					Url to display in the window
		
		menubar			(yes/no | 1/0)			The File, Edit, View Menus
		toolbar			(yes/no | 1/0)			Back, Forward, Home, Stop toolbar
		locationbar		(yes/no | 1/0)			The location box with the site URL
		statusbar		(yes/no | 1/0)			Status bar (with "Document: Done")
		scrollbars		(yes/no | 1/0)			Horizontal and vertical scrollbars
		resizable		(yes/no | 1/0)			Can the window be resized?
		height			number					window height
		width			number					window width
		top				number					window top position
		left			number					window left position
		--------------- ----------------------- ------------------------------------------------------

	example:
		<div onclick="popupWindow();">test</div>
*/

	



function popupWindow(windowName,windowUrl,menubar,toolbar,locationbar,statusbar,scrollbars,resizable,height,width,top,left) {
	for (var i=0; i < popupWindow.arguments.length; i++) {
		if ( popupWindow.arguments[i] == "yes" ) { popupWindow.arguments[i] = 1; }
		if ( popupWindow.arguments[i] == "no" ) { popupWindow.arguments[i] = 0; }
	}

	windowprops = "";

	windowprops += (menubar ? ",menubars" : "") +
	(width ? ",width=" + width : "") +
	(height ? ",height=" + height : "") +
	(top ? ",screenY=" + top : "") +
	(left ? ",screenX=" + left : "") +
	(top ? ",top=" + top : "") +
	(left ? ",left=" + left : "") +
	(scrollbars ? ",scrollbars" : "") +
	(locationbar ? ",location" : "") +
	(resizable ? ",resizable" : "") +
	(statusbar ? ",status" : "") +
	(toolbar ? ",toolbar" : "");

	var newWin = window.open(windowUrl,windowName, windowprops);
	if (window.focus) {newWin.focus()}

	// this is commented so that the calling page does not
	// navigate to a blank page with the text 'true' on it
	//return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		POPUP THE COIN DETAILS WINDOW
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function detailsWindow(sWindowName,sUrl) {
	sWindowName += "";
	sUrl += "";
	
	var yes = 1;
	var no = 0;

	var menubar = no;		// The File, Edit, View Menus
	var scrollbars = yes;   // Horizontal and vertical scrollbars
	var locationbar = no;	// The location box with the site URL
	var directories = no;	// the "What's New", "What Cool" links
	var resizable = yes;	// Can the window be resized?
	var statusbar = no;		// Status bar (with "Document: Done")
	var toolbar = no;		// Back, Forward, Home, Stop toolbar
	var width = 825;		// window width
	var height = 650;		// window height
	var top = 25;			// window top
	var left = 25;			// window left

	windowprops = "";

	windowprops += (menubar ? ",menubars" : "") +
	(width ? ",width=" + width : "") +
	(height ? ",height=" + height : "") +
	(top ? ",screenY=" + top : "") +
	(left ? ",screenX=" + left : "") +
	(top ? ",top=" + top : "") +
	(left ? ",left=" + left : "") +
	(scrollbars ? ",scrollbars" : "") +
	(locationbar ? ",location" : "") +
	(directories ? ",directories" : "") +
	(resizable ? ",resizable" : "") +
	(statusbar ? ",status" : "") +
	(toolbar ? ",toolbar" : "");

	var newWin = window.open(sUrl,sWindowName, windowprops);
	if (window.focus) {newWin.focus()}

	//return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////