// **********************
// Stuff for exclusive rotation
// **********************
var tt2;

function rotationFade(direction,filecount) {
	var offer = document.getElementById("imageoffer");
	var current = parseInt(offer.getAttribute('rel'));
	if (current == 1 && direction == "left") {
		return;
	} else if ( current == filecount && direction == "right") {
		offer.setAttribute("rel", 1);
		document.getElementById("num").innerHTML = 1;
		var newsrc = "offers/1.jpg";
		fadeOutOffer(90,newsrc);
	} else {
		if (direction == "left") {
			offer.setAttribute("rel", current - 1);
			current--;
			document.getElementById("num").innerHTML = current;
			var newsrc = "offers/"+current+".jpg";
			fadeOutOffer(90,newsrc);
		} else if ( direction == "right") {
			offer.setAttribute("rel", current + 1);
			current++;
			document.getElementById("num").innerHTML = current;
			var newsrc = "offers/"+current+".jpg";
			fadeOutOffer(90,newsrc);
		}		
	}
}

function rotate(direction,filecount) {
	rotationFade(direction,filecount);
	rotation(filecount);
}

function rotation(num) {
	tt2 = setTimeout("rotate('right','" +num+ "')",7000);
}

// *************************************************************************
// Ajax call to check offerings text file for a provided URL for corresponding offering(num)
// *************************************************************************
function getLink(num) {
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

function stateChanged()
{
if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
	var asdf = ajaxRequest.responseText;
	if (asdf == "") {
	} else {
			if (asdf.substr(0,1) == "1") {
				asdf = asdf.substr(1);
				var trueLink = asdf.substr(0,asdf.search(" "));
				document.getElementById('linkcheck').setAttribute("href",trueLink);
				greySizes = asdf.substr(asdf.search(" ")+1);
				greyWidth = greySizes.substr(0, greySizes.search(" "));
				greyHeight = greySizes.substr(greySizes.search(" ")+1);
				document.getElementById('linkcheck').onclick = function() {  return GB_showCenter('Chateau Elan Exclusives', this.href, parseInt(greyWidth), parseInt(greyHeight));}
			} else {
				document.getElementById('linkcheck').setAttribute("href",asdf);
			}
	}
}
}

var str = "str=" + num;
var url = "inc/checklink.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// *****************************************************************
// Function to preload home page offerings for improved animation performance
// *****************************************************************
function preloadImages(num) {
	var count = parseInt(num) + 1;
	var i = 2;
	while (i < count) {
		preload_image = new Image(370,441);
		preload_image.src = "offers/"+i+".jpg";
		i++;
	}
	getLink(1);
}

// ********************************
// Animation function for fading offers in
// ********************************
function fadeInOffer(g) {
	var offer = document.getElementById("offer");
	document.getElementById('linkcheck').removeAttribute('href');
	var q = parseInt(g);
		if (q < 100)
			{
				offer.style.filter = 'alpha(opacity = '+ q +')';
				offer.style.opacity = q/100;
				q = q + 10;
				t = setTimeout("fadeInOffer('" +q+ "')",20);
			}
			else
			{
				offer.style.filter = 'alpha(opacity = 100)';
				offer.style.opacity = 1;
				clearTimeout(t);
				var hoopty = document.getElementById('imageoffer').getAttribute('rel');
				getLink(hoopty);
			}
}

// *********************************
// Animation function for fading offers out
// *********************************
function fadeOutOffer(g, source) {
		var offer = document.getElementById("offer");
		var q = parseInt(g);
		if (q > 0)
			{
				offer.style.filter = 'alpha(opacity = '+ q +')';
				offer.style.opacity = q/100;
				q = q - 10;
				t = setTimeout("fadeOutOffer('" +q+ "','"+source+"')",20);
			}
			else
			{
				offer.style.filter = 'alpha(opacity = 0)';
				offer.style.opacity = 0;
				document.getElementById("imageoffer").setAttribute("src", source);
				document.getElementById("linkcheck").onclick = "";
				clearTimeout(t);
				fadeInOffer(10);
			}
}

// ***************************
// Code for home page offerings...
// ***************************
function offerFade(direction,filecount) {
	clearTimeout(tt2);
	var offer = document.getElementById("imageoffer");
	var current = parseInt(offer.getAttribute('rel'));
	if (current == 1 && direction == "left") {
		return;
	} else if ( current == filecount && direction == "right") {
		offer.setAttribute("rel", 1);
		document.getElementById("num").innerHTML = 1;
		var newsrc = "offers/1.jpg";
		fadeOutOffer(90,newsrc);
	} else {
		if (direction == "left") {
			offer.setAttribute("rel", current - 1);
			current--;
			document.getElementById("num").innerHTML = current;
			var newsrc = "offers/"+current+".jpg";
			fadeOutOffer(90,newsrc);
		} else if ( direction == "right") {
			offer.setAttribute("rel", current + 1);
			current++;
			document.getElementById("num").innerHTML = current;
			var newsrc = "offers/"+current+".jpg";
			fadeOutOffer(90,newsrc);
		}		
	}
}

// **************************************************************************************************
// Fun little function that augments the value of the submit button to pluralise if more than one checkbox is checked...
// **************************************************************************************************
function toggle(f) {
var i;
var count = 0;
	for (i = 0;i<document.delevent.elements.length;i++) {
		if (document.delevent.elements[i].type == "checkbox" && document.delevent.elements[i].checked) {
			count++;
		}
	}
	if (count > 1) {
		document.delevent.delsubmitbutton.value = "Delete Events";
	} else {
		document.delevent.delsubmitbutton.value = "Delete Event";
	}
}

