//去除空格
//作者：李伟干
function trim(str) {
	var reExp = /(^ *)(.*[^ ])( *$)/g;
	if (reExp.exec(str)!=null){
	  return RegExp.$2;
	}
	return '';
}

//将回车键转换为Tab键
//作者：黄烜东
function Element_Onkeydown()
{
	if(event.keyCode == 13)
	{
		event.keyCode = 9;
	}
}


//判断输入的年份是否太大或者太小
//作者：何滔
function Year_Onchange(eleName)
{
	var iYear;
	
	iYear = eleName.value;
	if ((iYear != "") && ((iYear > 2050) || (iYear < 1900)))
	{
		alert ("请输入正确的年份：1900 -> 2050。");
		eleName.value = "";
		eleName.focus();
	}
}

//判断输入的月份是否正确
//作者：何滔
function Month_Onchange(eleName)
{	
	var iMonth;
	
	iMonth = eleName.value
	if ((iMonth != "") && ((iMonth > 12) || (iMonth < 1)))
	{
		alert ("请输入正确的月份：1 -> 12。");
		eleName.value = "";
		eleName.focus();
	}
}

//判断输入的日是否正确
//作者：何滔
function Day_Onchange(eleName)
{
	var iDay;
	
	iDay = eleName.value;
	if ((iDay != "") && ((iDay > 31) || (iDay < 1)))
	{
		alert ("请输入正确的日期：1 -> 31。");
		eleName.value = "";
		eleName.focus();
	}
}

function IsNumber()
//作者：何滔
//判断输入的键是否阿拉伯数字或者Home、PageUp、NumLock、Tab、BackSpace、Esc、光标移动等键
{
	keyValue = window.event.keyCode;
	//if (( ((keyValue < 97) || (keyValue > 105)) && ((keyValue < 48) && (keyValue > 40)) || (keyValue > 57) || (keyValue < 33)) && (keyValue != 9) && (keyValue != 13) && (keyValue != 8) && (keyValue != 45) && (keyValue != 46) && (keyValue != 144) && (keyValue != 27))
	if(keyValue != 229 && keyValue != 8 && keyValue != 9 && keyValue != 12 && keyValue != 13 && (keyValue < 18 || keyValue > 20) && keyValue !=27 && (keyValue < 33 || keyValue > 40) && keyValue != 45 && keyValue != 46 && (keyValue < 48 || keyValue > 57) && keyValue != 91 && (keyValue < 96 || keyValue > 105 ) && (keyValue <112 || keyValue >123) && keyValue !=144 && keyValue != 145)
	{
		//alert ("请输入阿拉伯数字。");
		//alert(keyValue);
		event.returnValue =false;
		return false;
	}
	else
	{
		return true;
	}
}

function IsReal()
//作者：杨文捷
//判断输入的是否是小数
{
	keyValue = window.event.keyCode;		
	//if (( ((keyValue < 97) || (keyValue > 105)) && ((keyValue < 48) && (keyValue > 40)) || (keyValue > 57) || (keyValue < 33)) && (keyValue != 9) && (keyValue != 13) && (keyValue != 8) && (keyValue != 45) && (keyValue != 46) && (keyValue != 144) && (keyValue != 27))
	if(keyValue != 110 && keyValue != 190 && keyValue != 229 && keyValue != 8 && keyValue != 9 && keyValue != 12 && keyValue != 13 && (keyValue < 18 || keyValue > 20) && keyValue !=27 && (keyValue < 33 || keyValue > 40) && keyValue != 45 && keyValue != 46 && (keyValue < 48 || keyValue > 57) && keyValue != 91 && (keyValue < 96 || keyValue > 105 ) && (keyValue <112 || keyValue >123) && keyValue !=144 && keyValue != 145)
	{
		//alert ("请输入阿拉伯数字。");
		//alert(keyValue);
		event.returnValue =false;
		return false;
	}
	else
	{
		return true;
	}
}


