﻿//给字符型对象添加trim方法
String.prototype.trim=function()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}
//检查是否为数字
function isdig(s)
{
	var re = /^(-|\+)?\d+(\.\d+)?$/;
	return re.test(s);
}
//检查日期格式
function chkDate(datestr)
{
	var datetime_arr,date_arr,time_arr,year,mon,day;
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	datetime_arr=datestr.split(" ")
	
	//检查日期
	date_arr=datetime_arr[0].split("-");
	if (date_arr.length!=3) return false;
	year=date_arr[0];
	mon=date_arr[1];
	day=date_arr[2];		
	if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1]=29;
	if(!isdig(year) || !isdig(mon) || !isdig(day) || mon<1 || mon>12 || day>monthDays[mon-1]) return false;
	   
	//检查时间
	if(datetime_arr.length>1)
	{
		time_arr=datetime_arr[1].split(":");
		hour=time_arr[0];
		min=time_arr[1];
		sec=time_arr[2];
		if (!isdig(hour) || !isdig(min) || !isdig(sec) || hour<0 || hour>23 || min<0 || min>59 || sec<0 || sec>59) return false;
	}
	return true;
}
//检查Email格式
function chkEmail(strEmail)
{
	var re;
	re = new RegExp("(^([_.0-9a-z-])+)@{1}(([0-9a-z][0-9a-z-]+.)+)([a-z]{2,3}$)","i");

	return re.test(strEmail);
}	
//检查非法字符
function chkValidChar(str)
{
	var re;
	re = new RegExp("[\"&'“”,，]","ig");
	
	return re.test(str);
}
//检查表单输入
function chkForm(obj,strDesc,nMode)
{
	switch(nMode)
	{
		case 1://不得为空
		{
			var strTemp=obj.value
			if (strTemp.trim()=="")
			{
				alert(strDesc);
				obj.select();
				return false;
			}
			else
			{
				return true;
			}
			break;
		}
		case 2://检测数字
		{
			var strTemp=obj.value
			if (!isdig(strTemp))
			{
				alert(strDesc);
				obj.select();
				return false;
			}
			else
			{
				return true;
			}
			break;
		}
		case 3://检测日期
		{
			var strTemp=obj.value;
			if (strTemp=="") return true;
			if (!chkDate(strTemp))
			{
				alert(strDesc);
				obj.select();
				return false;
			}
			else
			{
				return true;
			}
			break;
		}
		default:
		{
			return true;
			break;
		}
	}
}
//设置Cookie的值	
function setCookie(name,value)
{
  expiryday=new Date();
  expiryday.setTime(expiryday.getTime()+3*30*24*60*60*1*1000);
  document.cookie=name+"="+escape(value)+";expires="+expiryday.toGMTString();
}
//取出Cookie的值
function getCookie(name)
{
  var search=name+"=";
  if(document.cookie.length>0)
  {
    offset=document.cookie.indexOf(search);
    if(offset!=-1)
    {
      offset+=search.length;
      end=document.cookie.indexOf(";",offset);
      if (end==-1) end=document.cookie.length;
      return unescape(document.cookie.substring(offset,end))
    }
  }
  return "";
}
function overMe(obj)						  //当鼠标移动到按钮上时
{
	obj.className="clsMainInputButtonLight";  //设置按钮风格为高亮
}
function outMe(obj)							  //当鼠标移开按钮上时
{
	obj.className="clsMainInputButton";       //设置按钮风格为普通
}
function overTR(obj)						  //当鼠标移动到按钮上时
{
	if(obj.className!="clsMainTRSelected")
	{
		obj.className="clsMainTRLight";  //设置按钮风格为高亮
	}
}
function outTR(obj)							  //当鼠标移开按钮上时
{
	if(obj.className!="clsMainTRSelected")
	{
		obj.className="clsMainTR";       //设置按钮风格为普通
	}
}
//选择日期
function selectDate(objText)
{
	nLeft=event.screenX+10;
	nTop=event.screenY+10;
	strArg=objText.value
	strReturn=window.showModalDialog("../include/selectDate.aspx",strArg, "dialogLeft:" + nLeft + ";dialogTop:" + nTop + ";dialogWidth:175px;dialogHeight:200px;status:0;scroll:0;help:0");
	if(strReturn!=null)
	{
		objText.value=strReturn;
	}
}
//选择颜色
function selectSimpleColor()
{
  nLeft=event.screenX+10;
  nTop=event.screenY+10;
  var strReturn = showModalDialog("../include/selcolor.html", "", "dialogTop:" + nTop + ";dialogLeft:" + nLeft + ";dialogWidth:260px; dialogHeight:230px; status:0;scroll:0");
  return strReturn
}
//写时间
function writeTime(strType,strObjName,nValue)
{
	document.write("<select name='" + strObjName + "' class='clsMainInputSelect' style='width:40px'>");
	if(strType=="hour")//如果是小时
	{
		for(i=0;i<=23;i++)	
		{
			if(i==nValue)
			{
				document.write("<option value='" + i + "' selected>" + (i<10?("0"+i):i) + "</option>");
			}
			else
			{
				document.write("<option value='" + i + "'>" + (i<10?("0"+i):i) + "</option>");
			}
		}
	}
	else
	{
		for(i=0;i<=59;i++)	
		{
			if(i==nValue)
			{
				document.write("<option value='" + i + "' selected>" + (i<10?("0"+i):i) + "</option>");
			}
			else
			{
				document.write("<option value='" + i + "'>" + (i<10?("0"+i):i) + "</option>");
			}
		}
	}
	document.write("</select>");
}
//从文件地址中取得文件名，不包括扩展名
function getFileName(strFullPath)
{
	var arrTemp = strFullPath.split("\\");
	var strFileName = arrTemp[arrTemp.length-1];
	var n = strFileName.lastIndexOf(".");
	if(n!=-1)
	{
		strFileName = strFileName.substr(0,n);
	}
	return strFileName;
}
//从文件地址中取得文件扩展名
function getFileExt(strFullPath)
{
	var strFileExt = "";
	var n = strFullPath.lastIndexOf(".");
	if(n!=-1)
	{
		strFileExt = strFullPath.substr(n+1);
	}
	return strFileExt;
}
//获取当前操作
function writeCurMenu()
{
	var strTemp;
	strTemp = top.frames["frmLeft"].getCurMenu();
	document.write(strTemp);
}
//检查数字
function checkNum(d)
{
	if (d>=48&&d<=57)
	{
		return true;
	}
	if (d==45||d==46)
	{
		return true;
	}
	return false;
}
//检查整数
function checkInt(d)
{
	if (d>=48&&d<=57)
	{
		return true;
	}
	return false;
}
//显示层
function showDiv(divID)
{
	$(divID).style.display = "block";
	if(event.x>$(divID).offsetWidth)
	{
		$(divID).style.left = event.x -$(divID).offsetWidth - 10;
		$(divID).style.top = event.y - $(divID).offsetHeight - 10;
	}
	else
	{
		$(divID).style.left = event.x + 10;
		$(divID).style.top = event.y + 10;
	}
	try
	{
		$("ifrDivBg").style.width = $(divID).offsetWidth;
		$("ifrDivBg").style.height = $(divID).offsetHeight;
		$("ifrDivBg").style.top = $(divID).style.top;
		$("ifrDivBg").style.left = $(divID).style.left;
		$("ifrDivBg").style.zIndex = $(divID).style.zIndex - 1;
		$("ifrDivBg").style.display = "block";
	}
	catch(e)
	{
		return;
	}
}
//隐藏层
function hideDiv(divID)
{
	$(divID).style.display = "none";
	try
	{
		$("ifrDivBg").style.display = "none";
	}
	catch(e)
	{
		return;
	}
}


     //全选
		function selectAll(regionName)
		{
		    var chk=$$('#'+regionName+' input');
			for(var i=0 ;i<chk.length-1;i++)
			{
				if(chk[i].type=='checkbox')
				{
				    chk[i].checked=true;
			    }
			}
		}
		//反选
		function differentAll(regionName)
		{
			var chk=$$('#'+regionName+' input');
			for(var i=0 ;i<chk.length-1;i++)
			{
				if(chk[i].type=='checkbox')
				{
				    chk[i].checked=!chk[i].checked;
			    }
			}
		}
