	function OpenPopup( sHref, sWindowName, nWidth, nHeight, sAttributes )
	{
		window.open( sHref, sWindowName, 'left=10,top=10,width=' + nWidth + ',height=' + nHeight + ',scrollbars=yes' + ( sAttributes ? ',' + sAttributes : '' ) );
	}
	//*****************************************************
	function OnUnload( sMessage )
	{
		window.event.returnValue = sMessage;
	}
	
	//*****************************************************
	function GetSelectedValue( oFormElement )
	{
		var sReturn = "";
		for ( var i = 0; i < oFormElement.length; i++ )
		{
			if ( oFormElement[i].selected )
			{
				if ( sReturn )
					sReturn += ", ";
					
				sReturn += oFormElement[i].value;
			}
		}
		
		return sReturn;
	}
	
	//*****************************************************
	function GetCheckedValue( oFormElement )
	{
		var sReturn = "";
		for ( var i = 0; i < oFormElement.length; i++ )
		{
			if ( oFormElement[i].checked )
				sReturn += oFormElement[i].value;
		}
		
		return sReturn;
	}

	//******************************************************************
	//  check for valid numeric strings
	function IsNumeric( sString )
	{
		var sValidCharacters = "0123456789";
		var sCharacter;
		var bReturn = true;
		
		if ( sString.length == 0)
			return false;
			
		//test strString consists of valid characters listed above
		for ( i = 0; i < sString.length && bReturn == true; i++ )
		{
			sCharacter = sString.charAt(i);
			if ( sValidCharacters.indexOf( sCharacter ) == -1 )
				bReturn = false;
      }
	  return bReturn;
   }
   
	function OnHoverRowColor( sDiv, sClass )
	{
//		eval("document.all." + sRowId + ".style.background = \"#" + sColor + "\";");
		eval("document.all." + sDiv + ".className = \"" + sClass + "\";");
	}
	
	function OnChangeDivClass( sDivId, sClass )
	{
		eval("document.all." + sDivId + ".className = \"" + sClass + "\";");
	}
	
	function OnChangeElementClass( oElement, sClass1, sClass2, bChecked )
	{
		if ( bChecked )
			sClass2 = sClass1;
			
		eval("document.all." + oElement + ".className = \"" + sClass2 + "\";");
	}
	
	function OnReloadFrame( sFrameName )
	{
		eval("parent.frames." + sFrameName+ ".location.reload();");
	}
		
	function OnChangeRowColor( sElementName, bChecked, sBackgroundColorOn, sBackgroundColorOff, bChangeFontColor )
	{
		//first check the status of the checkbox
		if ( bChecked )
		{
			//turn the cell on
			eval("document.all." + sElementName + ".style.background = \"#" + sBackgroundColorOn + "\"");
			if ( bChangeFontColor )
				eval("document.all." + sElementName + ".style.color = \"#000000\"");
		}
		else
		{
			//turn the cell off
			eval("document.all." + sElementName + ".style.background = \"#" + sBackgroundColorOff + "\"");
			if ( bChangeFontColor )
				eval("document.all." + sElementName + ".style.color = \"#999999\"");
		}
	}
	
	function BuildHref( sHref )
	{
		if ( sHref.indexOf("?") != -1 )
			sHref += "&";
		else
			sHref += "?";
		
		sHref += "u=" + gsUserLoginId;
		
		return sHref;
	}
	
	function OnSearch()
	{
		var oForm = document.forms.formSearch;
		
		if ( oForm.txtSearchWord.value.length < 3 )
		{
			alert("Please enter at least 3 characters to search on");
			return false;
		}
		else
			oForm.submit();
	}
	
	function SmartValidate( oForm, sElements )
	{
		var bValid = true;
		var aRequiredFields = sElements.split(",");
		
		var oCurrentObject = document.all[0];
		var sObjectType = "";
		
		//First check if the relevant fields are completed:
		for ( var i = 0; i < aRequiredFields.length; i++ )
		{
			var sTitle = aRequiredFields[i];
			
			//First get the type of Object from the Prefix 
			sObjectType = sTitle.substring( 0, sTitle.indexOf("|") );
			
			oCurrentObject = document.all[ sTitle.substring( ( sTitle.indexOf("|") + 1), sTitle.length ) ];
			
			if ( sObjectType == "r" ) //Radio Button
			{
				var bChecked = false;
				//Check if one of the buttons has been checked
				for ( var j = 0; j < oCurrentObject.length; j++ ) 
				{
					if ( oCurrentObject[j].checked )
					{
						bChecked = true
						break;
					}
				}
				
				if ( !bChecked )
				{
					bValid = false
					break;
				}
			}
			else if ( sObjectType == "sel" ) //Select Menu
			{
				if ( oCurrentObject.selectedIndex == 0 )
				{
					bValid = false;
					break;
				}
			}
			else if ( sObjectType == "txt" )  //Textfield
			{
				if ( oCurrentObject.value == "" )
				{
					bValid = false;
					break;
				}
			}
		}
		
		//Now if the form is not valid to continue, display the alert message
		if	( !bValid )
		{
			alert( "Please complete the required fields before submitting." );
			
			//Now got to the field that is not completed:
			if ( sObjectType == "r" )
				oCurrentObject[0].focus();
			else
				oCurrentObject.focus();
			
			return false;
		}
		//Form is valid to submit
		else
		{
			if ( confirm("Are you sure you are ready to submit this form?") )
				return true;
			else
				return false;
		}
	}

	/***************************************************************************/
	function InsertLineBreaks( sContent )
	{
		if ( sContent )
		{
			while( sContent.indexOf("\n") != -1 )
				sContent = sContent.replace( "\n", "<br>" );
			return sContent;
		}
	}

	/***************************************************************************/
	function RemoveQuotes( sContent )
	{
		if ( sContent )
		{
			while( sContent.indexOf("\"") != -1 )
				sContent = sContent.replace( "\"", "'" );
			return sContent;
		}
	}
	
	/***************************************************************************/
	var tempXmlHttp = null;
	function GetXmlDoc()
	{
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			tempXmlHttp = new XMLHttpRequest();
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			tempXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return tempXmlHttp;
	}
	
	function get(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=get(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function detectBrowser()
{
	if ( navigator.userAgent.indexOf("MSIE") > 0 )
		return "ie";
	else if ( navigator.userAgent.indexOf("Firefox") > 0 )
		return "firefox";
}