
/***************************************************************************************
 * 主要有显示客户端事件，select的操作，check的操作，打开新窗口，截取给定html中td或div中的字符串 等功能。
 ***************************************************************************************
 */

/*
 * function 去除字符串两端空格 
 */
String.prototype.trim=function(){
				return this.replace(/(^\s*)|(\s*$)/g, "");
}
/*
 * function 检验表单
 */
function checkForm(form)
{

if(Validator.Validate(form,3)){
	return true;
}
else {
	return false;
}
}
/*
 * 多项删除
 */
function deleteMunt(fieldName,src){
		var ID = document.getElementsByName(fieldName);
		var id=0;
		var num = 0;
		if(!ID){
			return false;
		}
		for(var i=0;i<ID.length;i++) {
		
			if(ID[i].checked==true){
			id=ID[i].value;
			num++;
			}
		}
		if(num <1){
			alert("该操作至少需要选择一条记录");
		}else {
		if(confirm("确定删除所选定的记录？")){
			form1.action=src;
			form1.submit();
		}
		}
}
 /*
  * 功能按钮删除
  */
function deleteFunc(src){
		
		 
		if(confirm("确定删除所选定的记录？")){
			window.location=src;
		}
}
/*
 * 修改
 */
function update(fieldName,src){
		var ID = document.getElementsByName(fieldName);
		var id=0;
		var num = 0;
		if(!ID){
			return false;
		}
		for(var i=0;i<ID.length;i++) {
		
			if(ID[i].checked==true){
			id=ID[i].value;
			num++;
			}
		}
		if(num>1 || num <1){
			alert("该操作只能选择一条记录");
		}else window.location=src+"&id="+id;
}

/*
 * function 返回上一页
 */
function goBack()
{
 javascript:history.back(-1);
}
/*
 * function 选择全部
 */
function selectAll(obj,flag) {
	if(!obj) {
		return false;	
	}
	if(!obj.length) {
		obj.checked=flag;
		//return true;
	}
	for(var i=0;i<obj.length;i++) {
		obj[i].checked=flag;
	}

	return true;	
} 
/*
 * function 客户端显示时间 
 */
function refreshCalendarClock(){
	var now = new Date();
	var yy = now.getYear();
	var mou = now.getMonth();
	var dd = now.getDate();
	var hh = now.getHours();
	var mm = now.getMinutes()+1;
	var ss = now.getTime() % 60000;
	ss = (ss - (ss % 1000)) / 1000;
	var clock = hh+':';
	if (mm < 10)clock += '0';
		clock += mm+':';
	if (ss < 10)clock += '0';
		clock += ss;
	var timeStr = yy + "-"+mou+ "-"+dd + " "+clock;
	setTimeout('refreshCalendarClock()',1000);
	document.getElementById("TimeSPAN").innerHTML = "服务器时间："+timeStr;
	 
}
 
	
/*
 * function 打开一个新窗口选择值
 * param url 所要打开的窗口url
 * param hiddenId 隐藏的输入框ID
 * param showName 显示的输入框ID
 * param defaultValue 查询中的默认查询条件（默认显示范围）
 */
 function choseInnewWindow(url,hiddenId,showName,defaultValue){
	var ids =  document.getElementByIdF(hiddenId);
	var names = document.getElementByIdF(showName);
	var sPath=url+"&ids="+ids+"&names="+names+"&defaultValue="+defaultValue;
	var retValue="";
	var strFeatures = "dialogWidth=600px;dialogHeight=500px;toolbar=no;location=no;directories=no;status=no;menubar=no;scrollbars=yes;scroll=yes;resizable=no;";
    var retvalue = window.showModalDialog(sPath,"",strFeatures);
    if( retvalue != null && retvalue != "")
	{
	 	 ids=getValue(retvalue,"ids");
		 names=getValue(retvalue,"names");
	     ids = ids.substring(0,ids.length-1);
	     names = names.substring(0,names.length-1);
	     if(ids != "|" || ids.length >1){
	     document.getElementByIdF(hiddenId)  = ids;
	     document.getElementByIdF(showName) = names;
	     }else{
	     document.getElementByIdF(hiddenId) = "";
	     document.getElementByIdF(showName) = "";
	   		}
	}
 }
/*
 * function 解析弹出窗口传回来的字符串
 * param str 传回来的值
 * param name 需要解析的字段名
 */
function getValue(str,name){
	var n=name+"=";
	var tmp=str+"|";
	var rtval=tmp.substring(tmp.indexOf(n)+n.length,tmp.indexOf("|",tmp.indexOf(n)));
	return rtval;
}
/*
 * function 选中指定对象元素
 * param obj 指定对象元素集合
 * param flag 是否选择标志
 */
function selectAll(obj,flag) {
	if(!obj) {
		return false;	
	}
	if(!obj.length) {
		obj.checked=flag;
		//return true;
	}
	for(var i=0;i<obj.length;i++) {
		obj[i].checked=flag;
	}

	return true;	
}
/*
 * function 从列表框中移除选中的项目
 * param selectObjName:列表框的对象名称
 */
function removeOneFromSelect(selectObjName)
{
	

 var fromList = document.getElementById(selectObjName);

  var sel = false;

  if(fromList.options&&fromList.options.length)
  {
  for (var i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {      sel = true;
 	  fromList.options[i] = null;
      i--;

    }
  }
  }
  if (!sel) alert ('您没有选择任何对象!');
}

