function trim(strValue)
{
	var intStart=0;
	for(var i=0;i<strValue.length;i++)
	{
		if(strValue.substring(i,i+1)!=" "){
			intStart=i;
			break;
		}
	}
	var intEnd=strValue.length;
	for(var i=strValue.length;i>=0;i--)
	{
		if(strValue.substring(i-1,i)!=" "){
			intEnd=i;
			break;
		}
	}
	return strValue.substring(intStart,intEnd);
}

function getFindCount(strSource,strFind)
{
	var s=strSource.split(strFind);
	return s.length-1;
}

function getStringLength(strValue)
{
	var k=0;
	for(var i=0;i<strValue.length;i++){
		if(strValue.charCodeAt(i)>=0 && strValue.charCodeAt(i)<=255){
			k=k+1;
		}
		else{
			k=k+2;
		}
	}
	return k;
}

function isInt(strValue)
{
	if(strValue.substring(0,1)=="+" || strValue.substring(0,1)=="-"){
		strValue=strValue.substr(1);
	}
	if(strValue.length==0){
		return false;
	}
	for(var i=0;i<strValue.length;i++){
		if(strValue.charCodeAt(i)<48 || strValue.charCodeAt(i)>57){
			return false;
		}
	}
	return true;
}

function isEmail(strValue)
{
	  if(!(strValue.indexOf("@") > -1 && strValue.indexOf(".") > -1))
         return false;    

	return true;
}

function isDouble(strValue)
{
	if(strValue.substring(0,1)=="+" || strValue.substring(0,1)=="-"){
		strValue=strValue.substr(1);
	}
	if(strValue.length==0){
		return false;
	}
	if(getFindCount(strValue,".")>1){
		return false;
	}
	if(strValue.substring(0,1)=="." || strValue.substring(strValue.length-1,strValue.length)=="."){
		return false;
	}
	for(var i=0;i<strValue.length;i++){
		var code=strValue.charCodeAt(i);
		if(code==46 || (code>=48 && code<=57)){}
		else{
			return false;
		}
	}
	return true;
}

function replace(strSource,strFind,strNew)
{
	var s=strSource;
	s=eval("strSource.replace(\/"+strFind+"\/g,\""+strNew+"\")");
	return s;
}

//,=44 '=39 "=34 >=62 <=60 & 38 ?
function replaceErrChar(strValue)
{
	strValue=replace(strValue,",","，");
	strValue=replace(strValue,"'","’");
	strValue=replace(strValue,"\"","”");
	strValue=replace(strValue,">","］");
	strValue=replace(strValue,"<","［");
	strValue=replace(strValue,"&","＋");
	strValue=replace(strValue,"\\?","？");
	return strValue;
}

//,=44 '=39 "=34 >=62 <=60 & 38 ?
function replaceHtmlErrChar(strValue)
{
	strValue=replace(strValue,"'","’");
	strValue=replace(strValue,"\"","”");
	strValue=replace(strValue,">","］");
	strValue=replace(strValue,"<","［");
	return strValue;
}

//yyyy-mm-dd
function isShortDate(strValue)
{
	if(strValue.length!=10){
		return false;
	}
	if(strValue.substring(4,5)!="-"){
		return false;
	}
	if(strValue.substring(7,8)!="-"){
		return false;
	}
	var strYear=strValue.substring(0,4);
	var strMonth=strValue.substring(5,7);
	var strDay=strValue.substring(8,10);
	if(isInt(strYear)==false){
		return false;
	}
	if(isInt(strMonth)==false){
		return false;
	}
	if(isInt(strDay)==false){
		return false;
	}
	if(strYear<1900 || strYear>2050){
		return false;
	}
	if(strMonth<1 || strMonth>12){
		return false;
	}
	if(strDay<1 || strDay>31){
		return false;
	}
	return true;
}

//12:23:12
function isTime(strValue)
{
	if(strValue.length!=8){
		return false;
	}
	if(strValue.substring(2,3)!=":"){
		return false;
	}
	if(strValue.substring(5,6)!=":"){
		return false;
	}
	var strHour=strValue.substring(0,2);
	var strMin=strValue.substring(3,5);
	var strSen=strValue.substring(6,8);
	if(isInt(strHour)==false){
		return false;
	}
	if(isInt(strMin)==false){
		return false;
	}
	if(isInt(strSen)==false){
		return false;
	}
	if(strHour<0 || strHour>23){
		return false;
	}
	if(strMin<0 || strMin>59){
		return false;
	}
	if(strSen<0 || strSen>59){
		return false;
	}
	return true;
}

