﻿<!-- 
// JScript File

	
/*
'==================================================================
'LTrim(string) : Returns a copy of a string without leading spaces.
'==================================================================
*/
function LTrim(str)
/*
'   PURPOSE: Remove leading blanks from our string.
'   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
/*      '// We have a string with leading blank(s)...*/

      var j=0, i = s.length;

/*      '// Iterate from the far left of string until we
      '// don't have any more whitespace...*/
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

/*      '// Get the substring from the first non-whitespace
      '// character to the end of the string...*/
      s = s.substring(j, i);
   }
   return s;
}

/*
'==================================================================
'RTrim(string) : Returns a copy of a string without trailing spaces.
'==================================================================
'*/
function RTrim(str)
/*'
'   PURPOSE: Remove trailing blanks from our string.
'   IN: str - the string we want to RTrim
'*/
{
/*   '// We don't want to strip JUST spaces, but also tabs,
   '// line feeds, etc.  Add anything else you want to
   '// "trim" here in Whitespace*/
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
/*      '// We have a string with trailing blank(s)...*/

      var i = s.length - 1;    /*   '// Get length of string */

/*      '// Iterate from the far right of string until we
      '// don't have any more whitespace...*/
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


 /*     '// Get the substring from the front of the string to
      '// where the last non-whitespace character is...*/
      s = s.substring(0, i+1);
   }

   return s;
}

/*'
'=============================================================
'Trim(string) : Returns a copy of a string without leading or trailing spaces
'=============================================================
'*/
function Trim(str)
/*'
   'PURPOSE: Remove trailing and leading blanks from our string.
   'IN: str - the string we want to Trim
   '
   'RETVAL: A Trimmed string!
'*/
{
   return RTrim(LTrim(str));
}

/*
'==================================================================
'function closePopupIfOrphaned()  ---  begins a timed interval to test if popup window has been orphaned
'function checkIfPopupIsOrphaned()  ---  Checks if this window is a popup which has been orphaned, then closes it
'==================================================================
'*/
	function closePopupIfOrphaned()
	{
		var intIntervalID = window.setInterval("checkIfPopupIsOrphaned();", 1500, "javascript");
		var intTimeoutID = window.setTimeout("window.close();", 3600000, "javascript");
	}
	function checkIfPopupIsOrphaned()
	{
		try
		{
/*			'//error occurs when the opener window has been closed */
			var objTestDoc = window.opener.document;
/*			'//error occurs if the opener window navigates away from our application */
			var strAppID = objTestDoc.forms[0].ctrl_ApplicationID.value;
		}
		catch (ex)
		{
			window.close();
		}
	}

	function closePopupIfParentChanges()
	{
		window.opener.AreYouMyParent = true;
		var intIntervalID = window.setInterval("checkIfPopupParentChanged();", 1500, "javascript");
		var intTimeoutID = window.setTimeout("window.close();", 3600000, "javascript");
	}
	function checkIfPopupParentChanged()
	{
		try
		{
/*			'//error occurs when the opener window has been closed*/
			var objTestDoc = window.opener.document;
/*			'//close me if the opener window navigates away from the original page*/
			if (window.opener.AreYouMyParent != true)
			{
				window.close();
			}
		}
		catch (ex)
		{
			window.close();
		}
	}
	
