//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------
function $el ( Id, Position )
{
  element = $e(Id);
  if ( element == null )
	{
		return 0;
	}
		
	if ( element.style && ( typeof ( element.style.left ) == 'string' )) 
	{
		if ( typeof ( Position ) == 'number' ) 
		{
			element.style.left = Position + 'px';
		}
		else 
		{
			Position = parseInt ( element.style.left );
			//if ( isNaN ( Position )) 
//				Position = 0;
		}
	}
	else if ( element.style && element.style.pixelLeft ) 
	{
		if ( typeof ( Position ) == 'number' ) 
			element.style.pixelLeft = Position;
		else Position = element.style.pixelLeft;
	}
	return Position;
}

function $eh ( Id, Size )
{
  element = $e(Id);
  if ( element == null )
	{
		return 0;
	}
		
	if ( element.style && ( typeof ( element.style.left ) == 'string' )) 
	{
		if ( typeof ( Size ) == 'number' ) 
		{
			element.style.height = Size + 'px';
		}
		else 
		{
			Size = parseInt ( element.style.height );
			if ( isNaN(Size) )
			{
			  Size = $e(element).clientHeght;
			}
			if ( isNaN(Size) )
			{
			  Size = $e(element).offsetHeight;
			}
		}
	}
	return Size;
}




// abstract the event source 
function GetEvent ( Sender )
{
	return ( Sender ) ? Sender : window.event;
}

// abstract the event target for browser

function GetTarget ( Sender )
{
	return ( Sender.target ) ? Sender.target : Sender.srcElement;
}

// simple helper to get a default value

function DefaultValue ( Source, Default )
{
	return ( Source ) ? Source : Default;
}

// abstract the removal of an event handler

function RemoveEvent ( EventName, EventMethod )
{
	if ( document.removeEventListener ) 
	{
		document.removeEventListener ( EventName, EventMethod, false )
	}
	else if ( document.detachEvent ) 
	{
		document.detachEvent ( EventName, EventMethod )
	}
}
// Handle the minimum operation whe there may be invalid values

function Min ( X, Y )
{
	if ( isNaN ( X ))
		return Y;
	if ( isNaN ( Y ))
		return X;
		
	return ( X < Y ) ? X : Y;
}

// Handle the maximum operation whe there may be invalid values

function Max ( X, Y )
{
	if ( isNaN ( X ))
		return Y;
	if ( isNaN ( Y ))
		return X;
		
	return ( X > Y ) ? X : Y;
}

// Bound a value between a lo and high bounds

function Bound ( Low, Current, High )
{
	return Min ( High, Max ( Current, Low ));
}


//This function allows only numeric values to be entered.
function CheckNumValue(e)
{
	var nVal=e.charCode? e.charCode : e.keyCode
		if (nVal!=8)						//if the key isn't the backspace key (which we should allow)
		{
			if (nVal<48||nVal>57)		   //if not a number
			return false				   //disable key press
		}
}


//Tool Tip 
function showtip(current,e,text)
{
	if (document.all)
	{
		thetitle=text.split('<br>')
		if (thetitle.length>1)
			{
				thetitles=''
				for (i=0;i<thetitle.length;i++)
				thetitles+=thetitle[i]
				current.title=thetitles
			}
		else
			current.title=text
	}
 }
		
function hidetip()
	{
		if (document.layers)
		document.tooltip.visibility="hidden"
	}

function RemoveAllRowsFromTable ( Table )
{
	while ( Table.rows.length > 0)
	{
		Table.deleteRow(0);
	}
}

function CreateCellWithHTML ( Row, CellID, HTML )
{
  var Cell = Row.insertCell(CellID);
  Cell.innerHTML = HTML;
}

function SetVisibility ( ElementName, Visibility )
{
	if( ElementName )
	{
		if ( typeof(ElementName) == "object" )
		{
			ElementName.style.visibility = Visibility;
		}
		else
		{
			if ( $e( ElementName ))
			{
				$e( ElementName ).style.visibility = Visibility;
			}
		}
	}
}

function Trim(TRIM_VALUE)
{
  if(TRIM_VALUE.length < 1)
  {
	return"";
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE=="")
  {
	return "";
  }
  else
  {
	return TRIM_VALUE;
  }
} //End Function


function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0)
  {
	return"";
  }
  var iTemp = v_length -1;

  while(iTemp > -1)
  {
	if(VALUE.charAt(iTemp) == w_space)
	{
	}
	else
	{
	  strTemp = VALUE.substring(0,iTemp +1);
	  break;
	}
	iTemp = iTemp-1;
  } //End While
  return strTemp;
} //End Function

function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1)
  {
	return"";
  }
  var v_length = VALUE.length;
  var strTemp = "";

  var iTemp = 0;

  while(iTemp < v_length)
  {
	if(VALUE.charAt(iTemp) == w_space)
	{
	}
	else
	{
	  strTemp = VALUE.substring(iTemp,v_length);
	  break;
	}
	iTemp = iTemp + 1;
  } //End While
  return strTemp;
} //End Function

function CancelEvent()
{
	event.returnValue = false;
	event.cancelBubble = true;
	
	return false;
}

function confirmYesNo(str, ttl)
{
	execScript('Result = msgbox("' + str + '", 36, "' + ttl + '")', "vbscript");
	return(Result == 6);
}