
// THE FOLLOWING DEVELOPMENT BY: MICHAEL LEAHY - WELK RESORTS WEB SYSTEMS MANAGER
// ============================================================ FUNCTIONS: IMAGES ============================================================
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_preloadImages() { //v3.0
	 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	//var img_path = '/assets/images/hnav_images/hnav_';
	//MM_preloadImages(img_path+'branson_or.gif',img_path+'palmsprings_or.gif',img_path+'sandiego_or.gif');
	
	//var img_path = '/assets/images/hnav_images/snav_';
	//MM_preloadImages(img_path+'olgiftshop_or.gif',img_path+'olgiftshop_or.gif',img_path+'newsgram_or.gif',img_path+'careers_or.gif',img_path+'contact_or.gif');

// ============================================================ FUNCTIONS: WINDOW ============================================================
	function newWindow(oPage, oW, oH, oScroll){
		close_pops();
		
		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 pop(h, w, p, n, s, r){
		var theHeight=h;
		var theWidth=w;
		var theTop=(screen.height/2)-(theHeight/2)
		var theLeft=(screen.width/2)-(theWidth/2)
		var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
		var winPop = window.open(p,n,"scrollbars="+s+","+features+",resizable="+r+"");
		winPop.focus();
	}
	
	function popGift(p){
		close_pops();
		
		var theWidth 		= 683;
		var theHeight 		= 400;
		
		var theTop 			= (screen.height/2)-(theHeight/2)
		var theLeft 		= (screen.width/2)-(theWidth/2)
		var winPop 			= window.open(p,'giftWin','scrollbars=1,'+'height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+',resizable=1,toolbar=1,menubar=1');
		winPop.focus();
	}
	
	function vfl_rules() {
		xpos 								= (screen.width) ? (screen.width - 400)/2 : 0;
		ypos 								= (screen.height) ? (screen.height - 400)/2 : 0;
		popWin = window.open('/confirmations_rules.asp','ruleWin','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400,left='+xpos+',top='+ypos);
		popWin.focus();
		
	}
	
	function close_pops() {
		if (navigator.appName.toLowerCase() != "netscape") {
			if (window.newWin) window.newWin.close();
			if (window.ruleWin) window.ruleWin.close();
			if (window.giftWin) window.giftWin.close();
		}
	}
	
	
	// FIXES NETSCAPE RESIZE BUG BY RELOADING AFTER WINDOW RESIZE
	function WM_netscapeCssFix() {
		if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight)
			document.location = document.location;
	}
	
	function WM_netscapeCssFixCheckIn() {
		if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
			if (typeof document.WM == 'undefined'){
				document.WM = new Object;
			}
			
			if (typeof document.WM.WM_scaleFont == 'undefined') {
				document.WM.WM_netscapeCssFix = new Object;
				document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
				document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
			}
			
			window.onresize = WM_netscapeCssFix;
		}
	}
	
	WM_netscapeCssFixCheckIn();
	
	// FIXES MICROSOFT ACTIVATING ACTIVEX CONTROL WITH SWF FILES
	function IE_activexControlFix() {
		var theObjects = document.getElementsByTagName("object");
		
		for (var i = 0; i < theObjects.length; i++) { 
			theObjects[i].outerHTML = theObjects[i].outerHTML;
		}
	}
	IE_activexControlFix();
	
	
	// BROWSER DETECTION
	var BrowserDetect = {
		// returns: BrowserDetect.browser, BrowserDetect.version, BrowserDetect.OS;
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{	string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},
			{	prop: window.opera,
				identity: "Opera"
			},
			{	string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{	string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{	string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{	string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{	// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{	string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{	string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 	// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{ 	string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{ 	string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{	string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();

// ============================================================ FUNCTIONS: BOOKING DEVICE ============================================================
	function load_calendarFrame(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="btn_calendar" name="btn_calendar" href="javascript:getCalendar();"><img src="/assets/images/icon_calendar.gif" width="20" height="15" alt="Click to view a Calendar" border="0" /></a>');
			document.write('<div id="div_calendar" style="position:absolute; left:0px; top:0px; width:210px; height:195px; visibility:hidden; z-index:1;">');
				document.write('<IFRAME unselectable="on" id="dlg_calendar" name="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(oForm, oMonth) {
		var cur = oForm.day.options[oForm.day.selectedIndex].value;
		var num = 31;
		
		if (oMonth == 4 || oMonth == 6 || oMonth == 9 || oMonth == 11) num = 30;
		
		if (oMonth == 2) {							
			var year = oForm.year.options[oForm.year.selectedIndex].value;
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			
			if (!isleap) num = 28;
			else num = 29;
		}
		
		oForm.day.options.length = 0;
		for (var i=0; i<num; i++) {
			oForm.day.options[i] = new Option(i+1,i+1);
			if (i+1 == cur) oForm.day.selectedIndex = i;
		}
	}
		
	function setBook_months(oForm) {
		//*
		var year = oForm.year.options[oForm.year.selectedIndex].value;
		var cur_date = new Date();
		
		oForm.month.options.length = 0;
		
		if (year > cur_date.getYear()) {
			for (var i=0; i<12; i++) oForm.month.options[i] = new Option(getBook_monthName(i+1),i+1);
		} else {
			for (var i=cur_date.getMonth(); i<12; i++) {
				oForm.month.options[i] = new Option(getBook_monthName(i+1),i+1);
			}
		}
		//*/
	}
	
	function getBook_monthName(oMonth) {
		switch (oMonth) {
			case 1:
				return "Jan"; break;
			case 2:
				return "Feb"; break;
			case 3:
				return "Mar"; break;
			case 4:
				return "Apr"; break;
			case 5:
				return "May"; break;
			case 6:
				return "Jun"; break;
			case 7:
				return "Jul"; break;
			case 8:
				return "Aug"; break;
			case 9:
				return "Sep"; break;
			case 10:
				return "Oct"; break;
			case 11:
				return "Nov"; break;
			case 12:
				return "Dec"; break;
		}
	}
	
	function closeCalendar() {
		document.getElementById('div_calendar').style.visibility = "hidden";
	}
	
	function getCalendar(oDate) {
		var bookingForm = document.forms['bookingForm'];
		var checkin = bookingForm.month.value+"/"+bookingForm.day.value+"/"+bookingForm.year.value;
		document.getElementById('dlg_calendar').src = "/dlg_calendar.asp?the_date="+checkin+"&start_date="+oDate;
		
		var div_calendar = document.getElementById('div_calendar');
		div_calendar.style.left = get_XYcoordinates('btn_calendar').x-194;
		div_calendar.style.top = get_XYcoordinates('btn_calendar').y+5;
		div_calendar.style.visibility = "visible";
	}
	
	function selectCalendar(oDate) {
		var bookingForm = document.forms['bookingForm'];
		var cur_date = new Date();
		var date_array = new Array();
		date_array = oDate.split("/");
				
		for(var i=0; i<bookingForm.year.length; i++)
			if (bookingForm.year.options[i].value == date_array[2]) bookingForm.year.selectedIndex = i;
		
		setBook_months(bookingForm);
		bookingForm.month.selectedIndex = date_array[0]-1;
		bookingForm.day.selectedIndex = date_array[1]-1;
		
		closeCalendar();
	}
	
	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: FORMS ============================================================
	function processKey(f) {
	    var keyvalue = window.event.keyCode;
	    if (keyvalue==13) f.submit();
	}
	
	function formError(oMsg, oField) {
		alert(oMsg);
		oField.focus();
	}
	
	function isDate(dateStr, field) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = dateStr.match(datePat);
		
		if (matchArray == null) {
			alert("Please enter a valid "+field+" Date as mm/dd/yyyy.");
			return false;
		}
		
		month = matchArray[1];
		day = matchArray[3];
		year = matchArray[5];
		
		if (month < 1 || month > 12) {
			alert("The "+field+" Date month, must be between 1 and 12.");
			return false;
		}
		if (day < 1 || day > 31) {
			alert("The "+field+" Date day, must be between 1 and 31.");
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("The "+field+" Date month, "+month+" doesn`t have 31 days!")
			return false;
		}
		if (month == 2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				alert("The "+field+" Date February "+year+", doesn`t have "+day+" days!");
				return false;
			}
		}
		
		return true;
	}