﻿function addloc(locs,mylocs){    //locs=left;mylocs=right
  	if(mylocs.length<1){
	  for(var x=0;x<locs.length;x++){
		var opt1 = locs.options[x];
		if (opt1.selected){
		  mylocs.options[mylocs.options.length] = new Option(opt1.text, opt1.value, 0, 0);
		}
	  } 
	   
	  for(var y=locs.length-1;y>=0;y--){
		var opt2 = locs.options[y];
		if (opt2.selected){
		  locs.options[y] = null;
		}
	  }
	 }
	else{
	alert('对不起，每次只能选择一个发送对象!');
	} 
}

function addalloc(locs,mylocs){
  for(var x=0;x<locs.length;x++){
    var opt1 = locs.options[x];
    //if (opt1.selected){
      mylocs.options[mylocs.options.length] = new Option(opt1.text, opt1.value, 0, 0);
    //}
  } 
  
   
  for(var y=locs.length-1;y>=0;y--){
    var opt2 = locs.options[y];
    //if (opt2.selected){
      locs.options[y] = null;
    //}
  }
}

function delloc(locs,mylocs){
  for(var x=0;x<mylocs.length;x++){
    var opt1 = mylocs.options[x];
    if (opt1.selected){
      locs.options[locs.options.length] = new Option(opt1.text, opt1.value, 0, 0);
    }
  } 
  
   
  for(var y=mylocs.length-1;y>=0;y--){
    var opt2 = mylocs.options[y];
    if (opt2.selected){
      mylocs.options[y] = null;
    }
  }
}

