String.prototype.trim = function()
{
  return this.replace(/(^\s+)|(\s+$)/g,"");
}
function searchfrm(theForm)
  {
	var theType = theForm.searchtype.options[theForm.searchtype.selectedIndex].value;
	var theValue = theForm.input.value;
	var theInputItem = theForm.input;
	if(theValue.trim()=='')
	{
		alert("查询条件不能为空！");
		theForm.input.focus();
		theForm.input.select();
		return false;
	}
	if(theType=="membername")
		return IsUserName(theInputItem);
	else if(theType == "memberid")
		return IsShortNum(theInputItem);
	else if(theType =="shortnumber")
		return IsShortNum(theInputItem);
	return true;
  }

  function IsUserName(item)
  {
		if(judgeStr(item.value,userNameMaxLength/2,userNameMaxLength))
		{
			alert("输入的成员名称不得多于"+userNameMaxLength/2+"个汉字或"+userNameMaxLength+"个英文字母,请重新输入");
			item.focus();
			item.select();
			return false;
		}
		return true;
  }
  function IsMobileNum(item)
  {
		//检查手机号码前几位是否满足手机号码要求
		if ( ! item.value.match(regMobile) )
		{
			alert("输入的手机号码有误或不在本系统服务范围之内！");
			item.focus();
			item.select();
			return false;
		}
		return true;
  }
  function IsShortNum(item)
  { /*
		if( judgeStr(item.value , shortNumMaxLength/2,shortNumMaxLength) )
		{
			alert("输入的短号不得多于"+shortNumMaxLength/2+"个汉字或"+shortNumMaxLength+"个英文字母,请重新输入！");
			item.focus();
			item.select();
			return false;
		}*/
		for ( i=0; i<item.value.length; i++ )
        {
			if (item.value.charCodeAt(i) > 57 || item.value.charCodeAt(i) < 48)
			{
				alert("输入含有非法字符!");
				item.focus();
				item.select();
				return false;
			}
        }
		return true;
  }
//判断短消息内容长度
function judgeStr(AStr, len1, len2)
{
	var cFlag = false;
	var strLen;
	for ( i=0; i<AStr.length; i++ )
	{
		if (AStr.charCodeAt(i) > 256)
		{
			cFlag = true;
			break;
		}
	}
	if ( cFlag )
	{
		strLen = len1;
	}
	else
	{
		strLen = len2;
	}
	return AStr.length > strLen;
}
function exit()
{
	top.returnValue="";
	top.close();
}
function cclear()
{
	top.returnValue=String.fromCharCode(9);
	top.close();
}
function ok()
{
	var ret="";
	if(returnType==1)
		ret=ret1();
	else
		ret=ret2();
	var retParam=gotoPage.retParam.value;
	if(retParam==null||retParam==String.fromCharCode(9)) retParam="";
	if(ret==null||ret==String.fromCharCode(9)) ret="";
	//alert("="+retParam+"=");
	if(retParam!=""&&ret=="")
	{
		top.returnValue=retParam;
	}
	if(ret!=""&&retParam=="")
	{
		top.returnValue=ret;
	}
	if(ret!=""&&retParam!="")
	{
		top.returnValue=retParam+notSameFieldInterval+ret;
	}
	if(top.returnValue=="")
	{
		alert("没有选择...，请继续");
	}
	else
	{
		top.returnValue+="*del*"+gotoPage.delParam.value;
		top.close();
	}
}

//多选返回值情况1
function ret1()
{
 	var n=0;
	if(mulSelect)
		n=1;
	var cel=myForm1.all.tags("TR");
	var value="";
	var sArray=aabb.substring(0,aabb.length-1).split(",");
	if(cel[1].style.cursor=="hand")
	{
		for (var i=1; i<cel.length; i++)
		{
//			alert(cel[i].id);
			if(cel(i).getAttribute("className")=="OnSelected")
			{
				for(var k=0;k<sArray.length;k++)
				{
					 value+=cel(i).all.tags("TD").item(parseInt(sArray[k])+n).innerText+sameFieldInterval;
				}
				value=value.substring(0,value.length-1);
				value+=notSameFieldInterval;
			}
		}
		return value.substring(0,value.length-1);
	}
	else
	{
		return value;
	}
}


