/* 
 ============================================================================
	Copyright Michael Leahy 2008. Used with Permission.                             
	May not be duplicated or reproduced.
	MINIMUM BROWSER CHECK - PC: IE6+/Firefox1+/Safari3+/Netscape7+
	MINIMUM BROWSER CHECK - MAC: Firefox1+/Safari3+
 ============================================================================ 
//*/

// ============================================================ FUNCTIONS: NAV CONTROLS ============================================================ //
	
	// ==================== GLOBAL SETTINGS ==================== //
	var snavSliderSpeed = 5; // Move Sub Nav: Lower = Faster
	var snavSliderIncr = 10; // Move Sub Nav: Higher = Faster
	var snavSliderExitX = true; // Exit Sub Nav: Mouseout Left or Right
	var snavSliderExitY = false; // Exit Sub Nav: Mouseout Up or Down
	var snavParentOpenHL = false; // Set True to enable standing hover for Parent Nav Item Slider Open
	
	var snavDefWidth = 143; // Parent Nav Item Width (hint: viewable navigation item width)
	var snavDefWidthPadLeft = 9; // Parent Nav Item Width - Padding on Left (hint: viewable navigation item width)
	var snavDefHeight = 22; // Parent Nav Item Height
	var snavExtraDivCount = 3; // Number of Non-Navigational DIVs in Sub Nav
	var snavDivHeight = 25.5; // Sub Nav DIV Height
	var snavExtraDivHeight = 28; // Height Non-Navigational DIVs in Sub Nav
	// ==================== GLOBAL SETTINGS ==================== //
	
	// !!!!!!!!!!!!!!!!!!!! DO NOT MODIFY BELOW HERE !!!!!!!!!!!!!!!!!!!! //
	
	// ==================== GLOBAL CONTROLS ==================== //
	var navIsHome = false; // Home Nav State
	var snavActiveObj = ''; // Sub Nav ID
	var snavOpenObj = new Array(); // Sub Nav Open IDs
	var snavParentObj = ''; // Sub Nav Parent Nav Object
	var snavOpenParentObj = new Array(); // Sub Nav Parent Nav Open Objects
	var snavIsActive = false; // Sub Nav Movement State
	var snavTimer = ''; 
	var mouseXY = new Object();
	
	var IE = document.all?true:false;
		if (IE) snavSliderIncr = snavSliderIncr + 5; // IE Timing is Slower than Other Browsers
		if (!IE) document.captureEvents(Event.MOUSEMOVE);
	
	document.onmousemove = snavExit; //get_mouseXY;
	// ==================== GLOBAL CONTROLS ==================== //
	
	
	function navMouseState(oObj) {
		if (oObj.className == '') {
			if (oObj.getElementsByTagName('a')[0].className == 'navHome') navIsHome = true;
					
			oObj.className = 'navBGHover';
			oObj.getElementsByTagName('a')[0].className = 'navHover';
			
			if (oObj.getElementsByTagName('img')) oObj.getElementsByTagName('img')[0].src = oObj.getElementsByTagName('img')[0].src.replace(/(.*).png/gi, '$1-ovr.png');
		} else {
			oObj.className = '';
			
			if (navIsHome) {
				navIsHome = false;
				oObj.getElementsByTagName('a')[0].className = 'navHome';
			} else oObj.getElementsByTagName('a')[0].className = 'nav';
			
			if (oObj.getElementsByTagName('img')) oObj.getElementsByTagName('img')[0].src = oObj.getElementsByTagName('img')[0].src.replace(/(.*)-dwn.png/gi, '$1.png');
			if (oObj.getElementsByTagName('img')) oObj.getElementsByTagName('img')[0].src = oObj.getElementsByTagName('img')[0].src.replace(/(.*)-ovr.png/gi, '$1.png');
		}
	}
	
	function snavMouseState(oObj) {
		if (oObj.className == 'snavItem') {
			oObj.className = 'snavItem navBGHover';
			oObj.getElementsByTagName('a')[0].className = 'navHover';
		} else {
			oObj.className = 'snavItem';
			oObj.getElementsByTagName('a')[0].className = 'nav';
		}
	}
	
	function snavParentMouseOver(oObj, oStand) {
		snavParentMouseState(oObj,true); // Must be called to work with array controls (Simplifies HTML Navigation)
		
		if (snavParentOpenHL) return;
			
		oObj.className = 'navBGHover';
		if (oObj.getElementsByTagName('a')) oObj.getElementsByTagName('a')[0].className = 'navHover';
		if (oObj.getElementsByTagName('img')) oObj.getElementsByTagName('img')[0].src = oObj.getElementsByTagName('img')[0].src.replace(/(.*)-dwn.png/gi, '$1-ovr.png');
	}	
	
	function snavParentMouseOut(oObj, oStand) {
		if (snavParentOpenHL) return; 
		
		oObj.className = 'snavParentHover';
		if (oObj.getElementsByTagName('a')) oObj.getElementsByTagName('a')[0].className = 'nav';
		if (oObj.getElementsByTagName('img')) oObj.getElementsByTagName('img')[0].src = oObj.getElementsByTagName('img')[0].src.replace(/(.*)-ovr.png/gi, '$1-dwn.png');
	}
	
	function snavParentMouseState(oObj, oOpen) {
		if (oOpen) {
			var exits = snavParentObjectArr(oObj);
			if (exits) return;
			
			navMouseState(oObj);
			snavParentObj = oObj;
		} else {
			navMouseState(oObj);
			if (snavParentObj == oObj) snavParentObj = '';
		}
	}
		
	function snavControl(oObj, oOpen) {
		if (snavIsActive && oOpen) return;
		if (oOpen && snavActiveObj == '') { snavActiveObj = oObj; }
		if (oOpen) snavObjectArr(oObj);
		
		var maxheight = Math.round((document.getElementById(oObj).getElementsByTagName('div').length - snavExtraDivCount) * snavDivHeight) + snavExtraDivHeight;
			if (!oOpen) maxheight = snavDefHeight;
		
		snavSlider(oObj, maxheight, oOpen);
	}
	
	function snavExit(oEvent) {
		get_mouseXY(oEvent);
		
		if (!snavIsActive && (snavActiveObj != '' || snavOpenObj.length > 0)) {
			var snavObj = document.getElementById(snavActiveObj);
				if (!snavObj) return;
			var objW = snavDefWidth;
			var objH = snavObj.clientHeight;
				if (objH == 0) objH = snavObj.offsetHeight;
			var objXY = get_XYcoordinates(snavActiveObj);
			
			if (snavSliderExitX) { 
				if (mouseXY.x < (objXY.x + snavDefWidthPadLeft) || mouseXY.x > ((objXY.x + snavDefWidthPadLeft) + objW)) {
					//snavControl(snavActiveObj, false);
					for (var i=0; i<snavOpenObj.length; i++) { snavControl(snavOpenObj[i], false); }
				}
			}
			if (snavSliderExitY) { if (mouseXY.y < objXY.y || mouseXY.y > (objXY.y + objH)) snavControl(snavActiveObj, false); }
		}
	}
		
	function snavSlider(oObj, oMaxHeight, oOpen) {
		var snavObj = document.getElementById(oObj);
		var curheight = snavObj.clientHeight;
			if (curheight == 0) curheight = snavObj.offsetHeight;
		
		if (oOpen) {
			if (curheight + snavSliderIncr < oMaxHeight) {
				snavObj.style.height = (curheight + snavSliderIncr)+'px';
				snavIsActive = true;
				snavIsOpen = true;
				snavTimer = setTimeout("snavSlider('"+oObj+"',"+oMaxHeight+",true)",snavSliderSpeed);
			} else {
				snavObj.style.height = oMaxHeight+'px';
				snavIsActive = false;
				//clearTimeout(snavTimer);
			}
		} else {
			if (curheight - snavSliderIncr > snavDefHeight) {
				snavObj.style.height = (curheight - snavSliderIncr)+'px';
				snavIsActive = true;
				snavTimer = setTimeout("snavSlider('"+oObj+"',"+oMaxHeight+",false)",snavSliderSpeed);
			} else {
				snavObj.style.height = snavDefHeight+'px';
				snavActiveObj = '';
				for (var i=0; i<snavOpenObj.length; i++) { if (snavOpenObj[i] == oObj) { var pos = i; snavOpenObj.splice(i,1); break; } }
				
				//* Disabled to de-activate the standing highlight for Parent Nav
				snavParentMouseState(snavOpenParentObj[pos],false);
					snavOpenParentObj.splice(pos,1);
				//*/
				
				snavIsActive = false;
				//clearTimeout(snavTimer);
			}
		}
	}
	
	function snavObjectArr(oObjID) {
		var exists = false;
		for (var i=0; i<snavOpenObj.length; i++) { if (snavOpenObj[i] == oObjID) exists = true; }

		if (!exists) snavOpenObj.push(oObjID);
	}
	
	function snavParentObjectArr(oObj) {
		var exists = false;
		for (var i=0; i<snavOpenParentObj.length; i++) { if (snavOpenParentObj[i] == oObj) exists = true; }

		if (!exists) snavOpenParentObj.push(oObj);
		
		return exists;
	}
	

