/* hoverbox.js */
var jsAlertMsg = {
	timeoutObj:null,
	AllowClose:0,
	AllowblockScreen:true,
	yPos:0,
	xPos:0,
  	title:'',
	DefaultTitle:'Please Note!',
	
	createBox : function(w, h, closeIcon)
	{
		window.clearTimeout(this.timeoutObj);
		var pageSize = getPageSize();
		var pageScroll = getPageScroll();
		
		var scr_w = 0, scr_h = 0, leftPos = 0, topPos = 0;
		scr_w = pageSize[0];
		scr_h = pageSize[3]+(pageScroll[1]*2);

		//if (this.AllowblockScreen) blockScreen(this.AllowClose);
		if (FireFox!=1) { this.hideSelects('hidden'); }
		
		bod 					= document.getElementsByTagName('body')[0];
		boxObj 					= document.createElement('div');
		boxObj.id				= 'AlertMsgBox';
		boxObj.className 		= "hoverSearch";
		boxObj.style.display	= 'none';
		boxObj.onselectstart 	= new Function("return false");
		
		boxTitle				= document.createElement('div');
		boxTitle.className		= 'titlebar';
		boxTitle.onSelect		= "return false";
		boxTitleTxt				= (this.title && this.title!=='') ? this.title : this.DefaultTitle;
		boxTitle.innerHTML		= this.title;
		
		Event.observe(boxTitle, 'mousedown', 	function(event) { jsAlertMsg.beginDrag(event); }, true);
		Event.observe(boxTitle, 'mouseup', 		function(event) { jsAlertMsg.endDrag(event); }, true);
		Event.observe(boxTitle, 'mousemove', 	function(event) { jsAlertMsg.drag(event); }, true);
		Event.observe(boxTitle, 'mouseout', 	function(event) { jsAlertMsg.endDrag(event); }, true);
		
		boxObj.move = this.move;
		boxObj.dragX = 0;
		boxObj.dragY = 0;
		boxObj.dragging = false;
		
		boxObj.appendChild(boxTitle);
		
		if (closeIcon!==0)
		{
			boxCloseIcon			= document.createElement('span');
			boxCloseIcon.className	= 'close';
			boxCloseIcon.innerHTML = '<a onclick=\"jsAlertMsg.closeHoverBox(); return false;\" class=\"hoverClose\"></a>';
			boxObj.appendChild(boxCloseIcon);
		}
		
		resultsObj 				= document.createElement("div");
		resultsObj.className 	= "results";
		contentObj 				= document.createElement("div");
		contentObj.className 	= "content";
	
		resultsObj.appendChild(contentObj);
		boxObj.appendChild(resultsObj);
		bod.appendChild(boxObj);
	
		if ((typeof(w)!="undefined") && (typeof(h)!="undefined"))
		{
			boxObj.style.width 			= (parseInt(w,10)+80) + 'px';
			boxObj.style.height 		= (parseInt(h,10)+45) + 'px';
			boxObj.style.opacity 		= '0.99999';
			boxObj.style.filter 		= "alpha(opacity:100)";
			contentObj.style.padding 	= '2px';
			
			leftPos = Math.round((scr_w - parseInt(w,10)-80)/2);
			topPos  = Math.round((scr_h - parseInt(h,10)-55)/2);
		}
		else
		{
			leftPos = Math.round((scr_w-200)/2);
			topPos  = Math.round((scr_h-60)/2);
		}
		
		boxObj.style.top		= topPos+"px"; 
		boxObj.style.left		= leftPos+"px"; 
		boxObj.style.display 	= 'block';
	},
	
	setTimer : function (timer) { 
		if (timer==="")		{ this.timeoutObj = window.setTimeout('jsAlertMsg.closeHoverBox()', 2800); }
		else { if (timer>0) { this.timeoutObj = window.setTimeout('jsAlertMsg.closeHoverBox()', timer); } }
	},

	closeHoverBox : function () {
		if ($('AlertMsgBox')) 
		{
			Element.remove('AlertMsgBox');
			this.AllowClose = 0;
			this.boxObj = null;
			this.contentObj = null;
			this.title = null;  
			if (FireFox!=1) { this.hideSelects('visible'); }
			if ($('blocker') && Element.getStyle('blocker', 'display')=="block") { blockScreen(); }
		}
	},
	
	beginDrag : function (event) {
		jsAlertMsg.dragX = Event.pointerX(event) - boxObj.offsetLeft;
		jsAlertMsg.dragY = Event.pointerY(event) - boxObj.offsetTop;
		jsAlertMsg.dragging = true;
		Element.addClassName(boxTitle, 'hoverDrag');
	},
	
	endDrag : function () {
		jsAlertMsg.dragging = false;
		Element.removeClassName(boxTitle, 'hoverDrag');
	},
	
	drag : function(event) {
    	if (!jsAlertMsg) return;
		if (jsAlertMsg.dragging) this.move(Event.pointerX(event) - jsAlertMsg.dragX, Event.pointerY(event) - jsAlertMsg.dragY);
	},

	move : function(left, top) {
		boxObj.style.left = left+"px";
		boxObj.style.top = top+"px";
	},
	
	hideSelects: function(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	},
	
	AlertMsg : function(string, msg, timer)
	{	
		if (!msg) { return; }
		if ($('AlertMsgBox')) { if (Element.getStyle('AlertMsgBox', 'display')=="block") { this.closeHoverBox(); } }
		
		if ((string) && (string!=='')) { this.title = string; }
		else { this.title = this.DefaultTitle; }
		jsAlertMsg.createBox();
		contentObj.innerHTML  = unescape(msg);
		this.setTimer(timer);
	},

	AlertMsgSize : function(title_string, msg, w, h, timer, align, closeIcon)
	{	
		if (!msg) { return; }
		if ($('AlertMsgBox')) { if (Element.getStyle('AlertMsgBox', 'display')=="block") { this.closeHoverBox(); } }

		h = (parseInt(h,10)+8);
		if (title_string) { this.title = title_string; }
		this.createBox(w,h,closeIcon);
		contentObj.innerHTML  = '<div align="'+align+'" style="margin:8px 0 8px 0;">'+unescape(msg)+'</div>';
	
		this.setTimer(timer);
	},

	AlertFrameSize : function(title_string, msg, w, h)
	{	
		if (!msg) { return; }
		if ($('AlertMsgBox')) { if (Element.getStyle('AlertMsgBox', 'display')=="block") { this.closeHoverBox(); } }
		
		if (title_string) { this.title = title_string; }
		this.createBox(w,h,1);
		contentObj.innerHTML  = unescape(msg);
	}
};


