if(Mony == undefined) var Mony = {};
_frontpage = false;
_Mony_Menu_Container = new Array();
_failed = false;
if(window.ActiveXObject)
	browser='ie';
else
       browser='mos';
Mony.Container = function()
{
	this.mainContainerDIV = document.createElement('div');
	this.menu_item_array = new Array();
	this.menu_item_count = 0;
	this.mainContainerDIV.className = "Mony_Menu_Container";
	
	this.domain = document.location;
	if(this.domain.toString().search("www")>=0)
		this.domain = this.domain.replace("www.", "");
	this.frontpage = false;
	if(this.domain.toString().search("index.php")>=0)
	{
		this.domain_array = this.domain.toString().split("index.php");
		this.domain = this.domain_array[0];
		this.chosen_url = this.domain_array[1];
		if(!this.chosen_url || this.chosen_url == "" || this.chosen_url.toString().search("view=frontpage")>=0)
			this.frontpage = true;
	}
	else
	{
		this.chosen_url = "";
		this.domain = "http://lederconsulting.com";
	}
	this.id = "69";
	//types are: list_flat horiz_flat vert_indent
	this.type = "vert_indent";
	
}
String.prototype.strip = function( exp ){ return this.replace(exp?exp:/\s/g,""); };
Mony.Container.prototype = 
{
	curContext: "",
	init: function(_self_ref, id, type)
	{
		this.id = id;
		if(type)
			this.type = type;
		_Mony_Menu_Container[this.id] = _self_ref;
		if(this.type == "horiz_flat")
		{
			//this.mainContainerDIV.style.height="30px";
			//this.mainContainerDIV.style.paddingTop="0px";
		}
		else
		{
			this.mainContainerDIV.style.marginBottom="12px";
			this.mainContainerDIV.style.padding="5px";
		}
		//this.mainContainerDIV.onmouseout = new Function("_Mony_Menu_Container.open_child_container('all', false);");
	},
	select_title: function(url)
	{
		alert(url);
		this.menu_item_array = new Mony.Menu_Item();
		this.menu_item_array.select_title(url);
        
	},
   	select_button: function(id)
	{
		for(var y = 0; y<=this.menu_item_count-1; y++)
		{
			this.menu_item_array[y].select_button(id);
		}
	},
	open_child_container: function(id, open)
	{
		for(var y = 0; y<=this.menu_item_count-1; y++)
		{
			if(this.menu_item_array[y].open_if(id, open))
				return true;
		}
		/*
		for(var y = 0; y<=this.menu_item_count-1; y++)
		{
			if(this.menu_item_array[y].open_if(id, open))
			{
				if(id!="all" || open || browser=='mos')
				{
					return true;
				}
			}
		}
		
		if(open)
		{
			for(var y = 0; y<=this.menu_item_count-1; y++)
			{
				if(this.menu_item_array[y].open_if(id, open))
					return true;
			}
		}
		else
		{
			setTimeout("_Mony_Menu_Container.start_child_container('"+id+"', 'false');", 3000);
		}
		*/
	},
	start_child_container: function(id, open)
	{
		open=false;
		for(var y = 0; y<=this.menu_item_count-1; y++)
		{
			if(this.menu_item_array[y].open_if(id, open))
				return true;
		}
	},
	menu_item:function(name, link, level)
	{
		var menu_item = new Mony.Menu_Item();
		menu_item.name = name;
		menu_item.link = link;
		menu_item.chosen_url = this.chosen_url;
		level = parseInt(level);
		menu_item.level = level;
		menu_item.domain = this.domain;
		menu_item.init(this.id, this.type);
		
		if(level>=1)
		{
			var menu_item_object = this.menu_item_array[this.menu_item_count-1];
			
			if(level>=2)
			{
				//for(var x = 0; x<=level-1; x++)
				//{
				menu_item_object = menu_item_object.getLastChild();
				//}
			}
			
			menu_item_object.addChild(menu_item);
		}
		else
		{
			this.menu_item_array[this.menu_item_count] = menu_item;
			this.menu_item_array[this.menu_item_count].set_actions();
			this.mainContainerDIV.appendChild(this.menu_item_array[this.menu_item_count].getDiv());
			this.menu_item_count++;
		}
		/*
		this.menu_item_array[this.menu_item_count] = document.createElement('div');
		this.menu_item_array[this.menu_item_count].className = "Mony_Menu_Button";
		this.menu_item_array[this.menu_item_count].innerHTML = name;
		
		this.mainContainerDIV.appendChild(this.menu_item_array[this.menu_item_count]);
		this.menu_item_count++;
		*/
	},
	getDiv: function()
	{
		return this.mainContainerDIV;
	}
};

