﻿function inputUserNameVerify(obj)
{
	
	if(obj.value=="用户名")
	{
		
		$(obj.id).value="";
		$(obj.id).className="loginInputSelect";
	}
	else if(obj.value=="")
	{
		$(obj.id).className="";
		$(obj.id).value="用户名";
	}

}
function inputUserPassVerify(obj)
{
	
	if(obj.value=="密码密码密码")
	{
		
		$(obj.id).value="";
		$(obj.id).className="loginInputSelect";
	}
	else if(obj.value=="")
	{
		$(obj.id).className="";
		$(obj.id).value="密码密码密码";
	}

}
function inputUserYZMVerify(obj)
{
	
	if(obj.value=="验证码")
	{
		
		$(obj.id).value="";
		$(obj.id).className="loginInputSelect";
	}
	else if(obj.value=="")
	{
		$(obj.id).className="";
		$(obj.id).value="验证码";
	}

}
function GetComments(pagesize,pageindex,catalog,showLayer)
{
    
    $(showLayer).innerHTML = "正在加载，请稍后... ...";
    //$("CommentList").style.height = 30 +"px" ;
   
    var myRequest = new Request({url: 'API/GetComment.aspx', method: 'get', 
                                onSuccess: function(responseText, responseXML) {
                               // alert(responseText); 
                                $(showLayer).innerHTML = responseText ;
                                //$("CommentList").style.height=$(showLayer).offsetHeight +"px";
                               //closeAjaxInfo();
                               
                                PageInfoShow(catalog,pagesize,pageindex,showLayer);
                                }});
    
    myRequest.send('pageNow='+pageindex+'&PageSize='+pagesize+'&CurrentSoft='+catalog+'&Random='+Math.random());
    
}
function changeCataLatest(id)
{
    
    $$("#CataNewsUL li").each(function(item,id){item.removeClass('curr');});
    $$("#latestSoftDiv div.cate-list").each(function(item,id){item.setStyle('display','none');});
    $("CataNewsLi" + id).addClass('curr');
    $("TOPLATESTLIST"+id).setStyle('display','block');
}
function slidetween()
{
    
    if($('picshows').style.height == "390px")
    $('picshows').tween('height','0px');
    else
    $('picshows').tween('height','390px');
}
function SlideRight()
{
    var test = $('ctl00_cphMain_EditedWalls').getPosition();
    var myFX = new Fx.Scroll('ctl00_cphMain_EditedWalls');
    //myFX.toRight();
    if(this.EditCount < (this.picArray.length-1) || ((this.EditCount < (this.picArray.length-1)) && (this.picArray[this.EditCount]==1) ))  
    {   
                                   
        this.EditOffSetX += ((this.picArray[this.EditCount]==1)?498:336);
        this.EditCount ++; 
        myFX.start(this.EditOffSetX,0);  
        
    }
   
    
    
   //alert("\""+this.EditOffSetX+"\"" + this.MaxOffSetX);
}


function SlideLeft()
{
    var test = $('ctl00_cphMain_EditedWalls').getPosition();
    var myFX = new Fx.Scroll('ctl00_cphMain_EditedWalls');
    //myFX.toRight();
    if(this.EditCount > 0)                                    
    {
        this.EditCount --;
        this.EditOffSetX -= ((this.picArray[this.EditCount]==1)?498:336);
         
        myFX.start(this.EditOffSetX,0);
        
    }
    
    
   // alert("\""+this.EditOffSetX+"\"");
}

function myFav()
{

     var myRequest = new Request({url: 'API/AddFav.aspx', method: 'get', 
                                onSuccess: function(responseText, responseXML) {
                           
                            var roar1 = new Roar({
		position: 'upperLeft'
	  });
                               roar1.alert(responseText);
                               
                                }});
    
    myRequest.send('softid='+$("ctl00_cphMain_currentSoftId").value+'&Random='+Math.random());
    
}

function verifyLogin()
{
  
  $('ssll').value=9;

  var myRequest = new Request({url: 'API/M8FansUserInterFace.aspx',async:false, method: 'get', 
                                onSuccess: function(responseText, responseXML) {
                            
                              $('ssll').value=responseXML.getElementsByTagName('IsOnline')[0].firstChild.nodeValue;
                            
                           
                                }});
    
    myRequest.send('Action=GetUser&Random='+Math.random());
 
   return $('ssll').value;
   
}

