function startpopupDoc() {
	 return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">'+'<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></script><link rel="stylesheet" href="/global/css/icc.css" /><title>Property Location - Google Maps</title></head><body>';
};

function endpopupDoc() {
	 return '</div></body></html>';
};

function prepareMap( postcode,balloon ) {
	
		return '<div class="mapholder"><iframe width="600" height ="300" SRC="http://bert.dezrez.com/utilities/map.asp?postcode='+postcode+'&Balloon=<address>'+balloon+'</address>&SHOWTEXTURE=1" style="oveflow:auto" frameborder="0"></iframe></div>';

}

function pic_onclick(theSrc) {
     var mainpicturestore;
     browserMake = navigator.appName.charAt(0) ;
     if(browserMake == 'M')	{
        mainpicturestore = mainpic.src;

	var tmpSrc = theSrc.src;
	// Width needs to be modded
        var myRegExp = /Width=140/;
	tmpSrc = tmpSrc.replace(myRegExp,"Width=340");	   
        mainpic.src = tmpSrc;

	tmpSrc = mainpicturestore;
        var myRegExp = /Width=340/;
	tmpSrc = tmpSrc.replace(myRegExp,"Width=140");	   
 	
        theSrc.src = tmpSrc;
     } 
     else {
      mainpicturestore = document.mainpic.src;

      	var tmpSrc = theSrc.src;
	// Width needs to be modded
        var myRegExp = /Width=140/;
	tmpSrc = tmpSrc.replace(myRegExp,"Width=340");	   

	document.mainpic.src = tmpSrc;

	tmpSrc = mainpicturestore;
        var myRegExp = /Width=340/;
	tmpSrc = tmpSrc.replace(myRegExp,"Width=140");	   

	theSrc.src = tmpSrc;
     }
}


// Function to create the marker and set up the event window
function createMarker(mtype,lat,long,name,phone,address,zip,price,img,detail) {

   var point = new GLatLng(lat,long);
   var markerhtml = getInfoHTML(mtype,name,phone,address,zip,price,img,detail);


   var icon = new GIcon();
   switch(mtype) {
      case 2:
      	      icon.image = "/global/images/icons/estateagent.png";
	      icon.iconSize = new GSize(20, 19);
	      icon.iconAnchor = new GPoint(20, 19);
	      icon.infoWindowAnchor = new GPoint(5, 1);
              break;
      default:	   
      	      icon.image = "/global/images/icons/house2.png";
	      icon.iconSize = new GSize(13, 13);
	      icon.iconAnchor = new GPoint(6, 10);
	      icon.infoWindowAnchor = new GPoint(5, 1);
              break;

   }   

   // Create the map marker
   var marker = new GMarker(point,{icon:icon,title:name+ ' '+price});

   // Add a click event to each marker which will open the HTML window
   GEvent.addListener(marker, "click", function() {
       marker.openInfoWindowHtml(markerhtml);
    });

   // Add a click event to each marker which will open the HTML window
   GEvent.addListener(marker, "mouseover", function() {
       var promptHTML = '';
       document.getElementById('mappromptImg').innerHTML = '<img src="'+icon.image+'" width="13" height="13"/>';
       promptHTML += name;

        var myRegExp = /<br\/>/g;
        address = address.replace(myRegExp,"");
       if ( address && address !='' ) promptHTML+=', '+address;
       if ( zip && zip !='' ) promptHTML+=', '+zip;
       if ( price && price !='' ) promptHTML+=' '+price;
       if ( phone && phone !='' ) promptHTML+=' Tel: '+phone;
       document.getElementById('mapprompt').innerHTML = promptHTML;
    });
   
   return marker;
}

function getInfoHTML(type,name,phone,address,zip,price,img, detailLink) {
   // Create the HTML text based on the values passed in from XML
   var markerhtml = "<div class='googleInfoBubble'> ";

   if ( img && img != '' || ( type == 2 ) ) markerhtml ="<div class='googleInfoBubbleWide'> ";
   
   if ( img && img !=''  ) markerhtml += '<div class="thumbImg"><img class="googleBubbleThumb" src="' + img + '"> </img></div>';

   if ( img && img != '' || ( type != 2) ) markerhtml += '<div class="propInfoWide">';
   if ( img && img == '' && (type != 2)) markerhtml += '<div class="propInfo">';
   if ( type == 2) markerhtml += '<div class="officeInfo">';
   if (name != "") markerhtml += "<b>" + name + "</b><br>";

   markerhtml += address + "<br>" + " " + zip + "<br>";
   if (phone != "") markerhtml += "Phone: " + phone + "<br>";
   if (price != "") markerhtml += "<br/>"+ price + "<br/>";
   if (detailLink && detailLink !="")  markerhtml += '<a href="'+ detailLink + '">View Detail</a>';
   markerhtml += "</div>";
   markerhtml += " </div>";
   return markerhtml;
}

function print_property() {
  var qs = new Querystring();
  var thisID = qs.get("id");
  if ( !thisID ) {
     alert('There was an error printing this page. Property Reference not found.');
     return 0;
  }
  var thisAction = qs.get("action");
  if ( !thisAction ) {
     alert('There was an error printing this page. Action not found.');
     return 0;
  }
  var tmpLocation = window.location.href;
  tmpLocation = tmpLocation.replace("#","&print=1");
  if ( tmpLocation.indexOf('print') == -1)  {
     tmpLocation = tmpLocation+'&print=1';
  }
  window.open(tmpLocation, 'Print','top=360, left=400, width=300, height=50, scrollbars=no, resizable=yes');
  return false;
}


function Querystring(qs) { // optionally pass a querystring to parse
        this.params = new Object()
        this.get=Querystring_get

        if (qs == null)
                qs=location.search.substring(1,location.search.length)

        if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
        qs = qs.replace(/\+/g, ' ')
        var args = qs.split('&') // parse out name/value pairs separated via &

// split out each name=value pair
        for (var i=0;i<args.length;i++) {
                var value;
                var pair = args[i].split('=')
                var name = unescape(pair[0])

                if (pair.length == 2)
                        value = unescape(pair[1])
                else
                        value = name

                this.params[name] = value
        }
}

function Querystring_get(key, default_) {
        // This silly looking line changes UNDEFINED to NULL
        if (default_ == null) default_ = null;

        var value=this.params[key]
        if (value==null) value=default_;

        return value
}
