var imgIds = new Array();
var evtDiv = null;

function populateEvents(eventDiv){

	evtDiv = document.getElementById(eventDiv);	
	
	try {
		if (window.XMLHttpRequest) {
			request = new XMLHttpRequest();
			request.overrideMimeType('text/xml');
		} else if (window.ActiveXObject) {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	catch(ex) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex2)
		{
			request = null;
		}
	}
	if ( request != null )
	{		
		request.open("POST","displayactiveevents.php",true);
		request.onreadystatechange = EventListLoadResponse;
		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send("");
	}	

}

function EventListLoadResponse(){
	if (request.readyState == 4){
		if(request.status != 200){
			alert("The response is complete. status=" + request.status);
			return;
		}		
		var eventHtml = request.responseText;
		evtDiv.innerHTML = eventHtml;
	}
}

function showImage(sUrl, hgt,wdt) {
	sOpts = "menubar=no,location=no,resizable=yes,height=" + hgt + ",width=" + wdt + ",scrollbars=yes,status=yes"; 
	WindowObjectReference = window.open(sUrl,"Historical Images",sOpts);
}

function SetDayMonthYear(inputField) {
	document.forms['form1'].zmonth.value = inputField.value.substr(0,2);
	document.forms['form1'].zday.value = inputField.value.substr(3,2);
	document.forms['form1'].zyear.value = inputField.value.substr(6,4);
	return true;
}

function submitToWebervations(){
	zl = document.forms['form1'].zlength.value;
	ad = document.forms['form1'].arrivedate.value;	
	if(ad == null || ad == ""){
		//alert("A valid arrival date must be entered");
		//return;
		window.status = "No date was provided, todays date will be used.";
		nD = new Date();
		sMnth = new String(nD.getMonth()+1);
		if(sMnth.length == 1) sMnth = "0" + sMnth; 
		sDay = new String(nD.getDate());
		if(sDay.length == 1) sDay = "0" + sDay; 	
		ad = sMnth + "/" + sDay + "/" + nD.getFullYear();			
		zl = "2";
	}
	nD = new Date(ad);
	if(isNaN(nD)){		
		alert("A valid arrival date must be entered");
		return;
	}
	sMnth = new String(nD.getMonth()+1);
	if(sMnth.length == 1) sMnth = "0" + sMnth; 
	sDay = new String(nD.getDate());
	if(sDay.length == 1) sDay = "0" + sDay; 	
	ad = sMnth + "/" + sDay + "/" + nD.getFullYear();	
	document.forms['form1'].zmonth.value = sMnth;
	document.forms['form1'].zday.value = sDay;
	document.forms['form1'].zyear.value = nD.getFullYear();
	window.location = "/CheckAvailability.php?zlength=" + zl + "&arrivedate=" + ad;
	//WindowObjectReference = window.open("/webervations.php?zlength=" + zl + "&arrivedate=" + ad,"Webervations","menubar=no,location=no,resizable=yes,height=450,width=700,scrollbars=yes,status=yes");
}

function checkReservations() {
	var date1 = document.getElementById("arrivedate").value;
	var date2 = document.getElementById("departdate").value;
	var date_pieces = date1.split("/");
	var errflag = 0;
	if (date_pieces.length != 3) {
		errflag = 1;
	}
	else {
		var in_month = parseInt(date_pieces[0],10);
		var in_day = parseInt(date_pieces[1],10);
		var in_year = parseInt(date_pieces[2],10);
		if ( (isNaN(in_month)) || (isNaN(in_day)) || (isNaN(in_year)) ) {
			errflag = 1;
		}
		else {
			var date1date = new Date(in_year, in_month, in_day);
			document.getElementById("zmonth").value = in_month;
			document.getElementById("zday").value = in_day;
			document.getElementById("zyear").value = in_year;
			date_pieces = date2.split("/");
			if (date_pieces.length != 3) {
				errflag = 1;
			}
			else {
				in_month = parseInt(date_pieces[0],10);
				in_day = parseInt(date_pieces[1],10);
				in_year = parseInt(date_pieces[2],10);
				if ( (isNaN(in_month)) || (isNaN(in_day)) || (isNaN(in_year)) ) {
					errflag = 1;
				}
				else {
					var date2date = new Date(in_year, in_month, in_day);
					var one_day = (1000*60*60*24);
					var in_length = Math.ceil((date2date.getTime()-date1date.getTime())/(one_day));
					document.getElementById("zlength").value = in_length;
				}
			}
		}
	}
	if (errflag == 1) {
		alert("Please specify valid arrival and departure dates.");
	}
	else {
           document.checkres.submit();
	}
}

