﻿// JScript 文件
/*
 enums
*/
KINDS = {
    "电影院":"6500",
    "咖啡":"1600",
    "超市":"2100|2101|2102|2106|2111|2116|2117|2118|2119|2120|2122|2123|2124|2125|2126|2127|2128",
    "加油站":"4080|4081|4082|4083|4084|4085",
    "停车场":"4100",
    "学校":"a700",
    "饭店":"1080|1081|1085|10c0|10c1|10c2|10c7|10c8|1300|1380|1980",        
    "酒吧":"1500"
}
//var dropDownCoord_search="";   //下拉对象绑定的变量，只有坐标
var strCityCode_IP="110100";
var strCityName_IP="北京市";
function getCityByIP(index,onFun)
{
   function onComplete(str)
   {
       if(str!=null&&str!=""&&str.Value!=null&&str.Value!="")
       {
           eval('pram='+str.Value); 
           strCityCode_IP=pram.citycode;
           strCityName_IP=pram.cityname;
           if(onFun!=undefined&&onFun!=null) onFun();
       }
    }
    var strPath="";
    if(index==1)  strPath="Handler/Handler.ashx";
    else if(index==2) strPath="../Handler/Handler.ashx";
    sfs.ajax.invoke(strPath,'getCityByIP',[],onComplete);
}