function SeparateDate(sTitle, iYear, iMonth, iDay, eleNameAndID,sOther)
//作者：何滔
//产生类似于editmask的日期输入框
{
	var eleYear, eleMonth, eleDay;
	var sTemp;

	eleYear = eleNameAndID + "Year";
	eleMonth = eleNameAndID + "Month";
	eleDay = eleNameAndID + "Day";
	sTemp = "<nobr>";
	if (sTitle != "")
	{
		sTemp += "<td align = right>" + sTitle + "：</td><td align = left>";
	}
	sTemp += "<table id=tbl_date on border = 0 cellpadding=0 cellspacing=0 width = 10 " + sOther + " >";
	sTemp += "<tr><td><table border = 0 cellpadding = 0 cellspacing = 0 bordercolor = white><tr>";
	sTemp += "<td><input type = text maxlength = 4 style = 'width: 30; border: 0 solid; ' id = '" + eleYear + "' name = '" + eleYear + "' onkeydown = 'IsNumber();' onfocus = 'javascript:" + eleYear + ".select();' onkeyup = 'javascript: if(window.event.srcElement.value.length == 4){" + eleMonth + ".focus();}' value = '" + iYear + "' " + sOther + "></td>";
	sTemp += "<td><input type = text style = 'width: 7; border: 0 solid;' value = '-' disabled " + sOther + "></td>";
	sTemp += "<td><input type = text maxlength = 2 style = 'width: 16; border: 0 solid;' id='" + eleMonth + "' name='" + eleMonth + "' onkeydown = 'IsNumber();' onfocus = 'javascript:" + eleMonth + ".select();' onkeyup = 'javascript: if(window.event.srcElement.value.length == 2){" + eleDay + ".focus();}' value = '" + iMonth + "' " + sOther + "></td>";
	sTemp += "<td><input type = text style = 'width: 7; border: 0 solid;' value = '-' disabled " + sOther + "></td>";
	sTemp += "<td><input type = text maxlength = 2 style = 'width: 16; border: 0 solid;' id='" + eleDay + "' name='" + eleDay + "' onkeydown = 'IsNumber();' onfocus = 'javascript:" + eleDay + ".select();' value = '" + iDay + "' " + sOther + "></td>";
	sTemp += "</tr></table></td></tr></table>";
	if (sTitle != "")
	{
		sTemp += "</td>";
	}
	sTemp += "</nobr>";
	return sTemp;
}

function property_td_onclick(PropertyCount)
//作者：何滔
//属性选项按钮的点击响应函数，PropertyCount——属性选项按钮的个数
{
	var i;
	var eleSrc = window.event.srcElement;
	var eleID = eleSrc.id;
	var sIndex = eleID.substring(3);

	if(eleID && sIndex)
	{
		for (i = 1; i <= PropertyCount; i ++)
		{
			if(document.all("div" + i))
				document.all("div" + i).style.display = "none";
			if(document.all("td_" + i))
			with (document.all("td_" + i).style) 
			{
				filter="gray(enabled=0)"
				borderLeft   = "1px solid buttonhighlight";
				borderRight  = "1px solid black";
				borderTop    = "1px solid buttonhighlight";
				borderBottom = "1px solid black";
				cursor = "hand";
			}
			document.all("td_" + i).innerHTML = document.all("td_" + i).innerText;
		}
		with (eleSrc.style) 
		{
			borderLeft   = "1px solid black";
			borderRight  = "1px solid white";
			borderTop    = "1px solid black";
			borderBottom = "1px solid white";
			cursor = "default";
		}
		document.all("div" + sIndex).style.display = "block";
		document.all("td_" + sIndex).innerHTML = "<b>" + document.all("td_" + sIndex).innerText + "</b>";
	}
}


//打开一个URL
//作者：杨文捷
function OpenUrl(sUrl,sTarget){
    window.open(sUrl,sTarget);
}

function CreateIntegers(iBegin,iCount){
    var i;
    var Ints = new Array;
    for(i = 0;i < iCount; i++){
        Ints[i] = iBegin + i;
    }
    return Ints;    
}