// ***********************************************************
// Function for calendar that allows the user to jump to any given month
// ***********************************************************
function jumpMonth(year) {
	var month = document.getElementById("monthselect").value;
	if (month == "") {
		return;
	} else {
		getCalendar(month,year);
	}
}

// *************************************************************************
// Quick Events function for calendar which queries chosen category events for one year
// *************************************************************************
function quickEvents(cat) {
	if (cat) {
		var category = cat;
	} else {
		var category = document.getElementById("eventselect").value;
	}
	
	if (category == "") {
		return;
	} else {
			var ajaxRequest;
			try {
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
				alert("Your browser broke!");
				return false;
					}
				}
			}

		function stateChanged()
		{
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
			{
		var yep = "quickEventResult";
		document.getElementById(yep).innerHTML=ajaxRequest.responseText;
		centerFadeDiv('quickEventDiv',350,350,1);
		 	}
		}

		var str = "str=quickevent|"+category;
		var url = "http://www.chateauelan.com/calendar/event.php";
		ajaxRequest.onreadystatechange=stateChanged;
		ajaxRequest.open("POST", url, true);
		ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", str.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		ajaxRequest.send(str);
		}
}

// ***************************************************************************
// This function is passed with AJAX to the cal.php function with month|year as parameters
// ***************************************************************************
function getCalendar(month, year) {
	// document.getElementById("calLoader").style.visibility = "visible";
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

function stateChanged()
{
	if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
		var yep = "cal";
		// document.getElementById("calLoader").style.visibility = "hidden";
		document.getElementById(yep).innerHTML=ajaxRequest.responseText;
		var navInfo = navigator.userAgent;
		var weatherClass = document.getElementsByTagName("span");
		if (navInfo.indexOf("MSIE 8.0") >= 0) {
			for (var i=0;i < weatherClass.length;i++) {
				var temp = weatherClass[i].getAttribute('class');
				if (temp && temp.indexOf("weather") >= 0) {
					weatherClass[i].style.marginTop = "0px";
					weatherClass[i].style.marginLeft = "-80px";
				}
			}
		document.getElementById("calButton").style.marginTop = "0px";
		document.getElementById("topCal").style.marginBottom = "1px";
		}
		if (navInfo.indexOf("Mozilla") >= 0) {
			for (var i=0;i < weatherClass.length;i++) {
				var temp = weatherClass[i].getAttribute('class');
				if (temp && temp.indexOf("weather") >= 0) {
					weatherClass[i].style.marginTop = "0px";
					weatherClass[i].style.marginLeft = "-80px";
				}
			}
			document.getElementById("calButton").style.marginTop = "0px";
			document.getElementById("topCal").style.marginBottom = "1px";
		}
 	}
}

var str = "str=" + month + "|" + year;
var url = "cal.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// **********************************************************************************
// Main function that closes the cal overlay and whichever div/result argument passed
// **********************************************************************************
function closeFadeDiv(div, result) {
	document.getElementById(div).style.display = "none";
	document.getElementById("overlay").style.display = "none";
	if (result) {
		if (result == "quickEventDivClose") {
			document.getElementById(result).style.display = "none";
			if (document.getElementById("eventselect")) {
			document.getElementById("eventselect").selectedIndex = "default";
			}
		} else {
		document.getElementById(result).innerHTML = "";
		}
	}
	// document.delevent.delsubmitbutton.value = "Delete Event";
}

// **************************************************************************************
// Sub function that is used when an action has been taken with an event. Main difference
// from closeFadeDiv() is that it reloads the calendar to show changes made.
// **************************************************************************************
function closeEventDiv(div,result) {
	document.getElementById(div).style.display = "none";
	document.getElementById("overlay").style.display = "none";
	document.getElementById(result).innerHTML = "";
	var currentDate = document.getElementById("selectCalFont").innerHTML;
	var dateArray = currentDate.split(" ");
	var thismonth;
	var thisyear = dateArray[1];
	switch(dateArray[0]) {
		case 'January':thismonth = 1;break;
		case 'February':thismonth = 2;break;
		case 'March':thismonth = 3;break;
		case 'April':thismonth = 4;break;
		case 'May':thismonth = 5;break;
		case 'June':thismonth = 6;break;
		case 'July':thismonth = 7;break;
		case 'August':thismonth = 8;break;
		case 'September':thismonth = 9;break;
		case 'October':thismonth = 10;break;
		case 'November':thismonth =11;break;
		case 'December':thismonth = 12;break;
	}
	getCalendar(thismonth, thisyear);
}

// *******************************************
// Exits calendar edit mode and kills PHP admin session
// *******************************************
function calAdminExit() {
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

function stateChanged()
{
if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
	document.getElementById("adminButtonSpan").style.display = "inline";
	var thismonth = document.admin.currentmonth.value;
	var thisyear = document.admin.currentyear.value;
	getCalendar(thismonth, thisyear);
 	}
}

var str = "str=logout";
var url = "check.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// *************************************************************************************
// This function closes cal overlay and the admin login div and controls the hidden link
// *************************************************************************************
function closeAdminSpecial() {
	document.getElementById("adminCheck").style.display = "none";
	document.getElementById("overlay").style.display = "none";
	document.getElementById("resultdiv").innerHTML = "";
	document.getElementById("adminButtonSpan").style.display = "none";
	var thismonth = document.admin.currentmonth.value;
	var thisyear = document.admin.currentyear.value;
	getCalendar(thismonth, thisyear);
}

