﻿/*========================
/*   Author:    KaiSin
/*   Remark:    Web Page JavaScript Base
/*   Data:      07/15/2008
/*   link:      http://x.aooshi.com/jscript/_.js
/*========================*/
if (![].push) Array.prototype.push=function(){for(var i=0; i<arguments.length; i++)this[this.length] = arguments[i];return this.length;}
if (typeof _aooshi=='undefined') var _$=function($)
{
    this.$=$;
    this._v='1.0';
    this._n="aooshi javascript base frame";
    this.create=function(_,to){_=document.createElement(_);if (to) {var __ = this.get(to);__.appendChild(_);}return _;}
    this.value = function(x,s){
        x = _.get(x);
        if (s){
            if (x && x.value){x.value = s;}
        }else{
            if (x && x.value){return _.Trim(x.value);}
            return "";
        }
    }
    this.style = function(x,s){
        x = _.get(x);
        if (s){
            if (x && x.cssText){x.cssText = s;}
        }else{
            if (x && x.cssText){return x.cssText;}
        }
    }
    this.html = function(x,s){
        x = _.get(x);
        if (s){
            if (x){x.innerHTML=s;}
        }else{
            if (x){return x.innerHTML;}
            return "";
        }
    }
    this.get=function(_){
        if (!_) return undefined;
        if (typeof(_)!='string') return _;
        if (_.indexOf(',')!= -1){
            var _=_.split(',');
            var r = [];
            for(var i in _)
            {
                i=this.get(_[i]);
                if (i instanceof Array){
                    for(var x in i)
                        r.push(i[x]);
                }else
                    r.push(i);
            }
            return r;
        }
        if (_.indexOf('>')!=-1){
            var $=[];
            var a=_.split('>');
            if (a[1] == "*"){
                a=this.gettag(a[0]);
                for(var i in a){$.push(a[i]);}
            }else{ 
                var b=a[1].split('=');
                if (b.length!=2) return undefined;
                a=this.gettag(a[0]);
                for(var i=0;i<a.length;i++){if (a[i][b[0]]&&a[i][b[0]]==b[1]) $.push(a[i]);}
            }
            return $;
        }
        if(this.$.all){return eval('this.$.all.'+_)};
        return this.$.getElementById(_);
    }
    function _css(e){
        e = _.get(e);
        if (!e) return ;
        this.add=function(n){if (e.className=='') e.className=n; else e.className += " " + n;}
        this.remove=function(n){
            var s = e.className.split(' ');var r=[];
            if (s.length==0)return;
            for(var i in s) if (s[i]!=n) r.push(s[i]);
            e.className = r.join(' ');
        }
        this.replace=function(o,n){this.remove(o);this.add(n);}
    }
    this.css = function(e){return new _css(e);}
    this.getname=function(_){
        if (!_) return undefined;
        if (typeof _!='string') return _;
        return this.$.getElementsByName(_.toString());
    }
    this.gettag=function(_){
        if (!_)return undefined;
        if (typeof _ != 'string') return _;
        return this.$.getElementsByTagName(_);
    }
    /* string */
    this.Trim = function(s){return s.toString().replace(/(^\s*)|(\s*$)/g,"");}
    this.isNumber = function(s){return s.toString().search(/^\d+$/) > -1;}
    this.isIE = function(){return navigator.userAgent.toLowerCase().indexOf("msie")!=-1;}
    this.isFirefox = function(){return navigator.userAgent.toLowerCase().indexOf('firefox')!=-1;}
    /* form */
    this.getRadio=function(n){
        var _=this.getname(n);
        for(var i=0; i< _.length;i++)
            if (_[i].checked) return _[i].value;
        return undefined;
    }
    this.setRadio = function(n,v){
        var _=this.getname(n);
        for(var i=0;i<_.length;i++){
            if (!_[i].type) continue;
            if (_[i].type != 'radio') continue;
            _[i].checked = _[i].value == v;
        }
    }
    this.setCheckBoxValue = function(n,v,split){
        var _=this.getname(n);
        if (split){
            v = v.split(split);
            for(var i=0;i<v.length;i++){this.setCheckBoxValue(n,v[i]);}
            return;
        }
        for(var i=0;i<_.length;i++){
            if (!_[i].type) continue;
            if (_[i].type != 'checkbox') continue;
            if (_[i].value == v) _[i].checked = true;
        }
    }
    this.getCheckBox=function(n){
        var _=this.getname(n);
        var __ = '';
        for(var i=0; i < _.length; i++)
            if (_[i].checked)__+=","+_[i].value;
            if (__.length>0)return __.substr(1);return '';
    }
    this.setCheckBox=function(n,v){
        var _=this.getname(n);
        for(var i=0;i<_.length;i++){
            if (!_[i].type) continue;
            if (_[i].type != 'checkbox') continue;
            if (!_[i].disabled)
                _[i].checked = v;
        }
    }
    this.setOptions=function(n,v){
        n = this.get(n);
        if (n.options && n.options.length)
            for(var i=0;i<n.options.length;i++) if (n.options[i].value == v) n.options[i].selected=true;
    }
    /* script */
    function _e(o){
        o=_.get(o);
        this.add=function(a,b){
            if (o.addEventListener) o.addEventListener(a,b,false);
            else if (o.attachEvent) o.attachEvent('on'+a,b);
            else o['on'+a]=b;
        }
        this.remove=function(a,b){
            if (o.removeEventListener) o.removeEventListener(a,b,false);
            else if(o.detachEvent) o.detachEvent('on'+a,b);
            else o['on'+a]=null;
        }
    }
    var _es = function(o){
        o=_.get(o);
        this.add = function(a,b){for(var i=0;i<o.length;i++) _.event(o[i]).add(a,b);};
        this.remove = function(a,b){for(var i=0;i<o.length;i++) _.event(o[i]).remove(a,b);}
    }
    this.event=function(o){return new _e(o);}
    this.events=function(o){return new _es(o);}
    this.eventElement=function(event){return (event.srcElement||event.target);}
    this.newclick=function(u){
	    var o = this.get('__aclick');
	    if (!o)
	    {
		    o = this.create('a');
		    o.style.display = 'none';
	        o.target = "_blank";
		    document.body.appendChild(o);
	    }
	    o.href = u;
	    if (o.click) o.click();
	    else window.open(u);
    }
    var _loadscript=function(u,f,_){
        this._exe=false;this._url = u;this._=_;
        this._load=function(){if (this._exe) return;if (f){f();this._exe=true}}
        this._i=function(){
            var t=this;
            var s=this._.gettag('script'); 
            var o=this._.create('script');
            var e;
            for(var i=0;i<s.length;i++)if (s[i].src)if (s[i].src.toLowerCase() == t._url.toLowerCase()){o=s[i];break;}
            e = this._.event(o);
            e.add('load',function(){t._load();});
            e.add('readystatechange',function(){
                 if((o.readyState!="loaded")&&(o.readyState!="complete")) return;
                o.onreadystatechange = null;t._load();
            });
            o.setAttribute("type","text/javascript");
            o.src = t._url;
            if (this._.gettag("head")[0]) this._.gettag("head")[0].appendChild(o);
        }
    }
    this.loadscript = function(u,fun){new _loadscript(u,fun,this)._i();}
    this.setmiddle = function(_s){
        var theWidth;var theHeight;if (_s) return;_s = this.get(_s);var _d=this.$.documentElement;
        if (_d&&_d.clientWidth&&this.isIE()){theWidth=_d.clientWidth+_d.scrollLeft*2;theHeight=_d.clientHeight+_d.scrollTop*2;}
        else if(window.innerWidth){theWidth = window.innerWidth;theHeight = window.innerHeight;}
        else{theWidth  = 800;theHeight = 150;}
        if (theHeight > 150) theHeight = theHeight - 100;
        obj.style.display = '';obj.style.position = "absolute";obj.style.left = (theWidth / 2) - (obj.offsetWidth / 2)+"px";
        if(isIE()) obj.style.top = ( (theHeight / 2 + this.$.body.scrollTop) - (obj.offsetHeight / 2) - 50 ) + "px";
        else{var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
        var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
        var sTop = -80 + (sClientHeight / 2 + sScrollTop) - (obj.offsetHeight / 2);
        obj.style.top = (theHeight / 2 + document.body.scrollTop) - (obj.offsetHeight / 2)+"px";}
    }
}
if (typeof _=='undefined') var _=new _$(document);