/**
 * @since 2006/08/01
 * @version 1.0
 */
function UaEnv(){
	this.isMac = false;
	this.isWin = false;
	this.isUnix = false;
	this.isNN = false;
	this.isIE = false;
	this.isFF = false;
	this.isOpera = false;
	this.brVer = null;
	this.isCokie = false;

	this.isCSS;
	this.isW3C;
	this.isIE4;
	this.isNN4;
	this.isIE6CSS;
	this.isCompatMode;
	this.check();
}
UaEnv.prototype = {
	check:function(){
		this.isMac = (navigator.userAgent.indexOf("Mac") != -1);
		this.isWin = (navigator.userAgent.indexOf("Win") != -1);
		this.isUnix = (navigator.userAgent.indexOf("X11") != -1);
		this.isNN = (navigator.appName.indexOf("Netscape") != -1);
		this.isIE = (navigator.appName.indexOf("Internet Explorer") != -1);
		this.isFF = (navigator.userAgent.indexOf("Firefox") != -1);
		this.isOpera = (navigator.userAgent.indexOf("Opera") != -1);
		this.brVer = (parseInt(navigator.appVersion));
		this.isCokie = this.isCookieAvarable();
		if (document.images) {
			//
			this.isCSS = (document.body && document.body.style) ? true : false;
			this.isW3C = (this.isCSS && document.getElementById) ? true : false;
			this.isIE4 = (this.isCSS && document.all) ? true : false;
			this.isNN4 = (document.layers) ? true : false;
			this.isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		}
		this.isCompatMode = (document.compatMode)?true:false;
	},
	isCookieAvarable:function(){
		var res = false;
		if(typeof document.cookie == "string"){
			if(document.cookie.length <= 0){
				document.cookie = "check";
				res = (document.cookie == "check");
				document.cookie = "";
			}else{
				res = true;
			}
		}
		return res;
	},
	getScrollLeft:function() {
		if (this.isIE) {
			return (this.isCompatMode)?document.documentElement.scrollLeft:document.body.scrollLeft;
		} else if (window.pageXOffset) {
			return window.pageXOffset;
		} else {
			return 0;
		}
	},
	getScrollTop:function() {
		if (this.isIE) {
			return (this.isCompatMode)?document.documentElement.scrollTop:document.body.scrollTop;
		} else if (window.pageYOffset) {
			return window.pageYOffset;
		} else {
			return 0;
		}
	},
	getScrollWidth:function() {
		if (this.isIE) {
			return document.body.scrollWidth;
		} else if (window.innerWidth) {
			return window.innerWidth;
		}
		return 0;
	},
	getScrollHeight:function() {
		if (this.isIE) {
			return document.body.scrollHeight;
		} else if (window.innerHeight) {
			return window.innerHeight;
		}
		return 0;
	},
	getInnerWidth:function() {
		if (this.isIE) {
			return (this.isCompatMode)?document.documentElement.clientWidth:document.body.clientWidth;
		} else if (window.innerWidth) {
			return window.innerWidth;
		}
		return 0;
	},
	getInnerHeight:function() {
		if (this.isIE) {
			return (this.isCompatMode)?document.documentElement.clientHeight:document.body.clientHeight;
		} else if (window.innerHeight) {
			return window.innerHeight;
		}
		return 0;
	}
}


/**********************************************************
* 
*/
var uaEnv = new UaEnv();

/**
 * @since 2006/08/01
 * @version 1.0
 * @requre UaUtil
 * @requre UaEnv
 */
