// JavaScript by Casper Thun - September-November 2008
var iResultsCount = 0;
var iNoResultsCount = 0;
var iTotalResultsCount = 0;

function alertDebugInfo(text) {
	//ClientDebug is set in ajaxsearchbox.js
	if(ClientDebug){
		alert(text);
	}
}

function checkFHUpsell(fId) {
	if(fId.checked) {
		o1 = document.getElementById('upsellCar');
		o2 = document.getElementById('upsellTransfer');
		if(o1&&o2) {
			if(fId.id.indexOf('Car')>-1) {
				o2.checked=false;
			}else{
				o1.checked=false;
			}
		}
	}
}

function BSChangeSearch(id) {
	oForm = document.forms['frmFlightHotel'];
	oAirportFrom = document.getElementById('idAirportFrom');
	oFlexibility = document.getElementById('idFlexibility');
	oFlexitrip = document.getElementById('SWITCHEDOFF'); //document.getElementById('idFlexitrip');
	oIncludeCarhire = document.getElementById('idIncludeCarHire');
	
	oDuration = document.getElementById('durationFlightHotel');
	oDuration_BYO = document.getElementById('duration_BYO_FlightHotel');
	
	for(x=1;x<4;x++) {
		/*if(document.getElementById('search'+x)){document.getElementById('search'+x).style.display='none';}*/
		if(document.getElementById('SearchText'+x)){document.getElementById('SearchText'+x).style.fontWeight='normal';}
	}
	document.getElementById('SearchText'+id).style.fontWeight='bold';
	if(id==3) {
		oForm.search_type.value='Flight_Hotel';
		if(oAirportFrom){oAirportFrom.style.display='';}
		if(oFlexibility){
			oFlexibility.style.display='';
			document.getElementById('flexibilityFlightHotel').options[1].selected = true;
		}
		if(oFlexitrip){oFlexitrip.style.display='';}
		if(oIncludeCarhire){oIncludeCarhire.style.display='';}
		if(oDuration){
			oDuration.style.display = 'none';
			oDuration.name = 'duration_OFF';
		}
		if(oDuration_BYO){
			oDuration_BYO.style.display = '';
			oDuration_BYO.name = 'duration';
		}
	}else if(id==2){
		oForm.search_type.value='Hotel';
		if(oAirportFrom){oAirportFrom.style.display='none';}
		if(oFlexibility){
			oFlexibility.style.display='none';
		}
		if(oFlexitrip){oFlexitrip.style.display='';}
		if(oIncludeCarhire){oIncludeCarhire.style.display='none';}
		if(oDuration){
			oDuration.style.display = 'none';
			oDuration.name = 'duration_OFF';
		}
		if(oDuration_BYO){
			oDuration_BYO.style.display = '';
			oDuration_BYO.name = 'duration';
		}
	}else{
		oForm.search_type.value='PackageHoliday';
		if(oAirportFrom){oAirportFrom.style.display='';}
		if(oFlexibility){
			oFlexibility.style.display='';
			document.getElementById('flexibilityFlightHotel').options[1].selected = true;
		}
		if(oFlexitrip){oFlexitrip.style.display='none';}
		if(oIncludeCarhire){oIncludeCarhire.style.display='none';}
		//setFlexiTrip(oForm.flexitrip,'FlightHotel');
		if(oDuration_BYO){
			oDuration_BYO.style.display = 'none';
			oDuration_BYO.name = 'duration_OFF';
		}
		if(oDuration){
			oDuration.style.display = '';
			oDuration.name = 'duration';
		}
	}
}

function BSRefineSearch(id, url) {
	for(x=1;x<4;x++) {
		if(document.getElementById('RefineText'+x)){document.getElementById('RefineText'+x).style.fontWeight='normal';}
	}
	if(document.getElementById('RefineText'+id)){document.getElementById('RefineText'+id).style.fontWeight='bold';}
	location.href=url;
}


function setReturnDate(sFormID) {
	oStartDate = document.getElementById('startdate'+sFormID);	
	oDuration = document.getElementById('duration'+sFormID);
	oEndDate = document.getElementById('enddate'+sFormID);
	if(oStartDate&&oDuration&&oEndDate) {
		arStartDate = oStartDate.value.split(' ');
		if(arStartDate.length==3) {
			sDay = arStartDate[0];
			sMonth = arStartDate[1];
			sYear = arStartDate[2];
			oDate = new Date(parseFloat(sYear), parseFloat(getMonthNumber(sMonth)), parseFloat(sDay));
			//var oModifiedDate = new Date(oDate.add("d", parseFloat(oDuration.value)));
			var oModifiedDate = new Date(oDate.setDate(oDate.getDate()+parseFloat(oDuration.value)));
			oEndDate.value = oModifiedDate.getDate()+' '+getProperMonth(oModifiedDate.getMonth()+1)+' '+oModifiedDate.getFullYear();
		}
	}
}

function clearDDL(listElem) {
	if(listElem!=0){
		while(listElem.options.length > 0) {
			listElem.options[0] = null;
		}
		while(listElem.hasChildNodes()) {
			listElem.removeChild(listElem.firstChild);
		}
	}
	listElem.selectedIndex=0;
}

function setFlexiTrip(oCheckbox, sFormID) {
	oDuration = document.getElementById('duration'+sFormID);
	if(oDuration) {
		sCurrentValue = oDuration.value;
		clearDDL(oDuration);
		if(oCheckbox.checked) {
			iSelectedIndex = 0;
			for(x=1;x<31;x++) {
				sText = 'day';
				if(x!=1){sText+='s';}
				oDuration.options[x-1] = new Option(x+' '+sText,x);
				if(parseFloat(sCurrentValue)==x) {
					iSelectedIndex = x-1;
				}
			}
			oDuration.selectedIndex=iSelectedIndex;
		}else{
			oDuration.options[0] = new Option('1 week','7');
			oDuration.options[1] = new Option('2 weeks','14');
			if(parseFloat(sCurrentValue)>11) {
				oDuration.selectedIndex=1;
			}
		}
	}
	setReturnDate(sFormID);
}

function setStartDate(sFormID) {
	oStartDate = document.getElementById('startdate'+sFormID);	
	oDuration = document.getElementById('duration'+sFormID);
	oEndDate = document.getElementById('enddate'+sFormID);
	if(oStartDate&&oDuration&&oEndDate) {
		arEndDate = oEndDate.value.split(' ');
		if(arEndDate.length==3) {
			sDay = arEndDate[0];
			sMonth = arEndDate[1];
			sYear = arEndDate[2];
			oDate = new Date(parseFloat(sYear), parseFloat(getMonthNumber(sMonth)), parseFloat(sDay));
			//var oModifiedDate = new Date(oDate.add("d", parseFloat(oDuration.value)));
			var oModifiedDate = new Date(oDate.setDate(oDate.getDate()-parseFloat(oDuration.value)));
			oStartDate.value = oModifiedDate.getDate()+' '+getProperMonth(oModifiedDate.getMonth()+1)+' '+oModifiedDate.getFullYear();
		}
	}
}


// NOT FINISHED
function getMonthNumber(sMonth) {
	switch(sMonth) {
		case 'January':return 0;break;    
		case 'February':return 1;break;  
		case 'March':return 2;break;  
		case 'April':return 3;break;  
		case 'May':return 4;break; 
		case 'June':return 5;break; 
		case 'July':return 6;break; 
		case 'August':return 7;break; 
		case 'September':return 8;break; 
		case 'October':return 9;break; 
		case 'November':return 10;break; 
		case 'December':return 11;break; 
	}	
}

function getProperMonth(iMonth) {
	switch(parseFloat(iMonth)) {
		case 1:return 'January';break;    
		case 2:return 'February';break;  
		case 3:return 'March';break;  
		case 4:return 'April';break;  
		case 5:return 'May';break; 
		case 6:return 'June';break; 
		case 7:return 'July';break; 
		case 8:return 'August';break; 
		case 9:return 'September';break; 
		case 10:return 'October';break; 
		case 11:return 'November';break; 
		case 12:return 'December';break; 
	}	
}

Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}


