// --------------------------------------------------------------------------------
//                                   Class MenuItem
// --------------------------------------------------------------------------------


function mi_toHtmlString(mnId)
{
var str = new String();

/* GOLD by Action
str = " class='menuItem' OnMouseOver='_overMenuItem(this)' OnMouseOut='_outofMenuItem(this)' onclick='_clickedMenuItem(\""+ mnId +"\", this); eval(\""+this.action+"\");'>"+
this.label;//+"</td></tr>"
*/

/* GOLD by user actionA
str = " class='menuItem' OnMouseOver='_overMenuItem(this)' OnMouseOut='_outofMenuItem(this)' onclick='_clickedMenuItem(\""+ mnId +"\", this);'>"+
this.action;//+"</td></tr>"
*/

// GOLD by engine action A HREF
str = ">"+ // fin du td ouvert !
"<a class='menuItem' OnMouseOver='_overMenuItem(this)' OnMouseOut='_outofMenuItem(this)' onclick='_clickedMenuItem(\""+ mnId +"\", this);' "+
"href='"+ this.action +"'";

if (this.target != "") str = str + " target='"+ this.target +"'"; 

str = str + ">" 
// GOOD but NO MORE "A GAUCHE" 20061022 ...utile finalement pour sym ga-dr
str += "<span class='space'>&nbsp;</span>"
str += this.label;
 str += "<span class='space'>&nbsp;</span>"; // mais utile a droite
 // str += "&nbsp;";// en fait ici pas besoin de format monospace car seul "le plus grand compte"
str += "</a>";

return str;
}

