var up, down;
var min1, sec1;
var cmin, csec;
var displayit;

displayit = false;
cmin = 9999;
csec = 0;

function Minutes(data)
{
	for (var i = 0; i < data.length; i++)
		if (data.substring(i, i+1)==":")
			break;
	return (data.substring(0, i));
}

function Seconds(data)
{
	for (var i=0;i<data.length;i++)
		if (data.substring(i, i+1)==":")
			break;
	return (data.substring(i+1,data.length)); 
}

function Display(min,sec) 
{     
	var disp;       
	
	if (min<=9)
		disp = " 0";
	else 
		disp = " ";
		
	disp += min+":";
	
	if (sec<=9)
		disp += "0" + sec;
	else
		disp += sec;
	
	return (disp);
}

function CountDown()
{
	if (displayit)
	{
		cmin = 1 * Minutes(document.SessionForm.StartTime.value);
		csec = 0 + Seconds(document.SessionForm.StartTime.value);
	}
	DownRepeat();
}

function DownRepeat() 
{
	if (cmin == 9999 && displayit)
	{
		cmin = 1 * Minutes(document.SessionForm.StartTime.value);
		csec = 0 + Seconds(document.SessionForm.StartTime.value);
	}
	
	csec--;
	
	if (csec == -1)
	{
		csec = 59;
		cmin--;
	}
	
	var t = document.getElementById('TimeLeft');
	
	if (displayit)
		if (true)
			if (cmin < 5)
			{
			    if(document.body.scrollTop)
			    {
			        if(document.body.scrollTop > 0)
			        {			            
			            t.style.position = "absolute";
			            t.style.left = 1;
			            t.style.top = document.body.scrollTop + 5;
			            t.style.backgroundColor = "#ffffff";
			            t.style.border = "solid 1px #000000";
			        }
			    }
			    else if(t.style.position == "absolute")
		        {
		            t.style.position = "";
	                t.style.backgroundColor = "";
	                t.style.border = "";
		        }
			        
				t.innerHTML = "<font color='FF0000'><b>&nbsp;Page&nbsp;Timeout:&nbsp;" + Display(cmin,csec) + "&nbsp;</b></font>";
			}
			else
				t.innerHTML = "Page&nbsp;Timeout:&nbsp;" + Display(cmin,csec) + "";
		else
			t.innerHTML = "You&nbsp;must&nbsp;complete&nbsp;this&nbsp;page&nbsp;in:&nbsp;" + Display(cmin,csec) + "";
	
	if ((cmin==0) && (csec==0))
	{
		if (displayit)
		{
			t.innerHTML = "<font color='FF0000'><b>Your session has expired</b></font>";
		}
	}
	else
		down = setTimeout("DownRepeat()", 1000);
}

function OpenWin( URL, width, height, name )
{
	var style;
	var s1;
	var s2;
	
	style = "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0";
	style += ",width=" + width + ",height=" + height;
		
	var win = window.open( URL, name, style, true );
	win.resizeTo( width, height );
		
	win.focus();
}

function OpenSearch( URL, strSearch )
{
	var style;
	var s1;
	var s2;
	var width = 400;
	var height = 500;
	var name = "StudentSearch";
	
	style = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1";
	style += ",width=" + width + ",height=" + height;
		
	var win = window.open( URL + "&strSearch=" + strSearch, name, style, true );
	win.resizeTo( width, height );
		
	win.focus();
}

function DeleteOK(passMsg)
{
	return window.confirm(passMsg);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


// function GetAbsoluteTop - when passed a control will determine the absolute Top position of the control relative to the page.
	function GetAbsoluteTop(el)
	{
		var et = 0;
		while (el)
		{
			et += el.offsetTop;
			el = el.offsetParent;
		}
		return et;
	}
	
// function GetAbsoluteBottom - when passed a control will determine the absolute Bottom position of the control relative to the page.
	function GetAbsoluteBottom(el)
	{
		var h = el.offsetHeight;
		var et = GetAbsoluteTop(el);
		
		et += h;
		return et;
	}
	
// function GetAbsoluteLeft - when passed a control will determine the absolute Left position of the control relative to the page.
	function GetAbsoluteLeft(el)
	{
		var et = 0;
		while (el != null)
		{
			et += el.offsetLeft;
			el = el.offsetParent;
		}
		return et;
	}

// function GetAbsoluteRight - when passed a control will determine the absolute Right position of the control relative to the page.
	function GetAbsoluteRight(el)
	{
		var h = el.offsetWidth;
		var et = GetAbsoluteLeft(el);
		
		et += h;
		return et;
	}

// function GetAbsoluteWidth - when passed a control will determine the absolute Width of the control.
	function GetAbsoluteWidth(el)
	{
		return el.offsetWidth;
	}

// function GetAbsoluteHeight - when passed a control will determine the absolute Height of the control.
	function GetAbsoluteHeight(el)
	{
		return el.offsetHeight;
	}

function NewWin( URL, width, height, name )
{
	var style;
	var s1;
	var s2;
	
	style = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0";
	style += ",width=" + width + ",height=" + height;
	style += ", modal=yes";
	
	var win = window.open( URL, name, style, true );
	win.resizeTo( width, height );
	
	win.focus();
	
}

function ReturnNewWin( URL, width, height, name )
{
	var style;
	var s1;
	var s2;
	
	style = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0";
	style += ",width=" + width + ",height=" + height;
	style += ", modal=yes";
	
	var win = window.open( URL, name, style, true );
	win.resizeTo( width, height );
	
	win.focus();
	
	return win;
}

function Left(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}

function Right(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function DropDownValue(strID)
{
	var o = document.getElementById(strID);
	
	if (o)
	{
		return o.options[o.selectedIndex].value;
	}
	else
	{
		return "";
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.-,";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;   
}

function IsInteger(s)
{
	var intVal;
	try
	{
		intVal = parseInt(s);
		return true;
	}
	catch(e)
	{
		return false;
	}
}