function iebody()
{
	// Sense the difference between Strict and Quirks mode
	return (document.compatMode != "BackCompat"? document.documentElement : document.body);
}
function resizeImg()
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1)
	{
		var nW = iebody().clientWidth * .90;
		nW = nW.toFixed();	
		
		for (var i = 0; i < imgIds.length; i++) {
			var el1 = document.getElementById(imgIds[i]);			
			if(el1.width < nW){	
				nWL = getParentNodeWidth(el1);
				if(nWL != null){
					el1.width = nWL;
					el1.style.width = nWL;
				}
			}

		}
		var imgTags = document.getElementsByTagName("img"); 
		for (var i = 0; i < imgTags.length; i++) {
		    	var elmId = imgTags[i].getAttribute("id");
			if(elmId != null && elmId != ""){				
				var el1 = document.getElementById(elmId);
				if(el1.width > nW){
					bAlreadyAdded = false;
					for (var i = 0; i < imgIds.length; i++) {
						if(imgIds[i] == elmId) bAlreadyAdded = true;
					}
					if(!bAlreadyAdded){
						imgIds[imgIds.length] = elmId;
					}
					var cssTxt = el1.style.cssText;
					// the min-width property is only supported on ie 7
					// so we'll have to do a little fanagleing to get it
					if(!el1.style.minWidth){
						if(cssTxt.indexOf("min-width") != -1){
							var prperties = cssTxt.split(";");
							for (var i=0; i < prperties.length; i++) {
								if(prperties[i].indexOf("min-width") != -1){
									var minwdth = prperties[i].split(":");
									if(minwdth[1].indexOf("px") != -1){
										var mW = new Number(minwdth[1].substring(0,minwdth[1].indexOf("px")));
										//window.status = mW + "," + nW;
										if(mW > nW) nW = mW;
									}
								}
							}
						}
					} else {
						if(el1.style.minWidth > nW) nW = el1.style.minWidth;	
					}
					
					el1.width = nW;
					el1.style.width = nW;
					//window.status = nW;
				}	
			}
		}	
	
		//window.status = nW;		
	} 
	else {
		var imgTags = document.getElementsByTagName("img"); 
		for (var i = 0; i < imgTags.length; i++) {
		    	var elmId = imgTags[i].getAttribute("id");
			if(elmId != null && elmId != ""){				
				var el1 = document.getElementById(elmId);
				if(el1.style.minWidth != "0" && el1.style.minWidth != "0px"){
					el1.style.minWidth = "0px";
				}
			}
		}
		
		divTags = document.getElementsByTagName("div"); 
		for (var i = 0; i < divTags.length; i++) {
			var elmId = divTags[i].getAttribute("id");
			if(elmId == "homepageflash"){				
				var el1 = document.getElementById(elmId);
				var nWL = getParentNodeWidth(el1);
				window.status = nWL;
			}

		}
	}
}

function getParentNodeWidth(el1){
	p1 = el1.parentNode;
	if(p1 == null){
		return null;
	} else {
		if(p1.width != null && p1.width != ""){
			return p1.width;
		} else {
			return getParentNodeWidth(p1);
		}
	}
}

function validateFrmSubscribe(){
 	if (isWhitespace(document.getElementById('SubName').value)) {
		alert('Please supply Your Name.');
		document.getElementById('SubName').focus();
		return false;
	}
	
	if (isValidEmail(document.getElementById('SubEmail').value) == false) {
	 	alert('Please supply a valid Your Email.');
		document.getElementById('SubEmail').focus();
		return false;
	}
}

function addNewContentPage(navString,fckEditFlag){
	if(document.form1.name.value == ""){
		alert("Navigation item name must be entered.");
		return
	}
	var sep = "";
	if(navString.indexOf("?") != 0 ){
		sep = "?";
	}

	window.location='/editcontent.php' + sep + navString + '&req=1&id=0&src=a&edt=' + fckEditFlag + '&n=' + escape(document.form1.name.value) + '&abbrev=' + escape(document.form1.Abbreviation.value);

}
function textLimit(infield,limit,dochandle) {
	var result = true;
	if (infield.value.length >= limit)
		result = false;
	dochandle.onkeypress = new Function('return ' + result + ';');
	return result;
}

function textTrim(infield,limit) {
	infield.value = infield.value.substring(0,limit);
}

