// Fonction d'activation de vote
function actiVote( id, url, votes, date_debut, type ) {
  // Initialisation
  var getvars = "?id="+id+"&date_debut="+date_debut+"&type="+type;
  // Chargement des données

    var xhr_object = new XHR({
        method: 'get',
	    onSuccess: function(req) {
            // Cas où les données ont été chargées
            if (this.response.text == "activate" ) {
              // Activation du vote
              for ( i = 0; i < votes.length; i++ ) {
                $('vote_' + votes[i]).setStyle('display','');
              }
              // Suppression du dernier élément temporaire
              votes.pop();
            }
          } }).send(url+getvars);
}

// Fonction de détection d'email existant
function checkEmail( email, parent_node_id, url, elt ) {
  // Initialisation
  var xhr_object = null;
  var url        = url+"?parent_node_id="+parent_node_id+"&email="+email;

  // Désactivation immédiate du bouton submit en attendant le résultat
  document.getElementById( 'PublishButton' ).disabled = true;


  if ( window.XMLHttpRequest ) {
    xhr_object = new XMLHttpRequest();
  } else {
    if ( window.ActiveXObject ) {
      xhr_object = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
  }

  // Chargement des données
  xhr_object.open( "GET", url, true );
  xhr_object.onreadystatechange = function() {
    // Cas où les données ont été chargées
    if ( xhr_object.readyState == 4 ) {
      if ( xhr_object.responseText != "0" ) {
        // Message d'erreur
        alert( "Электронный адрес, который вы указали, уже используется!" );
        elt.style.backgroundColor = "#ccc";
      } else {
        // Réactivation du bouton submit
        document.getElementById( 'PublishButton' ).disabled = false;
        elt.style.backgroundColor = "";
      }
    }
  }

  xhr_object.send(null);
}

// Fonction de gestion du vote
function doVote( value, votes, vote_value, first ) {
  // Enregistrement de la réponse
  $( vote_value ).value = value;

  // Désactivation des boutons
  for ( i = 0; i < votes.length; i++ ) {
    $( 'vote_'+votes[i] ).style.display = 'none';
  }
  $( 'vote_'+first ).style.display = 'none';
  
  var postVars= "parent_contentobject_id=" + $( vote_value+'_parent_contentobject_id' ).value + "&class_identifier=" + $( vote_value+'_class_identifier' ).value + "&date_debut=" + $( vote_value+'_date_debut' ).value + "&date_fin=" + $( vote_value+'_date_fin' ).value + "&vote=" + $( vote_value ).value + "&redirection=" + $( vote_value+'_redirection' ).value;

  var ajaxLayer = $('ajax_' + vote_value);
  ajaxLayer.setHTML('<div style="margin-left:100px;margin-top:30px;"><img src="/extension/gal/design/gal_rus-RU/images/loading_star.gif" style="border:0;" /></div><div class="divfix"</div>');
  new Ajax( $("form_" + vote_value).action ,{
                'postBody':postVars
                ,'update': ajaxLayer
                ,'method':'post'
                ,'evalScripts':true}).request();
}

// Fonction de chargement des Top & Toc
var processAjaxTopToc = function( node_path, layer_ajax, date_vote, votes, classement ){
    var lLayerAj = $(layer_ajax);
    if (lLayerAj){
        lLayerAj.setHTML('<div style="margin-left:100px;margin-top:30px;"><img src="/extension/gal/design/gal_rus-RU/images/loading_star.gif" style="border:0;" /></div><div class="divfix"</div>');
    }
    node_path += '/(date_vote)/'+date_vote+'/(votes)/'+votes+'/(classement)/'+classement;
    new Ajax(node_path,{'postBody':'node_path='+node_path,'update': layer_ajax,'method':'get','evalScripts':true}).request();
}