
/**
 * @version $Id: maj_playlist.js,v 1.7 2010-01-21 17:41:02 dsp Exp $
 * @package cjv
 * @copyright Copyright (C) 2008 BROCELIA. All rights reserved.
 */

window.addEvent('domready', function(){

    // version checkbox
	$$('.upl_play_with').each(function(el){
        el.addEvent('change', function(){
        	new Request({method: 'get', url:'{/literal}{$WWW_URL}{literal}', onSuccess:traitement}).send('do=communaute/profil/majplaylist&upl_play_with='+el.value, '');
        });
    });

    $$('.upl_own').each(function(el){
        el.addEvent('change', function(){
        	new Request({method: 'get', url:'{/literal}{$WWW_URL}{literal}', onSuccess:traitement}).send('do=communaute/profil/majplaylist&upl_own='+el.value, '');
        });
    });

    $$('.upl_info').each(function(el){
        el.addEvent('change', function(){
        	new Request({method: 'get', url:'{/literal}{$WWW_URL}{literal}', onSuccess:traitement}).send('do=communaute/profil/majplaylist&upl_info='+el.value, '');
        });
    });

    $$('.upl_look_for').each(function(el){
        el.addEvent('change', function(){
        	new Request({method: 'get', url:'{/literal}{$WWW_URL}{literal}', onSuccess:traitement}).send('do=communaute/profil/majplaylist&upl_look_for='+el.value, '');
        });
    });

    $$('.upl_supprimer').each(function(el){
        el.addEvent('click', function(e){
        	new Request({method: 'get', url:'{/literal}{$WWW_URL}{literal}', onSuccess:traitement}).send('do=communaute/profil/majplaylist&upl_supprimer='+el.title, '');
        	$('ligne_'+el.title).destroy();
        	new Event(e).stop();
        });
    });

    // version liens
	link_ajout_playlist();
});



function traitement(text, xml)
{
 	var tabcontent = text.split('||');
 	if(tabcontent[0] == "redirect")
 	{
 		window.location.replace(tabcontent[1]);
 		return 1;
 	}
 	return 0;
}

function confirmation(text){
 	if (text == "ok1")
		alert("Ce jeu est déjà présent dans votre playlist","Ajouter un jeu");
	else if (text == "ok2")
		alert("Ce jeu a bien été ajouté à votre playlist","Ajouter un jeu");
	else if (!traitement(text))
		alert("Une erreur s'est produite","Ajouter un jeu");
}

function link_ajout_playlist(){
	 $$('.upl_link').each(function(el){
	     el.onclick=function(){
	 	 	my_href = el.href;
	     	new Request({method: 'get', url:my_href, async:false, onSuccess:function(text, xml){confirmation(text);}}).send();
	    	return false;
	     };
	 });
}
