//============================================================//
var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

var clickX = 0;
var clickY = 0;

//***************** Capture Mouse XY *********************#
var mouseX = 0;
var mouseY = 0;
document.onmousemove = captureMouseXY;
function captureMouseXY(e)
{
	if(IE)
	{
		try
		{
			mouseX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			mouseY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		catch(e) {}
	}
	else
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	
	if (mouseX<0) mouseX = 0;
	if (mouseY<0) mouseY = 0;
}

//***************** Capture Screen X *********************#
var scrnX = 0;
var scrnY = 0;
function captureScreenXY(e)
{
	if(IE)
	{
		scrnX = event.screenX;
		scrnY = event.screenY;
	}
	else
	{
		scrnX = e.screenX;
		scrnY = e.screenY;
	}
	
	if (scrnX<0) scrnX = 0;
	if (scrnY<0) scrnY = 0;
}

//***************** Get Scroll X *************************#
function getScrollX(){

	var scrollX;

	if (self.pageXOffset)
	{
		scrollX = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft) // Explorer 6 Strict
	{	 
		scrollX = document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		scrollX = document.body.scrollLeft;
	}

	return scrollX;
}

//***************** Get Scroll Y *************************#
function getScrollY(){

	var scrollY;

	if (self.pageYOffset)
	{
		scrollY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
	{	 
		scrollY = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		scrollY = document.body.scrollTop;
	}

	return scrollY;
}

//********************************************************#
var currentPopupID = '';
//***************** Show Fixed Popup *********************#
function showFixedPopup(idPopup, x, y)
{
	hidePopup();

	currentPopupID = idPopup;

	var popup = document.getElementById(idPopup);

	var popupX = (window.screen.width - x) / 2;
	var popupY = (getScrollY() + window.screen.height*.5 - y) + 10;

	popup.style.left = popupX + "px";
	popup.style.top = popupY + "px";

	popup.style.display = "block";
	popup.style.visibility = "visible";
}

//***************** Show Custom Popup ********************#
function showCustomPopup(idPopup, x, y)
{
	hidePopup();

	currentPopupID = idPopup;
	
	var popup = document.getElementById(idPopup);
	
	popup.style.top = y + "px";
	popup.style.left = x + "px";
	
	popup.style.display = "block";
	popup.style.visibility = "visible";
}

//***************** Show Popup ***************************#
function showPopup(idPopup)
{
	hidePopup();

	currentPopupID = idPopup;
	
	var popup = document.getElementById(idPopup);
	
	if(clickX==0) clickX = mouseX;
	if(clickY==0) clickY = mouseY;
	
	popup.style.top = (clickY - 30) + "px";
	popup.style.left = (clickX + 30) + "px";
	popup.style.visibility = "Visible";
	popup.style.display = "block";
}

//***************** Hide Popup ***************************#
function hidePopup()
{
	if(currentPopupID!='')
	{
		var popup = document.getElementById(currentPopupID);
		popup.style.display = "none";
		popup.style.visibility = "hidden";
	}
	
	currentPopupID = '';
	clickX = 0;
	clickY = 0;
}


//***************** Hide Popup By ID***************************#
function hidePopupByID(elementID)
{
	var popup = document.getElementById(elementID);
	popup.style.display = "none";
	popup.style.visibility = "hidden";
}

//***************** Show Popup Message ********************#
function showPopupMessage (elementID, msg, heading)
{
	var waitMsg = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>';
	waitMsg += '<table id width="100%" border="0" cellspacing="0" cellpadding="5">';
	waitMsg += '<tr>';
	
	if(typeof(heading)!='undefined') waitMsg += '<td class="popupHead" style="text-align:left">' + heading + '</td>';
	
	waitMsg += '<td class="popupHead" style="text-align:right">';
	waitMsg += '<img onclick="javascript:hidePopup();" src="' + rootUrl + '/images/icon_close.gif" border="0" alt="Close" title="Close" class="hand">';
	waitMsg += '</td></tr></table>';
	waitMsg += '</td></tr><tr><td id="' + 'Con' +  elementID + '" class="msg" style="padding:10px;">' + msg + '</td></tr></table>';
	
	document.getElementById(elementID).innerHTML = waitMsg;
}

function hidePopupTimeout(elementID, time)
{
	setTimeout("hidePopupByID('" + elementID + "')", time);
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function confirmDelete(url)
{
	if(confirm("Are you sure want to delete?")==false)
	{
		return;
	}
	
	window.location.href = url;
}
