/* START: Log in form code*/
function testLogin()
		{
		var err = 0;
		var errMSG = "";
		if(document.loginForm.email.value == "")
			{
			errMSG = errMSG + "Please enter your email address.\n";
			err = 1;
			}
		if(document.loginForm.password.value == "")
			{
			errMSG = errMSG + "Please enter your password.";
			err = 1;
			}
		if(err == 1)
			{
			alert(errMSG);
			return false;
			}
		else
			{
			return true;
			}
		}
/* END: Log in form code*/

/* START: AJAX Code */
var browser			=	navigator.appName;
var b_version		=	navigator.appVersion;
var version			=	parseFloat(b_version);
var CalendarURL 	= 	"/CalendarAjax.cfm"; // The server-side script
var DirectoryURL 	= 	"/DirectoryAjax.cfm"; // The server-side script
var alphaNumArr 	= 	new Array("0","A","1","B","2","C","3","D","4","E","5","F","6","G","7","H","8","I","9","J");
/*Main branch functions for the calendar*/
	function loadDetailsWindow(cdid)
		{
		/*Setup the vars*/
			var myObject = document.getElementById('myData');
		/*Hide the div in case it is already open*/
			myObject.style.visibility = "hidden";
		
		/*Retrieve the data for the popup*/
		foo = retrieveCalendarData(cdid);
		/*make the popup visible and move it to where it belongs*/
			if( (browser == "Netscape") || (browser == "Microsoft Internet Explorer" && version > 4) )
				{
				myObject.style.left = (window.outerWidth / 2) - 110;
				myObject.style.top = (window.outerHeight / 2) - 80;
				}
			else
				{	
				myObject.style.left = (screen.width / 2) - 110;
				myObject.style.top = (screen.height / 2) - 80;
				//myObject.style.left = window.event.x;
				//myObject.style.top = window.event.y;
				}
			myObject.style.visibility = "visible";
		}
	function closeMyDataWindow()
		{
		var myObject = document.getElementById('myData');
		myObject.style.visibility = "hidden";
		myObject.style.left = 1;
		myObject.style.top = 1;
		}
	function retrieveCalendarData(cdid)
		{
		//create a random string
		var myNewRandomString = pickNums(4);
		//setup the http call
		httpa.open("GET", CalendarURL + "?fuseaction=showevent&cdid=" + cdid + "&Rand=" + myNewRandomString, true);
		httpa.onreadystatechange = handleCalendarHttpResponse;
		httpa.send(null);
		}
	function handleCalendarHttpResponse()
		{
		if (httpa.readyState == 4)
			{
			var xmlDocument = httpa.responseXML;
			var myOutputString = "";
			myOutputString = xmlDocument.getElementsByTagName('myHTML').item(0).firstChild.data;
			//Pass the data back out to the display div
			document.getElementById("DataArea").innerHTML  = myOutputString;
			}		
		};		
/*Main branch functions for the user directory*/
	function retrieveDirData()
		{
		//create a random string
		var myNewRandomString 	= 	pickNums(4);
		var myFirstName			=	document.dirForm.FirstName.value;
		var myLastName			=	document.dirForm.LastName.value;
		//setup the http call
		httpb.open("GET", DirectoryURL + "?process=query&LastName=" + myLastName + "&FirstName=" + myFirstName + "&Rand=" + myNewRandomString, true);
		httpb.onreadystatechange = handleDIRHttpResponse;
		httpb.send(null);
		}
	function handleDIRHttpResponse()
		{
		if (httpb.readyState == 4)
			{
			var xmlDocument = httpb.responseXML;
			var myOutputString = "";
			myOutputString = xmlDocument.getElementsByTagName('myHTML').item(0).firstChild.data;
			//Pass the data back out to the display div
			document.getElementById("DirArea").innerHTML  = myOutputString;
			}		
		};	

/*Utils*/
	function pickNums(nums)
		{
		var myString = "";
		for(var iee = 0; iee < nums; iee++)
			{
				myString = myString + Math.round((alphaNumArr.length-1)*Math.random());
			}
		return myString;
		}
	function findPosX(obj)
		{
		var curleft = 0;
		if(obj.offsetParent)
			while(1) 
			{
			  curleft += obj.offsetLeft;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.x)
			curleft += obj.x;
		return curleft;
		}
	
	function findPosY(obj)
		{
		var curtop = 0;
		if(obj.offsetParent)
			while(1)
			{
			  curtop += obj.offsetTop;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.y)
			curtop += obj.y;
		return curtop;
		}
/*Core AJAX Functional Stuff*/
	function getHTTPObject() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	  }
	  return xmlhttp;
	}
var httpa = getHTTPObject(); // We create the HTTP Object
var httpb = getHTTPObject(); // We create the HTTP Object
/* END: AJAX Code*/
/* START: Welcome Message Code */
function SetCFCookie (name, value)
	{
	var name = name.toUpperCase();
	var path = "/";
	document.cookie = name + "=" + escape (value) +"; path=" + path + ";";
	};
function GetCFCookie(name)
	{ 
	var cname = name.toUpperCase() + "="; //the cookie name is given an equal signs after it and assigned as cname
	var dc = document.cookie; //the main document.cookie code that will follow is assigned to dc
	var bl = "";
	if (dc.length > 0)
		{ //here the length of the cookie is checked, if it is above 0 the function continues and if not then it returns null
		begin = dc.indexOf(cname); //here the indexOf() method is used to find the location of the cookie's name and it is assigned to begin
		if (begin != -1)
			{ //if the cookie's name is not found in dc then begin is given a value of -1
			begin += cname.length; //if the name is found begin is increased by the length of the cname
			end = dc.indexOf(";", begin); //the indexOf() method now searches for a semicolon to be given to the variable end
			if (end == -1) end = dc.length; 
			return unescape(dc.substring(begin, end)); //here is where is made sure that the value of the cookie is extracted and returned using the substring() method on dc
			} 
		}
	return bl; 
	}


// Find and replace characters within a string
function Switch(item,OldChar,NewChar)
	{
	var _ONE=0;
	var _ret="";
	var _flag=0;
	var _item=item.split("");
	for(var i=0;i<_item.length;i++)
		{
		if(!_flag&&_item[i]==OldChar)
			{
			_item[i]=NewChar;
			_flag=_ONE;
			}
		_ret+=_item[i];
		}
	return(_ret);
	}

	

// Show the welcome in the header	
function showWelc()
	{
	var cookieName = 'IS_NAME'; //the cookie's name is finally assigned to cookieName
	datetoday = new Date();
	timenow=datetoday.getTime();
	datetoday.setTime(timenow);
	thehour = datetoday.getHours();
	if (thehour > 16)
	{
	var time="Good Evening<br>";
	}
	else if (thehour > 11)
	{
	var time="Good Afternoon<br>";
	}
	else
	{
	var time="Good Morning<br>";
	}
	document.write(time);
	document.write(Switch(GetCFCookie(cookieName),"+"," "));
	}
/* END: Welcome Message Code */