/////////////////////////////////////////////////////////////
//                System Class
/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////
//                Common Function
/////////////////////////////////////////////////////////////
// 根据HTML标签ID获取相应的标签对象
function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    } else {
		return false;
    }
}

// 获取指定字符串的字节长度：汉字为双字节
function getBytesLength(str) {
    var re=/[\x00-\xff]/g;
    var len=str.length;
    var array=str.match(re);
    
    if (array==null) {
        array="";
    }
    return len*2 - array.length;
}

function checkStrLen(value) {
	var str, Num = 0;
	
	for (var i=0;i < value.length; i++){
		str = value.substring(i, i+1);
		if (str <= "~")  //判断是否双字节
			Num+=1;
		else
			Num+=2;
	}
	
	return Num;
}

function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments;
	document.MM_returnValue = false;

	for (i=0; i<(args.length-1); i+=2) {
		eval(args[i]+".location='"+args[i+1]+"'");
	}
}

function GetRandomNum(Min,Max){
	// 生成随机数
	var Range = Max - Min;
	var Rand = Math.random();
	return(Min + Math.round(Rand * Range));
}

function focusObj(obj) {
    obj.focus()
    obj.select()
    return false;
}

//////////////////////////////////////////////////////////////

function showWindowOpen(url, w, h, t, l, s) {
	window.open(url, "", "width=" + w + ", height=" + h 
		+ ", resizable=0, top=" + t + ", left=" + l 
		+ ", toolbar=no, menubar=no, scrollbars=" + s 
		+ ", resizable=no, location=no, status=no");
}

function OpenWindow(page, size) {
	window.open(page, "newuser", "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no," + size);
}

//////////////////////////////////////////////////////////////

// 标题分页事件
function Title00_onClick(TrId,TdId,MaxTrId){
	for (var i=1;i<=MaxTrId;i++){
		if ( (getObject("Title00_Tr"+TrId+"_"+i+"_"+1).style != null) && (getObject("Title00_Tr"+TrId+"_"+i+"_"+2).style != null) && (getObject("Info00_Tr"+TrId+"_"+i).style != null) ) {
			if (i==TdId){
				getObject("Title00_Tr"+TrId+"_"+i+"_"+1).style.display="";
				getObject("Title00_Tr"+TrId+"_"+i+"_"+2).style.display="none";
				getObject("Info00_Tr"+TrId+"_"+i).style.display="";
			}else{
				getObject("Title00_Tr"+TrId+"_"+i+"_"+1).style.display="none";
				getObject("Title00_Tr"+TrId+"_"+i+"_"+2).style.display="";
				getObject("Info00_Tr"+TrId+"_"+i).style.display="none";
			}
		}
	}
}

function Title_onClick(TrId,TdId,MaxTrId){
	for (var i=1;i<=MaxTrId;i++){
		if ( (getObject("Title_Tr"+TrId+"_"+i+"_"+1).style != null) && (getObject("Title_Tr"+TrId+"_"+i+"_"+2).style != null) && (getObject("Info_Tr"+TrId+"_"+i).style != null) ) {
			if (i==TdId){
				getObject("Title_Tr"+TrId+"_"+i+"_"+1).style.display="";
				getObject("Title_Tr"+TrId+"_"+i+"_"+2).style.display="none";
				getObject("Info_Tr"+TrId+"_"+i).style.display="";
			}else{
				getObject("Title_Tr"+TrId+"_"+i+"_"+1).style.display="none";
				getObject("Title_Tr"+TrId+"_"+i+"_"+2).style.display="";
				getObject("Info_Tr"+TrId+"_"+i).style.display="none";
			}
		}
	}
}

//////////////////////////////////////////////////////////////

// Add by hezhibin 无缝滚动脚本 开始
var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
}

function addEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};


