function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

// THE FOLLOWING DEVELOPMENT BY: MICHAEL LEAHY - WELK RESORTS WEB SYSTEMS MANAGER
	 
// ============================================================ FUNCTIONS: WINDOW & BROWSER ============================================================
	var popWin = ""; // function:newWindow(oPage, oW, oH, oScroll); close_pops();
	
	function newWindow(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 close_pops() {
		if (navigator.appName.toLowerCase() != "netscape") {
			if (popWin) popWin.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;
		}
	}
	
	// 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: FORMS & DATE ============================================================
	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;
	}
	
	function dateAdd(intval, numb, oDate){
		switch(intval){
			case "M":
				base.setMonth(base.getMonth() + numb);
				break;
			case "YYYY":
				base.setFullYear(base.getFullYear() + numb);
				break;
			case "D":
				base.setDate(base.getDate() + numb);
				break;
			case "H":
				base.setHours(base.getHours() + numb);
				break;
			case "N":
				base.setMinutes(base.getMinutes() + numb);
				break;
			case "S":
				base.setSeconds(base.getSeconds() + numb);
				break;
			default:
		}
		return base
	}
	
// ============================================================ 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:101;">');
				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 = '-70px'; //(get_XYcoordinates(oField+oPos+'_btn_calendar').x-194)+'px';
		div_calendar.style.top = '150px'; //(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);
	}
	
	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;
	}


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 == '');
} }