// *********************************************************************************
// This function is used to build a list of events so user can choose which to edit.
// *********************************************************************************
function editEvent(day,month,year) {
	centerFadeDiv('editEvent',200,275);
	
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged() {
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete") {
			var yep = "editformcontent";
			document.getElementById(yep).innerHTML = ajaxRequest.responseText;
 		}
	}
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthString = months[month-1];
document.getElementById("editEventDate").innerHTML = monthString + " " + day + ", " + year;

var str = "str=editquery|" + day + "|" + month + "|" + year;
var url = "event.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// ***************************************************************************
// This function pulls the db info for the event that was chosen to be edited.
// ***************************************************************************
function editEventChosen() {
	if (document.editform.id) {
		var title = document.editform.title.value;
		var description = document.editform.description.value;
		var eventlink = document.editform.eventlink.value;
		var imagelink = document.editform.imagelink.value;
		var category = editform.category.options[editform.category.selectedIndex].name;
		var id = document.editform.id.value;

	var ajaxRequest2;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest2 = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged2() {
		if (ajaxRequest2.readyState == 4 || ajaxRequest2.readyState=="complete") {
			var yep2 = "editeventresult";
			if (ajaxRequest2.responseText == "success...") {
				document.getElementById(yep2).style.color = "green";
				document.editform.title.value = "";
				document.editform.description.value = "";
				document.editform.eventlink.value = "";
				document.getElementById(yep2).innerHTML=ajaxRequest2.responseText;
				setTimeout("closeEventDiv('editEvent','editeventresult')", 2000);
				} else {
				document.getElementById(yep2).innerHTML = ajaxRequest2.responseText;
				document.editform.title.focus();
				}
			}
		}
		
var str2 = "str=edit|" + id + "|" + escape(title) + "|" + escape(description) + "|" + eventlink + "|" + imagelink + "|" + category;
var url2 = "event.php";
ajaxRequest2.onreadystatechange=stateChanged2;
ajaxRequest2.open("POST", url2, true);
ajaxRequest2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest2.setRequestHeader("Content-length", str2.length);
ajaxRequest2.setRequestHeader("Connection", "close");
ajaxRequest2.send(str2);
	} else {
	var i;
	var k = 0;
	var event;
	if (document.editform.edit.length == undefined && document.editform.edit.checked == false) {
		alert("Please choose an event to edit.");
		return;
	} else if (document.editform.edit.length == undefined && document.editform.edit.checked == true) {
		event = document.editform.edit.value;
	} else if (document.editform.edit.length > 0) {
		for (i=0;i<document.editform.edit.length;i++) {
			if (document.editform.edit[i].checked) {
				event = document.editform.edit[i].value;
			} else { k++; }
		}
		if (k == i) {
			alert("Please choose an event to edit."); return;
		}
	}
	
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged() {
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete") {
			var yep = "editformcontent";
			document.getElementById(yep).innerHTML = ajaxRequest.responseText;
 		}
	}

var str = "str=editget|" + event;
var url = "event.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
} // End of main if statement...
}

// **************************************************************************************
// This function does not actually delete event(s). It actually just opens a div and then
// sends an AJAX request to the db to build a list of events to delete.
// **************************************************************************************
function delEvent(day,month,year) {
	centerFadeDiv('deleteEvent',200,200);
	
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged() {
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete") {
			var yep = "deleteform";
			document.getElementById(yep).innerHTML = ajaxRequest.responseText;
 		}
	}

var str = "str=delquery|" + day + "|" + month + "|" + year;
var url = "event.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// ******************************************************************************************
// This function actually handles deletion of selected events that was built from delEvent().
// Collects events to delete and passes AJAX request to server for deletion. 
// ******************************************************************************************
function deleteEvent() {
	var i;
	var buildstring = "placeholder";
	for (i=0;i<document.delevent.elements.length;i++) {
		if (document.delevent.elements[i].checked) {
			buildstring = buildstring + "|" + document.delevent.elements[i].name;
		}
	}

	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged() {
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete") {
			var yep = "deleteeventresult";
			if (ajaxRequest.responseText == "success...") {
				document.getElementById(yep).style.color = "green";
				document.delevent.reset();
				document.getElementById(yep).innerHTML=ajaxRequest.responseText;
				setTimeout("closeEventDiv('deleteEvent','deleteeventresult')", 2000);
			} else {
				document.getElementById(yep).innerHTML = ajaxRequest.responseText;
				document.delevent.reset();
			}

 		}
	}

var str = "str=del|" + buildstring;
var url = "event.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// ************************************************
// Opens overlay/centered div and the newEvent form
// ************************************************
function addEvent(day,month,year) {
	centerFadeDiv('newEvent',200,325);
	var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	var monthString = months[month-1];
	document.addevent.eventdate.value = month + "|" + day + "|" + year;
	document.getElementById("newEventDate").innerHTML = monthString + " " + day + ", " + year;
	document.addevent.title.focus();
}

