// JavaScript Document
var ES_Base_js=true;

var ES_imagePath = "/images/UI2007/";

//--判断传入是否对象，如果不是就当作是对象的id
function _Object( whichID ){
	var which = (typeof(whichID)=="object")? whichID : document.getElementById(whichID);
	return which
}

//--取得对象
function _ID( oID , target ){
	if( target != null ){
		return target.document.getElementById(oID)
	}else{
		return document.getElementById(oID)
	}
}

function _PID( oID  ){
	return parent.document.getElementById(oID)
}

function _Name( oName1 ){
	return document.getElementsByName(oName1)
}

function _Tags( which , oTag ){
	return which.getElementsByTagName(oTag)
}

var IE6 = (window.navigator.appVersion.indexOf('MSIE 6.0')>0)
var IE7 = (window.navigator.appVersion.indexOf('MSIE 7.0')>0)
var isIE =(window.navigator.appName == "Microsoft Internet Explorer" )
var isFF =(window.navigator.appName == "Netscape" )

//--IE代码
if( isIE ){	
	var textValue = 'innerText'
	
}
//--FF代码	
else if( isFF ){
	var textValue = 'textContent'
}

function _LeftClick(e){
	e = e || event; 
	var button = e.button

	if( isIE ){
		return (button == 1)
	}
	if( isFF ){
		return (button == 0)
	}
}

//--取得当前对象的style对象属性
function GetCurrentStyle (obj, prop) {
	if (obj.currentStyle) {
		return obj.currentStyle[prop];
	}
	else if (window.getComputedStyle) {
		prop = prop.replace (/([A-Z])/g, "-$1");
		prop = prop.toLowerCase ();
		return window.getComputedStyle (obj, null).getPropertyValue(prop);
	}
	return null;
}


//--取得真正的位置
/*function getRealPosition(which){
	var oParent 	= which.offsetParent
	var offsetTop 	= which.offsetTop ;
	var offsetLeft 	= which.offsetLeft;
	
	if( oParent == null ){
		return offsetTop;
	}
	
	while( oParent != null ){//alert(GetCurrentStyle(oParent,'borderTopWidth')+"/"+oParent.nodeName+"/"+oParent.id)
		var borderTopWidth 		= parseInt(GetCurrentStyle(oParent,'borderTopWidth'))
		var borderLeftWidth 	= parseInt(GetCurrentStyle(oParent,'borderLeftWidth'))
		
		borderTopWidth 	= isNaN?0:borderTopWidth
		borderLeftWidth = isNaN?0:borderLeftWidth
	
		offsetTop 	+= oParent.offsetTop + borderTopWidth //+ parseInt(GetCurrentStyle(oParent,'borderBottomWidth'));
		offsetLeft 	+= oParent.offsetLeft+ borderLeftWidth //+ parseInt(GetCurrentStyle(oParent,'borderRightWidth'));

		oParent = oParent.offsetParent;
	}
	
	return {'offsetTop':offsetTop,'offsetLeft':offsetLeft};
}*/
//--取得真正的位置
function getRealPosition(which){
	var oParent 	= which.offsetParent
	var scrollTop	= 0
	var scrollLeft	= 0
	
	var offsetTop 	= which.offsetTop ;
	var offsetLeft 	= which.offsetLeft;
	
	
	//if( oParent == null ){
	//	return {'offsetTop':offsetTop,'offsetLeft':offsetLeft};
	//}
	
	while( oParent != null ){//alert(GetCurrentStyle(oParent,'borderTopWidth')+"/"+oParent.nodeName+"/"+oParent.id)
		var borderTopWidth 		= parseInt(GetCurrentStyle(oParent,'borderTopWidth'))
		var borderLeftWidth 	= parseInt(GetCurrentStyle(oParent,'borderLeftWidth'))

		var borderTopStyle 		= parseInt(GetCurrentStyle(oParent,'borderTopStyle'))
		var borderLeftStyle 	= parseInt(GetCurrentStyle(oParent,'borderLeftStyle'))
		
		borderTopWidth 	= isNaN(borderTopWidth) || borderTopStyle  == 'none' ? 0 : borderTopWidth
		borderLeftWidth = isNaN(borderLeftWidth)|| borderLeftStyle == 'none' ? 0 : borderLeftWidth
			
		offsetTop 	+= oParent.offsetTop + borderTopWidth //+ parseInt(GetCurrentStyle(oParent,'borderBottomWidth'));
		offsetLeft 	+= oParent.offsetLeft+ borderLeftWidth //+ parseInt(GetCurrentStyle(oParent,'borderRightWidth'));
		
		scrollTop	+= oParent.scrollTop
		scrollLeft	+= oParent.scrollLeft

		oParent = oParent.offsetParent;
	}

	offsetTop 	= offsetTop - scrollTop;
	offsetLeft 	= offsetLeft- scrollLeft;

	return {'offsetTop':offsetTop,'offsetLeft':offsetLeft};
}