//yyyy-mm-dd hh:mm:ss
function isLongDate(strValue)
{
	if(strValue.length!=19){
		return false;
	}	
	if(isShortDate(strValue.substring(0,10))==false){
		return false;
	}
	if(isTime(strValue.substring(11,19))==false){
		return false;
	}
	return true;
}

function focus(ctlText,strInfo)
{
	alert(strInfo);
	if(ctlText.disabled==true){
		return ;
	}
	ctlText.focus();
	//ctlText.select();	
}


function formOnSubmit(frmForm)
{
	for(var i=0;i<frmForm.elements.length;i++){
		var ctl=frmForm.elements[i];
		if(ctl.getAttribute("IsTime")!=null){
			if(isShortDate(ctl.value)==false && isLongDate(ctl.value)==false){
				alert("时间必须不能为空");
				return false;
			}
		}

		if(ctl.getAttribute("type").toUpperCase()=="TEXT" || ctl.tagName=="TEXTAREA" || ctl.getAttribute("type").toUpperCase()=="PASSWORD" || ctl.getAttribute("type").toUpperCase()=="FILE"){
			var strInfo=ctl.getAttribute("Info");
			ctl.value=trim(ctl.value);
			
			if(ctl.getAttribute("IsHtml")=="1"){
				ctl.value=replaceHtmlErrChar(ctl.value);
			}
			else{
				ctl.value=replaceErrChar(ctl.value);
			}

			if(ctl.getAttribute("NoEmpty")=="1"){
				if(ctl.value==""){
					focus(ctl,strInfo+"不能为空");
					return false;
				}
			}

			if (ctl.getAttribute("isEmail")=="1")
			{
				if(ctl.value!=""){
				if (isEmail(ctl.value)==false)
				{
					focus(ctl,strInfo+"必须是正确的邮箱地址!");
					return false;
				}
				}
			}

			
				if(ctl.getAttribute("IsInt")=="1"){
					if(ctl.value!=""){
					if(isInt(ctl.value)==false){
						focus(ctl,strInfo+"应是整数");
						return false;
					}
					}
				}

				if(ctl.getAttribute("IsDouble")=="1"){
					if(ctl.value!=""){
					if(isDouble(ctl.value)==false){
						focus(ctl,strInfo+"应是小数型数据");
						return false;
					}
					}
				}

				if(ctl.getAttribute("MinValue")!=null){
					var dblValue=parseFloat(ctl.value);
					var dblMin=parseFloat(ctl.getAttribute("MinValue"));
					if(dblValue<dblMin){
						focus(ctl,strInfo+"不能小于"+ctl.getAttribute("MinValue"));
						return false;
					}
				}
		
				if(ctl.getAttribute("MaxValue")!=null){
					var dblValue=parseFloat(ctl.value);
					var dblMax=parseFloat(ctl.getAttribute("MaxValue"));
					if(dblValue>dblMax){
						focus(ctl,strInfo+"不能大于"+ctl.getAttribute("MaxValue"));
						return false;
					}
				}

				if(ctl.getAttribute("MinLen")!=null){
					var dblMinLen= parseInt(ctl.getAttribute("MinLen"));
					if(getStringLength(ctl.value)<dblMinLen){
						focus(ctl,strInfo+"字符长度不能小于"+ctl.getAttribute("MinLen"));
						return false;
					}
				}

				if(ctl.getAttribute("MaxLen")!=null){
					var dblMaxLen= parseInt(ctl.getAttribute("MaxLen"));
					if(getStringLength(ctl.value)>dblMaxLen){
						focus(ctl,strInfo+"字符长度不能超过"+ctl.getAttribute("MaxLen"));
						return false;
					}
				}


				if(ctl.getAttribute("IsShortDate")=="1"){
					if(ctl.value!=""){
					if(isShortDate(ctl.value)==false){
						focus(ctl,strInfo+"应是日期型数据（如：2003-04-18）");
						return false;
					}
					}
				}


				if(ctl.getAttribute("IsLongDate")=="1"){
					if(ctl.value!=""){
					if(isLongDate(ctl.value)==false){
						focus(ctl,strInfo+"应是日期型数据（如：2003-04-18 12:23:00）");
						return false;
					}
					}
				}
//判断有效字符传
				if(ctl.getAttribute("IsValidChar")=="1"){
				var arrValidChar=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","_","-","."]

				}


			}else{
				if(ctl.getAttribute("NoEmpty")=="1"){
					if(ctl.getAttribute("type").toUpperCase()=="HIDDEN" ){
						alert(ctl.getAttribute("Info")+"不能为空");
						return false;
					}else{
							if(ctl.value==""){
								focus(ctl,ctl.getAttribute("Info")+"不能为空");
								return false;
							}
						}
				}
			}

		}
		
		return true;	
}