if(Mony == undefined) var Mony = {};
_Menu_Item = null;
_ajax_timout = 0;
Mony.Menu_Item = function()
{
	this.mainContainerDIV = document.createElement('div');
	//this.mainContainerDIV.cancelBubble;
	this.mainContainerDIV.className = "Mony_Menu_Item";
	this.buttonDIV = document.createElement('div');
	this.buttonDIV.className = "Mony_Menu_Button";
	
	this.childContainerDIV = document.createElement('div');
	this.childContainerDIV.style.marginLeft = "5px";
	this.childContainerDIV.className = "child_container_close";
	this.window_open = false;
	this.id = "";
	this.child_array = new Array();
	this.child_count = 0;
	this.name="Menu Item 0";
	this.level = 0;
	this.link="";
	//types are: list_flat horiz_flat vert_indent
	this.type = "vert_indent";
	this.domain = "";
	this.parentID = "69";
	this.chosen_url = "";
	this.active = false;
	this.frontpage = false;
}
Mony.Menu_Item.prototype =
{
	curContext: "",
	init: function(id, type)
	{
		this.type = type;
		if(this.type == "horiz_flat")
		{
			this.mainContainerDIV.className = "Mony_Menu_Item_horz";
		}
		else
		{
			this.mainContainerDIV.className = "Mony_Menu_Item";
		}
		this.mainContainerDIV.appendChild(this.buttonDIV);
		
		this.buttonDIV.innerHTML = this.name;
		
		var randomnumber=Math.floor(Math.random()*1000);
		this.id = this.name + randomnumber;
		this.parentID = id;
		temp_link = escape(this.link);
		if(this.link.search(escape(this.chosen_url))>=0)
		{
			this.active = true;
			//this.buttonDIV.className = "Mony_Menu_Button_active";
			this.buttonDIV.className = "Mony_Menu_Button";
		}
		else
		{
			this.active = false;
			this.buttonDIV.className = "Mony_Menu_Button";
		}
		if(!this.link || this.link == "" || this.link.toString().search("view=frontpage")>=0)
			this.frontpage = true;
	},
	select_title: function(url)
	{
		this.link = url;
        alert(this.link);
		//if(this.id == id)
		//{
			this.buttonDIV.className = "Mony_Menu_Button_selected";
			 var div_id = "content_div";
			if(document.getElementById(div_id))
			{
				var indicator_image = document.createElement('img');
				indicator_image.src = "http://dev.lederconsulting.com/images/Mony_Wait.gif";
				indicator_image.className = "indicator_image";
				document.getElementById(div_id).appendChild(indicator_image);
			}
			_frontpage = this.frontpage;
			if(browser=="ie")
			{
				if(_frontpage)
				{
					if(document.getElementById("tabber_div"))
					{
						document.getElementById("tabber_div").className = "frontpage_content";
					}
				}
				else
				{
					if(document.getElementById("tabber_div"))
					{
						document.getElementById("tabber_div").className = "frontpage_content_closed";
					}
				}
			}
			var url_link = this.link+"?template=small";
			if(this.link.search('\\?')>=0)
			{url_link = this.link+"&template=small";}
			_tabLoader.updateValue(this.changeTabContent, url_link);
			//return true;
		//}
		//else
		//{
			this.buttonDIV.className = "Mony_Menu_Button";
			//return false;
		//}
		for(var i = 0; i<=this.child_count-1; i++)
		{
			this.child_array[i].select_button(id);
		}
        
        this.change_bookmark(document.title, this.link);
	},
    change_bookmark: function(title, url)
    {
        alert(title + " " + url);
        if(document.getElementById("bookmark_thispage"))
        { 
            document.getElementById("bookmark_thispage").setAttribute("path", url);
            document.getElementById("bookmark_thispage").title = title;
        }
    },
	select_button: function(id)
	{
		if(this.id == id)
		{
			this.buttonDIV.className = "Mony_Menu_Button_selected";
			 var div_id = "content_div";
			if(document.getElementById(div_id))
			{
				var indicator_image = document.createElement('img');
				indicator_image.src = "http://dev.lederconsulting.com/images/Mony_Wait.gif";
				indicator_image.className = "indicator_image";
				document.getElementById(div_id).appendChild(indicator_image);
			}
			_frontpage = this.frontpage;
			if(browser=="ie")
			{
				if(_frontpage)
				{
					if(document.getElementById("tabber_div"))
					{
						document.getElementById("tabber_div").className = "frontpage_content";
					}
				}
				else
				{
					if(document.getElementById("tabber_div"))
					{
						document.getElementById("tabber_div").className = "frontpage_content_closed";
					}
				}
			}
			var url_link = this.link+"?template=small";
			if(this.link.search('\\?')>=0)
			{url_link = this.link+"&template=small";}
			_tabLoader.updateValue(this.changeTabContent, url_link);
			if(this.window_open)
			{
				this.open_if(id, false);
			}
			else
			{
				this.open_if(id, true);
			}
			//return true;
		}
		else
		{
			this.buttonDIV.className = "Mony_Menu_Button";
			//return false;
		}
		for(var i = 0; i<=this.child_count-1; i++)
		{
			this.child_array[i].select_button(id);
		}
	},
	changeTabContent: function(thisURL)
	{
			if (_xmlhttp && _xmlhttp.readyState == 4) 
			{
				 var div_id = "content_div";
				 if (_xmlhttp.status == 200)
				 {
					results = _xmlhttp.responseText;
					
					if(document.getElementById(div_id))
					{
						document.getElementById(div_id).innerHTML = results;
						if(_frontpage)
						{
							if(document.getElementById("tabber_div"))
							{
								document.getElementById("tabber_div").className = "frontpage_content";
							}
						}
						else
						{
							if(document.getElementById("tabber_div"))
							{
								document.getElementById("tabber_div").className = "frontpage_content_closed";
							}
						}
						tabberAutomatic("");
					}
				 }
				 else if(_xmlhttp.status == 404)
				 {
					if(document.getElementById(div_id))
						document.getElementById(div_id).innerHTML = "<BR><BR><BR><BR><BR><BR><BR><BR>Error Number: "+_xmlhttp.status+" 404 Not Found";
				 }
				 else
				 {
					 
					 if(document.getElementById(div_id))
						document.getElementById(div_id).innerHTML = "<BR><BR><BR><BR><BR><BR><BR><BR>Error Number: "+_xmlhttp.status+" Could not Load.";
				 }
				 //_ajax_timout++;
			}
			else
			{}
	},
	open_if: function(id, open)
	{
		if(this.id==id)
		{
			this.open_container(open);
			return true;
		}
		for(var i = 0; i<=this.child_count-1; i++)
		{
			if(this.child_array[i].open_if(id, open))
				return true;
		}
	},
	addChild: function(new_menu_item)
	{
		if(this.child_count == 0)
		{
			this.mainContainerDIV.appendChild(this.childContainerDIV);
		}
		this.child_array[this.child_count] = new_menu_item;
		this.child_array[this.child_count].set_actions();
		this.childContainerDIV.appendChild(this.child_array[this.child_count].getDiv());
		this.child_count++;
	},
	open_container:function(open)
	{
		if(open)
		{
			this.childContainerDIV.className = "child_container_open";
			this.window_open = true;
		}
		else
		{
			//if(browser=="mos")
			//{
				this.childContainerDIV.className = "child_container_close";
				this.window_open = false;
			//}
			
		}
	},
	getLastChild: function()
	{
		return this.child_array[this.child_count-1];
	},
	set_actions: function()
	{
		this.buttonDIV.onclick = new Function("_Mony_Menu_Container["+this.parentID+"].select_button('"+this.id+"');");//document.location='" + this.link + "';");
		//this.buttonDIV.onmouseover = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', true);");
		//this.mainContainerDIV.onmouseover = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', true);");
		//this.childContainerDIV.onmouseover  = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', true);");
		//this.mainContainerDIV.onmouseout = new Function("if(this == event.target){_Mony_Menu_Container.open_child_container('"+this.id+"', false);}else{}");
		//window.event.cancelBubble = true;
		//this.mainContainerDIV.onmouseover = new Function("window.event.cancelBubble = true;");
		//if(this.type == "horiz_flat")
		//{
			//this.mainContainerDIV.onmouseout = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', false);");
			//if(browser=="ie")
			//{
				//this.buttonDIV.onmouseout = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', false);");
				//this.childContainerDIV.onmouseout = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', false);");
			//}
			//else if(browser=="mos")
				//this.mainContainerDIV.onmouseout = new Function("_Mony_Menu_Container["+this.parentID+"].open_child_container('"+this.id+"', false);");
		//}
		//this.mainContainerDIV.onmouseout = new Function("_Mony_Menu_Container.open_child_container('"+this.id+"', false);");
		//this.mainContainerDIV.onmouseleave = new Function("_Mony_Menu_Container.open_child_container('"+this.id+"', false);");
	},

	setDomain: function(newDomain)
	{this.domain = newDomain;},
	setText: function(new_text)
	{this.text = new_text;},
	getText: function()
	{return this.text;},
	setUrl: function(new_url)
	{this.url=new_url;},
	getUrl: function()
	{return this.url;},
	setTabNumber: function(new_number)
	{this.tabNumber = new_number;},
	getTabNumber: function()
	{return this.tabNumber;},
	setType: function(new_type)
	{this.type = new_type;},
	getType: function()
	{return this.type;},
	getChildContainerDiv: function()
	{
		return this.childContainerDIV;
	},
	getButtonDiv: function()
	{
		return this.buttonDIV;
	},
	getDiv: function()
	{
		return this.mainContainerDIV;
	}
};


Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
}

