var updated_row = new Array;
var actual_target = null;

var actual_selected_menus_id_menus = '';
var actual_selected_menus_onmouseover = '';
var actual_selected_menus_onmouseout = '';
// patch anti touche 'entrée'

var toucheDesac=255; //la touche 255 est inusitée ; touche enter = 13
var gk=window.Event?1:0;

function toucheenter(e) {
        var touche=gk?e.which:window.event.keyCode; //pour compatibilité FF IE
        if (touche == toucheDesac){
                return false;
        }
}

function is_array(input)
{
        return typeof(input)=='object'&&(input instanceof Array);
}
function creerElement(type, id, classe, texte){
        var elt = document.createElement(type);
        if(id)
                elt.id = id;
        if(classe)
                elt.className = classe;
        if(texte)
                elt.appendChild(document.createTextNode(texte));
        return elt;
}

// permet d'executer une methode dans un certain contexte
// instance : le context
// methode : la methode a appeler
function createDelegate(instance, methode) {
        // fonction anonyme
        return function(){
                // arguments parametres passe a la fonction anonyme
                return methode.apply(instance, arguments);
        }
}

function dump_element(element)
{
attributes_list = '';
for(attributes in element)
        attributes_list+=attributes+' = '+element[attributes];
return(attributes_list);
//return true;
}
function dump_element_for_context(element)
{
var target = element.target || element.srcElement;
new_target = document.getElementById(target['attributes'].getNamedItem('id').value);
//alert(new_target.value);
attributes_list = new Array();
nb_attributes = new_target['attributes'].length;
for(i=0;i<nb_attributes;i++)
{
        attributes_list[i] = new_target['attributes'].item(i).nodeName +'='+encodeURIComponent(new_target['attributes'].item(i).nodeValue);
}
attributes = attributes_list.join('&');
return(attributes);
//return true;
}
function dump_element_attributes(element)
{
var target = element;
attributes_list = new Array();
nb_attributes = target['attributes'].length;
for(i=0;i<nb_attributes;i++)
{
        attributes_list[i] = target['attributes'].item(i).nodeName +' = '+target['attributes'].item(i).nodeValue;
}
attributes = attributes_list.join('&');
return(attributes);
//return true;
}

