﻿
function addtoPlaylist(id,type)
{
    setSentToFlashCookie(id,false);
    var HttpRequest=new HTTPRequest();
    HttpRequest.send("action/addtoPlayList.aspx?type="+type+"&id="+id);
    HttpRequest.onresponse=function(res)
    {
//        if(res.responseText=="OK")
//        {
//            alert("已经成功添加到播放列表中..但目前播放器不支持播放列表.");
//        }
	
    }
}

function playsong(id)
{
    setSentToFlashCookie(id,true);
    var HttpRequest=new HTTPRequest();
    HttpRequest.send("action/addtoPlayList.aspx?type=play&id="+id);
    HttpRequest.onresponse=function(res)
    {
        if(res.responseText=="OK")
        {
            //setSentToFlashCookie(true);
			
        }
   }
}

function setAllSongId(obj,id)
{
    var list=id.split(",");
    if(obj.checked)
    {
        document.getElementById("song").value=id;
        for(var i=0;i<list.length;i++)
        {
            document.getElementById("song_"+list[i].toString()).checked="checked";
        }
    }
    else
    {
        document.getElementById("song").value="";
        for(var i=0;i<list.length;i++)
        {
            document.getElementById("song_"+list[i].toString()).checked="";
        }
    }
    return false;
}

//function setOppositeSongID(id)
//{
//    document.getElementById("allSelect").checked=""
//    var list=id.split(",");
//    for(var i=0;i<list.length;i++)
//    {
//        if(document.getElementById("song_"+list[i].toString()).checked)
//        {
//            document.getElementById("song").value=document.getElementById("song").value.replace(list[i].toString()+",","").replace(","+list[i].toString(),"").replace(list[i].toString(),"");
//            document.getElementById("song_"+list[i].toString()).checked="";
//        }
//        else
//        {
//            document.getElementById("song_"+list[i].toString()).checked="checked";
//            if(document.getElementById("song").value.length==0)
//            {
//                document.getElementById("song").value=list[i].toString();
//            }
//            else
//            {
//                document.getElementById("song").value +=","+list[i].toString();
//            }
//        }   
//    }
//}

function selectSongID(obj,id)
{
    if(obj.checked)
    {
        if(document.getElementById("song").value.length==0)
        {
            document.getElementById("song").value=id;
        }
        else
        {
            document.getElementById("song").value +=","+id;
        }
    }
    else
    {
        document.getElementById("song").value=document.getElementById("song").value.replace(id+",","").replace(","+id,"");
    }
}
function playselect()
{
    if(document.getElementById("song").value.length>0)
    {
        setSentToFlashCookie(document.getElementById("song").value,true);
        var HttpRequest=new HTTPRequest();
        HttpRequest.send("action/addtoPlayList.aspx?type=playAll&list="+document.getElementById("song").value);
        HttpRequest.onresponse=function(res)
        {
    //        if(res.responseText=="OK")
    //        {
    //            //openplayer("play.aspx");
    //        }
		
	}
    }    
}

function addselectToPlayList()
{
    if(document.getElementById("song").value.length>0)
    {
        setSentToFlashCookie(document.getElementById("song").value,false);
        var HttpRequest=new HTTPRequest();
        HttpRequest.send("action/addtoPlayList.aspx?type=addAll&list="+document.getElementById("song").value);
        HttpRequest.onresponse=function(res)
        {
    //        if(res.responseText=="OK")
    //        {
    //            alert("已经成功添加到播放列表中..但目前播放器不支持列表.");
		
    //        }
		
		}
    }
}
function share(id,type,sharediv)
{
    var HttpRequest=new HTTPRequest();
    //var shareContent="祝DiggCD进入alexa前一千名";
    HttpRequest.send("action/share.aspx?type="+type+"&id="+id+"&content="+escape(document.getElementById(sharediv).value));
    HttpRequest.onresponse=function(res)
    {
        if(res.responseText=="OK")
        {
            responseTips += "已经成功分享..并成功公开为新鲜事.<br />";
        }
        else if(res.responseText=="UnLogined")
        {
            responseTips = "UnLogined";
        }
        shareres=true;
        showsharetips();
    }
}

function reportError()
{
    var ErrorContent=document .getElementById("errorIntro").value;
    var ErrorUrl=document .getElementById("errorUrl").value;
    //var ErrorContent="祝DiggCD进入alexa前一千名";var ErrorUrl="祝DiggCD进入alexa前一千名";
    if(ErrorContent==""||ErrorUrl=="")
    {
        responseTips="内容不能为空!";
        showtips();
    }
    else
    {
        var HttpRequest=new HTTPRequest();
        HttpRequest.send("action/addError.aspx?errorcontent="+escape(ErrorContent)+"&errorurl="+escape(ErrorUrl));
        HttpRequest.onresponse=function(res)
        {
            if(res.responseText=="OK")
            {
                responseTips="汇报成功!";
            }
            else if(res.responseText=="UnLogined")
                 responseTips="UnLogined";
            showtips();
        } 
    }
}

