﻿function GetThemes(pagesize,pageindex,catalog,showLayer)
{
    showAjaxInfo();
    var myRequest = new Request({url: 'AjaxCode/GetThemes.aspx', method: 'get', 
                                onSuccess: function(responseText, responseXML) {
                                //alert(responseText); 
                                $(showLayer).innerHTML = responseText;
                               closeAjaxInfo();
                                PageInfoShow(catalog,pagesize,pageindex,showLayer);
                                }});
    
    myRequest.send('PageIndex='+pageindex+'&PageSize='+pagesize+'&CataLog='+catalog+'&Random='+Math.random());
    
}

function GetWallpapersTop(Action,showLayer)
{
    var myRequest = new Request({url: 'AjaxCode/GetThemeTop.aspx', method: 'get', 
                                onSuccess: function(responseText, responseXML) {
                                //alert(responseText); 
                                $(showLayer).innerHTML = responseText;                                
                                }});
    
    myRequest.send('Action='+Action+'&Random='+Math.random());
}

function showAjaxInfo()
{
    art.dialog(
        {	
            content:"<img src='image/ajax1.gif' />",
            lock:true,
            id:"shoaAjax",
            style:'noClose',
            width:'300px',
            title:'请等待.... ....'
        }
);
}
function closeAjaxInfo()
{
    art.dialog({id:'shoaAjax'}).close()
}

function getCatalog(catalogDiv)
{
  
  if($("ctl00_txtcatalog").value != null && $("ctl00_txtcatalog").value != "")
	changeCatalog($("ctl00_txtcatalog").value);
  else
	changeCatalog("All");


}

function changeCatalog(ctNum)
{
    //$$('#catalogLayer li').each(function(item){item.className="";});
    //$("CatalogShow"+ctNum).className="curr";
    GetThemes(16,1,ctNum,"WallPaperShow");
}

function PageInfoShow(catalog,pageSize,pageNow,showlayer)
{
    //alert("in" + catalog.toString() + pageSize.toString() + pageNow.toString()+showlayer.toString() );
    var myRequest = new Request({url: 'AjaxCode/GetThemeCount.aspx', method: 'get', 
                                  onSuccess: function(responseText, responseXML) {
                                  //alert(responseText);
                                  var pages = (parseInt(responseText) % pageSize == 0)?(parseInt(responseText) / pageSize):((parseInt(responseText) / pageSize)+1);
                                  var NextPage = (pageNow + 1 >= pages)  ? pages : (pageNow +1);
                                  var PrevPage = (pageNow -1<= 1)  ? 1 : (pageNow -1);
                                  var pageShowBF = 5 ; 
                                  var showHTML = "";
                                  var startPage = ((pageNow -pageShowBF)<0)? 1: (pageNow -pageShowBF);
                                  var endPage =((pageNow +pageShowBF)>pages)? pages: (pageNow +pageShowBF);      
                                  if(pageNow < pageShowBF) endPage = endPage + (pageShowBF - pageNow ) +1 ;                            
                                  for(i=1;i<=pages;i++)
                                  {
                                    if(i>=endPage)
                                    {
                                        showHTML += "<li class='suspension'>... ...</li> ";
                                        i=parseInt(pages);
                                    }
                                    if(i==pageNow)
                                    showHTML += "<li class='curr'>";
                                    else 
                                    showHTML += "<li>";
                                    
                                    showHTML += "<a href=\"#\" onclick=\"GetThemes(16,"+i.toString()+",'"+catalog+"','"+showlayer+"')\">"+i.toString() +"</a>";
                                    showHTML += "</li>";
                                    if(i<startPage)
                                    {
                                        showHTML += "<li class='suspension'>... ...</li> ";
                                        i=startPage;
                                    }
                                    
                                  }
                                  showHTML = "<li class='long'>"+"<a href=\"#\" onclick=\"GetThemes(16,"+PrevPage+",'"+catalog+"','"+showlayer+"')\">"+"上一页" +"</a>"+"</li>" + showHTML;
                                  showHTML = showHTML +"<li class='long'>"+"<a href=\"#\" onclick=\"GetThemes(16,"+NextPage+",'"+catalog+"','"+showlayer+"')\">"+"下一页" +"</a>"+"</li>";
                                  $("pageLayer").innerHTML=showHTML;
                                  //alert(showHTML);
                                  
                                  
                                  
                                  }});

    myRequest.send('CataLog='+catalog+'&Random='+Math.random());
}


