﻿// Search QueryString
var qrStr = window.location.search;
var spQrStr = qrStr.substring(1);
var arrQrStr = new Array();
// splits each of pair
var arr = spQrStr.split('&');
for (var i = 0; i < arr.length; i++) {
	// splits each of field-value pair
	var index = arr[i].indexOf('=');
	var key = arr[i].substring(0, index);
	var val = arr[i].substring(index + 1);

	// saves each of field-value pair in an array variable
	arrQrStr[key] = val;
}

//---------------------------------------------------------------------------------\\

// Create AirField Information

var locHref = window.location.href
var _airCode = locHref.split("/")
var airCode = _airCode[4]
var hotelCode = _airCode[6]


//----------------------------------------------------------------------------------\\

// Min Height Information

var minHeight = 600;

//----------------------------------------------------------------------------------\\

// Create Base Marker Icon

var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);

//---------------------------------------------------------------------------------\\

// Create Markers

var map = null;
var geocoder = null;

//http://www.google.com/mapfiles/marker.png

function createMarkerAB(point, html, index) {
	    var letter = String.fromCharCode("A".charCodeAt(0) + index); 
        var letteredIcon = new GIcon(baseIcon);  
        letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";  
	    var marker = new GMarker(point, { icon:letteredIcon });
	    
	    GEvent.addListener(marker, "click", function() {
	        marker.openInfoWindowHtml(html);
	    });
	    return marker;
	}

	function createMarker(point, html, index) {
	    var letteredIcon = new GIcon(baseIcon);
	    letteredIcon.image = "http://www.google.com/mapfiles/marker.png";
	    var marker = new GMarker(point, { icon: letteredIcon });

	    GEvent.addListener(marker, "click", function() {
	        marker.openInfoWindowHtml(html);
	    });
	    return marker;
	}
	function createMarker(point, html, index) {
	    var letteredIcon = new GIcon(baseIcon);
	    letteredIcon.image = "http://www.google.com/mapfiles/marker.png";
	    var marker = new GMarker(point, { icon: letteredIcon });

	    GEvent.addListener(marker, "click", function() {
	        marker.openInfoWindowHtml(html);
	    });
	    return marker;
	}

//---------------------------------------------------------------------------------\\

// Load Map Function

function myload() {
   map = new GMap2(document.getElementById("myMap"));
        map.setCenter(new GLatLng(38.048906, -84.499838), 4); //G_HYBRID_MAP
        var extLargeMapControl = new ExtLargeMapControl();
        map.addControl(extLargeMapControl);
 
        map.addControl(new GMapTypeControl());
        map.enableScrollWheelZoom();

        var request = GXmlHttp.create();
        var hotelTypeBit = 1;
   if (hotelCode != null) {
        request.open("GET", "/xmlOutput/hotelinfo.aspx?airCode="+hotelCode, true);
   } else if (airCode != null) {
        request.open("GET", "/xmlOutput/hotels.aspx?airCode="+airCode, true);
    } else {
    hotelTypeBit = 0;
    request.open("GET", "/xmlOutput/hotels.aspx", true);
   }

   var publisherID = 'ca-pub-2901497455830449';

   var adsManagerOptions = {
       maxAdsOnMap: 1,
       style: 'adunit',
       // The channel field is optional - replace this field with a channel number 
       // of your own for Google AdSense tracking
       //channel: '6864950726'
   };

   adsManager = new GAdsManager(map, publisherID, adsManagerOptions);
   adsManager.enable();

   request.onreadystatechange = function() {
       if (request.readyState == 4) {
           var xmlDoc = request.responseXML;
           var points = xmlDoc.documentElement.getElementsByTagName("point");
           //map.setCenter(new GLatLng(44.881234, -93.203111), 11);

           for (var i = 0; i < points.length; i++) {
               if (i == 0) {
                   map.setCenter(new GLatLng(parseFloat(points[i].getAttribute("airLat")), parseFloat(points[i].getAttribute("airLng"))), parseFloat(points[i].getAttribute("airZoom")));
               }
               var point = new GLatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
               if (hotelTypeBit != 1) {
                   var marker = createMarker(point, '<div style="width:240px">' + points[i].getAttribute("hotelname") + '<br /><a href="/airports/' + points[i].getAttribute("airCode") + '/hotels/' + points[i].getAttribute("hotelid") + '/' + points[i].getAttribute("hotelsname") + '">hotel information</a></div>', i)
               } else {
               var marker = createMarkerAB(point, '<div style="width:240px">' + points[i].getAttribute("hotelname") + '<br /><a href="/airports/' + points[i].getAttribute("airCode") + '/hotels/' + points[i].getAttribute("hotelid") + '/' + points[i].getAttribute("hotelsname") + '">hotel information</a></div>', i)
               }
               
               map.addOverlay(marker);
           }
       }
   }
             request.send(null);
             
        
       }
//---------------------------------------------------------------------------------\\

// Sizing Controls

function calcSize() {
var myWidth = 0, myHeight = 0;
 	if( typeof( window.innerWidth ) == 'number' ) {
        if ( window.innerHeight < minHeight ) {
        document.getElementById('myMap').style.height = minHeight-218+'px';
	    document.getElementById('content').style.height = minHeight-218+'px';
	    document.getElementById('myToolBar').style.height = minHeight-238+'px';  
	    } else {
        //Non-IE
        document.getElementById('myMap').style.height = window.innerHeight-218+'px';
	    document.getElementById('content').style.height = window.innerHeight-218+'px';
	    document.getElementById('myToolBar').style.height = window.innerHeight-238+'px';
        }
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    
        if ( document.documentElement.clientHeight < minHeight ) {
        //IE 6+ in 'standards compliant mode'
	    document.getElementById('myMap').style.height = minHeight-218+'px';
	    document.getElementById('content').style.height = minHeight-218+'px';
	    document.getElementById('myToolBar').style.height = minHeight-238+'px';       
        } else {
        //IE 6+ in 'standards compliant mode'
	    document.getElementById('myMap').style.height = document.documentElement.clientHeight-218+'px';
	    document.getElementById('content').style.height = document.documentElement.clientHeight-218+'px';
	    document.getElementById('myToolBar').style.height = document.documentElement.clientHeight-238+'px';
        }
        
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        if ( document.body.clientHeight < minHeight ) {        
        document.getElementById('myMap').style.height = minHeight-218+'px';
	    document.getElementById('content').style.height = minHeight-218+'px';
	    document.getElementById('myToolBar').style.height = minHeight-238+'px';  
	    } else {
        //IE 4 compatible
        document.getElementById('myMap').style.height = document.body.clientHeight-218+'px';
	    document.getElementById('content').style.height = document.body.clientHeight-218+'px';
	    document.getElementById('myToolBar').style.height = document.body.clientHeight-238+'px';
	    }
  }
}
