﻿// JScript 文件
var displayMsgInMap = function(_x, _y, _title, _content){
    try
    {
        if(_x<=0 || _y<=0) 
        {
            return ;
        }
    }
    catch(e)
    {
        return;
    }
    
    if(window.parent.map != null)
    {
        window.parent.map.showinfohint2(_x,_y, _title, _content);
    }
}

var displayMsgInMap2 = function(_x, _y, _title, _content){
    try
    {
        if( _x<=0 || _y<=0 ) 
        {
            return ;
        }
    }
    catch(e)
    {
        return;
    }
    
    if(window.parent.parent.map != null)
    {
        window.parent.parent.map.showinfohint2(_x,_y, _title, _content);
    }
}

var SetMiniWidth=function()
{
    if (null != window.parent.brws) 
    {
         window.parent.brws.setpnlwidth(500);
    }
}

function viewnpopo(i,n)
{
    with (window.parent.map.schrsltht[i]){
        txt.innerHTML = n;
        style.zIndex = 99;
    }
}

function hidenpopo(i)
{
    with (window.parent.map.schrsltht[i]){
        txt.innerHTML = '';
        style.zIndex = 2;
    }
}

//--------------------------------------------------------------
// Copyright (C) 2006 Michael Schwarz (http://www.ajaxpro.info).
// All rights reserved.
//--------------------------------------------------------------

// prototype.js
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
};

Object.extend = function(dest, source, replace) {
	for(var prop in source) {
		if(replace == false && dest[prop] != null) { continue; }
		dest[prop] = source[prop];
	}
	return dest;
};

Object.extend(Function.prototype, {
	apply: function(o, a) {
		var r, x = "__fapply";
		if(typeof o != "object") { o = {}; }
		o[x] = this;
		var s = "r = o." + x + "(";
		for(var i=0; i<a.length; i++) {
			if(i>0) { s += ","; }
			s += "a[" + i + "]";
		}
		s += ");";
		eval(s);
		delete o[x];
		return r;
	},
	bind: function(o) {
		if(!Function.__objs) {
			Function.__objs = [];
			Function.__funcs = [];
		}
		var objId = o.__oid;
		if(!objId) {
			Function.__objs[objId = o.__oid = Function.__objs.length] = o;
		}

		var me = this;
		var funcId = me.__fid;
		if(!funcId) {
			Function.__funcs[funcId = me.__fid = Function.__funcs.length] = me;
		}

		if(!o.__closures) {
			o.__closures = [];
		}

		var closure = o.__closures[funcId];
		if(closure) {
			return closure;
		}

		o = null;
		me = null;

		return Function.__objs[objId].__closures[funcId] = function() {
			return Function.__funcs[funcId].apply(Function.__objs[objId], arguments);
		};
	}
}, false);

Object.extend(Array.prototype, {
	push: function(o) {
		this[this.length] = o;
	},
	addRange: function(items) {
		if(items.length > 0) {
			for(var i=0; i<items.length; i++) {
				this.push(items[i]);
			}
		}
	},
	clear: function() {
		this.length = 0;
		return this;
	},
	shift: function() {
		if(this.length == 0) { return null; }
		var o = this[0];
		for(var i=0; i<this.length-1; i++) {
			this[i] = this[i + 1];
		}
		this.length--;
		return o;
	}
}, false);

Object.extend(String.prototype, {
	trimLeft: function() {
		return this.replace(/^\s*/,"");
	},
	trimRight: function() {
		return this.replace(/\s*$/,"");
	},
	trim: function() {
		return this.trimRight().trimLeft();
	},
	endsWith: function(s) {
		if(this.length == 0 || this.length < s.length) { return false; }
		return (this.substr(this.length - s.length) == s);
	},
	startsWith: function(s) {
		if(this.length == 0 || this.length < s.length) { return false; }
		return (this.substr(0, s.length) == s);
	},
	split: function(c) {
		var a = [];
		if(this.length == 0) return a;
		var p = 0;
		for(var i=0; i<this.length; i++) {
			if(this.charAt(i) == c) {
				a.push(this.substring(p, i));
				p = ++i;
			}
		}
		a.push(s.substr(p));
		return a;
	}
}, false);

Object.extend(String, {
	format: function(s) {
		for(var i=1; i<arguments.length; i++) {
			s = s.replace("{" + (i -1) + "}", arguments[i]);
		}
		return s;
	},
	isNullOrEmpty: function(s) {
		if(s == null || s.length == 0) {
			return true;
		}
		return false;
	}
}, false);

if(typeof addEvent == "undefined")
	addEvent = function(o, evType, f, capture) {
		if(o == null) { return false; }
		if(o.addEventListener) {
			o.addEventListener(evType, f, capture);
			return true;
		} else if (o.attachEvent) {
			var r = o.attachEvent("on" + evType, f);
			return r;
		} else {
			try{ o["on" + evType] = f; }catch(e){}
		}
	};
	