function frmBYOSubmitBS(bDoNotSubmit) {
	oFlightLogos = document.getElementById('pleasewaitFlightops');
	if(oFlightLogos && document.frmResults.txtLevel.value.toLowerCase()=='pricing') {
		sSearchType = queryString('search_type');
		if(sSearchType.toLowerCase()=='hotel'){
			sTypeText = 'hotel';
		}else if(sSearchType.toLowerCase()=='car') {
			sTypeText = 'car hire';
		}else{
			sTypeText = 'holiday';
		}
		oFlightLogos.innerHTML = 'We\'re currently bringing back the final details for this '+sTypeText+'.<br />We\'ll be just a moment...';
	}
	div_switch('pleasewaitDivText',false,true);
	div_switch('pleasewaitDivTopText',false,true);
	div_switch('websiteDiv',false,true);
	scroll(0,0);
	div_switch('pleasewaitDiv',true,true);
	if(!bDoNotSubmit){document.frmResults.submit();}
	setTimeout('replaceImages()',100);
	if(typeof exitSurvey=='function' && !bDoNotSubmit){
		exitSurvey(430, 390); 
	}
}
function checkPackageFormBS(sForm) {
	sCurForm = sForm;
	sCurSearchType = 'Package';
	sSubmitForm = document.getElementsByName('frm'+sForm);
	sLocationID = document.getElementById('packageLocationTo'+sForm);
	var e = sSubmitForm.elements, m = '';
	if(countPassengers()>9) {
		alert('You can only search for a maximum of 9 passengers when your search includes a flight');
		return false;
	}
	if(sLocationID.value==''){m += '- Please select a destination.\n';}
	if(validateDate('startdate_d'+sForm,'startdate_m'+sForm,'startdate_y'+sForm)<=2) {m += '- Departure date is not valid.\n';}
	if(m) {
		alert('The following errors occurred:\n\n' + m);
		return false;
	}else{
		return true;
	}	
}

function BSLoadGoogleMap(sDiv, iLat, iLng, iMaximumZoom, iDefaultZoom) {
	if(iDefaultZoom == undefined){
		iDefaultZoom = 9;
	}
	if(document.getElementById(sDiv)) {
		sDiv = document.getElementById(sDiv)
		if (GBrowserIsCompatible()) {
			var mygmap = new GMap2(sDiv);
			//map.addControl(new YSliderControl());
			mygmap.addControl(new GLargeMapControl());
    		mygmap.addControl(new GMapTypeControl());
			//mygmap.removeMapType(type)
			mygmap.addMapType(G_PHYSICAL_MAP)
			mygmap.setMapType(G_PHYSICAL_MAP);
			for(xxx=0;xxx<mygmap.getMapTypes().length;xxx++) {
				mygmap.getMapTypes()[xxx].getMinimumResolution = function(){return 2};
				if(iMaximumZoom) {
					mygmap.getMapTypes()[xxx].getMaximumResolution = function(){return iMaximumZoom}; 	
				}
			}
			mygmap.setCenter(new GLatLng(iLat, iLng), iDefaultZoom);
			var point = new GLatLng(iLat,iLng);
			mygmap.addOverlay(new GMarker(point));
		}
	}
}