//合法时间
//input : Year(年yy/yyyy),Month(月mm),Day(日dd)
//return: true(合法日期)/false(非法日期)
function IsDate(Year,Month,Day,AfAlert) {
  var theDate = new Date(Year,Month - 1,Day);
  if (theDate <= theDate) {//a Number
    if (Year < 1800 || Year > 9999) {
      if(AfAlert)
        window.alert("日期溢出");
      return false;
    }
    if (Month != theDate.getMonth() + 1 || Day != theDate.getDate()) {
      if(AfAlert)
        window.alert("非法日期");
      return false
    }
  }else{  //Not a Number
    if(AfAlert)
        window.alert("日期包含非法字符");
    return false;
  }
  return true;
}

//得到某月的天数
function GetDaysInMonth(iMonth,iYear) {
	 var aMonth = iMonth, aYear = iYear;
	
    switch (parseInt(aMonth)) {
	  case 4:
	  case 6:
	  case 9:
	  case 11:
		  return 30;
		break;
	  case 2:
		if ( ( (aYear % 4 == 0) && (aYear % 100 != 0) ) || aYear % 400 == 0 ) {
			return 29;
		}else{
			return 28;
		}
		break;
	  default:
		 return 31;
	}
}

//改变日期
//作者：杨文捷
function ChangeDate(AeleYear,AeleMonth,AeleDay,AsKind,AiNumber){    
    var iYear = parseInt(AeleYear.value);
    var iMonth = parseInt(AeleMonth.value) - 1;
    var iDay = parseInt(AeleDay.value);
    switch(AsKind){
        case "Y" :{            
            iYear += AiNumber;            
            break;
        }
        case "M" :{
            iMonth += AiNumber;            
            break;
        }
        case "D" :{
            iDay += AiNumber;                        
            break;
        }
    }    
    var dDate = new Date(iYear,iMonth,iDay);
    //alert(dDate);
    AeleYear.value = dDate.getYear();
    AeleMonth.value = dDate.getMonth() + 1;    
    AeleDay.value = dDate.getDate();
}

//时间组合框Change
//input: 组合框名称
function ChangeDateListBox(eleNameAndID) {
  var oOption;
  var i,iNum, iLength;
  var iMonth, iYear;
  
  
  iMonth = document.all("sel_Col" + eleNameAndID + "Month" ).value;
  iYear = document.all("sel_Col" + eleNameAndID + "Year" ).value; 
  iNum = GetDaysInMonth(iMonth,iYear);
  iLength = document.all("sel_Col" + eleNameAndID + "Day" ).length;
  i = 0;
  if (iNum >= iLength) {
    for (i = iLength + 1 ;i <= iNum; i++){
        oOption = document.createElement("OPTION");
        oOption.text = i; 
        oOption.value = i;
        document.all("sel_Col" + eleNameAndID + "Day" ).add(oOption);
    }
  }else{
      for (i = iLength; i > iNum; i--) {
        document.all("sel_Col" + eleNameAndID + "Day" ).remove(i-1);
      }  
   }
}

//返回
//梁健荣
function Back()
{
    window.history.back();
}	

//选择用户窗口
//梁健荣
function  SelectUsers(sNickEle, sPersonName, sIDs, iID, sGroupName){
    var sTemp;
    sTemp = 'SelectUsers.asp?IDs=' + sIDs;
    if (iID!='') sTemp += '&GID=' + iID;
    if (sGroupName!='') sTemp += '&GName=' + sGroupName;
    if(sPersonName!='') sTemp += '&PersonName=' + sPersonName;
    if(sNickEle!='') sTemp += '&NickEle=' + sNickEle;
    //alert(sTemp);
    window.open(sTemp,'SelectUsers','left=150,top=50,width=600,height=400,resizable=yes,scrollbars=yes,menubar=n');    
}

//选择单个用户,bbs版主
//潘懿
function SelectUser(sNickEle, sPersonName, sIDs, iID, sGroupName){
    var sTemp;
    sTemp = 'SelectUsers.asp?Action=Single&IDs=' + sIDs;
    if (iID!='') sTemp += '&GID=' + iID;
    if (sGroupName!='') sTemp += '&GName=' + sGroupName;
    if(sPersonName!='') sTemp += '&PersonName=' + sPersonName;
    if(sNickEle!='') sTemp += '&NickEle=' + sNickEle;
    //alert(sTemp);
    window.open(sTemp,'SelectUsers','left=150,top=50,width=600,height=400,resizable=yes,scrollbars=yes,menubar=n');
}