/*
'==================================================================
'openHelpWIndow(intTopicID) : opens a help topic in a popup window; returns handle to the window
'openHelpWIndowEx(intTopicID, strWindowFeatures) : opens a help topic in a popup window with the specified window features; returns handle to the window
'
'openHelpWindowSpecial(intTopicID, strWindowName, intHeight, intWidth, intTop, intLeft, blnIsStatusVisible, blnIsToolbarVisible, blnIsMenuVisible, blnIsResizable, blnIsScrollingEnabled)
'			gives full control over all features of opening the help window
'==================================================================
*/
var mstrStandardFeatures = 'left=100, top=100, height=400, width=590, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes';
var mstrHelpWindowName = "HelpWindow";
function openHelpWindow(intTopicID)
{
var strPage = "popup.aspx?Action=gethelp&id=" + intTopicID;
	var hWindow = window.open(strPage, mstrHelpWindowName, mstrStandardFeatures);
	hWindow.focus();
}
function openHelpWindowEx(intTopicID, strWindowFeatures)
{
/*	'//var strPage = "popup.aspx?Action=gethelp&id=" + intTopicID;*/
	var strPage = "../clientconnect/popup.aspx?Action=gethelp&id=" + intTopicID;	
	var hWindow = window.open(strPage, mstrHelpWindowName, strWindowFeatures);
	hWindow.focus();
}
function openHelpWindowSpecial(intTopicID, strWindowName, intHeight, intWidth, intTop, intLeft, blnIsStatusVisible, blnIsToolbarVisible, blnIsMenuVisible, blnIsResizable, blnIsScrollingEnabled)
{
/*	'//var strPage = "popup.aspx?Action=gethelp&id=" + intTopicID;*/
	var strPage = "../clientconnect/popup.aspx?Action=gethelp&id=" + intTopicID;
	var strWindowFeatures = new String();
/*	'//check height*/
	intHeight = parseInt(intHeight, 10);
	if (isNaN(intHeight) || intHeight < 100)
	{
		intHeight = 100;
	}
	else if (intHeight > screen.height)
	{
		intHeight = screen.height;
	}
/*	'//check width*/
	intWidth = parseInt(intWidth, 10);
	if (isNaN(intWidth) || intWidth < 100)
	{
		intWidth = 100;
	}
	else if (intWidth > screen.width)
	{
		intWidth = screen.width;
	}
/*	'//check top*/
	intTop = parseInt(intTop, 10);
	if (isNaN(intTop) || intTop < 0)
	{
		intTop = 0;
	}
	else if (intTop > screen.height - intHeight)
	{
		intTop = screen.height - intHeight;
	}
/*	'//check left*/
	intLeft = parseInt(intLeft, 10);
	if (isNaN(intLeft) || intLeft < 0)
	{
		intLeft = 0;
	}
	else if (intLeft > screen.width - intWidth)
	{
		intLeft = screen.width - intWidth;
	}
/*	'//set window size*/
	strWindowFeatures = "left=" + intLeft.toString() + ", top=" + intTop.toString() + ", height=" + intHeight.toString() + ", width=" + intWidth.toString() + ", "
	
/*	'//set status bar visibility*/
	if(blnIsStatusVisible)
	{
		strWindowFeatures += "status=yes, ";
	}
	else
	{
		strWindowFeatures += "status=no, ";
	}
/*	'//set toolbar visibility*/
	if(blnIsToolbarVisible)
	{
		strWindowFeatures += "toolbar=yes, ";
	}
	else
	{
		strWindowFeatures += "toolbar=no, ";
	}
/*	'//set menu visibility*/
	if(blnIsMenuVisible)
	{
		strWindowFeatures += "menubar=yes, ";
	}
	else
	{
		strWindowFeatures += "menubar=no, ";
	}
/*	'//set window border sizability*/
	if(blnIsResizable)
	{
		strWindowFeatures += "resizable=yes, ";
	}
	else
	{
		strWindowFeatures += "resizable=no, ";
	}
/*	'//set scrollbars visibility*/
	if(blnIsScrollingEnabled)
	{
		strWindowFeatures += "scrollbars=yes, ";
	}
	else
	{
		strWindowFeatures += "scrollbars=no, ";
	}
	
	var hWindow = window.open(strPage, strWindowName, strWindowFeatures);
	hWindow.focus();
}

	function openContactHSBWindow() {
		var strFeatures;
		var strPage;
		var hWindow;
		
		strFeatures = 'status,titlebar=no,toolbar=no,menubar=no,left=' + screen.width / 3 + ',top=' + screen.height / 3 + ',resizable,height=400,width=561'
		strPage = '../clientconnect/popup.aspx?Action=getcontacthsbemail'
		hWindow = window.open(strPage,"",strFeatures);
		hWindow.focus();
	}			