//多选返回值情况2：
function ret2()
{
 	var n=0;
	if(mulSelect)
		n=1;
	var cel=myForm1.all.tags("TR");
	var value="";
	var sArray=aabb.substring(0,aabb.length-1).split(",");
	if(cel[1].style.cursor=="hand")
	{
		for(var k=0;k<sArray.length;k++)
		{
			for (var i=1; i<cel.length; i++)
			{
				if(cel(i).getAttribute("className")=="OnSelected")
				{
					value+=cel(i).all.tags("TD").item(parseInt(sArray[k])+n).innerText+sameFieldInterval;
				}
			}
			value=value.substring(0,value.length-1);
			value+=notSameFieldInterval;
		}
		return value.substring(0,value.length-1);
	}
	else
	{
		return value;
	}
}

function select(id)
{
	var cel=myForm1.all.tags("TR");

	for (var i=0; i<cel.length; i++)
	{
		if(cel(i).getAttribute("className")=="OnSelected")
		{
			cel(i).setAttribute("className","UnSelected");
		}
	}
	id.setAttribute("className","OnSelected");
}

function MyClick(ckid,id)
{
	if(ckid.checked==true)
		ckid.checked=false;
	else
		ckid.checked=true;
	checkboxSelect(ckid,id)
}

function checkboxSelect(ckid,id)
{
	var strSub;

	strSub = id.all.tags("TD").item(1).innerText+sameFieldInterval;
	strSub +=id.all.tags("TD").item(2).innerText+sameFieldInterval;
	strSub +=id.all.tags("TD").item(4).innerText;

	if(ckid.checked){
		id.setAttribute("className","OnSelected");

		gotoPage.delParam.value=delString(strSub,gotoPage.delParam.value,1);
	}

	else
	{
		var sArray=aabb.substring(0,aabb.length-1).split(",");
		var n=0;
		if(mulSelect)
			n=1;
		var sub="";
		for(var k=0;k<sArray.length;k++)
		{
			sub+=id.all.tags("TD").item(k+n).innerText+sameFieldInterval;
		}
		sub=sub.substring(0,sub.length-1);
		id.setAttribute("className","UnSelected");

		gotoPage.delParam.value += strSub+String.fromCharCode(9);
		gotoPage.retParam.value=delString(sub,gotoPage.retParam.value,1);

	}

}

function search()
{
 	var n=0;
	if(mulSelect)
		n=1;
	var isFind=false;
	var currentLine;
	var query=document.all.QueryStr.value;
	var cel=myForm1.all.tags("TR");
	var myflag=false;
	var qArray=mmnn.substring(0,mmnn.length-1).split(",");
    if(cel[1].style.cursor=="hand")
	{
		for (var i=0; i<cel.length; i++)
		{

			if(cel(i).getAttribute("className")=="OnSelected")
			{
				cel(i).setAttribute("className","UnSelected");
			}
		}

		for(i=0;i<cel.length;i++)
		{
			for(var k=0;k<qArray.length;k++)
			{
				//	alert(qArray[k]);///////////////
				if((cel(i).all.tags("TD").item(parseInt(qArray[k])+n).innerText).indexOf(query)>=0)
					{
						myflag=true;
						break;
					}
			}
			if(myflag)
			{
				if(isFind==false)
				{
					if(n==0) cel(i).setAttribute("className","OnSelected");
					isFind=true;
					currentLine=i;
				}
				cel(i).style.display="block";
				myflag=false;
			}
			else
			{
				cel(i).style.display="none";
				cel(0).style.display="block";
			}

		}

		if(isFind==false)
		{
			top.returnValue="";
		}
		else
		{
		 	// cel(currentLine).scrollIntoView(true);
		}
	 if(query=="")
		{
			document.all.QueryStr.focus();
			cel(currentLine).setAttribute("className","UnSelected");
//			cel(currentLine+1).setAttribute("className","OnSelected");
		}
	}
}

 function setDefault()
 {
	var cel=myForm1.all.tags("TR");
	var value="";
	var aabb=gotoPage.retParam.value;
	var sArray=aabb.split(notSameFieldInterval);
	var ctrl;
	var checkCount=0;

	if(cel[1].style.cursor=="hand")
	{
		for(var k=0;k<sArray.length;k++)
		{
			var tempArray=sArray[k].split(",");
			//alert("="+aabb+"=");
			for (var i=1; i<cel.length; i++)
			{
				if((cel(i).all.tags("TD").item(parseInt(1)).innerText==tempArray[0])&&tempArray[0]!="")
				{
					ctrl=eval("document.all.cktr"+(i-1));
					ctrl.checked=true;
					checkCount++;
					//alert(cel(i).all.tags("TD").item(parseInt(1)).innerText);
					//alert(cel(i).tagName);
					cel(i).setAttribute("className","OnSelected");
					gotoPage.retParam.value=delString(sArray[k],gotoPage.retParam.value,1);
					break;
				}
					/*
				alert(cel(i).id);
				alert(cel(i).all.tags("TD").item(parseInt(1)).innerText);
				alert(tempArray[0]);*/
			}
		}
		if(checkCount==(cel.length-1)){
			ck000.click();
		}
	}
}

