
function CheckNum(TargetObject)
{	
	str = TargetObject.value;		
	//alert(str + " - " + str.length );
	lastChar = str.substring(str.length-1,str.length);
		//alert(lastChar);
	if ( (lastChar=="0") || (lastChar=="1") || (lastChar=="2") || (lastChar=="3") || (lastChar=="3") || (lastChar=="4") || (lastChar=="5") || (lastChar=="6") || (lastChar=="7") || (lastChar=="8") || (lastChar=="9") || (lastChar=="-") )
	{
		//alert(lastChar);
		return;
	}
	else
	{		
		TargetObject.value = TargetObject.value.substring(0,str.length-1);
		//alert('New string val - ' + TargetObject.value )
	}
}

		

function showModalPopup(url)
{

			if (document.all)
			{
				var modalWidth = '450px';
				var modalheight = '450px';
				
				var confirmed = showModalDialog(url, modalWidth,'dialogWidth='+ modalWidth + ';dialogHeight='+ modalheight +';status=0');
				//alert(confirmed);
				
				if ( confirmed )
				{
					return true;
				}
				
			}
			// Netscape Navigator
			else
			{
				return true;
			}
			
			return false;
			
}


// -- enter key press --
function FundSearchClick()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].FindTickerSymbolButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
		// -- enter key press --
function SubSearchClick()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].FindSubButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
// -- enter key press --
function ForgotPassClick()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].SubmitButton.click();
				
			}
			else
			{
				return true;
			}
		
		}

// -- confirm delete --
function confirmDelete(controlIn){
    if (confirm("Are you sure you wish to permanently remove this item from record?")){
        eval(controlIn);
        }
    }
    
   // -- confirm add --
function confirmAdd(controlIn)
{
    
    if (confirm("Are you sure you wish to add this new customer?"))
    {
        eval(controlIn);   
        return true;             
    }       
    else
	{
		return false;
	}
        
}
    
// -- confirm delete --
function confirmRefund()
{
    if (confirm("Are you sure you wish to permanently remove this item from record?"))
    {
        return true;
    }
	else
	{
		return false;
	} 
   
 }
 
 
 // -- confirm delete --
function confirmHousehold()
{
    if (confirm("Are you sure you wish to remove this Relation?"))
    {
        return true;
    }
	else
	{
		return false;
	} 
   
 }
 
 // -- format social --    
function formatSocial(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, "(", "");
			num= replaceSubstring(num, ")", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 9)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="";
				var ini = num.substring(0,3);
				_return+=ini+"-";
				var st = num.substring(3,5);
				_return+=st+"-";
				var end = num.substring(5,9);
				_return+=end;
			}
			return _return; 
		} 
		
		
	// -- format social --    
function formatTIN(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, "(", "");
			num= replaceSubstring(num, ")", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length > 3)
			{ 				
				/* formating phone number here */ 
				_return="";
				var ini = num.substring(0,2);
				_return+=ini+"-";
				var st = num.substring(2);
				_return+=st;
			}
			return _return; 
		} 
    

// -- format phone number --    
function formatPhone(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, "(", "");
			num= replaceSubstring(num, ")", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 10)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="(";
				var ini = num.substring(0,3);
				_return+=ini+") ";
				var st = num.substring(3,6);
				_return+=st+"-";
				var end = num.substring(6,10);
				_return+=end;
			}
			return _return; 
		} 
	
	
	// REPLACE A SUBSTRING WITHIN A STRING
	function replaceSubstring(inputString, fromString, toString) 
	{
		// Goes through the inputString and replaces every occurrence of fromString with toString
		var temp = inputString;
		if (fromString == "") 
		{
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) 
		{ // If the string being replaced is not a part of the replacement string (normal situation)
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		else 
		{ // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";
			// Find a string that doesn't exist in the inputString to be used
			// as an "inbetween" string
			while (midString == "") 
			{
				for (var i=0; i < midStrings.length; i++) 
				{
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) 
					{
						midString = tempMidString;
						i = midStrings.length + 1;
					}
				}
			} // Keep on going until we build an "inbetween" string that doesn't exist
			// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			// Next, replace the "inbetween" string with the "toString"
			while (temp.indexOf(midString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} // Ends the check to see if the string being replaced is part of the replacement string or not
		return temp; // Send the updated string back to the user
	
	} // Ends the "replaceSubstring" function   