// ***************************************************************************
// Collects user data and sends AJAX request to server for adding a new event.
// ***************************************************************************
function addNewEvent() {
	var title = document.addevent.title.value;
	var description = document.addevent.description.value;
	var eventlink = document.addevent.eventlink.value;
	var imagelink = document.addevent.imagelink.value;
	var category = addevent.category.options[addevent.category.selectedIndex].name;
	var eventdate = document.addevent.eventdate.value;
	if (document.addevent.weekly.checked == true) {
		var weekly = "yes";
	} else {
		var weekly = "no";
	}
	
	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	function stateChanged() {
		if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete") {
			var yep = "addeventresult";
				if (ajaxRequest.responseText == "success...") {
				document.getElementById(yep).style.color = "green";
				document.addevent.reset();
				document.getElementById(yep).innerHTML=ajaxRequest.responseText;
				setTimeout("closeEventDiv('newEvent','addeventresult')", 2000);
			} else {
			document.getElementById(yep).innerHTML = ajaxRequest.responseText;
			document.addevent.title.focus();
			}
 		}
	}
var str = "str=add|" + escape(title) + "|" + escape(description) + "|" + eventlink + "|" + imagelink + "|" + eventdate + "|" + category + "|" + weekly;
var url = "event.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// **************************************************************
// Checks login info when attempting to login to calendar control
// **************************************************************
function checkInfo() {
var username = document.admin.username.value;
var password = document.admin.password.value;
document.admin.reset();

var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

function stateChanged()
{
if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
	var yep = "resultdiv";
		if (ajaxRequest.responseText == "success...") {
			document.getElementById(yep).style.color = "green";
			document.getElementById(yep).innerHTML=ajaxRequest.responseText;
			setTimeout("closeAdminSpecial()", 2000);
		} else {
			document.getElementById(yep).innerHTML = ajaxRequest.responseText;
			document.admin.username.focus();
		}
 	}
}

var str = "str=" + username + "|" + password;
var url = "check.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// ********************************************************************************
// This function is used to create the login div and find the center of the screen.
// Using temporarily until I incorporate this with centerFadeDiv().
// ********************************************************************************
function calendarLogin() {
	var bodyHeight;
	var centerBodyX;
	var centerBodyY;
	var scrolledY;
	var scrolledX;
	// Checks for different browser types and then gets various offsets and window heights.
		if (self.innerHeight) {
			bodyHeight = self.innerHeight;
			bodyHeight += 432;
			centerBodyY = window.innerHeight / 2 - 20;
			centerBodyX = window.innerWidth / 2 - 200;
			scrolledY = self.pageYOffset;
			scrolledX = self.pageXOffset;
		} else if (document.body) {
			bodyHeight = document.body.clientHeight;
			centerBodyY = document.body.clientHeight / 2 - 20;
			centerBodyX = document.body.clientWidth / 2;
			scrolledY = document.documentElement.scrollTop;
			scrolledX = document.documentElement.scrollLeft;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			bodyHeight = document.documentElement.clientHeight;
			centerBodyY = document.documentElement.clientHeight / 2 - 20;
			centerBodyX = document.documentElement.clientWidth / 2 - 200;
			scrolledY = document.documentElement.scrollTop;
			scrolledX = document.documentElement.scrollLeft;
		}
		
	// Creates new div element and sets attributes. 
	if (document.getElementById("overlay")) {
		document.getElementById("overlay").style.display = "block";
	} else {
	var newdiv = document.createElement("div");
	newdiv.setAttribute('id','overlay');
	newdiv.style.height = bodyHeight + "px";
	newdiv.style.opacity = .5;
	newdiv.style.filter = 'alpha(opacity=' + 50 + ')';
	document.body.appendChild(newdiv);
	}
	
	// Shows adminCheck div and positions it in the dead center of the viewport.
	var admindiv = document.getElementById("adminCheck");
	admindiv.style.top = (scrolledY + (centerBodyY - 40) / 2) + "px";
	admindiv.style.left = centerBodyX - 100 + "px";
	admindiv.style.display = "block";
	document.admin.username.focus();
}

// ***********************************************************************************************
// Main function that opens overlay div/passed div and finds the center of the screen to place it.
// ***********************************************************************************************
function centerFadeDiv(divname,divwidth,divheight,optional) {
	var bodyHeight;
	var centerBodyX;
	var centerBodyY;
	var scrolledY;
	var scrolledX;
	// Checks for different browser types and then gets various offsets and window heights.
		if (self.innerHeight) {
			bodyHeight = self.innerHeight;
			bodyHeight += 432;
			scrolledY = self.pageYOffset;
			scrolledX = self.pageXOffset;
			centerBodyY = window.innerHeight / 2 + scrolledY;
			centerBodyY = centerBodyY - (divheight / 2);
			centerBodyX = window.innerWidth / 2;
			centerBodyX = centerBodyX - (divwidth / 2);
		} else if (document.body) {
			bodyHeight = document.body.clientHeight;
			scrolledY = document.documentElement.scrollTop;
			scrolledX = document.documentElement.scrollLeft;
			centerBodyY = document.documentElement.offsetHeight / 2 + scrolledY;
			centerBodyY = centerBodyY - (divheight / 2);
			centerBodyX = screen.width / 2;
			centerBodyX = centerBodyX - (divwidth / 2);
		} else if (document.documentElement && document.documentElement.clientHeight) {
			bodyHeight = document.documentElement.clientHeight;
			centerBodyY = document.documentElement.clientHeight / 2 - divheight;
			centerBodyX = document.documentElement.clientWidth / 2 - divwidth;
			scrolledY = document.documentElement.scrollTop;
			scrolledX = document.documentElement.scrollLeft;
		}
		
	// Creates new div element 'overlay' and sets attributes - if exists, block displays.
	if (document.getElementById("overlay")) {
		document.getElementById("overlay").style.display = "block";
	} else {
	var newdiv = document.createElement("div");
	newdiv.setAttribute('id','overlay');
	newdiv.style.height = bodyHeight + "px";
	newdiv.style.opacity = .5;
	newdiv.style.filter = 'alpha(opacity=' + 50 + ')';
	document.body.appendChild(newdiv);
	}
	
	// Shows adminCheck div and positions it in the dead center of the viewport.
	var thisDIV = document.getElementById(divname);
	thisDIV.style.top = centerBodyY + "px";
	thisDIV.style.left = centerBodyX + "px";
	if (optional) {
		thisDIV.scrollTop = 0;
		quickclose = document.getElementById("quickEventDivClose");
		quickY = centerBodyY + 2;
		quickX = centerBodyX + (divwidth - 10);
		quickclose.style.top = quickY + "px";
		quickclose.style.left = quickX + "px";
		quickclose.style.display = "inline";
	}
	thisDIV.style.display = "block";
}

