﻿String.prototype.trim = function(){return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");}
String.prototype.clearHTML = function(){return this.replace(/<[^>]+>/g,"");}
function $(v) { return document.getElementById(v); }
//导航菜单
var isOverMainMenu = false;
var isOverSubMenu = false;
function showMenu(id) {
	var a = document.getElementById("mainmenu").getElementsByTagName("a");
	for(var i=0;i<a.length;i++) {
		a[i].onmouseover = function() {
			if(this.className!="active") this.className = "hover";
			showSubMenu(this.id);
			isOverMainMenu=true;
		}
		a[i].onmouseout = function() {
			if(this.className!="active") this.className = "";
			setTimeout("showSubMenu('"+id+"')", 1);
			isOverMainMenu=false;
		}
		if(a[i].id == id) {
			a[i].className = "active";
			showSubMenu(id);
		} else {
			a[i].className = "";
		}
	}
}
function showSubMenu(id) {
	var a = $("submenu");
	a.onmouseover = function() {
		isOverSubMenu=true;
	}
	a.onmouseout = function() {
		isOverSubMenu=false;
	}
	if(!isOverSubMenu && !isOverMainMenu) {
		var b = document.getElementById("submenu").getElementsByTagName("ul");
		for(var i=0;i<b.length;i++) {
			if(b[i].id == "submenu_"+id) {
				b[i].className = "active";
			} else {
				b[i].className = "";
			}
		}
	}
}

function resizeFont(obj, size){
	$(obj).style.fontSize = size + 'px';
}

function addFavorite(url, title) {
  window.external.AddFavorite(url, title);
}

function resizeImg(_oObj){
	/*var tMark = true;var iWidth = 0;var sOuterHtml;var aNode = _oObj.attributes;
	for(var i = 0; i < aNode.length; i++){if(aNode[i].specified){if(aNode[i].name == "width" || aNode[i].name == "height"){tMark = false;}}}
	if(tMark){if(_iWidth){setTimeout("resize()",500);}}*/
	_iWidth = 600;
	setTimeout("resize()",500);
	this.resize = function(){if(_oObj.width > _iWidth){_oObj.width = _iWidth;}}
}

BindPopup.currentMenu=null;
BindPopup.back=null;
function BindPopup(binderId, popupId, align, offsetX, offsetY) {
    var binder=$(binderId);
    if(!binder)return;
    var popup=$(popupId);
    if(!popup) return;
    popup.style.position='absolute';
    popup.style.visibility='visible';
    popup.style.zIndex=10;
    if(!offsetX) offsetX=0;
    if(!offsetY)offsetY=0;
    var back=BindPopup.back;
    if(Browser.IsIE56&&!back){
        back=BindPopup.back=oNode.CreateNode('iframe');
        oNode.InsertBefore(back,popup);
        back.style.position='absolute';
        back.style.left='-1000px';
        back.style.top='-1000px';
        //CSS.SetAlpha(back,0);
    }
    var interval;
    Events.AttachEvent(binder,'mouseover',function(){
        if(interval) clearTimeout(interval);
        if(BindPopup.currentMenu&&BindPopup.currentMenu!=popup) BindPopup.currentMenu.hide();
        popup.style.zIndex=10;
        popup.style.display='';
        move();
        BindPopup.currentMenu=popup;
    });
    Events.AttachEvent(binder,'mouseout',function(){hide();});
    Events.AttachEvent(popup,'mouseover',function(){clearTimeout(interval);});
    Events.AttachEvent(popup,'mouseout',function(){hide();});
    Events.AttachEvent(window,'resize',move);
    function move(){
        popup.style.top=Global.GetOffsetTop(binder)+binder.offsetHeight+'px';
        var left=Global.GetOffsetLeft(binder);align=align||'left';
        switch(align.toString().toLowerCase()){
            case'left':
                break;
            case'center':
                left+=(binder.offsetWidth-popup.offsetWidth)/2;
                break;
            case'right':
                left+=binder.offsetWidth-popup.offsetWidth;
                break;
       }
        popup.style.left=left+offsetX+'px';
        if(back){
            back.style.left=popup.style.left;
            back.style.top=popup.style.top;
            back.style.width=popup.offsetWidth+'px';
            back.style.height=popup.offsetHeight+'px';
        }
    }
    
    function hide(){interval=setTimeout(_hide,500);}
    function _hide(){popup.style.display='none';popup.style.zIndex=1;if(back){back.style.left='-1000px';back.style.top='-1000px';}
    Events.RemoveEvent(window,'resize',move);}
    popup.hide=_hide;
}

function resetPopup(el){
    if(el.tagName.toLowerCase()=='div') return el;
    var c=document.createElement('div');
    c.innerHTML=el.innerHTML;
    oNode.RemoveNode(el);
    oNode.AddNode(c);
    c.style.display='none';
    return c;
}

function $Defined(cls){ if(typeof eval(cls)!='undefined') alert('变量'+cls+' 重定义。');}

function $USE(lib){document.write('<script type="text/javascript" src="'+Global.PATH+lib+'"><'+'/'+'script>');}
window.onerror=function(){};
String.prototype.Contains=function(str){return(this.indexOf(str)>-1);};
String.prototype.Trim=function(){return this.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,'');};
String.prototype.LTrim=function(){return this.replace(/^[ \t\n\r]*/g,'');};
String.prototype.RTrim=function(){return this.replace(/[ \t\n\r]*$/g,'');};
String.prototype.HtmlToStr=function(){return this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;');};
String.Space=function(num,htmlEntity){
    var meta=htmlEntity?'&nbsp;':'\x20';
    var str='';
    for(var i=0;i<num;i++)
        str+=meta;
    return str;
};
$Defined('Browser');
var Browser={s:navigator.userAgent.toLowerCase()};(function(b){b.IsIE=b.s.Contains('msie');b.IsIE5=b.s.Contains('msie 5');b.IsIE6=b.s.Contains('msie 6');b.IsIE7=b.s.Contains('msie 7');b.IsIE56=!b.IsIE7&&(b.IsIE6||b.IsIE5);b.IsGecko=b.s.Contains('gecko');b.IsSafari=b.s.Contains('safari');b.IsOpera=b.s.Contains('opera');b.IsMac=b.s.Contains('macintosh');b.IsIELike=(b.IsIE||b.IsOpera);b.IsGeckoLike=(b.IsGecko||b.IsSafari);})(Browser);
$Defined('Events');
var Events={};
Events.AttachEvent=function(obj,eventName,func,useCapture,_window){
    obj=$(obj);
    if(!obj)return;
    useCapture=useCapture?true:false;
    eventName=eventName.toLowerCase();
    if(obj.addEventListener){
        obj.addEventListener(eventName,func,useCapture);
    } else{
        var E=this;
        this._AttachEvent(obj,eventName,func);
        obj['on'+eventName]=function(e){E._FireEvent(obj,eventName,e,_window);};
    }
};
Events.RemoveEvent=function(obj,eventName,func,useCapture){
    obj=$(obj);
    if(!obj)return;
    useCapture=useCapture?true:false;
    eventName=eventName.toLowerCase();
    if(obj.removeEventListener){
        obj.removeEventListener(eventName,func,useCapture);
    } else{
        if(obj.events&&obj.events[eventName]){
            var evts=obj.events[eventName];
            for(var i=0,len=evts.length;i<len;i++){
                if(evts[i]&&func&&evts[i]===func){
                    evts.splice(i,1);break;
                }
            }
        }
    }
};
Events._AttachEvent=function(obj,eventName,func){
    eventName=eventName.toLowerCase();
    if(!obj.events)obj.events={};
    if(!obj.events[eventName])obj.events[eventName]=[];
    var evts=obj.events[eventName];
    evts[evts.length]=func;
};
Events._FireEvent=function(obj,eventName,e,_window){
    e=_window?_window.event:$E(e);
    eventName=eventName.toLowerCase();
    if(!obj||!obj.events||!obj.events[eventName])return;
    var evts=obj.events[eventName];
    for(var i=0,len=evts.length;i<len;i++)
        evts[i]&&evts[i].call(obj,e,obj);
};
Events.CancelBubble=function(e){
    if(!e)return;e.cancelBubble=true;
    if(e.stopPropagation)e.stopPropagation();
};
Events.CancelEvent=function(e){
    if(!e)return;e.returnValue=false;
    if(e.preventDefault)e.preventDefault();
};
Events.CancelAll=function(e){
    this.CancelBubble(e);
    this.CancelEvent(e);
};
Events.Button=function(e){
    if(e.button!=undefined)return e.button;
    else if(e.which!=undefined)return e.which;
};