function getSyncXML(url) {
	if (window.XMLHttpRequest) {              
		SyncDOM=new XMLHttpRequest();              
	} else {                                  
		SyncDOM=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (SyncDOM) {
		if(bDebug){
			var timestamp = new Date();
			if(url.indexOf('?')>-1) {
				url	= url+'&'+timestamp;
			}else{
				url	= url+'?'+timestamp;
			}
		}
		SyncDOM.open("GET", url, false);                             
		SyncDOM.send(null);
		if (SyncDOM.readyState == 4 && SyncDOM.status == 200) {
			return SyncDOM.responseXML.documentElement;
		}
	} else {
		return false;
	}   
}

function validateMSHEditDetailsSkiType(fId) {
	var e = '';
	bChecked = false;
	o1 = document.getElementsByName('typeofskier');
	for(x=0;x<o1.length;x++){
		if(o1[x].checked) {
			bChecked = true;
		}
	}
	if(!bChecked){e+='- Please select at least one type of skier\n'}
	if(e){
		alert(e);
		return false;
	}
}

function validateMSHEditDetails(fId) {
	var e = '';
	if(!fId.name.value){e+='- Please enter your name\n';}
	if(fId.password.value.length < 6 || fId.password.value.indexOf(' ') > -1){
		e+='- Please enter a password containing at least 6 characters (Spaces not allowed)\n';
	}else if(fId.password.value!=fId.password2.value){
		e+='- Confirmed password and password doesn\'t match\n';
	}
	if(!fId.Address.value){e+='- Please enter the first line of your address\n';}
	if(!fId.CityName.value){e+='- Please enter your town/city\n';}
	if(!fId.County.value){e+='- Please enter your county/state\n';}
	if(!fId.PostCode.value){e+='- Please enter your postcode/zip\n';}
	if(!fId.Country.value){e+='- Please enter your country\n';}
	if(!CTisDate(fId.dob_d.value+'/'+fId.dob_m.value+'/'+fId.dob_y.value)){e+='- Please enter your correct birth date\n';}
	if(e) {
		alert(e);
		return false;
	}
}

function validateEnquiryBS(fId) {
	var e = '';
	if(!fId.title.value){e+='- Please select your title\n';}
	if(!fId.firstname.value){e+='- Please enter your first name\n';}
	if(!fId.surname.value){e+='- Please enter your surname\n';}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter a valid email address\n'}
	if(!fId.telephone.value){e+='- Please enter your telephone number\n';}
	if(!fId.budget.value){e+='- Please select your budget\n';}
	if(!fId.preferences.value){e+='- Please select your skiing preferences\n';}
	/*bRequestBrochure = false;
	oRadars = document.getElementsByName('brochurerequest');
	if(oRadars[0].checked) {
		if(!fId.Address.value || fId.Address.value=='- Address line 1 -'){e+='- Please enter the first line of your address\n';}
		if(!fId.CityName.value){e+='- Please enter your town/city name\n';}
		if(!fId.County.value){e+='- Please enter your county name\n';}
		if(!fId.PostCode.value){e+='- Please enter your post code\n';}
	}*/
	if(e) {
		alert(e);
		showHolidayInfo();
		return false;
	}
	if(fId.Locality.value=='- Address line 2 -') {
		fId.Locality.value='';
	}
}

function validateEnquiry_CompBS(fId) {
	var e = '';
	//if(!fId.title.value){e+='- Please select your title\n';}
	//if(!fId.firstname.value){e+='- Please enter your first name\n';}
	//if(!fId.surname.value){e+='- Please enter your surname\n';}
	
	if(fId.Email_Recommended.value != ''){
	    if(!/.+@[^.]+(\.[^.]+)+/.test(fId.Email_Recommended.value) || isValidField(fId.Email_Recommended.value,2) == false){e+='- Please enter a valid email address\n'}
	}
	//if(!fId.telephone.value){e+='- Please enter your telephone number\n';}
	
	bChecked = false;
	//o1 = document.getElementsByName('question');
	//for(x=0;x<o1.length;x++){
		//if(o1[x].checked) {
		//	bChecked = true;
		//}
	//}
	
	//if(fId.Email_Recommended){
	//	if(fId.Email_Recommended.value == fId.email.value){
	//		e+='- Please make sure your email address is different to the recommended address!\n';
	//	}
	//}
	
	//if(!bChecked){e+='- Please select an answer!\n'}
	if(!fId.readterms.checked){e+='- Please ensure you have read and understood our terms and conditions\n';}

	if(e) {
		alert(e);
		return false;
	}
}

// Used in the contact form becuase you can't do basic javascript on an href.
function showHolidayInfo() {
	document.getElementById('tdHolidayInfo').style.display='none';
	document.getElementById('tbHolidayInfo').style.display='';
}

function validateRequestBrochure(fId) {
	var e = '';
	if(!fId.title.value){e+='- Please select your title\n';}
	if(!fId.firstname.value){e+='- Please enter your first name\n';}
	if(!fId.surname.value){e+='- Please enter your surname\n';}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter a valid email address\n'}
	if(!fId.telephone.value){e+='- Please enter your telephone number\n';}
	if(!fId.Address.value || fId.Address.value=='- Address line 1 -'){e+='- Please enter the first line of your address\n';}
	if(!fId.CityName.value){e+='- Please enter your town/city name\n';}
	if(!fId.County.value){e+='- Please enter your county name\n';}
	if(!fId.PostCode.value){e+='- Please enter your post code\n';}
	
	if(e) {
		alert(e);
		return false;
	}
	if(fId.Locality.value=='- Address line 2 -') {
		fId.Locality.value='';
	}

}



function validateSendToFriends(fId) {
	var e = '';
	if(!fId.name.value){e+='- Please enter your name\n';}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter your valid email address\n'}
	bEmailsEntered = false;
	oFriends = document.getElementsByName('friend');
	if(oFriends) {
		for(x=0;x<oFriends.length;x++) {
			if(oFriends[x].value) {
				bEmailsEntered = true;
				if(!/.+@[^.]+(\.[^.]+)+/.test(oFriends[x].value) || isValidField(oFriends[x].value,2) == false){
					e+='- Please enter a valid email address for friend '+parseFloat(x+1)+'\n'
				}
			}
		}
	}
	if(!bEmailsEntered){e+='- Please enter at least 1 friends email address\n'}
	if(e) {
		alert(e);
		return false;
	}
}

function validateMSHReminder(fId) {
	var e = '';
	if(!fId.email.value||!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter a valid email address\n'}
	if(e) {
		alert(e);
		return false;	
	}
}

function validateMSHLogin(fId) {
	var e = '';
	if(!fId.email.value||!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter a valid email address\n'}
	if(!fId.password.value){e+='- Please enter a password\n'}
	if(e) {
		alert(e);
		return false;	
	}
}


function validateMSHSignup(fId) {
	var e = '';
	if(!fId.email.value||!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false){e+='- Please enter a valid email address\n'}
	if(fId.password.value.length < 6 || fId.password.value.indexOf(' ') > -1){
		e+='- Please enter a password containing at least 6 characters (Spaces not allowed)\n';
	}else if(fId.password.value!=fId.confirmpassword.value){
		e+='- Confirmed password and password doesn\'t match\n';
	}
	if(!fId.captchacode.value){e+='- Please enter the verification code\n';}
	if(e) {
		alert(e);
		return false;	
	}
}

var SelectedResultTab = 'result_tab1';
function SwitchResult2(id, bIgnoreFunctions) {
	div_switch('ResultContent',true, true);
	div_switch('ShortlistContent',false, true);
	div = document.getElementById(id);
	if(Right(div.className,2)!='Na') {
		for(x=1;x<8;x++) {
			if(document.getElementById('result_tab'+x)) {
				if(Right(document.getElementById('result_tab'+x).className,2)!='Na'){
					document.getElementById('result_tab'+x).className = 'resulttab';
				}
			}
			if(document.getElementById('result_div'+x)) {
				document.getElementById('result_div'+x).style.display = 'none';
			}
		}
		SelectedResultTab = id;
		if(document.getElementById(id)) {
			document.getElementById(id).className = 'resulttabOver';
			
		}
		if(document.getElementById('result_div'+Right(id,1))) {
			document.getElementById('result_div'+Right(id,1)).style.display = '';
			document.getElementById('result_div'+Right(id,1)).innerHTML = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Checking availability - Please wait...</div>';
		}
	}
}

var LoadingAnimationStartInterval;
function LoadingAnimationStart(iSpeed, iPosition) {
	iBoxLength = 34;
	if(!iPosition){iPosition=0;}
	ox1 = document.getElementById('labox1');
	ox2 = document.getElementById('labox2');
	ox3 = document.getElementById('labox3');
	if(ox1&&ox2&&ox3) {
		ox1.style.visibility='hidden';ox2.style.visibility='hidden';ox3.style.visibility='hidden';
		iCurrentPosition = (iPosition * iBoxLength) - iBoxLength * 3;
		ox1.style.left=iCurrentPosition+'px';
		ox2.style.left=iCurrentPosition+'px';
		ox3.style.left=iCurrentPosition+'px';
		if(iCurrentPosition>=parseFloat('-'+parseFloat(iBoxLength*2)) && iCurrentPosition < parseFloat(iBoxLength*6)){ox3.style.visibility='visible';}
		if(iCurrentPosition>=parseFloat('-'+iBoxLength) && iCurrentPosition < parseFloat(iBoxLength*7)){ox2.style.visibility='visible';}
		if(iCurrentPosition>=0 && iCurrentPosition < parseFloat(iBoxLength*8)){ox1.style.visibility='visible';}
		
		if(iCurrentPosition>=0 && iCurrentPosition > parseFloat(iBoxLength*7)) {
			//LoadingAnimationStartInterval = setTimeout('LoadingAnimationStart('+iSpeed+',\'\')',parseFloat(iSpeed*1.5));	
		}else{
			//LoadingAnimationStartInterval = setTimeout('LoadingAnimationStart('+iSpeed+','+parseFloat(iPosition+1)+')',iSpeed);
		}
	}
}
function LoadingAnimationStop() {
	clearTimeout(LoadingAnimationStartInterval);
	clearTimeout(hotTipTimeout);
}

var LMSurl = '';
var LMSFromTop, LMSFromLeft;
function LMSMoreInfo(sAction, sValues, bFromTop, bFromLeft){
	if(bFromTop){
		LMSFromTop = true;	
	}else{
		LMSFromTop = false;	
	}
	if(bFromLeft){
		LMSFromLeft = true;	
	}else{
		LMSFromLeft = false;	
	}
	if(document.getElementById('divMoreInfo')) {
		PlaceHolder = document.getElementById('divMoreInfo');
		FramePlaceHolder = document.getElementById('frameMoreInfo');
		if(!sAction) {
			LMSurl = location.href;
			grayOut(true);
			FramePlaceHolder.style.display='block';
			PlaceHolder.style.display='block';
			if(bFromLeft) {
				FramePlaceHolder.style.left = MouseXPosition+'px';
				PlaceHolder.style.left = MouseXPosition+'px';

			}else{
				FramePlaceHolder.style.left = MouseXPosition-205+'px';
				PlaceHolder.style.left = MouseXPosition-205+'px';
			}
			if(bFromTop) {
				FramePlaceHolder.style.top = MouseYPosition+24+'px';
				PlaceHolder.style.top = MouseYPosition+24+'px';
			}else{
				FramePlaceHolder.style.top = MouseYPosition-250+'px';
				PlaceHolder.style.top = MouseYPosition-250+'px';
			}
		}
		var dTemp = new Date();
		PlaceHolder.innerHTML = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Please wait...</div>';
		sURL = "/includes/lastminuteskiing/more.asp?action=" + sAction + "&test=casptae&time=" + dTemp + "&values=" + sValues
		if(sURL!='') {
			if(bDebug) {
				if(confirm('Open '+ sURL)) {
					window.open(sURL);
				}
			}
			setTimeout("loadLMSDoc('"+sURL+"')", 500);
		}else{
			alert('No url defined');	
		}
	}
}
function CloseLMS() {
	if(document.getElementById('divMoreInfo')) {
		FramePlaceHolder = document.getElementById('frameMoreInfo');
		FramePlaceHolder.style.display='none';
		PlaceHolder = document.getElementById('divMoreInfo');
		PlaceHolder.style.display='none';
		grayOut(false);
	}
}

function loadLMSDoc(url) {
    // branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
        reqLMS = new XMLHttpRequest();
		reqLMS.onreadystatechange = processLMS;
        reqLMS.open("GET", url, true);
        reqLMS.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        reqLMS = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqLMS) {
            reqLMS.onreadystatechange = processLMS;
            reqLMS.open("GET", url, true);
            reqLMS.send();
        }
    }
}
function processLMS() {
	if (reqLMS.readyState == 4) {
		if (reqLMS.status == 200){
			PlaceHolder = document.getElementById('divMoreInfo');
			PlaceHolder.innerHTML = reqLMS.responseText;
		}
	}
}
var DestinationMap_Data, DestinationMap_General
function LoadDestinationGoogleMap() {
	inputGeneral = document.getElementById('DestinationMap_General');
	if(inputGeneral) {
		if(inputGeneral.value) {
			DestinationMap_General = inputGeneral.value;
		}
	}
	inputData = document.getElementById('DestinationMap_Data');
	if(inputData) {
		if(inputData.value) {
			DestinationMap_Data = inputData.value;
		}
	}
	if(DestinationMap_General) {
		arGeneral = DestinationMap_General.split('|');
		if(arGeneral.length>4) {
			divGoogle = document.getElementById(arGeneral[0]);
			sGeneralLat = arGeneral[1];
			sGeneralLng = arGeneral[2];
			iGeneralZoom = arGeneral[3];
			iGeneralMaxZoom = arGeneral[4];
			iGeneralMinZoom = arGeneral[5];
			if(!iGeneralZoom){iGeneralZoom=8;}
		}
		if(divGoogle && sGeneralLat && sGeneralLng) {
			var pinIcon = new GIcon();
			pinIcon.image = "/images/icons/googlemap_pin.png"
			pinIcon.iconSize = new GSize(14, 21);
			pinIcon.iconAnchor = new GPoint(13, 20);
			pinIcon.infoWindowAnchor = new GPoint(4, 3);
			
			var hotelIcon = new GIcon();
			hotelIcon.image = "/images/icons/googlemap_hotel.png"
			hotelIcon.iconSize = new GSize(24, 25);
			hotelIcon.iconAnchor = new GPoint(12, 12);
			hotelIcon.infoWindowAnchor = new GPoint(12, 2);
			var skiliftIcon = new GIcon();
			skiliftIcon.image = "/images/icons/googlemap_skilift.png"
			skiliftIcon.iconSize = new GSize(32, 32);
			skiliftIcon.iconAnchor = new GPoint(16, 16);
			skiliftIcon.infoWindowAnchor = new GPoint(23, 6);
			var airportIcon = new GIcon();
			airportIcon.image = "/images/icons/googlemap_airport.png"
			airportIcon.iconSize = new GSize(32, 32);
			airportIcon.iconAnchor = new GPoint(16, 16);
			airportIcon.infoWindowAnchor = new GPoint(16, 3);
		
			function createMarker(point, type, html) {
				if(type=='hotel') {
					var marker = new GMarker(point, hotelIcon);
				}else if(type=='skilift'){
					var marker = new GMarker(point, skiliftIcon);
				}else if(type=='pin'){
					var marker = new GMarker(point, pinIcon);
				}else if(type=='airport'){
					var marker = new GMarker(point, airportIcon);
				}else{
					var marker = new GMarker(point);
				}
				//marker.image = "/images/icons/googlemap_"+type+".png";
				GEvent.addListener(marker, "click", function() {
					if(html) {
						sHTML = html;
						marker.openInfoWindowHtml(sHTML);
					}
				});
				return marker;
			}
			var map = new GMap2(divGoogle);
			map.addControl(new GLargeMapControl());
    		map.addControl(new GMapTypeControl());
			map.addMapType(G_PHYSICAL_MAP)
			map.setMapType(G_PHYSICAL_MAP)
			for(xxx=0;xxx<map.getMapTypes().length;xxx++) {
				if(iGeneralMinZoom) {
					map.getMapTypes()[xxx].getMinimumResolution = function(){return parseFloat(iGeneralMinZoom)};
				}
				if(iGeneralMaxZoom) {
					map.getMapTypes()[xxx].getMaximumResolution = function(){return parseFloat(iGeneralMaxZoom)}; 	
				}
			}
			
			var maxLon='';
			var minLon='';
			var maxLat='';
			var minLat='';
			
			map.setCenter(new GLatLng(sGeneralLat,sGeneralLng), parseFloat(iGeneralZoom));
			if(DestinationMap_Data) {
				arData = DestinationMap_Data.split('###');
				for(xy=0;xy<arData.length;xy++) {
					arSingleData = arData[xy].split('|');
					if(arSingleData.length>2) {
						sLat = arSingleData[0];
						sLng = arSingleData[1];
						if(!maxLon||parseFloat(sLng)>parseFloat(maxLon)){
							maxLon = sLng
						}
						if(!minLon||parseFloat(sLng)<parseFloat(minLon)){
							minLon = sLng
						}
						if(!maxLat||parseFloat(sLat)>parseFloat(maxLat)){
							maxLat = sLat
						}
						if(!minLat||parseFloat(sLat)<parseFloat(minLat)){
							minLat = sLat
						}
						sType = arSingleData[2];
						sContent = arSingleData[3];
						var point = new GLatLng(sLat,sLng);
						map.addOverlay(createMarker(point, sType, sContent));
					}
				}
				var sw = new GLatLng(maxLat, minLon);
                var ne = new GLatLng(minLat, maxLon);
				var bounds = new GLatLngBounds(sw, ne);
				level  = map.getBoundsZoomLevel(bounds);
				//map.setCenter(new GLatLng(0.5*minLat+0.5*maxLat, 0.5*minLon+0.5*maxLon),level); 
			}
		}
	}
}

function showHidePasswordReminder() {
	o1 = document.getElementById('loginPasswordReminder');
	o2 = document.getElementById('loginGeneral');
	if(o1&&o2) {
		if(o1.style.display=='') {
			o1.style.display='none';
			o2.style.display='';
		}else{
			o1.style.display='';
			o2.style.display='none';
		}
	}
}

function MSHopenCloseDiv(id, text) {
	o1 = document.getElementById(id);
	o2 = document.getElementById(text);
	if(o1&&o2) {
		if(o1.style.display=='none') {
			o1.style.display='';
			o2.innerHTML = 'Hide';
		}else{
			o1.style.display='None';
			o2.innerHTML = 'View all';
		}
	}
}

function changeResortInfoContent(TabID) {
	oTotal = document.getElementById('ResortInfoContentCount');
	if(oTotal) {
		for(x=0;x<31;x++){
			if(document.getElementById('InfoTab' + x)){
				document.getElementById('InfoTab' + x).className = 'TabOFF';	
				document.getElementById('InfoContent' + x).className = 'ContentOFF';	
			}
		}
		document.getElementById('InfoTab' + TabID).className = 'TabON';	
		document.getElementById('InfoContent' + TabID).className = 'ContentON';	
		if(parseFloat(TabID)==parseFloat(oTotal.value)) {
			document.getElementById('InfoTab' + TabID).style.borderBottom='none';
		}
	}
}

function CTdivSwitch(id) {
	o1 = document.getElementById(id);
	if(o1) {
		if(o1.style.display=='') {
			o1.style.display='none';
		}else{
			o1.style.display='';
		}
	}
}

function BJDivSwitch(objToSwitch, objToHide) {
	CTdivSwitch(objToSwitch); 
	document.getElementById(objToHide).style.display = 'none';	
}

function GoToSelectOption(fId) {
	if(fId.value){
		location.href=fId.value;
	}
}

/* START RESORT CHOOSE */
	var RCurl = '';
	var RCValues = '';
	var RCx, RCy;
	function ResortChooser(sAction, sValues, iX, iY) {
		if(sValues){
			RCValues = sValues;	
		}
		if(!iX){iX=0}
		if(!iY){iY=0}
		if(document.getElementById('divResortChooser')) {
			PlaceHolder = document.getElementById('divResortChooser');
			FramePlaceHolder = document.getElementById('frameResortChooser');
			if(!sAction) {
				RCurl = location.href;
				grayOut(true);
				FramePlaceHolder.style.display='block';
				PlaceHolder.style.display='block';
				
				/*FramePlaceHolder.style.left = parseFloat(MouseXPosition-350+iX)+'px';
				PlaceHolder.style.left = parseFloat(MouseXPosition-350+iX)+'px';
				
				FramePlaceHolder.style.top = parseFloat(MouseYPosition-350+iY)+'px';
				PlaceHolder.style.top = parseFloat(MouseYPosition-350+iY)+'px';*/
				var iFromTop = parseFloat(((document.documentElement.clientHeight-350)/2)+document.documentElement.scrollTop);
				if(iFromTop<10){iFromTop=10;}
				FramePlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-350)/2)+'px';
				PlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-350)/2)+'px';
				FramePlaceHolder.style.top = iFromTop+'px';
				PlaceHolder.style.top = iFromTop+'px';
				
			}
			PlaceHolder.innerHTML = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Please wait...</div>';
			sURL = "/myskiingholidays/includes/chooseresorts.asp?action=" + sAction;
			if(sURL!='') {
				if(bDebug) {
					if(confirm('Open '+ sURL)) {
						window.open(sURL);
					}
				}
				setTimeout("loadRCDoc('"+sURL+"')", 500);
			}else{
				alert('No url defined');	
			}
		}
	}
	
	function CloseRC() {
		if(document.getElementById('divResortChooser')) {
			FramePlaceHolder = document.getElementById('frameResortChooser');
			FramePlaceHolder.style.display='none';
			PlaceHolder = document.getElementById('divResortChooser');
			PlaceHolder.style.display='none';
			grayOut(false);
		}
	}
	
	function loadRCDoc(url) {
		// branch for native XMLHttpRequest object
		sPostValues = RCValues
		if (window.XMLHttpRequest) {
			reqTAF = new XMLHttpRequest();
			reqTAF.onreadystatechange = processRC;
			reqTAF.open("POST", url, true);
			reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			reqTAF.setRequestHeader("Content-length", sPostValues.length);
			reqTAF.setRequestHeader("Connection", "close");
			reqTAF.send('resorts='+sPostValues);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			reqTAF = new ActiveXObject("Microsoft.XMLHTTP");
			if (reqTAF) {
				reqTAF.onreadystatechange = processRC;
				reqTAF.open("POST", url, true);
				reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				reqTAF.setRequestHeader("Content-length", sPostValues.length);
				reqTAF.setRequestHeader("Connection", "close");
				reqTAF.send('resorts='+sPostValues);
			}
		}
	}
	function processRC() {
		if (reqTAF.readyState == 4) {
			if (reqTAF.status == 200){
				PlaceHolder = document.getElementById('divResortChooser');
				PlaceHolder.innerHTML = reqTAF.responseText;
			}
		}
	}
	
	function SubmitRC(oFrm) {
		var e='';
		var string='';
		o1 = document.getElementsByName('chooseresort');
		for(x=0;x<o1.length;x++) {
			if(o1[x].checked){
				string+=o1[x].value+',';
			}
		}
		ResortChooser('chooseresorts',string);
		return false;
	}
	