// ***********************************************************************************
// Hack function that is executed on a body onchange event to "reset" content on page.
// ***********************************************************************************
function setFocus() {
	document.getElementById("testingasdf").style.display = "none";
	document.getElementById("testingasdf").style.display = "block";
}

function fieldFocus() {
	document.email.emailto.focus();
	return;
}

function fieldFocus2() {
	document.getElementById("emailLoading").focus();
	return;
}

// **********************************************************************************
// Next few functions handle animated div control for opening/closing hidden content.
// Function List: rollDivOut, rollDivIn, rollDivInSpecial, rollDiv
// **********************************************************************************
var divOutt;
var divOutg = 4;
var divInt;

function rollDivOut(div, f) {
	if (divOutg < f) {
		document.getElementById(div).style.height = divOutg+"px";
		divOutg = divOutg + 18;
		divOutt = setTimeout("rollDivOut('" + div + "','" + f + "')",15);
	} else {
		clearTimeout(divOutt);
		document.getElementById(div).style.height = f + "px";
		divOutg = 4;
	}
}

function rollDivIn(div, f) {
	if (f > 0) {
		document.getElementById(div).style.height = f + "px";
		f = f - 18;
		divInt = setTimeout("rollDivIn('" + div + "','" + f + "')",15);	
	} else {
		clearTimeout(divInt);
		document.getElementById(div).style.display = "none";
		document.getElementById(div).style.height = "100%";
		return;
	}
}

function rollDivInSpecial(div, time, div2, time2) {
	if (time > 0) {
		document.getElementById(div).style.height = time + "px";
		time = time - 18;
		divInt = setTimeout("rollDivInSpecial('" + div + "','" + time + "','" + div2 + "','" + time2 + "')",15);	
	} else {
		clearTimeout(divInt);
		document.getElementById(div).style.display = "none";
		document.getElementById(div).style.height = "100%";
		rollDivOut(div2, time2);
		return;
	}
}

function rollDiv(e, div) {
	var y=0;
	e=e||window.event;
	if(e.pageX || e.pageY) {
    y=e.pageY;
  } else if(typeof(e.clientX)=='number') {
    var dE=document.documentElement;
    y=e.clientY+document.body.scrollTop+(dE?dE.scrollTop:0);
  }

	if (document.getElementById(div).style.display == "none") {
		var qq = document.getElementById(div);
		qq.style.display = "block";
		var blah = qq.offsetHeight;
		qq.style.height = 0 + "px";
		var foo = document.getElementById(div).offsetTop;
		var divs = document.getElementsByTagName("div");
			for (var u=0;divs.length>u;u++) {
				if (divs[u].style.display == "block") {
					var ty = divs[u].offsetTop;
					var ty2 = divs[u].offsetHeight;
					if (ty <= y + 18 && ty >= y - 15 && div != divs[u].id) {
						return rollDivInSpecial(divs[u].id, ty2, div, blah);
						}
				}
			}
		rollDivOut(div, blah);
	} else if (document.getElementById(div).style.display == "block") {
		var qq = document.getElementById(div);
		var blah = qq.offsetHeight;
		rollDivIn(div, blah);
	}
}

// *********************************************************************************************
// Function specifically written for controlling the div width when weather content is displayed
// *********************************************************************************************
var q;
var t;

function changeDivWidth (start, end, build) {
	var startWidth = parseInt(start);
	var endWidth = end;
	 if (startWidth > endWidth) {
		document.getElementById("divWeather").style.width = startWidth - 10;
		q = startWidth - 10;
		t = setTimeout("changeDivWidth(\'" +q+ "\', \'" +endWidth+ "\', \'" +build+ "\')", 1);
	} else if (startWidth < endWidth) {
		document.getElementById("divWeather").style.width = startWidth + 10;
		q = startWidth + 10;
		t = setTimeout("changeDivWidth(\'" +q+ "\', \'" +endWidth+ "\', \'" +build+ "\')", 1);
	} else if (startWidth == endWidth) {
		clearTimeout(t);
		document.getElementById("details").innerHTML = build;
	}
}

// ***********************************************************************
// My function for book marking a page. I wish Tom would use it. :P <3 Tom
// Not tested. I will if current bookmarking system does not fly.
// ***********************************************************************
function bookmarkThisPage() {

var title;
var url = location.href;
var metas = document.getElementsByTagName('meta');
var metaLen = metas.length;

for (var x = 0; x<metaLen; x++) {
	if (metas[x].name == "title") {
		title = metas[x].content;
	}
}
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, " ");
	} else if (window.external) {
		window.external.AddFavorite(url,title);
	}
}

