﻿if (document.all) {
   // window.attachEvent('onload', initFloatTips);
}
else {
   // window.addEventListener('load', initFloatTips, false); //firefox
}
function showlayer(objid,eventid)
{
    var layer = document.getElementById(objid);
    var mrel = document.getElementById(eventid).rel;
    if(layer.style.display=='none' || layer.style.display=='')
    {
        layer.style.display="inline";
        document.getElementById(eventid).innerHTML = "&laquo;更少";
    }else
    {
        layer.style.display="none";
        if(mrel=='undefined')
            document.getElementById(eventid).innerHTML = "更多&raquo;";
        else
            document.getElementById(eventid).innerHTML = "更多(" + mrel + ")&raquo;";
    }
}

function efcSearchCls()
{
    this.m_country = 0 ;//区域
    this.m_storekind = 0;//行业分类
    this.m_bussarea =0;//商业区
    this.m_dishekind =0;//菜系
    this.m_consumperson = "";//人均消费
    this.m_park =0;//停车位
    this.m_box =0;//包厢
    this.m_bank =0;//银联
    this.m_wifi =0;//无线上网
    this.m_olorder =0;//在线订单
    this.m_order =0;
    this.m_card = 0;//支持食域卡打折
    this.m_keyword = '';//关键字
    this.m_ctrlKeyword = '';
    
    //城市区域
    this.country =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_country = value;
        this.Search();
    }
    //行业分类
    this.storekind =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_storekind = value;
        this.Search();
    }
    //商业圈
    this.bussarea =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_bussarea = value;
        this.Search();
    }
    //菜系
    this.dishekind =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_dishekind = value;
        this.Search();
    }
    //人均消费
    this.consumperson =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_consumperson = value;
        this.Search();
    }
    this.order =function(value)
    {
        //this.SelOption(masterelem,optindex);
        this.m_order = value;
        this.Search();
    }    
    //停车位
    this.park =function(value)
    {
        if(value)
            this.m_park = 1;
        else
            this.m_park =0;
        this.Search();
    }
    //包厢
    this.box =function(value)
    {
        if(value)
            this.m_box = 1;
        else
            this.m_box =0;
        this.Search();
    }
    //银联
    this.bank =function(value)
    {
        if(value)
            this.m_bank = 1;
        else
            this.m_bank =0;
        this.Search();
    }
    //无线网络
    this.wifi =function(value)
    {
        if(value)
            this.m_wifi = 1;
        else
            this.m_wifi =0;
        this.Search();
    }
    //在线订单
    this.olorder =function(value)
    {
        if(value)
            this.m_olorder = 1;
        else
            this.m_olorder =0;
        this.Search();
    }
    //持卡打折
    this.card =function(value)
    {
        if(value)
            this.m_card = 1;
        else
            this.m_card =0;
        this.Search();
    }
    
    
    //单选一个搜索选项
    this.SelOption = function(masterElem,tabNum)
    {
        var h = document.getElementById(masterElem).getElementsByTagName("a");
        for (var i = 0; i < h.length; i++) {
            if (tabNum - 1 == i) {
                h[i].className = "on";
            }
            else {
                h[i].className = "";
            }
        }
    }
    
    //定向搜索
    this.Search = function()
    {
        var txtkey =this.m_ctrlKeyword;
        var keyword = document.getElementById(txtkey).value;
        var title = document.getElementById(txtkey).title;
        if(keyword==null || keyword=="" || keyword ==title)
            this.m_keyword = encodeURI("推荐商家");
        else
            this.m_keyword = encodeURI(keyword);
            
        window.location.href ="/RestSearch," + this.m_country + "," + this.m_storekind + "," + this.m_bussarea + "," + this.m_dishekind + "," + this.m_consumperson + "," + this.m_park + "," + this.m_box + "," + this.m_bank + "," + this.m_wifi + "," + this.m_olorder + "," + this.m_card + "," + this.m_keyword + "," + this.m_order + ".aspx";
    }
}
function efc(id)
{
    var rtn = document.getElementById(id) || false;
    if(rtn)
    {
        return document.getElementsByName(id) || false;
    }
}
function efcUnionRest()
{
    this.m_country = 0 ;//区域
    this.m_storekind = 0;//行业分类
    this.m_bussarea =0;//商业区
    this.m_dishekind =0;//菜系
    this.m_consumperson = "";//人均消费
    
    //城市区域
    this.country =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_country = value;
        this.Search();
    }
    //行业分类
    this.storekind =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_storekind = value;
        this.Search();
    }
    //商业圈
    this.bussarea =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_bussarea = value;
        this.Search();
    }
    //菜系
    this.dishekind =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_dishekind = value;
        this.Search();
    }
    //人均消费
    this.consumperson =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_consumperson = value;
        this.Search();
    }
    //单选一个搜索选项
    this.SelOption = function(masterElem,tabNum)
    {
        var h = document.getElementById(masterElem).getElementsByTagName("a");
        for (var i = 0; i < h.length; i++) {
            if (tabNum - 1 == i) {
                h[i].className = "on";
            }
            else {
                h[i].className = "";
            }
        }
    }
    //定向搜索
    this.Search = function()
    {            
        window.location.href ="/UnionRest," + this.m_country + "," + this.m_storekind + "," + this.m_bussarea + "," + this.m_dishekind + "," + this.m_consumperson + ".aspx";
    }
}

