﻿// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
// obj completion : add par d.guillard le 12/03/2009, par d.guillard
// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
function js_completion(idOfTextBox, afficheNombres)
{

    this.targetId = idOfTextBox;
    this.withNumbers = afficheNombres;

    // Met à jour l'affichage de la liste de choix
    this.refresh = function(str_recherche)
    { 
	    var refreshCompletionByXHR;
	    refreshCompletionByXHR = new httpRequest("/ajax/ajax_Tags.aspx", "action=3&withNumbers=" + this.withNumbers + "&str_recherche=" + str_recherche, "get");
	    refreshCompletionByXHR.createRequestObject();
	    refreshCompletionByXHR.sendPostReq();

	    refreshCompletionByXHR.xmlhttp.onreadystatechange = function ()
	    {
		    if (refreshCompletionByXHR.xmlhttp.readyState == 4) /* 4 : état "complete" */
		    {
                document.getElementById('completion_list').innerHTML = refreshCompletionByXHR.xmlhttp.responseText;

                // on affiche ou masque la liste de complétion
                //if (document.getElementById('completion_list').innerHTML != '')                
                if (document.getElementsByTagName('dl').length > 0)
                {
                    currentCompletion.set_toVisible();
                }else{
                    currentCompletion.set_toHidden();
                }
		    }
	    }
	}
	
	// Change la class d'un élément dl
	this.setClass = function(id_selected, nameOfClass)
	{
	    document.getElementById('dl_' + id_selected).className = nameOfClass;
	}
	
	// Fait disparaitre la liste
	this.set_toHidden = function()
	{
	    document.getElementById('completion_list').style.visibility = 'hidden';
	}
	
	// Fait apparaître la liste
	this.set_toVisible = function()
	{
	    document.getElementById('completion_list').style.visibility = 'visible';
	}
	
	// Remplit l'input text avec le choix sélèctionné
	this.select = function(valueSelected)
	{
        document.getElementById(this.targetId).value = valueSelected;
	}
}

/* tmp */
function sort_cloud_tag(cur_sort)
{
    var refreshCloudTagByXHR;
    refreshCloudTagByXHR = new httpRequest("/ajax/ajax_Tags.aspx", "action=4&cur_sort=" + cur_sort, "get");
    refreshCloudTagByXHR.createRequestObject();
    refreshCloudTagByXHR.sendPostReq();

    refreshCloudTagByXHR.xmlhttp.onreadystatechange = function ()
    {
	    if (refreshCloudTagByXHR.xmlhttp.readyState == 4) /* 4 : état "complete" */
	    {
            document.getElementById('cloud_tag').innerHTML = refreshCloudTagByXHR.xmlhttp.responseText;
	    }
    }
}

function check_affiche_btnAddTag(typeOfObj,this_id_obj,thisTag)
{
    if (trim(thisTag) != '')
    {
	    var addTagByXHR;
    	
	    addTagByXHR = new httpRequest("/ajax/ajax_Tags.aspx", "action=1&thisTag=" + thisTag + "&typeOfObj=" + typeOfObj + "&this_id_obj=" + this_id_obj, "get");
	    addTagByXHR.createRequestObject();
	    addTagByXHR.sendPostReq();

	    addTagByXHR.xmlhttp.onreadystatechange = function ()
	    {
		    if (addTagByXHR.xmlhttp.readyState == 4) /* 4 : état "complete" */
		    {
            document.getElementById('show_tags_in_BO').innerHTML = addTagByXHR.xmlhttp.responseText;
		    }
	    }
	} else {
	    alert('D\351sol\351, vous ne pouvez pas ajouter un "Mot cl\351" vide');
	}
}