﻿//检查上传照片选择的个数
function PhotoUpNumCheck(obj)
{
     var ckbnum=0;
     $("input[@name=photo_id][@checked]").each(function(){
        ckbnum++;
     });
     if(ckbnum>5)
     {
         //alert('您已经选择超过5个作品了');
         CLdialog('刺陵弹出','text:您经选择的作品超过了5个',251,148,'','1');
         obj.checked=false;
     }     
}

//提交上传数据
function PhotoJoinSave()
{
    var PostData=""; 
    var p_id_l="";
    var ckbnum=0;
   $("input[@name=photo_id][@checked]").each(function(){
        p_id_l+=this.value+',';
        ckbnum++;
   }) ;
   if(ckbnum>5)
   {
       //alert('您经选择的作品超过了5个');
       CLdialog('刺陵弹出','text:您经选择的作品超过了5个',251,148,'','1')
       return ;
   }
   if(ckbnum<=0)
   {
        //alert('您未选择任何作品');
        CLdialog('刺陵弹出','text:您未选择任何作品',251,148,'','1')
       return ;
   }
   p_id_l=p_id_l.substr(0,p_id_l.length-1);
   PostData+="p_id="+p_id_l;   
    $.ajax({
        async: true,
        type:"post",
        url:'/Ciling/PhotoJoinSave/?rand='+Math.round(Math.random()*10000),
        data:PostData,
        error:function(){
            //alert("作品提交失败，应用程序错误！");            
             CLdialog('刺陵弹出','text:作品提交失败，应用程序错误！',251,148,'','1');
        },
        success:function(msg){ 
            if(msg>0)
            {
               // dialog('保存结果','text:圈子保存成功！',217,'auto',1,1,"GroupModiOk()","");
               //alert("作品提交成功！");
               CLdialog('刺陵弹出','text:作品提交成功',251,148,'javascript:location.reload();','')
               
               
            }
            else if(msg==-101)
            {
              //alert('未登录');
              CLdialog('刺陵弹出','text:未登录',251,148,'','1')
             }
           else if(msg==-102)
           {
              //alert('未选择作品');
              CLdialog('刺陵弹出','text:未选择作品',251,148,'','1')
           }
           else if(msg<=0)
           {
              //alert('提交的作品超过限额，您只能再提交'+Math.abs(msg)+'幅作品');
              CLdialog('刺陵弹出','text:提交的作品超过限额，您只能再提交'+Math.abs(msg)+'幅作品',251,148,'','1')
           }
           else
            {
                //dialog('保存结果','text:'+msg,217,'auto',1,1,"","");
                 //alert(msg);
                 CLdialog('刺陵弹出','text:'+msg,251,148,'','1')
            }
        }
    }) ;    
}

function PhotoVoteSave(vid)
{
    if($("input[@type=radio][@name=rdrt][@checked]").val()==''||$("input[@type=radio][@name=rdrt][@checked]").val()==undefined)
    {
        //alert('未选择投票项');
        CLdialog('刺陵弹出','text:未选择投票项',251,148,'','1');
        return;
    }
    //alert($("input[@type=radio][@name=rdrt][@checked]").val());
    var PostData=''
    PostData+="vid="+vid;
    PostData+="&voteitem="+$("input[@type=radio][@name=rdrt][@checked]").val();
    $.ajax({
        async: true,
        type:"post",
        url:'/Ciling/PhotoVoteSave/?rand='+Math.round(Math.random()*10000),
        data:PostData,
        error:function(){
            //alert("投票失败，应用程序错误！");            
            CLdialog('刺陵弹出','text:投票失败，应用程序错误！',251,148,'','1');
        },
        success:function(msg){ 
            if(msg==0)
            {
               // dialog('保存结果','text:圈子保存成功！',217,'auto',1,1,"GroupModiOk()","");
               //alert("投票成功！");
               CLdialog('刺陵弹出','text:投票成功',251,148,'javascript:location.reload();','');
               
            }
            else if(msg==-1)
            {
              //alert('未登录');
              CLdialog('刺陵弹出','text:未登录',251,148,'','1');
              }
           else if(msg==-2)
           {
              //alert('参数不正确');
              CLdialog('刺陵弹出','text:参数不正确',251,148,'','1');
              }
           else if(msg==-1806)
           {
              //alert('参数不正确');
              CLdialog('刺陵弹出','text:今日投票数已经达到极限啦',251,148,'','1');
              }
             else if(msg==-1808)
            {
              //alert('参数不正确');
              CLdialog('刺陵弹出','text:余额不够了',251,148,'','1');
              }
            else
            {
                //dialog('保存结果','text:'+msg,217,'auto',1,1,"","");
                // alert(msg);
                CLdialog('刺陵弹出','text:'+msg,251,148,'','1');
            }
        }
    }) ;
   
}

