//-------------------------------------

var bShowDebug = false;
//var bShowDebug = true;

//-------------------------------------
// Add any global functions here.

//-------------------------------------
// Debug Print function

var DBG =
{
	Print : function(_Text)
	{
		if (bShowDebug == true)
		{
/*
			if (this.LineNum != null)
			{
				this.LineNum++;
			}
			else
			{
				this.LineNum = 1;
			}

			//_Text = this.LineNum + ': ' + _Text;
*/
			_Text = GetDateTime() + ' ' + _Text;

			if (!window.dbgwnd)
			{
				window.dbgwnd = window.open("","debug","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=600,height=250");
				window.dbgwnd.document.write('<html><head></head><body style="background-color:black"><div id="main" style="color:green;font-size:12px;font-family:Courier New;"></div></body></html>');
			}

			var Console = window.dbgwnd.document.getElementById("main");

			if (Console.innerHTML != "")
			{
				Console.innerHTML = _Text + "<br/>" + Console.innerHTML;
			}
			else
			{
				Console.innerHTML = _Text;
			}
		}
	}
}

//-------------------------------------

function GetDateTime()
{
	var DT = new Date();
	return (Int2String(DT.getDate(),2) + '/' + Int2String(DT.getMonth() + 1,2) + '/' + DT.getFullYear() + ' ' + Int2String(DT.getHours(),2) + ':' + Int2String(DT.getMinutes(),2) + ':' + Int2String(DT.getSeconds(),2) + '.' + parseInt(((DT.getMilliseconds() % 1000) / 100) % 10));
}

//-------------------------------------

function Int2String(_Data,_Pad)
{
	_Data = _Data.toString();
	return (Array(_Pad + 1 - _Data.length).join('0') + _Data);
}

//-------------------------------------

function DecrementStringValue(_sValue)
{
	try
	{
		var Value = parseInt(_sValue);
		return ((--Value) + '');
	}
	catch (e)
	{
	}
	return (0);
}

//-------------------------------------

function TestAndDownloadFile()
{
	try
	{
		// If just downloaded a .pdf
		if ((window.name == "2") || (window.name == "1"))
		{
			var Index = document.URL.indexOf("FilePath=",0);
			if ((Index >= 0) && (Index < document.URL.length))
			{
				//DBG.Print("Index = " + Index + " URL = DownloadFile.aspx" + document.URL.substring(Index));
				window.location = "DownloadFile.aspx?" + document.URL.substring(Index);
			}

			// Used a counter to allow .pdf to be downloaded.
			// Set to 2 because IE may require 2nd pass for download confirmation.
			// And this still works otherwise, 'cos 2nd call is away from download page.
			window.name = DecrementStringValue(window.name);
		}
	}
	catch (e)
	{
	}
};
		
//-------------------------------------