// ============================================================ FUNCTIONS: COORIDNATES ============================================================	//
	
	function get_mouseXY(e) {
		if (IE) {
			mouseXY.x = event.clientX + document.body.scrollLeft;
			mouseXY.y = event.clientY + document.body.scrollTop;
		} else {
			mouseXY.x = e.pageX
			mouseXY.y = e.pageY
		}
	}
	
	function get_XYcoordinates(element) {
		var useWindow = false;
		var coordinates = new Object();
		var x = 0;
		var y = 0;
		var use_gebi = false;
		var use_css = false;
		var use_layers = false;
		
		if (document.getElementById) use_gebi = true;
		else if (document.all) use_css = true;
		else if (document.layers) use_layers = true;
		
		if (use_gebi && document.all) {
			x = get_Xposition(document.all[element]);
			y = get_Yposition(document.all[element]);
		} else if (use_gebi) {
			x = get_Xposition(document.getElementById(element));
			y = get_Yposition(document.getElementById(element));
		} else if (use_css) {
			x = get_Xposition(document.all[element]);
			y = get_Yposition(document.all[element]);
		} else if (use_layers) {
			var found = 0;
			for (var i=0; i<document.anchors.length; i++) {
				if (document.anchors[i].name==element) {
					found = 1; 
					break;
				}
			}
	
			if (found == 0) {
				coordinates.x = 0;
				coordinates.y = 0;
				return coordinates;
			}
			
			x = document.anchors[i].x;
			y = document.anchors[i].y;
		} else {
			coordinates.x = 0;
			coordinates.y = 0;
			return coordinates;
		}
		
		coordinates.x = x;
		coordinates.y = y;
		return coordinates;
	}
	
	function get_Xposition (element) {
		var ol = element.offsetLeft;
		while ((element = element.offsetParent) != null) {
			ol += element.offsetLeft;
		}
		return ol;
	}
	
	function get_Yposition (element) {
		var ot = element.offsetTop;
		while((element = element.offsetParent) != null) {
			ot += element.offsetTop;
		}
		return ot;
	}