//修改
		function updateDo(regionName,checkName,fieldAry)
		{
			var bOK;
			bOK = false;
			var chk=$$('#'+regionName+' input');
			for(var i=0 ;i<chk.length-1;i++)
			{
				if(chk[i].type=='checkbox')
				{
				
				    if (chk[i].checked){
				        var suffix = chk[i].id.substr(0,chk[i].id.length-checkName.length+2);//chkID
				        for (fieldName in fieldAry){
				            if (typeof(fieldAry[fieldName])=="string"){
						        //if(!chkForm(document.getElementById(suffix + fieldName),fieldAry[fieldName],1)) return false;
						    }
				        }
						bOK = true;
					}
			    }
			}
			if (bOK)
			{
				document.getElementById("txtOperation").value="update";
			}
			else
			{
				window.alert ("请先选择您要修改的记录！！");
			}
			
			return bOK;
		}

		//删除
		function deleteDo(regionName)
		{
		
		    var bOK;
			bOK = false;
			var chk=$$('#'+regionName+' input');
			for(var i=0 ;i<chk.length-1;i++)
			{
				if(chk[i].type=='checkbox')
				{
				    if (chk[i].checked){
						bOK = true;
						break;
					}
			    }
			}
			if (bOK)
			{
			    if (confirm("将要删除选中的记录\n您确定吗？"))
				{
				    document.getElementById("txtOperation").value="delete";
				}else{
				    bOK = false;
				}
			}
			else
			{
				window.alert ("请先选择您要删除的记录！！");
			}
			
			return bOK;
		}


