/*****************************
*   JavaScript Functions     *
******************************/

// Check for a valid email address
function isValidEmail( sEmail )
{
	var reFormatEmail = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;
	return reFormatEmail.test(sEmail);
}



// Trim leading and trailing characters from a string
function trim( sInputString, sRemoveChar )
{
	if ( sInputString == null )
		return null;

	if ( typeof sRemoveChar == 'undefined' )
	{
		sRemoveChar = ' ';
	}

	// Trim leading characters from input string
	while ( (sInputString.length > 0) && (sInputString.charAt(0) == sRemoveChar) )
	{
		sInputString = sInputString.substring(1, sInputString.length);
	}

	// Trim trailing characters from input string
	while ( (sInputString.length > 0) && (sInputString.charAt(sInputString.length - 1) == sRemoveChar) )
	{
		sInputString = sInputString.substring(0, sInputString.length - 1);
	}

	return sInputString;
}

//unescape back characters before displaying in a form field
function unEscapeChars( sString )
{
/*
 & --> &amp;  //Must be done first!
 < --> &lt;
 > --> &gt;
 " --> &quot;
 ' --> &#x27;  //&apos; is not recommended
 / --> &#x2F;  //forward slash is included as it helps end an HTML entity
*/

	sString = sString.replace(/&amp;/g,"&");
	sString = sString.replace(/&lt;/g,"<");
	sString = sString.replace(/&gt;/g,">");

	sString = sString.replace(/&quot;/g,'"');
	sString = sString.replace(/&#039;/g,"'");

	return sString;
}

function EscapeChars( sString )
{
	//sString = sString.replace(/&/g,"&amp;");
	sString = sString.replace(/</g,"&lt;");
	sString = sString.replace(/>/g,"&gt;");

	//sString = sString.replace(/&quot;/g,'"');
	//sString = sString.replace(/&#039;/g,"'");

	return sString;
}

// strip start and end tags from string
function stripStartEndTag( sString )
{
	return sString.replace(/[<>]/g, "")
}

function stripNonAlphaNum ( sString )
{
	//return sString.replace(/[^A-Za-z0-9]/g, " ");
	//return sString.replace(/[^A-Za-z0-9\/'_-]/g, " ");
	//return sString.replace(/[^A-Za-z0-9_-]/g, " ");
	return sString.replace(/[^A-Za-z0-9.,:\/'_-]/g, " ");
}




// Pop-up window
var XWin = null
Count = 0
var Name = "XWin"
function openXWin(URL, Width, Height){
  Name = "XWin" + Count++
  closeXWin()
   XWin = window.open(URL, Name, "width=" + Width + ",height=" + Height +",scrollbars,resizable")
}
function closeXWin(){
    if(XWin != null)
	if(!XWin.closed)
		XWin.close()
}