function CommentAdd(vid)
{
    if($("#txt_comment").val()==undefined||$("#txt_comment").val()=='')
    {
         CLdialog('刺陵弹出','text:评论内容不能为空！',251,148,'','1');
         return;
    }
    var PostData='';
    PostData+="vid="+vid;
    PostData+="&comment="+$("#txt_comment").val();
    $.ajax({
        async: true,
        type:"post",
        url:'/Ciling/CommentAdd/?rand='+Math.round(Math.random()*10000),
        data:PostData,
        error:function(){
            //alert("评论添加错误，应用程序错误！");            
            CLdialog('刺陵弹出','text:评论添加错误，应用程序错误！',251,148,'','1');
        },
        success:function(msg){ 
            if(msg==0)
            {
               // dialog('保存结果','text:圈子保存成功！',217,'auto',1,1,"GroupModiOk()","");
               //alert("评论成功！");
               CLdialog('刺陵弹出','text:评论成功！',251,148,'javascript:location.reload();','');               
               
            }
            else if(msg==-1)
            {
              //alert('未登录');
              CLdialog('刺陵弹出','text:未登录！',251,148,'','1');
              }
           else if(msg==-2)
           {
              //alert('参数不正确');
              CLdialog('刺陵弹出','text:参数不正确！',251,148,'','1');
              }
            else
            {
                //dialog('保存结果','text:'+msg,217,'auto',1,1,"","");
                 //alert(msg);
                 CLdialog('刺陵弹出','text:'+msg,251,148,'','1');
            }
        }
    }) ;
}

function CilingPhotoSearch()
{
    var kww='';
    if($("#pkw").val()!=undefined&&$("#pkw").val()!=''&&$("#pkw").val()!='作品名称')
       kww=$("#pkw").val();
    location.href="/Ciling/Photo?kw="+encodeURI(kww)
}

//拼图活动加入，并且领取碎片
function PuzzlesJoin()
{
    $.ajax({
        async: true,
        type:"get",
        url:'/Ciling/PuzzlesJoin/?rand='+Math.round(Math.random()*10000),        
        error:function(){
            //alert("加入拼图活动失败，应用程序错误！");            
            CLdialog('刺陵弹出','text:加入拼图活动失败，应用程序错误！',251,148,'','1');
        },
        success:function(msg){ 
            if(parseInt(msg)==0)
            {
               // dialog('保存结果','text:圈子保存成功！',217,'auto',1,1,"GroupModiOk()","");
              // alert("活动加入成功，已经领取一块拼图！");
               CLdialog('刺陵弹出','text:活动加入成功，已经领取一块拼图！',251,148,'/Ciling/Puzzles','');               
            }
            else if(parseInt(msg)==-1)
            {
                // alert("您未登录！");
                 CLdialog('刺陵弹出','text:您未登录！',251,148,'','1');
            }
            else if(parseInt(msg)==-2)
            {
                 //alert("您已经加入过此活动，不能重复领取拼图！");
                 CLdialog('刺陵弹出','text:您已经加入过此活动，不能重复领取拼图！',251,148,'/Ciling/Puzzles','1');
                             }
            else if(parseInt(msg)==-3)
            {
                 //alert("活动还未开始，无拼图可领！");
                 CLdialog('刺陵弹出','text:活动还未开始，无拼图可领！',251,148,'','1');
            }
            else
            {
                //dialog('保存结果','text:'+msg,217,'auto',1,1,"","");
                 //alert(msg);
                 CLdialog('刺陵弹出','text:'+msg,251,148,'','1');
            }
        }
    }) ;
}

//空间门票领取
function  TicketGet()
{
      $.ajax({
        async: true,
        type:"get",
        url:'/Ciling/TicketGet/?rand='+Math.round(Math.random()*10000),        
        error:function(){
           // alert("领取门票失败，应用程序错误！");            
           CLdialog('刺陵弹出','text:领取门票失败，应用程序错误！',251,148,'','1');
        },
        success:function(msg){ 
            if(parseInt(msg)==0)
            {
               // dialog('保存结果','text:圈子保存成功！',217,'auto',1,1,"GroupModiOk()","");
              // alert("门票领取成功！ 请重新登录客户端获得门票！");
              CLdialog('刺陵弹出','text:门票领取成功！',251,148,'javascript:location.reload();','');
            }
            else if(parseInt(msg)==-1)
            {
                 //alert("您未登录！");
                 CLdialog('刺陵弹出','text:您未登录！',251,148,'','1');
            }
            else if(parseInt(msg)==-2)
            {
                 //alert("活动还未开始，无门票可领！");
                 CLdialog('刺陵弹出','text:活动还未开始，无门票可领！',251,148,'','1');
            }
            else if(parseInt(msg)==-3)
            {
                 //alert("您已经领取过门票！");
                 CLdialog('刺陵弹出','text:您已经领取过门票！',251,148,'','1');
            }
            else
            {
                //dialog('保存结果','text:'+msg,217,'auto',1,1,"","");
                 //alert(msg);
                 CLdialog('刺陵弹出','text:'+msg,251,148,'','1');
            }
        }
    }) ;
}