function efcOlOrderRest()
{
    this.m_country = 0 ;//区域
    this.m_bussarea =0;//商业区
    this.m_building =0;
    this.m_consumperson = "";//人均消费
    this.m_order=0;
    this.m_keyword ='';
    this.m_ctrlKeyword ="keyword";
    
    //城市区域
    this.country =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_country = value;
        this.Search();
    }
    //商业圈
    this.bussarea =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_bussarea = value;
        this.Search();
    }
    //地标
    this.building =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_building = value;
        this.Search();
    }
    //人均消费
    this.consumperson =function(value,optindex,masterelem)
    {
        this.SelOption(masterelem,optindex);
        this.m_consumperson = value;
        this.Search();
    }
    this.order =function(value)
    {
        this.m_order = value;
        this.Search();
    }    
    //单选一个搜索选项
    this.SelOption = function(masterElem,tabNum)
    {
        var h = document.getElementById(masterElem).getElementsByTagName("a");
        for (var i = 0; i < h.length; i++) {
            if (tabNum - 1 == i) {
                h[i].className = "on";
            }
            else {
                h[i].className = "";
            }
        }
    }
    //定向搜索
    this.Search = function()
    {   
        var txtkey =this.m_ctrlKeyword;
        var keyword = document.getElementById(txtkey).value;
        var title = document.getElementById(txtkey).title;
        if(keyword==null || keyword=="" || keyword ==title)
            this.m_keyword = encodeURI("推荐商家");
        else
            this.m_keyword = encodeURI(keyword);
        window.location.href ="/OnlineRest," + this.m_country + "," + this.m_bussarea +  "," + this.m_building + "," + this.m_consumperson + "," +this.m_order + "," + this.m_keyword  + ".aspx";
    }
}

