
var objPopup;
objPopup = null;

var u3;

var browserType = '?';
var browserVersion = '?';
var elUnselect = true;

var prevDate = '';
var prevTime = '';

var spinTimer = null;

//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function getBrowser() {

	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;

	ua = navigator.userAgent;
	
	s = 'Opera';
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		browserType = 'Opera';
		browserVersion = this.version;
		return;
	}

	s = 'Netscape6/';
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		browserType = 'Netscape';
		browserVersion = this.version;
		return;
	}

	s = 'Firefox/';
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		browserType = 'Firefox';
		browserVersion = this.version;
		return;
	}

	// Treat any other "Gecko" browser as Netscape 6.1.

	s = 'Gecko';
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		browserType = 'Gecko';
		browserVersion = '(treated as Netscape 6.1)';
		return;
	}

	s = 'MSIE';
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		browserType = 'Microsoft IE';
		browserVersion = this.version;
		return;
	}
}

var objBrowser = new getBrowser();

//----------------------------------------------------------------------------
// Code to determine if cookies are enabled.
//----------------------------------------------------------------------------

var objCookieTest = {};

objCookieTest.set = function(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

objCookieTest.get = function(name) {
	name += "=";
	var s = document.cookie.split("; ");
	for(var i = 0; i < s.length; i++) {
		var c = s[i];
		if (c.indexOf(name) == 0) {
			return unescape(c.substring(name.length,c.length));
		}
	}
	return null;
}

objCookieTest.erase = function(name) {
	this.set(name,"",-1);
}

objCookieTest.isEnabled = function() {
	this.set("cookietest","cookietest");
	return this.get("cookietest") != null;
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


//----------------------------------------------------------------------------
// Code to determine if popups are blocked.
//----------------------------------------------------------------------------

function popupTest() {
	var objRegExp = new RegExp('object','gi');
	try {
		leftPos = screen.width + 1000;
		topPos = screen.height + 1000;
		popParams = 'width = 1, height= 1, top=' + topPos + ', left=' + leftPos + ', scrollbars=yes, location=no, directories=no, status=yes, menubar=no, toolbar=no, resizable=no, fullscreen=no';
		objPopup = window.open('','test', popParams);
		objPopup.close();
	}
	catch(e) { }
	if (!objRegExp.test(String(objPopup))) {
		return "blocked";
	}
	else {
		//alert('No pop-up blocker or pop-up blocker is disabled!');
		return "enabled";
	}
}

//----------------------------------------------------------------------------
// Code to determine browser window dimensions.
//----------------------------------------------------------------------------

function getWinHeight() {
	var winH = 0;
	if (typeof(window.innerHeight) == 'number') {
		winH = window.innerHeight;
		if (document.documentElement && document.documentElement.clientHeight) {
			winH2 = document.documentElement.clientHeight;
		}
		else {
		    if (document.body && document.body.clientHeight) {
				winH2 = document.body.clientHeight;
		    }
		}
		if (winH2 > 0 && winH2 < winH) { winH = winH2 }
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			winH = document.documentElement.clientHeight;
		}
		else {
		    if (document.body && document.body.clientHeight) {
				winH = document.body.clientHeight;
		    }
		}
	}
	return winH;
}

function getWinWidth() {
	var winW = 0;
	if (typeof(window.innerWidth) == 'number') {
		winW = window.innerWidth;
		if (document.documentElement && document.documentElement.clientWidth) {
			winW2 = document.documentElement.clientWidth;
		}
		else {
		    if (document.body && document.body.clientWidth) {
				winW2 = document.body.clientWidth;
		    }
		}
		if (winW2 > 0 && winW2 < winW) { winW = winW2 }
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			winW = document.documentElement.clientWidth;
		}
		else {
		    if (document.body && document.body.clientWidth) {
				winW = document.body.clientWidth;
		    }
		}
	}
	return winW;
}


//----------------------------------------------------------------------------
// Code to get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
//----------------------------------------------------------------------------

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }

