// Layer Menus.

var timer;
var timerSub;
var curItem;
var subItem;

function hold() {
	if(timer) clearTimeout(timer);
}

function holdSub() {
	if(timer) clearTimeout(timer);
	if(timerSub) clearTimeout(timerSub);
}

function display(which) {
	if(timer) clearTimeout(timer);
	if(curItem) hide(curItem);
	curItem=which;
	show(curItem);
}

function displaysub(which) {
	if(timerSub) clearTimeout(timerSub);
	if(subItem) hide(subItem);
	subItem=which;
	show(subItem);
}

function flush() {
	timer = setTimeout('clearCur()',500);
}

function flushSub() {
	timerSub = setTimeout('clearSub()',500);
	timer = setTimeout('clearCur()',500);
}

function clearCur() {
	if(subItem != null) {
		hide(subItem);
		subItem = null;
	}
	hide(curItem);
	curItem = null;
}

function clearSub() {
	if(subItem != null) {
		hide(subItem);
		subItem = null;
	}
}

// Determine browser.

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;

// Image stuff

function MM_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 MM_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=MM_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 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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapNestImgRestore() { //v3.0
  var i,x,a=document.MM_sr2; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapNestImage() { //v3.0
  var i,j=0,x,a=MM_swapNestImage.arguments; document.MM_sr2=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr2[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  if (selObj.options[selObj.selectedIndex].value != '') {
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
  }
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

/*
open a new window, center it and set dimensions relative to the users screen
url: url of new document
name: document name
statbar: boolean yes or no for statusbar display
scroll: boolean yes or no for scrollbars
locate: boolean yes or no for locationbars
x: set the new window height with a percentage value relative to the users screen
y: set the new window width with a pecentage value relative to the users screen
usage: javascript:winOpen('index.htm','newwin','yes','yes','yes',.5,.5)
*/
function winOpen(url,name,statbar,scroll,locate,x,y)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = parseInt(screenheight)* y//set new window height properties
var winwidth = parseInt(screenwidth)* x//set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft)
}

function winOpenCenter(url,name,statbar,scroll,locate,resize,xWidth,yWidth)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = yWidth //set new window height properties
var winwidth = xWidth //set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',resizable='+resize+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft);
return win;
}

function confirmDel(message, URL) {
	conWin = winOpenCenter('','confirmWindow','no','no','no','no',300,120)
	conWin.document.writeln('<html><head><title>Confirm Deletion</title></head><body>');
	conWin.document.writeln('<center><b>' + message + '</b><br>');
	conWin.document.writeln('<form><input type="button" value="Yes" onClick="window.opener.document.location=\'' + URL + '\'; window.close()">');
	conWin.document.writeln('<input type="button" value="No" onClick="window.close()"></form></center>');
	conWin.document.writeln('</body></html>');
}

// Email Checker

function onFormSubmit(formObj) {
	if (!isEmailValid(formObj.Email.value))
		{
		formObj.Email.focus();
		return false;
		}
	return true;
}

function isEmailValid(str)
{
	var pos;
	var errorCount = 0;
	var email = str;
	
	var validStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.[]-_";

	if (email == "") {
		alert("Please enter your email address.");
		return false;
	}
	
	if (email.charAt(0) == "@" || email.charAt(0) == "." || email.charAt(0) == "[" || email.charAt(0) == "]" || email.charAt(0) == "-" || email.charAt(0) == "_") errorCount++;
	
	if (!validCharacters(email,validStr)) errorCount++;
		
	for (i = 1; i < email.length; i++) {
		if ((email.charAt(i-1) == "." && email.charAt(i) == ".") || (email.charAt(i-1) == "." && email.charAt(i) == "@") || (email.charAt(i-1) == "@" && email.charAt(i) == ".")) {
			errorCount++;
			break;
		}
	}

	if (!errorCount && email.indexOf("@") < 0 && email.length > 0) {
		alert("Your email address is missing the domain name. The format should be "+str+"@somedomain.\n\nFor example, "+str+"@aol.com, "+str+"@earthlink.net, or "+str+"@yahoo.com.");
		return false;
	}

	if (email.length < 6) errorCount++;
	
	pos = email.indexOf("@");
	email = email.substring(pos+1,email.length);
	
	if (email.indexOf("@") != -1) errorCount++;
	
	if ((email.charAt(0) == "[" && email.charAt(email.length-1) != "]") || (email.charAt(0) != "[" && email.charAt(email.length-1) == "]") || (email.charAt(0) == "]" || email.charAt(email.length-1) == "[")) errorCount++;
	
	if (email.indexOf(".") < 0) {
		errorCount++;
	}
	else {
		pos = email.lastIndexOf(".");
		email = email.substring(pos+1,email.length);

		if ((!isNaN(email) && email != "") || (email.charAt(email.length-1) == "]")) {

			pos = str.indexOf("@");
			
			if (email.charAt(email.length-1) == "]") {
			
				email = str.substring(pos+1,str.length-1);

				if (email.charAt(0) == "[") {
					email = email.substring(1,str.length);
				}				
			}
			else {
				email = str.substring(pos+1,str.length);
			}
			
			var ipAddress = "";
			var periods = 0;

			for (i = 0; i < email.length; i++) {
				if (email.charAt(i) == ".") {
					periods++;

					if ((isNaN(ipAddress)) || (ipAddress < 0 || ipAddress > 255)) {
						errorCount++
						break;
					}
					ipAddress = "";
				}
				else
					ipAddress += email.charAt(i).toString();
			}
			if ((isNaN(ipAddress)) || (ipAddress < 0 || ipAddress > 255)) errorCount++

			if (periods != 3) errorCount++;
		}
		else {
			if (email.length < 2 || email.length > 3) errorCount++;
		}
	}

	if (errorCount > 0) {
		alert(str+" is not a valid email address. Please check your typing.");
		return false; }
	return true;
}

function containsCharacter(str,testchar)
	{ for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == testchar) return true;	}
	return false;
}

function validCharacters(teststr,validstr)
	{ for (i = 0; i < teststr.length; i++) {
		if (validstr.indexOf(teststr.charAt(i)) < 0) return false;	}
	return true;
}