function element_click(e)
{
//        if(blabla) alert(blabla);
        if (!e) var e = window.event;
        var target = e.target || e.srcElement;
//      alert('dedans');

//        if(!target.attributes['type']) target = target.parentNode;
//        alert(dump_element_attributes(target.parentNode));
        if((e['button'] == 0) && (target.attributes['type']))
        {
//                alert(target['attributes'].getNamedItem('type').value);
                switch(target['attributes'].getNamedItem('type').value)
                {
                        case 'led':
                                set_updated_row(target);
                                led_image_value = target.getAttribute('value');
                                if(led_image_value == '0')
                                {
                                        target.src = 'images/red-on.gif';
                                        target.setAttribute('value','1');
                                }
                                else
                                {
                                        target.src = 'images/green-off.gif';
                                        target.setAttribute('value','0');
                                }
                                return false;
                                break;
                        case 'input_text':
                //              target.innerHTML = prompt('Entrez une valeur',target.innerHTML);
                //              java_prompt('Veuillez entrer une valeur',target.innerHTML,'integer',3);

                                if(window.actual_target)
                                {
                                        window.actual_target.blur();
                                        while(window.actual_target != null);
                                }
                                var temp = creerElement('input',target.getAttribute('id'),'input_box');
                                temp.setAttribute('type','text');
                                temp.setAttribute('size','3');
                                temp.setAttribute('maxlength','3');
                                temp.value= target.getAttribute('value');

                                window.actual_target = temp;

                                if (document.addEventListener){
                                        temp.addEventListener('keypress', element_keypress, false);
                                        temp.addEventListener('blur', set_element_back, false);
                                } else if (document.attachEvent){
                                        temp.attachEvent('onkeypress', element_keypress);
                                        temp.attachEvent('onblur', set_element_back);
                                }

                                parent_node = target.parentNode;
                                parent_node.removeChild(parent_node.firstChild);
                                parent_node.appendChild(temp);
                                temp.focus();
                                return false;
                                break;
                        case 'supprimer':
                                yes_no = confirm('Voulez vous vraiment supprimer cet élément?');
                                if(yes_no == true)
                                {
                                        document.location.replace(target.getAttribute('href'));
                                }

                                break;
                        case 'releve':
                        case 'affiche':
                        case 'modifier':
                        case 'selectionner':
                        case 'change_loggin':
                        case 'stats':
                        case 'link':
                                //alert(target.getAttribute('href'));
                                //document.location.replace(target.getAttribute('href'));
                                top.bar_onglets_navigation.add_onglet(target.getAttribute('href'),'',true,target.getAttribute('new_page_title'),false,eval(target.getAttribute('calling_document_handler')));
                                break;
                        case 'up_arrow':
                                //il faut rechercher dans le DOM le noeud de la ligne qui contient la cellule actuelle
                                //il faut rechercher le noeud du premier TR dans le tableau
                                //il faut rechercher tout les éléments IMG dans la ligne en cour
                                //il faut rechercher les images qui ont pour attribut 'final' value
                                //il faut changer la valeur final_value-- (on remonte dans le tableau)
                                //il faut rechercher tout les éléments IMG dans la ligne précédente
                                //il faut rechercher les images qui ont pour attribut 'final' value
                                //il faut changer la valeur final_value = actual_value

                                parent_node = target.parentNode;

                                if(!parent_node.parentNode){
                                        //alert('pas de parent');
                                        //alert(dump_element(parent_node));
                                        return true;
                                }
                                index = 0;
                                //on recherche le noeud TR de la ligne en cour
                                while(parent_node.nodeName != 'TR')
                                {
                                        //alert(index);
                                        parent_node = parent_node.parentNode;
                                        index ++;
                                        if((!parent_node.parentNode) || (index == 10))
                                        {
                                                return false;
                                        }
                                        //alert(parent_node.nodeName);
                                }
                                // On sauvegarde le pointeur de la ligne en cour
                                actual_line = parent_node;
                                //alert(parent_node.nodeName);

                                // on récupère le pointeur sur l'objet TBODY
                                tbody = actual_line.parentNode;
                                index = 0;
                                if(!tbody.firstChild)
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                first_row = tbody.firstChild;

                                // on recherche le premier TR du tableau
                                for(i = 0;i < 2;i++)
                                {
                                        while(first_row.nodeName != 'TR')
                                        {
                                                if(!first_row.nextSibling)
                                                {
                                                        //alert('on sort');
                                                        return false;
                                                }
                                                first_row = first_row.nextSibling;
                                                index ++;
                                                if(index == 10)
                                                {
                                                        //alert('on sort');
                                                        return false;
                                                }
                                        }
                                        // au premier passage, first_row contient le noeud de l'entête du tableau. Il faut aller un TR plus loin pour trouver la première ligne
                                        //alert(dump_element(first_row));
                                        if(i<1){
                                                if(!first_row.nextSibling)
                                                {
                                                        //alert('on sort');
                                                        return false;
                                                }
                                                first_row = first_row.nextSibling;
                                        }
                                        //return true;
                                }
                                if(actual_line == first_row)        // si la ligne en cour est la première, du tableau, on sort.
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                //alert(parent_node);
                                //return true;

                                // bon, maintenant que l'on sait que ce n'est pas la prmière du tableau, il faut aller chercher la ligne précédente
                                index = 0;

                                if(!parent_node.previousSibling)
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                parent_node = parent_node.previousSibling;
                                while(parent_node.nodeName != 'TR')
                                {
                                        //alert(index);
                                        if(!parent_node.previousSibling)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                        parent_node = parent_node.previousSibling;
                                        index ++;
                                        if(index == 10)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                }
                                //alert(parent_node.nodeName);

                                // on récupère le noeud précédent
                                previous_line = parent_node;

                                actual_value = parseInt(target.getAttribute('final_value'));
                                final_value = (actual_value - 1);

                                // si on arrive jusqu'ici, c'est que tout est bon et que l'on peut appliquer les modifications
                                // on récupère la liste des images de la ligne en cour
                                liste_cells = actual_line.getElementsByTagName('IMG');

                                // on applique la nouvelle valeur seulement si on est sur un objet 'up_arrow' or 'down_arrow'
                                for(cells_index in liste_cells)
                                {
                                        //alert(dump_element(liste_cells[cells_index]));
                                        if((liste_cells[cells_index]['attributes']) && (liste_cells[cells_index]['attributes'].getNamedItem('type')) && ((liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'up_arrow') || (liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'down_arrow')))
                                        {
                                                liste_cells[cells_index].setAttribute('final_value',final_value) ;
                                                //alert(final_value);
                                        }
                                }

                                //même traitement pour la ligne à remplacer
                                liste_cells = previous_line.getElementsByTagName('IMG');

                                // on applique la nouvelle valeur seulement si on est sur un objet 'up_arrow' or 'down_arrow'
                                for(cells_index in liste_cells)
                                {
                                        //alert(dump_element(liste_cells[cells_index]));
                                        if((liste_cells[cells_index]['attributes']) && (liste_cells[cells_index]['attributes'].getNamedItem('type')) && ((liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'up_arrow') || (liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'down_arrow')))
                                        {
                                                liste_cells[cells_index].setAttribute('final_value',actual_value) ;
                                                //alert(actual_value);
                                        }
                                }
                                new_previous = actual_line.cloneNode(true);
                                new_actual = previous_line.cloneNode(true);
                                tbody.replaceChild(new_previous,previous_line);
                                tbody.replaceChild(new_actual,actual_line);
                                //alert(parent_node.previousSibling);
                                //parent_node.parentNode.removeChild(actual_line);
                                //alert('ok');
                                break;
                        case 'down_arrow':
                                //il faut rechercher dans le DOM le noeud de la ligne qui contient la cellule actuelle
                                //il faut rechercher le noeud du dernier TR dans le tableau
                                //il faut rechercher tout les éléments IMG dans la ligne en cour
                                //il faut rechercher les images qui ont pour attribut 'final' value
                                //il faut changer la valeur final_value++ (on descend dans le tableau)
                                //il faut rechercher tout les éléments IMG dans la ligne suivante
                                //il faut rechercher les images qui ont pour attribut 'final' value
                                //il faut changer la valeur final_value = actual_value

                                parent_node = target.parentNode;

                                if(!parent_node.parentNode){
                                        //alert('pas de parent');
                                        //alert(dump_element(parent_node));
                                        return true;
                                }
                                index = 0;
                                //on recherche le noeud TR de la ligne en cour
                                while(parent_node.nodeName != 'TR')
                                {
                                        //alert(index);
                                        parent_node = parent_node.parentNode;
                                        index ++;
                                        if((!parent_node.parentNode) || (index == 10))
                                        {
                                                return false;
                                        }
                                        //alert(parent_node.nodeName);
                                }
                                // On sauvegarde le pointeur de la ligne en cour
                                actual_line = parent_node;
                                //alert(parent_node.nodeName);

                                // on récupère le pointeur sur l'objet TBODY
                                tbody = actual_line.parentNode;
                                index = 0;
                                if(!tbody.lastChild)
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                last_row = tbody.lastChild;

                                // on recherche le dernier TR du tableau
                                while(last_row.nodeName != 'TR')
                                {
                                        if(!last_row.previousSibling)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                        last_row = last_row.previousSibling;
                                        index ++;
                                        if(index == 10)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                }
                                if(actual_line == last_row)        // si la ligne en cour est la dernière, du tableau, on sort.
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                //alert(parent_node);
                                //return true;

                                index = 0;
                                // bon, maintenant que l'on sait que ce n'est pas la dernière du tableau, il faut aller cherche la ligne suivante
                                if(!parent_node.nextSibling)
                                {
                                        //alert('on sort');
                                        return false;
                                }
                                parent_node = parent_node.nextSibling;
                                while(parent_node.nodeName != 'TR')
                                {
                                        //alert(index);
                                        if(!parent_node.nextSibling)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                        parent_node = parent_node.nextSibling;
                                        index ++;
                                        if(index == 10)
                                        {
                                                //alert('on sort');
                                                return false;
                                        }
                                }
                                //alert(parent_node.nodeName);

                                // on récupère le noeud précédent
                                next_line = parent_node;

                                actual_value = parseInt(target.getAttribute('final_value'));
                                final_value = (actual_value + 1);

                                // si on arrive jusqu'ici, c'est que tout est bon et que l'on peut appliquer les modifications
                                // on récupère la liste des images de la ligne en cour
                                liste_cells = actual_line.getElementsByTagName('IMG');

                                // on applique la nouvelle valeur seulement si on est sur un objet 'up_arrow' or 'down_arrow'
                                for(cells_index in liste_cells)
                                {
                                        //alert(dump_element(liste_cells[cells_index]));
                                        if((liste_cells[cells_index]['attributes']) && (liste_cells[cells_index]['attributes'].getNamedItem('type')) && ((liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'up_arrow') || (liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'down_arrow')))
                                        {
                                                liste_cells[cells_index].setAttribute('final_value',final_value) ;
                                                //alert(final_value);
                                        }
                                }

                                //même traitement pour la ligne à remplacer
                                liste_cells = next_line.getElementsByTagName('IMG');

                                // on applique la nouvelle valeur seulement si on est sur un objet 'up_arrow' or 'down_arrow'
                                for(cells_index in liste_cells)
                                {
                                        //alert(dump_element(liste_cells[cells_index]));
                                        if((liste_cells[cells_index]['attributes']) && (liste_cells[cells_index]['attributes'].getNamedItem('type')) && ((liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'up_arrow') || (liste_cells[cells_index]['attributes'].getNamedItem('type').value == 'down_arrow')))
                                        {
                                                liste_cells[cells_index].setAttribute('final_value',actual_value) ;
                                                //alert(actual_value);
                                        }
                                }
                                new_next = actual_line.cloneNode(true);
                                new_actual = next_line.cloneNode(true);
                                tbody.replaceChild(new_next,next_line);
                                tbody.replaceChild(new_actual,actual_line);
                                //alert(parent_node.previousSibling);
                                //parent_node.parentNode.removeChild(actual_line);
                                //alert('ok');
                                break;
                        case 'menus_link':
                                if(actual_selected_menus_id_menus != '')
                                {
                                        former_selected_menus_handler = document.getElementById(actual_selected_menus_id_menus);
                                        former_selected_menus_handler.setAttribute('class',former_selected_menus_handler.getAttribute('basic_class'));
                                        former_selected_menus_handler.setAttribute('onmouseover',actual_selected_menus_onmouseover);
                                        former_selected_menus_handler.setAttribute('onmouseout',actual_selected_menus_onmouseout);

                                }

                                actual_selected_menus_id_menus = target.getAttribute('id');
                                actual_selected_menus_class = target.getAttribute('class');
                                actual_selected_menus_onmouseover = target.getAttribute('onmouseover');
                                actual_selected_menus_onmouseout = target.getAttribute('onmouseout');

                                //alert(actual_selected_menus_id_menus);

                                target.setAttribute('class',actual_selected_menus_class + ' menuok');
                                target.setAttribute('onmouseover',null)
                                target.setAttribute('onmouseout',null)
                                menus_target = target.getAttribute('target');
                                menus_target_handler = document.getElementById(menus_target);
                                menus_target_handler.src = target.getAttribute('href');
                                break;

                        case 'menus_node':
                                //alert('coucou');
                                id_child = target.getAttribute('id_child');
                                toogle_display(id_child);
                                return false;
                                break;
                        case 'text':
                                break;
                        case 'clickable_object':
                                param = dump_element_for_context(e);
                                //alert(param);
                                //return true;
                                var OAjax;
                                if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
                                else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
                                OAjax.open('POST',"context.php",false);
                                OAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                                OAjax.send(param);

                                alert('coucou');

                                if (document.getElementById)
                                {
                                        var array_answer = OAjax.responseText.split(':',2);
                                        if (array_answer[0] =='true') {
                                                var temp = creerElement('div','input_div');
                                                temp.innerHTML = array_answer[1];
                                                alert(temp.innerHTML);//eval(temp.innerHTML);
                                        }else{
                                                //alert('tous les champs requis n\'ont pas été renseignés. Reportez vous au(x) message(s) en bas de cette page pour apporter vos modifications');
                                                target.style.backgroundColor = "red";
                                                document.getElementById('message').innerHTML = OAjax.responseText;
                                                document.getElementById('message').style.visibility = "visible";
                                                //alert(OAjax.responseText);
                                        }
                                }

                                break;

                }
        }
        return true;
}