if(Mony == undefined) var Mony = {};
	
Mony.loader = function()
{this.init();}
	
	var _xmlhttp;
	
	Mony.loader.prototype = {
	
		curContext: "",
		pairsGlob:  0,
		init: function()
		{
			
			var newHTTPRequest;
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				newHTTPRequest = new XMLHttpRequest();
				/*if (newHTTPRequest.overrideMimeType) {
					newHTTPRequest.overrideMimeType('text/xml');
				}*/
			} else if (window.ActiveXObject) { // IE
				var msXMLHTTPs = new Array (
				"Msxml2.XMLHTTP.5.0",
				"Msxml2.XMLHTTP.4.0",
				"Msxml2.XMLHTTP.3.0",
				"Msxml2.XMLHTTP",
				"Microsoft.XMLHTTP"
				);
				for(var i = 0; i < msXMLHTTPs.length; i++){
					try {
						newHTTPRequest = new ActiveXObject(msXMLHTTPs[i]);
						break;
					} catch (e) {
						newHTTPRequest = false;
					}
				}
			}
			if (typeof(newHTTPRequest) == 'undefined') {
				alert("Unable to create HTTP Request Object...");
			}
			_xmlhttp = newHTTPRequest;
		},
		loadContent: function(searchNumber, structure)
		{	
			Mony_Pane_searchNumber = searchNumber;
			this.curContext = structure;
			
			this.updateValue();
			return oidFoundBool;
		},
		getContentArray: function()
		{
			return contentArray;
		},
		updateValue: function(callbackFunction, thisURL)
		{
		    _xmlhttp.onreadystatechange = function() { callbackFunction(thisURL); };
		    _xmlhttp.open('GET', thisURL, true);
		    _xmlhttp.onreadystatechange = function() { callbackFunction(thisURL); };
		    _xmlhttp.send(null);
		    
		},
		
		parsequery: function()
		{
		    var arg_pairs = new Object();
		    arg_pairs.names = new Array();
		    arg_pairs.values = new Array();
		    var query = location.search.substring(1);
		    if(query == "") { return null; }
		    var pairs = query.split("\&");
		    this.pairsGlob = pairs.length;
		    for(var i = 0; i < pairs.length; i++)
		    {
			var pos = pairs[i].indexOf('=');
			if(pos == -1){ continue; }
			var arg_name = pairs[i].substring(0,pos);
			var arg_value = pairs[i].substring(pos+1);
			arg_pairs.names[i] = arg_name;
			arg_pairs.values[i] = arg_value;
		    }
		    return arg_pairs;
		}
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}