function creatPageHead(width)
{
    if(width!=undefined&&width!=null){
        var headDiv=select("#headDiv");
        if(width<950) width=957;
        headDiv.Width(width-20);
    }
    var isL=false;
    var strHref=window.location.href;
    var indexPage=strHref.search(/index.htm/i); 
    var firstPage=strHref.search(/.htm/i); 
    var mapPage=strHref.search(/map.htm/i);
    var extPage=strHref.search(/html/i); 
    if(indexPage!=-1||mapPage!=-1||firstPage==-1 || extPage!=-1)   isL=true;
    creatComplexPageHead(isL);
}
//添加页面的头部
function creatComplexPageHead(isL)
{
    var headDiv=select("#headDiv");
    if(isL==true){
        var headLDiv=document.createElement("div");
        headLDiv.id="headLDiv";
        headLDiv.className="headConL";
        headLDiv.innerHTML="<p><a id='city_introA' class='pT2'></a>"+
                           "<b><a id='map_city_weather' class='pT2'></a></b>"+
                           "<span><a id='cityWeather'></a></span></p>";
        headDiv.appendChild(headLDiv); 
    }
    var headRDiv=document.createElement("div");  
    headRDiv.id="ctl00_WebTopMid1_WebTopMini1_pnlLoginOut";
    headRDiv.className="headConR";   
    headRDiv.innerHTML="<ul>"+
                       "<li><a href='http://www.easemap.com/about/Intro_MSN.htm' style='color:Red;' target='_blank'>易图机器人</a>|</li>"+
                       "<li><a href='http://www.easemap.com'>网站首页</a>|</li>"+
                       "<li><a href='http://www.easemap.com/map/map.htm'>地图</a>|</li>"+
//                       "<li><a href='http://www.easemap.com/map/blankPage.htm'>专题地图</a>|</li>"+
                       "<li><a href='http://www.easemap.com/about/mapService.htm' target='_blank'>地图服务</a>|</li>"+
                       "<li><a href='http://www.easemap.com/about/introduceFirm.htm' target='_blank'>行业应用</a>|</li>"+
                       "<li><a href='http://www.easemap.com/about/mapMark_W.htm' target='_blank'>企业推广</a></li>"+
                       "</ul>";
    
    headDiv.appendChild(headRDiv);
}
//添加页面的尾部
function creatPageBottom()
{
   var pA=document.createElement("p");
   pA.innerHTML="<a href='http://www.easemap.com/about/aboutus.htm' target='_blank'>关于我们</a>|"+
                "<a href='http://www.easemap.com/about/aboutetu.htm' target='_blank'>关于易图</a>|"+
                "<a href='http://www.easemap.com/about/Link.htm' target='_blank'>友情链接</a>|"+
                "<a href='http://www.easemap.com/about/hr.htm' target='_blank'>人才招聘</a>|"+
                "<a href='http://www.easemap.com/about/relates.htm' target='_blank'>联系我们</a>|"+
                "<a href='http://www.easemap.com/about/CopyRight.htm' target='_blank'>版权声明</a>|"+
                "<a href='http://www.easemap.com/about/provision.htm' target='_blank'>使用条款</a>|"+
                "<a href='http://www.easemap.com/map/blankPage.htm' target='_blank'>使用帮助</a>";
   var pG=document.createElement("p");
   pG.innerHTML="易图版权所有 京ICP备07017164号 审图号：GS(2008)383";
   var pC=document.createElement("p");
   pC.innerHTML="Copyright ©2007-2009 easemap.com China, All rights reserved";
   var pageBottomDiv=select("#bottom");
   pageBottomDiv.appendChild(pA);
   pageBottomDiv.appendChild(pG);
   pageBottomDiv.appendChild(pC);
}
//添加下拉函数  INFOLIST下拉对象 con：map  obj：下拉的的容器input  width：下拉显示的宽度  element:绑定坐标的控件
function isNewDropDown(INFOLIST,con,obj,width,element)
{
   INFOLIST = new QcyxModule.infoList(con, obj,{width: ''+width+''});
   INFOLIST.load();
//   INFOLIST.initMapDropDown();
   if(con==null) {INFOLIST.toolsInstance = new ICT.Tools();INFOLIST.city('110100');}
   INFOLIST.regEvent('onOptionOver', function(e){ });
   if(element!=null&&element!=undefined)  INFOLIST.regEvent('onChange', function(e){} );
   else INFOLIST.regEvent('onChange', function(e){
        this.inputElement.setAttribute("xy",dropDownCoord_Search);
        if(con!=null) this.inputElement.setAttribute("citycode",con.cityCode);} );
   INFOLIST.regEvent('onOptionCreate', onCreateOption);
   if(element!=null&&element!=undefined)  INFOLIST.setAutoBind('element',element);
   else INFOLIST.setAutoBind('variable','dropDownCoord_Search');
   return INFOLIST;
}
function dropDownOptionChoose(objID,obj)
{
   if(objID!=null&&objID!=undefined){
      var inputElement=select("#"+objID+"");
      inputElement.setAttribute("xy",obj.site);
//      inputElement.setAttribute("citycode",objID.city());
   }
}
function onCreateOption(obj,i){
   var node = document.createElement('span');
   node.innerHTML = obj.info.adminname;
   return node;
}
//清空元素的xy属性
function clearNull(obj)
{
   obj.setAttribute("xy","");
   obj.setAttribute("citycode","");
}
//获取当前页面的Url
function Request(strName) 
{ 
    var strHref=window.location.href; 
    var intPos = strHref.indexOf('?'); 
    var strRight = strHref.substring(intPos + 1); 
    if( strRight.indexOf("#") == strRight.length-1) strRight = strRight.substr(0,strRight.length-1);
    var arrTmp = strRight.split('&');
    var str = "";
    for(var i = 0; i < arrTmp.length; i++) 
    { 
        var arrTemps = arrTmp[i].split('=');
        if(arrTemps[0].toUpperCase() == strName.toUpperCase())
        {
            str =  arrTemps[1];
        }
    }
    return str; 
}
function hasRequest(name){
    var strHref=window.location.href; 
    var intPos = strHref.indexOf('?'); 
    var strRight = strHref.substring(intPos + 1); 
    if( strRight.indexOf("#") == strRight.length-1) strRight = strRight.substr(0,strRight.length-1);
    var arrTmp = strRight.split('&');
    for(var i = 0; i < arrTmp.length; i++) 
    { 
        var arrTemps = arrTmp[i].split('=');
        if(arrTemps[0].toUpperCase() == name.toUpperCase())
        {
            return true;
        }
    }
    return false;
}
//查询天气，无地图
function getWeatherNoMap(citycode)
{
   if(citycode==undefined||citycode==""||citycode==null)  return;
   sfs.ajax.invoke('http://api.easemap.com/js/Handler/BaseHandler.ashx','getWeatherGoogle',[citycode],onWeatherComplete);
    function onWeatherComplete(strWeather)
    {
        var city_introA=select('#city_introA');
        var headLDiv=select('#headLDiv');
        var cityW=$('cityWeather');
        var map_city_weather=select('#map_city_weather');
        if(strWeather.Value!=null&&strWeather.Value!="") 
        {
            var f=strWeather.Value;
            if(f!=''){
                eval('ff='+f);            
                if(ff!=undefined&&ff.info!=undefined) {
                   city_introA.innerHTML="当前城市：";
                   map_city_weather.innerHTML=ff.cityname;
                   cityW.innerHTML=ff.info.today.day+' '+ff.info.today.conditon+' '+ff.info.today.low+'~'+ff.info.today.high+' &nbsp;&nbsp;'+ff.info.cur.wind_condition;
                   headLDiv.show();
                }
                else {headLDiv.hide();} 
            }
            else {headLDiv.hide();}
        }
        else {headLDiv.hide();}
    }
}
function getDoSearch(index)
{
    if(index==2)  searchPeripheralAround();   //周边查询
    else getSearchMapByName();  //地图搜索
}
//url传参（param：需要传递的参数，即url中？后面的内容；pageUrl：跳转页面的相对路径；cityCode：跳转参数,cityName）
function toLocation(param,pageUrl)
{
    url = ''+pageUrl+'?';
    var urlParam="";
    for( a in param){
        urlParam +='|'+ a +'=' + param[a];
    }
    urlParam=encode64(urlParam);
    url+=urlParam;
    window.open(url,'_blank');
}
//值为空时的默认形式
function getDefaultStr(str){
    if( str == null) return "暂无";
    if( str == undefined) return "暂无";
    if( str.trim().length == 0) return "暂无";
    if( str == "0米") return "暂无";
    return str;
}
/*
 utils
*/
function cumulativeOffset(element){
     var valueT = 0, valueL = 0,valueH =0;
     do {
       valueT += element.offsetTop  || 0;  
       valueL += element.offsetLeft || 0;
       element = element.offsetParent;
     } while (element);
     return { top : valueT, left : valueL};
}
function $(v){
    e = typeof v == 'string' ? select('#'+v) : v;
    return e;
}
function cancelEventBubble(e){
    e.stopPropagation && (e.preventDefault(), e.stopPropagation()) || (e.cancelBubble = true, e.returnValue = false);
}
function exchangeValue(n1,n2){
    n1 = $(n1);
    n2 = $(n2);
    v = n1.value;
    n1.value = n2.value;
    n2.value = v;
}
function copyValue(n1,n2,fN){
    $(n1).value = $(n2).value;
    if(fN) fN.focus();
}
/*
 utils
*/

