function toggleDisplay(id) {
	var div = document.getElementById('list-'+id)
	var img = document.getElementById('image-playlist-'+id)

	if( div.style.display == "none" ) {
    div.style.display = "block";
    img.src = '/images/playButtons/medium-white-whiteBck90.gif'
  } else {
    div.style.display = "none"; 
    img.src = '/images/playButtons/medium-white-whiteBck.gif'
  }
}

function toggleDisplayListState(control, value, id_element_toggle){
    element_toggle = document.getElementById(id_element_toggle)
	if (control.checked == value){
	 element_toggle.style.display = "block";
	}else{
	 element_toggle.style.display = "none";
	}
}


function toggleDisplayList(is_hide, id_list, id_button_open, id_button_close){
  if (is_hide) {
    document.getElementById(id_list).style.display = 'block'
    document.getElementById(id_button_open).style.display = 'none'
    document.getElementById(id_button_close).style.display = 'block'
  } else {
    document.getElementById(id_list).style.display = 'none'
    document.getElementById(id_button_open).style.display = 'block'
    document.getElementById(id_button_close).style.display = 'none'
  }
}

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function open_download(id){
  url = '/single/download/'+id;
  location= url
}

function openVideo(url) {
  var video_popup = window.open('url', 'video_mX3_v1', 'toolbar=0,menubar=0,location=0,scrollbars=0,width=660,height=405,resizable=no');  

   video_popup.location=url;	
   if (video_popup.opener == null){
      video_popup.opener = window;
   }
   video_popup.opener_name = 'parent_mx3'
   window.name = 'parent_mx3'
	 video_popup.focus();  
}

function openPopup(url,xml,add_to_playlist) {
  var  player_popup = window.open('', 'player_mX3_v1', 'toolbar=0,menubar=0,location=0,scrollbars=0,width=350,height=360,resizable=no');  
	
	if (player_popup.document.getElementById('flashcontent') == null){
	   player_popup.location=url+'?xml='+xml;
	} else {
		player_popup.addToPlaylist(xml);
	}
	
  if (player_popup.opener == null){
     player_popup.opener = window;
  }

  player_popup.opener_name = 'parent_mx3'
  window.name = 'parent_mx3'
	player_popup.focus();
}

function set_local(url){ 
  if (url.search("=") > -1) {
    window.location = url+"&url="+window.location;
  } else {
    window.location = url+"?url="+window.location;
  }
  
}

function player_play(CONTROL){
  CONTROL.opener=null;
  CONTROL.close();
  /*CONTROL.open('','player_config','').close();*/
  openPopup('/playlist/player','/playlist/listen_personal',true);
}

function close_player_config(CONTROL){
  CONTROL.opener=null;
  CONTROL.close();
}

function open_player_config(){
   url = "/playlist/player_config";
   var  player_popup = window.open(url, 'mx3PlayerConfiguration', 'toolbar=0,menubar=0,location=0,scrollbars=0,width=350,height=360,resizable=no');
   
   player_popup.opener_name = 'parent_mx3'
   window.name = 'parent_mx3'
	 player_popup.focus();
}

var arrOldValues;

function SelectAllList(CONTROL){

  for(var i = 0;i < CONTROL.length;i++){
    CONTROL.options[i].selected = true;
  }

}

function DeselectAllList(CONTROL){
  for(var i = 0;i < CONTROL.length;i++){
    CONTROL.options[i].selected = false;
  }
}


function FillListValues(CONTROL){
/*
  var intNewPos;
  var arrNewValues;
  var strTemp = GetSelectValues(CONTROL);
  arrNewValues = strTemp.split(",");

  for(var i=0;i<arrNewValues.length-1;i++){
    if(arrNewValues[i]==1){
      intNewPos = i;
    }
  }
  */
  var intNewPos = CONTROL.selectedIndex;

  for(var i=0;i<arrOldValues.length-1;i++){
    if(i != intNewPos){
      if(arrOldValues[i]==1){
        CONTROL.options[i].selected= true;
      }
      else {
        CONTROL.options[i].selected= false;
      }
    }
    
  }
 
  if(arrOldValues[intNewPos]== 1){
    CONTROL.options[intNewPos].selected = true;
    CONTROL.options[intNewPos].selected = false;
  }
  else{
    CONTROL.options[intNewPos].selected = false;
    CONTROL.options[intNewPos].selected = true;
  }
 
}


function GetSelectValues(CONTROL){
  var strTemp = "";
  for(var i = 0;i < CONTROL.length;i++){
    if(CONTROL.options[i].selected == true){
      strTemp += "1,";
    }else{
      strTemp += "0,";
    }
  }
  
  return strTemp;
}

function GetCurrentListValues(CONTROL){
  var strValues = "";
  strValues = GetSelectValues(CONTROL);
  arrOldValues = strValues.split(",");
}

function checkform(msg_composer, msg_lyrics_writer, msg_legal_term, msg_title, msg_song, msg_url, msg_image, is_edition)
{
  var msg = ''
  
	if (!is_edition && document.single_edit.single_terms_of_legal.checked == false){
		msg += msg_legal_term+'\n';
	}
	
  if (document.single_edit.single_composer.value == ""){
		msg += msg_composer+'\n';
	}

  if (document.single_edit.single_lyrics_writer.value == ""){
		msg += msg_lyrics_writer+'\n';
	}

  if (document.single_edit.single_title.value == ""){
		msg += msg_title+'\n';
	}
	
  if ((!is_edition && document.single_edit.single_song.value != "" && document.single_edit.single_song.value.search('\.mp3|\.MP3')== -1)){
		msg += msg_song + '\n';
	}
	
  var myRegExp1 = "\.jpg|\.JPG|\.jpeg|\.JPEG";

	if (!document.single_edit.single_image.value == "" && document.single_edit.single_image.value.search(myRegExp1)== -1 ){
		msg += msg_image+'\n';
	}
	
	if (msg == '') {
		return true;
	}	else {
	  Element.hide('spinner_bar_singles');
	  alert(msg);
	 
	  return false;
	}
}

function check_type_link(CONTROL,id){
  if (CONTROL.value == 'Autres'){
    Element.show(id);
  }else{
    Element.hide(id);
  } 
}

function disableEnterOnTagsInput(e) {
  var key;
  
  if (window.event) {
    key = window.event.keyCode;  // ie
  } else {
    key = e.which;               // firefox
  }
  
  if (key == 13) {
    return false;
  } else {
    return true;
  }
}