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);
	}
	
	if(cmin != 0 || csec != 0) csec--;
	
	if (csec == -1)
	{
		csec = 59;
		cmin--;
	}
	
	var t = document.getElementById('TimeLeft');
	
	if (displayit)
		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.border = "solid 1px #000000";
					t.style.backgroundColor = "#FFFFFF";
		        }
		    }
		    else if(t.style.position == "absolute")
	        {
	            t.style.position = "";
                t.style.backgroundColor = "";
                t.style.border = "";
	        }
			
			t.innerHTML = "<span style=\"background-color: #FFFFFF; color:#FF0000; font-size:1.25em; \"><b>&nbsp;Page&nbsp;Timeout:&nbsp;" + Display(cmin,csec) + "&nbsp;</b></span>";
		}
		else
			t.innerHTML = "Page&nbsp;Timeout:&nbsp;" + Display(cmin,csec) + "";
	
	if ((cmin==0) && (csec==0))
	{
		if (displayit)
		{
			t.innerHTML = "<font color='FF0000' size='5'><b>Your&nbsp;session&nbsp;has&nbsp;expired</b></font>";
			setTimeout("DownRepeat()", 1000);
		}
	}
	else
		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=1,resizable=0";
	style += ",width=" + width + ",height=" + height;
		
	var win = window.open( URL, name, style, true );
	win.resizeTo( width, height );
		
	win.focus();
}

function OpenResizableWin( URL, width, height, name )
{
	var style;
	var s1;
	var s2;
	
	style = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1";
	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;
	}
}

function DayDiff(strDate1, strDate2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	
	date1temp = new Date(strDate1);
	date1.setTime(date1temp.getTime());
	
	date2temp = new Date(strDate2);
	date2.setTime(date2temp.getTime());
	
	// sets difference date to difference of first date and second date
	
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	
	timediff = diff.getTime();
	
	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
	
	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	return days;
}


function TimeDiff(interval, strTime1, strTime2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	
	date1temp = new Date('11/24/1980 ' + strTime1);
	date1.setTime(date1temp.getTime());
	
	date2temp = new Date('11/24/1980 ' + strTime2);
	date2.setTime(date2temp.getTime());
	
	// sets difference date to difference of first date and second date
	
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	
	timediff = diff.getTime();
	
	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
	
	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);
	
	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);
	
	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);
	
	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;
	
	if(interval == 'h')
		{ return hours; }
	else if(interval == 'm' || interval == 'n')
		{ return (hours * 60) + mins; }
	else if(interval == 's')
		{ return (hours * 60 * 60) + (mins * 60) + secs; }
	else
		{ return false; }
}

function DelayFocus(c)
{
	setTimeout("document.getElementById('" + c + "').focus()", 100);
}