/* END RESORT CHOOSE */


var LightBoxurl = '';
var LightBoxValues = '';
var LightBoxx, LightBoxy;
var LB_Object = '';

/* START LIGHTBOX */
	function LightBox(sAction, sValues, iX, iY, ObjectID, sURL, iWidth, iHeight) {
		LB_Object = ObjectID;
		if(sValues){
			LightBoxValues = sValues;	
		}
		if(!iX){iX=0}
		if(!iY){iY=0}
		if(document.getElementById('div' + LB_Object)) {
			PlaceHolder = document.getElementById('div' + LB_Object);
			FramePlaceHolder = document.getElementById('frame' + LB_Object);
			if(!sAction) {
				LightBoxurl = location.href;
				grayOut(true);
				FramePlaceHolder.style.display='block';
				PlaceHolder.style.display='block';
				FramePlaceHolder.style.border='none';
				
				/*FramePlaceHolder.style.left = parseFloat(MouseXPosition-iWidth+iX)+'px';
				PlaceHolder.style.left = parseFloat(MouseXPosition-iWidth+iX)+'px';
				
				FramePlaceHolder.style.top = parseFloat(MouseYPosition-iHeight / 2 +iY)+'px';
				PlaceHolder.style.top = parseFloat(MouseYPosition-iHeight / 2 +iY)+'px';*/
				
				var iFromTop = parseFloat(((document.documentElement.clientHeight-iHeight)/2)+document.documentElement.scrollTop);
				if(iFromTop<10){iFromTop=10;}
				
				FramePlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-iWidth)/2)+'px';
				PlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-iWidth)/2)+'px';
				FramePlaceHolder.style.top = iFromTop+'px';
				PlaceHolder.style.top = iFromTop+'px';
				
				
				if(iWidth != ''){
					FramePlaceHolder.style.height = iHeight+'px';
					PlaceHolder.style.height = iHeight+'px';
					FramePlaceHolder.style.width = iWidth+'px';
					PlaceHolder.style.width = iWidth+'px';
				}
			}
			PlaceHolder.innerHTML = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Please wait...</div>';
			if(sURL!='') {
				if(bDebug) {
					if(confirm('Open '+ sURL)) {
						window.open(sURL);
					}
				}
				setTimeout("loadLightBoxDoc('"+sURL+"')", 500);
			}else{
				alert('No url defined');	
			}
		}
	}
	
	function CloseLightBox() {
		if(document.getElementById('div' + LB_Object)) {
			FramePlaceHolder = document.getElementById('frame' + LB_Object);
			document.getElementById('div' + LB_Object).innerHTML = '';
			FramePlaceHolder.style.display='none';
			PlaceHolder = document.getElementById('div' + LB_Object);
			PlaceHolder.style.display='none';
			grayOut(false);
		}
	}
	
	function loadLightBoxDoc(url) {
		// branch for native XMLHttpRequest object
		sPostValues = LightBoxValues
		url = '/includes/lightbox.asp?content=' + url;
		if (window.XMLHttpRequest) {
			reqTAF = new XMLHttpRequest();
			reqTAF.onreadystatechange = processLightBox;
			reqTAF.open("POST", url, true);
			reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			reqTAF.setRequestHeader("Content-length", sPostValues.length);
			reqTAF.setRequestHeader("Connection", "close");
			reqTAF.send('resorts='+sPostValues);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			reqTAF = new ActiveXObject("Microsoft.XMLHTTP");
			if (reqTAF) {
				reqTAF.onreadystatechange = processLightBox;
				reqTAF.open("POST", url, true);
				reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				reqTAF.setRequestHeader("Content-length", sPostValues.length);
				reqTAF.setRequestHeader("Connection", "close");
				reqTAF.send('resorts='+sPostValues);
			}
		}
	}
	function processLightBox() {
		if (reqTAF.readyState == 4) {
			if (reqTAF.status == 200){
				PlaceHolder = document.getElementById('div' + LB_Object);
				PlaceHolder.innerHTML = reqTAF.responseText;
			}
		}
	}
	
	function SubmitLightBox(oFrm) {

	}
	