function CloseFrm()
{
	self.close();
}

function getRadioSelectId(optValue)
{
	for(var i=0;i<optValue.length;i++){
		if(optValue[i].checked==true){
			return i;
		}
	}
}
function openwindow(strUrl,intWidth,intHeight){
	window.open(strUrl,"","width="+intWidth+",height="+intHeight);
}
function gotoURL(url){
if(url!==""){
document.location=url;
}
}
function checkJumpPage(thisform){
var number="0123456789";
if(thisform.page.value.length>0){
 for(i=0;i<thisform.page.value.length;i++){
	if(!(number.indexOf(thisform.page.value.charAt(i))>-1)){
	alert("页码必须是正整数！");
	thisform.page.select();
	return false;
	}
	}
}else{
	alert("请输入页码！");
	return false;
	thisform.page.select();
}
}



function isCheckBoxChecked(chkTemp)
{
	for(var i=0;i<chkTemp.length;i++){
		if(chkTemp[i].checked==true){
			return i;
		}
	}
}

//打印时间
function printDate(strDateTime,strTimeType){
var week,day,month,year,hour,minute,second;
function initArray(){
this.length = initArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]
}
var LastModDate = strDateTime;
var WeekArray = new initArray(" 星期日"," 星期一"," 星期二"," 星期三"," 星期四"," 星期五"," 星期六");
var MonthArray = new initArray("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
day = LastModDate.getDate() + "日 ";
year = LastModDate.getFullYear() +"年 ";
week = WeekArray[(LastModDate.getDay()+1)];
month = MonthArray[(LastModDate.getMonth()+1)];
hour=LastModDate.getHours()+":";
minute=LastModDate.getMinutes()+":";
second=LastModDate.getSeconds();

if(strTimeType=="LONG"){
	document.write(year,month,day,hour,minute,second,week);

}else{
	if(strTimeType=="SHOT"){
		document.write(year,month,day,week);
	}else{
		document.write(year,month,day,week);
	}
}
}



function getBOOKPicUpload(txtId,txtName,intSelType)
{
	var dte=new Date();
	var strFile="../bookpicupload/selectBOOKPicUpload.asp?dte="+dte.getTime()+"&SelType="+intSelType;
	var strResult=showModalDialog(strFile,1,"dialogHeight:480px;dialogWidth:425px;status=no;resizable=yes");
	if(strResult==null){
		return "";
	}
	var s=strResult.split("&");
	txtId.value=s[0];
	txtName.value=s[1];
    return strResult;
}



//HTMLEditor Function
function CreateFullHtmlEditor(strInstanceName,strValue){
	var oHtmleditor ;
	oHtmleditor = new FCKeditor(strInstanceName) ;
	oHtmleditor.Value = strValue ;
	oHtmleditor.Create() ;
	}

function CreateMiddleHtmlEditor(strInstanceName,strValue){
	var oHtmleditor ;
	oHtmleditor = new FCKeditor(strInstanceName) ;
	oHtmleditor.Value = strValue ;
	oHtmleditor.CanUpload = false ;	
	oHtmleditor.CanBrowse = false ;	
	oHtmleditor.Create() ;
	}
	
function CreateSimpleHtmlEditor(strInstanceName,strValue){
	var oHtmleditor ;
	oHtmleditor = new FCKeditor(strInstanceName, "100%", "150", 'Basic', strValue) ;
	oHtmleditor.CanUpload = false ;	
	oHtmleditor.CanBrowse = false ;	
	oHtmleditor.Create() ;
	}

//HTMLEditor Contraller
document.write("<SCRIPT language='javascript' src='../include/HtmlEditor/fckeditor.js'></SCRIPT>");

//DateTime Contraller
document.write("<LINK href=\"../include/datecontrol/DatePicker.css\" type=text/css rel=stylesheet>");
document.write("<SCRIPT language=javascript src=\"../include/datecontrol/DateObject.js\"></SCRIPT>");
document.write("<SCRIPT language=javascript src=\"../include/datecontrol/DatePicker.js\"></SCRIPT>");
document.write("<SCRIPT language=javascript src=\"../include/datecontrol/editlib.js\"></SCRIPT>");