/*
 * function 从列表框中移除选中的项目
 * param name 列表框的对象名称
 */
function removeFromSelect(name){
	var theSel = document.getElementById(name);
	var len = theSel.length;
	for(i=0;i<len;i++){		
		for(j=0 ; j<theSel.length ; j++){
			if(theSel.options[j].selected == true){
				theSel.options[j] = null;
			}				
		}
	}
}
/*
 * function 从列表框中移除所有的项目
 * param selectObjName:列表框的对象名称
 */
function removeAllFromSelect(selectObjName)
{
	 var fromList =document.getElementById(selectObjName);

  if(fromList.options&&fromList.options.length)
  {
  for (var i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];

 	  fromList.options[i] = null;
      i--;

  }
  }

}
/*
 * function 选择列表框中的所有选项
 * param  name 列表框控件名称
 */
function selectAllOptions(name){
	var sel = document.getElementById(name);
	for(i=0;i<sel.options.length;i++){
		sel.options[i].selected = "selected";
	}
}
/*
 * function 根据select option的值 设置select相应的默认选择项
 *          比如 select 里有 男、女两项 值分别为0，1 要选择女，只需要传入 1，女就会被选中
 * param id 为select 的id 
 * param value 为指定的值
 */
function setSelectValueByValue(id,value)
{
	var sel = document.getElementById(id);
	if(sel==undefined)
		return false;
	for(var i=0;i<sel.options.length;i++)
	{
		if(sel.options[i].value==value)
		{
			sel.options[i].selected=true;
			break;
		}
	}
	return true;
}

/*
 * function 根据select option的值 设置select相应的默认选择项
 *          比如 select 里有 男、女两项 值分别为0，1 要选择女，只需要传入 1，女就会被选中
 * param obj 为select 对象 
 * param value 为指定的值
 */
function setSelectObjValueByValue(obj,value)
{
	var sel = obj;
	if(sel==undefined)
		return false;
	for(var i=0;i<sel.options.length;i++)
	{
		if(sel.options[i].value==value)
		{
			sel.options[i].selected=true;
			break;
		}
	}
	return true;
}
 
/*
 * function 根据select显示的值 设置select相应的默认选择项
 *          比如 select 里有 男、女两项 值分别为0，1 要选择女，只需要传入 女，就会被选中
 * param id为select 的id 
 * param value 为指定的值
 */
function setSelectValueByText(id,value)
{ 
	var sel = document.getElementById(id);
	if(sel==undefined)
		return false;
	for(var i=0;i<sel.options.length;i++)
	{
		if(sel.options[i].text==value)
		{
			sel.options[i].selected=true;
			break;
		}
	}
	return true;
}

/*
 * function 根据 td 或者 div 的 id ，截取字符串
 * param  divId  
 * param  length
 */
function cutStrById(divId,length)//根据 td 或者 div 的 id ，截取字符串
{
	var div = document.getElementsByName(divId);
	if(div==null)
	{
		return false;
	}
	for(var i=0;i<div.length;i++)
	{
		div[i].innerHTML = trancuate(div[i].innerHTML,length);
	}
}
/*
 * function 截取字符串
 * param str  待截取的字符串
 * param length  长度
 */
function trancuate(str,length){
	var strLen=parseInt(str.length);
	var leng=parseInt(length);
	if(strLen<=leng){
		return str;
	}
	str=str.substring(0,length-3);
	return str+"...";

}
/*
 * function 在一个字符串中减掉一子串（以,分割）
 * param strold  老的字符串
 * param strrep  去掉的字符串
 */
 function subString(strold,strrep){
 	var strArr = strold.split(",");
 	var str = "" ; 
		for(i = 0; i < strArr.length; i++) 
		{ 
		if(strrep!=strArr[i]) str += strArr[i] + ",";
		}
 		return str 
 }
 
 /*
 * function 去除字符串中重复的子串（以,分割）
 * param str  字符串 
 */
 function filterMoreString(str){
		var strArr = str.split(",");
		str = ",";
		for(i = 0; i < strArr.length; i++) 
		{ 
		if(str.indexOf("," + strArr[i] + ",") == -1)str += strArr[i] + ",";
		} 
		return str.substring(1,str.length-1); 
}
/*
 * checkbox选中
 */
function setCheckboxValue(id,str){
			var obj = document.getElementsByName(id);
			if(str.length <1)return ;
			if(obj == undefined)return;
	 		for(var i=0;i<obj.length;i++)
			{   
				if(str.indexOf(","+obj[i].value+",") >-1 )  obj[i].checked = true; 
			 }  
			 }
 /*
 * function 将鼠标焦点固定在某一输入框上
 * param id  输入框ID
 */

function getFocus(id){
		var obj = document.getElementById(id);
		obj.focus();
		var rng = obj.createTextRange();
		rng.collapse(false);
		rng.select();
}
/*
 * 设置cookie
 */
function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
	{
	var Days = 30; //此 cookie 将被保存 30 天
	var exp   = new Date(); //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
	}
/*
 * 获取cookie
 */
function getCookie(name)//取cookies函数       
	{
		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	    if(arr != null) return unescape(arr[2]); return null;
	
	}
/*
 * 删除cookie
 */
function delCookie(name)//删除cookie
	{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
	}

/*
 * 提交
 */
function doSubmit(form){ 
   form.submit();
}