function normalizeNumber(amount,len)
{
	var objRegExp = '-|[A-z -+/:-@\$[-`{-~,]';
	var newamount;

	newamount=removeCharacters(amount, objRegExp);
	
	//remove leading zeros, if any
    while(newamount.length > 1 && newamount.substring(0,1) == '0')
    {
		newamount = newamount.substring(1,newamount.length);
    }
    newamount=newamount.substring(0,len);
	newamount=parseInt(newamount.toString());
	//if(isNaN(newamount))
	//    newamount=0;
	return newamount;
}

	function formatNumberWithCommas(fieldToFormat, amount, len)
	{
		newamount = normalizeNumber(amount, len);
		newamount = addCommas(newamount.toString());

		fieldToFormat.value=newamount;
		setPageIsDirty();
	}

	function formatCurrency(fieldToFormat, amount, len)
	{
		setPageIsDirty();

		if(amount=="") 
			return;

		newamount = normalizeNumber(amount,len);
		newamount = '$'+addCommas(newamount.toString());

		fieldToFormat.value=newamount;
		
		return newamount;
	}

	function addCommas( strValue ) {
	/************************************************
	DESCRIPTION: Inserts commas into numeric string.

	PARAMETERS:
	strValue - source string containing commas.

	RETURNS: String modified with comma grouping if
	source was all numeric, otherwise source is
	returned.

	REMARKS: Used with integers or numbers with
	2 or less decimal places.
	*************************************************/
	var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');

		//check for match to search criteria
		while(objRegExp.test(strValue)) {
		//replace original string with first group match,
		//a comma, then second group match
		strValue = strValue.replace(objRegExp, '$1,$2');
		}
	return strValue;
	}

	function removeCharacters( strValue, strMatchPattern ) {
	/************************************************
	DESCRIPTION: Removes characters from a source string
	based upon matches of the supplied pattern.

	PARAMETERS:
	strValue - source string containing number.

	RETURNS: String modified with characters
	matching search pattern removed

	USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd',
									'\s*')
	*************************************************/
	var objRegExp =  new RegExp( strMatchPattern, 'gi' );

	//replace passed pattern matches with blanks
	var newValue = strValue.replace(objRegExp,'');
	
	if(newValue=='')
	{
		newValue='0';
	}
	return newValue;
	 
	}

    function autotab(e,original,destination){
	if((e.keyCode>=48 && e.keyCode<=57) || (e.keyCode>=96 && e.keyCode<=105)){
		if (original.getAttribute && (original.value.length == original.getAttribute("maxlength") ) ) {
			destination.focus();
			if(destination.type == "text"){
				destination.select();
				}
			}
		}
	}
	
	function disableHyperLinks()
	{
	//var intIntervalID = window.setInterval("disableHyperLinks2();", 10, "javascript");
	    try	
	    {
		    var allLinks = document.all.tags("A");
		    for(i=0;i<allLinks.length;i++){
			    allLinks[i].onpaste = allLinks[i].href;	
			    allLinks[i].href = "#";	}				
	    }
	        catch(ex){}									
    }
    
    //generate a link to CompanyUsers List Page in Client Connection app.
	function getCompanyUsers(sUserName,sRoleTypeID,sSearchCompanyCode)
	{				
		var mstrStandardFeatures = 'left=100, top=100, width=' + (screen.width / 6) * 4 + ', height=' + (screen.height / 6) * 4 + ',  status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes';
		var mstrHelpWindowName = "HelpWindow";			
		var strPage = "../ClientConnect/popup.aspx?Action=getcompanyusers&usr=" + encodeURIComponent(sUserName) + "&rtid=" + encodeURIComponent(sRoleTypeID) + "&cmp=" + encodeURIComponent(sSearchCompanyCode);
		var hWindow = window.open(strPage, mstrHelpWindowName, mstrStandardFeatures);
		hWindow.focus();
	}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()		

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	
	if(isNaN(i)) { return ''; }
	
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];

	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);

//d comes up undefined?
//	if(d.length < 1) 
//	{ 
		amount = n; 
//	}
//	else 
//	{ 
//		amount = n + '.' + d; 
//	}
//	amount = minus + amount;

	return '$' + amount;
}
// end of function CommaFormatted()

function RoundtoTwoPlaces(amount) { 

  var ans = amount * 1000
  ans = Math.round(ans /10) + "" 
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
} 


function formatCurrencyAmt(fieldToFormat)
{

    if (!(isNaN(fieldToFormat.value)))
        {
        formatCurrency(fieldToFormat,fieldToFormat.value, 9)
        }
        
    setPageIsDirty();

}
//-->