function getAbsPos(elt,which) {
	iPos = 0;
	while (elt != null) {
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}

function findPosX(obj) {
	var curLeft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)	{
			if (obj.offsetLeft >= 0) {
				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;
}

//----------------------------------------------------------------------------
// Code to redirect unsupported browsers.
//----------------------------------------------------------------------------

function bypassBrowserCheck() {
	return false;
}

supportedTest = function() {
	if (objCookieTest.isEnabled() != true) {
		document.location = '/unsupported.asp?e=cookies';
	}
	if (bypassBrowserCheck() == true) {
	}
	else {
		if (objBrowser.isOP == true) {
			//document.location = '/unsupported.asp?e=Opera';
		}
		if (objBrowser.isIE == true && objBrowser.version < 5.5) {
			document.location = '/unsupported.asp?e=oldIE';
		}
	}
}

runPopupTest = function() {
	var popTest = popupTest();
	if (popTest == 'blocked') {
		document.location = '/unsupported.asp?e=popupblocker';
	}
}

function closePopup() {
	if (objPopup && !objPopup.closed && objPopup.location)	{
		objPopup.close();
	}
	//if (objXtendr && !objXtendr.closed && objXtendr.location)	{
	//	objXtendr.close();
	//}
}

function focusPopup() {
	if (objPopup && !objPopup.closed && objPopup.location)	{
		if (objPopup.focus) {
			objPopup.focus();
			return false;
		}
	}
}

function startUnselect() {
	elUnselect = true;
	if (document.getElementById) {
		document.body.onselect = function() { document.selection.empty();return false; };
		if (document.getElementById('header')) {
			childEls(document.getElementById('header'),unselectable);
		}
		if (document.getElementById('navmenu')) {
			childEls(document.getElementById('navmenu'),unselectable);
		}
		if (document.getElementById('photoPages')) {
			childEls(document.getElementById('photoPages'),unselectable);
		}
		if (document.getElementById('formsNavigation')) {
			childEls(document.getElementById('formsNavigation'),unselectable);
		}
	}
}

function childEls(el,f) {
	f(el)
	for (var c = el.firstChild; c; c = c.nextSibling) {
		if (c.nodeType == 1) {
			childEls(c,f);
		}
	}
}

function unselectable(el) {
	if (el.id == 'layout') {
		return;
	}
	if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA') {
		return;
	}
	if (el.className == 'pauseUnselect') {
		elUnselect = false;
	}
	if (elUnselect == false && el.className == 'resumeUnselect') {
		elUnselect = true;
	}
	if (elUnselect == true) {
		//el.unselectable = 'on';
		cn = el.className;
		if (cn != '') {
			el.className = cn + ' unselectable';
		}
		else {
			el.className = 'unselectable';
		}
		el.onselectstart=function() { document.selection.empty();return false; };
	}
}

function cancelMouseDrag(o,e) {
	var txt = '';
	if (window.getSelection)	{
		txt = window.getSelection();
	}
	else if (document.getSelection) {
		txt = document.getSelection();
	}
	else if (document.selection) {
		txt = document.selection.createRange().text;
	}
	else return;
	if (txt != '') {
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		e.keyCode = 0;
		e.returnValue = false;
		if (document.selection) {
			alert('Sorry, but you can\'t drag\nyour selection into this area!');
			document.selection.empty();
		}
	}
	return false;
}

function doHourglass() {
	document.body.style.cursor = 'wait';
}

function clearHourglass() {
	document.body.style.cursor = '';
}

function pageWait() {
	setTimeout("disableInputs()", 500);
}

function disableInputs() {
	document.body.style.cursor = 'wait';
	//if (document.getElementById('navmenu')) {
	//	closeMenu();
	//}
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'hidden') {
			x[i].style.cursor = 'wait';
			x[i].disabled = true;
		}
	}
	var x = document.getElementsByTagName('select');
	for (var i=0;i<x.length;i++) {
		x[i].style.cursor = 'wait';
		x[i].disabled = true;
	}
	var x = document.getElementsByTagName('textarea');
	for (var i=0;i<x.length;i++) {
		x[i].style.cursor = 'wait';
		x[i].disabled = true;
	}
	return true;
	objLinks = document.links;
	for(i=0;i<objLinks.length;i++){
		objLinks[i].disabled = true;
		//link with onclick
		if (objLinks[i].onclick){  
			objLinks[i].onclick = new Function("return false;");
		}
		//link without onclick
		else {  
			objLinks[i].onclick = function(){return false;}
		}
	}
	return true;
}

