(function($){$.widget("MMI.MapLayer",$.extend({},{_init:function(){this.som=null;this.geo=null;this.context=null;this.showCategories=null;this.requestFilter=false;this.markerFactory=new Array;this.searchparam=$("input[name=isearch]","#gSearch");L.Layer("searchBinder",{refer:this})},inAndOutAction:function(){var a=this;$(this.element[0]).unbind("zoom.boundsChanged");$(this.element[0]).unbind("center.boundsChanged");$(this.element[0]).bind("zoom.boundsChanged, center.boundsChanged",function(a){a.stopPropagation();a.preventDefault();if(L.Layer("levelOrCenterStatus")){if(!somaction){var b=L.Layer("pastprocess");if(b!=null&&b.q=="202"){var c=b.search.split("*");c.pop();c.push("current map view");b.search=c.join("*");internal=true;somaction=true;L.Layer("postprocess",{param:b})}}}else{internal=false;L.Layer("zoomAndAction",{more:false,csom:true,slideup:true})}})},setGeo:function(a){this.geo=a.param;delete a},searchUseful:function(){var a=$(".poi_rtxt span");a.unbind().click(function(a){a.stopPropagation();var b=new Array;b.push($(this).html().toLowerCase());b.push("current map view");AC.release(a);var c=new mGeo;c.q=201;c.search=b.join("*");AC.release(b);M.MapLayer("setValue",{prompt:true,request:c,post:true,title:b.join(" in ")});AC.release(b)})},search:function(a){var b=$("#isearch",a.process).val();if(b.length==0){L.Layer("loadPrompt",{flag:"e_"});$("body").APL({action:0});return}var c=null;var d=new mGeo;var e=true;if(b.match(/(start directions from |directions from |direction from |start route from |route from |from | to | via )/gi)){c=b.split(/(start directions from |directions from |direction from |start route from |route from |from )/gi);if(c.length==3)c.splice(0,2);if(c.length==1){var f=c[0].split(/ to /);if(f.length==2){c=null;c=new Array;var g=f[0].split(" via ");var h=null;if(g.length==1){h=f[1].split(" via ");if(h.length>1){c.push(f[0]);for(var i=1;i<h.length;i++)c.push(h[i]);c.push(h[0])}else{c=g;c.push(f[1])}}else{c=null;c=g;c.push(f[1])}e=false;d.q=300;if(a.enroute)d.enroute=a.enroute;d.search=c.join("*")}}}if(e==true&&b.match(/( in | around | nearby )/gi)){c=b.split(/( in | around | nearby )/gi);if(c.length==3){c.splice(1,1);d.q=200;d.search=c.join("*");e=false}}if(e){b=$.trim(b);d.q=b.length==6&&b.match(/[a-zA-Z0-9]{6}/ig)?102:100;d.search=b}if(this.geo!=null&&this.geo.length>0){d.geo=this.geo;this.geo=null}d["common"]=true;if($("#autosel").val()!="yes"){this.postprocess.call(this,{param:d,direct:true,link:typeof a.link=="undefined"?true:a.link})}return false},postprocess:function(a){L.Layer("zoomAndAction",{more:false});internal=true;L.Layer("postprocess",a)},getShareUrl:function(a){var b=new Array;try{var c=window.location.toString();var d=c.indexOf("#");if(d>-1&&a.flag!=false&&c.length!=d+1){b.push(c)}else{var e=$(this.element[0]).MireoMap("getCenter");var f=$(this.element[0]).MireoMap("getZoomLevel");if(a.flag==false){b.push(BASE);b.push("index.html")}else{b.push(c.split("#")[0])}b.push("?layer=");b.push(layer)}b.push("#current:");b.push(f);b.push(",");b.push(e.x);b.push(",");b.push(e.y)}catch(g){}return b.join("")},_buildPrint:function(){var a=this.options.ie>6?910:900;var b=$(window).height();var c=L.Layer("currentUrl").split("#")[1];var d=[];d.push(BASE);d.push("screenshot.html?layer=");d.push(layer);d.push("#");d.push(c);var e=new Array;e.push("width=");e.push(Math.ceil(a));e.push("px,height=");e.push(Math.ceil(b));e.push("px,scrollbars=yes,resizable=yes,menubar=yes");window.open(d.join(""),"",e.join(""));AC.release(e);L.Layer("mbuildlog",{type:"Print",url:c.replace(/\s/g,"+"),url:d.join(""),auto:null});AC.release(d)},_buildHistory:function(){var a=$("#hisdiv");if(a.length==0)a=$('<div id="hisdiv" class="history_div"><div class="history_top">Searches in this Session :</div><ul/></div>').appendTo("body");if(a.is(":visible")){a.slideUp()}else{$("#sharediv").slideUp(400);var b=L.Layer("getHistory");if(b.length==0){L.Layer("loadPrompt",{flag:"ehistory"})}else{a=$("#hisdiv ul");a.html("");var c=0;for(var d=b.length-1;d>=0;d--){if(c>4)break;a.append('<li><table border=0 cellSpacing=0 cellPadding=3><tr><td vAlign="top"><div class="maplicon history_mark" ></div></td><td><a>'+b[d]+"</a></td></tr></table></li>");c++}$("#hisdiv").slideDown(400,function(){$(this).find("li a").unbind().click(function(a){a.stopPropagation();var b=$(this).text().split(/( in | near | around )/);if(b.length>1){if(b[0].split(",").length>1){b.splice(1,1);L.Layer("postprocess",{param:{q:202,search:b.join("*")},direct:false})}else{M.MapLayer("setValue",{prompt:true,request:$(this).text(),post:false,title:$(this).text()});app.goAhead()}}else{M.MapLayer("setValue",{prompt:true,request:$(this).text(),post:true,title:$(this).text()})}$("#hisdiv").slideUp(400)})})}}},menu:function(a){var b=a.process;var c=this;mlog=null;mlog=new com.mmi.logs;mlog.setType($(b.elem).text());if(a.menu=="bottom"){$("body").APL({action:1});if(b.idx==0){L.Layer("feedback",{search:$(b.elem).text(),menu:true})}else if(b.idx==1){L.Layer("spot",{search:$(b.elem).text(),menu:true})}else if(b.idx==2){window.location.hash="";c.preprocess({param:""});L.Layer("clearMap",{callback:function(){L.Layer("helper")}})}}else if(a.menu=="top"){b.q=400;if(b.idx==0){this._buildPrint();return}else if(b.idx==1){this._buildHistory();return}else if(b.idx==2){$("#hisdiv").slideUp(400);L.Layer("loadShare",{});return}L.Layer("fireProcess",{flag:null,process:b})}},calculate:function(arg){var service=arg.result.service;var evalResult=eval("("+arg.result.response+")");if(service==101){var index=evalResult.content;if(index==0||index==3)L.Layer("calculate",{param:arg.result});if(index==3){if($("#shortcut_Search_Nearby").length==1){$("#shortcut_Search_Nearby").slideDown();$(".link_dir_tofrom span:last").css({color:"#435D8F"})}}else if(index>0&&index<3){var output=L.Layer("isAlternates",{result:evalResult.childList,service:service,isvisible:false,plot:true});var status=$("form[lang=300]","#sidebar").length==1?true:false;var TA=[];var param=$("#current b").length==1?$("#current b").text():"";if(index==1){TA.push(output._addr);TA.push(param);L.Layer("buildpast",{x:output.point.y,y:output.point.x,addr:output._addr,index:0,setter:true})}else if(index==2){TA.push(param);TA.push(output._addr);if(status){L.Layer("buildpast",{swap:true,x:output.point.y,y:output.point.x,addr:output._addr,index:1,from:1,to:0,setter:true})}else{L.Layer("buildpast",{x:output.point.y,y:output.point.x,addr:output._addr,index:$(".search_txt_sml").length-1,setter:true})}}if(!status){L.Layer("showDirection",{close:true,show:true,param:TA})}else{$(".search_txt_sml:last").val(output._addr)}mlog.setValue(output._addr);mlog.setUrl(L.Layer("currentUrl"));mlog.persist()}}else if(service==400){if(evalResult.go==0){L.Layer("setPageLayout",{result:evalResult,index:2})}else if(evalResult.go==1){L.Layer("setPageLayout",{result:evalResult,index:3})}else if(evalResult.go==2){this.clearMap(evalResult)}}else{L.Layer("calculate",{param:arg.result})}$("body").APL({action:0})},validate:function(a){},accessAlternate:function(a){var b=a.request.q;if(b>=100&&b<200){a.request.search=a.value}else if(b>=200&&b<300){}else if(b>=300&&b<400){}this.postprocess.call(this,{param:a.request,direct:false});AC.release(b)},showonmap:function(a){var b=this;$("#sharediv").slideUp("fast").unbind();$("#hisdiv").slideUp("fast").unbind();var c=a.selected.elem.replace(" & ","_");var d=$("#poi_"+c,"#show_on_map_container");var e=a.selected.evt.position().left;a.selected.evt.addClass("active").siblings().removeAttr("class");var f=parseInt(e)+$("#show_on_map_container").width()+20;if(f>M.width())e-=f-M.width();if(d.length==1){if(!$("#show_on_map_container").is(":visible"))$("#show_on_map_container").slideDown(400);$(".poi_on_map_content","#show_on_map_container").hide();d.fadeIn("fast");$("#show_on_map_container").animate({left:e})}else{if(this.som==null){$.ajax({type:"GET",url:"place.html",dataType:"xml",success:function(a){b.som=a;b.cviewItems(a,c,e)}})}else{b.cviewItems(b.som,c,e)}}AC.release(f)},cviewItems:function(a,b,c){$(a).find(b).each(function(){var a=new Array;$(this).find("label").each(function(){a.push($(this).text())});var d=new Array;d.push('<div class="poi_on_map_content" id="poi_');d.push(b);d.push('"><div class="poi_bar_div"><div class="poi_bar_div_sall"> <table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="6%"><input type="checkbox" value="All" /></td></td><td width="70%" align="left">Select All </td><td width="24%" align="right" style="padding-right:10px;"><div lang="poi_');d.push(b);d.push('" align="right" react=8 onclick="parent.closeMe(this);" title="Close" alt="Close" class="maplicon closebox"></div></tr></table></div><div class="poi_bar_div_txt"><table width="100%" border="0" cellspacing="0" cellpadding="1">');var e=a.length;for(var f=0;f<e;f++){d.push("<tr>");d.push('<td width="12"><input name="input3" type="checkbox" value="');d.push(a[f]);d.push('" /></td><td>');d.push(a[f++]);d.push("</td>");if(f<e){d.push('<td width="12"><input name="input3" type="checkbox" value="');d.push(a[f]);d.push('" /></td><td>');d.push(a[f]);d.push("</td>")}d.push("</tr>")}d.push("</table></div></div></div>");$("#show_on_map_container").animate({left:c});$(".poi_on_map_content","#show_on_map_container").hide();if(!$("#show_on_map_container").is(":visible")){$("#show_on_map_container").append(d.join("")).show()}else{$("#show_on_map_container").append(d.join("")).fadeIn("fast")}$(".closebox","#poi_"+b).click(function(){$("li[class=active]","#poi_on_map ").removeAttr("class")});M.MapLayer("poiMapBinder",{pholder:$("#poi_"+b,"#show_on_map_container")})})},poiMapBinder:function(a){var b=a.pholder;var c=b.find(this.options.CBOX[1]);var d=this;c.click(function(a){a.stopPropagation();var b=0;var e=b;this.showCategories=new Array;var f=$("li[class=active]","#poi_on_map ");if($(this).val()!="All"){c.each(function(){if(b==0){$(this).attr({checked:L.Layer("getValue",{key:"BOOL",index:0})});b=1}else if($(this).is(d.options.CBOX[0])){++e}});var g=$("#poi_"+f.text().replace(" & ","_"));var h=g.find("input[type=checkbox]");var i=$("input[type=checkbox]:first-child",g);var j=h.length;if(j==e+1){i.attr({checked:true});b=0;d.showCategories=null;d.showCategories=new Array;d.showCategories.push($(".active","#poi_on_map").text())}AC.release(g);AC.release(h);AC.release(i);AC.release(j)}else if($(this).val()=="All"){c.attr({checked:$(this).is(d.options.CBOX[0])})}d.sendCategoriesRequest()})},sendCategoriesRequest:function(){var a=new Array;var b=new Array;var c=this;$(".poi_on_map_content").each(function(){var d=this;$(this).find(c.options.CBOX[0]).each(function(){if($(this).is(c.options.CBOX[1])){if($(this).val()=="All"){a.push($(d).attr("id").replace("poi_",""));return L.Layer("getValue",{key:"BOOL",index:0})}else{b.push($(this).val())}}})});if(a.length>0||b.length>0){var d=new Array;if(a.length>0)d.push(a.join(","));if(b.length>0)d.push(b.join(","));this.showCategories=null;this.showCategories=new Array;this.showCategories.push(a);this.showCategories.push(b);var e=[];e.push(d.join(""));e.push("current map view");internal=true;L.Layer("zoomAndAction",{more:true});this.inAndOutAction();L.Layer("postprocess",{param:{q:202,search:e.join("*")},direct:false})}else if(a.length==0&&b.length==0){this.showCategories=null;$(this.element[0]).unbind("zoom.boundsChanged");$(this.element[0]).unbind("center.boundsChanged");L.Layer("zoomAndAction",{more:false})}},getBuilder:function(){return this},setValue:function(a){if(a.prompt)L.Layer("removePrompt");this.searchparam.val(a.title);if(a.post)this.postprocess.call(this,{param:a.request,direct:false,useful:true})},preprocess:function(a){if(a.param!=""){$("#ph_isearch").hide()}this.searchparam.val(a.param)}}));$.extend($.MMI.MapLayer,{getter:["getBuilder"].join(""),defaults:{CBOX:[":checked","input[type=checkbox]"],CONTEXT:"0:Show Address Here,1:Directions from here,2:Directions to here,3:Find Nearby,4:Center & Zoom In,5:Center & Zoom Out,6:Add a Spot here,7:Something wrong here?"}})})(jQuery);MapsFinder.prototype.init=function(a){a.Layer({center:center,zoom:zoom,percentage:panel,app:"Maps",resize:true,oapp:this,action:M})};MapsFinder.prototype.showonmap=function(a){M.MapLayer("showonmap",{selected:a})};MapsFinder.prototype.menutopbar=function(a){M.MapLayer("menu",{menu:"top",process:a})};MapsFinder.prototype.menufooterbar=function(a){M.MapLayer("menu",{menu:"bottom",process:a})};MapsFinder.prototype.layerResponse=function(a){M.MapLayer(a.process,{result:a})};MapsFinder.prototype.goAhead=function(){M.MapLayer("search",{process:$("#gSearch"),from:layer})};MapsFinder.prototype.example=function(){var a=window.location.hash;var b=a.split(";geo=");var c=null;if(b.length==2){c=b[0];this.geo=b[1];M.MapLayer("setGeo",{param:this.geo})}else{c=b[0]}b=c.split("&mng=");c=null;if(b.length==2){c=b[0];LID=b[1];if(LID!=null&&LID!=""&&LID!=undefined){$("#autosel").val("yes");L.Layer("fireProcess",{view:1,q:"autobuild",id:LID,loading:true,callback:function(a){searchOBJ=a[0];app.autopass();if(typeof atips!="undefined")L.Layer("showtips")}})}return}else{c=b[0]}c=$.trim(c.replace(/[#]/,"").replace(/[+]/g," "));c=c.replace(/map of /ig,"");var d=null;var e=null;if(c){if(c.indexOf("current")>-1){c=c.replace(/( around current:| in current:|current:)/,"|");d=c.split("|");if($.trim(d[0]).length==0){e=d[1].split(",")}else{e=d}}else{d=c.split(/ enroute /gi);var f=null;if(d.length==2){c=d[0];f=d[1]}var g=c.replace(/direction( from )/gi,"");c=$.trim(g);M.MapLayer("preprocess",{param:c});M.MapLayer("search",{process:$("#gSearch"),enroute:f,from:layer,link:false,history:false})}if(e!=null&&typeof e==="object"){var h=null;if(isNaN(e[0])){e=e.join(",");h=e.split(",");e=null;e=new Array;var i=h.length-3;var j=h.length;for(var k=i;k<j;k++){if(!isNaN(h[k])){e.push(h[k])}else{break}}var l=new Array;l.push(h.splice(0,i).join(","));l.push("current map view");M.MapLayer("preprocess",{param:l.join(" in ")});L.Layer("pointAndZoomUpdate",{center:new Point(parseFloat(h[1]),parseFloat(h[2])),zoom:parseInt(h[0])});this.setParam({param:{q:202,search:l.join("*")},direct:false,link:false,history:false});return true}else if(c.length==2){e.push(e.shift());M.MapLayer("preprocess",{param:e.join(",")})}else{L.Layer("pointAndZoomUpdate",{center:new Point(parseFloat(e[1]),parseFloat(e[2])),zoom:parseInt(e[0])})}}}};MapsFinder.prototype.setParam=function(a){this.param=a};MapsFinder.prototype.getParam=function(a){return this.param};MapsFinder.prototype.preAction=function(){if(this.param!=null||typeof this.param!="undefined")M.MapLayer("postprocess",this.param);this.param=null;delete this.param};MapsFinder.prototype.start=function(a){M=a;M.MapLayer()};MapsFinder.prototype.updateLevelOrCenter=function(){M.MapLayer("updateShowAccess",{param:false})};MapsFinder.prototype.history=function(a){if(a.param.length>0){if(a.action==1)history.go(-1);this.example({param:$("#gSearch"),history:true})}};MapsFinder.prototype.autopass=function(a){if((typeof a!="undefined"||$("#autosel").val()=="yes")&&searchOBJ.search=="maps"){if(typeof a!="undefined"){autoObj=a.auto}else{var b=new Object;b.process="error";b.service="100";b.error='{"content": 0,"list":{"num":"1","type":"map"},"tagName":"resultset","childList":[{"list":'+JSON.stringify(searchOBJ)+',"tagName":"result","childList":[]}]}';b.response=null;if(isNaN(b.error)){b.process="calculate";b.response=b.error;b.error=null}autoObj=b}$("input[name=isearch]","#gSearch").val(searchOBJ.addr);L.Layer("setTitle",{param:"map of "+searchOBJ.addr});L.Layer("setUrl",{hash:true,param:("map+of+"+searchOBJ.addr).replace(/\s/g,"+")+"&mng="+LID});M.MapLayer("calculate",{result:autoObj});L.Layer("mbuildlog",{type:"Map of location",value:searchOBJ.addr,url:L.Layer("currentUrl"),auto:"Autosuggest Selection"});autoFlag=true}else if((typeof a!="undefined"||$("#autosel").val()=="yes")&&searchOBJ.search=="nearby"){$("input[name=isearch]","#gSearch").val(searchOBJ.addr);var c=searchOBJ.addr.toLowerCase();L.Layer("setTitle",{param:c});L.Layer("setUrl",{hash:true,param:c.replace(/\s/g,"+")+";geo="});var d=searchOBJ.y;var e=searchOBJ.x;var f=searchOBJ.addr;$("body").APL({action:1});mf.MarkerFactory("removeOverlays");$.getJSON("mgeonear_one.php?a="+f+"&p="+d+"&q="+e,function(a){var b=new Object;b.process="error";b.service="200";b.error=JSON.stringify(a);b.response=null;if(isNaN(b.error)){b.process="calculate";b.response=b.error;b.error=null}autoObj=b;L.Layer("calculate",{param:autoObj})})}else{autoFlag=false;autoObj=null}};MapsFinder.prototype.partner=function(a){var b=new Array;var c=a.content;var d=c.others;$("#current b a").attr({href:"http://mapmyindia.com/"+c.eloc});$("#current b").after("<span>[<a href='http://mapmyindia.com/"+c.eloc+"' target='_blank' style='color:#000;text-decoration: none'>"+c.eloc+"</a>]</span>");b.push('<div style="margin:10px 0 0 -5px">');var e=new Object;e.address=c.address;e.state=c.state;e.city=c.city;e.district=c.district;e.locality=c.locality;e.pincode=c.pincode;e.web=c.web;b.push('<table cellspacing="3" cellpadding="1" border="0" width="100%">');b.push(L.Layer("getPoiLayout",{request:e}));b.push("</table>");if(c.others.layer=="zomato"){b.push('<table cellspacing="0" cellpadding="1" border="0" width="100%"><tr><td width="17"><div class="maplicon zomato_tel" ></div></td><td>Tel : ');b.push(d.output.phone);b.push('</td> </tr> <tr> <td><div class="maplicon zomato_time"  ></div></td> <td>Timing : ');b.push(d.output.timing);b.push('</td> </tr><tr> <td><div class="maplicon zomato_cuisine"  ></div></td> <td>Cuisine : ');b.push(d.output.cuisines);b.push('</td> </tr> <tr> <td><div class="maplicon zomato_meal" ></div></td><td>Meal for Two : ');b.push(d.output.avgcost);b.push('</td> </tr><tr> <td class="poi_ntxt_link" colspan="2"> <a target="_blank" class="zomata_menu" href="');b.push(d.output.menu);b.push('">View Menu</a>');if(c.photos!=null&&c.photos.length>0){b.push('| <a target="_blank"  class="zomata_menu" href="');b.push(c.others.output.photos);b.push('">Photos </a> ')}b.push('   <a href="http://www.zomato.com/" style="border:0" title="Zomata" target="_blank"><div class="maplicon zomataicon"></div></td> </tr> </tbody></table> </div></td> </tr> </tbody></table>')}b.push("</div>");if(typeof a.pedit==="undefined"){b.push('<a href="http://maps.mapmyindia.com/edit-a-spot/?q=');b.push(L.Layer("callEncodeOrDecoder",{param:c.eloc,index:0}));b.push('" target="_blank" style="margin:5px 0 5px 0px;color:#FF00A4"><i>Edit details</i></a>')}return b.join("")}
