function get(n, d)
{
  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";
	}
	
	
function loading_indicator(object)
{
    var icon = new Image();
    icon.src = '/myfy/_images/icons/ajax_loading.gif';
    icon.className = "loading";
    object.appendChild(icon);
}


function move_div_to_mouse_position(div,e)
{
	//check what browser we're using:
	if ( detectBrowser() == "firefox" )
	{
		x = e.pageX;
		y = e.pageY;
	}
	else
	{
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
	}
	div.style.top = y;
	div.style.left = x;
}

function get_iframe_document( iframe_name )
{
	var iframe = get(iframe_name);
	if (iframe.document)
	{
		return iframe.document;
	}
	else
	{
		return iframe.contentDocument;
	}
		
}
function get_iframe_text( iframe_name )
{
	if (document.all)
		return get(iframe_name).document.body.innerText;
	else
	{
		return get(iframe_name).contentDocument.body.textContent;
	}
}

function check_file_type( file, filetype )
{
	return file.toLowerCase().lastIndexOf(filetype) > -1;
}
	function OpenPopup( sHref, sWindowName, nWidth, nHeight, sAttributes )
	{
		window.open( sHref, sWindowName, 'left=10,top=10,width=' + nWidth + ',height=' + nHeight + ',scrollbars=yes' + ( sAttributes ? ',' + sAttributes : '' ) );
	}
//***************************************************************** OLDER FUNCTIONS
//***************************************************************** NOT SURE WHERE THEY'RE USED
	//*****************************************************
	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");
		else
			oForm.submit();
	}
	
	/***************************************************************************
	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 getNodeValue(xml, nodeName)
    {
		if (xml.getElementsByTagName(nodeName) != null )
		{
			if ( xml.getElementsByTagName(nodeName)[0].childNodes.length > 0 )
				return xml.getElementsByTagName(nodeName)[0].childNodes[0].nodeValue;
			else
				return "";
		}
		else
			return "";
    }
    
    function _textToXml(text)
    {
		// code for IE
		var xml = null;
		if (window.ActiveXObject)
		{
			var xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.async="false";
			xml.loadXML(text);
		}
		// code for Mozilla, Firefox, Opera, etc.
		else
		{
			var parser=new DOMParser();
			xml = parser.parseFromString(text,"text/xml");
		}
		return xml;
	}
	
	function replaceUrls(content)
	{
		var regExp = new RegExp(/(http:\/\/|www\.)[^(\s|<)]*/g);
		var matches = content.match(regExp);
		for (var i = 0; i < matches.length; i++)
			content = content.replace(matches[i], "<a href=\"" + matches[0] + "\" target=\"_blank\">" + matches[0] + "</a>");
		return content;
	}