//Java.js
//
//Summary
//
//This is a set of JavaScript functions for performing common
//functions throughout the application

//Global Variables used throughout this document

//Variables for building new windows
var newWindow
var newURL

//This function changes a button to something else
//to provide somewhat of an animation effect.
function changeImages(imgName,imgLocation){
	document[imgName].src=imgLocation;
}

//Transfers a user to the logout.asp so that the
//session variable can be reset
function submitLogOut(){
	window.open('logout.asp','display');
}

//Sets and sends a hidden field to another page
function submitname(name) {
	form.supervisor.value = name;
	form.submit();
}

//Enables fields for database update
function enableAdd(){
	pages.cmdEditLink.disabled = true;
	pages.cmdAddLink.disabled = false;	
	pages.cboLinkList.disabled = true;
	//pages.txtName.value = "You Must Enter a name"
}

//Enables fields for database update
function enableEdit(){	
	pages.cmdAddLink.disabled = true;
	pages.cmdEditLink.disabled = false;	
	pages.cboLinkList.disabled = false;
}

//Updates fields for Database update and checks for blanks
function submitAdd(){
var name = pages.txtName.value;
var url = pages.txtURL.value;
var description = pages.txtDescription.value;
	if (name == "")
	{
		alert('You must enter a Link Name')
		pages.txtName.focus()
	}
	else if (url == "http://" || url == "")
	{
		alert('You must enter a URL')
		pages.txtURL.focus()
	}
	else
	{
		pages.page.value = name;
		pages.url.value = url;
		pages.description.value = description;
		pages.pagetype.value = pages.cboPageList.value
		// Debug - alert(pages.page.value + " " + pages.url.value + " " + pages.description.value + " " + pages.pagetype.value)
		pages.update.value = "add";
		// Debug - alert(pages.update.value);
		document.pages.submit();
		// Debug - alert('On to update');
	}		
}

//Updates fields for Database edit and checks for blanks
function submitEdit(){
var name = pages.txtName.value;
var url = pages.txtURL.value;
var description = pages.txtDescription.value;
var selected = pages.cboLinkList.value;
	if (selected == "topLink")
	{
		alert('You must select a page to Edit. If you are adding a new link please press the "Add a Link" button first.');
		pages.cboLinkList.focus();
	}
	else
	{
		if (name == "")
		{
			alert('You must enter a Link Name');
			pages.txtName.focus();
		}
		else if (url == "http://" || url == "")
		{
			alert('You must enter a URL');
			pages.txtURL.focus();
		}
		else
		{
			pages.page.value = name;
			pages.url.value = url;
			pages.description.value = description;
			pages.pagetype.value = pages.cboPageList.value;
			// Debug - alert(pages.page.value + " " + pages.url.value + " " + pages.description.value + " " + pages.pagetype.value)
			pages.update.value = "edit";
			// Debug - alert(pages.update.value);
			pages.returnPage.value = "yes";
			document.pages.submit();
			// Debug - alert(pages.linkid.value);
		}
	}		
}

//Checks the Page selected and what else is selected on the page
function submitPageChange(){
	if(pages.cboLinkList.value != "topLink")
	{
		pages.cboLinkList.value = "topLink";
		document.pages.submit();
	}
	else
	{
		document.pages.submit();
	}
}

//Checks the Link selected and what else is selected on the page
function submitLinkChange(){
	document.pages.submit();
	pages.cmdAddLink.disabled = true;
}

//Sets focus to a textfield
function setFocus()
{
	login.userid.focus();
}

//Checks to make sure no fields are blank
function checkLogon()
{
	if (login.userid.value == null || login.userid.value == "" ||
   	login.passwd.value == null || login.passwd.value == "")   	
   	{
   		alert("Please enter both User ID and Password");
   		setFocus();
   	}
   	else
   	{
   		login.submit();
   	}
}

//Checks to see if a user presses the Enter key,
//then sends to checkLogon to see if fields are blank
function checkEnter(e){ 
var characterCode
	if(e && e.which)
	{
		e = e
		characterCode = e.which
	}
	else
	{
		e = event
		characterCode = e.keyCode
	}
	if(characterCode == 13)
	{
		checkLogon()
		return false
	}
	else
	{
		return true
	}
}

//Builds the logon window
function makeLogonWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
	newWindow = window.open(newURL,"mywindow","width=200,height=350,top=150,left=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no")
}

//Makes a small window
function makeSmallWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
	newWindow = window.open(newURL,"mywindow","width=330,height=455,top=90,left=190,toolbar=no,location=Yes,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes")
}

//makes a tiny window
function makeTinyWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
	newWindow = window.open(newURL,"mywindow","width=330,height=150,top=100,left=350,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no")
}