function delString(delstr,src,n)
{
	var index=src.indexOf(delstr,0);
	if(index>=0)
	{
		if(src.length>delstr.length)
		{
			if(index==0)
			{
				src=src.substring(index+delstr.length+parseInt(n));//first
			}
			else if(src.length==index+delstr.length)
			{
				src=src.substring(0,index-parseInt(n));//last
			}
			else
			{
				src=src.substring(0,index-parseInt(n))+src.substring(index+delstr.length);//middle
			}
		}else
			src="";
			//src=src.substring(0,index)+src.substring(index+delstr.length);//equal
	}
	return src;
}
    function submitPage(value,localPage) {
		var retParam=gotoPage.retParam.value;
		var ret="";
		if(returnType==1)
			ret=ret1();
		else
			ret=ret2();
		if(retParam==null||retParam==String.fromCharCode(9)) retParam="";
		if(ret==null||ret==String.fromCharCode(9)) ret="";
		if(retParam!=""&&ret=="")
		{
			gotoPage.retParam.value=retParam;
		}
		if(ret!=""&&retParam=="")
		{
			gotoPage.retParam.value=ret;
		}
		if(ret!=""&&retParam!="")
		{
			gotoPage.retParam.value=retParam+notSameFieldInterval+ret;
		}
		gotoPage.pageNo.value=value;
        gotoPage.action=localPage;
		gotoPage.submit();
    }

   function submitBack()
    {
      self.location.href="/websms/corp/group/pop/popSelMember.jsp";
    }
	/**
     * 在字符串中用一指定的字符串替换查找到的所有子串
     * @param originalString 原字符串
	 * @param findText       查找的字符串
	 * @param replaceText    替换的字符串
     */
    function stringReplace(originalString, findText, replaceText) {
      var pos = 0;
      var len = findText.length;
      pos = originalString.indexOf(findText);
      while (pos != -1) {
        preString = originalString.substring(0, pos);
        postString = originalString.substring(pos + len,
          originalString.length);
        originalString = preString + replaceText + postString;
        pos = originalString.indexOf(findText);
      }
      return originalString;
    }

	/*
	 * 打开弹出选择框（用于添加/编辑 个人群组、集团群组和短号群组的选择集团成员）
	 × @param setControls 存放返回值的网页控件
	 * @param theJSP      弹出页面的URL
	 * @param width       弹出页面的宽度
	 * @param height      弹出页面的高度
	 */
	function selectListQ(setControls,theJSP,width,height){
		var sArray,vArray;
		var retValue,text,value;
		var retParam="";
		var ctrl=eval("document."+setControls);
//new
		var retValueAll,retValueDel;//String
		var allArray,delArray,delValueArray;//array
//end
		for (var n= 0;n < ctrl.length;n++) {
			retParam += ctrl.options[n].value+","+stringReplace(ctrl.options[n].text,"/",",")+"^";
		}
		if(retParam.length>1){
		frmGroupEdit.saveRet.value=retParam.substring(0,retParam.length-1);
		}else{
		frmGroupEdit.saveRet.value="";
		}
                frmGroupEdit.action="/websms/corp/public/saveRetParam.jsp";
                frmGroupEdit.target="saveRetFrame";
                frmGroupEdit.submit();
		retValueAll=window.showModalDialog(theJSP,"haha","help:0;resizable:0;status=0;scrollbars=0;dialogWidth="+width+";dialogHeight="+height+";center=true");
	    if(retValueAll==null)
			retValueAll='';
//new
		if((retValueAll==null)||(retValueAll=="")){
			retValueAll="*del*";
		}
		allArray = retValueAll.split("*del*");

		retValue = allArray[0];
		retValueDel = allArray[1];

//		alert(retValueDel);
//end


		if(retValue!=""&&retValue!=String.fromCharCode(9)) {
			//开始赋新值
			sArray=retValue.split(String.fromCharCode(9));

			var exitCheck;
			for(var i=0;i<sArray.length;i++)
			{
				vArray=sArray[i].split(",");
				value=vArray[0];
				exitCheck = 1;

				for(var j=0;j<ctrl.length;j++){
					if(value==ctrl.options[j].value){
						exitCheck=0;
						continue;
					}
				}
				if(exitCheck==1){
					if(vArray[1]=="")
						text=vArray[0]+"/"+vArray[2];
					else
						text=vArray[1]+"/"+vArray[2];
					var newOption = new Option(text, value, false, false);
					ctrl.add(newOption);
				}
			}
		}
//new
		if(retValueDel!=""&&retValueDel!=String.fromCharCode(9)) {

			delArray=retValueDel.split(String.fromCharCode(9));
//									alert(delArray[0]);

			for(i=0;i<delArray.length;i++){
				delValueArray = delArray[i].split(",");
//									alert(delValueArray[0]+"=="+ctrl.options[j].value);
				for( j=0;j<ctrl.length;j++){
//									alert(delValueArray[0]+"=="+ctrl.options[j].value);

					if(delValueArray[0]==ctrl.options[j].value){
//这里删除


						ctrl.options[j].value="";
						ctrl.options[j].text="";
						BumpUp(ctrl);
					}
				}

			}

		}
//end
		return retValue;
	}


	function BumpUp(ctrl) {
	  for(var i = 0; i < ctrl.options.length; i++) {
		  if(ctrl.options[i].value == "")  {
			  for(var j = i; j < ctrl.options.length - 1; j++)  {
				  ctrl.options[j].value = ctrl.options[j + 1].value;
				  ctrl.options[j].text = ctrl.options[j + 1].text;
			  }
			  var ln = i;
			  break;
		  }
	  }
	  if(ln < ctrl.options.length)  {
		  ctrl.options.length -= 1;
		  BumpUp(ctrl);
	  }
	}

	function remove(ctrl) {
		for(var i=0; i<ctrl.options.length; i++) {
			if(ctrl.options[i].selected && ctrl.options[i] != "") {
				ctrl.options[i].value = "";
				ctrl.options[i].text = "";
			}
		}
		BumpUp(ctrl);
	}

	/*
	 * 打开弹出选择框（用于发送短信页面的选择个人群组和集团群组）
	 × @param setControls 存放返回值的网页控件
	 * @param theJSP      弹出页面的URL
	 * @param width       弹出页面的宽度
	 * @param height      弹出页面的高度
	 */
	function selectListG(setControls,theJSP,width,height){
		var sArray,vArray;
		var retValue,text,value,retValueAll;
		var retParam="";var value,text,flag;
		var ctrl=eval("document."+setControls);
		retValueAll=window.showModalDialog(theJSP,"","help:0;resizable:0;status=0;scrollbars=0;dialogWidth="+width+";dialogHeight="+height+";center=true");
	//	alert('123456'+retValueAll);
	    if(retValueAll==null)
			retValueAll='';
		flag=theJSP.substring(theJSP.length-1,theJSP.length);

		retValue = (retValueAll.split("*del*"))[0];

		if(flag==1) //个人群组
			flag=2;
		else //集团群组
			flag=1;
		if(retValue!=""&&retValue!=String.fromCharCode(9)) {
			//开始赋新值
			sArray=retValue.split(String.fromCharCode(9));
			for(var i=0;i<sArray.length;i++)
			{

				vArray=sArray[i].split(",");
                if(vArray[0]==null || vArray[0]=="null")continue;
               // alert(vArray[0]);
               // alert(vArray[1]);
                //alert(vArray[2]);
                if(vArray[0].length==11){
                  if(vArray[1]==""||vArray[1]=="null")
					text=vArray[0]+"/"+vArray[2];
				  else
					text=vArray[1]+"/"+vArray[2];
				    value="7"+"\4"+vArray[2];
                }else{
				  value=flag+"\4"+vArray[0];
				  text=vArray[1];
               }
			//	alert(value);
				if(mayAdd(ctrl,value))
				{
					var newOption = new Option(text, value, false, false);
					ctrl.add(newOption);
				}
			}
		}
		return retValue;
	}

	/*
	 * 打开弹出选择框（用于个人版本的选择联系人）
	 × @param setControls 存放返回值的网页控件
	 * @param theJSP      弹出页面的URL
	 * @param width       弹出页面的宽度
	 * @param height      弹出页面的高度
	 */
	function selectListLinkMan(setControls,theJSP,width,height){
		var sArray,vArray,allArray;
		var retValue,text,value,retValueAll;
		var retParam="";var value,text,flag;
		var ctrl=eval("document."+setControls);
		for (var n= 0;n < ctrl.length;n++) {
			retParam += ctrl.options[n].value+","+stringReplace(ctrl.options[n].text,"/",",")+"^";
		}
		theJSP+="&retParam="+retParam.substring(0,retParam.length-1);
		retValueAll=window.showModalDialog(theJSP,"","help:0;resizable:0;status=0;scrollbars=0;dialogWidth="+width+";dialogHeight="+height+";center=true");
		//alert(retValue);
	    if(retValueAll==null)
			retValueAll='';
		allArray = retValueAll.split("*del*");
		retValue = allArray[0];

		if(retValue!=""&&retValue!=String.fromCharCode(9)) {
			//alert(retValue);
			//删除原来的select值
			for (var n= 0;n < ctrl.length;n++)
			{
				ctrl.options[n].value="";
				ctrl.options[n].text="";
			}
			BumpUp(ctrl);
			//开始赋新值
			sArray=retValue.split(String.fromCharCode(9));
			for(var i=0;i<sArray.length;i++)
			{
				vArray=sArray[i].split(",");
				value=vArray[0];
				text=vArray[1];
			//	alert(value);
				if(mayAdd(ctrl,value))
				{
					var newOption = new Option(text, value, false, false);
					ctrl.add(newOption);
				}
			}
		}
		return retValue;
	}
	/*
	 * 打开弹出选择框（用于发送短信页面的选择集团成员）
	 × @param setControls 存放返回值的网页控件
	 * @param theJSP      弹出页面的URL
	 * @param width       弹出页面的宽度
	 * @param height      弹出页面的高度
	 */
    function selectListM(setControls,theJSP,width,height){
		var sArray,vArray;
		var retValue,text,value,retValueAll;
		var ctrl=eval("document."+setControls);
		retValueAll=window.showModalDialog(theJSP+="?retParam=","","help:0;resizable:0;status=0;scrollbars=0;dialogWidth="+width+";dialogHeight="+height+";center=true");
	    if(retValueAll==null)
			retValueAll='';
		retValue =(retValueAll.split("*del*"))[0];

		if(retValue!=""&&retValue!=String.fromCharCode(9)) {
			//开始赋新值
			sArray=retValue.split(String.fromCharCode(9));
			for(var i=1;i<sArray.length;i++)
			{
				vArray=sArray[i].split(",");
				value=vArray[2];
				if(vArray[1]==""||vArray[1]=="null")
					text=vArray[0]+"/"+vArray[2];
				else
					text=vArray[1]+"/"+vArray[2];
				value="7"+"\4"+value;
				if(mayAdd(ctrl,value)){
					var newOption = new Option(text, value, false, false);
					ctrl.add(newOption);
				}
			}
		}
		return retValue;
	}

    //add by zhangjinshu 2004.11.17
    function selectMsg(id)
    {
        var cel=myForm1.all.tags("TR");

      	for (var i=0; i<cel.length; i++)
	    {
            if (i == id){
                cel(i).setAttribute("className","OnSelected");
            }else{
	    		cel(i).setAttribute("className","UnSelected");
            }
	    }
    }

    /**
     * 打开选择预置短消息对话框
     * @param setControls 存放返回值的网页控件
	 * @param theJSP      弹出页面的URL
	 * @param width       弹出页面的宽度
	 * @param height      弹出页面的高度
     * @return
     */
    function selectPresetMsg(setControls,theJSP,width,height){
		var retValue;
		var ctrl=eval("document."+setControls);
        var orginValue = ctrl.value;

		retValue=window.showModalDialog(theJSP,"","help:0;resizable:0;status=0;scrollbars=0;dialogWidth="+width+";dialogHeight="+height+";center=true");

	    if(retValue==null)
			retValue='';

        if (orginValue == ''){
           ctrl.value = retValue;
        }else if(retValue != ''){
           retValue = orginValue + "  " + retValue;
           ctrl.value = retValue;
        }

		return retValue;
	}

    /**
     * 关闭选择预置短消息对话框
     */
        function SubmitPresetMsg()
    {
        var n=0;
  	    var cel=myForm1.all.tags("TR");
        var input = myForm1.all.tags("input");
    	var value="";

	    for (var i=0; i<cel.length; i++)
        {
	  	    if(cel(i).getAttribute("className")=="OnSelected")
		    {
                value += input(i*2+1).value;
		        break;
	         }
	     }

         if ((cel.length != 0)&&(i == cel.length))
         {
               value = input(1).value;
         }
         top.returnValue=value;
         top.close();
     }