var Scroller = Class.create();
Scroller.prototype = {
  initialize: function(idScroller, idScrollMid, options) {
    var oScroll = this, oScroller = $(idScroller), oScrollMid = $(idScrollMid);
    
    this.SetOptions(options);
    this.Scroller = oScroller;    
    this.Speed = this.options.Speed;
    this.timer = null;
    this.Pause = 0;
    
    //用于上下滚动
    this.heightScroller = parseInt(oScroller.style.height) || oScroller.offsetHeight;
    this.heightList = oScrollMid.offsetHeight;
    
    //用于左右滚动
    this.widthScroller = parseInt(oScroller.style.width) || oScroller.offsetWidth;
    this.widthList = oScrollMid.offsetWidth;
    
    //js取不到css设置的height和width
    
    oScroller.style.overflow = "hidden";
    oScrollMid.appendChild(oScrollMid.cloneNode(true));
    
    //方向设置
    switch (this.options.Side.toLowerCase()) {
        case "right" :
            if(this.widthList <= this.widthScroller) return;
            this.Scroll = this.ScrollLeftRight;
            this.side = -1;
            break;
        case "left" :
            if(this.widthList <= this.widthScroller) return;
            this.Scroll = this.ScrollLeftRight;
            this.side = 1;
            break;
        case "down" :
            if(this.heightList <= this.heightScroller) return;
            this.Scroll = this.ScrollUpDown;
            this.side = -1;
            break;
        case "up" :
        default :
            if(this.heightList <= this.heightScroller) return;
            this.Scroll = this.ScrollUpDown;
            this.side = 1;
    }
    
    addEventHandler(oScroller, "mouseover", function() { oScroll.Stop(); });
    addEventHandler(oScroller, "mouseout", function() { oScroll.Start(); });
    
    this.Start();
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
      Step:            1,//每次变化的px量
      Speed:        50,//速度(越大越慢)
      Side:            "up",//滚动方向:"up"是上，"down"是下，"left"是左，"right"是右
      PauseHeight:    0,//隔多高停一次
      PauseWidth:    0,//隔多宽停一次
      PauseStep:    0//停顿时间(PauseHeight或PauseWidth大于0该参数才有效)
    };
    Object.extend(this.options, options || {});
  },  
  //上下滚动
  ScrollUpDown: function() {
    this.Scroller.scrollTop = this.GetScroll(this.Scroller.scrollTop, this.heightScroller, this.heightList, this.options.PauseHeight);
    
    var oScroll = this;
    this.timer = window.setTimeout(function(){ oScroll.Scroll(); }, this.Speed);
  },
  //左右滚动
  ScrollLeftRight: function() {
    //document.getElementById("test").innerHTML+=iStep+",";
    //注意:scrollLeft超过1400会自动变回1400 注意长度
    this.Scroller.scrollLeft = this.GetScroll(this.Scroller.scrollLeft, this.widthScroller, this.widthList, this.options.PauseWidth);
    
    var oScroll = this;
    this.timer = window.setTimeout(function(){ oScroll.Scroll(); }, this.Speed);
  },
  //获取设置滚动数据
  GetScroll: function(iScroll, iScroller, iList, iPause) {
    var oScroll = this, iStep = this.options.Step * this.side;
    
    if(this.side > 0){
        if(iScroll >= (iList * 2 - iScroller)){ iScroll -= iList; }
    } else {
        if(iScroll <= 0){ iScroll += iList; }
    }
    
    this.Speed = this.options.Speed;
    if(iPause > 0){
        if(Math.abs(this.Pause) >= iPause){
            this.Speed = this.options.PauseStep; this.Pause = iStep = 0;
        } else {
            this.Pause += iStep;
        }
    }
    
    return (iScroll + iStep);
  },
  //开始
  Start: function() {
    this.Scroll();
  },
  //停止
  Stop: function() {
    clearTimeout(this.timer);
  }
};