if(typeof removeEvent == "undefined")
	removeEvent = function(o, evType, f, capture) {
		if(o == null) { return false; }
		if(o.removeEventListener) {
			o.removeEventListener(evType, f, capture);
			return true;
		} else if (o.detachEvent) {
			o.detachEvent("on" + evType, f);
		} else {
			try{ o["on" + evType] = function(){}; }catch(e){}
		}
	};

  
/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/


//note: this is a stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
}


Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

//-------------------------

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
}

//-------------------------

if (!window.Element) {
  var Element = new Object();
}

Object.extend(Element, {
  remove: function(element) {
    element = $(element);
    element.parentNode.removeChild(element);
  },

  hasClassName: function(element, className) {
    element = $(element);
    if (!element)
      return;
    var a = element.className.split(' ');
    for (var i = 0; i < a.length; i++) {
      if (a[i] == className)
        return true;
    }
    return false;
  },

  addClassName: function(element, className) {
    element = $(element);
    Element.removeClassName(element, className);
    element.className += ' ' + className;
  },
  
  removeClassName: function(element, className) {
    element = $(element);
    if (!element)
      return;
    var newClassName = '';
    var a = element.className.split(' ');
    for (var i = 0; i < a.length; i++) {
      if (a[i] != className) {
        if (i > 0)
          newClassName += ' ';
        newClassName += a[i];
      }
    }
    element.className = newClassName;
  },
  
  // removes whitespace-only text node children
  cleanWhitespace: function(element) {
    element = $(element);
    for (var i = 0; i < element.childNodes.length; i++) {
      var node = element.childNodes[i];
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
        Element.remove(node);
    }
  }
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};


// Add by wenkang...... begin
Object.extend = function(dest, source, override) {
	for(prop in source) {
		if(override || typeof dest[prop] == "undefined")
			dest[prop] = source[prop];
	}
	return dest;
}

Object.prototype.extend = function(o, override) {
	return Object.extend.apply(this, [this, o, override != false]);
}

String.prototype.extend({
	endsWith: function(s) {
		return (this.substr(this.length - s.length) == s);
	},
	startsWith: function(s) {
		return (this.substr(0, s.length) == s);
	},
	trimLeft: function() {
		return this.replace(/^\s*/,"");
	},
	trimRight: function() {
		return this.replace(/\s*$/,"");
	},
	trim: function() {
		return this.trimRight().trimLeft();
	}
}, false);

String.format = function(s){
	for(var i=1; i<arguments.length; i++){
		s = s.replace("{" + (i -1) + "}", arguments[i]);
	}
	return s;
}

// add by wenkang.... end 

function selectSimulate(objid){
	var o=document.createElement('DIV');
	o.className='selectsimulate';
	o.innerHTML=
		'<div><div class="menu" style="display:none;"></div></div>'+
		'<input type="text" class="text" readonly="readonly"/>'+
		'<a href="#" class="btn" hidefocus="hidefocus">&darr;</a>';
	o.oo=$(objid);
	o.menuobj=o.firstChild.firstChild;
	o.textobj=o.childNodes[1];
	o.btnobj=o.childNodes[2];
	o.genmenu=function(){
		if(this.oo.options.length>10){
			this.menuobj.style.height='200px';
			this.menuobj.style.overflow='auto';
		}
		else{
			this.menuobj.style.height='';
			this.menuobj.style.overflow='';
		}
		this.items=[];
		for(var i=0;i<this.oo.options.length;i++){
			var itm=this.menuobj.appendChild(document.createElement('A'));
			itm.href="#"
			itm.innerHTML=this.oo.options[i].text;
			itm._value=this.oo.options[i].value;
			itm._o=this;
			itm.onclick=function(){
				this._o.textobj.value=this.innerHTML;
				this._o.oo.value=this._value;
				this._o.menuobj.style.display='none';
				return false;
			};
			this.items.push(itm);
		}
	};
	o.togglemenu=function(evt){
		with(this.menuobj.style){
			display=(display=='none')?'':'none';
			width=this.offsetWidth-6+'px';
		}
		evt.cancelBubble=true;
		return false;
	}
	o.btnobj.onclick=o.togglemenu.bindAsEventListener(o);
	o.textobj.onclick=o.togglemenu.bindAsEventListener(o);
	o.textobj.value=o.oo.options[o.oo.selectedIndex].text;
	o.genmenu();
	o.oo.style.display='none';
	o.oo.parentNode.insertBefore(o,o.oo);
};
function selectSimulateOnBodyClick(evt){
	var ctrls=document.body.getElementsByTagName('DIV');
	for(var i=0;i<ctrls.length;i++){
		if(ctrls[i].className=='selectsimulate'){
			ctrls[i].menuobj.style.display='none';
		}
	}
};
addEvent(window,'load',function(){
	addEvent(document.body,'click',selectSimulateOnBodyClick,false);
},false);