// **********************************************************************************
// Function that sends an AJAX request to the server for processing an email request.
// **********************************************************************************
function sendToFriend() {
	document.getElementById("emailLoading").style.display = "inline";
	
	var emailto = document.email.emailto.value;
	var yourname = document.email.yourname.value;
	var emailfrom = document.email.emailfrom.value;
	var title;
	var url = location.href;
	var metas = document.getElementsByTagName('meta');
	var metaLen = metas.length;
	
	for (var x = 0; x<metaLen; x++) {
		if (metas[x].name == "title") {
			title = metas[x].content;
		}
	}

	var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

	function clearMsg() {
		document.getElementById("emailSuccess").style.display = "none";
		fieldFocus();
	}
	
function stateChanged()
{
if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
		var text=ajaxRequest.responseText;
		if (text == "success") {
			document.getElementById("emailLoading").style.display = "none";
			document.getElementById("emailSuccess").style.display = "inline";
			document.email.reset();
			setTimeout(clearMsg, 2000);
		} else if (text == "error") {
			document.getElementById("emailLoading").style.display = "none";
			document.getElementById("emailSuccess").style.display = "inline";
			document.getElementById("emailSuccess").innerHTML = "<font color='red'>Error!</font>";
		}
	}
}

var str = "str=" + emailto + "|" + yourname + "|" + emailfrom + "|" + title + "|" + url;
var url = "http://www.chateauelan.com/inc/email.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);
}