// Add by hezhibin 无缝滚动脚本 结束
//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
/* 数据库定义的remark字段为varchar(100)
jsp中定义的remark为textarea，这里定义一个函数限制输入文本的字数
add by linleran 2005.05.19
*/

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) {
		//如果元素区字符数大于最大字符数，按照最大字符数截断
		field.value = field.value.substring(0, maxlimit);
	}
}

//////////////////////////////////////////////

function selectRequestType(radioObj) {
	if(!radioObj) {
		return 0;
	}
	var intTypeCode = 0;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		if(radioObj.checked) {
			intTypeCode = radioObj.value;
		}
	} else {
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				intTypeCode = radioObj[i].value;
			}
		}
	}
	
	return intTypeCode;
	
//	alert(intTypeCode);
}

function getCheckboxValue(obj) {
	if(!obj) {
		return "";
	}
	var strReturn = "";
	var intObjLength = obj.length;
	if(intObjLength == undefined) {
		if(obj.checked) {
			strReturn = obj.value;
		}
	} else {
		for(var i = 0; i < intObjLength; i++) {
			if(obj[i].checked) {
				strReturn = strReturn + obj[i].value + ',';
			}
		}
		if (strReturn.length >1) {
			strReturn = strReturn.substr(0, strReturn.length -1); 
		}
	}
	// alert(strReturn);
	
	return strReturn;
}
/////////////////////////////////////////////

function selectAll(items, trueOrFalse){
	if(document.all(items)){
		var items = document.all(items);
		if(items.length > 1){
			for(i=0;i<items.length;i++){
				if (trueOrFalse) {
					items[i].selected = "selected";
				} else {
					items[i].selected = "";
				}
			}
			
		} else {
			if (trueOrFalse) {
				items.selected = "selected";
			} else {
				items.selected = "";
			}
		}
	}
}

function countSelectItem(objItems){
	var countNum = 0;
	if (objItems == null) {
		return countNum;
	}
	var len = objItems.length;
	// alert(len);
	if ( (len != null) && ( len != undefined ) && ( len > 0) ) {
//	if (len == undefined) {
//	if (formName.checkedItems.checked) return 1;				
//	} else {
		for(var i = 0; i < len; i++) {
			// alert(objItems[i].selected);
			if ( (objItems[i].selected) ) {
				if ( objItems[i].value == "" ) {
				} else {
					countNum = countNum +1;
				}
			}
		}
	}				
	
	// alert(countNum);
	return countNum;
}

function checkAll(items,trueOrFalse){
	if(document.all(items)){
		var items = document.all(items);
		if(items.length > 1){
			for(i=0;i<items.length;i++){
				items[i].checked = trueOrFalse;
//				if(items[i].checked == true){
//					items[i].parentNode.parentNode.style.backgroundColor = over_color;
//				}
//				else{
//					items[i].parentNode.parentNode.style.backgroundColor = "";
//				}
			}
		}
		else{
			items.checked = trueOrFalse;
//			if(items.checked == true){
//				items.parentNode.parentNode.style.backgroundColor = over_color;
//			}
//			else{
//				items.parentNode.parentNode.style.backgroundColor = "";
//			}
		}
	}
}

function countCheckedBox(formName){
	 var countNum = 0;
	 var len=formName.checkedItems.length;

		//undefined表示只有一个checkbox
		if (len==undefined) {
			if (formName.checkedItems.checked) return 1;				
		}
		else {
			for(var i=0;i<len;i++){      
				if (formName.checkedItems[i].checked) 
				 countNum++;  								
			}
		}				
		 
		 return countNum;
		
}

///////////////////////////////////////////////////////
function isWhitespace(s) {
	if(isEmpty(s)) {
		return true;
	}

	var whitespace=" /t/n/r";   
	var i;
	for(i=0;i<s.length;i++) {
		var c = s.charAt(i);
		if(whitespace.indexOf(c)!=-1) {
			continue;
		} else {
			return false;
		}
	}
	return true;
}

function isEmpty(s) {
	return ((s==null)||(s.length==0));
}