function getRealPosition2( which ){
	//-记录浮动的对象
	var p = new Array();
	
	//--
	var oParent 	= which.parentNode;
	
	while( oParent.tagName != "BODY" ){
		if( oParent.style.position == "absolute"){
			p.push(oParent.id);
		}
		oParent = oParent.parentNode;
	}
	
	var X = 0 ;
	var Y = 0 ;
	
	for( var i = 0 ; i < p.length ; i++ ){
		var pObject = document.getElementById(p);
		
		X += pObject.offsetLeft;
		Y += pObject.offsetTop;
		
	}
	
	var position = which.style.position
	
	if(position != "absolute"){
		which.style.position = "absolute"
	}

	Y += which.offsetTop 
	X += which.offsetLeft 
	which.style.position = position
	
	
	return {offsetLeft:X,offsetTop:Y}
}


//--
function ES_MaskCreate(){
	if( document.getElementById("ES_SplitterMask") == null ){
		if( IE7 || isFF ){
			document.write('<div id="ES_SplitterMask" style="position:absolute;z-index:1000;width:100%;height:100%;background-image:url('+ES_imagePath+'mask.png);display:none"></div>')
		}else{
			document.write('<div id="ES_SplitterMask" style="position:absolute;z-index:1000;width:100%;height:100%;background:white;filter:alpha(opacity=5);opacity:0.05;display:none"></div>')
		}
	}
}
function ES_MaskShow(){
	document.getElementById("ES_SplitterMask").style.display="";
}

function ES_MaskHide(){
	document.getElementById("ES_SplitterMask").style.display="none";
}

//--表格效果
var ES_TableFX = new Object();
	ES_TableFX.hoverColor 		= "#eeffee";
	ES_TableFX.activedBgColor 	= "#6C93D9";
	ES_TableFX.activedColor 	= "white";
	ES_TableFX.activedObject= null;
	

function ES_TableFX_Set( which ){
	var tHead = which.getElementsByTagName("thead")
	var tbody = which.getElementsByTagName("tbody")[0]
	var tr = tbody.getElementsByTagName("tr")
	
	var startIndex = (tHead.length > 0) ? 0 : 1;
	
	for( var i=startIndex; i < tr.length ; i ++ ){
		tr[i].onmouseover 	= function(){
										if( ES_TableFX.activedObject != this ){
											this.style.backgroundColor=ES_TableFX.hoverColor;
										}
									}
		
		tr[i].onmouseout 	= function(){
										if( ES_TableFX.activedObject != this ){
											this.style.backgroundColor=this.getAttribute('defaultColor')||'transparent';
										}
									}
		
		tr[i].onmousedown 	= function(){
										this.style.backgroundColor	= ES_TableFX.activedBgColor;
										ES_TableFX_TdSet( this )
										
										if( ES_TableFX.activedObject != null &&  ES_TableFX.activedObject != this  ){
											ES_TableFX.activedObject.style.backgroundColor=ES_TableFX.activedObject.getAttribute('defaultColor')||'transparent';
											ES_TableFX_TdReset( ES_TableFX.activedObject ,'black' )
										}
										ES_TableFX.activedObject = this;
								}
		
	}
}

function ES_TableFX_TdSet( tr ){
	var tds = tr.childNodes;
	
	for( var i=0; i < tds.length ; i ++ ){
		tds[i].style.color = ES_TableFX.activedColor;
	}
}