/* END LIGHTBOX */
/* START WRITE A REVIEW */
	var Review_CurrentResortID;
	function WriteAReview(id, iX, iY) {
		Review_CurrentResortID = id;
		if(!iX){iX=0}
		if(!iY){iY=0}
		if(document.getElementById('divWriteAReview')) {
			PlaceHolder = document.getElementById('divWriteAReview');
			FramePlaceHolder = document.getElementById('frameWriteAReview');
			grayOut(true);
			FramePlaceHolder.style.display='block';
			PlaceHolder.style.display='block';
			
			/*FramePlaceHolder.style.left = parseFloat(MouseXPosition-475+iX)+'px';
			FramePlaceHolder.style.top = parseFloat(MouseYPosition-710+iY)+'px';
			
			PlaceHolder.style.left = parseFloat(MouseXPosition-475+iX)+'px';
			PlaceHolder.style.top = parseFloat(MouseYPosition-710+iY)+'px';*/
			
			var iFromTop = parseFloat(((document.documentElement.clientHeight-572)/2)+document.documentElement.scrollTop);
			if(iFromTop<10){iFromTop=10;}
			
			FramePlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-475)/2)+'px';
			PlaceHolder.style.left = parseFloat((document.documentElement.clientWidth-475)/2)+'px';
			FramePlaceHolder.style.top = iFromTop+'px';
			PlaceHolder.style.top = iFromTop+'px';

			
			PlaceHolder.innerHTML = '<a name="WARTop"></a><div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Please wait...</div>';
			sURL = "/includes/reviews/addreview.asp?id="+id+"&returnurl="+encodeURI(window.location.href.replace('?e=reviewadded','').replace(/&/g,'|'));
			if(sURL!='') {
				if(bDebug) {
					if(confirm('Open '+ sURL)) {
						window.open(sURL);
					}
				}
				setTimeout("loadWARDoc('"+sURL+"')", 500);
			}else{
				alert('No url defined');	
			}
		}
	}
	
	function CloseWAR() {
		if(document.getElementById('divWriteAReview')) {
			FramePlaceHolder = document.getElementById('frameWriteAReview');
			FramePlaceHolder.style.display='none';
			PlaceHolder = document.getElementById('divWriteAReview');
			PlaceHolder.style.display='none';
			grayOut(false);
		}
	}
	
	function loadWARDoc(url) {
		// branch for native XMLHttpRequest object
		sPostValues = RCValues
		if (window.XMLHttpRequest) {
			reqTAF = new XMLHttpRequest();
			reqTAF.onreadystatechange = processWAR;
			reqTAF.open("POST", url, true);
			reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			reqTAF.setRequestHeader("Content-length", sPostValues.length);
			reqTAF.setRequestHeader("Connection", "close");
			reqTAF.send('resorts='+sPostValues);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			reqTAF = new ActiveXObject("Microsoft.XMLHTTP");
			if (reqTAF) {
				reqTAF.onreadystatechange = processWAR;
				reqTAF.open("POST", url, true);
				reqTAF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				reqTAF.setRequestHeader("Content-length", sPostValues.length);
				reqTAF.setRequestHeader("Connection", "close");
				reqTAF.send('resorts='+sPostValues);
			}
		}
	}
	function processWAR() {
		if (reqTAF.readyState == 4) {
			if (reqTAF.status == 200){
				PlaceHolder = document.getElementById('divWriteAReview');
				PlaceHolder.innerHTML = reqTAF.responseText;
			}
		}
	}
	

