
//<![CDATA[
var vgooglemap;
var gmarkers = [];
var glookup = [];
var i = 0;				
var eventClick=0;
function load() {
  if (GBrowserIsCompatible()) {
	vgooglemap = new GMap2(document.getElementById("googlemap"));
	vgooglemap.addControl(new GSmallMapControl());
	vgooglemap.setCenter(new GLatLng(0,0),2);
	vgooglemap.setMapType(G_PHYSICAL_MAP);
	var myObserver = new Object;		
	dsProducts.setURL("/cfpages/xml/iglu_data.cfm");
	dsProducts.loadData();					
	myObserver.onPostLoad = function(dataSet, data)
	{					
		dataloadedyet();
	};
	dsProducts.addObserver(myObserver);				
	}
}		 

// Creates a marker at the given point with the given number label
function createMarker(point,index, itemtype,itemtname,subtype,htmldata,id  ) {
  var theicon = new GIcon();
 
  theicon.infoWindowAnchor = new GPoint(9, 12);
  theicon.infoShadowAnchor = new GPoint(18, 12);				  			  
  
  if (itemtype == "R") {
	if (subtype == "1") {
		theicon.image =  "/images/mapicons/resortartificial.png"; 
	} else if (subtype == "2") {	
		theicon.image =  "/images/mapicons/resortindoor.png"; 
	} else {
		theicon.image =  "/images/mapicons/resortmtn.png"; 
	}					
	theicon.shadow = "/images/mapicons/shadow.png"
	theicon.iconSize = new GSize(25, 25);	
	theicon.shadowSize = new GSize(37, 25);
	theicon.iconAnchor = new GPoint(9, 25);						  
  } else if (itemtype == "A") {
	theicon.image =  "/images/mapicons/smallairport.png"; 	
	theicon.shadow = "/images/mapicons/smallshadow.png"
	theicon.iconSize = new GSize(22, 22);	
	theicon.shadowSize = new GSize(37, 22);
	theicon.iconAnchor = new GPoint(9, 22);						  	
  }			  

  var marker = new GMarker(point,{icon: theicon,title:itemtname}); 
  GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(htmldata);
	if (eventClick == 0) {					
		}
	});
	gmarkers[i] = marker;
	glookup[i]= id;
	i++;
  return marker;
}  


function updatemap(acid,cid,dfrom,drange,vPriceRange,vRatingno,vAirport,curTrees,curOffpiste,curPark,curHalfpipe,curNightriding,curFreeridePer,curFreestylePer,curPistePer) {				
	var myObserver = new Object;				
	dsProducts.setURL("/cfpages/xml/iglu_data.cfm?AirportCountryID=" + acid + "&CountryID=" + cid + "&From=" + dfrom + "&daterange=" + drange + "&PriceRange=" + vPriceRange + "&Ratingno=" + vRatingno + "&Airport=" + vAirport + "&trees=" + curTrees + "&offpiste=" + curOffpiste + "&park=" + curPark + "&halfpipe=" + curHalfpipe + "&nightriding=" + curNightriding + "&freerideper=" + curFreeridePer + "&freestyleper=" + curFreestylePer + "&pisteper=" + curPistePer);
	dsProducts.loadData();						
	myObserver.onPostLoad = function(dataSet, data)
	{					
		dataloadedyet();
	};
	dsProducts.addObserver(myObserver);
}
	
function dataloadedyet()
{	
	vgooglemap.clearOverlays();
	var bounds = new GLatLngBounds();						
	var rows = dsProducts.getData();
	for (var i = 0; i < rows.length; i++)
	{			
		var point = new GLatLng(parseFloat(rows[i]["lat"]),
							parseFloat(rows[i]["lng"]));
			vgooglemap.addOverlay( createMarker(point, i + 1, rows[i]["itemtype"], rows[i]["itemtname"],rows[i]["subtype"],rows[i]["htmldata"],rows[i]["id"]  ) );
		bounds.extend(point);
	}	
	var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
	var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
	vgooglemap.setZoom(vgooglemap.getBoundsZoomLevel(bounds));
	vgooglemap.setCenter(new GLatLng(clat,clng));	
}				