function playall(listall)
{
    setSentToFlashCookie(listall,true);
    var HttpRequest=new HTTPRequest();
    HttpRequest.send("action/addtoPlayList.aspx?type=playAll&list="+listall);
    HttpRequest.onresponse=function(res)
    {
//        if(res.responseText=="OK")
//        {
//            //openplayer("play.aspx");
//        }
		
	}
}

function addAllToPlayList(addlistall)
{
    setSentToFlashCookie(addlistall,false);
    var HttpRequest=new HTTPRequest();
    HttpRequest.send("action/addtoPlayList.aspx?type=addAll&list="+addlistall);
    HttpRequest.onresponse=function(res)
    {
//        if(res.responseText=="OK")
//        {
//            alert("已经成功添加到播放列表中..但目前播放器不支持列表.");
//        }
		
   }
}

function operateshare()
{
    if(logined)
        var share=new openTable( "shareDiv" );
    else
        var open = new openTable( "userLogin" );
}

function onShareSubmit(id,type)
{
    share(id,type,"shareDivWord");
    openTable.close(document.getElementById("shareDiv"));
}

function showsharetips()
{
    if(shareres&&!tagres&&!rateres&&!favres)
        showtips();
}

var songid;
function operateSongShare(id)
{
   if(logined)
   {
        songid=id;
        var share=new openTable( "shareSongDiv" );
   }
    else
        var open = new openTable( "userLogin" );
    
}

function operateDown(url)
{
    if(logined)
        location.href=url;
    else
    {
        updateDirectDown();
        var open = new openTable( "userLogin" );
    }
    return false;
}

function updateDirectDown()
{
    var HttpRequest=new HTTPRequest();
    HttpRequest.onresponse=function(res)
    {
    }
     HttpRequest.send("action/updateDirectDown.aspx");
}

function onSongShareSubmit()
{
    share(songid,"Song","shareWordSC");
    openTable.close(document.getElementById("shareSongDiv"));
}

var artistid;
function operateArtistShare(id)
{
   if(logined)
   {
        artistid=id;
        var share=new openTable( "shareDiv" );
   }
    else
        var open = new openTable( "userLogin" );
    
}

function onArtistShareSubmit()
{
    share(artistid,"Artist","shareWord");
    openTable.close(document.getElementById("shareDiv"));
}

function operatereport()
{
    if(logined)
        var error=new openTable("errorDiv");
    else
        var open = new openTable( "userLogin" );
}

function onErrorSubmit()
{
    reportError();
    openTable.close(document.getElementById("errorDiv"));
}

function  upSelfAlbum(sid)
{
    if(logined)
    {
        var HttpRequest=new HTTPRequest();
        HttpRequest.send("action/upSelfalbum.aspx?id="+sid);
        HttpRequest.onresponse=function(res)
        {
            document.getElementById("upvalue").innerHTML=res.responseText;
            document.getElementById("upoperate").innerHTML="<a href='#' style='color:gray'>已顶</a>";
        }
    }
    else
    {
        var open = new openTable( "userLogin" );
    }
}

function setSentToFlashCookie(list,playType)
{
    if(playType)
    {
        setCookie("PlayType","true",24);
    }
    else
    {
        setCookie("PlayType","false",24);
    }
    setCookie("AddPlayList",list,24);
    if(getCookie("player").indexOf("true")>=0)
    {
        if(typeof(openForm)!="undefined")
            openForm.focus();
    }   
}

function setCookie(sName,sValue,oExpires)
{
    var   expire   =   ""; 
    if(oExpires   !=   null)   
    {   
        expire   =   ";   expires="   +   (new Date((new Date()).getTime() + oExpires * 3600000)).toGMTString();   
    }   
    document.cookie   =   sName   +   "="   +   sValue   +   expire ;   
}

function getCookie(sName)
{
    var reg = new RegExp("(^| )"+sName+"=([^;]*)(;|$)","gi");
	var ck = reg.exec(document.cookie);
	if(ck==null||typeof(ck) == "undefined"||ck.length==0)
	    return "false";
	if(ck[2] == null || typeof(ck[2]) == "undefined"||ck[2].length==0) 
	    return "false";
	return ck[2];
}

function playRandom()
{
    var HttpRequest=new HTTPRequest();
    HttpRequest.send("action/createRandomPlayList.aspx");
    HttpRequest.onresponse=function(res)
    {
//        if(res.responseText=="OK")
//        {
//            alert("已经成功添加到播放列表中..但目前播放器不支持播放列表.");
//        }
    }
}
