﻿var BigLoctionList = { "0": "福田区", "1": "南山区", "2": "罗湖区", "3": "盐田区"};
var BigCategory = { "0": "", "1": "", "2": "", "3": ""};
var COLUMNS=10;
var MenuCOLUMNS=4;
function ShowSearchItems(referenceObject, itemType, targetControlID)
{
    if (itemType == 'location')
    {
        var locationDOM = document.getElementById("locationDIV");
        $.blockUI.defaults.fadeOut = 100;
        $.blockUI.defaults.css.left = "60%";
        $.blockUI.defaults.css.top = "35%";
        $.blockUI.defaults.overlayCSS.opacity = '0.2';
        $.blockUI.defaults.css.border = "1px solid #333333";          
        if (locationDOM==null)
        {
           $.blockUI({ message: GenerateLocationDom(targetControlID) });
        }
    }
    else {
        var categoryDOM = document.getElementById("categoryDIV");
        if (categoryDOM==null)
        {
            $.blockUI({ message: GenerateCategoryDom(targetControlID) });              
        }
    }

}

function GenerateLocationDom(targetControlID) {
    var LocationJson = 
                    [
                        {"0":"车公庙,中心区,东园路,华强北,福田南,南园路,中信广场,八卦岭,园岭,白沙岭,体育馆,梅林,沙嘴,莲花北,莲花村,岗厦,景田,黄木岗,福田区委,福田保税区,皇岗口岸,上下沙,新洲,竹子林,荔枝公园,*香蜜湖"},
                        {"1":"华侨城,蛇口,南头,西丽,松坪山,中山公园,南油,科技园,前海,后海"},
                        {"2":"东门,国贸,地王,笋岗,翠竹,宝安北路,田贝,文锦中路,怡景花园,黄贝岭,仙湖,火车站,水库,布心,银湖,泥岗,莲塘,新秀村,清水河,罗湖区委"},
                        {"3":"沙头角,盐田港,大梅沙,小梅沙"}
                    ];
                        var domString = "<table id=\"locationDIV\" border='0' cellspacing=\"2\" cellpadding=\"2\" style='width:100%'>";
                        //domString += "<tr><td style='font-size: 12px' colspan='" + COLUMNS + "' align='right'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='$.unblockUI();'>[关闭]</span></td></tr>";

     for (i = 0; i < LocationJson.length; i++) {
        var count = 1;
        var detailDom = LocationJson[i][i].split(",");
        domString += "<tr><td style='width:68px;font-size: 12px;line-height:18px;font-weight: bold;'><span style='cursor:hand;'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + BigLoctionList[i] + "' target='_blank'>" + BigLoctionList[i] + "</a></span></td>";
        
        for(j=0;j<detailDom.length;j++){
            if (count < COLUMNS) {
                if(detailDom[j].substring(0,1)=="*")
                {
                    domString += "<td style='width:68px;font-size: 12px;line-height:18px;'><span style='cursor:hand' onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"locationDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j].substring(1) + "' target='_blank'><span style='color:red; font-weight:bold;'>" + detailDom[j].substring(1) + "</span></a></span></td>";
                }
                else
                {
                    domString += "<td style='width:68px;font-size: 12px;line-height:18px;'><span style='cursor:hand' onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"locationDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                }
                count++;
            }
            else
            {
                if(detailDom[j].substring(0,1)=="*")
                {
                    domString += "</tr><tr><td style='width:68px;font-size: 12px;line-height:18px;'><span style='cursor:hand' onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"locationDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j].substring(1) + "' target='_blank'><span style='color:red; font-weight:bold;'>" + detailDom[j].substring(1) + "</span></a></span></td>";
                }
                else
                {
                domString += "</tr><tr><td style='width:68px;font-size: 12px;line-height:18px;'><span style='cursor:hand' onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"locationDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                }
                count = 1;
            }
        }
        var remainCount=COLUMNS - count-1;
        if (remainCount>0){
            domString += "<td colspan='" + remainCount + "'></td>";
         }
         domString += "</tr>";
         //domString += "<tr><td style='height:5px'>&nbsp;</td></tr>";
     }
     domString+="</table>"
     //debugger;
    return domString;
}