function delalloc(locs,mylocs){
  for(var x=0;x<mylocs.length;x++){
    var opt1 = mylocs.options[x];
    //if (opt1.selected){
      locs.options[locs.options.length] = new Option(opt1.text, opt1.value, 0, 0);
    //}
  } 
  
   
  for(var y=mylocs.length-1;y>=0;y--){
    var opt2 = mylocs.options[y];
    //if (opt2.selected){
      mylocs.options[y] = null;
    //}
  }
}

	function textCounter(field, countfield,countfield2, maxlimit) {
		if (field.value.length > maxlimit) 
			field.value = field.value.substring(0,maxlimit);
		else 
			countfield.value = maxlimit - field.value.length;
			countfield2.value = field.value.length;
			document.getElementById("ylcontext").innerHTML = field.value;		
	}

		//检查 - 用户输入
		function CheckUserInput()
		{
			var MsgContent=document.form1.memo;
			var SendName=document.form1.sendname;
			var SendMobile=document.form1.faminfo;
			var ReciveList=document.form1.rcvlist;
			var Identity=document.form1.radiobutton1;
			var Validity=document.form1.Confirm;

			
			if(ReciveList.length>0)
			{
				if(ReciveList.length>1)
				{
					ReciveList.focus();
					window.alert('每次只能请选择一个发送对象！');
					return false;
				}
	
				for (var y=0;y<ReciveList.length;y++)
				{
				   ReciveList.options[y].selected = true;
				}

			}
			else
			{
				ReciveList.focus();
				window.alert('请选择要发送消息的对象！');
				return false;
			}



			if(MsgContent.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写消息内容!');
				MsgContent.focus();
				return false;
			}
			
			if(SendName.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写发送人姓名!');
				SendName.focus();
				return false;
			}

			if(SendMobile.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写发送人号码!');
				SendMobile.focus();
				return false;				
			}
			else
			{
				if(ismobile(SendMobile.value)==false)
				{
					SendMobile.focus();
					return false;
				}
			}

			if(CheckRadio(Identity)!="true")
			{
				alert('请选择你的身份!');
				//Identity.focus();
				return false;
			}

			if(Validity.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写验证码!');
				Validity.focus();
				return false;
			}
			else
			{
				if(CheckValidity(Validity.value)==false)
				{
					Validity.focus();
					return false;
				}
			}
			return true;
			
		}

		function CheckRadio(myRadio)
		{
			var flag;
			for(i=0;i<myRadio.length;i++)
			{
				if(myRadio[i].checked==true)
				{					
					flag="true";
					break;
				}
			}
			return flag;
		}
		
		function CheckValidity(myValidity)
		{
			if(myValidity.length==4)
			{
				if(isNaN(myValidity))
				{
					alert("验证码应为数字组合!");
					return false;
				}
			}
			else
			{
				alert('验证码位数应为4位!');
				return false;
			}
		}

	function ReloadPage(CID,schid,comid)
	{
		window.location="selectMessage.asp?classid="+CID+"&schid="+schid+"&comid="+comid;
	}

	function loadform(temp)
	  {
	  window.location="selectMessage.asp?schid="+temp
	  }
	function loadform1(temp)
	{
	  window.location="selectMessage.asp?comid="+temp
	}
	function loadform2(temp1,temp2)
	{
	  window.location="selectMessage.asp?schid="+temp1+"&comid="+temp2
	}

	function loadform01(temp1)
	  {
	  window.location="selectMessage.asp?selarea="+temp1;
	}
	function loadform02(temp1,temp2)
	{
	  window.location="selectMessage.asp?selarea="+temp1+"&schid="+temp2;
	}

	function loadform03(temp1,temp2,temp3)
	{
	  window.location="selectMessage.asp?selarea="+temp1+"&schid="+temp2+"&cur_classid="+temp3
	}

	function CheckSel()
	{
		//onclick="form1.tbExamName.value='期中考试';"
			//$(".showbox").hide();
			//$(".cover").hide();
			//$("#identity").css("visibility", "visible");
		
			var teacherinfo,teacherinfolist;
			teacherinfo=form2.sel_teacher.value;


			teacherinfolist=teacherinfo.split(",");	
			if(typeof(teacherinfolist[1])=="undefined")
			{
				alert("对不起，请先选择老师再提交!");
				return false;
			}
			window.opener.document.form1.rname.value=teacherinfolist[1];
			window.opener.document.form1.rmobile.value="***********";
			window.opener.document.form1.teacherid.value=teacherinfolist[0];
			//window.opener.document.form1.rmobile.readonly="true;SetReadOnly	
			window.opener.SetReadOnly();
			window.close();	
	}


	//---------------------

		//检查 - 用户输入
		function subcheck_bak()
		{
			var rname=document.form1.rname;
			var rmobile=document.form1.rmobile;
			var sname=document.form1.sname;
			var smobile=document.form1.smobile;
			var willing=document.form1.willingtext;
			var confirm=document.form1.Confirm;			
			
			alert("对不起，新年心语活动已于2月28日截止，敬请继续关注评选结果。");
			return false;


			if(rname.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写接收人姓名!');
				rname.focus();
				return false;
			}
			
			if(rmobile.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写接收人手机/小灵通号码!');
				rmobile.focus();
				return false;
			}
			else
			{
				if (rmobile.value!="***********")
				{
					if(ismobile(rmobile.value)==false)
					{
						rmobile.focus();
						return false;
					}
				}

			}

			if(willing.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写您的祝福内容!');
				willing.focus();
				return false;
			}

			if(sname.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写您的姓名!');
				sname.focus();
				return false;				
			}

			//if(smobile.value.replace(/(^\s+|\s$)/g,"")=="")
			//{
			//	alert('请填写您的联系电话；\r联系电话仅用户抽奖!');
			//	smobile.focus();
			//	return false;
			//}
			//else
			if(smobile.value.replace(/(^\s+|\s$)/g,"")!="")
			{
				if(ismobile(smobile.value)==false)
				{
					smobile.focus();
					return false;
				}
			}



			if(confirm.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写验证码!');
				confirm.focus();
				return false;
			}
			else
			{
				if(CheckValidity(confirm.value)==false)
				{
					confirm.focus();
					return false;
				}
			}
			return true;			
		}

		
		function CheckValidity(myValidity)
		{
			if(myValidity.length==4)
			{
				if(isNaN(myValidity))
				{
					alert("验证码应为数字组合!");
					return false;
				}
			}
			else
			{
				alert('验证码位数应为4位数字组合!');
				return false;
			}
		}


		//判断手机号码是否正确
		function ismobile(jmobile)
		{
			if(isNaN(jmobile))
			{
				alert("手机/小灵通必须全为数字组合");
				return false;
			}

			if(jmobile.substring(0,2)=="13" || jmobile.substring(0,2)=="15")
			{
				if(jmobile.length!=11)
				{
					alert("手机号码必须以\"13\"或\"15\"开头,并且长度为11位");
					return false;
				}
			}
			else
			{
				if(jmobile.substring(0,1)=="0")
				{
					if(jmobile.substring(0,3)=="013" || jmobile.substring(0,3)=="015")
					{
						alert("手机号码不以0开头");
						return false;
					}
					if(jmobile.length!=11 && jmobile.length!=12)
					{
						alert("小灵通号码为区号+号码，但不包括+号,长度为11或12位");
						return false;
					}
				}
				else
				{
					alert("手机号码以‘13’或‘15’开头，长度为11位；小灵通号码为区号+号码，区号以‘0’开头！");
					return false;
				}
			}
		}
			function OnMouseUp()
			{
				var d_title="请填写120字以内的祝福内容";
				if(document.form1.willingtext.value == d_title)
				{
					document.form1.willingtext.value = "";
				}
			}
			
			function OnMouseOut()
			{					
				var d_title="请填写120字以内的祝福内容";
				if (document.form1.willingtext.value == "")
				{
					document.form1.willingtext.value = d_title;
				}
				
			}