function saveComment(confirm,comment,softid)
{
  
 
  var myRequest = new Request({url: 'API/SaveComment.aspx',async:false, method: 'get', headers: { "Content-Type": "application/json; charset=utf8" },
                                onRequest:function()
                                {
                                 alerts  = "提交中.......";
                                 showAlertMessage(alerts);
                                },
                                onSuccess: function(responseText, responseXML) {changeImage('validateImage','commentyzm');
                              rst = responseText.split('|');
                              if(rst[0]==1){

                              alerts  ="<font color=red>Error:"+rst[1]+"</font>";
                              changeImage('validateImage','commentyzm');
                              showAlertMessage(alerts,2000);
				
}
                              else
                              {
                              GetC();
                              ClearC();
                              alerts  ="<font color=blue>"+rst[1]+"</font>";
                              showAlertMessage(alerts,2000);
                              }
                             // loginInfo=responseXML.childNodes.item(1).firstChild.text;
                           
                                }});
    
    myRequest.send('confirmation='+confirm+'&comment='+ escape(comment)+'&softid='+softid+'&Random='+Math.random());

   
   
}

function loginUser(confirm,username,password)
{
  
 
  var myRequest = new Request({url: 'API/UserLoginAPI.aspx',async:false, method: 'get', headers: { "Content-Type": "application/json; charset=utf8" },
                                onRequest:function()
                                {
                                 showAlertMessage("登录中.......");
                                },
                                onSuccess: function(responseText, responseXML) {
                               //alert(responseText);
                          
                              rst = responseText.split('|');
                              if(rst[0]==1)
				{

	                                alerts  ="<font color=red>"+rst[1]+"</font>";
	                                showAlertMessage(alerts,2000);
					changeImage('loginImage','loginyzm');
				}
                              else
                              {

                              
                              alerts  ="<font color=blue>"+rst[1]+"</font>";ifLogin();
                              showAlertMessage(alerts,2000);
                              }
                             
                           
                                }});
    
    myRequest.send('confirmation='+confirm+'&LoginUser='+ escape(username)+'&LoginPWD='+password+'&Random='+Math.random());

   
   
}

function AdminLogin()
{
    art.dialog(
        {	
            iframe : '/AdminLogin.aspx',
            lock:true,
            id:"shoaAjax",
            style:'noClose',
            width:'300px',
            height:'150px',
            title:'管理员登陆管理'
            
        }
        ).close(function(){location.reload();});
}

function UserLoginDialog()
{
    art.dialog(
        {	
            iframe : '/LoginUser.aspx',
            lock:true,
            id:"loginDialog",                        
            width:'320px',
            height:'180px',                   
            title:'登陆... ...'          
            
        }
       
        ).close(function(){location.reload();});
}

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 ifLogin()
            {
               
                if(verifyLogin()==0)
                {
                    $('divNotLoggedin').style.display = "";
                    $('divLoggedIn').style.display ="none";
                    changeImage('loginImage','loginyzm');
                }
                else if(verifyLogin()==1)
                {
                    $('divLoggedIn').style.display = "";
                    $('divNotLoggedin').style.display ="none";
                    changeImage('validateImage','commentyzm');
                }
            }   

function PageInfoShow(catalog,pageSize,pageNow,showlayer)
{
    //alert("in" + catalog.toString() + pageSize.toString() + pageNow.toString()+showlayer.toString() );
    var myRequest = new Request({url: 'API/GetCommentCount.aspx', method: 'get', 
                                  onSuccess: function(responseText, responseXML) {
                                  //alert(responseText);
                                  var pages = (parseInt(responseText) % pageSize == 0)?(parseInt(responseText) / pageSize):((parseInt(responseText) / pageSize)+1);
                                  pages = parseInt(pages);
                                  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=\"#cmBegin\" onclick=\"GetComments(20,"+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=\"#cmBegin\" onclick=\"GetComments(20,"+PrevPage+",'"+catalog+"','"+showlayer+"')\">"+"上一页" +"</a>"+"</li>" + showHTML;
                                  showHTML = showHTML +"<li class='long'>"+"<a href=\"#cmBegin\" onclick=\"GetComments(20,"+NextPage+",'"+catalog+"','"+showlayer+"')\">"+"下一页" +"</a>"+"</li>";
                                  $("pageLayer").innerHTML=showHTML;
                                  
                                  
                                  
                                  
                                  }});

    myRequest.send('CurrentSoft='+catalog+'&Random='+Math.random());
}

function showAlertMessage(ex,dura)
{
    $('alertMessage').innerHTML = ex;    
    $('alertMessage').fade('in').slide('hide').slide('in');
    if(dura>0)
    {
        (function(){$('alertMessage').slide('out');$('alertMessage').fade('out');}).delay(dura);
    }

}

