function load_player(SongID)
{
        if(document.getElementById("DivPlayer"))
        {
        var xmlHttp=GetXmlHttpObject();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==1)
                {
                        document.getElementById("DivPlayer").innerHTML='<div style="padding:20px 40px;color:#008000;font-size:20px"> Đang tải dữ liệu <img src="http://phanvien.com/templates/phanvien/images/waiting.gif"></div>';
                }
                else if (xmlHttp.readyState==4)
                {
                        document.getElementById("DivPlayer").innerHTML=xmlHttp.responseText;
                }

        }
        xmlHttp.open("GET","/ajax_get_player.php?song="+SongID);
        xmlHttp.send(null);
        }
}
function GetXmlHttpObject()
{
        var xmlHttp=null;
        try
        {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
                // Internet Explorer
                try
                {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
        }
        return xmlHttp;
}
function RateSong(song,point)
{
        if(confirm("Are you sure rating this song with points are "+point))
        {
                var xmlHttp=GetXmlHttpObject();
                xmlHttp.onreadystatechange=function()
                {
                        if (xmlHttp.readyState==4)
                        {
                                window.location.reload();
                        }

                }
                if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/html');}
                var parameters='song='+song+'&point='+point;
                xmlHttp.open("POST","/ajax_rate_song.php",true);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", parameters.length);
                xmlHttp.setRequestHeader("Connection", "close");
                xmlHttp.send(parameters);
        }
}
function UpdateSongViews(song)
{
        var xmlHttp=GetXmlHttpObject();
        if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/html');}
        var parameters='song='+song;
        xmlHttp.open("POST","/ajax_update_song_views.php",true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", parameters.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(parameters);
}
function UpdateArtistViews(artist)
{
        var xmlHttp=GetXmlHttpObject();
        if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/html');}
        var parameters='artist='+artist;
        xmlHttp.open("POST","/ajax_update_artist_views.php",true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", parameters.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(parameters);
}
function DeleteMediaLink(link,src)
{
        if(confirm("Are you sure you want to delete this media link?"))
        {
                var xmlHttp=GetXmlHttpObject();
                if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/html');}
                var parameters='media='+link;
                xmlHttp.onreadystatechange=function()
                {
                        if (xmlHttp.readyState==4)
                        {
                                if(xmlHttp.responseText=='0')
                                {
                                        alert('Sorry! You do not have permission to delete this media link!');
                                }
                                else if(xmlHttp.responseText=='1')
                                {
                                        alert('This media link was deleted!');
                                        src.parentNode.parentNode.removeChild(src.parentNode);
                                }
                        }

                }
                xmlHttp.open("POST","/ajax_delete_media_link.php",true);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", parameters.length);
                xmlHttp.setRequestHeader("Connection", "close");
                xmlHttp.send(parameters);

        }
}
function AddMediaLink(song)
{
        if(document.getElementById("InputMediaUrl"))
        {
                var MediaUrl=document.getElementById("InputMediaUrl").value;
                if(MediaUrl.length<10) {alert("The media URL is too short!");document.getElementById("InputMediaUrl").focus();}
                else if(((MediaUrl.split(":")[0])!='http') & ((MediaUrl.split(":")[0])!='https')& ((MediaUrl.split(":")[0])!='mms')) {alert('Please include a valid URL prefix! Ex: http:// or mms://');document.getElementById("InputMediaUrl").focus();};
                else if(confirm("Are you sure you want to submit this media link\n"+document.getElementById("InputMediaUrl").value))
                {
                        var xmlHttp=GetXmlHttpObject();
                        if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/html');}
                        var parameters='song='+song+'&url='+encodeURIComponent(MediaUrl);
                        xmlHttp.onreadystatechange=function()
                        {
                        if (xmlHttp.readyState==4)
                        {
                                if(xmlHttp.responseText=='1')
                                {
                                        alert('Your media link was added successfully!');
                                        document.getElementById("InputMediaUrl").value='';
                                        window.location.reload();
                                }
                                else
                                {
                                        alert("Sorry! This URL was in our database!");
                                }
                        }

                        }
                        xmlHttp.open("POST","/ajax_add_media_link.php",true);
                        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xmlHttp.setRequestHeader("Content-length", parameters.length);
                        xmlHttp.setRequestHeader("Connection", "close");
                        xmlHttp.send(parameters);

                }
        }
}
function SubmitSongLyric()
{
        if(document.getElementById("DivSubmitSong"))
        {
                var xmlHttp=GetXmlHttpObject();
                xmlHttp.onreadystatechange=function()
                {
                        if (xmlHttp.readyState==4)
                        {
                                document.getElementById("DivSubmitSong").innerHTML=xmlHttp.responseText;

                        }

                }
                xmlHttp.open("GET","/ajax_submit_song.php",true);
                xmlHttp.send(null);

        }
}
function SubmitSongButton()
{
        if(document.getElementById("DivSubmitSong"))
        {
                var xmlHttp=GetXmlHttpObject();
                var parameters='SongTitle='+encodeURIComponent(document.FormSubmitSong.SongTitle.value)+'&ArtistName='+encodeURIComponent(document.FormSubmitSong.ArtistName.value)+'&SongLangID='+encodeURIComponent(document.FormSubmitSong.SongLangID.value)+'&SongLyric='+encodeURIComponent(document.FormSubmitSong.SongLyric.value);
                xmlHttp.onreadystatechange=function()
                {
                        if (xmlHttp.readyState==1)
                        {
                                document.FormSubmitSong.Submit.value="Sending data";
                                document.FormSubmitSong.Submit.disabled=true;
                        }
                        if (xmlHttp.readyState==4)
                        {
                                document.getElementById("DivSubmitSong").innerHTML=xmlHttp.responseText;
                        }

                }
                xmlHttp.open("POST","/ajax_submit_song.php",true);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", parameters.length);
                xmlHttp.setRequestHeader("Connection", "close");
                xmlHttp.send(parameters);

        }
}
function GetRelevanceSongTitle()
{
        if(document.getElementById("DivRelevanceSongTitle"))
        {
                var xmlHttp=GetXmlHttpObject();
                xmlHttp.onreadystatechange=function()
                {
                        if (xmlHttp.readyState==4)
                        {
                                document.getElementById("DivRelevanceSongTitle").innerHTML=xmlHttp.responseText;

                        }

                }
                xmlHttp.open("GET","/ajax_get_rel_song.php?song="+encodeURIComponent(document.FormSubmitSong.SongTitle.value),true);
                xmlHttp.send(null);
        }
        else
        {
                alert("Not found DivRelevanceSongTitle ID");
        }
}