﻿// Global Javascript Library

function ShowStatusBar(displayText)
{
    window.status = displayText; 
}

function OpenPopUpWindow(theUrl, winName, features)
{
	fooWin = window.open(theUrl, winName, features)
	if(!fooWin){
	  alert("Please turn off your pop up blocker -- or refer to our Help section.");
	}
	else
	{
		fooWin.focus();
	}
}

function ConfirmDelete(msg)
{
	returnValue = confirm(msg);
	if(returnValue)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function CloseSelfAndRefreshParent()
{
	top.window.opener.location.reload();
	top.window.opener.focus();
	top.window.close();
}

function CloseSelf()
{
	top.window.opener.focus();
	top.window.close();
}

function CheckToolConsoleIsTop()
{
    CheckFrameIsTop("ToolConsole.aspx?page=home.aspx");
}

function CheckFrameIsTop(topFramePageUrl)
{
	if (parent.location.href == self.location.href) 
	{
		if (window.location.href.replace)
		{
			window.location.replace(topFramePageUrl);
		}
		else
		{
			// causes problems with back button, but works
			window.location.href = topFramePageUrl;
		}
	}
}

function BreakOutOfFrame()
{
	//check if in a frame
	if (top.location != location) 
	{
		top.location.href = document.location.href;
	}
	LoadPopupPageInOpener();
}

function LoadPopupPageInOpener()
{
	//check to see if popup
	if (window.opener != null)
	{
		window.opener.location.href = window.location.href;
		window.opener.focus();
		window.close();
	}
}

function GoToUrl(sHref)
{
	var i, args=GoToUrl.arguments; document.sReturnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function DisableControl(controlId, controlText)
{
  document.getElementById(controlId).disabled = true;
  document.getElementById(controlId).value = controlText;
}
 
function DisableControl_SetTimeout(controlId,interval, controlText)
{
  if(controlText == null)
  {
    controlText = "Processing...";
  }
  
  //need timeout in order to push/send POST before disable-ment.
  setTimeout("DisableControl('" +controlId + "', '" + controlText + "')",interval);
}

function ToggleVisibility(me)
{
    if (me.style.visibility=="hidden")
    {
	    me.style.visibility="visible";
	}
    else 
    {
	    me.style.visibility="hidden";
	}
}


function trim(value)
{
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   return temp;
}

function ToUppercase(value) 
{
    value = value.toUpperCase();
    return value;
}

function ProcessingImage(Control1, Control2,msg)
{
if(trim(msg) != "")
{ 
    if(confirm(msg)==true)
    {
     document.getElementById(Control1).style.display='block';
     document.getElementById(Control2).style.display='none';
     return true;
     }
    else 
    return false;
}
else
{
   document.getElementById(Control1).style.display='block';
   document.getElementById(Control2).style.display='none';
}
}

 function SelectAllCheckboxes(spanChk)
 {

   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
     {
       //elm[i].click();
       if(elm[i].checked!=xState)
       elm[i].click();
       //elm[i].checked=xState;
     }
 }

