var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month++;
var curr_year = d.getFullYear();
document.getElementById("date").innerHTML = (curr_date + "-" + curr_month + "-" + curr_year);
    //<![CDATA[
    if (GBrowserIsCompatible()) {
      var sidebar_html = "";
      var gmarkers = [];
	  var gmarkerst = [];
	  var gmarkerstt = [];
	  var gmarkersttt = [];
	  var gmarkerstv = [];
	  var gmarkersv = [];
	  var gmarkersvt = [];
      var htmls = [];
	  var ohtml= [];
	  var astar =[];
	  var iialt =[];
	  var aimiss =[]; 
	  var aprice =[];
	  var aname =[];
	  var aurl =[];
	  var acur =[];
      var thums = [];
	  var sider=[];
	  var i =0;
	  var loh =0;
	  var db1lower =-61.1068000793457
	  var db2lower =-1.5794522762298584
	  var db3lower =2.626199960708618
	  var db4lower =8.043959617614746


 var oneIcon = new GIcon();
      oneIcon.image = "markers/marker1_s.png";
      oneIcon.shadow = "markers/shadow50_s.png";
      oneIcon.iconSize = new GSize(10, 17);
      oneIcon.shadowSize = new GSize(19, 17);
      oneIcon.iconAnchor = new GPoint(5, 9);
      oneIcon.infoWindowAnchor = new GPoint(5, 2);
      oneIcon.infoShadowAnchor = new GPoint(9, 13);
      oneIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      oneIcon.printImage = "markers/marker1_s.gif";
      oneIcon.mozPrintImage = "markers/marker1_s.gif";

	  var twoIcon = new GIcon();
      twoIcon.image = "markers/marker2_s.png";
      twoIcon.shadow = "markers/shadow50_s.png";
      twoIcon.iconSize = new GSize(10, 17);
      twoIcon.shadowSize = new GSize(19, 17);
      twoIcon.iconAnchor = new GPoint(5, 9);
      twoIcon.infoWindowAnchor = new GPoint(5, 2);
      twoIcon.infoShadowAnchor = new GPoint(9, 13);
      twoIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      twoIcon.printImage = "markers/marker2_s.gif";
      twoIcon.mozPrintImage = "markers/marker2_s.gif";

	  var threeIcon = new GIcon();
      threeIcon.image = "markers/marker3_s.png";
      threeIcon.shadow = "markers/shadow50_s.png";
      threeIcon.iconSize = new GSize(10, 17);
      threeIcon.shadowSize = new GSize(19, 17);
      threeIcon.iconAnchor = new GPoint(5, 9);
      threeIcon.infoWindowAnchor = new GPoint(5, 2);
      threeIcon.infoShadowAnchor = new GPoint(9, 13);
      threeIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      threeIcon.printImage = "markers/marker3_s.gif";
      threeIcon.mozPrintImage = "markers/marker3_s.gif";

	  var fourIcon = new GIcon();
      fourIcon.image = "markers/marker4_s.png";
      fourIcon.shadow = "markers/shadow50_s.png";
      fourIcon.iconSize = new GSize(10, 17);
      fourIcon.shadowSize = new GSize(19, 17);
      fourIcon.iconAnchor = new GPoint(5, 9);
      fourIcon.infoWindowAnchor = new GPoint(5, 2);
      fourIcon.infoShadowAnchor = new GPoint(9, 13);
      fourIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      fourIcon.printImage = "markers/marker4_s.gif";
      fourIcon.mozPrintImage = "markers/marker4_s.gif";

	  var fiveIcon = new GIcon();
      fiveIcon.image = "markers/marker5_s.png";
      fiveIcon.shadow = "markers/shadow50_s.png";
      fiveIcon.iconSize = new GSize(10, 17);
      fiveIcon.shadowSize = new GSize(19, 17);
      fiveIcon.iconAnchor = new GPoint(5, 9);
      fiveIcon.infoWindowAnchor = new GPoint(5, 2);
      fiveIcon.infoShadowAnchor = new GPoint(9, 13);
      fiveIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      fiveIcon.printImage = "markers/marker5_s.gif";
      fiveIcon.mozPrintImage = "markers/marker5_s.gif";

	  var sixIcon = new GIcon();
      sixIcon.image = "markers/marker6_s.png";
      sixIcon.shadow = "markers/shadow50_s.png";
      sixIcon.iconSize = new GSize(10, 17);
      sixIcon.shadowSize = new GSize(19, 17);
      sixIcon.iconAnchor = new GPoint(5, 9);
      sixIcon.infoWindowAnchor = new GPoint(5, 2);
      sixIcon.infoShadowAnchor = new GPoint(9, 13);
      sixIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      sixIcon.printImage = "markers/marker6_s.gif";
      sixIcon.mozPrintImage = "markers/marker6_s.gif";

      var sevenIcon = new GIcon();
      sevenIcon.image = "markers/hemiC_s.png";
      sevenIcon.shadow = "markers/shadowhemi_s.png";
      sevenIcon.iconSize = new GSize(17, 17);
      sevenIcon.shadowSize = new GSize(22, 17);
      sevenIcon.iconAnchor = new GPoint(9, 9);
      sevenIcon.infoWindowAnchor = new GPoint(9, 9);
      sevenIcon.infoShadowAnchor = new GPoint(9, 9);
      sevenIcon.printImage = "markers/hemiC_s.gif";
      sevenIcon.mozPrintImage = "markers/hemiC_s.gif";

      var icons = [];
      icons[0] = oneIcon;
      icons[1] = twoIcon;
      icons[2] = threeIcon;
      icons[3] = fourIcon;
      icons[4] = fiveIcon;
      icons[5] = sixIcon;


      // A function to create the marker and set up the event window
      function markerdata(dmarker, bounds){         
              // obtain the attribues of each marker
              var lat = parseFloat(dmarker.getAttribute("lat"));
              var lng = parseFloat(dmarker.getAttribute("lng"));
              var point = new GLatLng(lat,lng);
			  bounds.extend(point)
              var html = dmarker.getAttribute("html");
              var label = dmarker.getAttribute("label");
              var price = dmarker.getAttribute("price");
			  comp=parseInt(price)
			  if (comp<36)
			  {var icontype = 5
			  }
			  else if (comp<51)
			  {var icontype = 4
			  }
			  else if (comp<66)
			  {var icontype = 3
			  }
			  else if (comp<76)
			  {var icontype = 2
			  }
			  else if (comp<86)
			  {var icontype = 1
			  }
			  else{
			  var icontype = 0
			  }
              var uadd = dmarker.getAttribute("url");
              var iurl = dmarker.getAttribute("iurl");
              var stars = dmarker.getAttribute("stars");
              var ims = dmarker.getAttribute("ims");
              var hid = dmarker.getAttribute("hid");
              var ialt = dmarker.getAttribute("ialt");
			  var cash = dmarker.getAttribute("cash");
			  if (cash.substring(0,3)=='GBP')
			  {var cur ='&#163;'
			  }
			  else if(cash.substring(0,3)=='EUR'){
			  var cur =' &#8364;'
				}
			  else if(cash.substring(0,3)=='USD'){
			  var cur =' $'
				}
			  else{var cur = cash.substring(0,3)+' '}
			  if (loh >50)
			  {html = html.substring(0,300)+".....";
			  ialt = ialt.substring(0,50);
			  }
			  var imss = ''
			  var thum =''
			  var ids=hid.substring(1)
			  if(ims.charAt(0) =='y'){
			  imss = "<img src='/Images/email.gif' alt='Office Services' width=23 height=23 >&nbsp;&nbsp;&nbsp; ";}
			  if(ims.charAt(1) =='y'){
			  imss = imss + "<img src='/Images/parking.gif' alt='Parking' width=23 height=23 >&nbsp;&nbsp;&nbsp; ";}
			  if(ims.charAt(2) =='y'){
			  imss = imss + "<img src='/Images/swim.gif' alt='Sports Facilities' width=23 height=23>";}
			  if(hid.charAt(0) =='a'){
			  thum ="<img src='"+iurl+"' height=150>";}
			  if(hid.charAt(0) =='s'){
			  thum="<img src='http://www.superbreak.com/hotelnet/superbreak/pictures/"+ids+"_BRO.jpg' height=150>";}
              // create the marker
              var marker = createMarker(point,label,html, price,uadd, stars, imss, thum, ialt, icontype, cur);
			  return marker

            }

      // A function to create the marker and set up the event window
      function createMarker(point,name,html, price, uadd, stars, imss, thum, ialt, icontype, cur) {
        var marker = new GMarker(point, icons[icontype]);
		var nhtml=''
		nhtml= '<table><TR><TD width=200 align=left><font color=red><B>'+stars+'</B></font>&nbsp;&nbsp;<img src="/Images/info.gif" alt="'+ialt+'"> '+imss+' &nbsp;&nbsp;'+cur+price+'<BR><font color=#0000CC face=verdana><A href="'+uadd+'" target="'+name+'">'+name+'</A><BR>'+html.substring(0,60)+'....<BR><A HREF="'+uadd+'" target="'+name+'"><I>Click on here for more info</I></A></TD></TR></TABLE>';
		GEvent.addListener(marker, "click", function() {
		  nhtml= '<table><TR><TD width=200 align=left><font color=red><B>'+stars+'</B></font>&nbsp;&nbsp;<img src="/Images/info.gif" alt="'+ialt+'"> '+imss+' &nbsp;&nbsp;'+cur+price+'<BR><font color=#0000CC face=verdana><A href="'+uadd+'" target="'+name+'">'+name+'</A><BR>'+html.substring(0,60)+'....<BR><A HREF="'+uadd+'" target="'+name+'"><I>Click here for more info</I></A></TD></TR></TABLE>';
		  document.getElementById("thumbs").innerHTML='<A HREF="'+uadd+'" target="'+name+'">'+thum+'</A>'
		  document.getElementById("sfg").innerHTML="<B>"+name+"</B><BR>"+html+"....<BR><A HREF='"+uadd+"' target='"+name+"'><I>Click on photo for more info</I></A>"
		  marker.openInfoWindowHtml(nhtml);
        });
		gmarkers[i]=marker;
		if (icontype==0)
		{gmarkerst[gmarkerst.length]=i;
		}
		else if (icontype==1)
		{gmarkerstt[gmarkerstt.length]=i;
		}
		else if (icontype==2)
		{gmarkersttt[gmarkersttt.length]=i;
		}
		else if (icontype==3)
		{gmarkerstv[gmarkerstv.length]=i;
		}
		else if (icontype==4)
		{gmarkersv[gmarkersv.length]=i;
		}
		else 
		{gmarkersvt[gmarkersvt.length]=i;
		}
		ohtml[i]=html
		astar[i]=stars
		iialt[i] =ialt
		aimiss[i]=imss
		aprice[i]=price
		aname[i]=name
		aurl[i]=uadd
		acur[i] = cur
		thums[i]='<A HREF="'+uadd+'" target="'+name+'">'+thum+'</A>'
		sider[i]= stars+'<BR><a href="javascript:myclick(' + i + ')">' + name + '</a>  '+cur+price+'&nbsp;&nbsp;&nbsp;&nbsp;<HR>';
        sidebar_html += stars+'<BR><a href="javascript:myclick(' + i + ')">' + name + '</a>  '+cur+price+'&nbsp;&nbsp;&nbsp;&nbsp;<HR>';
		i++
        return marker;
      }
      function myclick(i) {
		nhtml= '<table><TR><TD width=200 align=left><font color=red><B>'+astar[i]+'</B></font>&nbsp;&nbsp;<img src="/Images/info.gif" alt="'+iialt[i]+'"> '+aimiss[i]+' &nbsp;&nbsp;'+acur[i]+aprice[i]+'<BR><font color=#0000CC face=verdana><A href="'+aurl[i]+'" target=new>'+aname[i]+'</A><BR>'+ohtml[i].substring(0,60)+'....<BR><A HREF="'+aurl[i]+'" target="'+aname[i]+'"><I>Click here for more info</I></A></TD></TR></TABLE>';
        gmarkers[i].openInfoWindowHtml(nhtml);
		document.getElementById("thumbs").innerHTML = thums[i];
		document.getElementById("sfg").innerHTML="<B>"+aname[i]+"</B><BR>"+ohtml[i]+"....<BR><A HREF='"+aurl[i]+"' target='"+aname[i]+"'><I>Click here for more info</I></A>"
      }


      function clicky(rang, htms) {
		var bounds = new GLatLngBounds();
        var icontype = parseInt(rang)
            // hide the info window, otherwise it still stays open where the removed marker used to be
        map.getInfoWindow().hide();
        map.clearOverlays();
        sidebar_html="Hotels priced " + htms+" <BR><BR>";
		if (icontype==0){
		var lo =gmarkerst.length;
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkerst[i]]);
			  point =gmarkers[gmarkerst[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkerst[i]]}
		}
		else if (icontype==1){
		var lo =gmarkerstt.length;
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkerstt[i]]);
			  point =gmarkers[gmarkerstt[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkerstt[i]]}
		}
		else if (icontype==2){
		var lo =gmarkersttt.length
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkersttt[i]]);
			  point =gmarkers[gmarkersttt[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkersttt[i]]}
		}
		else if (icontype==3){
		var lo =gmarkerstv.length
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkerstv[i]]);
			  point =gmarkers[gmarkerstv[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkerstv[i]]}
		}
		else if (icontype==4){
		var lo =gmarkersv.length;
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkersv[i]]);
			  point =gmarkers[gmarkersv[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkersv[i]]}
		}
		else if (icontype==5){
		var lo =gmarkersvt.length
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[gmarkersvt[i]]);
			  point =gmarkers[gmarkersvt[i]].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[gmarkersvt[i]]}
		}
		else {
		var lo =gmarkers.length
        sidebar_html="<BR> " + htms+" <BR><BR>";
		for (var i = 0; i < lo; i++) {
              map.addOverlay(gmarkers[i]);
			  point =gmarkers[i].getPoint();
			  bounds.extend(point);
			  sidebar_html +=sider[i]}
		}
		if (lo > 1)
		{if (document.getElementById('zoom').checked==true)
		{
		
		map.setZoom(map.getBoundsZoomLevel(bounds));
		var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
        var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
        map.setCenter(new GLatLng(clat,clng));
		}}
		else if(lo == 1){
		if (document.getElementById('zoom').checked==true)
		{
        map.setCenter(point, 12);
		}}
		else{sidebar_html="There are no hotels priced<BR><BR>"+htms }
        document.getElementById("sidebar").innerHTML = sidebar_html;
     }