function openwin(page,size,winname)
{//弹出窗口
	window.open(page,winname,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,"+ size);

}
	function SetReadOnly()
	{
		var myrname,myrmobile,myteacher;
		myrname=document.form1.rname;
		myrmobile=document.form1.rmobile;
		myteacher=document.form1.teacherid;

		if(myrmobile.value=="***********" )
		{
			myrname.readOnly=true;
			myrmobile.readOnly=true;
			myrname.title="接收人姓名已输入，若要修改请重新选择或点击下方“重写”按钮重新输入";
			myrmobile.title="号码已输入且被隐藏，无需再输入";
		}
	}
	
	function SetReadOnly2()
	{
		var myrname,myrmobile,myteacher;
		myrname=document.form1.rname;
		myrmobile=document.form1.rmobile;
		myteacher=document.form1.teacherid;

		//if(myrmobile.value=="" )
		{
			myrname.readOnly=false;
			myrmobile.readOnly=false;
			myrname.title="接收对象为老师的可点击右侧“选择老师”进行选择";
			myrmobile.title="";
		}
	}

			//检查 - 用户输入
		function subcheck()
		{
			var context=document.form1.txt_content;
			var sendname=document.form1.sendname;
			var sendtype=document.form1.rad_usertype;
			var sendmob=document.form1.txt_mob;
			var area=document.form1.areaname;
			//var confirm=document.form1.Confirm;

			if(context.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写内容!');
				context.focus();
				return false;
			}

			if(sendname.value.replace(/(^\s+|\s$)/g,"")=="")
			{
				alert('请填写您的姓名!');
				sendname.focus();
				return false;
			}

			if(!(sendtype[0].checked || sendtype[1].checked || sendtype[2].checked ))
			{
				alert('请您的身份!');			
				return false;				
			}			
			
			if(area.value=="0")
			{
				alert('请选择地区!');
				area.focus();
				return false;
			}

			if(sendmob.value.replace(/(^\s+|\s$)/g,"")!="")			
			{
				if(ismobile(sendmob.value)==false)
				{
					sendmob.focus();
					return false;
				}
			}
			return true;			
		}

	function getTime(){
	//获得当前时间
	var ThisTime = new Date();
	document.write(ThisTime.getFullYear()+"-"+(ThisTime.getMonth()+1)+"-"+ThisTime.getDate()+" "+ThisTime.getHours()+":"+ThisTime.getMinutes()+":"+ThisTime.getSeconds()); 
}


function $(id){
 return document.getElementById(id);
}


function selectPic(pic)
{	
	$("mytitle").innerHTML = "";
	var title;
	title="许愿："
	$("bgpic").style.cssText = "background:url(images/" + pic + ".gif) no-repeat";
	if (pic=="1")
	{
		title="祈福：";
	}
	if (pic=="2")
	{
		title="许愿：";
	}
	if (pic=="3")
	{
		title="加油：";
	}
	if (pic=="4")
	{
		title="哀悼：";
	}
	$("mytitle").innerHTML = title;
}

function TextYlType(typeid){
	var yltype="";
	if (typeid=="1")
	{
		yltype="教师"
	}
	if (typeid=="2")
	{
		yltype="家长"
	}
	if (typeid=="3")
	{
		yltype="学生"
	}
	$("yltype").innerHTML = yltype;
	ylname
}

function TextYlName(obj){
	$("ylname").innerHTML = "";
	$("ylname").innerHTML = obj;	
}

