$j(document).bind("ready", function(){
        $j('#filetitle').change(function(){
                testBlaz();
        });
        $j('#containerid').change(function(){
                testCat();
        });
});     

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

//test blaz son
function validUpload() {
       testCat();
       testBlaz();
       if(formOk) {
            $j('.envoie').hide();
            s2tLog('-- Valid Upload');
            return true;
        } else {
            s2tLog('-- Not Valid Upload');
            return false; 
        }
}

function testCat() {
    cat = $j('#containerid').attr('value');
    if(cat == 2 || cat == 18 || cat == 3){
        $j('#containerid').css({background:'#BF3730'})
        s2tLog('*Sound Container Ko*'); 
        formOk = false;
                
    } else {
        s2tLog('*Sound Container Ok*'); 
        $j('#containerid').css({background:'#00CC00'})
        formOk =  true; 
    }

}
function testBlaz() {
        blaz = $j('#filetitle').attr('value')
        if(blaz=='') {
                     $j('#filetitle').css({background: '#BF3730'});
                     return false;
                     }
        jQuery.ajax({
                    type: "GET",
                    url: "/index2.php",
                    data: "option=com_ajax&task=validSoundName&soundName=" + blaz,
                    success: function(msg){
                            if(msg=="1") { 
                               $j('#filetitle').css({background: '#BF3730'});
                               s2tLog('*Sound Name Ko*');
                                 formOk =  false;
                            } else {
                               s2tLog('*Sound Name Ok*');
                               $j('#filetitle').css({background: '#00CC00'});
                               formOk =  true;
                                 
                            }
                    }
   });


}
// record de playlist :
function recordplaylist(iduser,idson) {
if(confirm("es-tu sur de vouloir ajouter ce son à ta playlist ?")){
jQuery.ajax({
    type: "POST",
    url: "/index2.php?",
    data: "option=com_playlists&task=record&iduser="+iduser+"&idson="+idson,
    success: function(msg){

        alert(msg);
    }
});
}
}


// record de playlist de son a ecouter :

function recordplaylistsae(iduser,idson) {
if(confirm("es-tu sur de vouloir ajouter ce son à ta liste de son à écouter ?")){
jQuery.ajax({
    type: "POST",
    url: "/index2.php?",
    data: "option=com_playlists&task=recordsae&iduser="+iduser+"&idson="+idson,
    success: function(msg){

        alert(msg);
    }
});}
}

// record de playlist de son a ecouter :

function recordplaylistcontacts(iduser,idson) {
if(confirm("es-tu sur de vouloir envoyer ce son à tous tes contacts ?")){
jQuery.ajax({
    type: "POST",
    url: "/index2.php?",
    data: "option=com_playlists&task=recordcontacts&iduser="+iduser+"&idson="+idson,
    success: function(msg){

        alert(msg);
    }
});}}


// delete de la playlist :

function deletefromplaylist(id) {
if(confirm("es-tu sur de vouloir supprimer ce son de ta playlist ?")){
jQuery.ajax({
    type: "POST",
    url: "/index2.php?",
    data: "option=com_playlists&task=removeplaylistsrecord&id="+id,
    success: function(msg){
            //window.location.reload()
        //alert(msg);
    }

});}}

// delete de la playlist a écouter :

function deletefromplaylistae(id) {
if(confirm("es-tu sur de vouloir supprimer ce son de ta liste de son à écouter ?")){
jQuery.ajax({
    type: "POST",
    url: "/index2.php?",
    data: "option=com_playlists&task=removeplaylistsaerecord&id="+id,
    success: function(msg){
            //window.location.reload()
        //alert(msg);
    }

});}}

