var oldAlert = window.alert;
window.alert = function() { };
function EnableAlert(f) {
	if (f)
		window.alert = oldAlert;
	else
		window.alert = function() { }
}

var JsLib = {
	/* JsLib.DependantVisible */
	DependantVisible: {
		useFading: false,
		zIndex:1000,
		Initialize: function(parentId,childId,delay,clickCloseID){
			var p=$(parentId);
			var c=$(childId);
			p.delay=delay;
			p.timerId=-1;
			p.childVisible=false;
			var z;
			if(clickCloseID){
				z=$(clickCloseID);
				z.parentObject=p;
			}else{
				z=$(childId);
			}
			p.childObject=c;
			c.parentObject=p;				
			
			if(null!=p.onclick){
				p.onclick=function(){
					if(this.childVisible)
						JsLib.DependantVisible.Hide(this.id);
					else
						JsLib.DependantVisible.Display(this.id);
					return false;
				};
				p.onmouseover=function(){
					if(-1!=this.timerId){
						window.clearTimeout(this.timerId);
						this.timerId=-1;
					}
				};
			}else{
				if(null!=p.onmouseover){
					p.onclick=function(){
						return false;
					};
					p.onmouseover=function(){
						if(-1!=this.timerId){
							window.clearTimeout(this.timerId);
							this.timerId=-1;
						}
						if(!this.childVisible)
							JsLib.DependantVisible.Display(this.id);
					};
				}
			}
			p.onmouseout=function(){
				if(this.childVisible)
					this.timerId=window.setTimeout('JsLib.DependantVisible.Hide(\''+this.id+'\')',this.delay);
			};
			c.onmouseover=function(){
				if(-1!=this.parentObject.timerId){
					window.clearTimeout(this.parentObject.timerId);
					this.parentObject.timerId=-1;
				}
			};
			c.onmouseout=function(){
				this.parentObject.timerId=window.setTimeout('JsLib.DependantVisible.Hide(\''+this.parentObject.id+'\')',this.parentObject.delay);
			};
			z.onclick=function(){
				JsLib.DependantVisible.Hide(this.parentObject.id);
			};
			JsLib.DependantVisible.Display(parentId);
		},
		Display: function(parentId){
			var p=$(parentId);
			var c=p.childObject;
			p.childVisible=true;
			c.style.zIndex=this.zIndex++;
			if(this.useFading)
				Effect.Appear(c,{duration:0.5});
			else
				c.style.display='block';
		},
		Hide: function(parentId){
			var p=$(parentId);
			if(p&&p.childObject&&p.childVisible){
				var c=p.childObject;
				if(-1!=p.timerId){
					window.clearTimeout(p.timerId);
					p.timerId=-1;
				}
				p.childVisible=false;
				if(this.useFading){
					Effect.Fade(c,{duration:0.5});
				}else{
					c.style.display='none';
				}
			}
		}
	}
};

JsLib.UI = {
	EqualiseBoxesHeight:function(){
		for (var i = 0; i < arguments.length; i++)if (!$(arguments[i]))return;
		var maxh=this.MaxHeight(this.GetElementsFromIDs(arguments));
		for(var i=0;i<arguments.length;i++) $(arguments[i]).style.height=maxh+"px";
	},
	EqualiseBoxesHeightByClassNameInsideElement:function(className,elementId) {
		var elements=this.GetElementsByClassName(className,null,$(elementId));
		var maxh=this.MaxHeight(elements);
		for (var i=0;i<elements.length;i++) elements[i].style.height = maxh + "px";
	},
	MaxHeight:function(elements){
		var heights=new Array();
		for(var i=0;i<elements.length;i++){
			if (navigator.userAgent.toLowerCase().indexOf('opera')==-1)
				heights.push(elements[i].scrollHeight);
			else
				heights.push(elements[i].offsetHeight);
		}
		heights.sort(function sortNumeric(f,s){return f-s;});
		return heights[elements.length-1];
	},
	GetElementsFromIDs:function(elementIDs){
		var elements = new Array();
		for(var i=0;i<elementIDs.length;i++)
			elements.push($(elementIDs[i]));
		return elements;
	},
	GetElementsByClassName:function(className, tag, elm){
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	}
}

JsLib.Browser = {
	supportsFixed: function() {
		var testDiv = document.createElement("div");
		testDiv.id = "testingPositionFixed";
		testDiv.style.position = "fixed";
		testDiv.style.top = "0px";
		testDiv.style.right = "0px";
		document.body.appendChild(testDiv);
		var offset = 1;
		if (typeof testDiv.offsetTop == "number"
            && testDiv.offsetTop != null
            && testDiv.offsetTop != "undefined") {
			offset = parseInt(testDiv.offsetTop);
		}

		document.body.removeChild(testDiv);
		
		if (offset == 0) {
			return true;
		}

		return false;
	}
}

