function findObject(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObject(n,d.layers[i].document); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObject(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function openPopup(szFile, szName, w, h, status, scrollbars, resizable, menubar, locationOption) 
{
	var szWinFeatures;
	
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/3 : 0;

	// convert all characters to lowercase to simplify testing
	var agt=navigator.userAgent.toLowerCase();

        this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
				&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
				&& (agt.indexOf('webtv')==-1));

	if (this.nav)
		szWinFeatures = "height=" + h + ",width=" + w + ",screenY=" + TopPosition + ",screenX=" + LeftPosition + ",status=" + status + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",menubar=" + menubar + ",location=" + locationOption;
	else
		szWinFeatures = "height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",status=" + status + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",menubar=" + menubar + ",location=" + locationOption;
	
	var szErrMsg  = "\nYour web browser has failed to open a separate window "
		szErrMsg += "\nto display the help document.  Please close all unused "
		szErrMsg += "\nbrowser windows, and try again."

	// Netscape Navigator allows to open only 100 windows at the maximum
	// recycle the existing one to avoid exceeding the limit (R.L.)
	popupWin = window.open(szFile, szName, szWinFeatures)

	// check if new window failed to open
	if (popupWin)
	{
		popupWin.focus()
	} 
	else
	{
		alert(szErrMsg) // this is an extremely rare case, if it ever happens.
	}
}

function fullPopup(szFile, szName)
{
	openPopup(szFile, szName, 765, 450, "yes", "yes", "no", "yes", "yes");
}

function smallPopup(szFile, szName)
{
	openPopup(szFile, szName, 400, 400, "no", "yes", "no", "no", "no");
}

function helpPopup(szHelp) 
{
	var szFile;

	if (szHelp)
		szFile = "help/" + szHelp   // open with a given file
	else
		szFile = "help/index.htm"  // by default, open the help content file

	openPopup(szFile, "help", 400, 300, "no", "yes", "no", "no", "no") 
}

function loadMainImgs() {
	preloadImages(
		"graphics/guide_doorwayshome_on.gif", 
		"graphics/guide_whats_new_on.gif", 
		"graphics/guide_faqs_on.gif",
		"graphics/guide_related_links_on.gif", 
		"graphics/guide_contact_us_on.gif",
		"graphics/leftnavitem_folder_agguide_sel.gif",
		"graphics/leftnavitem_folder_courselistsite_sel.gif",
		"graphics/leftnavitem_logout_sel.gif", 
		"graphics/leftnavitem_login_sel.gif",
		"graphics/icon_homelinks_guide_on.gif",
		"graphics/icon_homelinks_list_on.gif",
		"graphics/icon_homelinks_updates_on.gif");
}

function loadMainSubmImgs() {
	preloadImages(
		"graphics/topnavitem_school_info_on.gif",
		"graphics/topnavitem_revise_courses_on.gif", 
		"graphics/topnavitem_add_courses_on.gif", 
		"graphics/topnavitem_summary_on.gif",
		"graphics/topnavitem_submit_on.gif", 
		"graphics/topnavitem_district_info_on.gif", 
		"graphics/topnavitem_program_info_on.gif",
		"graphics/leftnavitem_folder_schoolreturn_sel.gif", 
		"graphics/leftnavitem_folder_districtreturn_sel.gif",
		"graphics/leftnavitem_folder_programreturn_sel.gif");
}

function loadAddCoursesImgs() {
	preloadImages(
		"graphics/leftnavitem_addcourses_instr_sel.gif", 
		"graphics/leftnavitem_addcourses_list_sel.gif");
}

function loadReviseCoursesImgs() {
	preloadImages(
		"graphics/leftnavitem_revisecourses_instr_sel.gif",
		"graphics/leftnavitem_revisecourses_caltype_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesa_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesb_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesc_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesd_sel.gif",
		"graphics/leftnavitem_revisecourses_coursese_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesf_sel.gif",
		"graphics/leftnavitem_revisecourses_coursesg_sel.gif",
		"graphics/leftnavitem_revisecourses_courses_sel.gif");
}

function loadInstInfoImgs() {
	preloadImages(
		"graphics/leftnavitem_schoolinfo_instr_sel.gif",
		"graphics/leftnavitem_schoolinfo_name_sel.gif",
		"graphics/leftnavitem_schoolinfo_streetaddr_sel.gif",
		"graphics/leftnavitem_schoolinfo_website_sel.gif",
		"graphics/leftnavitem_schoolinfo_principal_sel.gif",
		"graphics/leftnavitem_schoolinfo_curdirector_sel.gif",
		"graphics/leftnavitem_schoolinfo_listcontact_sel.gif",
		"graphics/leftnavitem_schoolinfo_schoolinfo_sel.gif");
}

function submitUpdates(szLocation)
{
	var answer = confirm("ARE YOU SURE YOU ARE FINISHED UPDATING?\n\nIf you are sure all desired updates to your 2003-04 course list \nare included in this submission, click the 'OK' button.  \n\nOtherwise, click 'Cancel' and continue updating.");

	if (answer)
	{
		document.location = szLocation;
	}
}

function returnToDoorwaysHome()
{
	var answer = confirm("ARE YOU SURE YOU WANT TO LOGOUT?\n\nIf you are sure you want to logout of this site \nand return to Doorways Home, click the 'OK' button.  \n\nOtherwise, click 'Cancel'.");

	if (answer)
	{
		goTo('logoutToDoorwaysHome');
		//document.location = "index.htm";
	}
}

function init(szFieldName)
{
	document.frm.elements[szFieldName].focus();
	document.frm.elements[szFieldName].select();
}

function prototypeLogin()
{
	if (document.frm.userID.value == "district")
	{
		document.location = "folder_district.htm";
	}
	else if (document.frm.userID.value == "program")
	{
		document.location = "folder_program.htm";
	}
	else
	{
		document.frm.submit();
	}
}

NS4 = (document.layers) ? true : false;

function checkEnter(event)
{ 	
	var code = 0;
	
	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
	if (code==13)
		prototypeLogin();
}

function checkAll(fieldName)
{
	var i;
	var len;
	
	if (fieldName)
	{
		len = fieldName.length;
	}
	
	for (i=0; i<document.frm.elements.length; i++)
	{	
		if (document.frm.elements[i].type == "checkbox" &&
				(!fieldName || (fieldName && document.frm.elements[i].name.substring(0, len) == fieldName)))
		{
			document.frm.elements[i].checked = true;
		}
	}
}

function goTo(event)
{
	document.frm.event.value = event;
	document.frm.submit();
}

function selectTranInProgress(tranID, academicYrKey)
{
	document.transinprogress.tranID.value = tranID;
	document.transinprogress.academicYrKey.value = academicYrKey;
	document.transinprogress.submit();
}