function postcode(){
		posc=document.getElementById('postcode').value
		var request = GXmlHttp.create();
		url = "http://www.discount-hotels-uk.com/data/postcode.php?posc="+posc
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("center");
            
            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();
            
            map.clearOverlays();
            var lat = parseFloat(markers[0].getAttribute("lat"));
            var lng = parseFloat(markers[0].getAttribute("lng"));
			var county = markers[0].getAttribute("town");
            var town = markers[0].getAttribute("county");
			var btown=town.substring(0,1).toUpperCase()+ town.substring(1, town.length);
			var bcounty=county.substring(0,1).toUpperCase()+ county.substring(1, county.length);
			if (town!=='no')
			{map.setCenter(new GLatLng( lat,lng), 12);
			document.getElementById("codres").innerHTML = " ";
			document.getElementById("tit").innerHTML = "<A href='http://www.discount-hotels-uk.com'>Home</A> / <A href='http://www.discount-hotels-uk.com/mapdata/ukhotelsmap.html'> UK </A> / <A href='http://www.discount-hotels-uk.com/mapdata/"+county+"_map.html'> "+bcounty+" </A><BR><H1>Google Map of hotels in "+btown+", "+bcounty+"</H1>"
			checkbounds()
			}
			else{
			document.getElementById("codres").innerHTML = "Sorry, postcode not found";
			}
            }
        }
        request.send(null);
      }



	function checkbounds(){
		var bunds = map.getBounds()
		var zom = map.getBoundsZoomLevel(bunds)
		if ( zom > 8)
		{	htms = 'All Hotels'
			var bounds = new GLatLngBounds();
			var bunds = map.getBounds()
			var swm = bunds.getSouthWest()
			var swml = swm.lat()
			var swmg = swm.lng()
			var nem = bunds.getNorthEast()
			var neml = nem.lat()
			var nemg = nem.lng()
			var wh=''
			var rt=''
			gmarkers = [];
			gmarkerst = [];
			gmarkerstt = [];
			gmarkersttt = [];
			gmarkerstv = [];
			gmarkersv = [];
			gmarkersvt = [];
			htmls = [];
			ohtml= [];
			astar =[];
			iialt =[];
			aimiss =[]; 
			price =[];
			aname =[];
			aurl =[];
			thums = [];
			sider=[];
			acur =[]
			i =0;
			loh =0;
			var request = GXmlHttp.create();
			url = "http://www.discount-hotels-uk.com/data/axml.xml.php?net="+neml+"&neg="+nemg+"&swt="+swml+"&swg="+swmg
			request.open("GET", url, true);
			request.onreadystatechange = function() {
			  if (request.readyState == 4) {
				var xmlDoc = request.responseXML;
				// obtain the array of markers and loop through it
				var markers = xmlDoc.documentElement.getElementsByTagName("marker");
				
				if (rt !='')
					{alert(rt)
					}
				// hide the info window, otherwise it still stays open where the removed marker used to be
				map.getInfoWindow().hide();
				
				map.clearOverlays();
				
				// empty the array
				// reset the sidebar
				sidebar_html="<BR><B>All Hotels </B><BR><BR>";
				loh =markers.length
				document.getElementById('thumbs').innerHTML='<B>Loading '+loh.toString()+' Hotels</B><BR><BR>';
				if (markers.length>1){
				for (var i = 0; i < markers.length; i++) {
				  marker = markerdata(markers[i], bounds);}
				// put the assembled sidebar_html contents into the sidebar div
				}
				else if (markers.length==1){
					for (var i = 0; i < markers.length; i++) {
					marker = markerdata(markers[i], bounds);
					}}
				else {
					sidebar_html = "<BR><BR>There are no hotels in this area";
					}
					
				setTimeout("overlay()",100);
				}
			}
			request.send(null);
			}
		else{	document.getElementById('thumbs').innerHTML='<B><H1> Zoom level too high!!</B></H1><BR>Try zooming in a little';
				document.getElementById("sfg").innerHTML=" ";}
      }

