﻿var ComMap = ComMap ? ComMap : {};

/*
*   the front of the Map Com
*   For the outside website
*/
ComMap.Front=function(){
    this.doc          = document.compatMode == "CSS1Compat" ? document.documentElement : document.body;
    this.MarginTop    = 94;
    this.MarginRight  = 357;
    this.MarginBottom = 0;
    this.MarginLeft   = 0;
    this.Width        = 0;
    this.Height       = 0;
    this.DocWidth     = 0;
    this.DocHeight    = 0; 
    this.ScrWidth     = 0;
    this.ScrHeight    = 0;    
    
    this.DivID        = 'DivID';
    this.Div        = null;
    this.MapID        = 'MapFrame';
    this.Map          = null;
    this.IsFullScreen = false;
    this.screenHeight = 0;
    this.screenWidth  = 0;
    //this.debug        = "";
    this.Container    = null;
    this.ContainerID  = "Container";
    this.mainDivID    = "mainDiv";
    this.topMainID    = "topmain";
    this.innerFrameID = "innerframe";
    this.innerDivID   = 'innerDiv';
    
    /*
    *   init
    */
    this.init=function(){

        this.Div = this.Div?this.Div:this.$id(this.DivID);
        this.Container = this.$id(this.ContainerID);
        this.screenHeight = window.screen.height;
        this.screenWidth  = window.screen.width;
        this.getMapFrame();
        this.resize();
    }
    /*
    *   get element by id
    */
    this.$id          = function(id){return document.getElementById(id);};
    /*
    *   get map
    */
    this.getMapFrame       = function(){ this.Map = this.Map?this.Map:this.$id(this.MapID);};
    /*
    *   get document width and height
    */
    this.getDocBox    = function()
    {
        this.DocWidth  = Math.max(this.doc.clientWidth,0);
        this.DocHeight = this.doc.clientHeight;
        this.ScrWidth  = Math.max(this.doc.scrollWidth,0);
        this.ScrHeight = this.doc.scrollHeight;
        
        //this.debug += " dw:"+this.DocWidth+" dh:"+this.DocHeight+" sw:"+this.ScrWidth+" sh:"+this.ScrHeight+"\n";
        
        this.Height    = this.SrcHeight>this.DocHeight?(this.ScrWidth>this.DocWidth?this.ScrHeight-15:this.ScrHeight):this.DocHeight;
        this.Width     = this.ScrWidth>this.DocWidth?(this.SrcHeight>this.DocHeight?this.ScrWidth-15:this.ScrWidth):this.DocWidth;
        
        this.Height     = this.Height>this.screenHeight?(this.screenHeight-15):this.Height;
        this.Width     = this.Width>this.screenWidth?(this.screenWidth-15):this.Width;
        this.doc.style.height = this.Height + 'px';
        this.doc.style.width  = this.Width  + 'px';;
        
    };
    this.FullScreen = function(arg){
        arg = arg?arg:(!this.IsFullScreen);
        this.IsFullScreen = arg;
        this.resize();
    };
    /*
    *   resize map
    */
    this.resize=function(){
        //this.getMapFrame();
        this.getDocBox();
        this.Container.style.height = this.DocHeight+'px';
        this.Container.style.width  = this.ScrWidth +'px';
        if(this.IsFullScreen==false){
            this.Map.style.left = '0px';
            this.Map.style.top = '0px';
            this.Map.style.width = (this.Width - this.MarginLeft - this.MarginRight)+'px';
            this.Map.style.height = (this.Height - this.MarginTop - this.MarginBottom)+'px';
            this.$id(this.innerDivID).style.width = "356px";
            this.$id('msgitem').style.display = '';          
        }else{
            //FullScreen
            this.Map.style.left = '0px';
            this.Map.style.top = '0px';
            this.Map.style.width = (this.Width - this.MarginLeft - 10)+'px';
            this.Map.style.height = (this.Height - this.MarginTop - this.MarginBottom)+'px';
            this.$id(this.innerDivID).style.width = "10px";
            this.$id('msgitem').style.display = 'none';          
        }
        
        //set the out Div Box
        if(this.Div)
        {
            this.Div.style.width = this.Map.style.width;
            this.Div.style.height = this.Map.style.height;
            this.$id(this.innerDivID).style.left = this.Map.style.width;
        }
        //if(this.DocWidth<600){this.doc.clientWidth = 600+'px';}
        //document.title+= this.DocWidth+','+this.ScrWidth+' - ';
        com.setScrWidth(this.mainDivID);
        com.setWidth(this.topMainID);
        com.setHeight('shmsg');
        com.setHeight(this.innerFrameID);
    };
    /*
    *   set Element Scrwidth
    */
    this.setScrWidth = function(id, dec)
    {        
        if(dec){
            this.$id(id).style.width = (this.ScrWidth-parseInt(dec))+'px';
        }else{
            this.$id(id).style.width = this.ScrWidth+'px';
        }
    };
    /*
    *   set Element width
    */
    this.setWidth = function(id, dec)
    {        
        if(dec){
            this.$id(id).style.width = (this.Width-parseInt(dec))+'px';
        }else{
            this.$id(id).style.width = this.Width+'px';
        }
    };
    /*
    *   set Element height
    */
    this.setHeight = function(id, dec)
    {
        if(dec){
            this.$id(id).style.height = (parseInt(this.Div.style.height)-parseInt(dec))+'px';
        }else{
            this.$id(id).style.height = this.Div.style.height;
        }
    };
};


