var menuids=["liste_regions"]; //Enter id(s) of menus, separated by commas

function buildsubmenus() {
	for (var i=0; i<menuids.length; i++) {
		var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul");
		for (var t=0; t<ultags.length; t++) {
			//alert (ultags[t].innerHTML);
			ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle";
			if (ultags[t].parentNode.parentNode.id==menuids[i]) {
				//if this is a first level submenu
				ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px";
				//dynamically position first level submenus to be width of main menu item
			} else {
				//else if this is a sub level submenu (ul)
				ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px";
				//position menu to the right of menu item that activated it
			}
		}
		var atags = document.getElementById(menuids[i]).getElementsByTagName("a");
		for (var t=0; t<atags.length; t++) {
			atags[t].onclick = function() {
				if (this.parentNode.getElementsByTagName("ul")[0].style.display == 'none') {
					this.parentNode.getElementsByTagName("ul")[0].style.display="block";
				} else {
					this.parentNode.getElementsByTagName("ul")[0].style.display="none";
				}
			}
		}
		for (var t=ultags.length-1; t>-1; t--) {
			//loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
			ultags[t].style.visibility="visible";
			ultags[t].style.display="none";
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", buildsubmenus, false);
else if (window.attachEvent)
	window.attachEvent("onload", buildsubmenus);

/////////////////////////

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent) break;
		  obj = obj.offsetParent;
		}
	else if(obj.y) curtop += obj.y;
	return curtop;
}

function BrowserCheck() {
	var b = navigator.appName

	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.plfrm = navigator.platform.indexOf('Mac') > -1 ? 'mac' : (navigator.platform.indexOf('Win') > -1 ? 'win' : 'other')
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
	us = 'disabled'; ust = true
}
// automatically create the "is" browser object
var is = new BrowserCheck()

var ComboBoxSkins = {
	listeReg : {
		Border: "1px solid #999999",
		BorderOver: "1px solid #999999",
		ButtonOver: url_site+"images/xpbtn_o.gif",
		ButtonNormal: url_site+"images/xpbtn_n.gif",
		ButtonPressed: url_site+"images/xpbtn_p.gif",
		ssWidth: "9px",
		ssHeight: "9px",
		isWidth: 9,
		isHeight: 9,
		FaceBackgroundColor: "white",
		ContentBackgroundColor: "white",
		Cursor: "pointer",
		FontFamily: "Arial, Helvetica, sans-serif",
		FontSize: "1.1em",
		FontColor: "#000000",
		Padding:"2px"
	},
	AlphaChannel: url_site+"images/spacer.png",
	MaxHeight : 16,
	HolderHeight: 120,
	ApplyIEFilter: function (El)
	{
		El.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + El.src + "', sizingMethod='image')";
		El.src = this.AlphaChannel;
	}
}; // ComboBoxSkins class