function element_onmouseover(e)
{
//        alert('coucou');
        if (!e) var e = window.event;
        var target = e.target || e.srcElement;
//      alert('dedans');
        if(target.attributes['type'])
        {
                switch(target.getAttribute('type'))
                {
                        case 'menus_link':
                                menus_class = target.getAttribute('onmouseover_class');
                                target.setAttribute('class',menus_class);
                                break;
                }
        }
        return true;
}

function set_updated_row(target)
{
        var target_id = target.getAttribute('id');
        var target_main_id_array = target_id.split('_');
        var target_main_id = target_main_id_array[(target_main_id_array.length - 1)];
        window.updated_row[target_main_id] = target_main_id;
        return(target_id);
}

function set_element_back(e)
{
        window.actual_target = null;
        var target = e.target || e.srcElement;
        if (document.addEventListener){
                target.removeEventListener('keypress', element_keypress, false);
                target.removeEventListener('blur', set_element_back, false);
        } else if (document.attachEvent){
                target.detachEvent('onkeypress', element_keypress);
                target.detachEvent('onblur', set_element_back);
        }

        var temp = creerElement('div','input_div',null,target.value);
        var target_id = set_updated_row(target);

        temp.setAttribute('type','input_text');
        temp.setAttribute('value',target.value);
        temp.setAttribute('id',target_id);
        temp.setAttribute('class','input_box');
        parent_node = target.parentNode;
        parent_node.removeChild(parent_node.firstChild);
        parent_node.appendChild(temp);
        if (window.event)
                window.event.cancelBubble = true;
        else
                e.cancelBubble = true;
}