var Ie_ver=navigator["appVersion"].substr(22,1);
if(Ie_ver=="6")
{
    document.execCommand("BackgroundImageCache", false, true);
}

////BASE64编码
var keyStr="ABCDEFGHIJKLMNOP"+"QRSTUVWXYZabcdef"+"ghijklmnopqrstuv"+"wxyz0123456789._"+",";   
function   encode64(input)   {   
    input   =   escape(input);   
    var   output   =   "";   
    var   chr1,   chr2,   chr3   =   "";   
    var   enc1,   enc2,   enc3,   enc4   =   "";   
    var   i   =   0;   

    do   {   
        chr1   =   input.charCodeAt(i++);   
        chr2   =   input.charCodeAt(i++);   
        chr3   =   input.charCodeAt(i++);   

        enc1   =   chr1   >>   2;   
        enc2   =   ((chr1   &   3)   <<   4)   |   (chr2   >>   4);   
        enc3   =   ((chr2   &   15)   <<   2)   |   (chr3   >>   6);   
        enc4   =   chr3   &   63;   

        if   (isNaN(chr2))   {   
              enc3   =   enc4   =   64;   
        }   else   if   (isNaN(chr3))   {   
              enc4   =   64;   
        }   

        output   =   output   +     
              keyStr.charAt(enc1)   +     
              keyStr.charAt(enc2)   +     
              keyStr.charAt(enc3)   +     
              keyStr.charAt(enc4);   
        chr1   =   chr2   =   chr3   =   "";   
        enc1   =   enc2   =   enc3   =   enc4   =   "";   
    }   while   (i   <   input.length);   

    return   output;   
}   

function   decode64(input)   {   
    var   output   =   "";   
    var   chr1,   chr2,   chr3   =   "";   
    var   enc1,   enc2,   enc3,   enc4   =   "";   
    var   i   =   0;   

    //   remove   all   characters   that   are   not   A-Z,   a-z,   0-9,   +,   /,   or   =   
    var   base64test= /[^A-Za-z0-9\.\_\,]/g;   
    if   (base64test.exec(input))   {   
         return output;
    }   
    input   =   input.replace(/[^A-Za-z0-9\.\_\,]/g,   "");   

    do   {   
        enc1   =   keyStr.indexOf(input.charAt(i++));   
        enc2   =   keyStr.indexOf(input.charAt(i++));   
        enc3   =   keyStr.indexOf(input.charAt(i++));   
        enc4   =   keyStr.indexOf(input.charAt(i++));   

        chr1   =   (enc1   <<   2)   |   (enc2   >>   4);   
        chr2   =   ((enc2   &   15)   <<   4)   |   (enc3   >>   2);   
        chr3   =   ((enc3   &   3)   <<   6)   |   enc4;   

        output   =   output   +   String.fromCharCode(chr1);   

        if   (enc3   !=   64)   {   
              output   =   output   +   String.fromCharCode(chr2);   
        }   
        if   (enc4   !=   64)   {   
              output   =   output   +   String.fromCharCode(chr3);   
        }   

        chr1   =   chr2   =   chr3   =   "";   
        enc1   =   enc2   =   enc3   =   enc4   =   "";   

    }   while   (i   <   input.length);   

    return   unescape(output);   
} 

function getDisSelected(peripheralAround)
{
    var  indexPeripheralAround=peripheralAround.selectedIndex;
    var dis=2000;
    switch(indexPeripheralAround){
       case 0:
         dis=2000;
         break;
       case 1:
         dis=100;
         break;
       case 2:
         dis=300;
         break;
       case 3:
         dis=500;
         break;  
       case 4:
         dis=1000;
         break;
       case 5:
         dis=2000;
         break;
       default:break;            
    }
    return dis;
}