/* JsLib.SwapImage */
JsLib.SwapImage = {
	preload: function(){
	  var d=document; if(d._images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=JsLib.SwapImage.preload.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	},
	restore: function(){
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	},
	findObj: function(n, d){
		var p,i,x;if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=JsLib.SwapImage.findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	},
	swap: function(){
		var i,j=0,x,a=JsLib.SwapImage.swap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=JsLib.SwapImage.findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
};

/* JsLib.Ajax */
JsLib.Ajax = {
	CreateXMLHttpRequest: function(){
		if( window.XMLHttpRequest ){
			return new XMLHttpRequest();;
		}else{
			if(window.ActiveXObject){
				return new ActiveXObject( "Microsoft.XMLHTTP" );
			}
		}
		return null;
	},
	LoadTEXT: function( url ){
		var xmlHttp=this.CreateXMLHttpRequest();
		xmlHttp.open('GET',url,false);
		xmlHttp.send(null);
		return xmlHttp.responseText;
	}
};

/* JsLib.GENERAL */
JsLib.General = {
	ObjectExists: function( element ){
		return (null!=element&& (typeof(element)=="string"&&element=="")==false&&"undefined"!=typeof(element));
	}
};

/* JsLib.Positioner */
JsLib.Positioner = {
	GetElementSize: function(element){ 
		return new JsLib.Positioner.Point(element.offsetWidth,element.offsetHeight);
	},
	GetAbsolutePos: function(element){
		var point=new JsLib.Positioner.Point(0, 0);
		if(JsLib.General.ObjectExists(element.offsetParent)){
			point=JsLib.Positioner.GetAbsolutePos(element.offsetParent);
			point.Offset(element.offsetLeft,element.offsetTop);
		}else{
			point=new JsLib.Positioner.Point(element.offsetLeft,element.offsetTop);
		}
		return point;
	},
	Point: function(x,y){
		this.x=x;this.y=y;
		this.Offset=function(dx,dy){this.x+=dx;this.y+=dy;};
		return this;
	}
};
	
/* JsLib.IFrame */
JsLib.IFrame = {
	AutoResize: function(divContent){
		var iframe=top.document.getElementById(self.name);
		var height=JsLib.Positioner.GetElementSize(divContent).y;
		iframe.height=height;
	}
};

JsLib.POPUP = {
	Window: function(url,width,height,name){
		var l=(screen.width)?(screen.width-width)/2:100;
		var t=(screen.height)?(screen.height-height)/2:100;
		window.open(url,name,'height='+height+',width='+width+',top='+t+',left='+l+',scrollbars=yes').focus();
	},
	WindowNoScroll: function(url,width,height,name){
		var l=(screen.width)?(screen.width-width)/2:100;
		var t=(screen.height)?(screen.height-height)/2:100;
		window.open(url,name,'height='+height+',width='+width+',top='+t+',left='+l+',scrollbars=no').focus();
	}
};

JsLib.AutoScroll = {
	ScrollDown: function(listid,listoverflowid,pixel){
		var li=$(listid), lo=$(listoverflowid);
		var sli=JsLib.Positioner.GetElementSize(li);
		var pli=JsLib.Positioner.GetAbsolutePos(li);
		var slo=JsLib.Positioner.GetElementSize(lo);
		var plo=JsLib.Positioner.GetAbsolutePos(lo);
		if((pli.y+sli.y)>(slo.y+plo.y))
			li.style.marginTop = (parseInt(li.style.marginTop.replace('px',''))-pixel)+'px';
	},
	ScrollUp: function(listid,listoverflowid,pixel){
		var li=$(listid), lo=$(listoverflowid);
		var sli=JsLib.Positioner.GetElementSize(li);
		var pli=JsLib.Positioner.GetAbsolutePos(li);
		var slo=JsLib.Positioner.GetElementSize(lo);
		var plo=JsLib.Positioner.GetAbsolutePos(lo);
		if(pli.y!=plo.y)
			li.style.marginTop = (parseInt(li.style.marginTop.replace('px',''))+pixel)+'px';
	}
};

JsLib.Flash = {
	getFlashMovieObject: function(movieName){
		if(window.document[movieName])
			return window.document[movieName];
		if(navigator.appName.indexOf("Microsoft Internet")==-1){
			if(document.embeds && document.embeds[movieName])
				return document.embeds[movieName]; 
		}else{
			return document.getElementById(movieName);
		}
	}	
};


/* UTILITIES */
JsLib.Utilities = {
	ScrollTop: function() {
		scroll(0, 0);
	},
	AutoHide: function(oid, delay) {
		window.setTimeout('$(\'' + oid + '\').style.display=\'none\';', delay);
	},
	ShowHide: function() { // Switch the 'display' property of a specified object 
		var args = arguments, id;
		for (var i = 0; i < args.length; i++) {
			id = args[i];
			var Object = $(id);
			if (Object.style.display == 'none') {
				Object.style.display = 'block';
			} else {
				Object.style.display = 'none';
			}
		}
	},
	ShowHideR: function() {
		var flag, id, args = arguments;
		for (var i = 0; i < args.length; i++) {
			id = args[i];
			var Object = $(id);
			if (Object.style.display == 'none') {
				flag = true;
				Object.style.display = 'block';
			} else {
				flag = false;
				Object.style.display = 'none';
			}
		}
		return flag;
	},
	Hide: function(id) {
		if (null != $(id))
			$(id).style.display = 'none';
	},
	Show: function(id) {
		if (null != $(id))
			$(id).style.display = 'block';
	},
	GetPageSize: function() {
		var xScroll, yScroll;
		var windowWidth, windowHeight;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		if (self.innerHeight) {	// all except Explorer
			if (document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if (yScroll < windowHeight) {
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if (xScroll < windowWidth) {
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth, pageHeight];
	},
	ReplaceQuote: function(str, c) {
		var nstr = str;
		while (nstr.indexOf('\'') > -1) {
			nstr = nstr.replace('\'', c);
		}
		return nstr;
	}
};