function element_keypress(e)
{
        if (!e) var e = window.event;
        // si on appuie sur enter
        var touche = e.which || e.keyCode;
        var target = e.target || e.srcElement;
        if(touche == 13)
        {
                set_element_back(e);
        }
}

function toogle_display(id_element){
        element_handler = document.getElementById(id_element);
        actual_display = element_handler.style.display;
        //alert('bbb'+actual_display);
        element_handler.style.display = ((actual_display == "none")?"block":"none");
}

function set_event_listener(event_name, function_handler,bubbling)
{
        if (document.addEventListener){
        //      alert('FF');
                document.addEventListener(event_name, function_handler, bubbling);
        } else if (document.attachEvent){
        //      alert('IE');
                document.attachEvent('on'+event_name, function_name);
        }

}

if (document.addEventListener){
//      alert('FF');
        document.addEventListener('click', element_click, false);
//        document.addEventListener('mouseover', element_onmouseover, false);
} else if (document.attachEvent){
//      alert('IE');
        document.attachEvent('onclick', element_click);
//        document.attachEvent('onmouseover', element_onmouseover);
}


function add_document_to_select(id_select,document_name,document_title)
{
        if((id_select) && (document.getElementById(id_select)))
        {
                if((document_name) && (document_name != ''))
                {
                        nb_element_into_select_control = document.getElementById(id_select).options.length;
                        document.getElementById(id_select).options[nb_element_into_select_control] = new Option(document_name,nb_element_into_select_control);
                }
        }
}