function UaPanel(uaEnv){
	this.uaEnv = uaEnv;
	this.behindSelects = new Array();
}
UaPanel.prototype = {
	initialize:function(elemId){
		this.targetElem = document.getElementById(elemId);
		if(this.targetElem){
			this.targetElem.style.display = "none";
		}
	},
	showCenter:function(){
		this.targetElem.style.display = "block";
		var obj = this.getCenterPos(this.targetElem);
		this.shiftTo(this.targetElem, obj.x, obj.y);
		this.hideSelects(this.targetElem);
	},
	close:function(){
		this.showSelects();
		this.targetElem.style.display = "none";
	},
	getCenterPos:function(){
		var res = new Object();
		var w = (this.targetElem.offsetWidth)?this.targetElem.offsetWidth:0;
		var h = (this.targetElem.offsetHeight)?this.targetElem.offsetHeight:0;
		res.x = this.uaEnv.getScrollLeft()+this.uaEnv.getInnerWidth()/2-w/2;
		res.y = this.uaEnv.getScrollTop()+this.uaEnv.getInnerHeight()/2-h/2;
		return res;
	},
	shiftTo:function(obj, x, y) {
		var theObj = this.getObject(obj);
		if (theObj) {
			if (this.uaEnv.isCSS) {
				var units = (typeof theObj.left == "string") ? "px" : 0 ;
				theObj.left = x + units;
				theObj.top = y + units;
			} else if (this.uaEnv.isNN4) {
				theObj.moveTo(x,y);
			}else if(this.uaEnv.isIE){
				theObj.style.left = x;
				theObj.style.top = y;
			}else{
				theObj.style.left = x + "px";
				theObj.style.top = y + "px";
			}
		}
	},
	hideSelects:function(elem) {
		var towd = this.get2D(this.getObject(elem));
		var selects = document.getElementsByTagName("SELECT");
		var len = selects.length;
		for(var i=0; i<len; i++){
			var obj = this.get2D(selects[i]);
			if(obj.x+obj.w>towd.x && obj.x<towd.x+towd.w){
				if(obj.y>towd.y && obj.y<towd.y+towd.h){
					selects[i].style.visibility = "hidden";
					this.behindSelects[this.behindSelects.length] = selects[i]; 
				}
			}
		}
	},
	showSelects:function() {
		var len = this.behindSelects.length;
		for(var i=0; i<len; i++){
			this.behindSelects[i].style.visibility = "visible";
		}
	},
	getRawObject:function(obj) {
		var theObj;
		if (typeof obj == "string") {
			if (this.uaEnv.isW3C) {
				theObj = document.getElementById(obj);
			} else if (this.uaEnv.isIE4) {
				theObj = document.all(obj);
			} else if (this.uaEnv.isNN4) {
				theObj = seekLayer(document, obj);
			}
		} else {
			theObj = obj;
		}
		return theObj;
	},
	getObject:function(obj) {
		var theObj = this.getRawObject(obj);
		if (theObj && this.uaEnv.isCSS) {
			theObj = theObj.style;
		}
		return theObj;
	},
	get2D:function(obj) {
		var res = new Object();
		var theObj = this.getObject(obj);
		if (theObj) {
			res.x = this.getElementX(theObj);
			res.y = this.getElementY(theObj);
			res.w = this.getElementW(theObj);
			res.h = this.getElementH(theObj);
		}
		return res;
	},
	getElementY:function(obj){
		targetElem  = obj;
		var offsetTrail = targetElem;
		var offsetTop  = 0;
		while( offsetTrail ){
			offsetTop  += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		return offsetTop;
	},
	getElementX:function(obj){
		targetElem  = obj;
		var offsetTrail = targetElem;
		var offsetLeft  = 0;
		while( offsetTrail ){
			offsetLeft  += offsetTrail.offsetLeft;
			offsetTrail = offsetTrail.offsetParent;
		}
		return offsetLeft;
	},
	getElementH:function (obj) {
		var res = null;
		if(obj){
			res = obj.offsetHeight;
		}
		return res;
	},
	getElementW:function (obj) {
		var res = null;
		if(obj){
			res = obj.offsetWidth;
		}
		return res;
	}
}



/**********************************************************
* 
*/
var uaPanel = new UaPanel(uaEnv);