function ES_TableFX_TdReset( tr ){
	var tds = tr.childNodes;
	
	for( var i=0; i < tds.length ; i ++ ){
		tds[i].style.color="";
	}
}


//--取得触发当前事件的对象
function eventElement(e){
	e = e || event;
	var object = e.srcElement || e.target;
	return object
}

//--取消冒泡
function cancelBubble(e){
	e = e || event;
	e.cancelBubble = true;
}

//--互换对象
function ES_replaceNode(which,where){
	 where.parentNode.replaceChild(which, where);
}


function String_cLength( type ) { 
	var _num 	= this.length
	var chinese	= this.match(/[^\x00-\x80]/ig)	//符合中文的集合	
	var english	= this.match(/[a-z]/ig)			//符合英文的集合	
	var number	= this.match(/[0-9]/ig)			//符数字的集合	
	var space	= this.match(/ /ig)				//符合空格的集合	
	
	if( type == "chinese" ){					//符合中文字符串的长度				
		if( chinese != null ){
			return chinese.length
		}else{
			return 0
		}
	}else if( type == "english"){				//符合英文字符串的长度
		if( english != null ){
			return english.length
		}else{
			return 0
		}	
	}else if( type == "number"){				//符合数字字符串的长度			
		if( number != null ){
			return number.length
		}else{
			return 0
		}
	}else if( type == "space"){				//符合空格字符串的长度
		if( space != null ){
			return space.length
		}else{
			return 0
		}
	}else{
		if( chinese != null ){					//整个字符串的长度	
			_num = _num + chinese.length
		}
		return _num
	}
}
String.prototype.cLength 	= String_cLength





function ES_PNG(which){
	if( IE6 ){
		var src = which.src
		var img = new Image();
			img.onload = function(){
				var width 	= this.width
				var height 	= this.height
				
					which.style.width 	= which.width == null ? width 	+ "px" : which.width
					which.style.height 	= which.height == null ?height 	+ "px" : which.height
					which.src 			= ES_imagePath + '1px.gif'
					
					which.style.filter	= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"
			}
		
		img.src = which.src;
	}
	
}


function ES_sortString(x,y){
	if(x.value==y.value ){
		return -0
	}

	var a = new Array(x.value,y.value)
	a.sort()
	
	if( a[0] == x.value ){
		return -1
	}else{
		return 1
	}
}


function ES_sortNumber(x,y){
	var a = isNaN(x.value) ? 99999 : x.value
	var b = isNaN(y.value) ? 99999 : y.value
	
  	return a - b
}



//--表格排序
function ES_SortTable( which , index ,filter ){
	which = _Object(which)	//--表格
	
	filter = filter || new Object();
	var startIndex	= filter["startIndex"]
	var tbodyIndex	= filter["tbodyIndex"]
	var inputMode	= filter["inputMode"] || false
	var inputIndex 	= filter["inputIndex"]
	var reverse 	= filter["reverse"]
	
	
	if( startIndex == null ){
		startIndex = 1;
	}
	if( tbodyIndex == null ){
		tbodyIndex = 0;
	}
	if( inputIndex == null ){
		inputIndex = 0;
	}
	
		
	var tbody 	= which.getElementsByTagName('tbody')[tbodyIndex]
	var TRs 	= tbody.childNodes
	
	var indexArray = new Array();
	var stringArray = new Array();
	
	//--将数字与行对象放到数组中
	for( var i=startIndex ; i <TRs.length ; i++ ){
		if( TRs[i].tagName ){		
			if( TRs[i].tagName.toLowerCase() == 'tr' ){	//--为ff判断是否是tr对象
			
				var c = TRs[i].childNodes
				var k = 0
				
				if( isFF ){
					for( var j=0 ; j<c.length ; j++ ){			//--为ff判断是否是td对象
						if( c[j].tagName ){
							if( c[j].tagName.toLowerCase() == 'td' ){
								
								if( k == index ){
									var value = ''
					
									if( inputMode == true ){
										value = TRs[i].childNodes[j].getElementsByTagName('input')[inputIndex].value
									}else{
										value = TRs[i].childNodes[j][textValue]
									}
									
									if( isNaN(value) ){
										stringArray.push({value:value,object:TRs[i]})
									}else{
										indexArray.push({value:value,object:TRs[i]})
									}
									
								}
								k ++ 
							}
						}
					}
					
				}else if( isIE ){								//--IE方法
					var value = ''
					
					if( inputMode == true ){
						value = TRs[i].childNodes[index].getElementsByTagName('input')[inputIndex].value
					}else{
						value = TRs[i].childNodes[index][textValue]
					}
					
					if( isNaN(value) ){
						stringArray.push({value:value,object:TRs[i]})
					}else{
						indexArray.push({value:value,object:TRs[i]})
					}
					
				}
						
			}	
		}
	}		
	
	//--按数字排时使用比较函数		
		indexArray.sort(ES_sortNumber)	
		stringArray.sort(ES_sortString)
			
	if( reverse ){	
		indexArray.reverse()	
		stringArray.reverse()	
	}		
		
	//--重新排列
	for( var i=0 ; i <indexArray.length ; i++ ){
		tbody.appendChild(indexArray[i].object)
	}
	for( var i=0 ; i <stringArray.length ; i++ ){
		tbody.appendChild(stringArray[i].object)
	}
	
}

