window.onerror = null;
window.onload = setFocus;

function setFocus()
{
	if ( document.getElementById )
	{
		if ( (window.location.pathname.indexOf("search.html") > - 1) || (window.location.pathname.indexOf("lab_ctr_search.php") > - 1) )
		{
			document.getElementById("quickSearch").focus();
		}
	}
}	

var menuActive = 0;
var onLayer;
var timeOn = null;
var useMenu = 0;

var hide  = true;


if ((navigator.appName=="Netscape" && parseInt(navigator.appVersion)<5)) {
	rollovers = 0; 
}
else
{
	rollovers = 1; 
}

function preloadimages() {
if (rollovers) {
n1 = new Image(); 
n1.src ="./uiparts/";
}
}

function storyactivate(name) {
	if (rollovers) {
		document [name].src = "./images/" + name + "on.jpg";
	}
}
function storydisable(name) {
	if (rollovers) {
		document [name].src = "./images/" + name + ".jpg";
	}
}

function am(name) {
	if (rollovers) {
	}
}
function dm2(name) {
	if (rollovers) {
	}
}

function dm(name) {
	if (rollovers) {
	}
	btnTimer();
}

function setLyr(obj,lyr)
{
if (rollovers) {
	am(lyr);
	lyr = 'menu_'+lyr;
	if (timeOn != null) {
		clearTimeout(timeOn);
		hideLayer(onLayer);
	}
  
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
	x.style.top = newY + 'px';

	onLayer = lyr;
}
}

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;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
		document.getElementById(name).style.visibility = "visible";
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
		document.all[name].style.visibility = "visible";
	}
	else if (document.layers)
	{
	if (document.layers[name])
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
		document.layers[name].visibility = "show";
	}
	else
	{
		this.obj = document.layers.testP.layers[name];
	this.style = document.layers.testP.layers[name];
	}
	}
}

// Hide the given layer
function hideLayer(layerName) {
  if (menuActive == 0) {
    if (document.getElementById) {
      document.getElementById(layerName).style.visibility = "hidden";
    } else if (document.layers) {
      document.layers[layerName].visibility = "hidden";
    } else if (document.all) {
      document.all[layerName].style.visibility = "hidden";
    }
  }
}

// Timer for button mouse out
function btnTimer() {
  timeOn = setTimeout("btnOut()", 800);
}

// Button mouse out
function btnOut(layerName) {
	if (menuActive == 0) {
		hideLayer(onLayer);
		hideLayer(onLayer);
	}
}

// Menu mouse over
function menuOver(itemName) {
	clearTimeout(timeOn);
	 menuActive = 1;
}

// Menu mouse out
function menuOut(itemName) {
	menuActive = 0;
	timeOn = setTimeout("hideLayer(onLayer)", 800);
}


function popupHelp(pageURL) {
	newWindow = window.open(pageURL, "Help" ,"statusbar=no,menubar=no,location=no,scrollbars=yes,toolbar=no,directories=no,resizable=yes,width=775,height=800");
	newWindow.focus();
}

function popupVideo(pageURL) {
	newWindow = window.open(pageURL, "Video" ,"statusbar=no,menubar=no,location=no,scrollbars=yes,toolbar=no,directories=no,resizable=yes,width=450,height=350");
	newWindow.focus();
}

function demoView(pageURL) {
	newWindow = window.open(pageURL, "Demo", "statusbar=no,menubar=no,location=no,scrollbars=no,toolbar=no,directories=no,resizable=yes,width=800,height=600")
newWindow.focus()
}


function openImage(theURL, winName, features) {
	window.open(theURL, winName, features);
}

// added for popup in current_students/activities_student_orgs.html, et al
function openWindow(URL) {
var thisWin = window.open(URL,"targetWindow","width=470,height=350,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
thisWin.focus();
}


// This javaScript object is used to show current html element and hide the last selected html element (by ID)
// ACTIVE ON dbforms/fac_publications.php, dbforms/fac_courses.php
var DynamicSelection = new Object();

DynamicSelection.memoryId = new String("");

DynamicSelection.displayElement = function(elementId)
{
	if ("" == this.memoryId)
	{
		var htmlElement = window.document.getElementById(elementId);
		htmlElement.style.display = "block";
		
		this.memoryId = elementId;
	}
	else if (this.memoryId == elementId)
	{
		var htmlElement = window.document.getElementById(elementId);
		if ("block" == htmlElement.style.display)
		{
			htmlElement.style.display = "none";
		}
		else
		{
			htmlElement.style.display = "block";
		}
	}
	else
	{
		var htmlElementHide = window.document.getElementById(this.memoryId);
		htmlElementHide.style.display = "none";
		
		var htmlElement = window.document.getElementById(elementId);
		htmlElement.style.display = "block";
		
		this.memoryId = elementId;
	}
}

DynamicSelection.hideElement = function(elementId)
{
	var htmlElement = window.document.getElementById(elementId);
	htmlElement.style.display = "none";
	
	this.memoryId = "";
}

//This validation if for validating the date on /dbforms/fac_publication.php
function validateDateForm(formObj) {
	var date_range_low  = 1753;
	var date_range_high = 9999;
	
	var date_year = formObj.date_year.value;
	
	if ("" != date_year) {
		if (!isNaN(date_year) 
				&& date_year >= date_range_low 
				&& date_year <= date_range_high) {
			return true;
		}
		else {
			alert("Date must be numeric and between the values: 1753 - 9999")
			return false;
		}
	}
}