function GenerateCategoryDom(targetControlID) {
    var CateoryJson=
        [
             {"0":"粤菜,客家菜,潮州菜,*川菜,湘菜,京菜,鲁菜,淮扬菜,上海菜,浙江菜,东北菜,湖北菜,江西菜,云南菜,贵州菜,福建菜,新疆菜,蒙古菜,徽菜,西北菜,广西菜,河南菜,北方菜,西餐,日本菜,韩国菜,法国菜,意大利菜,东南亚菜"},
             {"1":"快餐,茶餐厅,糕点,咖啡,茶舍,小吃,甜品冷饮,面食,清真,素食,烧烤,*自助餐,海鲜,*火锅,靓汤,早茶,夜宵,私房菜,江湖菜,农家乐,供应商,猪肚 鸡,水景,*羊肉,田鸡,小龙虾"},
             {"2":"购物,电影院,酒吧,KTV,夜总会,运动,桑拿,休闲,旅游,酒店"},
             {"3":"能刷卡,商务,约会,家庭,朋友,同事,年夜饭,婚宴,吃饭唱歌,公司活动,部门活动,表演,老字号,露天,水景,宴席,麻将"}
         ];
             var domString = "<table id=\"categoryDIV\" border='0' cellspacing=\"2\" cellpadding=\"2\" style='width:100%'>";
             //domString += "<tr><td style='font-size: 12px' colspan='" + COLUMNS + "' align='right'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='$.unblockUI();'>[关闭]</span></td></tr><tr>";

     for(i=0;i<CateoryJson.length;i++){
         var count = 0;
         var detailDom = CateoryJson[i][i].split(",");
         domString += "<tr><td style='width:68px;font-size: 12px;line-height:18px;font-weight: bold;' colspan='" + COLUMNS + "'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + BigCategory[i] + "' target='_blank'>" + BigCategory[i] + "</a></span></td></tr>";
         domString += "<tr><td style='width:68px;line-height:1px;border-bottom-width:1px;border-bottom-style: dashed;border-bottom-color: #462A06' colspan='" + COLUMNS + "'>&nbsp;</td></tr><tr>";
         for (j = 0; j < detailDom.length; j++) {
            if (count < COLUMNS) {
                if(detailDom[j].substring(0,1)=="*")
                {
                    domString += "<td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j].substring(1) + "' target='_blank'><span style='color:red; font-weight:bold;'>" + detailDom[j].substring(1) + "</span></a></span></td>";
                }
                else
                {
                    domString += "<td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                }                
                count++;
            }
            else
            {
                if(detailDom[j].substring(0,1)=="*")
                {
                    domString += "</tr><tr><td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j].substring(1) + "' target='_blank'><span style='color:red; font-weight:bold;'>" + detailDom[j].substring(1) + "</span></a></span></td>";
                }
                else
                {
                    domString += "</tr><tr><td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                }                
                count = 1;
            }
         }
         var remainCount = COLUMNS - count - 1;
         if (remainCount > 0) {
             domString += "<td colspan='" + remainCount + "'></td>";
         }
         domString += "</tr>";
         //domString += "<tr><td style='height:5px'>&nbsp;</td></tr>";    
     }
     domString+="</table>"
    return domString;
         
}


function SetValueIntoSearchItem(txtObj,DivID,targetControlID)
{
   
    var searchText = document.getElementById(targetControlID);
    if (searchText != null)
    {
        searchText.value = searchText.value+txtObj.innerText + " ";
        searchText.focus();
        var range = searchText.createTextRange();
        var charLength = searchText.value.length;
        range.moveStart('character', charLength);    
        range.collapse(true);
        range.select();  
    }
}

function SetElementBG(element,isAdd){
    if (isAdd) {
        element.style.background = "#FFFFFF";
        //element.style.fontWeight = "bolder";
        element.style.fontWeight = "";
    }
    else {
        element.style.background = "#FFFFFF";
        element.style.fontWeight = "";    
    }
}

function cc() {
    var e = document.getElementById("textbox1");
    var r = e.createTextRange();
    r.moveStart('character', 3);    //定位到第三个字符
    r.collapse(true);
    r.select();
}   
function GenerateCategoryDomMenu(targetControlID) {
    var CateoryJson=
        [
             {"0":"粤菜,客家菜,潮州菜,川菜,湘菜,京菜,鲁菜,淮扬菜,上海菜,浙江菜,东北菜,湖北菜,江西菜,云南菜,贵州菜,福建菜,新疆菜,蒙古菜,徽菜,西北菜,广西菜,河南菜,北方菜,西餐,日本菜,韩国菜,法国菜,意大利菜,东南亚菜,猪肚 鸡,水景,蟹,田鸡,小龙虾"},
             {"1":"快餐,茶餐厅,糕点,咖啡,茶舍,小吃,甜品冷饮,面食,清真,素食,烧烤,自助餐,海鲜,火锅,靓汤,早茶,夜宵,私房菜,江湖菜,农家乐,供应商"},
             {"2":"购物,电影院,酒吧,KTV,夜总会,运动,桑拿,休闲,旅游,酒店,户外"},
             {"3":"能刷卡,商务,约会,家庭,朋友,同事,年夜饭,婚宴,吃饭唱歌,公司活动,部门活动,表演,老字号,露天,水景,宴席,麻将"}
         ];
             var domString = "<table id=\"categoryDIV\" border='0' cellspacing=\"1\" cellpadding=\"1\" style='width:100%'>";
             //domString += "<tr><td style='font-size: 12px' colspan='" + COLUMNS + "' align='right'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='$.unblockUI();'>[关闭]</span></td></tr><tr>";

     for(i=0;i<CateoryJson.length;i++){
         var count = 0;
         var detailDom = CateoryJson[i][i].split(",");
         domString += "<tr><td style='width:68px;font-size: 12px;line-height:18px;font-weight: bold;' colspan='" + MenuCOLUMNS + "'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + BigCategory[i] + "' target='_blank'>" + BigCategory[i] + "</a></span></td></tr>";
         domString += "<tr><td style='width:68px;line-height:1px;border-bottom-width:1px;border-bottom-style: dashed;border-bottom-color: #462A06' colspan='" + MenuCOLUMNS + "'>&nbsp;</td></tr><tr>";
         for (j = 0; j < detailDom.length; j++) {
            if (count < MenuCOLUMNS) {
                domString += "<td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                count++;
            }
            else
            {
                domString += "</tr><tr><td style='width:68px;line-height:18px;font-size: 12px'><span style='cursor:hand'onmouseover='SetElementBG(this,true)' onmouseout='SetElementBG(this,false)' onclick='SetValueIntoSearchItem(this,\"categoryDIV\",\"" + targetControlID + "\")'><a href='http://www.chilema.cn/dir/dirshop.aspx?key=" + detailDom[j] + "' target='_blank'>" + detailDom[j] + "</a></span></td>";
                count = 1;
            }
         }
         var remainCount = MenuCOLUMNS - count - 1;
         if (remainCount > 0) {
             domString += "<td colspan='" + remainCount + "'></td>";
         }
         domString += "</tr>";
         //domString += "<tr><td style='height:5px'>&nbsp;</td></tr>";    
     }
     domString+="</table>"
    return domString;
         
}