// JScript 文件
$().ready(function(){getLink();});
var PropertyTable = null;
var listTable=null;
var type=null;
var tb = null;
var PropertyName = null;
var List = null;
var AddNew = null;
var li1 = null;
var soutcount=null;
var scount=null;
function g(id){return document.getElementById(id);}
function getId(){
          PropertyTable=g("PropertyTable");
          listTable=g("listTable");
          tb = g("tb");
          PropertyName=g("PropertyName");
          PropertyUrl = g("PropertyUrl");
          PropertDesc = g("PropertDesc");
          hID=g("hID");
          List = g("List");
          AddNew = g("AddNew");
          li1 = g("li1");
          soutcount=g("soutcount");
          scount = g("scount");
}
function Change(n)
{   
    getId();
    switch(n)
    {
      case 0:
         PropertyTable.style.display="none";
         listTable.style.display="";
         type=null;
         AddNew.className="";
         li1.className = "";
         List.className = "hover";
         li1.style.display = "none";
         break;
      case 1:
         PropertyTable.style.display="";
         listTable.style.display="none";
         AddNew.className="hover";
         li1.className = "";
         List.className = "";
         li1.style.display = "none";
         type=0;
         break;
      case 2:
        type=1;
        PropertyTable.style.display="";
        listTable.style.display="none";
        AddNew.className="";
         li1.className = "hover";
         List.className = "";
         li1.style.display = "";
        break;
    }
}
var mArray = new Array();
function mEntity()
{
   id=null;
    sname=null;
    surl=null;
    sdesc=null;
    scount=null;
    soutcount=null;
    sstatus=null;
    sfirst=null;
   
}

var CurrentRowsNum=1;
var RowsShowNum = 10;
function getLink(Num)
{
  if(Num==null)
    CurrentRowsNum=1;
  else
    CurrentRowsNum = Num;
  getId();
  $("#tb").html("<tr><td colspan=7>正在查询，请稍后。。</td></tr>");
  var response = admini_ManageLink.getLink(CurrentRowsNum,RowsShowNum).value;
  if(response!=null)
  {
    if(response.length>0)
    {
        var str="";
         mArray.length=0;
        for(i=0;i<response.length-2;i++)
        {
           str+="<tr><td>"+response[i][1]+"</td>";
           str+="<td>"+response[i][2]+"</td>";
           str+="<td>"+response[i][3]+"</td>";
           str+="<td>"+response[i][4]+"</td>";
           str+="<td>"+response[i][5]+"</td>";
           str+="<td>"+(response[i][6]==true?"是":"否")+"</td>";
           str+="<td><a href=\"javascript:Update("+response[i][0]+")\">修改</a><a href=\"javascript:del("+response[i][0]+")\">删除</a></td>";
          
           var m = new mEntity();
           m.id=response[i][0];
           m.sname=response[i][1];
           m.surl=response[i][2];
           m.sdesc=response[i][3];
           m.scount=response[i][4];
           m.soutcount=response[i][5];
           m.sstatus=response[i][6];
           m.sfirst=response[i][7];
           mArray.push(m);
        }
        $("#tb").html(str);

        var SumRows=response[response.length-1];
        var CurrentRowsNum=response[response.length-2];
        var PageCount = Math.ceil(SumRows/RowsShowNum); 
        initPagingation(PageCount,CurrentRowsNum,SumRows,CurrentRowsNum,"getLink(_pn_)","");
    }
  }
}
function Save()
{
   var k = hID.value;
   var sname =PropertyName.value;
   var st = $("#select1").val();
   var surl=PropertyUrl.value;
   var sdesc = PropertDesc.value; 
   var sc = scount.value;
   var sco = soutcount.value;
   var response = null;
   if(type==0)
       response = admini_ManageLink.addNewSite(null,sname, surl, sdesc, st,sc,sco).value;
   else
      response = admini_ManageLink.addNewSite(k,sname, surl, sdesc, st,sc,sco).value;
      if(response==null)
      {
         alert("失败！");
      }else if(response=="1"){
        alert("成功！");
        getLink();
        Change(0);
      }
      else if(response=="0")
        alert("失败");
      else
         alert(response);
}

function Update(key)
{
   Change(2);
   var m=null;
   for(i=0;i<mArray.length;i++)
   {
       if(key==mArray[i].id)
       {
           m=mArray[i];
           break;
       }
   }
   
   if(m==null)
    return;
   hID.value=key;
   PropertyName.value=m.sname;
   $("#select1").val(m.sstatus==true?"1":"0");
   PropertyUrl.value=m.surl;
   PropertDesc.value=m.sdesc;
   soutcount.value=m.soutcount;
   scount.value = m.scount;
   
   
}

function del(key)
{
    if(!confirm("确定删除吗？"))
        return;
    var response = admini_ManageLink.del(key).value;
    if(response=="1")
    {
        alert("ok");
        getLink();
        Change(0);
    }else if(response=="0")
        alert("执行失败");
     else
        alert(response);
}

function Cancel(){Change(0);};