// ********************
// Gets the weather. :P
// ********************
function getWeather(day)
{
var ajaxRequest;
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

function stateChanged()
{
if (ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete")
	{
var text=ajaxRequest.responseText;

document.getElementById('weatherLoad').style.display = 'none';

try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(text);
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(text,"text/xml");
  }
  catch(e)
  {
  alert(e.message);
  return;
  }
}

var datafoo = xmlDoc.getElementsByTagName("data")[0];
var dataparam = datafoo.getElementsByTagName("parameters")[0];

var firstTemp = dataparam.getElementsByTagName("temperature")[0].getAttribute("type");

if (firstTemp == "maximum") {
	document.getElementById("high").innerHTML= "<font class='tempTitle'>HIGH: </font>" + 
	dataparam.getElementsByTagName("temperature")[0].getElementsByTagName("value")[0].childNodes[0].nodeValue + "&#176\;";
	
	document.getElementById("low").innerHTML= "<font class='tempTitle'>LOW: </font>" + 
	dataparam.getElementsByTagName("temperature")[1].getElementsByTagName("value")[0].childNodes[0].nodeValue + "&#176\;";
} else if (firstTemp == "minimum") {
	var shortVer = 0;
	document.getElementById("high").innerHTML = "<font class='tempTitle'>HIGH: </font>n/a";
	document.getElementById("low").innerHTML= "<font class='tempTitle'>LOW: </font>" + 
	dataparam.getElementsByTagName("temperature")[0].getElementsByTagName("value")[0].childNodes[0].nodeValue + "&#176\;";
}

/* try {
document.getElementById("high").innerHTML= "<font class='tempTitle'>HIGH: </font>" + xmlDoc.getElementsByTagName("data")[0].childNodes[5].childNodes[0].childNodes[1].text + "&#176\;";
}
catch(e)
{
	alert("Error retrieving weather. Please try again later.");
	document.getElementById("divWeather").style.display = "none";
	return;
}



document.getElementById("low").innerHTML= "<font class='tempTitle'>LOW: </font> " + xmlDoc.getElementsByTagName("data")[0].childNodes[5].childNodes[1].childNodes[1].text + "&#176\;";
*/
// var details = "<br /><b><u>Details</u></b><br /><br />";


// *** weather-1: This block of code gets the time intervals from the NWS XML parse (provided via AJAX request) ***
if (shortVer == 0) {
var foolen = datafoo.childNodes[3].childNodes.length;
} else {
var foolen = datafoo.childNodes[4].childNodes.length;
}
var i = 1;
var joo = "";
var loc;
var timeVal;
var daynight;
var wtimes = new Array();
var arraycount = 0;

while (foolen > i) {
if (shortVer == 0) {
joo = datafoo.childNodes[3].childNodes[i].text;
} else {
joo = datafoo.childNodes[4].childNodes[i].text;
}
loc = joo.indexOf('T') + 1;
timeVal = joo.substring(loc, loc + 2);
timeVal = parseInt(timeVal, 10);
if (timeVal > 12) {
	timeVal = timeVal - 12;
	daynight = "pm";
}
else { daynight = "am"; }
// details = details + timeVal + ":00" + daynight + "<br />";
wtimes[arraycount] = "<b>" + timeVal + ":00" + daynight + "</b>";

i++;
arraycount++;
}
// *** weather-1: END ***

// *** weather-1.5: This block of code (added after the fact) gets temperatures at each time interval from the NWS XML parse (provide via AJAX request) ***
var wtemp = new Array();
arraycount = 0;
i = 1;

while (foolen > i) {
if(shortVer == 0) {
	joo = dataparam.childNodes[1].childNodes[1].text;
	} else {
	joo = datafoo.childNodes[5].childNodes[2].childNodes[i].text;
	}
	wtemp[arraycount] = joo;
	i++;
	arraycount++;
}

// *** weather-1.5: END ***


// *** weather-2: This block of code gets wind speeds (mph) at each time interval from the NWS XML parse (provided via AJAX request) ***
i = 1;
var wwind = new Array();
arraycount = 0;

while (foolen > i) {
if(shortVer == 0) {
	joo = dataparam.childNodes[2].childNodes[1].text;
} else {
joo = datafoo.childNodes[5].childNodes[3].childNodes[i].text;
}
wwind[arraycount] = joo;

i++;
arraycount++;
}

// *** weather-2: END ***


// *** weather-3: This block of code gets cloud cover (%) at each time interval from the NWS XML parse (provided via AJAX request) ***
i = 1;
var wcloud = new Array();
arraycount = 0;

while (foolen > i) {
if(shortVer == 0) {
	joo = dataparam.childNodes[3].childNodes[1].text;
} else {
joo = datafoo.childNodes[5].childNodes[4].childNodes[i].text;
}
wcloud[arraycount] = joo;

i++;
arraycount++;
}
// *** weather-3: END ***


// *** weather-4: This block of code gets weather conditions/intensity at each time interval from the NWS XML parse (provided via AJAX request) ***
i = 0;
var k = 1;
var wweather = new Array();
var wconditions = "";
var count;
arraycount = 0;
var zoo;

// alert(datafoo.childNodes[5].childNodes[4].childNodes[7].length);

if(shortVer == 0) {

	while (foolen > k) {
	dataWeather = dataparam.childNodes[4];
	if (dataWeather.childNodes[k].childNodes.length > 0) {
	count = dataWeather.childNodes[k].childNodes.length;
	i = 0;
	zoo = "";
	wconditions = "";
	
	while (count > i) {
	 	wconditions = wconditions + dataWeather.childNodes[k].childNodes[i].getAttribute("intensity");
		wconditions = wconditions + dataWeather.childNodes[k].childNodes[i].getAttribute("weather-type");
		wconditions = wconditions + dataWeather.childNodes[k].childNodes[i].getAttribute("coverage");
		i++;
	}
zoo = wconditions;
}
else {
zoo = "noweather";
}
wweather[arraycount] = zoo;
k++;
arraycount++;
}

} // End of shortVer check
else {
	while (foolen > k) {
if (datafoo.childNodes[5].childNodes[5].childNodes[k].childNodes.length > 0) {
	count = datafoo.childNodes[5].childNodes[5].childNodes[k].childNodes.length;
	i = 0;
	zoo = "";
	wconditions = "";
	
	while (count > i) {
	 	wconditions = wconditions + datafoo.childNodes[5].childNodes[5].childNodes[k].childNodes[i].getAttribute("intensity");
		wconditions = wconditions + datafoo.childNodes[5].childNodes[5].childNodes[k].childNodes[i].getAttribute("weather-type");
		wconditions = wconditions + datafoo.childNodes[5].childNodes[5].childNodes[k].childNodes[i].getAttribute("coverage");
		i++;
	}
zoo = wconditions;
}
else {
zoo = "noweather";
}
wweather[arraycount] = zoo;
k++;
arraycount++;
}
} // End of shortVer check (else)

// *** weather-4: END ***

// *** weather-5: This block of code is to generate the output from the captured array data on-screen (temporary) ***
i = 0;
var yep = document.getElementById("details");
var build = "<table border=\"0\"><tr>"; 

function convertCloud(cover) {
	if (cover <= 10) {
		return "Clear";
	} else if (cover <= 35 && cover >= 11) {
		return "Partly Cloudy";
	} else if (cover <= 75 && cover >= 36) {
		return "Mostly Cloudy";
	} else if (cover >= 76) {
		return "Cloudy";
	}
}

function convertImage(weather, cloud, time) {
	var coverage = convertCloud(cloud);
	var weather2;
	weather2 = weather + "1";
	
	if (time.search("pm") > 0) {
		var what = "pm";
	} else {
		var what = "am";
	}
	
	var whatever = time.substr(3,1);
	parseInt(whatever);
	
	if (whatever >= 6 & what == "pm") {
		var night = "night";
	}
	
	if (weather2.search("noweather") >= 0 || weather2.search("frost") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("light") >= 0 && weather2.search("thunderstorms") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_light_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_light_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_light_tstorm.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("moderate") >= 0 && weather2.search("thunderstorms") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_moderate_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_moderate_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_moderate_tstorm.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("heavy") >= 0 && weather2.search("thunderstorms") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_heavy_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_heavy_tstorm.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_heavy_tstorm.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("light") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_light_rain.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_light_rain.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_light_rain.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("moderate") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_moderate_rain.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_moderate_rain.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_moderate_rain.jpg\" border=\"0\"><br />"; break;
		}
	} else if (weather2.search("rain showers") >= 0 && weather2.search("heavy") >= 0) {
		switch (coverage) {
			case "Clear": return "<img src=\"icons/clear.jpg\" border=\"0\"><br />"; break;
			case "Partly Cloudy": return "<img src=\"icons/partly_cloudy_heavy_rain.jpg\" border=\"0\"><br />"; break;
			case "Mostly Cloudy": return "<img src=\"icons/mostly_cloudy_heavy_rain.jpg\" border=\"0\"><br />"; break;
			case "Cloudy": return "<img src=\"icons/cloudy_heavy_rain.jpg\" border=\"0\"><br />"; break;
		}
	}
}

while (foolen - 1 > i) {
		// build = build + wtimes[i] + ": " + wcloud[i] + "% cloud cover | " + wwind[i] + "mph wind speed | " + wweather[i] + "<br />";
		build = build + "<td valign=\"top\" width=\"45\" align=\"center\">" + wtimes[i] + "<br />" + convertImage(wweather[i], wcloud[i], wtimes[i]) + "<br />" + wwind[i] + "mph<br /><b>" + wtemp[i] + "&#176\;</b></td>";
		i++;
}
build = build + "</tr></table>";

foolen = foolen - 1;
var endWidth = foolen * 50;
if (endWidth <200) { endWidth = 200;}
var currentWidth = document.getElementById("divWeather").style.width;
currentWidth = currentWidth.substr(0, currentWidth.length - 2);
changeDivWidth(currentWidth, endWidth, build);

// document.getElementById("divWeather").style.width = foolen * 50;

// yep.innerHTML = build;

// *** weather-5: END ***

}
 	}
