function winOpen() 
{
 	window.open('recommend.asp','recomend','width=450,height=350,scrollbars=no,resizable=no,toolbar=no'); 
}
function CreateBookmarkLink() {
	title = document.title; 
	url = location.href;
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

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];}}
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function viewAvailability(goAnchor) {
	var newScreen = window.open(goAnchor,"","alwaysRaised=1,toolbar=0,location=0,status=0,resizable=0,scrollbars=1,menubar=0,width=650,height=450");
  	return false;
}

function ArrivalMonth(theForm, departmonth) {
	var arrivalmonth = theForm.arrivalmonth.options[theForm.arrivalmonth.selectedIndex].value;
	window.location = window.location.pathname + "?departmonth=" + departmonth + "&arrivalmonth=" + escape(arrivalmonth) + "#ski";
}

function DepartMonth(theForm, arrivalmonth) {
	var departmonth = theForm.departmonth.options[theForm.departmonth.selectedIndex].value;
	var arrival = theForm.arrival.options[theForm.arrival.selectedIndex].value;
	if (theForm.arrivalmonth.options[theForm.arrivalmonth.selectedIndex].value=="")	{ 
		alert("Please select your arrival month");
		theForm.arrivalmonth.focus();
		return false; 
	}
	if (theForm.arrival.options[theForm.arrival.selectedIndex].value=="")	{ 
		alert("Please select your arrival date");
		theForm.arrival.focus();
		return false; 
	}  
	window.location = window.location.pathname + "?arrivalmonth=" + arrivalmonth + "&arrival=" + arrival + "&departmonth=" + escape(departmonth) + "#ski";
}

function validateCity(theForm){
	 if (theForm.arrival.options[theForm.arrival.selectedIndex].value=="") { 
		alert("Please select your arrival date");
		return false; 
	 }
	 
	 if (theForm.departdate.options[theForm.departdate.selectedIndex].value=="") { 
	 	alert("Please select your depart date");
	 	return false; 
	 }
	
	var arrdate = new Date(theForm.arrival.value);
	var depardate = new Date(theForm.departdate.value);
	var todayDate = new Date('<%=formatDateTime(date(), vbGeneralDate)%>')	
	
	if (arrdate >= depardate)
	{
	 	alert('The arrival date must be less then the departure date!');
		theForm.arrival.focus();
		return false;
	}
	
	if (todayDate > arrdate)
	{
		alert("The arrival date must be later than today.")
		theForm.arrival.focus();
		return false;	
	}
	
	if (todayDate > depardate)
	{
		alert("The departure date must be later than today.")
		theForm.departdate.focus();
		return false;
	}
	
	//depdate = dateDiff(depardate, arrdate)
	datDate1 = Date.parse(arrdate);
    datDate2 = Date.parse(depardate);
    depdate = Math.round((datDate2-datDate1)/(1000*60*60*24))
	
	maxdiff = 60
	if (depdate > maxdiff)
	{
		alert("The date interval cannot be larger than " + maxdiff +" days. It's " + depdate + " days.")
		theForm.departdate.focus();
		return false;
	}
		
	if (depdate < 3) {
		alert("The minimum length of stay is 3 nights, right now you have only selected " + depdate + " nights.")
		theForm.departdate.focus();
		return false;
	}	
}

function trim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(" " + str + " ");
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
			j++;
		}
            s = s.substring(j, i);
	}

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
			i--;
		}
            s = s.substring(0, i+1);
	}
	return s;
}

function checkContactForm(theForm) {
	var msg = "";
	
	if (trim(theForm.elements['fullname'].value) == "") msg += "\tFull Name\n";
	var femail = trim(theForm.elements['email'].value);
	if (femail == "") {
		msg += "\tEmail Address\n";
	} else {
		var regexpEmail = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		if (regexpEmail.test(femail) == false) {
			msg += "\tBad Email Address Format\n";
		}
	}
	if (trim(theForm.elements['message'].value) == "") msg += "\tMessage\n";
	if (msg != "") {
		alert("These items need attention...\n" + msg);
		return false;
	}
	return true;
}
