//**************************************************
// Javascript Operating System 
// By Kinvix@gmail.com 2008.5
//**************************************************

//==================================================
//系统核心:javascript语句增强部分
//
//包括：OOP编程模式类的实现，程序动态载入器
//==================================================


//-------------------------
//让IE支持HTMLElement的代码，必须结合$()用；
//例：
//HTMLElement.prototype.getHeight=function(){
//	alert(this.innerHTML)
//	return this.style.height;
//}
//alert($E("div1").getHeight());
//-------------------------
if (!("HTMLElement" in window)){
	window.isIE=true;
	window.HTMLElement = function() {};
}
//可以让IE支持HTMLElement的$()
function $E() {
	var elements,i,length,element,m;;
	elements = new Array();
	length = arguments.length;
	for (i= 0; i < length; i++){
		element = arguments[i];
		//复制HTMLElement对象的方法和属性
		if (typeof element == "string"){
			element = document.getElementById(element);
		}
		//如果是IE，不支持HTMLElement，则复制HTMLElement对象的方法和属性到当前对象
		if(window.isIE){
			for(m in HTMLElement.prototype){
				if(element!=null){
					element[m]=HTMLElement.prototype[m];
				}
			}
		}
		elements.push(element);
	}
	//如果只有一个对象
	if (arguments.length == 1){
		elements=elements[0];
	}
	return elements;
}
function getElementByClassName(cls,elm) {   
    var arrCls =[];   
    var seeElm = elm ? elm : '*';   
    var rexCls = new RegExp('(^|\\\\s)' + cls + '(\\\\s|$)','i');
    var lisElm = document.getElementsByTagName(seeElm);   
    for (var i=0; i<lisElm.length; i++ ) {   
        var evaCls = lisElm[i].className;   
        if(evaCls.length > 0 && (evaCls == cls || rexCls.test(evaCls))) {   
            arrCls.push(lisElm[i]);   
        }   
    }   
    return arrCls;   
} 
//var $C=getElementByClassName;



//-------------------------
//jos底层定义
//-------------------------
if(!window["jos"]){
	var b_name=navigator.appName  
	var b_version=navigator.appVersion  
	var version=b_version.split(";");  
	var trim_Version=version[1].replace(/[ ]/g,"");  
	if(b_name=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){  
		//alert("IE 7.0");  
	}  
	else if(b_name=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){  
		//alert("IE 6.0");  
	}  
	
	window["jos"]={};
	jos = {
		//环境参数
		Version:'0.1',
		
		Browser:{
			IE:     !!(window.attachEvent && !window.opera),
			IE6:    b_name=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"?true:false,
			IE7:    b_name=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"?true:false,
			Opera:  !!window.opera,
			WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
			Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
			MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
		},
		//-------------------------
		//jos.config框架全局配置
		//-------------------------
		config:{
			isDebug: true, 
			debugContainerId: "",
			allowQueryConfig: false,
			basescriptUri: "",
			parseWidgets: true,
			searchIds: [],
			baseRelativePath: "",
			libraryscriptUri: "",
			iePreventClobber: false,
			ieClobberMinimal: true,
			preventBackButtonFix: true
		},
		
		
		
		

		parentX:function(elem) {

				return elem.parentNode == elem.offsetParent ?
						elem.offsetLeft :

						pageX( elem ) - pageX( elem.parentNode );
		},
		

		parentY:function(elem) {

				return elem.parentNode == elem.offsetParent ?
						elem.offsetTop :

						pageY( elem ) - pageY( elem.parentNode );
		},
		//窗口
		windowWidth:function(){
			var de=document.documentElement;
			return self.innerWidth||(de&&de.clientWidth)||document.body.clientWidth;
		},
		windowHeight:function(){
			var de=document.documentElement;
			return self.innerHeight||(de&&de.clientHeight)||document.body.clientHeight;
		}
		
	};
	
	
	
	
	HTMLElement.prototype.show=function(){
		show(this);
	};
	HTMLElement.prototype.hide=function(){
		hide(this);
	};
	HTMLElement.prototype.setOpacity=function(level){
		setOpacity(this, level);
	};
	HTMLElement.prototype.setFlash=function(level){
		setFlash(this, level);
	};
	HTMLElement.prototype.fadeIn=function(level,callback){
		fadeIn(this,level,callback);
	};
	HTMLElement.prototype.blurIn=function(){
		blurIn(this);
	};
	HTMLElement.prototype.waveIn=function(){
		waveIn(this);
	};
	HTMLElement.prototype.dreamIn=function(){
		dreamIn(this);
	};
	HTMLElement.prototype.slideOut=function(){
		slideOut(this);
	};
	HTMLElement.prototype.slideRight=function(){
		slideRight(this);
	};
	HTMLElement.prototype.slideDown=function(){
		slideDown(this);
	};
	
	window.width=jos.windowWidth;
	window.height=jos.windowHeight;
	
	HTMLElement.prototype.addDrag=function(oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper, callbackObj){
		var o=this;
		oRoot=oRoot||null;
		minX=minX||null;
		maxX=maxX||null;
		minY=minY||null;
		maxY=maxY||null;
		bSwapHorzRef=bSwapHorzRef||null;
		bSwapVertRef=bSwapVertRef||null;
		fXMapper=fXMapper||null;
		fYMapper=fYMapper||null;	
		callbackObj=callbackObj||null;
		jos.Drag.init(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper,callbackObj);
	};
	
	//DOM method
	HTMLElement.prototype.cleanWhitespace=function(){
		return cleanWhitespace(this);
	};
	HTMLElement.prototype.parent=function(){
		return parent(this);
	};
	HTMLElement.prototype.first=function(){
		return first(this);
	};
	HTMLElement.prototype.last=function(){
		return last(this);
	};
	HTMLElement.prototype.prev=function(){
		return prev(this);
	};
	HTMLElement.prototype.next=function(){
		return next(this);
	};
	
	
	HTMLElement.prototype.getHeight=function(){
		return getHeight(this);
	};
	
	HTMLElement.prototype.parentX=function(){
		return jos.parentX(this);
	};
	
	HTMLElement.prototype.parentY=function(){
		return jos.parentY(this);
	};
	
	


}










//DOM操作

function cleanWhitespace( element ) {
    element = element || document;
    var cur = element.firstChild;
    while ( cur != null ) {
        if ( cur.nodeType == 3 && ! /\S/.test(cur.nodeValue) ) {
            element.removeChild( cur );
        } else if ( cur.nodeType == 1 ) {
             cleanWhitespace( cur );
        }
        cur = cur.nextSibling; 
    }
}
function parent( elem, num ) {
    num = num || 1;
    for ( var i = 0; i < num; i++ )
        if ( elem != null ) elem = elem.parentNode;
    return elem;
}
function prev( elem ) {
    do {
        elem = elem.previousSibling;
    } while ( elem && elem.nodeType != 1 );
    return elem;
}
function next( elem ) {
    do {
        elem = elem.nextSibling;
    } while ( elem && elem.nodeType != 1 );
    return elem;
}
function first( elem ) {
    elem = elem.firstChild;
    return elem && elem.nodeType != 1 ?next( elem ) : elem;
}
function last( elem ) {
    elem = elem.lastChild;
    return elem && elem.nodeType != 1 ?prev( elem ) : elem;
}



// trim() , lTrim() , rTrim()
String.prototype.trim = function(){ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
String.prototype.lTrim = function() 
{ 
return this.replace(/(^\s*)/g, ""); 
} 
String.prototype.rTrim = function() 
{ 
return this.replace(/(\s*$)/g, ""); 
} 








