
MQLocation.prototype = new MQBaseLocation;

function MQLocation () {

   var _internalId = getguid();

   this.getId = function() {
      return _internalId;
   }

   this.loadXml = function (strXml,skipId) {
      this.m_xmlDoc = mqCreateXMLDoc(strXml);
      if(!skipId)
      {
         this.setProperty("user1",this.getId());
      }
   }


   this.saveAsRest = function (nCount, prefix, transaction) {

      var strRest = new String;
      var strName = mqurlencode(this.getName());
      var strAddress = mqurlencode(this.getAddress());

      

      if (prefix == null || prefix.toString() == "")
         prefix = "";
      if (nCount == null || nCount.toString() == "")
         nCount="";
      if (transaction == null || transaction.toString() == "")
         transaction="";


      strRest = "&" + prefix + "name" + nCount.toString() + "=" + strName;
      if (this.getAddress() != "")
         strRest += "&" + prefix + "address" + nCount.toString() + "=" + strAddress;
      if (this.getCity() != "")
         strRest += "&" + prefix + "city" + nCount.toString() + "=" + this.getCity();
      if (this.getCounty() != "")
         strRest += "&" + prefix + "county" + nCount.toString() + "=" + this.getCounty();
      if (this.getStateProvince() != "")
         strRest += "&" + prefix + "stateProvince" + nCount.toString() + "=" + this.getStateProvince();
      if (this.getPostalCode() != "")
         strRest += "&" + prefix + "postalCode" + nCount.toString() + "=" + this.getPostalCode();
      if (this.getCountry() != "")
         strRest += "&" + prefix + "country" + nCount.toString() + "=" + this.getCountry();

      var iconid = this.getIconId();
      if (this.getIconSource() != "") {
         iconid = "500";
      }
      if (this.getLatitude() != "")
         strRest += "&" + prefix + "latitude" + nCount.toString() + "=" + this.getLatitude();

      if (this.getLongitude() != "")
         strRest += "&" + prefix + "longitude" + nCount.toString() + "=" + this.getLongitude();

      if (prefix == "poi_") {
         strRest += "&poi_user1_" + nCount.toString() + "=" + this.getId();
      } else if (transaction.toLowerCase() == "poimap") {
         strRest += "&user1=" + this.getId();
      }

      return strRest;
   }
   
   this.getDistance = function(){
		var recordId = this.getRecordId();
		var dist = null;
		if(av){
			if(av.searchResults){
				for(var i=0; i < av.searchResults.getAt.length; i++){
					if(recordId == av.searchResults.getAt[i].recordId)
						return av.searchResults.getAt[i].distance.value + " " + av.searchResults.getAt[i].distance.units;
				}
			}
		}
   
		return dist;
 		
   }

   this.getPhone = function(){
		var recordId = this.getRecordId();
		var loc = null;
		if(av){
			if(av.searchResults){
				for(var i=0; i < av.searchResults.getAt.length; i++){
					if(recordId == av.searchResults.getAt[i].recordId)
					{
						loc = av.searchResults.getAt[i];
						return loc.userFields.user1;
					}
				}
			}
		}
		return "";
 		
   }	
   this.getLocation = function(){
		var recordId = this.getRecordId();
		var loc = null;
		if(av){
			if(av.searchResults){
				for(var i=0; i < av.searchResults.getAt.length; i++){
					if(recordId == av.searchResults.getAt[i].recordId)
					{
						loc = av.searchResults.getAt[i];
						return loc.userFields.user5;
					}
				}
			}
		}
		return "";
 		
   }	
   this.getRetailer = function(){
		var recordId = this.getRecordId();
		var loc = null;
		if(av){
			if(av.searchResults){
				for(var i=0; i < av.searchResults.getAt.length; i++){
					if(recordId == av.searchResults.getAt[i].recordId)
					{
						loc = av.searchResults.getAt[i];
						return loc.userFields.user4;
					}
				}
			}
		}
		return "";
 		
   }	

   this.htmlStr = function (showLink){

      var nm = this.getName();
      var ad = this.getAddress();
      var cy = this.getCity();
      var sp = this.getStateProvince();
      var pc = this.getPostalCode();
      var lng = this.getLongitude();
      var ltd = this.getLatitude();
      var recordId = this.getRecordId();
      var country = this.getCountry();
      var phone = this.getPhone();
      var location = this.getLocation();
      var retailertype = this.getRetailer();
      if(showLink)
      {
	 
         var dnm = (nm=="")?"Click for map":nm;
         var href="?distance=" + this.getDistance() + "&template=map&amp;transaction=locMap&amp;address="+ad+"&amp;city="+cy+"&amp;stateProvince="+sp+"&amp;postalCode="+pc+"&amp;name="+nm+"&recordId="+recordId+"&rollover=2";
         if(lng!="") href+="&amp;longitude="+lng;
         if(ltd!="") href+="&amp;latitude="+ltd;
	 
// Mainak. This points to test server now.
          
href="http://order.yesvideo.com/serviceselector.aspx?Address="+ad+"&City="+cy+"&State="+sp+"&Postcode="+pc+"&PhoneNo="+phone+"&recordId="+recordId+"&LocationCode="+location+"&PartnerId=" +retailertype;

         var htmlString = "<div><b><a class='mqPopupLink' href=\""+href+"\" >" + dnm+"</a></b></div>";
      } else {
         var htmlString = "<div><b>"+nm+"</b></div>";
      }
      if (ad != "")  htmlString = htmlString + "<div>" + ad + "</div>";

      htmlString = htmlString + "<div>";
      if (cy != "")  htmlString = htmlString + cy;
      if (sp != "") {
         if (cy != "") {
            htmlString = htmlString + ", ";
         }
         htmlString = htmlString + sp;
      }
      if (pc != "") {
         if (cy != "" || sp != "") {
            htmlString = htmlString + " ";
         }
         htmlString = htmlString + pc;
         if(country !="")
           htmlString = htmlString + " "+ country.toUpperCase();
      }

      htmlString = htmlString + "</div>";
      return (htmlString);
   }

}