/* END WRITE A REVIEW*/
/* START RATING */
	function Rating_MouseOver(id, imgid, isclick) {
		o2 = parseFloat(document.getElementById('ratingvalue_'+id).value); //eval('Rating'+id+'_Min');
		o3 = document.getElementById('ratingtext_'+id);
		if(imgid>o2) {
			for(x=1;x<11;x++) {
				o1 = document.getElementById('ratingimg_'+id+'_'+x);
				if(o1) {
					if(imgid>=x) {
						o1.src = '/images/starrating/flake.gif';
					}else{
						o1.src = '/images/starrating/flake_none.gif';
					}
				}
			}
			o3.innerHTML=imgid;
		}

	}
	function Rating_MouseOut(id) {
		o2 = parseFloat(document.getElementById('ratingvalue_'+id).value);
		for(x=1;x<11;x++) {
			o1 = document.getElementById('ratingimg_'+id+'_'+x);
			if(o1 && x > o2) {
				o1.src = '/images/starrating/flake_none.gif';
			}
		}
		o3 = document.getElementById('ratingtext_'+id);
		if(o3){
			o3.innerHTML=o2;
		}
	}
	function Rating_MouseClick(id, imgid) {
		o1 = document.getElementById('ratingvalue_'+id);
		if(o1) {
			o1.value=imgid;	
		}
		Rating_MouseOut(id);
	}
	function Rating_ShowHideItem(id) {
		o1 = document.getElementById('rating_'+id);
		o2 = document.getElementById('rating_nachecked'+id);
		if(o1&&o2) {
			if(o2.checked) {
				o1.style.display='none';
			}else{
				o1.style.display='';
			}
		}
	}
	function Rating_AddValidate(fId) {
		var sAction = document.getElementById('review_action').value;
		var e = '';
		if(!fId.review_subject.value){e+='- Please enter a review subject\n';}
		bEverythingRated = true;
		o1 = document.getElementsByTagName('input');
		var iCount = 0
		for(x=0;x<o1.length;x++) {
			if(o1[x].name.indexOf('rating_nachecked_')>-1) {
				iCount++;
				if(!o1[x].checked) {
					arInput = o1[x].name.split('_');
					iInputID = parseFloat(arInput[2]);
					o2 = document.getElementsByName('reviewvalue_'+iInputID);
					if(o2.length>0) {
						if(parseFloat(o2[0].value)==0) {
							if((sAction=='step2'&&iCount<=7)||sAction!='step2') {
								bEverythingRated = false;
							}
						}
					}
				}
			}
		}
		if(!bEverythingRated){e+='- Please ensure all ratings are entered before submitting\n'}
		if(!fId.review_comments.value.replace(/ /g,'').replace(/\n/g,'')){e+='- Please enter overall comments\n';}
		if(!fId.review_month.value||!fId.review_year.value){e+='- Please enter the dates you stayed at the resort\n';}
		if(!fId.rating_terms.checked){e+='- Please confirm that you have read and understood our terms and conditions\n';}
		if(e){
			alert(e);
			return false;
		}else{
			if(sAction=='step2') {
				oLogin = document.getElementById('review_login');
				if(oLogin){
					div_switch('review_step1',false,true);
					div_switch('review_login',true,true);
					return false;
				}else{
					Rating_Step2();
					return false;	
				}
			}
		}
	}
	function Rating_Step2() {
		FramePlaceHolder = document.getElementById('frameWriteAReview');
		PlaceHolder = document.getElementById('divWriteAReview');
		sNewTop = parseFloat(PlaceHolder.style.top.replace('px',''))+130+'px';
		sNewHeight = parseFloat(PlaceHolder.offsetHeight-168)+'px';
		PlaceHolder.style.height=sNewHeight;
		FramePlaceHolder.style.height=sNewHeight;
		PlaceHolder.style.top=sNewTop;
		FramePlaceHolder.style.top=sNewTop;
		document.getElementById('review_action').value = 'add';
		div_switch('review_step1',false,true);
		div_switch('review_login',false,true);
		div_switch('review_step2',true,true);	
	}
	function WARSubmitStep1Only() {
		document.getElementById('review_action').value = 'add_step1only';
		document.frmAddReview.submit();
	}
/* END RATING */
function MSH_AddReviewNewUser() {
	email = document.getElementById('MSH_NewUser_Email').value;
	password = document.getElementById('MSH_NewUser_Password').value;
	password2 = document.getElementById('MSH_NewUser_Password2').value;
	captcha = document.getElementById('MSH_NewUser_Captcha').value;
	var e = '';
	if(!email||!/.+@[^.]+(\.[^.]+)+/.test(email) || isValidField(email,2) == false){e+='- Please enter a valid email address\n'}
	if(password.length < 6 || password.indexOf(' ') > -1){
		e+='- Please enter a password containing at least 6 characters (Spaces not allowed)\n';
	}else if(password!=password2){
		e+='- Confirmed password and password doesn\'t match\n';
	}
	if(!captcha){e+='- Please enter the verification code\n';}
	if(e) {
		alert(e);
	}else{
		sURL = '/myskiingholidays/includes/reviews_newuser.asp?email='+encodeURI(email)+'&password='+encodeURI(password)+'&captcha='+encodeURI(captcha)+'&resortid='+Review_CurrentResortID;;
		var sResponse = readFile(sURL);
		if(window.DOMParser) {
			var parser=new DOMParser();
			var XMLDocTemp=parser.parseFromString(sResponse,"text/xml");
		}else{
			var XMLDocTemp=new ActiveXObject("Microsoft.XMLDOM");
			XMLDocTemp.async='false';
			XMLDocTemp.loadXML(sResponse);
		}
		sStatus = GetNode(XMLDocTemp.getElementsByTagName("status")[0].childNodes[0]);
		if(sStatus.toLowerCase()=='ok') {
			iUserID = parseFloat(GetNode(XMLDocTemp.getElementsByTagName("userid")[0].childNodes[0]));
			document.getElementById('review_userid').value=iUserID;
			Rating_Step2();
			document.getElementById('MSH_NewUser_Captcha').value = '';
			document.getElementById('MSH_NewUser_Password').value = '';
			document.getElementById('MSH_NewUser_Password2').value = '';
			document.getElementById('MSH_NewUser_Email').value = '';
		}else if(sStatus.toLowerCase()=='alreadyrated') {
			alert('You have already rated this destination.\nClick OK to close this window.');
			location.href=window.location.href;
		}else{
			var sErrors = '';
			oErrors = XMLDocTemp.getElementsByTagName("error");
			for(x=0;x<oErrors.length;x++){
				sErrors+=GetNode(oErrors[x].childNodes[0])+'\n';
			}
			document.getElementById('MSH_NewUser_Captcha').value='';
			document.getElementById('MSH_NewUser_CaptchaImg').src='/includes/captcha.asp?timestamp='+new Date();
			alert(sErrors);
		}
	}
}

function MSH_AddReviewLogin() {
	email = document.getElementById('MSH_Login_Email').value;
	password = document.getElementById('MSH_Login_Password').value;
	if(!email||!password) {
		alert('Please enter your email address and password.');		
	}else{
		sURL = '/myskiingholidays/includes/reviews_login.asp?email='+encodeURI(email)+'&password='+encodeURI(password)+'&resortid='+Review_CurrentResortID;
		var sResponse = readFile(sURL);
		if(window.DOMParser) {
			var parser=new DOMParser();
			var XMLDocTemp=parser.parseFromString(sResponse,"text/xml");
		}else{
			var XMLDocTemp=new ActiveXObject("Microsoft.XMLDOM");
			XMLDocTemp.async='false';
			XMLDocTemp.loadXML(sResponse);
		}
		sStatus = GetNode(XMLDocTemp.getElementsByTagName("status")[0].childNodes[0]);
		if(sStatus.toLowerCase()=='ok') {
			iUserID = parseFloat(GetNode(XMLDocTemp.getElementsByTagName("userid")[0].childNodes[0]));
			Rating_Step2();
			document.getElementById('MSH_Login_Email').value = '';
			document.getElementById('MSH_Login_Password').value = '';
		}else if(sStatus.toLowerCase()=='alreadyrated') {
			alert('You have already rated this destination.\nClick OK to close this window.');
			location.href=window.location.href;
		}else{
			alert('Incorrect email address or password');			
		}
	}
}
function showRow(theID) {
	for(x=1;x<100;x++){
		if(document.getElementById(theID + x + '_a')){
			var sDisplay = 'none';
			var sTitle = 'Click here to view';
			if(document.getElementById(theID + x + '_a').style.display == 'none'){
				sDisplay = '';
				sTitle = 'Click here to hide';
			}
			document.getElementById(theID + x + '_a').style.display = sDisplay;
			document.getElementById(theID + x + '_b').style.display = sDisplay;
			document.getElementById('row' + theID + 'Title').style.display = sDisplay;
			document.getElementById('a' + theID).innerHTML = sTitle;
		}else{
			break;
		}
	}
}