//end of add by zhangjinshu

	/*
	 * 判断ctrl控件列表内是否已经存在value值
	 * @param ctrl       控件名称
	 * @param value      判断的value值
	 */
	function mayAdd(ctrl,value){
		for (var n= 0;n < ctrl.length;n++)
		{
			if(value==ctrl.options[n].value)
			{
				return false;
			}
		}
		return true;
	}

function existCheck(flag,nullCheck)
{
	top.returnValue='';
	window.returnValue='';
	if(flag=='notlog')
	{
		alert("您没有登录或者登录超时！");
		top.close();
	}
	else if(flag=='group')
	{
		if(nullCheck==null||nullCheck==0)
		{
			alert("对不起，该群组还没有一个成员，请先为该群组增加成员");
			top.close();
		}
	}
	else if(flag=='member')
	{
		if(nullCheck==null||nullCheck==0)
		{
			alert("对不起，该集团还没有一个成员，请先为该集团增加成员");
			top.close();
		}
	}
	else if(flag=='linkMan')
	{
		if(nullCheck==null||nullCheck==0)
		{
			alert("对不起，您没有联系人信息，请先增加联系人");
			top.close();
		}
	}
}
function allChange(){
	var cel=myForm1.all.tags("TR");
	if(ck000.checked==true){
		for (var i=1; i<cel.length; i++)
		{
			if(!eval("chk"+(i-1)).checked)
				cel[i].click();
		}
	}else{
		for (var i=1; i<cel.length; i++)
		{
			if(eval("chk"+(i-1)).checked)
				cel[i].click();
		}

	}

}