/*
*   the front of the Map Com
*   For the inside website
*/
ComMap.Main=function(){
    this.MenuHide     = false;
    this.MenuDivID    = 'divFullScreen';
    this.MenuDiv      = null;
    /*
    *   get element by id
    */
    this.$id          = function(id){return document.getElementById(id);};
    this.init=function()
    {
        this.MenuDiv = this.$id(this.MenuDivID);
    }
    /*
    *   Hide Or Show Menu
    */
    this.HideMenu   = function(arg){
        if(arg)
        {
            this.MenuHide = arg;
        }else{
            this.MenuHide = this.MenuHide==true ? false : true;
        }
        this.MenuDiv.style.display = this.MenuHide==true ? 'none' : '';
    }
};

ComMap.Proxy = function() {
    this.FrameID = "MapFrame";
    this.Frame = null;
    this.FromID = "map_post_from";
    this.From = null;

    this.RndID = "map_post_rnd";
    this.Rnd = null;
    this.ActID = "map_post_act";
    this.Act = null;
    this.FieldID = "jscode";
    this.Field = null;
    /*
    *   get element by id
    */
    this.$id = function(id) { return document.getElementById(id); };
    this.init = function() {
        this.Frame = this.$id(this.FrameID);
        this.From = this.$id(this.FromID);
        this.Field = this.$id(this.FieldID);
        this.Act = this.$id(this.ActID);
        this.Rnd = this.$id(this.RndID);
    };
    this.showPopPage = function(code, id, x, y) {
        code = code.replace("{@id}", id);
        code = code.replace("{@x}", x);
        code = code.replace("{@y}", y);
        this.postCode(code);
    };
    this.postCode = function(code) {
        code = code.replace("{@f}", this.FrameID);
        this.Field.value = code;
        this.Act.value = "js";
        this.Rnd.value = Math.random();
        this.From.action = "http://map.lyz.cn/map.ashx";
        this.From.submit();

        //清除数据
        this.Field.value = "";
        this.Act.value = "";
        this.Rnd.value = "";
    };
    this.setPopPage = function(w, h) {
        var code = "top.frames['{@f}'].popomap.setPopPage(" + w + "," + h + ");";
        this.postCode(code, 0, 0, 0);
    };
    /**
    *   显示楼房弹出窗
    *   调用方法:
    *       设:在顶页面中实例化了本类
    *       top.proxy.showBuilding(4,160512,93184);
    */
    this.showBuilding = function(id, x, y) {
        var code = "top.frames['{@f}'].popomap.showBuilding({@id},{@x},{@y});";
        this.showPopPage(code, id, x, y);
    };
    /**
    *   显示商铺弹出窗
    */
    this.showShop = function(id, x, y) {        
        var code = "top.frames['{@f}'].popomap.showShop({@id},{@x},{@y});";
        this.showPopPage(code, id, x, y);
    };
    /**
    *   显示新闻弹出窗
    */
    this.showNews = function(id, x, y) {
        var code = "top.frames['{@f}'].popomap.showNews({@id},{@x},{@y});";
        this.showPopPage(code, id, x, y);
    };
    /**
    *   显示房产信息弹出窗-lbk
    */
    this.showHouse = function(id, x, y) {
        var code = "top.frames['{@f}'].popomap.showHouse({@id},{@x},{@y});";
        this.showPopPage(code, id, x, y);
    };
    /**
    *   显示产品弹出窗
    */
    this.showProduct = function(id, x, y) {
        var code = "top.frames['{@f}'].popomap.showProduct({@id},{@x},{@y});";
        this.showPopPage(code, id, x, y);
    };
};

var Box = Box?Box:{
    getWidth:function(doc){
        doc = doc?doc:document;
        return parseInt(doc.body.parentNode.scrollWidth);
    },
    getHeight:function (doc){
        doc = doc?doc:document;
        return parseInt(doc.body.parentNode.scrollHeight);
    },
    getTop:function (doc){
        doc = doc?doc:document;
        return parseInt(doc.body.parentNode.scrollTop);
    },
    page_width:function(doc){
        doc = doc?doc:document;
        return (navigator.appName.indexOf('Netscape', 0) != -1) ? innerWidth  : doc.body.clientWidth; 
    },
    page_height:function(doc){
        doc = doc?doc:document;
        return (navigator.appName.indexOf('Netscape', 0) != -1) ? innerHeight : doc.body.clientHeight; 
    }
};