// verifies field value
function isWhitespace (s){   	
	// whitespace characters
	var whitespace = ' \t\n\r';

	var i;
	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
	{
		// Check that current character isn't whitespace.
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace.
	return true;
}	

// validates emails
function isValidEmail(emailAddress) {					
	// declare variables
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
						
	// the email was validated
	if (filter.test(emailAddress)){
		return true;
	}
	// the email was invalid
	else {
		// alert the user
		return false;

	}
				
}

function verifyPhone(source_fld) {
	// convert phone alphas to corresponding numbers
	re = /[abc]/gi;
	source_fld.value = source_fld.value.replace(re, "2");
	re = /[def]/gi;
	source_fld.value = source_fld.value.replace(re, "3");
	re = /[ghi]/gi;
	source_fld.value = source_fld.value.replace(re, "4");
	re = /[jkl]/gi;
	source_fld.value = source_fld.value.replace(re, "5");
	re = /[mno]/gi;
	source_fld.value = source_fld.value.replace(re, "6");
	re = /[prs]/gi;
	source_fld.value = source_fld.value.replace(re, "7");
	re = /[tuv]/gi;
	source_fld.value = source_fld.value.replace(re, "8");
	re = /[wxy]/gi;
	source_fld.value = source_fld.value.replace(re, "9");
	// get rid of other non-numerics
	re = /[^0-9]/gi;
	source_fld.value = source_fld.value.replace(re, "");
	// only verify if present
	if (!source_fld.value) {
		return true;
	}
	// append area code if required
	if (source_fld.value.length == 7) {
		source_fld.value = "908" + source_fld.value;
	}
	// drop the long distance 1
	if (source_fld.value.length == 11 && source_fld.value.substring(0,1) == "1") {
		source_fld.value = source_fld.value.substring(1,12);
	}
	// if not a full number, alert and set focus
	if (source_fld.value.length != 10) {
		alert("Improper phone number format, please correct.");
		source_fld.focus();
	}
	else {
		source_fld.value = source_fld.value.substring(0,3) + "-" + source_fld.value.substring(3,6) + "-" + source_fld.value.substring(6,10);
	}
}

function wDelete(TARGET) {
	if (window.confirm("Are you sure you want to delete this entry?")) {
		window.location.href = TARGET;
	}
}

// function used to open the link selector window
function openFileSelect(fileType, formName, fieldName){
	// open the selector window
	window.open('link_manager.php?reqtype=' + fileType + '&form=' + formName + '&cntrl=' + fieldName, 'FileSelect', 'status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=650,height=425');
}

//
// vDate can be:
//   null: no display
//   shortdate: 09/21/2007
//   abbrdate: Sun, Sep 21, 2007
//   date: Sunday, September 21, 2007
// vTime can be:
//   null: no display
//   time: 09:32 PM
//   miltime: 21:32
// vSync can be:
//   null: no sync
//   sync: refreshes very second
//
function printDate(vDate, vTime, vSync) {
	var now = new Date(); 
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); 
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');    
	var daysabbr = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); 
	var monthsabbr = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');    
	var day = ((now.getDate()<10) ? "0" : "") + now.getDate();
	var month = ((now.getMonth()<10) ? "0" : "") + now.getMonth();
	var hours = ((now.getHours()<10) ? "0" : "") + now.getHours();
	var minutes = ((now.getMinutes()<10) ? "0" : "") + now.getMinutes();
	var ampm = ((now.getHours()>11) ? "PM" : "AM");
	function fourdigits(number) { return (number < 1000) ? number + 1900 : number; } 
	var today = "";
	var todaytime = "";
	if (vDate == "shortdate") {
		today = month + "/" + day + "/" + (fourdigits(now.getYear())); 
	}
	if (vDate == "abbrdate") {
		today = daysabbr[now.getDay()] + ", " + monthsabbr[now.getMonth()] + " " + day + ", " + (fourdigits(now.getYear())); 
	}
	if (vDate == "date") {
		today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + day + ", " + (fourdigits(now.getYear())); 
	}
	if (vTime == "time") {
		todaytime = hours + ":" + minutes + " " + ampm;
	}
	if (vTime == "miltime") {
		todaytime = now.getHours() + ":" + minutes;
	}
	document.write("<div id='syncdate'>" + today + " " + todaytime + "</div>");
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	return true;
}

function showVideo(vFile) {
	var so = new SWFObject('/include/flvplayer.swf','player','330','250','7');
	so.addParam("allowfullscreen","false");
	so.addVariable('autostart','true');
	so.addVariable('showdigits','true');
	so.addVariable('height','240');
	so.addVariable('width','320');
	so.addVariable('lightcolor','0x335500');
	so.addVariable('file',vFile);
	so.addVariable('linkfromdisplay','false');
	so.write('fvparea');
}

// function used to open the link selector window			
function openLinkSelect(formName, fieldName){
	// open the selector window
	window.open('/linkselect.php?form=' + formName + '&cntrl=' + fieldName, 'LinkSelect', 'status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=300,height=250');
}

function openFileSelect2(fileType, functionName){
	// open the selector window
	window.open('link_manager.php?reqtype=' + fileType + '&function=' + functionName, 'FileSelect', 'status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=650,height=425');	
}