//梁健荣
//显示照片
function DisplayPhoto(PathEleName, ImgEleName) {
	var strPhoto = trim(PathEleName.value);
	var strExtend;
	
	if (strPhoto.length > 0) {
		strExtend = strPhoto.substr(strPhoto.length-3,3);//UCase(Right(strPhoto, 3))
		strExtend = strExtend.toUpperCase();
		//window.alert(strExtend);
		if (strExtend != "GIF" && strExtend != "JPG" && strExtend != "BMP") {
			window.alert("错误的图像格式,请输入GIF或JPG或BMP图像.");
			PathEleName.value = "";
		}else{
			ImgEleName.src=strPhoto;
		}
	}
}

//对应于 Common.asp 中的 ShowHeadButtons 的点击事件响应函数
//何滔
function HeadButtonOnClick(AsIFrame, AsUrl, AiCount)
{
	var i;
	var eleSrc = window.event.srcElement;
	var eleID = eleSrc.id;
	var sIndex = eleID.substring(3);
	AsIFrame.location.replace(AsUrl);
	if(eleID && !isNaN(sIndex))
	{
		for (i = 0; i < AiCount; i ++)
		{
			if(document.all("td_" + i))
			with (document.all("td_" + i).style) 
			{
				filter="gray(enabled=0)"
				borderLeft   = "1px solid buttonhighlight";
				borderRight  = "1px solid black";
				borderTop    = "1px solid buttonhighlight";
				borderBottom = "1px solid black";
				cursor = "hand";
			}
			document.all("td_" + i).innerHTML = document.all("td_" + i).innerText;
		}
		with (eleSrc.style) 
		{
			borderLeft   = "1px solid black";
			borderRight  = "1px solid white";
			borderTop    = "1px solid black";
			borderBottom = "1px solid white";
			cursor = "default";
		}
		document.all("td_" + sIndex).innerHTML = "<b>" + document.all("td_" + sIndex).innerText + "</b>";
	}
}

//选择用户窗口的扩充
//梁健荣
function SelectUsersEx(sNickEle, sPersonName, sNicks){
    var sTemp;
   
    sTemp = 'SelectUsers.asp?Nicks=' + sNicks; 
    if(sPersonName!='') sTemp += '&PersonName=' + sPersonName;
    if(sNickEle!='') sTemp += '&NickEle=' + sNickEle;
    window.open(sTemp,'SelectUsers','left=150,top=50,width=600,height=400,resizable=yes,scrollbars=yes,menubar=n');    
} 

//将信息添加到收藏夹
function AddInfoToFavorite(sTitle)
{   
    window.open("AddInfoToFavorite.asp?Title=" + sTitle, "_self");
}

//反选
function reselect()
{   var i;   
    for(i=0;i<document.all.tags('INPUT').length;i++){                     
        document.all.tags('INPUT')[i].checked = !document.all.tags('INPUT')[i].checked ;
    }
}

//把子结点选上
function check_click()
{   var i, j, k, sID, subID;
    var srcID = "_" + window.event.srcElement.id + "_";
    
    for(i=0;i<document.all.tags('INPUT').length;i++){
        sID = "_" + document.all.tags('INPUT')[i].id + "_";              
        if (sID.indexOf(srcID) >= 0)
        {
            document.all.tags('INPUT')[i].checked = window.event.srcElement.checked;
        }
    }
}

function OpenHTMLEditor(txt_name){
	window.open("editor.asp?txt_name=" + txt_name,"editor","left=0,top=0,width=790,height=550");
}

function IsNumberEx(sEleID, sEleDescription)
{
	var sTemp = document.all(sEleID).value;
	
	if(trim(sTemp) == "" || isNaN(sTemp))
	{
		alert("“" + sEleDescription + "”必须是数值！");
		return false;
	}
	return true;
}