// ============================================================ FUNCTIONS: BOOKING DEVICE ============================================================	
	
	function load_calendarFrame(oPos, oField) {
		var load_calendar = false;
		
		switch(BrowserDetect.browser) {
			case "Explorer":
				if (BrowserDetect.version >= 5) {load_calendar = true;} break;
			case "Firefox":
				 if (BrowserDetect.version >= 1) {load_calendar = true;} break;
			case "Netscape":
				if (BrowserDetect.version >= 7) {load_calendar = true;} break;
		}
		
		if (load_calendar) {
			document.write('<a id="'+oField+oPos+'_btn_calendar" name="'+oField+oPos+'_btn_calendar" href="javascript:getCalendar(\'\',\''+oPos+'\',\''+oField+'\');"><img src="/assets/images/btn_calendar.gif" width="20" height="15" alt="Click to view a Calendar" border="0" /></a>');
			document.write('<div id="'+oField+oPos+'_div_calendar" style="position:absolute; left:0px; top:0px; width:210px; height:195px; visibility:hidden; z-index:1;">');
				document.write('<IFRAME unselectable="on" id="'+oField+oPos+'_dlg_calendar" name="'+oField+oPos+'_dlg_calendar" src="/dlg_calendar.asp" width="100%" height="100%" marginheight="0" marginwidth="0" frameBorder="0" noResize scrolling="no"></IFRAME>');
			document.write('</div>');
		} else {
			document.write('&nbsp;');
		}
	}
	
	function setBook_days(oPos, oField) {
		var bookingForm = document.forms['bookingForm'+oPos];
		var mo_array = new Array();
		mo_array = bookingForm[oField+'_moyr'].options[bookingForm[oField+'_moyr'].selectedIndex].value.split(",");
		var mo = mo_array[0];
		var cur = bookingForm[oField+'_day'].options[bookingForm[oField+'_day'].selectedIndex].value;
		var num = 31;
		
		if (mo == 4 || mo == 6 || mo == 9 || mo == 11) num = 30;
		
		if (mo == 2) {
			var year = mo_array[1];
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			
			if (!isleap) num = 28;
			else num = 29;
		}
		
		bookingForm[oField+'_day'].options.length = 0;
		for (var i=0; i<num; i++) {
			bookingForm[oField+'_day'].options[i] = new Option(i+1,i+1);
			if (i+1 == cur) bookingForm[oField+'_day'].selectedIndex = i;
		}
	}
	
	function closeCalendar(oPos, oField) {
		document.getElementById(oField+oPos+'_div_calendar').style.visibility = "hidden";
	}
	
	function getCalendar(oDate, oPos, oField) {
		//if (navigator.appName.toLowerCase() == "netscape") return;
		
		var bookingForm = document.forms['bookingForm'+oPos];
		var moyr_array = new Array();
		moyr_array = bookingForm[oField+'_moyr'].value.split(",");
		var the_date = moyr_array[0]+"/"+bookingForm[oField+'_day'].value+"/"+moyr_array[1];
		document.getElementById(oField+oPos+'_dlg_calendar').src = "/dlg_calendar.asp?the_date="+the_date+"&start_date="+oDate+"&pos="+oPos+"&field="+oField;
		
		var div_calendar = document.getElementById(oField+oPos+'_div_calendar');
		div_calendar.style.left = (get_XYcoordinates(oField+oPos+'_btn_calendar').x-194)+'px';
		div_calendar.style.top = (get_XYcoordinates(oField+oPos+'_btn_calendar').y+5)+'px';
		div_calendar.style.visibility = "visible";
		
		
	}
	
	function selectCalendar(oDate, oPos, oField) {
		if (oPos != '') { //SET FOR PACKAGES - FORCE NEXT DATE SELECTION
			var cur_date = new Date();
			cur_date.setDate(cur_date.getDate()+1);
			var sel_date = new Date(oDate);
			if (cur_date > sel_date) oDate = (cur_date.getMonth()+1)+"/"+cur_date.getDate()+"/"+cur_date.getFullYear();
		}
		
		var bookingForm = document.forms['bookingForm'+oPos];
		var date_array = new Array();
		date_array = oDate.split("/");
		
		bookingForm[oField+'_day'].selectedIndex = date_array[1]-1;
		for(var i=0; i<bookingForm[oField+'_moyr'].length; i++)
			if (bookingForm[oField+'_moyr'].options[i].value == date_array[0]+','+date_array[2]) bookingForm[oField+'_moyr'].selectedIndex = i;
		
		setBook_days(oPos,oField);
		closeCalendar(oPos,oField);
	}
	
	
	var popWin = ""; // function:newWindow(oPage, oW, oH, oScroll); close_pops();
	
	function openWindow(oPage, oW, oH, oScroll){
		if (popWin) popWin.close();
		
		xpos 								= (screen.width) ? (screen.width - oW)/2 : 0;
		ypos 								= (screen.height) ? (screen.height - oH)/2 : 0;
		
		if (oScroll == 'Y')
			popWin = window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
		else
			popWin = window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
		
		popWin.focus();
	}
	
	
	
	function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }