function initializePage()
{
	var ua = navigator.userAgent.toLowerCase();
	
	if (ua.indexOf('msie') != -1 && parseInt(navigator.appVersion) >= 4) //IE4+
		document.all.mnuMarker.className = "markerIE";
	else //NS
	{		document.getElementById('mnuMarker').className = "markerOther";
	}}


//CCH - 6/4/04
//We will look at combining these very soon, into 1 function
function newWindow(definitions) 
{
	var intLeft   = (screen.width - 500) / 2;
	var intTop    = (screen.height - 275) / 2;

	defnWindow = window.open(definitions, 'Attrdefn', 'left='+intLeft+',top='+intTop+',height=275,width=500,scrollbars=yes')
	defnWindow.focus()
}

function newWindow1(definitions) 
{
	
	var intLeft = (screen.width - 550) / 2;
	var intTop  = (screen.height - 450) / 2;
	
	defnWindow1 = window.open(definitions, 'Attrdefn', 'left='+intLeft+',top='+intTop+',height=450,width=550,scrollbars=yes')
	defnWindow1.focus()
}

function addFavorite(intActivityID, strActivityName)
{
	var objXMLHTTP = createXMLHTTP()
	objXMLHTTP.open("POST","/addfavorite.asp",false)
	objXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	var strData = "ActivityID=" + intActivityID
	objXMLHTTP.send(strData)
	
	if (objXMLHTTP.responseXML.xml=="")
	{
		alert('We\'re sorry, the activity \'' + strActivityName + '\' was not added to your favorites.  Please try again.');
	}
	else
	{
		alert('The activity \'' + strActivityName + '\' was successfully added to your favorites.\n\nTo view your favorites, click on the \'My Favorite Activities\' button on the left side of your screen.');
	}
	
}


function createXMLHTTP() 
{
		
	// Code to work with IE versions 5.0 and greater
	var xhhtp

	try
	{
		 xhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); 
		 //xhttp = new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch (e)
	{
		try
		{
			xhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		}
		catch (e)
		{	
			xhttp=false
			
			try
			{
				xhttp = new ActiveXObject("Msxml2.XMLHTTP.2.6");
			}
			catch (e)
			{	
				xhttp=false
			
				try
				{
					xhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e)
				{	
					xhttp=false
					
				}	
			}
		}
	}
	
	
			
	if (!xhttp) 
	{
		try
		{
			xhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xhttp = false
			alert("Error creating XMLHTTP, please contact the NDI IT Staff.")
			return
		}
	}
		
	return(xhttp)


}

//////////////////////////////////////////////
// CCH
// 06/29/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function validateAddEditUserForm(objForm)
{
	
	//Check First Name
	if (Trim(objForm.FirstName.value) == "")
	{
		alert("A valid First Name is required.");
		objForm.FirstName.focus();
		return false;
	}
	//Check Last Name
	if (Trim(objForm.LastName.value) == "")
	{
		alert("A valid Last Name is required.");
		objForm.LastName.focus();
		return false;
	}
	//Check UserName (aka Email) for valid email address format (a@b.c)
	if (!isEmail(Trim(objForm.Username.value)))
	{
		alert("A valid Email Address is required.");
		objForm.Username.focus();
		return false;
	}	
	//Check Password
	if (Trim(objForm.Password.value) == "")
	{
		alert("A valid Password is required.");
		objForm.Password.focus();
		return false;
	}
	//Check that Password is at least 6 characters
	if (Trim(objForm.Password.value).length < 6)
	{
		alert("For security purposes, the Password must be at least 6 characters in length.");
		objForm.Password.focus();
		objForm.Password.select();
		return false;
	}
	//Check that Password = Confirm Password
	if (Trim(objForm.Password.value) != Trim(objForm.ConfirmPassword.value))
	{
		alert("The passwords do not appear to match, please re-confirm your password.");
		objForm.ConfirmPassword.focus();
		objForm.ConfirmPassword.select();
		return false;
	}

	//Check Grade
	//var intIndex = objForm.Grade.selectedIndex;
	//if (Trim(objForm.Grade.options[intIndex].value) == "")
	//{
	//	alert("A valid Grade Preference is required.");
	//	objForm.Grade.focus();
	//	return false;
	//}

	//Check to see if School None and School Admin Checked
	if (objForm.SchoolAdmin && objForm.School){
		if (objForm.SchoolAdmin.checked && objForm.School.options[objForm.School.selectedIndex].value == "None")
		{
		    alert("You can not have a School Administrator and a None School.");
		    objForm.School.focus()
		    return false;
		}
	}
	//Verify StationPE Administrator
	if (objForm.Admin){
		if (objForm.Admin.checked)
		{
			if (!confirm("You have chosen to make this user a website administrator for myStationPE.com.\n\nClick 'OK' to proceed, or 'Cancel' to go back."))
			{
				objForm.Admin.focus()
				return false;
			}
		}
	}
	//Verify Inactive
	//if (objForm.Active){
	//	if (!objForm.Active.checked)
	//	{
	//		if (!confirm("You have chosen to Inactivate this user which will prevent them from using myStationPE.com.\n\nClick 'OK' to proceed, or 'Cancel' to go back."))
	//		{
	//			objForm.Active.focus()
	//			return false;
	//		}
	//	}
	//}
	
	return true;
}

function validateUsernamePassword(objForm)
{

	//Check UserName has value
	if (!Trim(objForm.Username.value).length > 5)
	{
		alert("A valid Email Address is required.");
		objForm.Username.focus();
		return false;
	}
	//Check UserName (aka Email) for valid email address format (a@b.c)
	if (!isEmail(Trim(objForm.Username.value)))
	{
		alert("A valid Email Address is required.");
		objForm.Username.focus();
		return false;
	}
	//Check that Password is at least 6 characters
	if (Trim(objForm.Password.value).length < 6 && Trim(objForm.Password.value).length > 0)
	{
		alert("For security purposes, the Password must be at least 6 characters in length.");
		objForm.Password.focus();
		objForm.Password.select();
		return false;
	}
	//Check that Password = Confirm Password
	if (Trim(objForm.Password.value) != Trim(objForm.ConfirmPassword.value))
	{
		alert("The passwords entered do not match, please re-confirm your password.");
		objForm.ConfirmPassword.focus();
		objForm.ConfirmPassword.select();
		return false;
	}
	
	return true;
}

function validatePassword(objForm)
{

	//Check that Password is at least 6 characters
	if (Trim(objForm.Password.value).length < 6 && Trim(objForm.Password.value).length > 0)
	{
		alert("For security purposes, the Password must be at least 6 characters in length.");
		objForm.Password.focus();
		objForm.Password.select();
		return false;
	}
	//Check that Password = Confirm Password
	if (Trim(objForm.Password.value) != Trim(objForm.ConfirmPassword.value))
	{
		alert("The passwords entered do not match, please re-confirm your password.");
		objForm.ConfirmPassword.focus();
		objForm.ConfirmPassword.select();
		return false;
	}
	
	return true;
}

//////////////////////////////////////////////
// CCH
// © 2004 NetOvation, LLC
//////////////////////////////////////////////

function Trim(rsString) 
{
	var lobjLeftSpacesRE = /^\s+/;
	var lobjRightSpacesRE = /\s+$/;

	rsString = rsString.replace(lobjLeftSpacesRE, '');
	rsString = rsString.replace(lobjRightSpacesRE, '');

	return rsString;
}


//////////////////////////////////////////////
// CCH
// 06/29/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function isEmail (strEmail)
{   
	if (strEmail == "") 
		return false;  
    
    // There must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = strEmail.length;

    // look for @
    while ((i < sLength) && (strEmail.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (strEmail.charAt(i) != "@")) 
		return false;
    else 
		i += 2;

    // look for .
    while ((i < sLength) && (strEmail.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (strEmail.charAt(i) != ".")) 
		return false;
    else 
		return true;
}

//////////////////////////////////////////////
// CCH
// 06/29/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteUser(intUserID, strUserInfo)
{	
	if (confirm("Are you sure you wish to delete user " + strUserInfo + "?\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = 'deleteuser.asp?UserID=' + intUserID + '&UserInfo=' + strUserInfo;
}

function confirmDeleteUser2(intUserID)
{	
	if (confirm("Are you sure you wish to delete the selected user?\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = 'deleteuser.asp?UserID=' + intUserID;
}


//////////////////////////////////////////////
// CCH
// 09/20/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteActivity(intActivityID, strActivityName)
{	
	if (confirm("Are you sure you wish to delete activity " + strActivityName + "?\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = 'deleteactivity.asp?ActivityID=' + intActivityID + '&ActivityName=' + strActivityName;
}

//////////////////////////////////////////////
// CCH
// 07/07/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit) //if the string has reached the maxlength, then lets trim it
		field.value = field.value.substring(0, maxlimit);
}

//////////////////////////////////////////////
// CCH
// 08/04/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function popImage(imageURL,imageTitle)
{
	
	// Set the horizontal and vertical position for the popup
	
	PositionX = 0;
	PositionY = 0;

	// Set these value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)

	var defaultWidth  = 600;
	var defaultHeight = 600;

	// Set autoclose true to have the window close automatically
	// Set autoclose false to allow multiple popup windows

	var AutoClose = false;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=100,height=100,left='+PositionX+',top='+PositionY;

	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=document.images[1].width+10;');
		writeln('height=document.images[1].height+53;');
		writeln('PositionX = (screen.width - width) / 2;');
		writeln('PositionY = (screen.height - height) / 2;');
		writeln('window.moveTo(PositionX, PositionY);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["temp"].width;');writeln('window.innerHeight=document.images["temp"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=#000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=#000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<button class="ICONBUTTON" style="cursor:hand" onClick="window.print()"><img alt="Print this diagram" align="absmiddle" src="/images/printer2.gif" border="0" width="16" height="16"></button>');
		writeln('<img name="temp" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

function calc_date(date_form, date_field_name)
{

 var date_field = date_form(date_field_name);

 var month_field = date_form(date_field_name + '_month');
 var day_field = date_form(date_field_name + '_day');
 var year_field = date_form(date_field_name + '_year');

 date_field.value = (month_field.options[month_field.selectedIndex].value + '/' + day_field.options[day_field.selectedIndex].value + '/' + year_field.options[year_field.selectedIndex].value);

 if (date_field.value == '//') date_field.value = '';

}

function calc_datetime(date_form, date_field_name)
{

 var date_field = date_form(date_field_name);

 var month_field = date_form(date_field_name + '_month');
 var day_field = date_form(date_field_name + '_day');
 var year_field = date_form(date_field_name + '_year');

 var hour_field = date_form(date_field_name + '_hour');
 var minute_field = date_form(date_field_name + '_minute');
 var ampm_field = date_form(date_field_name + '_ampm');

 date_field.value = (month_field.options[month_field.selectedIndex].value + '/' + day_field.options[day_field.selectedIndex].value + '/' + year_field.options[year_field.selectedIndex].value + ' ' + hour_field.options[hour_field.selectedIndex].value + ':' + minute_field.options[minute_field.selectedIndex].value + ' ' + ampm_field.options[ampm_field.selectedIndex].value);

 if (date_field.value == '// : ') date_field.value = '';

}