
function showItemOn(strItem, strOn) 
{
	var x,y;
	
	var elItem = document.getElementById(strItem); 
	var elOn = document.getElementById(strOn); 
	
	if (!elItem) return;
	if (!elOn) return;

	x = getPageOffsetLeft(elOn) - 4;
	y = getPageOffsetTop(elOn) - 3;
			
	elItem.style.left = x + "px";
	elItem.style.top  = y + "px";
	
	elItem.style.visibility = "visible"; 
	
}


//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = 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 Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    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 ) 
{
    // 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";
    }
}


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();
	}
}


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;
}

//---------------------------------------------------------------------------
// General Form Utility Funcions
//---------------------------------------------------------------------------

function SearchListBox(txtSearch, lboxID)
{
	var lbox = document.getElementById(lboxID); 
	var sel = 0;

	// var parentForm = txtSearch;
	// Climb node tree until we find the parent form. 
	// No use for it now but just in case. 
	// while (parentForm.tagName != "FORM")
	// {
	//	parentForm = parentForm.parentNode;
	// }
	
	// if we can't get a clean object then it must be ASP.NET, 
	// let's find out path. 
	// watch out for case sensitivity

	if (!lbox) {
		tempID = txtSearch.getAttribute("id").replace("_Search", "");
		lbox = document.getElementById(tempID); 
	}	

	if (!lbox) return;

	if (txtSearch.value != "")
	{
		lbox.ItemCount = lbox.length;

		if (lbox.ItemCount > 0)
		{
			strSearch = txtSearch.value;
			lbox.options[sel].selected = false;
			for(i=0;i<lbox.ItemCount;i++)
			{
				if (strSearch.toUpperCase() == lbox.options[i].text.substring(0,strSearch.length).toUpperCase())
				{
					sel = i; 
					lbox.options[i].selected = true;
					i = lbox.ItemCount;
				}
			}
		}
	}
}

function LimitListBox(txtSearch, lboxID)
{
	var lbox = document.getElementById(lboxID); 
	var sel = 0;

	// var parentForm = txtSearch;
	// Climb node tree until we find the parent form. 
	// No use for it now but just in case. 
	// while (parentForm.tagName != "FORM")
	// {
	//	parentForm = parentForm.parentNode;
	// }
	
	// if we can't get a clean object then it must be ASP.NET, 
	// let's find out path. 
	// watch out for case sensitivity

	if (!lbox) {
		tempID = txtSearch.getAttribute("id").replace("_Search", "");
		lbox = document.getElementById(tempID); 
	}	

	if (!lbox) return;

	if (txtSearch.value != "")
	{
		lbox.ItemCount = lbox.length;

		if (lbox.ItemCount > 0)
		{
			strSearch = txtSearch.value;
			lbox.options[sel].selected = false;
			for(i=0;i<lbox.ItemCount;i++)
			{
				if (strSearch.toUpperCase() == lbox.options[i].text.substring(0,strSearch.length).toUpperCase())
				{
					sel = i; 
					lbox.options[i].selected = true;
					//i = lbox.ItemCount;
				}
				else 
				{
					lbox.options.remove; 
				}
			}
		}
	}
}

//---------------------------------------------------------------------------
// 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 SendPage() {
 
	var x,y;
	x = (self.screen.availWidth / 2);
	y = (self.screen.availHeight / 2);
	
	strStyle = "height=330, width=550, left=300, top=200";
	
	newwindow=window.open("/SendFriend.aspx?pageurl=" + location.href, "SendPage", 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();

}

function openImageBrowser (button, fieldId) {

	var x,y;
	x = getPageOffsetLeft(button);
	x = (self.screen.availWidth / 4);
	y = (self.screen.availHeight / 4);

  // For IE, adjust position.

	if (browser.isIE) {
	    x += button.offsetParent.clientLeft;
	    y += button.offsetParent.clientTop;
	}
	
	calendar_window=window.open('/common/aspx/imageBrowserPopup.aspx?formname=' + fieldId,'imageBrowserPopup','width=500,height=350,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 CCA(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 hL(E) {
	
	var TR
	TR = E
	
	if (supported) {
		while (TR.tagName!="TR")
		{TR=TR.parentNode;}

		//if's this is from the directory
		if (E.innerText == "Del")
			TR.className = "HlDel";
		else
			TR.className = "H";

	}


}

function dL(E)	{

	if (supported) {
		while (E.tagName!="TR")
		{E=E.parentNode;}

		E.className = "";

	}

}




