/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5 && version < 7.0) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
*/

 function CloseOpenerRefresh()
 {
    window.opener.location.reload();
    window.close();
 }
 
 function WaitCloseOpenerRefresh(time)
 {
    window.setTimeout('CloseOpenerRefresh();', time);
 }

function openWindow(url)
{
    return openWindowOptions(url,'650','500');
}
function openWindowOptions(url,width,height)
{
    window.open(url,null,'width=' + width + ',height=' + height + ',location=no,menubar=no,toolbar=no,titlebar=no,status=no,scrollbars=yes,resizable=yes');
    return false;
}

function ToggleDisplay(id)
{	
	var idArray = id.split(",");
	for(i = 0; i < idArray.length; i++)
	{
		var curState = document.getElementById(idArray[i]).style.display;
		if(curState == "none")
			document.getElementById(idArray[i]).style.display = "";
		else
			document.getElementById(idArray[i]).style.display = "none";
	}
}

function ToggleText(id,txt1,txt2)
{
	var text = document.getElementById(id).innerText;
	if(text == txt1)
		document.getElementById(id).innerText = txt2;
	else
		document.getElementById(id).innerText = txt1;
}

function ToggleColumns(tableId,columnNumbers) 
{
	var tbl  = document.getElementById(tableId);
	var rows = tbl.getElementsByTagName('tr');
	var columnArray = columnNumbers.split(",");
	
	for (var row=0; row < rows.length; row++) 
	{
		var cells = rows[row].getElementsByTagName('td')
		for(i = 0; i < columnArray.length; i++)
		{			
			var curState =cells[columnArray[i]].style.display;
			if(curState == "none")
				cells[columnArray[i]].style.display = "";
			else
				cells[columnArray[i]].style.display = "none";;
		}
	}
}

function HoverRow(obj,action,type)
{
	if(action == "on")
	{
		obj.style.background = '#CCCCCC';
	}
	else
	{
		if(type == "altrow")
			obj.style.background = '#ECECEC';
		else
			obj.style.background = '#FFFFFF';
			
	}
}
// EBA ComboBox utility methods
function clearEmpty(comboID, txtBoxID) 
{ 
	// copy selected value from list to the hidden .net TextBox control 
	if(document.getElementById(comboID).object.GetTextValue() == "") 	
	    document.getElementById(txtBoxID).value = "";
} 
function selectEvent(comboID,txtBoxID,fieldIndex)
{
    selectEvent(comboID,txtBoxID,fieldIndex,false);
}
function selectEvent(comboID, txtBoxID, fieldIndex,postback) 
{ 
	// copy selected value from list to the hidden .net TextBox control 
	var field = document.getElementById(txtBoxID);	
	field.value = document.getElementById(comboID).object.GetSelectedRowValues()[fieldIndex]; 
	
	// Fire the onChange event		
	fireOnChange(field);
		
	if(postback == true) __doPostBack(comboID,'Select');
} 
 // Fires when the user clicks on the parent combo.
function cmbLinkedSelect(parentControl,childControl,fieldIndex,parentComboId,childComboId)
{
	// Get the combo objects using their ids.
	var childCombo = document.getElementById(childComboId).object;
	var parentCombo = document.getElementById(parentComboId).object;
    	
	childCombo.SetEnabled(true);
	childCombo.GetList().Clear();
	
	var selectedID = document.getElementById(parentControl + "_txtSelectedID").value;	
	var dataSourceUrl = childCombo.GetList().GetDatasourceUrl();
	
	document.getElementById(parentControl + "_btnEdit").disabled = false;
	
	var regex=  new RegExp("OwnerID=[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}");
	dataSourceUrl = dataSourceUrl.replace(regex,'OwnerID=' + selectedID);
	
	childCombo.GetList().SetDatasourceUrl(dataSourceUrl);
	childCombo.GetList().GetPage(0,50,"");	
	childCombo.GetList().SetSelectedRowIndex(-1);
	childCombo.GetTextBox().SetValue("");
	
	document.getElementById(childControl + "_btnNew").disabled = false;
	document.getElementById(childControl + "_btnEdit").disabled = true;
	document.getElementById(childControl + "_txtOwnerID").value = selectedID;
	document.getElementById(childControl + "_txtSelectedID").value = "";
}

var popup;
function ShowHelp(sender, applyFilters)
{				
	//if there are any other popups open close them now
	if(popup)
		HideHelp();
	else
	{
		var loc = getMouseLoc();
		//var loc = getObjLoc(sender);
	
		//get the help msg for this link
		popup = document.getElementById(sender.HelpPanelID);	
		
		if(!popup)
		    return;
		    
		//if(popup.parentElement.tagName == "LEGEND")		
		document.getElementsByTagName("body").item(0).appendChild(popup);
        popup.style.width = popup.width;
        
		if(applyFilters && popup.filters != null && popup.filters.length > 0)
			popup.filters[0].apply();
	
		popup.style.position = "absolute";		
		popup.style.top = loc.y;
		popup.style.left = loc.x;
		popup.style.display = "block";
		popup.style.visibility = "visible"
		
		if(applyFilters && popup.filters != null && popup.filters.length > 0)
			popup.filters[0].play();
	
	}
}

function HideHelp(applyFilters)
{	
	if(popup)
	{			
		if(applyFilters && popup.filters != null && popup.filters.length > 0)
			popup.filters[0].apply();

		popup.style.visibility = "hidden";

		if(applyFilters && popup.filters != null && popup.filters.length > 0 )
			popup.filters[0].play();				
		
		popup = null;
	}
}

function getMouseLoc() {
	var x;
	var y;

	x = event.clientX + document.body.scrollLeft;
	y = event.clientY + document.body.scrollTop;

	var loc = new Object();
	loc.x = x + 12;
	loc.y = y + 10;
	return loc;
}

//not used but could be useful
function getCenter()
{
	var clientHeight;
	var clientWidth;
	var docTop;
	var docLeft;	

	clientHeight = document.body.clientHeight;
	clientWidth = document.body.clientWidth;
	docTop = document.body.scrollTop;
	docLeft = document.body.scrollLeft;
    
	var loc = new Object();
	loc.x = docLeft + clientWidth/2;
	loc.y = docTop + clientHeight/2;
	return loc;
}

function getObjLoc(obj)
{
	var objTop = obj.offsetTop;
	var objLeft = obj.offsetLeft;
	var clientWidth= obj.offsetWidth;
	var clientHeight= obj.offsetHeight;		

	var loc = new Object();
	loc.x = objLeft + clientWidth;
	loc.y = objTop + clientHeight;
	return loc;
}

function fireOnChange(field)
{
	// If FireFox fireEvent does not work
	if(navigator.userAgent.indexOf("Firefox") != -1)
	{
		var e = document.createEvent('HTMLEvents');
		e.initEvent('change', false, false);
		field.dispatchEvent(e);
	}
	else
		field.fireEvent("onchange");
}