MQLocationCollection.prototype = new MQObjectCollection;

function MQLocationCollection() {

   MQObjectCollection.call(this);
   var transaction = null;

   this.setTransaction = function(strTransaction){
      transaction = strTransaction;
   }

   this.getTransaction = function(){
      return transaction;
   }

   this.loadFromStr = function (strXml, skipId) {

      this.removeAll();
      var xmlDoc = mqCreateXMLDoc(strXml);
      var maxCount = mqGetXPathNodeText(xmlDoc,"/locations/@count");
      var minCount;

      if (__mqcontainer.browser.isIE) {
         minCount = 0;
         maxCount = maxCount - 1;
      } else if (__mqcontainer.browser.isNS) {
         minCount = 1;
      }

      skipId = skipId? true: false;
      for (var count=minCount;count <= maxCount; count++) {
         var loc = new MQLocation();
         loc.loadXml(mqXmlToStr(mqGetNode(xmlDoc,"/locations/location[" + count + "]")),skipId);
         this.add(loc);
      }
   }

   this.loadRemote = function (strUrl) {
      var lrXMLHttp = mqXMLHttpRequest();
      lrXMLHttp.open("GET", strUrl, false);
      lrXMLHttp.send(null);
      this.loadFromStr(mqXmlToStr(lrXMLHttp.responseXML));
   }

   this.xmlStr = function () {
      var strXml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<locations count=\"" + this.getSize() + "\" >";
      for (var count = 0; count < this.getSize(); count++) {
         strXml += mqXmlToStr(mqGetNode(this.getAt(count).m_xmlDoc,"/location"));
      }
      strXml += "</locations>";
      return strXml;
   }

   this.getByName = function (strName) {
      for (var count = 0; count < this.getSize(); count++) {
         if (this.getAt(count).getName() == strName) {
            return this.getAt(count);
         }
      }
      return null;
   }

   this.getByRecordId = function (strId) {
      for (var count = 0; count < this.getSize(); count++) {
         if (this.getAt(count).getRecordId() == strId) {
            return this.getAt(count);
         }
      }
      return null;
   }

   this.getById = function (strId) {
      for (var count = 0; count < this.getSize(); count++) {
         if (this.getAt(count).getId() == strId) {
            return this.getAt(count);
         }
      }
      return null;
   }


   this.updateLL = function (transaction, xmlDoc) {

      var mqGetTextFromNode = (__mqcontainer.browser.isSafari)? mqGetNodeText : mqXmlToStr ;//safari
      var resultsPath = getAdvantageResultPath( transaction );
      var llDoc = mqCreateXMLDoc(mqXmlToStr(mqGetNode(xmlDoc,"/advantage/"+transaction+"/"+resultsPath)));
      var maxCount = mqGetXPathNodeText(llDoc,"/"+resultsPath+"/@count");
      var minCount;
      var loc;
      if (__mqcontainer.browser.isIE) {
         minCount = 0;
         maxCount = maxCount - 1;
      }
      else if (__mqcontainer.browser.isNS) {
         minCount = 1;
      }
      for (var count=minCount;count <= maxCount; count++) {
         ndLoc = mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]");

         if(transaction.toLowerCase() == 'poimap') {
            mqNodeObj = mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]/userFields/user1/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getById(strId);
         } else if(transaction.toLowerCase() != 'search') {
            mqNodeObj = mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]/name/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getByName(strId);
         } else {
            mqNodeObj = mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]/recordId/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getByRecordId(strId);
         }
         if(loc != null) {
            loc.setLatitude(mqGetTextFromNode(mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]/latitude/text()")));
            loc.setLongitude(mqGetTextFromNode(mqGetNode(llDoc,"/"+resultsPath+"/location[" + count + "]/longitude/text()")));
         }
      }

   }

   this.updateXY = function (transaction, xmlDoc) {
      var mqGetTextFromNode = (__mqcontainer.browser.isSafari)? mqGetNodeText : mqXmlToStr;
      var mapPath = getAdvantageMapPath( transaction );
      var xmlDoc = mqCreateXMLDoc(mqXmlToStr(mqGetNode(xmlDoc,mapPath+"/rollover")));
      var maxCount = mqGetXPathNodeText(xmlDoc,"/rollover/@count");
      var minCount;
      var loc;
      if (__mqcontainer.browser.isIE) {
         minCount = 0;
         maxCount = maxCount - 1;
      }
      else if (__mqcontainer.browser.isNS) {
         minCount = 1;
      }
      //zero out pixel coordinates of loc's on the map.
      for (var count=0;count < this.getSize(); count++) {
         loc = this.getAt(count);
         loc.setX("");
         loc.setY("");
      }
      for (var count=minCount;count <= maxCount; count++) {
        if(transaction.toLowerCase() == 'poimap')
        {
            mqNodeObj = mqGetNode(xmlDoc,"/rollover/point[" + count + "]/data/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getById(strId);
         } else if(transaction.toLowerCase() != 'search') {
            mqNodeObj = mqGetNode(xmlDoc,"/rollover/point[" + count + "]/data/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getByName(strId);
         } else {
            mqNodeObj = mqGetNode(xmlDoc,"/rollover/point[" + count + "]/recordId/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getByRecordId(strId);
         }

         if(loc != null) {
            loc.setX(mqGetTextFromNode(mqGetNode(xmlDoc,"/rollover/point[" + count + "]/x/text()")));
            loc.setY(mqGetTextFromNode(mqGetNode(xmlDoc,"/rollover/point[" + count + "]/y/text()")));
         }
      }
   }

   this.loadXY = function (transaction, xmlDoc) {
      var mqGetTextFromNode = (__mqcontainer.browser.isSafari)? mqGetNodeText : mqXmlToStr;
      var mapPath = getAdvantageMapPath( transaction );
      var xmlDoc = mqCreateXMLDoc(mqXmlToStr(mqGetNode(xmlDoc,mapPath+"/rollover")));
      var maxCount = mqGetXPathNodeText(xmlDoc,"/rollover/@count");
      var minCount;
      var locCount=0;
      var loc;
      if (__mqcontainer.browser.isIE) {
         minCount = 0;
         maxCount = maxCount - 1;
      }
      else if (__mqcontainer.browser.isNS) {
         minCount = 1;
      }
      //zero out pixel coordinates of loc's on the map.
      for (var count=0;count < this.getSize(); count++) {
         loc = this.getAt(count);
         loc.setX("");
         loc.setY("");
      }
      for (var count=minCount;count <= maxCount; count++) {
         if(transaction != 'search')
         {
            loc = this.getAt(locCount);
            locCount = locCount + 1;
         }
         else
         {
            mqNodeObj = mqGetNode(xmlDoc,"/rollover/point[" + count + "]/recordId/text()");
            strId = mqGetTextFromNode(mqNodeObj);
            loc = this.getByRecordId(strId);
         }
         if(loc != null) {
            loc.setX(mqGetTextFromNode(mqGetNode(xmlDoc,"/rollover/point[" + count + "]/x/text()")));
            loc.setY(mqGetTextFromNode(mqGetNode(xmlDoc,"/rollover/point[" + count + "]/y/text()")));
         }
      }
   }

}



MQMap.prototype = new MQBaseMap();

function MQMap (strDivName) {

   var revertState;
   this.transaction = "";
   this.maxSearchResults       = "";
   this.setMaxSearchResults = function(strMaxSearchResults) {
     this.maxSearchResults = strMaxSearchResults;
   }

   this.getMaxSearchResults = function(){
     return this.maxSearchResults;
   }

   if( strDivName ) {
      this.init(strDivName);
      this.locations = new MQLocationCollection();
      this.origin = null;
      this.slider = new MQSlider();
      this.pageObj = getElementById("mqpage"+this.UId);
   }
   if (document.getElementById(this.parentDivName) == null)
   {
      this.parentDivName = "map_parent_" + (Math.round((Math.random()*197)+1));
      var bodyObj = document.getElementsByTagName('body').item(0);
      this.parent = createDiv(bodyObj,"",this.parentDivName);
   }
   else
   {
      this.parent = document.getElementById(this.parentDivName);
   }

   this.popup = new MQPopup(this.parentDivName);

   this.setRevertState = function(strRevertState) {
      revertState = strRevertState;
   }

   this.getRevertState = function() {
      return revertState;
   }


   this.generateRQTemplate = function () {
      mapIdObj = getElementById(this.mapImageId);
      width = this.mapState.getWidth();
      height = this.mapState.getHeight();

      strQueryData = "transaction=" + ((this.transaction)?  (this.transaction + "").toLowerCase() : "locmap")+
      (this.getRollOver()? "&rollover="+ this.getRollOver():"")+  "&ambiguities=0" +
      (this.getProxIconId()? "&proxIconId="+this.getProxIconId():"" ) +
       "&init=true"+
      "&click=init&mapid=" + this.mapImageId +
      "&mapstyle=" + this.mapState.getMapStyle() +
      "&pHeight=" + height + "&pWidth=" + width;

		if(av){
			if(av.parameters){
				if(av.parameters.proxIconId){
					strQueryData += "&proxIconId=" + av.parameters.proxIconId;
				}
				if(av.parameters.text2){
				 strQueryData += "&text2=" + av.parameters.text2;
				}
			}
		}

      if (this.transaction == "search" )
      {
         strQueryData += (this.getRadius()? "&radius="+this.getRadius():"" );
         strQueryData += (this.getMaxSearchResults() ? "&maxSearchResults="+this.getMaxSearchResults():"" );

      }
      strQueryData += ((this.locations.getAt(0) && this.origin != null) ? this.locations.getAt(0).saveAsRest("","",this.transaction):"");
      if ( this.transaction == "poiMap")
      {
         var offset = (this.origin != null)? 0 : 1;
         for (var count=1-offset; count < this.locations.getSize(); count++) {
            strQueryData += this.locations.getAt(count).saveAsRest(count+offset , "poi_");
         }
      }
      return strQueryData;
   }


   this.__handleResponse = function (strAdvantageXML) {

      var flag = 1;
      var transaction ;
      var resultsDoc ;
      var proxIconId;
      var orgZoomLevel = "";
      var id = this.mapImageId;
      if (__mqcontainer.browser.isSafari)
      strAdvantageXML = strAdvantageXML.replace(/&amp;/g, "&");
      var xmlDoc = mqCreateXMLDoc(strAdvantageXML);

      var xmlDocLower = mqCreateXMLDoc(strAdvantageXML.toLowerCase());
      /*** Error Handling routine ***/

      var errorCode = mqGetXPathNodeText(xmlDoc,"/advantage/error/code");
      if (errorCode != "") {
         this.__handleError(strAdvantageXML);
         return;
      }

      /*** Creation of DOM for loading map objects ***/

      if(mqGetNode(xmlDoc,"/advantage/locMap")) {
         transaction = "locMap";
         locationsDoc = mqGetNode(xmlDoc,"/advantage/locMap/locations");
         resultsDoc = mqGetNode(xmlDoc,"/advantage/locMap/locations");
         var orgZ = mqGetXPathNodeText(xmlDoc,"/advantage/locMap/parameters/orgZoomLevel");
         orgZoomLevel = orgZ ? orgZ: "";
      }
      else if(mqGetNode(xmlDoc,"/advantage/poiMap")) {
         transaction = "poiMap";
         locationsDoc = mqGetNode(xmlDoc,"/advantage/poiMap/locations");
         resultsDoc=mqCreateXMLDoc(mqXmlToStr(mqGetNode(xmlDoc,"/advantage/poiMap/poiResults")));
      }
      else if(mqGetNode(xmlDoc,"/advantage/search")) {
         transaction = "search";
         locationsDoc = mqGetNode(xmlDoc,"/advantage/search/locations");
         resultsDoc=mqCreateXMLDoc(mqXmlToStr(mqGetNode(xmlDoc,"/advantage/search/searchResults")));
      }

      var mapPath = getAdvantageMapPath(transaction);
      var mapBrowse = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/mapBrowse");
      var rollover = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/rollover");
      var init = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/init");
      var maxSearchResults = mqGetXPathNodeText(xmlDocLower,"/advantage/"+transaction+"/parameters/maxsearchresults");
      //var searchSessionId = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/searchsessionid");
      var isMQInit = (init=="true") ? true : false;
      var hasWidget = getElementById(id+"-widget")? true : false;

      /*** Load values related to the map state and transaction ***/
      if(!(isMQInit && hasWidget ))
      {
         this.orgMapState.load(xmlDoc, mapPath);
         if(orgZoomLevel != "")
         {
            this.orgMapState.setZoomLevel(orgZoomLevel);
         }

         if(getElementById("orgZoomLevel")) {
              getElementById("orgZoomLevel").value=this.orgMapState.getZoomLevel();
          }
         this.transaction = transaction;
         this.setRollOver(rollover);
         this.setProxIconId(proxIconId);
         if(!hasWidget) {
            this.renderMap();
            mapInit(id,this);
         }
      }
      this.mapState.load(xmlDoc, mapPath);
      this.centerlatapi = this.mapState.getLatitude();
      this.centerlngapi = this.mapState.getLongitude();
      this.maxSearchResults = maxSearchResults;
      var zoomLvlId = getElementById(id+"-z"+ this.mapState.getZoomLevel());
      zoomLvlId.className="mqZ_hover";
      if (transaction=='search')
         this.setRadius(mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/radius"));

      mapObj = getElementById("mapcontainer" + this.UId);

      this.transaction = transaction;
      this.setRollOver(mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/rollover"));


      if(mqGetNode(xmlDoc,"/advantage/locMap")||mqGetNode(xmlDoc,"/advantage/search")) {
         var revState = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/revertState");
         var clickSet = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/parameters/clickSet");
         revState = (revState && revState==1)? 1 : 0;
         if(revState==1){
          var zoomLvlId = getElementById(id+"-z"+ this.mapState.getZoomLevel());
          zoomLvlId.className="mqZ_hover";
         }
         this.setRevertState(revState);
         if(getElementById("mapSessionId")){
            getElementById("mapSessionId").value=this.mapState.getSessionId();
         }
         if(document.prev&&document.prev.url) {
         document.prev.url.value +="&mapSessionId="+this.mapState.getSessionId();
         }
         if(document.next&&document.next.url) {
            document.next.url.value +="&mapSessionId="+this.mapState.getSessionId();
         }
         if(getElementById(id + "-" + clickSet))
           getElementById(id + "-" + clickSet).checked = 'true';

      }


      /*** Hide popup if any, clear the transparent layers over POIs ***/

      var size = this.locations.getSize();
      this.popup.hide(1);
      for (var i=0; i < size ;i++)
      {
         var currentLocation = this.locations.getAt(i);
         if (currentLocation.poiLayer)
         {
            oldLayer = document.getElementById(currentLocation.poiLayer.id);
            mapObj.removeChild(oldLayer);
            currentLocation.poiLayer = null;
         }
      }

      /*** Handle the response based on user's action ***/

      if(isMQInit) {

         var mapUrl = this.mapState.getMapUrl();

         if(mapBrowse.indexOf("pan") >= 0)
         {
            var pan = mapBrowse.split('_')[1];
            this.callSlideImage(pan);

         }
         else if(mapBrowse == "center")
         {
            this.callSlideImage();

         }
         else if(mapBrowse == "center_zoom")
         {
            this.swapImage();

         }
         else if(mapBrowse.indexOf("zoom") >= 0)
         {
            this.swapImage();

         }
         else
         {
            if(getElementById(id))
            {
               flag = 1;
               showMapWidget(id);
               this.swapImage();
               this.toggleRevert(0);
               getElementById(id).style.top = "0px";
               getElementById(id).style.left = "0px";
            }
         }
         if(getElementById(id))
            setZoomLevel(this.mapState.getZoomLevel(), id);
      }


      if(document.getElementById("mapBrowse"))
         document.getElementById("mapBrowse").value=mapBrowse;





      /*** Load the location collection from the response ***/



      if(!(isMQInit && hasWidget ))
      {


         var resultsPath = getAdvantageResultPath(transaction);
         if(locationsDoc != null)
         {
             if(transaction != 'search')
                  this.locations.loadFromStr(mqXmlToStr(locationsDoc));
             else
                  this.locations.loadFromStr(mqXmlToStr(locationsDoc, false));
             this.origin = this.locations.getAt(0);
         }
         this.locations.setTransaction(transaction);

         if(transaction != 'locMap')
         {
            var maxCountpoi = mqGetXPathNodeText(xmlDoc,"/advantage/"+transaction+"/"+resultsPath+"/@count");

            var minCountpoi;

            if (__mqcontainer.browser.isIE) {
               minCountpoi = 0;
               maxCountpoi = maxCountpoi - 1;
            }
            else if (__mqcontainer.browser.isNS) {
               minCountpoi = 1;
            }
            for (var count=minCountpoi;count <= maxCountpoi; count++)
            {
               ndLoc = mqGetNode(resultsDoc ,"/"+resultsPath+"/location[" + count + "]");
               loc = new MQLocation();

               if(transaction != 'search')
               {
                  loc.loadXml(mqXmlToStr(ndLoc));
               }
               else
               {
                  loc.loadXml(mqXmlToStr(ndLoc),false);
               }
               this.locations.add(loc);
            }
         }

         this.locations.loadXY(transaction, xmlDoc);

      } else {

         /*** Update lat/lngs and rollover points in location collection ***/
         this.locations.updateLL(transaction, xmlDoc);
         this.locations.updateXY(transaction, xmlDoc);
      }

      if(flag)
      {
         this.placeLayers(this.popup);
      }
      if (this.getMapCallback != null) {
         eval(this.getMapCallback)(this);
      }

   }

   this.getNewMap = function (fData)
   {
      var __mqcontainerUrl = "";
      var browseval;
      var zoomlevel;
      if(typeof(fData) == "object")
      {
         switch(fData.action)
         {
            case "drag":
               __mqcontainerUrl += this.generateRQTemplate();
               __mqcontainerUrl += "&mapBrowse=center";
               __mqcontainerUrl += "&x=" + fData.x + "&y=" + fData.y;
               __mqcontainerUrl += "&mapSessionID=" + this.mapState.getSessionId();
               break;

            case "pan":
               __mqcontainerUrl += this.generateRQTemplate();
               __mqcontainerUrl += "&pan=" + fData.change;
               __mqcontainerUrl += "&mapSessionID=" + this.mapState.getSessionId();
               __mqcontainerUrl += "&mapBrowse=" + fData.action + "_" + fData.change;
               __mqcontainerUrl += "&zoomLevel="+this.mapState.getZoomLevel();
               break;

            case "zoom":
               __mqcontainerUrl += this.generateRQTemplate();
               __mqcontainerUrl += "&zoomLevel=" + parseInt(fData.change);
               __mqcontainerUrl += "&mapSessionID=" + this.mapState.getSessionId();
               __mqcontainerUrl += "&dupSession=1";
               __mqcontainerUrl += "&mapBrowse=" + fData.action + "_" + parseInt(fData.change);
               break;

            case "center":
               __mqcontainerUrl += this.generateRQTemplate();
               if(fData.change==0) {
                  __mqcontainerUrl += "&dupSession=1";
                  if(this.mapState.getZoomLevel() <10){
                     zoomlevel = eval(parseInt(this.mapState.getZoomLevel()) + 1);
                  }
                  else
                     zoomlevel = this.mapState.getZoomLevel();
                  __mqcontainerUrl += "&zoomLevel=" + zoomlevel;
                  browseval = "zoom_"+zoomlevel;
               }
               else if(fData.change==1){
                  browseval = "center";
                  __mqcontainerUrl += "&x=" + fData.x + "&y=" + fData.y;
               }
               else if(fData.change==2){
                  browseval = "center_zoom";
                  __mqcontainerUrl += "&x=" + fData.x + "&y=" + fData.y;
               }
               __mqcontainerUrl += "&mapBrowse="+browseval;
               __mqcontainerUrl += "&mapSessionID=" + mq.mapState.getSessionId();
               break;

            case "resize":
               __mqcontainerUrl += "pHeight=" + fData.height + "&pWidth=" + fData.width;
               break;

            case "revert":
               __mqcontainerUrl += this.generateRQTemplate();
               if(getElementById("orgZoomLevel") && getElementById("orgZoomLevel").value!="")
               {
                  __mqcontainerUrl += "&zoomLevel=" + getElementById("orgZoomLevel").value;
               }
               else
               {
                  __mqcontainerUrl += "&zoomLevel=" + this.orgMapState.getZoomLevel();
               }
               break;

            default:
               return;
         }
         if (fData.action != "revert" && this.transaction == "search" )
         {
            if( this.centerlatapi)
            {
               __mqcontainerUrl += "&mapLatitude=" + this.centerlatapi + "&mapLongitude=" + this.centerlngapi;
            }
         }
         if((fData.action != "resize") && (fData.action != "revert"))
         {   // enable revert
            this.toggleRevert(1);
         }
      }
      else
      {
         return;
      }
      __mqcontainerUrl += "&rand=" + (Math.round((Math.random() * 10000)));
      getAdvantageXml(__mqcontainerUrl,this);
   }

   this.renderMap = function()
   {
      UId = this.UId;
      parentId = this.parentDivName;
      var wrap_map = parseInt(this.width) + 22;
      var wrap_size = wrap_map + 70;
      var spacer_ns = (this.orgMapState.getWidth() - 98)/2;
      var spacer_ew = (this.orgMapState.getHeight() - 98)/2;

      // TO GET WIDGET ADJUSTABLE.


      var height = this.orgMapState.getHeight();
      var width = this.orgMapState.getWidth();
      var mapUrl = this.orgMapState.getMapUrl();

      var minWidth = "463";
      var maxWidth = "1400";
      var paddingWidth = "12";
      var optionsWidth = "41";
      var sideWidth = "28";
      var gapWidth = "5";
      var widgetMinWidth = minWidth + optionsWidth + paddingWidth+ sideWidth + gapWidth;
      var widgetMaxWidth = maxWidth + optionsWidth + paddingWidth+ sideWidth + gapWidth;
      var nsSpacerOffset = 49 + 15 + 76 + 11 + 52 - sideWidth;
      var ewSpacerOffset = 37 + 13 + 76 + 10 + 37;
      var newMapWidth = Math.round(eval(width) + eval(optionsWidth) + eval(paddingWidth) + eval(sideWidth) + eval(gapWidth));
      var newMapHeight = Math.round(eval(height) + 4 + 32 + 22);
      var mapWellWidth = newMapWidth;
      var wrapperWidth = mapWellWidth;
      document.getElementById(parentId).style.height=newMapHeight+"px";
      document.getElementById(parentId).style.width=newMapWidth+"px";
      parentDivId = parentId;


      Mainparent  = document.getElementById(parentDivId);

      var mapImgId = "map"+UId;
      var m1wrapDiv = createDiv(Mainparent,"mqClear",mapImgId +"-wrapper");
      var mapwidgetDiv = createDiv(m1wrapDiv,"mqMapwidget",mapImgId +"-widget");
      mapwidgetDiv.style.width = mapWellWidth+'px';
      var mapctrlsDiv = createDiv(mapwidgetDiv,"mqMapcontrols",mapImgId +"-controls");
      mapctrlsDiv.style.width = eval(width) + eval(sideWidth) +'px';

      var nsSpacerWidth  =Math.round((eval(width) - eval(nsSpacerOffset)) / 2);

      var ewSpacerHeight =Math.round((eval(height) - eval(ewSpacerOffset)) / 2)-1;

      var d1,d2;

      if(eval(eval(width)-eval(nsSpacerOffset))/2 == nsSpacerWidth)
      d1 = 0;
      else
      d1 =1;

      if(eval(eval(height)-eval(ewSpacerOffset))/2 == ewSpacerHeight)
      d2 = 0;
      else
      d2 =1;



      // Div and images for nw-n-ne
      var ndirDiv = createImgDiv(mapctrlsDiv,"","",16,"","","");
      ndirDiv.className = "mqNw-n-ne";
      var nwImg = createImgDiv(ndirDiv,"",49,16,mapImgId +"-nw","","Pan Northwest");
      nwImg.className = "mqNw";
      nwImg.title = "Pan Northwest";
      var nxnwImg = createImgDiv(ndirDiv,"",15,16,mapImgId +"-nxnw","","Pan Northwest");
      nxnwImg.className = "mqNxnwc mqNxnw";
      nxnwImg.title = "Pan Northwest";
      var nspaImg = createImgDiv(ndirDiv,"",nsSpacerWidth,16,mapImgId +"-na","","Pan North");
      nspaImg.className = "mqNa";
      nspaImg.title = "Pan North";
      var nImg = createImgDiv(ndirDiv,"",76,16,mapImgId +"-n","","Pan North");
      nImg.className = "mqN";
      nImg.title = "Pan North";
      var nspbImg = createImgDiv(ndirDiv,"",eval(nsSpacerWidth) - eval(d1),16,mapImgId +"-nb","","Pan North");
      nspbImg.className = "mqNb";
      nspbImg.title = "Pan North";
      var nxneImg = createImgDiv(ndirDiv,"",11,16,mapImgId +"-nxne","","Pan Northeast");
      nxneImg.className = "mqNxnec mqNxne";
      nxneImg.title = "Pan Northeast";
      var neImg = createImgDiv(ndirDiv,"",52,16,mapImgId +"-ne","","Pan Northeast");
      neImg.className = "mqNe";
      neImg.title = "Pan Northeast";
      // wrapper div for w-map-e
      var ewdirDiv = createDiv(mapctrlsDiv,"mqW-map-e mqClear","");
      // Div and images for west
      var wDiv = createDiv(ewdirDiv,"mqWest",mapImgId +"-west");
      var wnwImg = createImgDiv(wDiv,"w",12,37,mapImgId +"-wnw","","Pan Northwest");
      wnwImg.className = "mqWnw";
      wnwImg.title = "Pan Northwest";
      var wxnwImg = createImgDiv(wDiv,"",12,13,mapImgId +"-wxnw","","Pan Northwest");
      wxnwImg.className = "mqWxnwc mqWxnw";
      wxnwImg.title = "Pan Northwest";
      var wspaImg = createImgDiv(wDiv,"",12,eval(ewSpacerHeight) + eval(d2),mapImgId +"-wa","","Pan West");
      wspaImg.className = "mqWa";
      wspaImg.title = "Pan West";
      var wImg = createImgDiv(wDiv,"",12,76,mapImgId +"-w","","Pan West");
      wImg.className = "mqW";
      wImg.title = "Pan West";
      var wspbImg = createImgDiv(wDiv,"",12,ewSpacerHeight,mapImgId +"-wb","","Pan West");
      wspbImg.className = "mqWb";
      wspbImg.title = "Pan West";
      var wxswImg = createImgDiv(wDiv,"",12,10,mapImgId +"-wxsw","","Pan Southwest");
      wxswImg.className = "mqWxswc mqWxsw";
      wxswImg.title = "Pan Southwest";
      var wswImg = createImgDiv(wDiv,"",12,37,mapImgId +"-wsw","","Pan Southwest");
      wswImg.className = "mqWsw";
      wswImg.title = "Pan Southwest";
      // Div and images for map
      var mDiv = createDiv(ewdirDiv,"mqMiddle","mapcontainer"+UId);
      mDiv.style.clip = "rect(0px," + String(eval(width) + 2) + "px," + String(eval(height) + 2) + "px,0px)";
      mDiv.style.height = String(height) + "px";
      mDiv.style.width = String(width) + "px";


      map1Img = createImg(mDiv,mapUrl,width,height,mapImgId,"map","");
      map1Img.style.position = "absolute";
      map1Img.style.left="0";
      map1Img.style.top="0";
      map0Img = createImg(mDiv,"",0,0,"map0"+UId,"map","");
      map0Img.style.position = "absolute";
      map0Img.style.zindex = "-1";
      map0Img.style.visibility = "hidden";
      map0Img.style.left="0px";
      map0Img.style.top="0px";

      // Div and images for east
      var eDiv = createDiv(ewdirDiv,"mqEast",mapImgId +"-east");
      var eneImg = createImgDiv(eDiv,"",16,37,mapImgId +"-ene","","Pan Northeast");
      eneImg.className = "mqEne";
      eneImg.title = "Pan Northeast";
      var exneImg = createImgDiv(eDiv,"",16,13,mapImgId +"-exne","","Pan Northeast");
      exneImg.className = "mqExnec mqExne";
      exneImg.title = "Pan Northeast";
      var espaImg = createImgDiv(eDiv,"",16,eval(ewSpacerHeight) + eval(d2),mapImgId +"-ea","","Pan East");
      espaImg.className = "mqEa";
      espaImg.title = "Pan East";
      var eImg = createImgDiv(eDiv,"",16,76,mapImgId +"-e","","Pan East");
      eImg.className = "mqE";
      eImg.title = "Pan East";
      var espbImg = createImgDiv(eDiv,"",16,ewSpacerHeight,mapImgId +"-eb","","Pan East");
      espbImg.className = "mqEb";
      espbImg.title = "Pan East";
      var exseImg = createImgDiv(eDiv,"",16,10,mapImgId +"-exse","","Pan Southeast");
      exseImg.className = "mqExsec mqExse";
      exseImg.title = "Pan Southeast";
      var eseImg = createImgDiv(eDiv,"",16,37,mapImgId +"-ese","","Pan Southeast");
      eseImg.className = "mqEse";
      eseImg.title = "Pan Southeast";
      // Div and images for south
      var sdirDiv = createImgDiv(mapctrlsDiv,"","",16,"","","");
      sdirDiv.className = "mqSw-s-se";
      var swImg = createImgDiv(sdirDiv,"",49,16,mapImgId +"-sw","","Pan Southwest");
      swImg.className = "mqSw";
      swImg.title = "Pan Southwest";
      var sxswImg = createImgDiv(sdirDiv,"",15,16,mapImgId +"-sxsw","","Pan Southwest");
      sxswImg.className = "mqSxswc mqSxsw";
      sxswImg.title = "Pan Southwest";
      var sspaImg = createImgDiv(sdirDiv,"",nsSpacerWidth,16,mapImgId +"-sa","","Pan South");
      sspaImg.className = "mqSa";
      sspaImg.title = "Pan South";
      var sImg = createImgDiv(sdirDiv,"",76,16,mapImgId +"-s","","Pan South");
      sImg.className = "mqS";
      sImg.title = "Pan South";
      var sspbImg = createImgDiv(sdirDiv,"",eval(nsSpacerWidth) - eval(d1),16,mapImgId +"-sb","","Pan South");
      sspbImg.className = "mqSb";
      sspbImg.title = "Pan South";
      var sxseImg = createImgDiv(sdirDiv,"",11,16,mapImgId +"-sxse","","Pan Southeast");
      sxseImg.className = "mqSxsec mqSxse";
      sxseImg.title = "Pan Southeast";
      var seImg = createImgDiv(sdirDiv,"",52,16,mapImgId +"-se","","Pan Southeast");
      seImg.className = "mqSe";
      seImg.title = "Pan Southeast";

      // form at bottom click...



      var clickForm = document.createElement("form");
      mapctrlsDiv.appendChild(clickForm);
      clickForm.action = "#";
      clickForm.id = mapImgId +"-mapclick";
      clickForm.appendChild(document.createTextNode("Clicking on map will:"));
      var zoomin = null;
      var clickrcz = null;
      if (__mqcontainer.browser.isIE) {
      zoomin = document.createElement("<input name='clickAction'>");
      } else if (__mqcontainer.browser.isNS) {
      zoomin = document.createElement("input");
      zoomin.name = "clickAction";
      }
      zoomin.type = 'radio';
      clickForm.appendChild(zoomin);
      zoomin.id = mapImgId + "-clickzoom";
      zoomin.value = "zoom";
      zoomin.checked=false;
      removeEvent(zoomin, "click", clickSetting);
      addEvent(zoomin, "click", clickSetting);

      var zoominLbl = document.createElement("label");
      zoominLbl.setAttribute("for",zoomin.id);
      zoominLbl.appendChild(document.createTextNode("Zoom In"));
      clickForm.appendChild(zoominLbl);


      var clickrc = null;
      if (__mqcontainer.browser.isIE) {
      clickrc = document.createElement("<input name='clickAction'>");
      } else if (__mqcontainer.browser.isNS) {
      clickrc = document.createElement("input");
      clickrc.name = "clickAction";
      }

      clickrc.type = 'radio';
      clickForm.appendChild(clickrc);
      clickrc.id = mapImgId +"-clickrecenter";
      clickrc.value = "recenter";
      clickrc.checked=true;
      removeEvent(clickrc, "click", clickSetting);
      addEvent(clickrc, "click", clickSetting);

      var clickrcLbl = document.createElement("label");
      clickrcLbl.setAttribute("for",clickrc.id);
      clickrcLbl.appendChild(document.createTextNode("Re-Center"));
      clickForm.appendChild(clickrcLbl);

      if (__mqcontainer.browser.isIE) {
      clickrcz = document.createElement("<input name='clickAction'>");
      } else if (__mqcontainer.browser.isNS) {
      clickrcz = document.createElement("input");
      clickrcz.name = "clickAction";
      }
      clickrcz.type = 'radio';
      clickForm.appendChild(clickrcz);
      clickrcz.id =  mapImgId + "-clickrecenterzoom";
      clickrcz.value = "center_zoom";
      clickrcz.checked=false;
      removeEvent(clickrcz, "click", clickSetting);
      addEvent(clickrcz, "click", clickSetting);

      var clickrczLbl = document.createElement("label");
      clickrczLbl.setAttribute("for",clickrcz.id);
      clickrczLbl.appendChild(document.createTextNode("Re-Center and Zoom In"));
      clickForm.appendChild(clickrczLbl);



      // Zoom options to left side
      var mapoptsDiv = createDiv(mapwidgetDiv,"mqMapoptions",mapImgId +"-options");
      var mzoom = createDiv(mapoptsDiv,"mqZoom",mapImgId +"-zoom");
      mzoom.style.marginTop = Math.round((eval(height) + 32 - 259) / 2) + "px";
      mzoom.style.position = "relative";
      mzoom.style.width = optionsWidth + "px";
      var zinImg = createImgDiv(mzoom,"",41,46,mapImgId +"-zin","","Zoom In");
      zinImg.className="mqZin";
      var z110Div = createDiv(mzoom,"","");
      var z10Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z10","","Zoom Level 10");
      z10Img.className = "mqZ10";
      var z9Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z9","","Zoom Level 9");
      z9Img.className = "mqZ9";
      var z8Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z8","","Zoom Level 8");
      z8Img.className = "mqZ8";
      var z7Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z7","","Zoom Level 7");
      z7Img.className = "mqZ7";
      var z6Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z6","","Zoom Level 6");
      z6Img.className = "mqZ6";
      var z5Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z5","","Zoom Level 5");
      z5Img.className = "mqZ5";
      var z4Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z4","","Zoom Level 4");
      z4Img.className = "mqZ4";
      var z3Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z3","","Zoom Level 3");
      z3Img.className = "mqZ3";
      var z2Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z2","","Zoom Level 2");
      z2Img.className = "mqZ2";
      var z1Img = createImgDiv(z110Div,"",32,17,mapImgId +"-z1","","Zoom Level 1");
      z1Img.className = "mqZ1";
      var zoutImg = createImgDiv(mzoom,"",optionsWidth,43,mapImgId +"-zout","","Zoom Out");
      zoutImg.className = "mqZout";

      var rvtImg = createImgDiv(mzoom,"",optionsWidth,26,mapImgId +"-revert","","");
      //rvtImg.style.marginTop += Math.round((eval(height) + 32 - 259) / 2);
      rvtImg.style.display = "block";
      rvtImg.style.position = "relative";
      rvtImg.className = "mqRevert";
      var finclrDiv = createDiv(Mainparent,"mqClear","");

   }
   this.__handleError = function (strAdvantageXML) {
      var xmlDoc = mqCreateXMLDoc(strAdvantageXML);
      var error_code = mqGetXPathNodeText(xmlDoc,"/advantage/error/code");
      var error_desc = mqGetXPathNodeText(xmlDoc,"/advantage/error/text");
      if(error_code == 500)
      {
         if(confirm("Your session has expired. Please click OK to restart your session"))
         {
           var url = this.generateRQTemplate() + "&zoomLevel=" + this.mapState.getZoomLevel();
           newMapXml = getAdvantageXml(url,this);
         }
      }
      else if (error_code < 9000 && error_code > 9002)
      {
         alert("Error: " + error_code +" - "+ error_desc);
      }
   }
}


