﻿// JScript File

var Message=Class.create();
Message.prototype={
container:null,
contracted:false,
initialize:function(container)
{
    this.container=container;
    if(container)
    {
        this.content_html=document.createElement('div');
        this.content_html.className='jy_box';
        this.content_html.id='jy_box';
        this.content_html.innerHTML='<div class="jy_helplink"><div id="jy_contract">-</div><div>提一个改进建议？</div></div><div id="jy_thanks" style="display:block;overflow:hidden;height:0px;margin-top:5px;"><div style="display:block;height:30px;line-height:30px;font-weight:700;text-align:center;width:100%;"><font style="background:#aaeeaa;">感谢您为isay365.com提供建议！</font></div></div><div id="jy_controller" style="display:block;overflow:hidden;height:0px;"><div class="jy_content" id="jy_content"><div class="jy_text">您对此功能有何建议，欢迎您提出来，以便我们为您提供更好的服务。</div><div class="jy_textarea"><textarea name="" cols="" rows="" class="jy_textarea" id="jy_textarea"></textarea><div class="jy_bt"><a href="#" class="btn_login" id="jy_btn_sub">提交留言</a></div></div></div>';
             
    }
    else
    this.content_html=null;
    var _this=this;
},
showContainer:function()
{
   if(this.content_html)
   {
        this.container.appendChild(this.content_html);
        this.contract();
        this.presentData();
        $('jy_contract').innerText="+";       
    }
},
contract:function()
{
   
   $('jy_contract').onclick=function(){
  
   if(this.innerText=="-")
   {
       this.innerText="+";       
       divGradual(-15,0);    
   }
   else
   {        
        this.innerText="-";
         divGradual(15,150);
         isReturn=false; 
         $("jy_textarea").focus();          
   }
  }
},
presentData:function()
{   
    var _this=this;
    $('jy_btn_sub').onclick=function()
    {
        var content = $('jy_textarea').innerText;        
        if(content=='' || content ==null)
        {
            alert('留言不能为空！');
            $("jy_textarea").focus();  
            return false;
        }
        var category="0";
        try{category=cur_url_arr[cur_url_arr.length-1].toString();}catch(e){e}
        var params=[];
	    params[0] = {"Name":"userName","Value":userName};
	    params[1] ={"Name":"category","Value":category};
	    params[2]={"Name":"content","Value":content};
	    WebServiceClient.Invoke("../study.asmx","UploadFeedBack",params,_this.presentDataReturn);
	    this.disabled="disabled";
	    return false;
    }
},
presentDataReturn:function(result)
{
    $('jy_btn_sub').disabled=false;
    if(result != "")
    {
        isReturn=true;
        markMessage = true;
        $("jy_textarea").value='';
        $('jy_contract').innerText="+";
        divGradual(-15,0);
    }
    else
    {
        alert('登录后才能留言！');
    }    
}
}
function deleteMessage()
{
try{
        var obj = $("jy_box");
        if(obj)
        {
            obj.parentNode.removeChild(obj);
        }
    }
    catch(e)
    {
    }
}
var timeControl=null;
var isReturn=false;
var markMessage =true;
function divGradual(speed,toHeight)
{
   timeControl=setInterval("changeHeight($('jy_controller'),"+speed+","+toHeight+")",20);
}
function changeHeight(obj,speed,toHeight)
{
    if(isReturn)
    {
        if(markMessage)
        {
            $('jy_thanks').style.height=(parseInt($('jy_thanks').style.height)+5)+"px";            
        }
       if( parseInt($('jy_thanks').style.height)>=30)
       {
           markMessage=false;
       }
    }
    else if(parseInt($('jy_thanks').style.height)>0)
    {
        var height=parseInt($('jy_thanks').style.height)-5;
        $('jy_thanks').style.height=(height>=0?height:0)+"px";
    }
    else
    {}
    if(speed>0)
    {      
        if(parseInt(obj.style.height)>=toHeight)
        {
            clearInterval(timeControl);
            return;
         }
    }
    else
    {
         if(parseInt(obj.style.height)<=toHeight && timeControl !=null)
         {
            clearInterval(timeControl);
            return;
          }
    }
     obj.style.height=(parseInt(obj.style.height)+speed)+"px";
}