function CjComboBox(Skin, Mnu,divregion) {
//	IContainer(this); // Inherit IContainer

	var divregion = document.getElementById(divregion);
	
	this.Skin = Skin;
	this.hasEvent = false; // Has the outside click event handler = false

	this.Width = 350; //default width

	this.getWidth = function() { return this.Width; }
	this.setWidth = function(w) { this.Width = w; this.setContentWidth(w) }

	this.ContentWidth = this.Width; //defualt to size of parent
	this.ContentHeight = ComboBoxSkins.HolderHeight; //default width
	this.getHeight = function() { return this.ContentHeight; }
	this.setHeight = function(h) { this.ContentHeight = h; }

	this.setContentWidth = function(w) { this.ContentWidth = w;}
	this.Float = "left";

	this.CloseBoxes = new Array();
	
	this.closeOnOpen = function(boxes) {
		this.CloseBoxes = boxes;
	}
	
	this.setFloat = function(f) {
		this.Float = f;
	}

	this.Caption = "";
	this.FirstCaption = "";
	this.setCaption = function(newText) {
		this.Caption = newText;
		if (this.ComboCaption) {
			this.ComboCaption.innerHTML = this.Caption;
		}

		if (this.FirstCaption == "") {
			this.FirstCaption = this.Caption;
		}
	}

	this.AttachTo = function (Container) {
		this.Container = Container;
		// override default AttachTo
		if (typeof this.Container == "string") {
			System.DOM.ObjPointer(this.Container).appendChild(this.ComboFace);
			System.DOM.ObjPointer(this.Container).appendChild(this.ContentHolder);
		}
	}
	

	this.RepositionHolder = function() {
		//this.ContentHolder.style.top = (System.DOM.findPosY(this.ComboFace) + ComboBoxSkins.MaxHeight + 1) + "px";
		//this.ContentHolder.style.left = System.DOM.findPosX(this.ComboFace) + "px";
		//if (System.OS.Browser != BT_IE) this.ContentHolder.style.top = "21px"
		//this.ContentHolder.style.zIndex = "1000000";

//alert(findPosY(this.ComboCaption))
		//this.ContentHolder.style.top = (findPosY(this.ComboCaption) + ComboBoxSkins.MaxHeight + 4) + "px";

		//this.ContentHolder.style.top = findPosY(this.ComboCaption) + (is.b == 'ie' ? 4 : 1) + ComboBoxSkins.MaxHeight  + "px";
		//this.ContentHolder.style.left = findPosX(this.ComboCaption) + "px";
/*
		this.ContentHolder.style.top =  0 + "px";
		this.ContentHolder.style.left = 0 + "px";
		this.ContentHolder.style.zIndex = "1000000";
*/		
		//if (System.OS.Browser != BT_IE) this.ContentHolder.style.top = "21px"
		//this.ContentHolder.style.zIndex = "1000000";

	}

	this.Create = function()
	{		
		this.ComboFace = document.createElement("span");
		this.ComboFace.id = "CjComboBox" //System.DOM.uniqueID("CjComboBox");
		this.ComboFace.style.width = this.Width + "px";
		this.ComboFace.style.height = ComboBoxSkins.MaxHeight + "px";
		//this.ComboFace.style.line-height = ComboBoxSkins.MaxHeight + "px";
		this.ComboFace.style.border = this.Skin.Border;
		this.ComboFace.style.lineHeight = ComboBoxSkins.MaxHeight + "px";
		this.ComboFace.style.backgroundColor = this.Skin.FaceBackgroundColor;
		this.ComboFace.style.cursor = this.Skin.Cursor;
		this.ComboFace.style.zIndex = 10000;
		this.ComboFace.style.styleFloat = this.Float;
		this.ComboFace.style.cssFloat = this.Float;
		
		this.ComboFace.style.padding = this.Skin.Padding;

		this.ComboFace.style.position = "relative"; //"absolute";

this.ComboFace.style.backgroundColor = '#FFFFFF';
//this.ComboFace.style.left = 150 + "px";



		// Create Caption bar
		this.ComboCaption = document.createElement("span");
		this.ComboCaption.id = "jComboCaption" //System.DOM.uniqueID("jComboCaption");
		this.ComboCaption.style.FontFamily = this.Skin.FontFamily;
		this.ComboCaption.style.FontSize = this.Skin.FontSize;
		this.ComboCaption.style.FontColor = this.Skin.FontColor;
		this.ComboCaption.style.styleFloat = "left";
		this.ComboCaption.style.cssFloat = "left";
		this.ComboCaption.style.backgroundColor = this.Skin.FaceBackgroundColor;
		this.ComboCaption.style.cursor = this.Skin.Cursor;
		this.ComboCaption.style.lineHeight = ComboBoxSkins.MaxHeight + "px";
		this.ComboCaption.style.paddingLeft = "2px";
		this.setCaption(this.Caption);

//this.ComboCaption.style.left = 150 + "px";

		// Create Button Holder
		this.ComboButtonHolder = document.createElement("span");
		this.ComboButtonHolder.style.styleFloat = "right";
		this.ComboButtonHolder.style.cssFloat = "right";
		this.ComboButtonHolder.style.width = ComboBoxSkins.MaxHeight + "px";
		this.ComboButtonHolder.style.height = ComboBoxSkins.MaxHeight + "px";


		// Create Button
		this.ComboButton = document.createElement("img");
		this.ComboButton.alt = this.Caption;
		this.ComboButton.id = "jComboButton" //System.DOM.uniqueID("jComboButton");
		this.ComboButton.src = this.Skin.ButtonNormal;
		
		var brclr = document.createElement("br");
			brclr.style.clear = "both";
			brclr.style.cssFloat = "none";
			brclr.style.styleFloat = "none";

		this.ContentHolder = document.createElement("span");
		this.ContentHolder.style.height = /*200*/ this.ContentHeight + "px";
		this.ContentHolder.style.width = this.ContentWidth + "px";
		this.ContentHolder.style.backgroundColor = this.Skin.ContentBackgroundColor;
		this.ContentHolder.style.border = this.Skin.Border;
		this.ContentHolder.style.position = "relative";
		this.ContentHolder.style.overflow = "auto";
		this.ContentHolder.style.overflowX = "hidden";
		this.ContentHolder.style.display = "none";
		this.ContentHolder.style.top = 0 + "px";
		this.ContentHolder.style.zIndex = this.ComboFace.style.zIndex - 1;
		this.ContentHolder.style.clear = "both";
		this.ContentHolder.id = "jComboContentHolder" //System.DOM.uniqueID("jComboContentHolder");

this.ContentHolder.innerHTML = Mnu;

		this.ComboFace.appendChild(this.ComboCaption);
		this.ComboButtonHolder.appendChild(this.ComboButton);

		this.ComboFace.appendChild(this.ComboButtonHolder);
		this.ComboFace.appendChild(brclr);
		//var markerid=System.DOM.uniqueID("marker");
		//document.write("<span id='" + markerid + "' style='display: none'></span>");

		//System.DOM.ObjPointer(markerid).parentNode.appendChild(this.ComboFace);
		//document.body.appendChild(this.ComboFace);
		divregion.appendChild(this.ComboFace);

		this.RepositionHolder();
		divregion.appendChild(this.ContentHolder);
		//document.body.appendChild(this.ContentHolder);
//		System.DOM.bringToFront(this.ComboFace);
		//document.body.removeChild(this.ComboFace);
		//document.body.appendChild(this.ComboFace);




		// Adding Events
		this.ComboButton.onmouseover = this.BtnMouseOver;
		this.ComboButton.onmouseout = this.BtnMouseOut;
		this.ComboButton.onmousedown = this.BtnMouseDown;
		this.ComboButton.onclick = this.BtnMouseUp;

		this.ComboFace.onmouseover = this.BtnMouseOver;
		this.ComboFace.onmouseout = this.BtnMouseOut;
		this.ComboFace.onclick = this.MCCOpen;

		this.ComboCaption.onmouseover = this.BtnMouseOver;
		this.ComboCaption.onmouseout = this.BtnMouseOut;
		this.ComboCaption.onclick = this.MCCOpen;

	}

	this.ContentVisible = function() { return this.ContentHolder.style.display == "none" ? false : true; }
	this.ShowContent = function() { this.RepositionHolder(); this.ContentHolder.style.display = "block"; }
	this.HideContent = function() { this.ContentHolder.style.display = "none"; }

	this.BtnMouseOver = function (CallerObject) {
							return function () {
								CallerObject.ComboButton.src = CallerObject.Skin.ButtonOver;
//								CallerObject.ComboFace.style.border = CallerObject.XPRoyale.Skin.BorderOver;
							}
						} (this);

	this.BtnMouseOut = function (CallerObject) {
							return function () {
								CallerObject.ComboButton.src = CallerObject.Skin.ButtonNormal;
								CallerObject.ComboFace.style.border = CallerObject.Skin.Border;
							}
						} (this);

	this.BtnMouseDown = function (CallerObject)
						{
							return function ()
							{
								CallerObject.ComboButton.src = CallerObject.Skin.ButtonPressed;
							}
						} (this);

	this.BtnMouseUp = function (CallerObject)
						{
							return function (e)
							{
								for (i=0; i<CallerObject.CloseBoxes.length; i++) 
								{
									if (CallerObject.CloseBoxes[i].ContentVisible()) {
										CallerObject.CloseBoxes[i].MCCOpen();
									}
								}
								
								CallerObject.ComboButton.src = CallerObject.Skin.ButtonOver;

								if (is.b == 'ie' /*System.OS.Browser == BT_IE*/) {
									window.event.cancelBubble = true;
									if (CallerObject.hasEvent) {
										divregion.detachEvent("onclick", CallerObject.ClickHandler);
									} else divregion.attachEvent("onclick", CallerObject.ClickHandler);
								} else {
									if (CallerObject.hasEvent) {
										divregion.removeEventListener("click", CallerObject.ClickHandler, false);
									} else divregion.addEventListener("click", CallerObject.ClickHandler, false);
									e.stopPropagation();
								}

								CallerObject.hasEvent = !CallerObject.hasEvent;

								if (CallerObject.ContentVisible()) {
									CallerObject.HideContent();
								} else {
									CallerObject.ShowContent();
								}
							}
						} (this);

	this.ClickHandler = function (CallerObject)
						{
							return function(mevent)
							{
								src = is.b == 'ie' /*System.OS.Browser == BT_IE*/ ? window.event.srcElement : mevent.srcElement;
								if (!src) src = is.b == 'ie' /*System.OS.Browser == BT_IE*/ ? window.event.target : mevent.target;

								inside = false;
								while (src.nodeName != "BODY") {
									if (src.id.indexOf("jCombo") > -1 ) {
										inside = true;
										break;
									}
									src = src.parentNode;
								}

								if (!inside) {
									CallerObject.MCCOpen();
								}
							}

						} (this);


	this.MCCOpen = function(CallerObject)
					{
						return function (e)
						{
							for (i=0; i<CallerObject.CloseBoxes.length; i++) 
								{
									if (CallerObject.CloseBoxes[i].ContentVisible()) {
										CallerObject.CloseBoxes[i].MCCOpen();
									}
							}
							
							if (is.b == 'ie' /*System.OS.Browser == BT_IE*/) {
								window.event.cancelBubble = true;
								if (CallerObject.hasEvent) {
									divregion.detachEvent("onclick", CallerObject.ClickHandler);
								} else divregion.attachEvent("onclick", CallerObject.ClickHandler);
							} else {
								if (CallerObject.hasEvent) {
									divregion.removeEventListener("click", CallerObject.ClickHandler, false);
								} else divregion.addEventListener("click", CallerObject.ClickHandler, false);
								if (e) e.stopPropagation();
							}

							CallerObject.hasEvent = !CallerObject.hasEvent;

							if (CallerObject.ContentVisible()) {
								CallerObject.HideContent();

							} else {
								CallerObject.ShowContent();
							}
						}
				} (this);
}
