// PHirePhly Systems Javascript Library. (c) 2007 Bill Heller www.HellerSoftware.com
	
	var PHPh_LibraryType="MooTools";
	var PHPh_FormHandlers=new Array();

	function toggle_div_visibility(eID) {
		toggle_visibility(eID,'block');
	};
	
	function toggle_visibility(eID,visibile_style) {
		visibile_style=visibile_style?visibile_style:'';
		try {
			el=document.getElementById(eID);
			if(el.style.display=="none")
				el.style.display=visibile_style;
			else
				el.style.display="none";
		} catch (e) {  }
	};
	
	function PHPh_AJAXLoadURL(URL,container) {
		//alert('PHPh_AJAXLoadURL '+URL+' '+container.id);
		new Ajax(URL, {
					method: get,
					update: container,
					evalScripts: true,
					onComplete: function(){PHPh_AJAXParseContent(container);}
				}).request();
	};
	
	function PHPh_AJAXParseContent(container) {
		//alert('PHPh_AJAXParseContent '+container.id);
		$$(container.getElementsByTagName('form')).each(
				function(el){
					PHPh_FormHandlers["PHPh_form_handler_"+PHPh_FormHandlers.length]=new PHPh_AJAXFormHandler(el,container);
				}
			);
	};
	
	function PHPh_ReplaceAllTextareas(els) {
		//alert(els);
		//alert(els.length);
		for (var i=0; i < els.length; i++) {
        	var oFCKeditor = new FCKeditor( els[i].name ) ;
            oFCKeditor.BasePath = "/fckeditor/" ;
            oFCKeditor.ToolbarSet = 'Basic' ;
            oFCKeditor.ReplaceTextarea() ;
        }
     };
	 
	 function PHPh_InputFieldChange(el) {
		if(el) {
			if(el.prevonchange)el.prevonchange();
			if(el.value==el.prevVal) {
				el.className=el.className.replace(/ PHPh_mouseover/g,'');
			} else {
				el.className+=' PHPh_Input_Field_Edited';
				if(el.form && el.form.className.search(/PHPh_Edited/)==-1)
					el.form.className+' PHPh_Edited';
			}
		}	
	 };
	 
		function PHPh_PostToDiv(div,formid,targetURL) {
			//$(div).setStyle('opacity', .5);
			new Ajax(targetURL, {
					method: 'post',
					postBody: $(formid),
					update: $(div),
					evalScripts: true//,
					//onComplete: new Function("$('"+div+"').setStyle('opacity', 1);PHPh_FormHandlerAttach('"+div+"')")
				}).request();
				
		};
		function PHPh_GetToDiv(div,targetURL) {
			//$(div).setStyle('opacity', .5);
			new Ajax(targetURL, {
					method: 'get',
					update: $(div),
					evalScripts: true//,
					//onComplete: new Function("$('"+div+"').setStyle('opacity', 1);PHPh_FormHandlerAttach('"+div+"')")
				}).request();
				
		};
		function PHPh_BackgroundPost(formid,targetURL) {
			PHPh_PostToDiv('',formid,targetURL);
		};
		function PHPh_BackgroundGet(targetURL) {
			PHPh_GetToDiv('',targetURL)
		};
	 
	 function PHPh_ClearModal() {
	 	$('PHPh_ModalDiv').display='none';
	 };
	 function PHPh_Modal(content,url,color,el,stillmodalwhenclicked) {
		if(!color) color="#222255";
	 	if(!$('PHPh_ModalDiv')) {
			//md=new Element('div',{
			//	'id':'PHPh_ModalDiv',
			//	'styles':{
			//		'position': 'absolute',
			//		'display': 'block'
			//	}
			//};
			//if(!stillmodalwhenclicked){md.addEvent('click', function(){PHPh_ClearModal()});}
			////window.getWidth(
			//md.injectInside(document.body);
		}
		var l,r,t,b;
		if(!el) {
			$('PHPh_ModalDiv').setStyles({
   					top: 0,
   					left: 0,
   					width: window.getWidth(),
   					height: window.getHeight(),
					display: 'block'
				});			
		} else {
			elsize=el.getSize();
			$('PHPh_ModalDiv').setStyles({
   					top:el.getTop(),
   					left:el.getLeft(),
   					width:elsize.x,
   					height:elsize.y,
					display: 'block'
				});			
		}
	 };

	 function PHPh_isset(x) { return (typeof(x)=='undefined' || x.length==0); };

	 function PHPh_FormHandlerAttach(el) {
	 	//alert(el);
	 	//if($(el)) { $$(el+'.PHPh_Input_Field').each(function(el){ el.prevVal=el.value;if(el.onchange)el.prevonchange=el.onchange;el.onchange=PHPh_InputFieldChange(el); }) }	
	 };
