
//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code to check for w3c dom level 1 support
//----------------------------------------------------------------------------

function supported()
{
	if (!(document.getElementById && document.getElementsByTagName)) 
		return false;
	else
		return true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getParameter ( queryString, parameterName ) 
{
	if (queryString == "") queryString = top.location.href;

    // Add "=" to the parameter name (i.e. parameterName=value)
    var parameterName = parameterName + "=";
    if ( queryString.length > 0 ) 
    {
        // Find the beginning of the string
        begin = queryString.indexOf ( parameterName );
        // If the parameter name is not found, skip it, otherwise return the value
        if ( begin != -1 ) 
        {
            // Add the length (integer) to the beginning
            begin += parameterName.length;
            // Multiple parameters are separated by the "&" sign
            end = queryString.indexOf ( "&" , begin );
            if ( end == -1 ) 
            {
                end = queryString.length
            }
            // Return the string
            return unescape ( queryString.substring ( begin, end ) );
        }
        
        // Return "null" if no parameter has been found
        return "null";
    }
}

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;  

  if (el.className == null)
    return;    

  // Remove the given class name from the element's className property.
  
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

//---------------------------------------------------------------------------
// Popup's
//---------------------------------------------------------------------------

function OpenWindow(strURL, strName, strStyle, blnShowModal) {
 
	var x,y;
	x = (self.screen.availWidth / 2);
	y = (self.screen.availHeight / 2);
	
	strDefaultStyle = " left=300, top=300";
	
	if (blnShowModal == true) 
	{
		if (Browser.isIE)
		{
			//window.showModalDialog("SMD_target.htm","Dialog Box Arguments # 1","dialogHeight: 237px; dialogWidth: 554px; dialogTop: 155px; dialogLeft: 481px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
			//var arr = showModalDialog("/Components/HTMLBox/goimage.asp","","dialogWidth:30em; dialogHeight:34em" );	
		}
		else
		{
			newwindow=window.open(strURL, strName, strStyle + strDefaultStyle);
			if (window.focus) {newwindow.focus()}
		}
	}
	else 
	{
		newwindow=window.open(strURL, strName, strStyle);
		if (window.focus) {newwindow.focus()}
	}

}

function calendarPopup (button, fieldId) {

	var x,y;
	x = getPageOffsetLeft(button);
	y = (self.screen.availHeight / 2);

  // For IE, adjust position.

	if (browser.isIE) {
	    x += button.offsetParent.clientLeft;
	    y += button.offsetParent.clientTop;
	}
	
	calendar_window=window.open('/common/aspx/calendarPopup.aspx?formname=' + fieldId,'calendar_window','width=200,height=178,left='+x+', top='+y+'');
	calendar_window.focus();

}

//----------------------------------------------------------------------------
// Code for listing grids 
//----------------------------------------------------------------------------

function confirmDelete()
{
	var agree=confirm("Are you sure you want to delete?");
	if (agree)
		return true ;
	else
		return false ;
}
	
function gridItem_Hightlight_Check(E) {

	var TR
	TR = E
		
	if (supported) {
		while (TR.tagName!="TR")
		{TR=TR.parentNode;}
		
	if (TR.className!="H" && TR.className!="HlDel")
		hL(E);
	else
		dL(E);
		
	}
}

function ListItem_HL(E, newClassName) {

	var TR
	TR = E

	if (supported) {
		while (TR.tagName!="TR")
		{
			//if it's a table it's ok too. 
			if (TR.tagName=="TABLE") break; 
			
			// if not, keep climbing
			TR=TR.parentNode;
		}
		
		//alert(TR.className + " <- old | new -> " + newClassName);
		
		if (TR.className != "") TR.SavedClassName = TR.className;
		
		TR.className = newClassName;		

	}


}

function ListItem_HL_Clear(E)	{

	if (supported) {
	
		while (E.tagName!="TR")
		{
			//if it's a table it's ok too. 
			if (E.tagName=="TABLE") break; 
			
			// if not, keep climbing
			E=E.parentNode;
		}

		if ((E.SavedClassName) && (E.SavedClassName != ""))
		{
			E.className = E.SavedClassName;
			E.SavedClassName = "";
		}
		else
			E.className = "";

	}

}

function gridItem_Hightlight_Set(program, inName)
{
	//trace("tvV() in Util.js: START.", 2);
	program.savedClassName = program.className;
	program.className = inName;
}

function gridItem_Hightlight_Clear(program)
{
	//trace("tvX() in Util.js: START.", 2);
	program.className = program.savedClassName;
}

function btnDisableCheck(btn) 
{
	try {		
		if (Page_IsValid)
		{
			btn.disabled = false;	
		}
		else 
		{
			btn.disabled = true;
		}
	}
	catch(e) {}

}


var loadHandlerArray = null;
function RegisterOnLoad(handler)
{
	if ( handler == null ) return;
	if ( loadHandlerArray == null )
	{
		loadHandlerArray = new Array();
		if ( window.onload != null )
		{
			loadHandlerArray[0] = window.onload;
		}
		window.onload = OnLoadHandler;
	}
	
	loadHandlerArray[loadHandlerArray.length] = handler;
}
	
function OnLoadHandler()
{
	for (var length = loadHandlerArray.length; length > 0; length--)
	{
		var func = loadHandlerArray[length-1];func();
	}
}
