//判断是否为空字符串
String.prototype.isEmpty=function(){
    if(this==null || this.trim().length == 0){
        return true;
    }
    return false;
}

// Function Description: ȥ���去除字符串的首尾的空格
String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

// Function Description: s2替换全部指定字串s1
String.prototype.replaceAll = function(s1,s2){
	return this.replace(new RegExp(s1,"gm"),s2);
}

// Function Description: 判断输入是否是一个正整数
String.prototype.isValidPositiveInteger=function(){
	var result=this.match(/^\d+$/);
	if(result==null) return false;
	if(parseInt(this)>0) return true;
	return false;
}

// Function Description:判断输入是否是一个由 0-9 组成的数字
String.prototype.isValidDigits=function(){
	var result=this.match(/^[0-9]+$/);
	if(result==null) return false;
	return true;
}

// Function Name: isValidDigits2
// Function Description:判断输入是否是一个由 0-9 组成的2位的数字
// Creation Date: 2004-7-13 10:10
// Last Modify By: N/A
// Last Modify Date: N/A
String.prototype.isValidDigits2=function(){
	var result=this.match(/(^[0-9]{2}$)/);
	if(result==null) return false;
	return true;
}

// Function Name: isValidDigits3
// Function Description:判断输入是否是一个由 0-9 组成的3位的数字
// Creation Date: 2004-7-13 10:10
// Last Modify By: N/A
// Last Modify Date: N/A
String.prototype.isValidDigits3=function(){
	var result=this.match(/(^[0-9]{3}$)/);
	if(result==null) return false;
	return true;
}



// Function Name: isValidDate
// Function Description: 判断输入是否是有效的短日期格式 : "YYYY-MM-DD"或"YYYY-M-D"
// Creation Date: 2004-7-13 9:58
// Last Modify By: N/A
// Last Modify Date: N/A
String.prototype.isValidDate=function(){
	var result=this.match(/^(\d{4})(-)(\d{1,2})(-)(\d{1,2})$/);
	if(result==null) return false;
	var d=new Date(result[1], result[3]-1, result[5]);
	return (d.getFullYear()==result[1] && d.getMonth()+1==result[3] && d.getDate()==result[5]);
}

// Function Name: isValidTime
// Function Description: 判断输入是否是有效的短时间格式 : "HH:mm"
// Creation Date: 12:58
// Last Modify By: N/A
// Last Modify Date: N/A
String.prototype.isValidTime=function() { 
 var a = this.match(/^(\d{1,2})(:)(\d{1,2})$/); 
 if (a == null) {return false;} 
 if (a[1]>24 || a[3]>60 || a[4]>60)  {
 	return false 
 } 
 return true; 
} 


//判断是否为有效的email地址
String.prototype.isValidEmail=function(){
	//var emailPat=/^(.+)@(.+)$/; 
	var emailPat=/(\w)+@(\w)+\.(com|net|cn|org)/;
	var matchArray=this.match(emailPat); 
	if (matchArray==null)return false;
	return true;
}

//判断是否为有效的大写字母
function validLengthAlphabet(val){
	var allBigAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (var i = 0; i < val.length; i++){
		var c = val.charAt(i);
    	if (allBigAlphabet.indexOf(c) == -1) return false;
	}
	return true;
}

//判断是否由26个英文字母或数字组成的字符串
function isAlphabet(s){
	var patrn=/^[A-Za-z0-9]+$/;
	if (s.match(patrn)==null) return false;
	return true;
}




//是否格式为：1,5-100
//使用","和"-"分割的数字
function validCommaLineDigit(str){
	var str1 = new Array();
	var str2 = new Array();
	str1 = str.split(",");
	for(var i=0;i<str1.length;i++){
		str2 = str1[i].split("-");
		if(str2.length==1){
			if(!str2[0].isValidDigits())
				return false;
		}else{
			if(str2.length==2){
				if(!str2[0].isValidDigits())
					return false;
				else{
					if(!str2[1].isValidDigits())
						return false;
				}
			}else
				return false;
		}
	}
	return true;
}


//判断是否使用"-"分割的连续数字
function validLineContinusDigit(str){
	var str1 = new Array();
	var str2 = new Array();
	str1 = str.split(",");
	if(str1.length>1)
		return false;
	else{
		for(i=0;i<str1.length;i++){
			str2 = str1[i].split("-");
			if(str2.length==1){
				if(!str2[0].isValidDigits())
					return false;
			}else{
				if(str2.length==2){
					if(!str2[0].isValidDigits())
						return false;
					else{
						if(!str2[1].isValidDigits())
							return false;
					}
				}else
					return false;
			}
		}
	}
	return true;
}

