/*
$RCSfile: core.js,v $ $Revision: 1.1.1.1 $ in tag $Name:  $
last committed $Date: 2006/11/20 03:39:30 $
  core.js
============================================================
When   		Who   	What
------------------------------------------------------------
2000-04-09  jtc   	Added documentation; added time/date format
					functions.
2001-02-09	jtc		added focusOn()
2002-10-09	jtc		merged CCC with VSS repository - added formfocus() back in
============================================================

Notes:

*/

/*	Use as an onLoad function - set focus to a specified element. 
	Standard usage in an asp file would be something like this: 
		onloadfunc = "focusOn(studentform['fname']);";
*/
function formfocus(formname, elname)
{
	/*	This manages to fake out the error handling if formname doesn't exist. */
	if ("object" == eval("typeof " + formname)) {

		/*	Assume the element specified exists at this point. Could be modified to
			do the same thing we're doing above, but usually this would represent
			a programming error, I think. */
		var elstr = formname + "['" + elname + "']";
//		alert(elstr);
		var element = eval(elstr);
		element.focus();
	}
}

/*	2000-01-31 - modified so an empty date string returns a blank string. */
/*	2000-04-10 - jtc - modified to use getFullYear() instead of getYear() - started
	running into 2/4 problems in some places. */
function format_date_mdy(datestr)
{
	if (datestr == "") return "";
	var tmpdate = new Date(datestr);
	var format = new String((tmpdate.getMonth() + 1) + "/" + tmpdate.getDate() + "/" + tmpdate.getFullYear());
//	Response.write(format + "<br>");
	return format;
}

function format_time_civhm(datestr)
{
	if (datestr == "") return "";
	var tmpdate = new Date(datestr);
	var hours = tmpdate.getHours();
	var minutes = tmpdate.getMinutes();
	var m = " am";
//	hours = "" + ((hours < 10) ? "0" : "") + hours;
	if (hours > 12){
		hours = (hours - 12)
		m = " pm"
	}
	minutes = "" + ((minutes < 10) ? "0" : "") + minutes;
	var format = new String(hours + ":" + minutes + m);
	return format;
}

/*	Kick off a popup window. 
    2001-08-29 - jnn - added the optional 'extra' parameter in which you can pass a string 
	                   containing any of the other extra properties for the new window
					   including scrollbars, resizable, toolbar, menubar, status...
					   (which are off by default - 'no' - and can be turned on by 
					   setting to 'yes')
*/
function openWindow(url, name, w, h /* , extra */) 
{
  // initialize winX and winY to default values
  // for cases where Screen object isn't supported
  var winX = 0;
  var winY = 0;
  var extra = '';
  
  with (openWindow) {
    if (arguments.length >= 5) extra = new String("," + arguments[4]);
  }

  // only set new values if 4.0 browser
  if (parseInt(navigator.appVersion) >= 4) {
    winX = (screen.availWidth - w)*.5;
    winY = (screen.availHeight - h)*.5;
  }

  popupWin = window.open(url, name, 'width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY + extra);
}


function openOpener(url, name, w, h){
	var extra = 'scrollbars=yes,resizable=yes,addressbar=yes,menubar=yes,location=yes,toolbar=yes,status=yes,directories=yes';

	if(!window.opener.closed){
		opener.document.location.href=url;
		opener.focus();
	} 
	else{
		openWindow(url, name, w, h, extra);
		/*  Can't figure out how to make this next line work...  */
		//var newwin = eval(name);
		//newwin.focus();
	}
}

// javascript sleep
function jsleep(secs) {
	secs = secs * 1000;
	d = new Date() //today's date
	while (1) {
		mill = new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if (diff > secs) {
			break;
		}
	}
}

function openMyPage(myPage, url, name, w, h /* level */){

	var extra = ''; 
	
	with (openMyPage) {
		if (arguments.length > 5) level = parseInt(arguments[5]);
	}
	
	switch (level){
		case 3: 
			extra = '';
			break;
		case 2: 
			extra = 'scrollbars=yes,resizable=yes,status=yes';
			break;
		default: 
			extra = 'scrollbars=yes,resizable=yes,addressbar=yes,menubar=yes,location=yes,toolbar=yes,status=yes,directories=yes';
			break;
	}
	
	if (!myPage || myPage.closed){
		openWindow(url, name, w, h, extra);
	}
	else {
		myPage.document.location.href = url;
		myPage.focus();
	}
}