function sendEmailBasic(sendTo, CC, BCC, replyTo, subject, message) {
    var emailBody;
    var emailTo;
    var emailSubject;
    var emailCC;
    var emailBCC;
    var emailReplyTo;

    var emailURL; // The URL that will open the user's email client
    
    var emailDisclaimer;
    
    emailDisclaimer = "\n\nThis e-mail contains information which (a) may be PROPRIETARY IN NATURE OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the addressee(s) named above. If you are not the addressee, or the person responsible for delivering this to the addressee(s), you are hereby notified that reading, copying or distributing this e-mail is prohibited. If you have received this e-mail in error, please contact the sender immediately.";

    // Set some default values
    emailBody = message + emailDisclaimer;
    emailTo = sendTo ? sendTo : ' ';
    emailSubject = subject ? subject : ' ';
    emailCC = CC ? CC : ' ';
    emailBCC = BCC ? BCC : ' ';
    emailReplyTo = replyTo ? replyTo : ' ';
    
    emailURL = "mailto:" + escape(emailTo) + 
	"?subject=" + escape(emailSubject) +
	"&cc=" + escape(emailCC) +
	"&bcc=" + escape(emailBCC) +
	"&replyto=" + escape(emailReplyTo) +
	"&body=" + escape(emailBody);
	
	//alert(emailURL);

    window.location = emailURL;
    return true;
}

//----------------------------------------------------------------------------
// Code to load functions on certain page events.
//----------------------------------------------------------------------------

function addLoadEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onload", func);
	}
	else if (document.getElementById) {
		window.onload=func; 
	}
	else {
		document.location = '/unsupported.asp?e=eventsJS'; 
	}
}

function addResizeEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("resize", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onresize", func);
	}
	else if (document.getElementById) {
		window.onresize=func; 
	}
	else {
		document.location = '/unsupported.asp?e=eventsJS'; 
	}
}

function addFocusEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("focus", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onfocus", func);
	}
	else if (document.getElementById) {
		window.onfocus=func; 
	}
	else {
		document.location = '/unsupported.asp?e=eventsJS'; 
	}
}

function addBlurEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("blur", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onblur", func);
	}
	else if (document.getElementById) {
		window.onblur=func; 
	}
	else {
		document.location = '/unsupported.asp?e=eventsJS'; 
	}
}

function addBeforeUnloadEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("beforeunload", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onbeforeunload", func);
	}
	else if (document.getElementById) {
		window.onbeforeunload=func; 
	}
}

function addUnloadEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("unload", func, false);
	} 
	else if (window.attachEvent) {
		window.attachEvent("onunload", func);
	}
	else if (document.getElementById) {
		window.onunload=func; 
	}
}

function popVideo(i,v) {
	if (document.getElementById) {
		el = document.getElementById(i);
		if (el) {
			var vidW, vidH; //dimensions of video popup
			vidW = 350;
			vidH = 300;
			var elX, elY; //position of page element
			elX = xPageX(el);
			elY = xPageY(el);
			var scrX, scrY; //scroll amount of page element
			scrX = xScrollX(el);
			scrY = xScrollY(el);
			var winX, winY; //position of popup window
			if (typeof window.screenLeft != "undefined") { //IE
				winX = window.screenLeft + elX - scrX;
				winY = window.screenTop + elY - scrY; 
			}
			else if (typeof window.screenX != "undefined") { //NS/Moz
				winX = window.screenX + elX - scrX;
				winY = window.screenY + elY - scrY;
			}
			else { //default - center of screen
				winX = screen.availWidth/2 - vidW/2;
				winY = screen.availHeight/2 - vidH/2;
			}
			if ((winX + vidW) > (screen.availWidth - 25)) {
				winX = screen.availWidth - vidW - 50;
			}
			if ((winY + vidH) > (screen.availHeight - 50)) {
				winY = screen.availHeight - vidH - 100;
			}
			popWinStatusBarXY('/formslib/videoOpen.asp?fld=' + el.id + '&vid=' + v, 'video', vidW, vidH, 'no', winX, winY);
		}
	}
}

function setStretch() {
	if (document.getElementById) {
		cellEl = document.getElementById('contentCell');
		stretchEl = document.getElementById('textFlowStretch');
		contentEl = document.getElementById('flowedContent');
		if (cellEl && stretchEl && contentEl) {
			var h = 0;
			var re = new RegExp('\\btextFlow\\b', 'i');
			var list = cellEl.getElementsByTagName('div');
			for (var i = 0; i < list.length; ++i) {
				if (list[i].className.search(re) != -1) {
					h = h + xHeight(list[i]);
				}
			}
			h = h - xHeight(stretchEl);
			x = xHeight(cellEl);
			xHeight(stretchEl, (x - h));
			//contentEl.style.visibility = 'visible';
		}
	}
}

function showFlow() {
	if (document.getElementById) {
		cellEl = document.getElementById('contentCell');
		if (cellEl) {
			var re = new RegExp('\\btextFlow\\b', 'i');
			var list = cellEl.getElementsByTagName('div');
			for (var i = 0; i < list.length; ++i) {
				if (list[i].className.search(re) != -1) {
					list[i].className = 'textFlowShow';
				}
			}
		}
	}
}