var str = "str=" + day;
var url = "capture.php";
ajaxRequest.onreadystatechange=stateChanged;
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", str.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(str);

}

// *******************************************************************************************
// These are functions to fade a div in and out. Currently used just for sendToFriend feature.
// Function list: fadeInDiv, fadeoutDiv
// *******************************************************************************************
function fadeInDiv(g, div) {
	var q = parseInt(g);
		if (q < 100)
			{
				document.getElementById(div).style.filter = 'alpha(opacity = '+ q +')';
				document.getElementById(div).style.opacity = q/100;
				q = q + 10;
				t = setTimeout("fadeInDiv('" +q+ "','"+div+"')",20);
			}
			else
			{
				document.getElementById(div).style.filter = 'alpha(opacity = 100)';
				document.getElementById(div).style.opacity = 1;
				clearTimeout(t);
				setTimeout( fieldFocus , 100 );
			}
}

function fadeOutDiv(g, div) {
		var q = parseInt(g);
		if (q > 0)
			{
				document.getElementById(div).style.filter = 'alpha(opacity = '+ q +')';
				document.getElementById(div).style.opacity = q/100;
				q = q - 10;
				t = setTimeout("fadeOutDiv('" +q+ "','"+div+"')",20);
			}
			else
			{
				document.getElementById(div).style.filter = 'alpha(opacity = 0)';
				document.getElementById(div).style.opacity = 0;
				document.getElementById(div).style.display = "none";
				clearTimeout(t);
			}
}

function mouseXandY(e, div) {
  var x=0;
  var y=0;
  e=e||window.event;
  if(e.pageX || e.pageY) {
    x=e.pageX;
    y=e.pageY;
  } else if(typeof(e.clientX)=='number') {
    var dE=document.documentElement;
    x=e.clientX+document.body.scrollLeft+(dE?dE.scrollLeft:0);
	x = x - document.body.offsetLeft;
    y=e.clientY+document.body.scrollTop+(dE?dE.scrollTop:0);
  }
  	y = y - 205;
	// if (document.getElementById("container")) { x = x - 140; }
	document.getElementById(div).style.position = "absolute";
	document.getElementById(div).style.top = y + "px";
	document.getElementById(div).style.left = x + "px";
	document.getElementById(div).style.filter = 'alpha(opacity = 0)';
	document.getElementById(div).style.opacity = 0;
	// document.getElementById(div).style.display = "inline";
	fadeInDiv(10, div);
}

function mouseXandYWeather(e, div, day) { 
  var x=0,y=0;
  e=e||window.event;
  if(e.pageX || e.pageY) {
    x=e.pageX;
    y=e.pageY;
  } else if(typeof(e.clientX)=='number') {
    var dE=document.documentElement;
    x=e.clientX+document.body.scrollLeft+(dE?dE.scrollLeft:0);
    y=e.clientY+document.body.scrollTop+(dE?dE.scrollTop:0);
	y = y - 155;
  }
  	var cWidth = document.documentElement.clientWidth;
	var cWidthDiff = cWidth - x;
	if (cWidthDiff <= 410) {
		x = x - (410 - cWidthDiff);
	}
  	
	document.getElementById("high").innerHTML = "";
	document.getElementById("low").innerHTML = "";
	document.getElementById("details").innerHTML = "";		
	document.getElementById('weatherLoad').style.display = 'inline';
	document.getElementById(div).style.position = "absolute";
	document.getElementById(div).style.top = y + "px";
	document.getElementById(div).style.left = x + "px";
	document.getElementById(div).style.display = "inline";
	getWeather(day);
}

function closeEmail(div) {
	fadeOutDiv(90, div);
}

function closeWeather(div) {
	document.getElementById(div).style.display = "none";
}

if (window.location.href.indexOf("https") >= 0) {
} else { document.onclick=check; }

function check(e){ 
var target = (e && e.target) || (event && event.srcElement); 

var obj = document.getElementById('divEmailTo');
checkParent(target)?obj.style.display='none':null;

if (document.getElementById('divWeather')) {
var obj1 = document.getElementById('divWeather');
checkParent(target)?obj1.style.display='none':null;

var divEls = document.getElementsByTagName("img");
var i = 0;
var m;
var yep = document.getElementById('divWeather');
	for (i=0;i<divEls.length;i++) {
		if (parseInt(divEls[i].id) <= 31) {
			m = document.getElementById(divEls[i].id);
			target==m?yep.style.display='inline':null;
		}
	}
}

var obj2 = document.getElementById('emailLink');
var obj3 = document.getElementById('emailLink2');
target==obj2?obj.style.display='inline':null;
target==obj3?obj.style.display='inline':null;
}

function checkParent(t){ 
while(t.parentNode){ 
if(t==document.getElementById('divEmailTo')){ 
return false
}
if(t==document.getElementById('divWeather')){ 
return false
}
t=t.parentNode
} 
return true
} 