function efcCompare()
{
    this.counter = 0;
    this.shopids = "";
    this.pro_arr = {};
    this.maxcounter = 4;
    this.parenteid ="shopcompare";
    this.comparebox = jQuery("#shopcompare");
    this.instancename = "efccompare";

    this.init = function(id)
    {
        this.comparebox = jQuery("#"+id);
        this.parenteid = id;
        this.counter=0;
    }
    //用指定的字符串div切开str字符串后返回一个数组
    this.strtoarr = function(str,div){
        objArr = str.split(div);
        return objArr;
    }
    this.in_array = function(needle, haystack) {
        if(typeof needle == 'string') {
            for(var i in haystack) {
                if(haystack[i] == needle) {
                    return true;
                }
            }
        }
        return false;
    }
    this.show = function()
    {
        this.comparebox.css('display','block');
    }
    this.hide = function()
    {
        this.comparebox.css('display','none');
    }
    this.add = function(shopid,shopname,shopurl,shopimg)
    {
        this.show();
        //判断是否在列表中
        if(this.counter==this.maxcounter)
        {
            alert("对比的商家不能超过 "+this.maxcounter+" 家！");
            return false;
        }
        if (this.pro_arr['shop_'+shopid]) return false;
        var appendhtml = "";
        appendhtml = "<div class='item' id='d"+shopid+"'><label for='s"+shopid+"'><input type='checkbox' onclick='"+this.instancename+".remove("+shopid+");' value='"+shopid+"' id='s"+shopid+"' name='s"+shopid+"' checked />"+shopname+"</label></div>";
        this.comparebox.html(this.comparebox.html() + appendhtml);
        this.pro_arr['shop_'+shopid] = shopid;
        this.counter++;
        return true;
    }
    this.remove = function(shopid)
    {
        var selitem = jQuery("#d"+shopid);
        selitem.remove();
        var checkbox = jQuery("#c"+shopid)
        if(checkbox) checkbox.attr('checked',false); 
        delete this.pro_arr['shop_'+shopid];
        this.counter-- ;
        if(this.counter==0)
            this.hide();
        return true;
    }
    this.clickitem = function(shopid,shopname,shopurl,shopimg)
    {
        var selitem = jQuery("#c"+shopid);
        if(selitem.attr("checked"))
        {
            return this.add(shopid,shopname,shopurl,shopimg);
        }else
        {
            return this.remove(shopid);
        }
    }
    this.clear = function()
    {
        this.comparebox.html("");
        this.counter = 0;
        this.pro_arr.length =0;
        this.shopids ="";
        this.hide();
        return true;
    }
    this.exec = function()
    {
        if(this.counter ==0 || this.counter < 2)
        {
            alert("请至少选择两个以上的商家才能进行对比！");
            return false;
        }
        if(this.counter>this.maxcounter)
        {
            alert("对比的商家不能超过 "+this.maxcounter+" 家！");
            return false;
        }
        //进行路径跳转
        this.shopids = "";
        for(var arr1 in this.pro_arr)
        {
            this.shopids +=this.pro_arr[arr1] + ",";
        }
        //alert(this.shopids);
        window.open("/Shopcompare-"+this.shopids+".aspx");
    }
}

var mapinited = false;
var map ;
function locationmap(lng,lat,restid,restname,restaddress,resttel) {
if(mapinited==false){
    //if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.addControl(new GMenuMapTypeControl(true));
        map.enableScrollWheelZoom();
        map.setCenter(new GLatLng(lat,lng), 16);
        map.addControl(new GSmallMapControl());
        
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        markerOptions = { icon: blueIcon };
        
        var latlng = new GLatLng(lat,lng);
        var marker = new GMarker(latlng, markerOptions);
        GEvent.addListener(marker, "click", function() {
            markinfowin(latlng,restid,restname,restaddress,resttel);
        });
        map.addOverlay(marker);

        markinfowin(latlng,restid,restname,restaddress,resttel);
        mapinited = true;
    //}
}else
{
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        markerOptions = { icon: blueIcon };

        var latlng = new GLatLng(lat,lng);
        var marker = new GMarker(latlng, markerOptions);
        GEvent.addListener(marker, "click", function() {
            markinfowin(latlng,restid,restname,restaddress,resttel);
        });
        map.addOverlay(marker);

        markinfowin(latlng,restid,restname,restaddress,resttel);
        map.setCenter(new GLatLng(lat,lng));
        mapinited = true;
}

}
function markinfowin(latlng,restid,restname,restaddress,resttel)
{
    map.openInfoWindow(latlng,"<p style='line-height:30px'><div><h3><a href='http://s.eshiyu.com/"+restid+"' target='_blank'>"+restname+"</a></h3></div><div>地址："+restaddress+"</div><div>电话："+resttel+"</div></p>");
}
function keyword_high(keywords)
{
    if(keywords.length>0)
    {
        var strKey = keywords;
        var arrKey = strKey.split(',');
        for(var j = 0; j < arrKey.length; j ++)
        {
            var key = arrKey[j];
            $("#res").highlight(key);
        }
    }
}

/*
var tips; 
var theTop = 120;//这是默认高度
var minTop = 600;
var old = theTop;

function initFloatTips() {
    tips = document.getElementById('smapr');

    moveTips();
};
function moveTips() {
    var tt = 50;
    if (window.innerHeight) {
        pos = window.pageYOffset
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        pos = document.documentElement.scrollTop
    }
    else if (document.body) {
        pos = document.body.scrollTop;
    }
    pos = pos - tips.offsetTop + theTop;
    pos = tips.offsetTop + pos / 10;
    if (pos < theTop) pos = theTop;
    //if (pos != old) {
    if(pos>minTop)
    {
        tips.style.top = pos + "px";

        tt = 10;
    }
    //}

    old = pos;
    setTimeout(moveTips, tt);
    
}*/
