var firstWin = true;

function openWin(winURL, winName, winFeatures) 
{	
	if (navigator.appName.indexOf("Netscape") != -1)
	{ if (!firstWin)
		{ if (popupWin.document)
			{ popupWin.close(); }
		}
	}
	popupWin = window.open(winURL, winName, winFeatures);
	popupWin.focus();
	firstWin = false;
}

function jumpToElementAtCharLimit(elmCurrent, charLimit, nextElmId)
{
	try
	{
		if(elmCurrent.value.length == charLimit)
        {
			focusElement(nextElmId);
        }
	}
	catch(e)
	{
            
    }
}
    
function focusElement(elmName)
{
	try
	{
		var elmTarget = document.getElementById(elmName);
		elmTarget.focus();
		elmTarget.select();
    }
    catch(e)
    {
		// ignore error...
    }    
}

function getFormElementValue(id)
{
    try
    {
        var ctl;
        ctl = document.getElementById(id);
        if (typeof(ctl.value) == "string")
        {
            return ctl.value;
        }
        else
        {
            return "";
        }
    }
    catch(e)
    {
        // ignore error...
    }
}

function setFormElementValue(id,val)
{
    try
    {
        var ctl;
        ctl = document.getElementById(id);
        if (ctl != null)
        {
            if (val != null)
            {
                ctl.value = val;
            }
            else
            {
                ctl.value = "";
            }
        }
    }
    catch(e)
    {
        // ignore error...
    }

}

function TrimText(input) 
{
	var	str = input.replace(/^\s\s*/, '');
	var ws = /\s/;
	var i = str.length;
	
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function ShowSection(DivTag)
{
	document.getElementById(DivTag).style.visibility='visible';
}

function HideSection(DivTag)
{
	document.getElementById(DivTag).style.visibility='hidden';
}

function HelpWindow(name)
{
	var help_loc = 'help.htm' + '#' + name;
	HelpTextWindow=window.open(help_loc,'HelpTextWindow','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=590,height=450');
	HelpTextWindow.focus();
}

function tierMenu(objMenu,objImage)
{
   var menu = document.getElementById(objMenu);
   var image = document.getElementById(objImage);
   
   if (menu.style.display == "none")
   {
       menu.style.display = "";
       image.src = "Images/Icons/bullet_toggle_minus.gif";
   }
   else
   {
       menu.style.display = "none";
       image.src = "Images/Icons/bullet_toggle_plus.gif";
   }
}

function onUpdating(divName, divGridName){
    // get the update progress div
    var updateProgressDiv = $get(divName); 
    // make it visible
    updateProgressDiv.style.display = '';

    //  get the div gridview element        
    var gridView = $get(divGridName);
    
    // get the bounds of both the div gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    
    //    do the math to figure out where to position the element (the center of the div gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
    
    //    set the progress element to this position
    Sys.UI.DomElement.setLocation (updateProgressDiv, x, y);        
}

function onUpdated(divName) {
    // get the update progress div
    var updateProgressDiv = $get(divName); 
    // make it invisible
    updateProgressDiv.style.display = 'none';
}