function getImageSize(id, sType){
	var iWidthHeight = 0;
	document.getElementById('Pic'+id).style.display = 'block';
	iWidthHeight = eval("document.getElementById('Pic"+id+"')." + sType);
	if(document.getElementById('Pic'+id).width < 248 && document.getElementById('Pic'+id).height < 200) {
		// Use this in case you want a minimum width and height. 
		// I couldn't get it working with the lightbox so commented out it goes...
		if(sType == 'width'){
			//iWidthHeight = 248;
		}else{
			//iWidthHeight = 200;
		}
	}
	document.getElementById('Pic'+id).style.display = 'none';
	return iWidthHeight;
}

function validateNewsletter_SH(fId) {
	var m = '';
	var b = false;
	if(!fId.name.value || fId.name.value=='Enter your name') {m+='- Please enter your name\n'}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false || fId.email.value=='Enter your email'){m+='- Please enter a valid email address\n'}
	for(x=1;x<4;x++){
		if(document.getElementById('Signup' + x).checked) {b=true}
	}
	if(!b){m+='- Please choose 1 or more email signup options\n'}
	if(m){
		alert(m);
		return false;		
	}else{
		return true;		
	}
}

function changeSnowReports(fId) {
	sSelectedValue = fId.value;
	if(sSelectedValue) {
		location.href=sSelectedValue;
	}
}

function fillPassengerData() {
	sURL = '/includes/getpassengerxml.asp?ts='+new Date();
	var sResponse = readFile(sURL);
	if(window.DOMParser) {
		var parser=new DOMParser();
		var XMLDocTemp=parser.parseFromString(sResponse,"text/xml");
	}else{
		var XMLDocTemp=new ActiveXObject("Microsoft.XMLDOM");
		XMLDocTemp.async='false';
		XMLDocTemp.loadXML(sResponse);
	}
	var oPassengers = XMLDocTemp.getElementsByTagName('Passenger');
	if(oPassengers.length > 0) {
		for(x=0;x<oPassengers.length;x++) {
			iID = x+1
			sTitle = GetNode(oPassengers[x].getElementsByTagName("Title")[0].childNodes[0]);
			sFirstName = GetNode(oPassengers[x].getElementsByTagName("FName")[0].childNodes[0]);
			sSurname = GetNode(oPassengers[x].getElementsByTagName("SName")[0].childNodes[0]);
			sDOBd = GetNode(oPassengers[x].getElementsByTagName("DOB_D")[0].childNodes[0]);
			sDOBm = GetNode(oPassengers[x].getElementsByTagName("DOB_M")[0].childNodes[0]);
			sDOBy = GetNode(oPassengers[x].getElementsByTagName("DOB_Y")[0].childNodes[0]);
			o1 = document.getElementById('title'+iID);
			o2 = document.getElementById('firstname'+iID);
			o3 = document.getElementById('surname'+iID);
			o4 = document.getElementById('dobd'+iID);
			o5 = document.getElementById('dobm'+iID);
			o6 = document.getElementById('doby'+iID);
			if(o1) {
				for(y=0;y<o1.length;y++) {
					if(o1[y].value.toLowerCase()==sTitle.toLowerCase()) {
						o1.selectedIndex = y;
						y = o1.length;
					}
				}
			}
			if(o2){o2.value=sFirstName;}
			if(o3){o3.value=sSurname;}
			if(o4&&o5&&o6) {
				for(y=0;y<o4.length;y++) {
					if(o4[y].value.toLowerCase()==sDOBd.toLowerCase()) {
						o4.selectedIndex = y;
						y = o4.length;
					}
				}
				for(y=0;y<o5.length;y++) {
					if(o5[y].value.toLowerCase()==sDOBm.toLowerCase()) {
						o5.selectedIndex = y;
						y = o5.length;
					}
				}
				for(y=0;y<o6.length;y++) {
					if(o6[y].value.toLowerCase()==sDOBy.toLowerCase()) {
						o6.selectedIndex = y;
						y = o6.length;
					}
				}
			}
		}
	}
}
function selectAirport(sCityCode){
	sURL = '/includes/getairport.asp?citycode='+sCityCode+'&ts='+new Date();
	var sResponse = readFile(sURL);
	if(window.DOMParser) {
		var parser=new DOMParser();
		var XMLDocTemp=parser.parseFromString(sResponse,"text/xml");
	}else{
		var XMLDocTemp=new ActiveXObject("Microsoft.XMLDOM");
		XMLDocTemp.async='false';
		XMLDocTemp.loadXML(sResponse);
	}
	alert(XMLDocTemp);
}

var sCurrentFormID = '';
var sCurrentForm = '';
function findDestAirport(sFormID, sLocation) {
	sCurrentForm = document.getElementsByName('frm'+sFormID)
	sCurrentFormID = sFormID
	if(document.getElementById('idAirportto'+sFormID)) {
		sLocationList = document.getElementById('idAirportto'+sFormID);
		sLocationList.disabled='true';
		if(sLocation.length>0 && sLocation!='-') {
			sURL = "/includes/search/LookupXML.asp?searchtype=findairports&location=" + sLocation + "&c"
			if(sURL!='') {
				//if(confirm('Open '+ sURL)) {
				//	window.open(sURL);
				//}
				clearLocationList(sLocationList);
				sLocationList.options[0] = new Option('Loading... Plase wait','');
				setTimeout("loadServedAirportXMLDoc('"+sURL+"')", 100);
			}else{
				alert('No url defined');	
			}
		}else{
			sLocationList.options[0] = new Option('- Select destination airport -','');
			sLocationList.selectedIndex = 0;
			sLocationList.disabled='true';
		}
	}else{
		sCurrentForm[0].submit();	
	}
}

//XML Loader
function loadServedAirportXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processServedAirportChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processServedAirportChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processServedAirportChange() {
	if (req.readyState == 4){
		if (req.status == 200){
			sLocationList = document.getElementById('idAirportto'+sCurrentFormID);
			xmldoc = req.responseXML.documentElement;
			nodes = xmldoc.getElementsByTagName('Location');
			sLocationList.options[0] = new Option('- Please select -','');
			for(var i = 0; i < nodes.length; i++) {
				if (nodes.length != 0) {
					sCode = nodes.item(i).attributes.getNamedItem("code").nodeValue;
					sName = nodes.item(i).childNodes.item(0).nodeValue;
					sLocationList.options[sLocationList.options.length] = new Option(sName, sCode);
				}
			}
			sLocationList.disabled='';
			if(nodes.length==1) {
				//sLocationList.selectedIndex = 1;
				//sCurrentForm[0].submit();
			}else if(nodes.length==0 && bFirstTimer==true){
				//alert('No airports found for this destination');
				//locationGoBack(sCurrentFormID);
			}else{
				//switchLocationDivs('divLocation'+sCurrentFormID);	
			}
		}
	}
}

// NE 09/12/2008
function updateSkiWorldPrices(totalRooms, adultCount, childCount, infantCount) {
	var totalPrice = 0;
	var roomPrice = 0;
	var infantPrice = 0;
	
	for (iSelect=0; iSelect<totalRooms; iSelect++) {
		var oSelectBox = document.getElementById('SkiWorldRoom'+(iSelect+1));
		if (oSelectBox) {
			if (oSelectBox.options[oSelectBox.selectedIndex].value > 0) {
				roomPrice = 0;
				var extraInfo = new String(oSelectBox.getAttribute('extrainfo')).split(';');
				
				if (adultCount > 0) roomPrice += (parseFloat(extraInfo[1]) * parseInt(extraInfo[0]));
				if (childCount > 0) roomPrice += (parseFloat(extraInfo[3]) * parseInt(extraInfo[2]));
				//if (infantCount > 0) roomPrice += (parseFloat(extraInfo[5]) * parseInt(extraInfo[4]));
				if (infantPrice == 0) infantPrice = parseFloat(extraInfo[5]);
				roomPrice *= parseFloat(oSelectBox.options[oSelectBox.selectedIndex].value);
			} else {
				roomPrice = 0;
			}
			totalPrice += roomPrice;
		}
	}
	
	totalPrice += (infantPrice * infantCount);
	totalPrice /= (adultCount + childCount);
	
	if(document.getElementById('PricePerPax_Top'))
		document.getElementById('PricePerPax_Top').innerHTML = formatCurrency(totalPrice);
}