function remove_document_from_select(id_select)
{
        if((id_select) && (document.getElementById(id_select)))
        {
                selected_index = document.getElementById(id_select).options.selectedIndex;
                if(selected_index == -1)
                {
                        alert('Vous n\'avez pas sélectionné d\'élément dans la liste');
                        return true;
                }

                document.getElementById(id_select).options[selected_index] = null;
        }
        else
        {
                alert('Element inconnu: '+id_select);
        }
}

function control_mail_contact_form()
{
        var email = trim(document.getElementById('email').value);
        if(email != '')
        {
                test_email = new RegExp('^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$');
                if(!email.match(test_email))
                {
                        alert('Email non valide');
                        document.getElementById('email').value = email;
                        document.getElementById('email').focus;
                        return(false);
                }

        }
        else
        {
                alert('Email vide');
                document.getElementById('email').focus;
                return(false);

        }
        var message = trim(document.getElementById('message').value);
        if(message == '')
        {
                alert('Message vide');
                document.getElementById('message').value = message;
                document.getElementById('message').focus;
                return(false);
        }
        input_control = creerElement('input', 'input_control', false, false);
        input_control.setAttribute('type','hidden');
        input_control.setAttribute('name','input_control');
        input_control.setAttribute('value','ok');
        document.getElementById('form1').appendChild(input_control);

        //alert(document.getElementById('input_control').name);
        return(true);
}