/*	
	function PHPh_AJAXFormHandler(f,container) {
		this.id="PHPh_form_handler_"+PHPh_FormHandlers.length;
		this.index=PHPh_FormHandlers.length
		this.form=f
		this.container=container
		this.action=f.action
		this.method=f.method
		this.form_onsubmit=f.onsubmit
		if(this.form_onsubmit)
			this.onsubmit=function(){if(this.form_onsubmit()){this.submit()}return false;};
		else
			this.onsubmit=function(){this.submit();});
		f.onsubmit=new Function("PHPh_FormHandlers['"+this.id+"']();return false;");
		this.submit=new Function("
			new Ajax(this.action, {
					update: this.container,
					evalScripts: true,
					onComplete: function(){PHPh_AJAXParseContent(this.container);}
				}).request();
		");
	};
	*/
	
	/////////////////////////////////////////////////////////////////
	// TOOL TIP JS
	/*Based on Bubble Tooltips by Alessandro Fulciniti */
	var PHPh_TTenabled=true;
	function PHPh_tooltiptoggle() {
		PHPh_TTenabled=!PHPh_TTenabled;
		$('ttIcon').src=PHPh_TTenabled?"oawiOasis_Alerter_WebInterface/tooltipicon.gif":"oawiOasis_Alerter_WebInterface/tooltipicon_off.gif";
		//PHPh_Set_Cookie('PHPh_ToolTipsDisabled',PHPh_TTenabled?"0":"1",30,'/','','')
	};
	function PHPh_TTEnable(el){
		var i,elTT;
		//ttDisable=PHPh_Get_Cookie('PHPh_ToolTipsDisabled')
		//if(ttDisable && ttDisable=="1")PHPh_tooltiptoggle();
		i=-1;
		elTT=document.createElement("div");
		elTT.id="PHPh_ToolTip";
		elTT.setAttribute("id","PHPh_ToolTip");
		elTT.style.position="absolute";
		b=document.getElementsByTagName("body");
		//alert(b);
		if(b && b[0]){
			b[0].appendChild(elTT);
			if(el==null) el=document.getElementsByTagName("a");
			while(el[++i]){PHPh_TTPrepare(el[i]);}
		}
	};

	function PHPh_TTPrepare(el){
		var tooltip,t,b,s,l;
		t=el.getAttribute("title");
		el.removeAttribute("title");
		tooltip=PHPh_TooltipCreateEl("span","PHPh_tooltip");
		s=PHPh_TooltipCreateEl("span","top");
		s.appendChild(document.createTextNode(t));
		tooltip.appendChild(s);
		b=PHPh_TooltipCreateEl("b","bottom");
		//l=el.getAttribute("href");
		//if(l.length>28) l=l.substr(0,25)+"...";
		b.appendChild(document.createTextNode(" "));
		tooltip.appendChild(b);
		PHPh_setOpacity(tooltip);
		el.tooltip=tooltip;
		el.onmouseover=PHPh_ShowTooltip;
		el.onmouseout=PHPh_HideTooltip;
		el.onmousemove=PHPh_LocateToolTip;
	};

	function PHPh_ShowTooltip(e){
		if(this.id=="toolTipToggleLink") {
			this.title = PHPh_TTenabled?"Disable Tool Tips":"Enable Tool Tips";
			PHPh_TTPrepare(this);
		}
		if(PHPh_TTenabled||(this && this.id=="toolTipToggleLink")){
			document.getElementById("PHPh_ToolTip").appendChild(this.tooltip);PHPh_LocateToolTip(e);
		}
	};

	function PHPh_HideTooltip(e){
		var d=$("PHPh_ToolTip");
		if(d.childNodes.length>0) d.removeChild(d.firstChild);
	};

	function PHPh_setOpacity(el){
		el.style.filter="alpha(opacity:85)";
		el.style.KHTMLOpacity="0.85";
		el.style.MozOpacity="0.85";
		el.style.opacity="0.85";
	};

	function PHPh_TooltipCreateEl(t,c){
		var x=document.createElement(t);
		x.className=c;
		x.style.display="block";
		return(x);
	};

	function PHPh_TooltipAddCss(){
		var l=CreateEl("link");
		l.setAttribute("type","text/css");
		l.setAttribute("rel","stylesheet");
		l.setAttribute("href","bt.css");
		l.setAttribute("media","screen");
		document.getElementsByTagName("head")[0].appendChild(l);
	};

	function PHPh_LocateToolTip(e){
		var posx=0,posy=0;
		if(e==null) e=window.event;
		if(e.pageX || e.pageY){
    		posx=e.pageX; posy=e.pageY;
    	}
		else if(e.clientX || e.clientY){
    		if(document.documentElement.scrollTop){
        		posx=e.clientX+document.documentElement.scrollLeft;
        		posy=e.clientY+document.documentElement.scrollTop;
        		}
    		else{
        		posx=e.clientX+document.body.scrollLeft;
        		posy=e.clientY+document.body.scrollTop;
        		}
    	}
		document.getElementById("PHPh_ToolTip").style.top=(posy+5)+"px";
		document.getElementById("PHPh_ToolTip").style.left=(posx+2)+"px";
	};

	if(MooTools.version > '1.11')
		window.addEvent('domready',function() { PHPh_TTEnable($$('.PHPh_tt')) });
	else
		Window.onDomReady(function() { PHPh_TTEnable($$('.PHPh_tt')) });
	/////////////////////////////////////////////////////////////////
	
	function PHPh_StretchMenu(MenuItems,direction,inactivesize,maxsize,minsize,duration){
		//Adapted from kwiks on MooTools.net
		//var kwicks = $$('#kwick .kwick');
		//PHPh_StretchMenu($$('#PHPh_menu_container .menuitem'),'width',72,172,57,250)
		if(!duration)duration=200;
		var fx = new Fx.Elements(MenuItems, {wait: false, duration: duration, transition: Fx.Transitions.quadOut});
		var fxC = new Fx.Elements($$('div.menulinks'), {wait: false, duration: duration*3, transition: Fx.Transitions.quadOut});
		MenuItems.each(function(mi, i){
			mi.addEvent('mouseenter', function(e){
				var obj = {};
				var chobj = {};
				var child=$(mi.id+'_links');
				child.setStyle('opacity',0.0);
				child.setStyle('display','block');
				obj[i] = {
					'height': [mi.getStyle('height').toInt(), 180]
				};
				chobj[i] = {
					'opacity': [0, 1]
				};
				MenuItems.each(function(other, j){
					if (other != mi){
						var h = other.getStyle('height').toInt();
						if (h != 36) obj[j] = {'height': [h, 36]};
						var thisc=$(other.id+'_links');
						//$$('#'+other.id+'_links .hr').each(function(el){
						//	el.setStyle('opacity',0.0);
 						//});
						var o = thisc.getStyle('opacity').toFloat();
						if (o != 0) chobj[j] = {'opacity': [o, 0]};
						other.removeClass('moused');
						$(other.id+'_bottom').removeClass('moused');
						$(other.id+'_header').src = $(other.id+'_header').src.replace('_on\\.gif','.gif');
						$(other.id+'_header').src = '/i/menu/'+other.id.replace(/menu_/,'')+'.gif';
					} else {
						mi.addClass('moused');
						$(mi.id+'_bottom').addClass('moused');
						//$$('#'+mi.id+'_links .hr').each(function(el){
						//	el.setStyle('opacity',1.0);
 						//});
						$(mi.id+'_header').src = '/i/menu/'+mi.id.replace(/menu_/,'')+'_on.gif';
					}
				});
				fxC.start(chobj);
				fx.start(obj);
			});
			//mi.addEvent('mouseleave', function(e){
			//});
		});
		
		$('PHPh_menu_container').addEvent('mouseleave', function(e){
			var obj = {};
			var chobj = {};
			MenuItems.each(function(other, j){
				var thisc=$(other.id+'_links');
				//$$('#'+other.id+'_links .hr').each(function(el){
				//	el.setStyle('opacity',0.0);
 				//});
				var o = thisc.getStyle('opacity').toFloat();
				chobj[j] = {'opacity': [o, 0]};
				obj[j] = {'height': [other.getStyle('height').toInt(), 72]};
				other.removeClass('moused');
				$(other.id+'_bottom').removeClass('moused');
				$(other.id+'_header').src = '/i/menu/'+other.id.replace(/menu_/,'')+'.gif';
			});
			fxC.start(chobj);
			fx.start(obj);
		});
	}