function ES_SortIt( which ){
	var d = which.getAttribute('sortDirection')
	var r = null
	
	if( d == 'desc' ){
		r = true 
		which.setAttribute('sortDirection','asc')
	}else{
		which.setAttribute('sortDirection','desc')
	}
	
	ES_SortTable('tb1',which.cellIndex,{reverse:r})
}



function ES_Alert( str , stillTime){
	var stillTime = stillTime || 2000
	var oDiv = document.getElementById('ES_Alert_Div')
	
	if( oDiv == null ){
	
		oDiv = document.createElement('div')
		oDiv.id = 'ES_Alert_Div';
		//oDiv.disabled			= true;
		oDiv.style.fontWeight 	= 'bold'
		oDiv.style.position 	= 'absolute'
		oDiv.style.border 		= '2px outset'
		oDiv.style.background	= '#eaeaea'
		oDiv.style.color		= '#330000';
		oDiv.style.padding		= '16px';
		oDiv.style.zIndex		= '10000';
		oDiv.style.textAlign	= 'center';
		oDiv.style.overflow		= 'hidden';
		
		document.body.appendChild(oDiv);
	}
	
	oDiv.style.display = '';
	oDiv.innerHTML = str;
	
	oDiv.style.left	= (document.body.offsetWidth - oDiv.offsetWidth)/2 + 'px'
	oDiv.style.top 	= (document.body.offsetHeight - oDiv.offsetHeight)/2 + 'px'
	
	
	setTimeout(function(){oDiv.style.display = 'none'},stillTime)

}







//把已有函数的内容提取出来
function contentInFunction( whichFuc ){
	if( whichFuc != null ){
		getString 	= whichFuc.toString()			//使函数成为字符串
	
		startIndex	= getString.indexOf('{')+1		//找出大括号"{"的位置
		getString	= getString.substr(startIndex)	//提取字符
		lastIndex	= getString.lastIndexOf('}')	//找出大括号"}"的位置
		getString	= getString.substr(0,lastIndex)	//提取字符
	
		return getString
	}else{
		return ""
	}
}	

//--重构函数
function reFunction( whichFuc , addFunction ){
	eval( whichFuc+'=function(e){' + contentInFunction(eval(whichFuc)) + ';' + addFunction + '}' )
}

function ES_onSelectStart(e){
	e = e || event;
	if( ES_cancelSelect == true ){
		return false;
	}
}


function ES_onMouseMove(e){
	e = e || event;
}


function ES_onMouseUp(e){
	e = e || event;
}

function ES_onMouseWheel(e){
	e = e || event;
	ES_onMouseUp(e)
}

//--
var ES_cancelSelect = false ;
function ES_onMouseDown(e){
	e = e || event;
	
	if( ES_cancelSelect == true ){
		return false;
	}
}