function trim (myString)
{
  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function clicMenu(num) {

  // Booléen reconnaissant le navigateur (vu en partie 2)
  isIE = (document.all)
  isNN6 = (!isIE) && (document.getElementById)

  // Compatibilité : l'objet menu est détecté selon le navigateur
  // il faut passer en revue toutes les div 'partie' pour s'assurer qu'elles fermée
  if (isIE)
  {
        menu = document.all['partie' + num];
  }

  if (isNN6)
  {
        menu = document.getElementById('partie' + num);
  }

  // On ouvre ou ferme
  if (menu.style.display == "none"){
        // Si la div était cachée, alors il faut regarder si il n'y en avait pas une d'ouverte
        i=0;
        if (isIE)
        {
                while((document.all['partie' + i]) && (i<100))
                {
                        document.all['partie' + i].style.display = "none";
                        i++;
                        //alert(i);
                }
        }
        if (isNN6)
        {
                while((document.getElementById('partie' + i)) && (i<100))
                {
                        document.getElementById('partie' + i).style.display = "none";
                        i++;
                        //alert(i);
                }
        }
        menu.style.display = ""
  } else {
        // si par contre elle était ouverte, alors on la ferme
        menu.style.display = "none"
   }
}


function select_image(id_image){
        image_pointer = document.getElementById(id_image);
        document.getElementById('image_big').src = image_pointer['attributes'].getNamedItem('normal_path').value;
}

/*
//Generic Drag Script- © Dynamic Drive (www.dynamicdrive.com)
//For full source code and terms of usage,
//visit http://www.dynamicdrive.com

var ie=document.all
var ns6=document.getElementById&&!document.all

var dragapproved=false
var z,x,y

function move(e){
if (dragapproved){
z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x
z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y
return false
}
}

function drags(e){
if (!ie&&!ns6)
return
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "HTML" : "BODY"

while (firedobj.tagName!=topelement&&firedobj.className!="drag"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.className=="drag"){
dragapproved=true
z=firedobj
temp1=parseInt(z.style.left+0)
temp2=parseInt(z.style.top+0)
x=ns6? e.clientX: event.clientX
y=ns6? e.clientY: event.clientY
document.onmousemove=move
return false
}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")*/



function FindPos(AObject)
{
    var posX = 0, posY = 0;

    do
    {
        posX += AObject.offsetLeft;
        posY += AObject.offsetTop;
        AObject = AObject.offsetParent;
    }
    while( AObject != null );

    var pos = [];
    pos['X'] = posX;
    pos['Y'] = posY;

    return pos;
}

//////////////////////////////
// function setAttributeStyle( string style, object_handler object)
//
// auteur: Nicolas LE DREFF
// date: 13/03/2010
//
// cette fonction s'occupe d'appliquer à la volée un style contenu dans une chaine de caractère.
// Sous IE6, la méthode setAttribute('style','height:100%') n'est pas permise. Il faut passer par object.style.height = '100%'.
// usage :
// my_div_handler = getElementById('my_div');
// setAttributeStyle( 'height:100%;font-weigth:bold;line-height:16px;text-color:red', my_div_handler);


function setAttributeStyle( style, object)
{
        if((!style) || (style == ''))
        {
                return false;
        }
        object.setAttribute('style',style);      // d'abord on applique avec la méthode récente
        if(!object.attributes.getNamedItem('style').nodeValue)    // si malgré celà, la propriété style vaut 'null'
        {
                //alert('start');
                var style_reg = new RegExp("[;]+", "g");           // on recherche les ';'
                var tableau_attributes = style.split(style_reg);    // on explose le style avec l'expression régulière
                for (var i=0; i<tableau_attributes.length; i++) {    //on passe en revue les != éléments
                        //alert('dans boucle for');
                        // on retire les espace superflus
                        tableau_attributes[i] = tableau_attributes[i].replace(/^\s+/g,'').replace(/\s+$/g,'');
                        var attributes_reg = new RegExp("[:]+", "g");   // on recherche les ':'
                        tableau_attribute_value = tableau_attributes[i].split(attributes_reg); // on explose
                        attribute_name = tableau_attribute_value[0];   // le premier élément est le nom de l'attribut
                        var attributes_name_reg = new RegExp("[-]+", "g");  // on recherche les '-'
                        tableau_attribute_name = attribute_name.split(attributes_name_reg);   // on explose

                        if(tableau_attribute_name.length > 1)   // si le tableau a plus d'1 élément, il y avait 1 '-'
                        {
                                // on passe en majuscule l'initiale du 2ème morceau
                                initiale_attribute_name = tableau_attribute_name[1].substr(0,1).toUpperCase();
                                // on remet tout dans la bonne boite
                                tableau_attribute_name[1] = initiale_attribute_name + tableau_attribute_name[1].substr(1,(tableau_attribute_name[1].length -1));
                                attribute_name = tableau_attribute_name.join('');  // on ré-assemble les deux morceaux
                        }
                        attribute_value =  tableau_attribute_value[1];  // la valeur de l'attribut
                        //alert(attribute_name + ' = ' + attribute_value);
                        object.style[attribute_name] = attribute_value;   // application de l'attribut
                }
                //alert('fin boucle for');
        }
        //alert('end');
        return true;

}