function inlineImgPop(title_str,img,w,h,scr)
{
	jsAlertMsg.AllowClose = 1;
	//if (scr==1) { jsAlertMsg.AllowblockScreen = false; }
	var msg = '<img class="pointer" onClick="jsAlertMsg.closeHoverBox();" src="'+img+'" width="'+w+'" height="'+h+'" alt="" border="0" />';
	jsAlertMsg.AlertMsgSize(unescape(title_str), unescape(msg), w, h, -1, null, 1);
}

function inlineWinImgPop(title_str,img,w,h)
{
	jsAlertMsg.AllowClose = 1;
	var msg = '<img src="'+img+'" alt="" border="0" />';
	jsAlertMsg.AlertMsgSize(unescape(title_str), unescape(msg), w, h, -1, null, 1);
}

function inlineFramePop(title_str,src,frameID,w,h,style)
{
	var addedStyle = (style!=="") ? 'style="'+style+'"' : '';
	var msg = '<iframe '+addedStyle+' class="tab-frame" src="'+src+'" name="'+frameID+'" id="'+frameID+'" width="'+(parseInt(w,10)+72)+'" height="'+(parseInt(h,10)+15)+'" marginwidth="0" marginheight="0" scrolling="auto" frameborder="0"></iframe>';
	jsAlertMsg.AllowClose = 1;
	jsAlertMsg.AlertFrameSize(unescape(title_str), unescape(msg), w, h);
}

function inlineSizePop(title_str, msg, w, h, align)
{
	if (typeof(align=="undefined")) { align = "center"; }
	jsAlertMsg.AlertMsgSize(title_str,msg,w,h,-1,align,1);
}

function inlineAlertMsg(title_str, msg,timer)
{
	jsAlertMsg.AlertMsg(unescape(title_str),unescape(msg),timer);
}

function inlineProcessing(Text, Close)
{
	var AnimDiv = '<div id="anim"></div>';
	if (Text==="") { Text="Processing, Please Wait!"; }
	var msg = AnimDiv+Text;
	Close = (typeof(Close)!='undefined') ? Close : 1;
	jsAlertMsg.AlertMsgSize('Please Wait', msg, 250, 40, -1, 'center', Close);
}

function inlineHtml(title_str,html,w,h)
{
	jsAlertMsg.AllowClose = 1;
	jsAlertMsg.AlertFrameSize(unescape(title_str), unescape(html), w, h);
}

function getPageSize()
{
	var xScroll,yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else { 
	if (document.body.scrollHeight>document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	}
	var windowWidth,windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	var pageHeight = 0, pageWidth = 0;
	pageHeight 	= (yScroll<windowHeight) 	? windowHeight 	: yScroll;
	pageWidth 	= (xScroll<windowWidth) 	? windowWidth	: xScroll;
	
	var arrayPageSize = [pageWidth, pageHeight, windowWidth, windowHeight];
	return arrayPageSize;
}

function getPageScroll()
{
	var yScroll;
	if (self.pageYOffset) { yScroll = self.pageYOffset; }
	else { 
		if (document.documentElement && document.documentElement.scrollTop) { 
			yScroll = document.documentElement.scrollTop;
		} 
		else { 
			if (document.body) { yScroll = document.body.scrollTop; } 
		} 
	}
	var arrayPageScroll = ['',yScroll];
	return arrayPageScroll;
}