﻿//定义验证愿望内容的函数  
  function checkXuYuan(id)
    {
   var form=document.getElementById(id);
   var checkEmail=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; //声明验证电子邮件地址的正则表达式

   if(form.wishTitle.value.replace(/(^\s*)|(\s*$)/g,"")=="")
      {
     alert("标题不可以为空！");
     form.wishTitle.focus();
      }
   else if(form.wishContent.value.replace(/(^\s*)|(\s*$)/g,"")=="")
     {
     alert("内容不可以为空！");
     form.wishContent.focus();    
     }
   else if(form.wishNiCheng.value.replace(/(^\s*)|(\s*$)/g,"")=="")
     {
      alert("昵称不可以为空！");
      form.wishNiCheng.focus();
     }
   else if(form.wishTitle.value.replace(/(^\s*)|(\s*$)/g,"").length>50)
     {
      alert("标题不可以超过50个字符！");
      form.wishTitle.value="";
      form.wishTitle.focus();
     }
   else if(form.wishContent.value.replace(/(^\s*)|(\s*$)/g,"").length>200)
     {
     alert("内容不可以超过200个字符！");
     form.wishContent.value="";
     form.wishContent.focus();
     }
  else if(form.wishNiCheng.value.replace(/(^\s*)|(\s*$)/g,"").length>20)
    {
     alert("昵称不可以超过20个字符！")
     form.wishNiCheng.value="";
     form.wishNiCheng.focus();
    }
  else if(form.friendEmail.value.replace(/(^\s*)|(\s*$)/g,"")!="")
	{
      if(checkEmail.test(form.friendEmail.value.replace(/(^\s*)|(\s*$)/g,""))==false)
       {
       alert("电子邮箱地址格式不正确！");
       form.friendEmail.value="";
       form.friendEmail.focus();  
       }
	   
	  else {
      resetDiv();
      startAnimationUp();
      saveEmail(id);
      saveWish(id);
	   }
    }
 else if(form.friendEmail.value.replace(/(^\s*)|(\s*$)/g,"").length>50)
   {
    alert("电子邮箱不可以超过50个字符！");
    form.friendEmail.value="";
    form.friendEmail.focus();
   }
 else
    {
      resetDiv();	   
      startAnimationUp();
      saveEmail(id);
      saveWish(id);                         
   }
}
  
  //定义提交邮件信息的函数
  function saveEmail(id)
       {
       var form=document.getElementById(id);
       var wishTitle=document.getElementById("wishTitle");       
       var wishContent=form.wishContent.value;      
       var wishNiCheng=document.getElementById("wishNiCheng");
       var friendEmail=document.getElementById("friendEmail");

       var now=new Date();
       var yy=now.getFullYear();
       var mm=now.getMonth()+1;
       var dd=now.getDate();
       var hh = now.getHours(); //截取小时
       var mn = now.getMinutes(); //截取分钟
       var ss = now.getTime() % 60000; //获取时间，因为系统中时间是以毫秒计算的，所以秒要通过余60000得到
       ss = (ss - (ss % 1000)) / 1000; //然后，将得到的毫秒数再处理成秒 

       var wishTime=yy+"-"+mm+"-"+dd+" "+hh+":"+mn+":"+ss;
        
         
       var data="wishTitle="+wishTitle.value+"&wishContent="+wishContent+"&wishNiCheng="+wishNiCheng.value+"&friendEmail="+friendEmail.value+"&wishTime="+wishTime;
       var url="send/sendEmail.php";
       var http=false;
       try
        {http= new XMLHttpRequest();}
       catch(trymicrosoft)
         {try 
           {http = new ActiveXObject("Msxml2.XMLHTTP");}
          catch (othermicrosoft) 
            {try 
              {http = new ActiveXObject("Microsoft.XMLHTTP");}
             catch (failed) 
               {http = false;}
               }
          }

       if(!http) 
         {alert("浏览器出现问题");}
       else
           {
         http.open("post",url,true);
         http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  
         http.send(data); 
           }  
     }

  //定义验证搜索框内容的函数
  function checkSearch(id)
       {
      var check=/^[0-9]+$/; //声明判断是否是数字的正则表达式 
      
     if(check.test(document.getElementById("wishSearch").value.replace(/(^\s*)|(\s*$)/g,""))==true)
        {
       resetDiv();
       searchWish(id);
       startAnimationDown();
        }
     else
         {
          alert("请输入正确的愿望号码！");
          document.getElementById("wishSearch").value="";
          document.getElementById("wishSearch").focus();
         }
       }

   //定义选择图案的函数
  function  changeImg(){
       var gift0=document.getElementById("gift0");
       var gift1=document.getElementById("gift1");
       var gift2=document.getElementById("gift2");
       var gift3=document.getElementById("gift3");

       var img1=document.getElementById("img1");

       if(gift0.checked==true)
            {img1.src="images/gift0.gif";}
       if(gift1.checked==true)
            {img1.src="images/gift1.gif";}
       if(gift2.checked==true)
            {img1.src="images/gift2.gif";}
       if(gift3.checked==true)
            {img1.src="images/gift3.gif";}
           
       }