//判断是否使用"."分割的连续数字
function validPointContinusDigit(str){
	var str1 = new Array();
	var str2 = new Array();
	str1 = str.split(",");
	if(str1.length>1)
		return false;
	else{
		for(i=0;i<str1.length;i++){
			str2 = str1[i].split(".");
			if(str2.length==1){
				if(!str2[0].isValidDigits())
					return false;
			}else{
				if(str2.length==2){
					if(!str2[0].isValidDigits()){
						return false;
					}else{
						if(!str2[1].isValidDigits())
							return false;
					}
				}else
					return false;
			}
		}
	}
	return true;
}

//判断是否使用":"分割的连续数字
function validLineContinusDigit2(str){
	var str1 = new Array();
	var str2 = new Array();
	str1 = str.split(",");
	if(str1.length>1)
		return false;
	else{
		for(i=0;i<str1.length;i++){
			str2 = str1[i].split(":");
			if(str2.length == 1){
				if(!str2[0].isValidDigits())
					return false;
			}else{
				if(str2.length==2){
					if(!(str2[0].isValidDigits() || str2[0].isValidDigits2() || str2[0].isValidDigits3()))
						return false;
					else{
						if(!(str2[1].isValidDigits() || str2[1].isValidDigits2() || str2[1].isValidDigits3()))
							return false;
					}
				}else{
					return false;
				}
			}
		}
	}
	return true;
}

/**
 * 处理字符串，将里面得"?"替换成":"
*/
function strReplace(sourceStr){
	var destStr;
	if(sourceStr.indexOf("?") >= 0){
		var strArr = sourceStr.split("?");
		destStr = strArr.join(":");
	}
	return destStr;
}

/**
	弹出指定大小、无帮组按钮、无滚动条的模式对话框
function openModalWin(page,params,pWidth,pHeight){
	window.showModalDialog(page,params,'help:no;scroll:no;status: no;dialogWidth='+pWidth+'px;dialogHeight='+pHeight+'px');
}
*/

/**
 * 弹出特定格式(无工具栏、无地址栏等)的窗口
*/
function openNewWin(page,name,pWidth,pHeight){
	allSets='resizable=no,toolbar=no,location=no,width='+pWidth+',height='+pHeight+',diretories=no,status=no,menubar=no,left=0,top=0';
	newWin = window.open( page, name, allSets);
	newWin.focus();
}

//得到特定ｉｄ的复选框数组
function getCheckBoxArrayByName(idName){
	var checkBoxArr = new Array();//标记为input的标签元素
	var checkBoxArray = new Array();//标签类型为text的input标签元素
	with (document.all) {
		checkBox = document.getElementsByTagName("input");//提出标记为input的标签元素
		for(j = 0;j<checkBox.length;j++){
			if(checkBox[j].type=='checkbox' && checkBox[j].name==idName){//提取标签类型为text的标签元素
				checkBoxArray[checkBoxArray.length] = checkBox[j];
			}
		}
	}
	return checkBoxArray;
}

/**
 * 弹出式菜单
 */
function showPopUpContent(content){
	var oPopup = window.createPopup();
	var oPopBody = oPopup.document.body;
	oPopBody.style.backgroundColor = "#F0F4F9";
	oPopBody.style.border = "solid #577290 1px";
	oPopBody.style.text = "vertical-align:middle";
	oPopBody.innerHTML = "<p align=center>"+content+"</p>";
	oPopup.show(screen.width/2 - 15, screen.height/2 - 90, 180, 30, document.body);
}


/**
 * 系统等待提示信息
 * 层显示控制
*/
function showTipDiv(contentDivId,tipDivId){
	document.all(contentDivId).style.display = "none";
	document.all(tipDivId).style.display = "block";
}
/**
 *javascript 时间对象的格式化
 *如new Date().format("yyyy-MM-dd hh:mm:ss")
 *返回2007-2-23 0:35:12 
*/
Date.prototype.format = function(format){
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(), //day
		"h+" : this.getHours(), //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter
		"S" : this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format)) 
		format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	return format;
} 


function goUrl(str){
	window.top.location = str;
}


function E(id){
	return document.getElementById(id);
}


/******************计算object在document的top,left***********************/
function getElementTop(obj){
	return calculateOffsetTop(obj) + obj.offsetHeight;
}

function getElementLeft(obj){
	return calculateOffsetLeft(obj);
}

function calculateOffsetLeft(field) {
  return calculateOffset(field, "offsetLeft");
}

function calculateOffsetTop(field) {
  return calculateOffset(field, "offsetTop");
}

function calculateOffset(field, attr) {
  var offset = 0;
  while(field) {
    offset += field[attr]; 
    field = field.offsetParent;
  }
  return offset;
}