function overlay(){
    var popo = 0
	var poo =0
	for (var u = 0; u < gmarkers.length; u++) {
		if (gmarkers[u]!= undefined)
		{setTimeout("map.addOverlay(gmarkers["+u+"])",200);
		popo++;
		}
		else {
		poo++}
	}
	document.getElementById('thumbs').innerHTML='<B> '+gmarkers.length.toString()+' Hotels Loaded</B>'
	document.getElementById('sidebar').innerHTML = sidebar_html;
}

      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng( xu,yu), zu);

     // A function to read the data
      function readMap(url, htms) {
		var bounds = new GLatLngBounds();
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();
            
            map.clearOverlays();
            
            // empty the array
            gmarkers = [];
			gmarkerst = [];
			gmarkerstt = [];
			gmarkersttt = [];
			gmarkerstv = [];
			gmarkersv = [];
			gmarkersvt = [];
			htmls = [];
			ohtml= [];
			astar =[];
			iialt =[];
			aimiss =[]; 
			price =[];
			aname =[];
			aurl =[];
			thums = [];
			sider=[];
			i =0;
			loh =0;
            // reset the sidebar
            sidebar_html="<BR><B>" + htms+" </B><BR><BR>";
            loh =markers.length
			if (markers.length>1){
            for (var i = 0; i < markers.length; i++) {
              marker = markerdata(markers[i], bounds);
			  map.addOverlay(marker);}
            // put the assembled sidebar_html contents into the sidebar div
			map.setZoom(map.getBoundsZoomLevel(bounds));
			var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
            var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
            map.setCenter(new GLatLng(clat,clng));
            document.getElementById("sidebar").innerHTML = sidebar_html;
			}
			else if (markers.length==1){
            for (var i = 0; i < markers.length; i++) {
              marker = markerdata(markers[i], bounds);
			  map.addOverlay(marker);}
			  map.setCenter(marker.getPoint());
			document.getElementById("sidebar").innerHTML = sidebar_html;
			  }
			else{
			document.getElementById("sidebar").innerHTML = "There are no <BR>hotels priced <BR>"+htms;
			}
			}
        }
        request.send(null);
      }
    }



