// 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);
}

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+',location=0');
return win;
}

var resetTimer;
var stepTimer;
var menuArray = new Array();

function MenuItem(name,maxi) {
	this.Name = name;
	this.Direction = 0;
	this.Maxi = maxi;
	this.Current = 0;
}

function showSubMenu(which) {
  clearReset();
  for(i=0; i<menuArray.length; i++) {
	  thisItem = menuArray[i];
	  if((which-1) == i) {
		  if(thisItem.Current != thisItem.Maxi) thisItem.Direction = 1;
	  } else {
		  if(thisItem.Current != 0) thisItem.Direction = -1;
	  }
  }      
  if(stepTimer) clearTimeout(stepTimer);
  stepIt();
}

function stepIt() {
  change = false;
  for(i=0; i<menuArray.length; i++) {
    thisItem = menuArray[i];
  	if(thisItem.Direction != 0) {
	  if(thisItem.Direction == 1) {
	    thisItem.Current = thisItem.Current + 1;
		show('lay_'+(i+1)+'_'+thisItem.Current);
	    if(thisItem.Current == thisItem.Maxi) thisItem.Direction = 0;
	  } else {
		hide('lay_'+(i+1)+'_'+thisItem.Current);
	    thisItem.Current = thisItem.Current - 1;
	    if(thisItem.Current == 0) thisItem.Direction = 0;
	  }
	  change = true;
	}
  }
  if(change) stepTimer = setTimeout('stepIt()',50);
}

function setReset(which) {
  resetTimer = setTimeout('reset('+which+')',800);
}

function clearReset() {
  if(resetTimer) clearTimeout(resetTimer);
}

function reset(which) {
  thisItem = menuArray[which-1];
  if(thisItem.Current != 0) thisItem.Direction = -1;
  if(stepTimer) clearTimeout(stepTimer);
  stepIt();
}

function confirmDel(message, URL) {
	conWin = window.open('','confirmWindow','resizable,left=200,top=200,height=120,width=300')
	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 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;
}

function isEmailValid(str) {
	var pos;
	var errorCount = 0;
	var email = str;
	
	var validStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.[]-_";

	if (email == "") {
		alert("Please enter an 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;
}

