﻿var timeId=null;

  function startAnimationUp()
      {timeId=setInterval("animateUp()",220);}

  //定义愿望div向上飘移的函数
  function animateUp()
        {     
       var div1=document.getElementById("div1");
       var top=eval(div1.style.top.replace("px",""));
       div1.style.visibility="visible";
       if(top>400)
          {
         div1.style.left=Math.random()*50+250;
         div1.style.top=top-10;
             }
      else
             {
           clearInterval(timeId);
             }
        }

   //定义发表愿望时使用xmlhttprequest对象实现局部刷新的函数
  function saveWish(id)
       { 
       var form=document.getElementById(id);
       var wishContent=form.wishContent.value;
       document.getElementById("contentDiv").innerHTML=wishContent;

       var img1=document.getElementById("img1");
       var imgPath=img1.src.substring(img1.src.lastIndexOf("/"),img1.src.length);
           imgPath="images"+imgPath

       var url="insertRespond.php";
       var wishTitle=document.getElementById("wishTitle");
       var wishNiCheng=document.getElementById("wishNiCheng");
       var friendEmail=document.getElementById("friendEmail");
       var wishFenLei=document.getElementById("wishFenLei");
       var data="wishFenLei="+wishFenLei.value+"&imgUrl="+imgPath+"&wishTitle="+wishTitle.value+"&wishContent="
+wishContent+"&wishNiCheng="+wishNiCheng.value+"&friendEmail="+friendEmail.value;

       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.onreadystatechange=function responseMode(){
             if(http.readyState==4&&http.status==200) 
                    {
                alert("你的心愿是心苑彩绫的第"+http.responseText+"号，你可以在搜索框中输入你的心愿号码，查看你的彩绫心愿。");
                    }
                   }
         http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  
         http.send(data); 
           }
        form.wishTitle.value="";
        form.wishContent.value="";
        form.wishNiCheng.value="";
        form.friendEmail.value="";
        form.wishTitle.focus();   
     }