// Gets the date the document was last modified
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}
// This is a set of JavaScript functions for creating new windows
// and allowing the original web page to remain stationary.
imageDB = new Array(10)
imageMDB = new Array(10)
imageLDB = new Array(10)
imagePDB = new Array(10)
for (var i = 0; i < imageDB.length ; i++) {
	imageDB[i] = new Image(112,144)
	imageDB[i].src = "desk" + (i+1) + ".jpg"
	imageMDB[i] = new Image(112,144)
	imageMDB[i].src = "mesk" + (i+1) + ".jpg"
	imageLDB[i] = new Image(112,144)
	imageLDB[i].src = "lesk" + (i+1) + ".jpg"
	imagePDB[i] = new Image(112,144)
	imagePDB[i].src = "pesk" + (i+1) + ".jpg"
	}
var newWindow
var newURL
function showStatus(msg) {
	window.status = msg
	return true
}

function makeNewWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
	newWindow = window.open(newURL,"mywindow","width=660,height=455,top=90,left=126,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes")
}
function makeSmallWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
	newWindow = window.open(newURL,"mywindow","width=330,height=455,top=90,left=190,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes")
}
function closeNewWindow(newURL) {
	if (newWindow) {
		newWindow.close() 
	}
}

//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();
 

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y < 100)
    {
	
   	y += 2000;
    }
  
  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'January':( 2==m)?'February':(3==m)?'March':
    ( 4==m)?'April':( 5==m)?'May':(6==m)?'June':
    ( 7==m)?'July':( 8==m)?'August':(9==m)?'September':
    (10==m)?'October':(11==m)?'November':'December';

  return "" +
	mmm+ " "+ (d<10?"0"+d:d) + ", " +
     (y<10?"0"+y:+y);

  
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}
function makeArray() {  var args = makeArray.arguments;
  for (var i=0; i<args.length; i++) {    this[i] = args[i];  }
  this.length = args.length;}var pages = new makeArray  ("select...",
   "A Page", "B Page",   "C Page", "D Page ");var urls = new makeArray
  ("main.html",   "a.html", "b.html",   "c.html", "d.html");thisUrl = 0;
urlCt = urls.length - 1;function uberNav(navigation) {
  if(navigation == "backbutton") {    if (thisUrl > 0) {      thisUrl--;
      parent.content.location.href = urls[thisUrl];
      for(i=0;i<pages.length;i++) {
        document.menuform.menu.selectedIndex=thisUrl;      }    }
  } else if (navigation == "nextbutton") {    if(thisUrl < urlCt) {
      thisUrl++;      parent.content.location.href = urls[thisUrl];
      document.menuform.menu.selectedIndex=thisUrl;    }  } else {
    i = document.menuform.menu.selectedIndex;    if(i != 0) {
      parent.content.location.href = urls[i];      thisUrl = i;      }  }}


function loadIndividual(form) {
	var jpgName = form.individual.options[form.individual.selectedIndex].value
	document.thumbnail1.src = jpgName
}
function loadCached(form) {
	var jpgIndex = form.cached.selectedIndex
	document.thumbnail2.src = imageDB[jpgIndex].src
}

function checkTimer() {
	 
	var timeoutID = setTimeout("checkTimer1()",500)
		
	 
}
function checkTimer1() {
	 
		var newIndex = 0
		var jpgName = document.thumbnail2.src
		var jpgIndex = (jpgName.charAt(jpgName.length - 5)) - 1
		if (jpgIndex < imageDB.length - 1) {
			newIndex = jpgIndex + 1
		}
		document.thumbnail2.src = imageDB[newIndex].src
		
		var timeoutID = setTimeout("checkTimer2()",500)
		
		
		
	 
}
function checkTimer2() {
	 
				
		var newMIndex = 0
		var jpgMName = document.thumbnail3.src
		var jpgMIndex = (jpgMName.charAt(jpgMName.length - 5)) - 1
		if (jpgMIndex < imageMDB.length - 1) {
			newMIndex = jpgMIndex + 1
		}
		document.thumbnail3.src = imageMDB[newMIndex].src
		var timeoutID = setTimeout("checkTimer3()",500)
		
		
		
	 
}
function checkTimer3() {
	 
		var newLIndex = 0
		var jpgLName = document.thumbnail4.src
		var jpgLIndex = (jpgLName.charAt(jpgLName.length - 5)) - 1
		if (jpgLIndex < imageLDB.length - 1) {
			newLIndex = jpgLIndex + 1
		}
		document.thumbnail4.src = imageLDB[newLIndex].src
		var timeoutID = setTimeout("checkTimer4()",500)
		
		
		
}
function checkTimer4() {
	 
		var newPIndex = 0
		var jpgPName = document.thumbnail5.src
		var jpgPIndex = (jpgPName.charAt(jpgPName.length - 5)) - 1
		if (jpgPIndex < imagePDB.length - 1) {
			newPIndex = jpgPIndex + 1
		}
		document.thumbnail5.src = imagePDB[newPIndex].src
		var timeoutID = setTimeout("checkTimer1()",500)
		
		
		
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0

eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

if (restore) selObj.selectedIndex=0;

}

function MM_findObj(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=MM_findObj(n,d.layers[i].document); return x;

}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0

var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);

}