function setFields() {
				selIndex=document.getElementById("country").selectedIndex;
				vcountryid=document.getElementById("country").options[selIndex].value;				
				
				vfrom=document.getElementById("from").value;	
				
				selIndex=document.getElementById("daterange").selectedIndex;
				vdaterange=document.getElementById("daterange").options[selIndex].value;	

				selIndex=document.getElementById("pricerange").selectedIndex;
				vPriceRange=document.getElementById("pricerange").options[selIndex].value;				
				
				selIndex=document.getElementById("ratingno").selectedIndex;
				vRatingno=document.getElementById("ratingno").options[selIndex].value;				

				selIndex=document.getElementById("airport").selectedIndex;
				vAirport=document.getElementById("airport").options[selIndex].value;				

				selIndex=document.getElementById("trees").selectedIndex;
				curTrees=document.getElementById("trees").options[selIndex].value;				
				
				selIndex=document.getElementById("offpiste").selectedIndex;
				curOffpiste=document.getElementById("offpiste").options[selIndex].value;				

				selIndex=document.getElementById("park").selectedIndex;
				curPark=document.getElementById("park").options[selIndex].value;							

				selIndex=document.getElementById("halfpipe").selectedIndex;
				curHalfpipe=document.getElementById("halfpipe").options[selIndex].value;	

				selIndex=document.getElementById("nightriding").selectedIndex;
				curNightriding=document.getElementById("nightriding").options[selIndex].value;					

				selIndex=document.getElementById("freerideper").selectedIndex;
				curFreeridePer=document.getElementById("freerideper").options[selIndex].value;	

				selIndex=document.getElementById("freestyleper").selectedIndex;
				curFreestylePer=document.getElementById("freestyleper").options[selIndex].value;	

				selIndex=document.getElementById("pisteper").selectedIndex;
				curPistePer=document.getElementById("pisteper").options[selIndex].value;	
	
	
}
function sendpage() 
{					
																
		
				setFields();
				/*window.location.href='<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>?resortID=' + vresortid + '&AirportCountry=' + <cfoutput>#curAirportCountry#</cfoutput> + '&Country=' + vcountryid + '&from=' + vfrom + '&daterange=' + vdaterange;*/


				ctl=document.getElementById("sendrequest")
				ctl.value = 'Searching ...';
				ctl.disabled = true;
				
				updatemap(21,vcountryid,vfrom,vdaterange,vPriceRange,vRatingno,vAirport,curTrees,curOffpiste,curPark,curHalfpipe,curNightriding,curFreeridePer,curFreestylePer,curPistePer);
				ctl.disabled = false;				
				ctl.value = 'Get offers';

	}		
	function alertme() {
		setFields();
		
		var theQuery="AirportCountryID=" + 21 + "&CountryID=" + vcountryid + "&From=" + vfrom + "&daterange=" + vdaterange + "&PriceRange=" + vPriceRange + "&Ratingno=" + vRatingno + "&Airport=" + vAirport + "&trees=" + curTrees + "&offpiste=" + curOffpiste + "&park=" + curPark + "&halfpipe=" + curHalfpipe + "&nightriding=" + curNightriding + "&freerideper=" + curFreeridePer + "&freestyleper=" + curFreestylePer + "&pisteper=" + curPistePer;
		var theTitle=prompt("Give the alert a name","myalert");
		DWREngine._execute(_cfscriptLocation, null, 'alertme', theQuery, theTitle, alertmeResult);
		
	}		
	function alertmeResult(result) {
		document.getElementById("myalerts").innerHTML = result;
		window.alert("You will now recieve an email when we find offers that match this criteria. Manage you alerts by going to your MyWSG section on the website or clicking the unsubscrible link on the email alert");
	}
	//]]>
