//New Alert: with Filter/Opacity
var alertIE = (navigator.appName.indexOf("Microsoft") != -1);
if (typeof(alertDefaultSkinName) == "undefined")
	alertDefaultSkinName = "Blue";
var alertDefaultTitle = "Alert";
var alertDefaultText = "Are you sure?";
var alertDefaultTrueButtonText = "Yes";
var alertDefaultFalseButtonText = "No";
var oAlertBlockingLayer = null;
var oAlertLayer = null;
var oAlertTemporalLayer = null;
var alertFunctionParameter = null;
var alertScrollTimerId = null;
var alertPreviousTopPosition=0;
var alertPreviousLeftPosition=0;
var alertHalfBoxHeight = 0;
var alertHalfWinHeight = 0;
var alertHalfBoxWidth = 0;
var alertHalfWinWidth = 0;
var oAlertTrueButton = null;
var oAlertFalseButton = null;
function alertDisplayShowElements(sTagName,sStatus)
{
	var aElm = document.getElementsByTagName(sTagName);
	var oElm = null;
	for (i=0; i<aElm.length; i++)
	{
		oElm = aElm[i];
		oElm.style.display = sStatus;
	}
}
function alertHideShowElements(sTagName,sStatus)
{
	var aElm = document.getElementsByTagName(sTagName);
	var oElm = null;
	for (i=0; i<aElm.length; i++)
	{
		oElm = aElm[i];
		oElm.style.visibility = sStatus;
	}
}
function alertGetScrollTop()
{
	var iValue = 0;
	if (document.body.scrollTop)
	{
		iValue = document.body.scrollTop;
	}
	else
	{
		if (window.pageYOffset)
		{
			iValue = window.pageYOffset;
		}
		else
		{
			if (document.documentElement)
			{
				iValue = document.documentElement.scrollTop;
			}
		}
	}
	return iValue;
}
function alertGetScrollLeft()
{
	var iValue = 0;
	if (document.body.scrollLeft)
	{
		iValue = document.body.scrollLeft;
	}
	else
	{
		if (window.pageXOffset)
		{
			iValue = window.pageXOffset;
		}
		else
		{
			if (document.documentElement)
			{
				iValue = document.documentElement.scrollLeft;
			}
		}
	}
	return iValue;
}
function alertGetWinWidth()
{
	var iWidth = 0;
	if (window.innerWidth)
	{
		iWidth = window.innerWidth;
	}
	else
	{
		if (document.body.offsetWidth)
		{
			iWidth = document.body.offsetWidth;
		}
	}
	return iWidth;
}
function alertGetWinHeight()
{
	var iHeight = 0;
	if (window.innerHeight)
	{
		iHeight = window.innerHeight;
	}
	else
	{
		if (document.body.offsetHeight)
		{
			iHeight = document.body.offsetHeight;
		}
	}
	return iHeight;
}
function alertGetMaxWidth()
{
	var iWidth = alertGetWinWidth();
	if (document.width)
	{
		if (document.width > iWidth)
		{
			iWidth = document.width;
		}
	}
	if (document.body.scrollWidth)
	{
		if (document.body.scrollWidth > iWidth)
		{
			iWidth = document.body.scrollWidth;
		}
	}
	return iWidth;
}
function alertGetMaxHeight()
{
	var iHeight = alertGetWinHeight();
	if (document.height)
	{
		if (document.height > iHeight)
		{
			iHeight = document.height;
		}
	}
	if (document.body.scrollHeight)
	{
		if (document.body.scrollHeight > iHeight)
		{
			iHeight = document.body.scrollHeight;
		}
	}
	return iHeight;
}
function alertKeepFocus(obj)
{
	if (oAlertLayer)
	{
		if (obj == oAlertFalseButton)
		{
			if (oAlertTrueButton) oAlertTrueButton.focus();
		}
		else
		{
			if (oAlertFalseButton) oAlertFalseButton.focus();
		}
	}
}
function alertBlockAll()
{
	var iWidth = alertGetMaxWidth();
	var iHeight = alertGetMaxHeight();
	if (iHeight >= alertGetWinHeight())
	{
		iWidth = iWidth - (alertIE ? 20 : 16);
	}
	if (alertIE)
	{
		if (iWidth > alertGetWinWidth() - 20)
		{
			iHeight = iHeight - 20;
		}
		else
		{
			iHeight = iHeight - 4;
		}
	}
	else
	{
		if (iWidth >= alertGetWinWidth())
		{
			iHeight = iHeight - 16;
		}
	}
	if (oAlertBlockingLayer == null)
	{
		oAlertBlockingLayer = document.createElement("Div");			
		// Filter/Opacity
		// We assign an Id to be able to reference it and set the Filter/Opacity
		oAlertBlockingLayer.id = "divAlertBlockingLayer";
	}
	oAlertBlockingLayer.style.top = "0";
	oAlertBlockingLayer.style.left = "0";
	oAlertBlockingLayer.style.width = iWidth + "px";
	oAlertBlockingLayer.style.height = iHeight + "px";
	oAlertBlockingLayer.style.zIndex = "10000";
	oAlertBlockingLayer.style.position="absolute";
	if (alertIE)
	{
		oAlertBlockingLayer.style.background="#FFFFFF";
		oAlertBlockingLayer.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";			
	}
	document.getElementById("divAlertDeleteContainer").appendChild(oAlertBlockingLayer);
}
function alertCloseAlert(bStatus)
{
	if ( document.getElementById("divAlertDeleteContainer") )
		if ( oAlertLayer != null )
			document.getElementById("divAlertDeleteContainer").removeChild(oAlertLayer);
	if ( document.getElementById("divAlertDeleteContainer") )
		if ( oAlertBlockingLayer != null )
			document.getElementById("divAlertDeleteContainer").removeChild(oAlertBlockingLayer);
	oAlertLayer = null;
	oAlertBlockingLayer = null;
	clearTimeout(alertScrollTimerId);
	if (alertIE) 
		alertHideShowElements("SELECT","visible");
	alertHideShowElements("OBJECT","visible");
	if (window.fnDeleteAlertReturn)
	{
		fnDeleteAlertReturn(bStatus, alertFunctionParameter);
	}
	// ******* Removing Filter/Opacity *********** //
	if ( document.getElementById( "divBodyPage") )
	{
		document.getElementById( "divBodyPage" ).style.filter = '';
		document.getElementById( "divBodyPage" ).style.opacity = "";
	}
	showDivScroll("list","listhidescroll");
}
function alertGetAlertTable(sMessage,sTrueButton,sFalseButton,sTitle,sSkinName,sOnlyAlert)
{
	var sTable = "";
	sTable += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"alertoutertable\" id=\"tblAlert\">";
	sTable += "<tr><td>";
	sTable += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"alertinnertable\" width='100%'>";
	sTable += "<tr><td>";
	//sTable += '<div style="cursor: move;" onmousedown="MoveDiv.MouseDownEvent(event, this)" onmouseup="MoveDiv.MouseUpEvent()">';
	sTable += "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\" class=\"alerttitletable\">";
	sTable += "<tr><td align=\"left\" width=\"98%\" style=\"cursor: move;\" onmousedown=\"MoveDiv.MouseDownEvent(event, this)\" onmouseup=\"MoveDiv.MouseUpEvent()\">";
	sTable += sTitle ? sTitle : alertDefaultTitle;
	sTable += "</td><td align=\"right\">";
	sTable += "<a href=\"javascript:alertCloseAlert(false);\"><img src=\"Images/AlertDelete/Close-icon.gif\" border=\"0\"></a>";
	sTable += "</td></tr>";
	sTable += "</table>";
	//sTable += '</div>';
	sTable += "</td></tr>";
	sTable += "<tr><td align=\"right\" width='100%'>";
	sTable += "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" class=\"alertmessagetable\" width=\"100%\">";
	sTable += "<tr><td colspan=\"5\">&nbsp;</td></tr>";
	sTable += "<tr valign=\"middle\">";
	sTable += "<td align=\"left\" width=\"10\">";
	sTable += "</td><td align=\"left\" width=\"10\">";
	sTable += "<img src=\"Images/AlertDelete/Alert-icon.gif\" border=\"0\">";;
	sTable += "</td><td width=\"1\"></td><td align=\"left\" width='100%'>";
	if ( alertIE )
		sTable += "<div>";
	else
		sTable += "<div style='border: solid 1px Transparent; width:100%'>";
	sTable += sMessage ? sMessage.replace(/\n/g,"<br>") : alertDefaultText;
	sTable += "</div></td><td width=\"10\"></td>";
	sTable += "</tr>";
	sTable += "<tr><td colspan=\"5\">&nbsp;</td></tr>";
	sTable += "</table>";
	sTable += "</td></tr>";
	sTable += "<tr><td align=\"center\">";
	sTable += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"alertbuttontable\" width=\"100%\">";
	sTable += "<tr height=\"27\" valign=\"middle\">";
	sTable += "<td align=\"left\">";
	sTable += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	sTable += "<tr valign=\"middle\">";
	sTable += "<td width=\"10\"></td>";
	if ( sOnlyAlert == null )
	{
		sTable += "<td align=\"left\">";
		sTable += "<a class=\"imagebutton\" href=\"javascript:alertCloseAlert(true);\" onblur=\"javascript:alertKeepFocus(this);\" id=\"btnAlertTrueButton\"><img align=\"absmiddle\" src=\"Images/AlertDelete/yes-icon.gif\" border='0'>&nbsp;&nbsp;" + (sTrueButton ? sTrueButton : alertDefaultTrueButtonText) + "</a>&nbsp;&nbsp;"
		sTable += "<td class=\"alertbuttonseparatorskin\"></td>";
		sTable += "<td class=\"alertbuttonseparatorwhite\"></td>";
		sTable += "</td><td width=\"10\"></td>";
	}
	else 
		sTable += "<td width=\"10\"></td>";
	sTable += "<td align=\"center\">";
	if ( sOnlyAlert == null )
		sTable += "<a class=\"imagebutton\" href=\"javascript:alertCloseAlert(false);\" onblur=\"javascript:alertKeepFocus(this);\" id=\"btnAlertFalseButton\"><img align=\"absmiddle\" src=\"Images/AlertDelete/no-icon.gif\"  border='0'>&nbsp;&nbsp;" + (sFalseButton ? sFalseButton : alertDefaultFalseButtonText) + "</a>&nbsp;&nbsp;"
	else
		sTable += "<a class=\"imagebutton\" href=\"javascript:alertCloseAlert(false);\" onblur=\"javascript:alertKeepFocus(this);\" id=\"btnAlertFalseButton\"><img align=\"absmiddle\" src=\"Images/AlertDelete/ok-icon.gif\" border='0'>&nbsp;&nbsp;" + (sFalseButton ? sFalseButton : sOnlyAlert) + "</a>&nbsp;&nbsp;"
	sTable += "</td>";
	sTable += "<td class=\"alertbuttonseparatorskin\"></td>";
	sTable += "<td class=\"alertbuttonseparatorwhite\"></td>";
	sTable += "<td width=\"10\"></td>";
	sTable += "</tr>";
	sTable += "</table>";
	sTable += "</td>";
	sTable += "</tr>";
	sTable += "</table>";
	sTable += "</td></tr>";
	sTable += "</table>";
	sTable += "</td></tr>";
	sTable += "</table>";
	return sTable;
}
function alertDrawTemporalAlert()
{
	if (oAlertTemporalLayer == null)
		oAlertTemporalLayer = document.createElement("Div");
	oAlertTemporalLayer.style.zIndex="1";
	oAlertTemporalLayer.style.position="absolute";
	oAlertTemporalLayer.style.background="#FFFFFF";
	oAlertTemporalLayer.appendChild(oAlertLayer);
	oAlertTemporalLayer.style.top = "0";
	oAlertTemporalLayer.style.left = "0";
	oAlertTemporalLayer.style.width = "0";
	oAlertTemporalLayer.style.height = "0";
	oAlertTemporalLayer.style.overflow = "hidden";
	document.getElementById("divAlertDeleteContainer").appendChild(oAlertTemporalLayer);
	return document.getElementById("tblAlert");
}
function alertDeleteTemporalAlert()
{
	document.getElementById("divAlertDeleteContainer").removeChild(oAlertTemporalLayer);
}
function alertBuildAlert(sMessage,sTrueButton,sFalseButton,sTitle,sSkinName,sFunctionParm,sOnlyAlert)
{
	/* new code, when an alert already was in the page */
	if ( document.getElementById("divAlertDeleteContainer") )
		if ( oAlertLayer != null )
			document.getElementById("divAlertDeleteContainer").removeChild(oAlertLayer);
	if ( document.getElementById("divAlertDeleteContainer") )
		if ( oAlertBlockingLayer != null )
			document.getElementById("divAlertDeleteContainer").removeChild(oAlertBlockingLayer);
	/*end new code*/
	
	// If the div for Alert does not exist we create it and add it to the body
	if ( !document.getElementById( "divAlertDeleteContainer") )
	{
		var divAlert = document.createElement( "div" );
		divAlert.id = "divAlertDeleteContainer";
		document.body.appendChild( divAlert );
	}
	if (alertIE) 
		alertHideShowElements("SELECT","hidden");
	alertHideShowElements("OBJECT","hidden");
	alertBlockAll();
	alertFunctionParameter = sFunctionParm;
	alertPreviousTopPosition = alertGetScrollTop();
	alertPreviousLeftPosition = alertGetScrollLeft();
	alertHalfWinHeight = parseInt(alertGetWinHeight() / 2);
	alertHalfWinWidth = parseInt(alertGetWinWidth() / 2);
	var iTop = alertPreviousTopPosition + alertHalfWinHeight;
	var iLeft = alertPreviousLeftPosition + alertHalfWinWidth;
	oAlertLayer = document.createElement("Div");
	oAlertLayer.style.zIndex="10001";
	oAlertLayer.style.position="absolute";
	oAlertLayer.style.background="#FFFFFF";
	oAlertLayer.innerHTML = alertGetAlertTable(sMessage,sTrueButton,sFalseButton,sTitle,sSkinName,sOnlyAlert);
	var oTblAlert = alertDrawTemporalAlert();
	alertHalfBoxHeight = parseInt(oAlertLayer.offsetHeight / 2);
	alertHalfBoxWidth = parseInt(oAlertLayer.offsetWidth / 2);
	oAlertLayer.style.top = iTop - alertHalfBoxHeight;
	oAlertLayer.style.left = iLeft - alertHalfBoxWidth;
	oAlertLayer.style.top = -1000;
	oAlertLayer.style.left = -1000;
	alertDeleteTemporalAlert();
	document.getElementById("divAlertDeleteContainer").appendChild(oAlertLayer);
	oAlertTrueButton = document.getElementById("btnAlertTrueButton");
	oAlertFalseButton = document.getElementById("btnAlertFalseButton");
	if (oAlertFalseButton) 
		oAlertFalseButton.focus();
	alertScrollTimerId = setTimeout("alertCheckScroll()", 500);
	alertHalfBoxHeight = parseInt(oAlertLayer.offsetHeight / 2);
	alertHalfBoxWidth = parseInt(oAlertLayer.offsetWidth / 2);
	oAlertLayer.style.top = iTop - alertHalfBoxHeight;
	oAlertLayer.style.left = iLeft - alertHalfBoxWidth;
	if ( parseInt(oAlertLayer.style.left) < 0 ) 
		oAlertLayer.style.left = 0;
	showDivScroll("listhidescroll","list");
	// If divBodyPage exist, then we set the Filter/Opacity for the entire page
	if ( document.getElementById( "divBodyPage") )
	{
		if ( alertIE )
		{
			document.getElementById( "divAlertBlockingLayer" ).style.background = "silver";
			document.getElementById( "divAlertBlockingLayer" ).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)';
			
		}
		else
		{
			document.getElementById( "divBodyPage" ).style.opacity = ".40";
		}
	}
}
function alertCheckScroll()
{
	var iTop = alertGetScrollTop();
	if (alertPreviousTopPosition != iTop)
	{
		oAlertLayer.style.top = iTop + alertHalfWinHeight - alertHalfBoxHeight;
		alertPreviousTopPosition = iTop;
	}
	var iLeft = alertGetScrollLeft();
	if (alertPreviousLeftPosition != iLeft)
	{
		oAlertLayer.style.left = iLeft + alertHalfWinWidth - alertHalfBoxWidth;
		alertPreviousLeftPosition = iLeft;
	}
	clearTimeout(alertScrollTimerId);
	alertScrollTimerId = setTimeout("alertCheckScroll()", 500);
}
/***********************************/
/* with this code we can move divs */
var MoveDiv = {	};
MoveDiv.Layer = null;
MoveDiv.IsIE = navigator.userAgent.indexOf("MSIE") != -1;
MoveDiv.Top = 0;
MoveDiv.MouseUpEvent = function()
{
	MoveDiv.Layer = null;
}
MoveDiv.MouseDownEvent = function( e, obj, bIsInBox )
{
	MoveDiv.Top = 0;
	if ( bIsInBox != null )
		if ( bIsInBox )
			if ( document.getElementById( "divMasterContent" ) )
			{
				if ( MoveDiv.IsIE )
					MoveDiv.Top = document.getElementById( "divMasterContent" ).offsetTop+4;
				else
					MoveDiv.Top = document.getElementById( "divMasterContent" ).offsetTop-2;
			}

	while ( obj.parentNode.tagName  != "DIV")
		obj = obj.parentNode;
	MoveDiv.Layer = obj.parentNode;
	if ( MoveDiv.IsIE )
	{
		MoveDiv.difX = e.offsetX+4;
		MoveDiv.difY = e.offsetY+4;
	}
	else
	{
		MoveDiv.difX = e.layerX;
		MoveDiv.difY = e.layerY;
	}
}
MoveDiv.MouseMoveEvent = function( e )
{
	if ( MoveDiv.Layer != null )
	{
		MoveDiv.Layer.style.top = ( ( e.clientY - MoveDiv.difY ) - MoveDiv.Top ) + "px";
		MoveDiv.Layer.style.left = ( e.clientX - MoveDiv.difX ) + "px";
	}
}