function hideFlow() {
	if (document.getElementById) {
		cellEl = document.getElementById('contentCell');
		if (cellEl) {
			var re = new RegExp('\\btextFlowShow\\b', 'i');
			var list = cellEl.getElementsByTagName('div');
			for (var i = 0; i < list.length; ++i) {
				if (list[i].className.search(re) != -1) {
					list[i].className = 'textFlow';
				}
			}
		}
	}
}

function hideFade() {
	if (document.getElementById) {
		for (var i = 1; i <= 7; ++i) {
			el = document.getElementById('fade' + i + 'a');
			if (el) { el.style.display = 'none'; }
			el = document.getElementById('fade' + i + 'b');
			if (el) { el.style.display = 'none'; }
			el = document.getElementById('fade' + i + 'c');
			if (el) { el.style.display = 'none'; }
			el = document.getElementById('fade' + i + 'd');
			if (el) { el.style.display = 'none'; }
			el = document.getElementById('fade' + i + 'e');
			if (el) { el.style.display = 'none'; }
		}
	}
}

function showFade(i) {
	if (document.getElementById) {
		hideFade();
		el = document.getElementById('fade' + i + 'a');
		if (el) { el.style.display = 'block'; }
		el = document.getElementById('fade' + i + 'b');
		if (el) { el.style.display = 'block'; }
		el = document.getElementById('fade' + i + 'c');
		if (el) { el.style.display = 'block'; }
		el = document.getElementById('fade' + i + 'd');
		if (el) { el.style.display = 'block'; }
		el = document.getElementById('fade' + i + 'e');
		if (el) { el.style.display = 'block'; }
	}
}

function setBottomNav1() {
	if (document.getElementById) {
		el = document.getElementById('bottomNav1');
		if (el) { el.style.display = 'block'; }
	}
}

function setBottomNav2() {
	if (document.getElementById) {
		el = document.getElementById('bottomNav2');
		if (el) { el.style.display = 'block'; }
	}
}

function pHover(el) {
	if (document.getElementById) {
		containerEl = document.getElementById(el);
		if (containerEl) {
			cTags = containerEl.getElementsByTagName('p');
			for (j = 0 ; j < cTags.length ; j++ ) {
				cTags[j].onmouseover=function() {
					this.className+=" pHover";
				}
				cTags[j].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" pHover\\b"), "");
				}
			}
		}
	}
}

function setPhover() {
	if (objBrowser.isIE == true) {
		pHover('container');
		pHover('content');
	}
}

function swapLogo(logo) {
	if (document.getElementById) {
		biggerEl = document.getElementById('logo');
		smallerEl = document.getElementById('logo2');
		smallestEl = document.getElementById('logo3');
		if (logo == 'smallest') {
			biggerEl.style.display = 'none';
			smallerEl.style.display = 'none';
			smallestEl.style.display = 'block';
		}
		else if (logo == 'smaller') {
			biggerEl.style.display = 'none';
			smallerEl.style.display = 'block';
			smallestEl.style.display = 'none';
		}
		else {
			biggerEl.style.display = 'block';
			smallerEl.style.display = 'none';
			smallestEl.style.display = 'none';
		}
	}
}

function toggleImage(el) {
	if (document.getElementById) {
		img = document.getElementById(el);
		if (img) {
			if (img.style.display == 'none') {
				img.style.display = 'block';
				showFlow();
			}
			else {
				img.style.display = 'none';
				hideFlow();
			}
		}
	}
}

function spinErth() {
	clearTimeout(spinTimer);
	if (document.getElementById) {
		erth = document.getElementById('animation');
		if (erth) {
			erth.innerHTML = '<a href="/home.asp" title="USSE home"><img src="/images/spinner.gif" width="74" height="74" alt="" class="animation" /></a>';
			erth.style.display = 'block';
		}
	}
}

function startErthSpin() {
	clearTimeout(spinTimer);
	spinTimer = setTimeout('spinErth()', 1000);
}

//addLoadEvent(setStretch);
//addResizeEvent(setStretch);

addLoadEvent(setPhover);
addLoadEvent(startErthSpin);

//addLoadEvent(supportedTest);
//addLoadEvent(startUnselect);
//addLoadEvent(startSessionXtendr);
//addBeforeUnloadEvent(doHourglass);
//addFocusEvent(focusPopup);
//addUnloadEvent(closePopup);
//addUnloadEvent(doHourglass);
//addFocusEvent(clearHourglass);