function FlexiAccomm(){
	Accomm_LoadResults();
	setTimeout("hideFlexi()", 3000)
}
function hideFlexi() {
	if((parseInt(iResultsCount) + parseInt(iNoResultsCount)) == iTotalResultsCount) {
		if(parseInt(iResultsCount) == 0){
			document.getElementById('divFlightSelector').style.display = 'none';
		}
	}else{
		setTimeout("hideFlexi()", 300)
	}
}

var bNoResults = false;

function Accomm_LoadResults() {
	var timestamp = new Date();
	
	
	var sTempQS_s = queryString('startdate');
	var sTempQS_e = queryString('enddate');
	var dActualStartDate = new Date(sTempQS_s.replace(/ /gi, '+').split('+')[2], getMonthNumber(sTempQS_s.replace(/ /gi, '+').split('+')[1]), sTempQS_s.replace(/ /gi, '+').split('+')[0]);
	
	
	sAccomm_URL_Main = '/includes/ajaxresults/ajaxresults.asp'+window.location.search+'&ts='+timestamp+'&updatesession=false';
	
	sAccomm_URL_Main = sAccomm_URL_Main.replace(/%20/g, ' ')
	
	iDateCount = 0;
	
	for(xxx=0; xxx<20; xxx++) {
		var oDateDiv = document.getElementById('divDate_' + xxx);
		if(!oDateDiv){
			oDateDiv = document.getElementById('divDate-nr_' + xxx);
			if(oDateDiv){
				bNoResults = true;
			}
		}else{
			bNoResults = false;
		}
		
		if(oDateDiv){
			var sDateDiv_StartDate = new String(oDateDiv.attributes.getNamedItem("startdate").value);
			var sDateDiv_EndDate = new String(oDateDiv.attributes.getNamedItem("enddate").value);
			var dDate = new Date();//TESTING DAY EXCLUSION LB
			
			dDate.setTime(Date.parse(sDateDiv_StartDate));
			iDay = dDate.getDay();
			if(iDay == 0 || iDay == 6){
			    sAccomm_URL = sAccomm_URL_Main.replace(sTempQS_s, sDateDiv_StartDate.replace(/%20/gi, ' '));
			    sAccomm_URL = sAccomm_URL.replace(sTempQS_e, sDateDiv_EndDate.replace(/%20/gi, ' '));
			    sAccomm_URL = sAccomm_URL.replace(/flexibility=1/gi, 'flexibility=0');
			    sAccomm_URL = sAccomm_URL.replace(/flexibility=2/gi, 'flexibility=0');
			    sAccomm_URL = sAccomm_URL.replace(/flexibility=3/gi, 'flexibility=0');
			    sAccomm_URL = sAccomm_URL.replace(/transfer=1/gi, 'transfer=0');
			    sAccomm_URL = sAccomm_URL.replace(/carhire=1/gi, 'carhire=0');
                sAccomm_URL = sAccomm_URL.replace(/Flight_Hotel/gi, 'PackageHoliday');

			    sAccomm_URL=sAccomm_URL.replace("'","");
			    Accomm_loadAjaxResultsXMLDoc(sAccomm_URL, oDateDiv.id);
			    iDateCount++;
			}else{
		        oDateDiv.style.display = 'none';
		        if(bNoResults) {
		            document.getElementById('divMainBox_' + xxx).style.display = 'none';
		        }
			}	
		}else{
			iTotalResultsCount = xxx;
			break;
		}
		
	}
	iTotalResultsCount = iDateCount;
}
var sDivID = '';
function Accomm_loadAjaxResultsXMLDoc(url, divid) {
	//alert(url + ',' + divid)
	var timestamp = new Date();
	url += '&timestamp=' + timestamp;
	var UpdateAccomFlexi = new ajaxObject(divid, url);
	var iTest = UpdateAccomFlexi.update(divid);
}


var sInnerHTMLToReplace = 'Checking availability..<br><img src="/images/animations/ajax-loader-white.gif">';
var sOriginalInnerHTML_0 = '';
var sOriginalInnerHTML_1 = '';
var sOriginalInnerHTML_2 = '';
var sOriginalInnerHTML_3 = '';
var sOriginalInnerHTML_4 = '';
var sOriginalInnerHTML_5 = '';
var sOriginalInnerHTML_6 = '';
var sOriginalInnerHTML_7 = '';
var sOriginalInnerHTML_8 = '';
var sOriginalInnerHTML_9 = '';
function ajaxObject(layer, aO_url) { 

	if(layer.indexOf('divDate') > -1){
		if(!bNoResults){
			sInnerHTMLToReplace = sInnerHTMLToReplace.replace('<br><img src="/images/animations/ajax-loader-white.gif">', ''); 
		}
	} else {
		sInnerHTMLToReplace = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Checking availability - Please wait...</div>';
	}

	window['sOriginalInnerHTML_' + layer.split('_')[1]] = document.getElementById(layer).innerHTML;
	document.getElementById(layer).innerHTML = sInnerHTMLToReplace;

	var that=this;                                                    
	var updating = false;                                                
	this.callback = function() {}                                        
	this.update = function(passData) {                                 
		if (updating==true) { return false; }                                
		updating=true;                                                 
		var aO_AJAX = null;                                                  
		if (window.XMLHttpRequest) {                                    
			aO_AJAX=new XMLHttpRequest();                              
		} else {                                                      
			aO_AJAX=new ActiveXObject("Microsoft.XMLHTTP");                
		}                                                             
		if (aO_AJAX==null) {                                                    
			alert("Your browser doesn't support AJAX.");                                                                 
			return false                                                   
		} else {        
			aO_AJAX.onreadystatechange = function() {                          
			if(LayerID){
				if (aO_AJAX.readyState==4 || aO_AJAX.readyState=="complete") {  
					var sText = aO_AJAX.responseText
					try{
						AccommAvail_XMLDoc = aO_AJAX.responseXML.documentElement
						formatAJAX(layer, LayerID, AccommAvail_XMLDoc, sText);
					}catch(err){
						formatAJAX(layer, LayerID, '', sText);
					}
					
					delete aO_AJAX;                                                      
					updating=false;                                                    
					that.callback();                                                  
				}                                                       
			}
		}                                                            
		var timestamp = new Date();                                      
		var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1);           
		aO_AJAX.open("GET", uri, true);                                 
		aO_AJAX.send(null);                                                
		return true;                                              
		}                                                                            
	}         // This area set up on constructor calls.   
	var LayerID = document.getElementById(layer);                        
	var urlCall = aO_url;  
	// Remember the url associated with this object.

}  
// END

function formatAJAX(olayer, oLayerID, oAccommAvail_XMLDoc, sText) {
	if(oLayerID.id.indexOf('divDate') > -1){
		if(sText.indexOf("|") > -1){
			sText = sText.split("|")[1]
		}
		var oAvailable = oAccommAvail_XMLDoc.getElementsByTagName('AVAILABLE');
		var iResultCount = parseFloat(GetAttribute(oAvailable.item(0).attributes.getNamedItem("ResultCount")));
		var sOriginalInnerHTML = window['sOriginalInnerHTML_' + olayer.split('_')[1]];
		if(parseInt(iResultCount) > 0) {
			if(parseInt(iResultCount) > 1) {sS = 's'}else{sS = ''}
			oLayerID.innerHTML= sOriginalInnerHTML.replace(sInnerHTMLToReplace, '') + '<br/><span style="color:#246C17;">' + iResultCount + ' skiing holiday' + sS + ' available</span>';
			iResultsCount += 1;
		}else{
			iNoResultsCount += 1;
			if(bNoResults){
				oLayerID.innerHTML= sOriginalInnerHTML.replace(sInnerHTMLToReplace, '') + '<br/><span style="color:red;">No skiing holidays available</span>';
				if(document.getElementById('divMainBox_' + olayer.split('_')[1])) {
					document.getElementById('divMainBox_' + olayer.split('_')[1]).className = 'bg1 bg3';
					document.getElementById('butBook_' + olayer.split('_')[1]).style.display = 'none';
				}
			}else{
				document.getElementById('divContainer_' + olayer.split('_')[1]).style.display = 'none';
			}
		}
	}else{
		oLayerID.innerHTML = sText;	
	}
}  

function LMS_SwitchDays(url, divid, bCountry) {
	var timestamp = new Date();
	url += '&timestamp=' + timestamp;
	var UpdateAccomFlexi = new ajaxObject(divid, url.split('?')[0]);
	var iTest = UpdateAccomFlexi.update(url.split('?')[1]);	
}