function MenuItem(label, action, target) // Now action=HREF
{
/*
var s1 = new String("to'tOx'oot");
var s2 = new String();
s2 = s1.replace(/'/gi, "K\"");


//alert( s1+ " "+ s2);
*/

/* gold by action onclick + EVAL -eval rajoute une indirection qui justifie le \\\\-
this.label = new String();
this.label = label;//.replace(/'/gi, "\\\"");
this.action = new String();
this.action = action.replace(/'/gi, "\\\"");
*/

this.label = new String();
this.label = label;//.replace(/'/gi, "\\\"");
this.action = new String();
this.action = action.replace(/'/gi, "\"");

this.target = new String("");
//alert("target is "+target);
//if (target != "") this.target = target.replace(/'/gi, "\\\"");// replace BY SECU
if (target != "") this.target = target.replace(/'/gi, "\"");// replace BY SECU

//alert(label);

this.toHtmlString = mi_toHtmlString;
}

function _MenuItem(actionA)
{
/*
var s1 = new String("to'tOx'oot");
var s2 = new String();
s2 = s1.replace(/'/gi, "K\"");


//alert( s1+ " "+ s2);
*/

/* Gold By Action 
this.label = new String();
this.label = label;//.replace(/'/gi, "\\\"");
this.action = new String();
this.action = action.replace(/'/gi, "\\\"");

NB : un jour remplacer aussi les " pour pemettre au user de choisir soit "' soit '"
a creuser : delicat...
*/
this.action = new String();
this.action = actionA;

//alert(label);

this.toHtmlString = mi_toHtmlString;
}
// end class



// --------------------------------------------------------------------------------
//                                    Class Menu
// --------------------------------------------------------------------------------
// contient un tableau de menuitems (+ tard faire a la java? mouais mais pb vert horiz navigation...

function mn_renderToDocument(doc)
{
var j = 0;
if (this.menuitems.length == 0) return 0;

// MN HEADER
doc.writeln("<table id='"+this.id+"_items"+"' class='menuList' cellspacing='0' cellpadding='0'>\n");
//<table id='mh5_items' class='menuList' cellspacing='0'>


// Render SPECIAL FORMATTING FIRST ITEM

/* GOLDISSIME
doc.writeln("<tr><td id='"+ this.id + "_f"+
"' class='menuItem' OnMouseOver='_overMenuItem(this)' OnMouseOut='_outofMenuItem(this)' onclick='_clickedMenuItem(\""+ this.id +"\", this); eval(\""+this.menuitems[j].action+"\");'>"+
this.menuitems[j].label+"</td></tr>");
*/

doc.writeln("<tr><td id='"+ this.id + "_f' "+ 
this.menuitems[j].toHtmlString(this.id)+"</td></tr>");


// Render OTHER MenuItems

for (j = 1; j < this.menuitems.length; j++)
{
/* GOLDISSIME
doc.writeln("<tr><td class='menuItem' onmouseover='_overMenuItem(this)' onmouseout='_outofMenuItem(this)' onclick='_clickedMenuItem(\""+ this.id +"\", this); eval(\""+this.menuitems[j].action+"\");'>"+
this.menuitems[j].label+"</td></tr>");
*/
doc.writeln("<tr><td " + this.menuitems[j].toHtmlString(this.id) + "</td></tr>");

/* PLUS TARD  span avec prise en charge de onmouseover a virer dici ?
*/

}

// MN FOOTER
doc.writeln('</table>\n');
}


function mn_addMenuItem(label, action, target) // now label et action=HREF !
{
var i = 0;
i = this.menuitems.length;// +1;
this.menuitems[i] = new MenuItem(label, action, target);
//this.nmenus = i;

//	window.status ='Created MenuItem in MN_'+ this.title +'['+ i +'] = '+ this.menuitems[i].label + ' len=' + this.menuitems.length;

return(this.menuitems[i]);
}

function mn_addMenuItem_A(actionA)
{
var i = 0;
i = this.menuitems.length;// +1;
this.menuitems[i] = new MenuItem(actionA);
//this.nmenus = i;

//	window.status ='Created MenuItem in MN_'+ this.title +'['+ i +'] = '+ this.menuitems[i].label + ' len=' + this.menuitems.length;

return(this.menuitems[i]);
}

function Menu(label, id)
{
this.id = id;

this.label = label;
this.menuitems = new Array();

this.addMenuItem = mn_addMenuItem;
this.renderToDocument = mn_renderToDocument;
}

// --------------------------------------------------------------------------------
//                                Class menubar
// --------------------------------------------------------------------------------
var mbidgen = 0; // generateur d'id unique de mb, de mn, et de mni.

// contient un tableau de menus

function mb_addMenu(label)
{
var i = 0;
var mnid = 0; 

i = this.menus.length;// +1;
mnid = this.id +"_"+ i ;
this.menus[i] = new Menu(label, mnid);
//this.nmenus = i;

//	window.status ='Created Menu MB_'+ this.name +'['+ i +'] = '+ this.menus[i].title + ' len=' + this.menus.length;
return(this.menus[i]);
}

function mb_renderToDocument(doc)
{
var i = 0;
//var mnid = 0;

	//doc.writeln('mbid = '+ this.id+'<br />\n');

// MB HEADER

// GOLD au 20061009 doc.writeln("<table id='"+this.id+"' class='menuBar' cellspacing='0'>\n<tr>\n");
// petite erreur : padding pas nec sur m mas sur MN!
doc.writeln("<table id='"+this.id+"' class='menuBar' cellspacing='0'>\n<tr>\n");

// Render MenuHeads

for (i = 0; i < this.menus.length; i++)
{

// valign='top'
doc.writeln("<td id='"+ this.menus[i].id +"' class='menuHead' \n"+
"OnMouseOver='_overMenuHead(this);' onMouseOut='_outofMenuHead(this);'>\n"+
this.menus[i].label + "</td>\n");

}

// MB FOOTER
doc.writeln('</tr>\n</table>\n');

// Render MenuLists (hidden)

for (i = 0; i < this.menus.length; i++)
{
this.menus[i].renderToDocument(doc);
}

}



function MenuBar(label)
{
this.id = "mb"+mbidgen; mbidgen = mbidgen + 1;
this.label = label;
//this.nmenus = 0;
this.menus = new Array();
this.addMenu = mb_addMenu;
this.renderToDocument = mb_renderToDocument;
//	window.status = 'Created MenuBar '+ this.name + ' len=' + this.menus.length;


/* 
NB : on peut faire riche en prenant en prm xyw et en forcant style htm avec xyw,
renoncant a feuille de style css, reportant dans style la css...
MAIS la mbprend tout sn sens en racine dune fenetre, comme en programmetiion classique,
qui plus est meme si je mets 2 mb sur lq meme feuille comment positionner lq deuxieme en etant
sur quelle ne se superpose pas a autre chose PUISQUE en principe ele se place en abs.
certes on peut commentcer a imaginer la placer en rel mais la ca devient compliqué.
*/
}
// end class


// ---------------------
//     VARIOUS TOOLS
// ---------------------

function loadUrlToFrame(url, target) // target is an object, NOT a string !
{ 
// alert(url +" go to "+ target);
target.location = url; 
}


/* 
RAF: harmoniser _items avec autre chose mnid etc ...

onclick sur span : le cpter sur td le router vers span ? CAR span pas sensible sur 
toute la larheur sous ie5 : RAF tester sous ie6 ff op

*/


