//this is just some functions that make things easisr

/**********************************************************************
*
*  tableDate()
*
*  Description: formats dates for text display,
*				returns the formatted date, or &nbsp if it is blank
*
*  Inputs: date (date)
*
*  Outputs: 
*
*  Returns: date (text)
*
************************************************************************/
function tableDate(dDate)
{
	if(dDate && typeof(dDate) == "string")
	{
		dDate = parseDate(dDate);

		if(isBlank(dDate))
		{
			dDate = "&nbsp";
		}
	}

	return(dDate);
}

/**********************************************************************
*
*  parseDate()
*
*  Description: formats dates for text display
*
*  Inputs: date (date)
*
*  Outputs: 
*
*  Returns: date (text)
*
************************************************************************/

function parseDate(dDate) 
{
	var tmpDate = "";
	if(dDate && typeof(dDate) == "string")
	{
		if(dDate.length > 0)
		{
			tmpDate = new Date(dDate);
			
			if(dDate.indexOf("1900") != -1)
			{ 
				dDate = "";
			}
			else
			{
				dDate = tmpDate.formatDate("MM/DD/YYYY");
			}
		}
	}

	return dDate;
}

/**********************************************************************
*
*  isBlank()
*
*  Description: Checks to see if the inputed value is null
*
*  Inputs: str
*
*  Outputs:
*
*  Returns: false if str is not null; true if str is null
*
************************************************************************/

function isBlank(str) 
{
	var tmpStr = "";

	if(str && typeof(str) == "string")
	{
		tmpStr = str.replace(/ /gi, '');
		return(tmpStr.length == 0);
	}
	else
	{
		return(true);
	}
}   

/**********************************************************************
*
*  str_isBlank()
*
*  Description: Checks to see if the inputed value is null or spaces
*
*  Inputs: str
*
*  Outputs:
*
*  Returns: false if str is not null; true if str is null
*
************************************************************************/

function str_isBlank() 
{
	return(isBlank(this.toString()));
}   

/**********************************************************************
*
*  parseQuoteStr()
*
*  Description: changes double quotes to single quotes
*
*  Inputs: toParse (text)
*
*  Outputs:
*
*  Returns: toParse (text)
*
************************************************************************/

function parseQuoteStr(toParse)
{
	if(toParse && typeof(toParse) == "string")
	{
		toParse = toParse.replace(/"/gi, "'");
	}

	return(toParse);
}

/**********************************************************************
*
*  parseQuoteCtrl()
*
*  Description: changes double quotes to single quotes
*
*  Inputs: ctrl (javascript control)
*
*  Outputs:	ctrl.value with double quotes changed to single quotes
*
*  Returns: 
*
************************************************************************/

function parseQuoteCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = parseQuoteStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  str_parseQuote()
*
*  Description: changes double quotes to single quotes
*
*  Inputs: this the string
*
*  Outputs:	
*
*  Returns: this.toString() with double quotes changed to single quotes
*
************************************************************************/

function str_parseQuote()
{
	return(parseQuoteStr(this.toString()));
}

/**********************************************************************
*
*  parseNewLine()
*
*  Description: changes newlines in text to <BR>
*
*  Inputs: toParse (text)
*
*  Outputs:
*
*  Returns: toParse (text)
*
************************************************************************/
function parseNewLine(toParse) 
{
	if(toParse && typeof(toParse) == "string")
	{
		toParse = toParse.replace(/\r/gi, "<BR>");
	}

	return(toParse);
}

/**********************************************************************
*
*  parseCRLF()
*
*  Description: changes crlf's in text to <BR>
*
*  Inputs: toParse (text)
*
*  Outputs:
*
*  Returns: toParse (text)
*
************************************************************************/
function parseCRLF(toParse) 
{
	if(toParse && typeof(toParse) == "string")
	{
		toParse = toParse.replace(/\r\n/gi, "<BR>");
	}

	return(toParse);
}

/**********************************************************************
*
*  parseBR()
*
*  Description: changes <BR> in text to crlf
*
*  Inputs: toParse (text)
*
*  Outputs:
*
*  Returns: toParse (text)
*
************************************************************************/
function parseBR(toParse) 
{
	if(toParse && typeof(toParse) == "string")
	{
		toParse = toParse.replace(/<BR>/gi, "\r\n");
	}

	return(toParse);
}


/**********************************************************************
*
*  isDigitStr()
*
*  Description: is it is number?
*
*  Inputs: str(string)
*
*  Outputs: 
*
*  Returns: true if it is a number and false for anything else
*
************************************************************************/
function isDigitStr(str)
{
	if(str && typeof(str) == "string")
	{
		if(!isBlank(str))
		{
			return(!isNaN(str));
		}
	}
	return(false);
}   

/**********************************************************************
*
*  isDigitCtrl()
*
*  Description: is it is number?
*
*  Inputs: ctrl(the js control)
*
*  Outputs: error if not a number, and sets that control.value to "" and puts focus there
*
*  Returns: true if it is a number or tbd or blank, and false for anything else
*
************************************************************************/
function isDigitCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			str = ctrl.value;
			if(!isBlank(str)) 
			{
				if(!isDigitStr(str))
				{
					alert("Please enter a numeric value only.\nCommas and other punctuation are not valid.");
					ctrl.value = "";
					ctrl.focus();
					return false ;
				}
			}
		}
	}
	return true;
}

/**********************************************************************
*
*  str_isNumeric()
*
*  Description: is it is number?
*
*  Inputs: this
*
*  Outputs: error if not a number, and sets that control.value to "" and puts focus there
*
*  Returns: true if it is a number or tbd or blank, and false for anything else
*
************************************************************************/
function str_isNumeric()
{
	return(isDigitStr(this.toString()));
}

/**********************************************************************
*
*  isFloatStr()
*
*  Description: is it is float?
*
*  Inputs: str(string)
*
*  Outputs: 
*
*  Returns: true if it is a float, and false for anything else
*
************************************************************************/
function isFloatStr(str)
{
	if(str && typeof(str) == "string")
	{
		if(!isBlank(str))
		{
			return((!isNaN(str)) && (str.indexOf(".") != -1));
		}
	}

	return(false);
}

/**********************************************************************
*
*  isFloatCtrl()
*
*  Description: is it is float?
*
*  Inputs: ctrl (javascript control)
*
*  Outputs: ctrl.value is blanked if it is not a float
*
*  Returns: true if it is a float, and false for anything else
*
************************************************************************/
function isFloatCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			if(!isFloatStr(ctrl.value))
			{
				alert(((isFloatCtrl.arguments.length > 1) ? isFloatCtrl.arguments[1] : "This") + " is not a Float value.\nPlease enter a float value.");
				ctrl.value = "";
				ctrl.focus();
			}
		}
	}
}

/**********************************************************************
*
*  str_isFloat()
*
*  Description: is it is float?
*
*  Inputs: this
*
*  Outputs: 
*
*  Returns: true if it is a float, and false for anything else
*
************************************************************************/
function str_isFloat()
{
	isFloatStr(this.toString());
}

/**********************************************************************
*
*  validateDate()
*
*  Description: is it is real date?
*
*  Inputs: mo, (int), da (int), ye(int)
*
*  Outputs: 
*
*  Returns: true or false
*
************************************************************************/
function validateDate(mo, da, ye)
{
	mo = stripZero(mo);
	da = stripZero(da);
	ye = stripZero(ye);

	if((parseInt(da, 10) < 1) || (parseInt(da, 10) > 31) || (parseInt(ye, 10) < 100) || (parseInt(ye, 10) > 9999))
	{
		return(false);
	}

	switch(parseInt(mo, 10))
	{
		//months with 31 days
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			//do nothing, already checked for > 31
		break;
		
		//month with weird # of days
		case 2:
			if ((((parseInt(ye, 10) % 4 == 0) && (parseInt(ye, 10) % 100 !=0)) || (parseInt(ye, 10) % 400 ==0)))
			{
				if(parseInt(da, 10) > 29)
				{
					return(false);
				}	
			}
			else
			{
				if(parseInt(da, 10) > 28)
				{
					return(false);
				}
			}

		break;

		//months with 30 days
		case 4:
		case 6:
		case 9:
		case 11:
			if (parseInt(da, 10) > 30)
			{
				return(false);
			}
		break;

		default:
			return(false);
		break; 
	}

	return(true);
}

/**********************************************************************
*
*  isDateLengthCtrl()
*
*  Description: is there any value in the ctrl?  If so is it a date?
*				if not put up an error if there is a value in the ctrl
*
*  Inputs: ctrl (js ctrl), ctrlTitle (string)
*
*  Outputs: nothing if it is 0 length or error message if length > 0
*			and it is not a date, it will return an error and put the
*			user back on the control
*
************************************************************************/
function isDateLengthCtrl(ctrl, ctrlTitle)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(!isDateLengthStr(ctrl.value))
		{
			alert("You must provide a valid Date value for " + ctrlTitle);
			ctrl.value = "";
			ctrl.focus();
			return;
		}
	}

	return;
}

/**********************************************************************
*
*  isDateLengthStr()
*
*  Description: is there any value in the str?  If so is it a date?
*				if not return false
*
*  Inputs: str (string)
*
*  Outputs: nothing
*
*  Returns: true or false
*
************************************************************************/
function isDateLengthStr(str)
{
	if(str && typeof(str) == "string")
	{
		if(str.length > 0)
		{
			if(isDateStr(str))
			{
				return(true);
			}
			else
			{
				return(false);
			}
		}
		else
		{
			return(true);
		}
	}
	else
	{
		return(true);
	}
}

/**********************************************************************
*
*  isDateStr()
*
*  Description: is it is real date?
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: true or false
*
************************************************************************/
function isDateStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = stripBlanksStr(str);

		if (!(str == "TBD" || str.length == 0 || isBlank(str)))
		{
			mo = "";
			da = "";
			ye = "";

			if(str.length == 8)
			{
				var mo = str.substr(0,2);
				var da = str.substr(2,2);
				var ye = str.substr(4,4);
			}
			else
			{
				var tmpSplitIsDateStr = str.split("/");
				var mo = tmpSplitIsDateStr[0];
				var da = tmpSplitIsDateStr[1];
				var ye = tmpSplitIsDateStr[2];
			}


			mo = stripZero(mo);
			da = stripZero(da);
			ye = stripZero(ye);

			if (str.length > 10 || isNaN(mo) || isNaN(da) || isNaN(ye)) 
			{
				return(false);
			}
			else
			{
				return(validateDate(mo, da, ye));
			}

		}
		else
		{
			return(false);
		}
	}
	else
	{
		return(false);
	}
}

/**********************************************************************
*
*  isDateCtrl()
*
*  Description: is it is real date?
*
*  Inputs: ctrl (a js control)
*
*  Outputs: error if not a date, and sets control.value to "" and puts focus there.
*
*  Returns: true if it is a date or tbd or blank, and false for anything else
*
************************************************************************/
function isDateCtrl(ctrl)
{
	var rc = true;

	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			if(!isDateStr(ctrl.value))
			{
				ctrl.value = "";
				ctrl.focus();

				alert("You must enter a valid date.\n\n\nThe valid format is \"mm/dd/yyyy\"");
			}
			else
			{
				return(true);
			}
		}
	}
	
	return(false);
}       

/**********************************************************************
*
*  str_isDate()
*
*  Description: is it is real date?
*
*  Inputs: 
*
*  Outputs: 
*
*  Returns: true if it is a date and false for anything else
*
************************************************************************/
function str_isDate(seperator, format)
{
	var tmpSplit = "";
	var formatSplit = "";
	var da = "", mo = "", ye = "";
	var i = 0;

	switch(str_isDate.arguments.length)
	{
		case 0:
			//assuming mm/dd/yyyy format
			return(isDateStr(this.toString()));
		break;

		case 1:
			//assuming mm/dd/yyyy format 
			//with a different seperator
			tmpSplit = this.toString().split(seperator);
			
			if(tmpSplit.length == 3)
			{
				return(validateDate(tmpSplit[0], tmpSplit[1], tmpSplit[2]));
			}
			else
			{
				return(false);
			}		
		break;

		case 2:
			//a different seperator and format
			//break up the format string with the seperator
			if(format.toLowerCase().indexOf("mm") == -1 || 
			   format.toLowerCase().indexOf("dd") == -1 ||
			   format.toLowerCase().indexOf("yyyy") == -1)
			{
				return(false);
			}
			else
			{
				tmpSplit = this.toString.split(seperator);
				formatSplit = format.split(seperator);
				
				for(i = 0; i < formatSplit.length; i++)
				{
					if(formatSplit[i].toLowerCase() == "mm")
					{
						mo = tmpSplit[i];
						continue;
					}
					else
					{
						if(formatSplit[i].toLowerCase() == "dd")
						{
							da = tmpSplit[i];
							continue;
						}
						else
						{
							if(formatSplit[i].toLowerCase() == "yyyy")
							{
								ye = tmpSplit[i];
								continue;
							}
						}
					}
				}//end for

				return(validateDate(mo, da, ye));
			}	
		break;

		default:
			//more args than I know what to do with
			return(false);
		break;
	}
}       

/**********************************************************************
*
*  isDateTimeStr()
*
*  Description: is it is real date time?
*
*  Inputs: str (string) representing the date time
*
*  Outputs: 
*
*  Returns: true if it is a valid date / time and false for anything else
*
************************************************************************/
function isDateTimeStr(str)
{
	var tmpSplit = "";

	if(str && typeof(str) == "string")
	{
		if(str.length > 0)
		{
			if(str.indexOf(" ") != -1)
			{
				tmpSplit = str.split(" ");
				return((isDateStr(tmpSplit[0]) && isTimeStr(tmpSplit[1])));
			}
		}
	}
	return(false);
}

/**********************************************************************
*
*  isDateTimeCtrl()
*
*  Description: is it is real date time?
*
*  Inputs: ctrl (js control) the text control
*		   [control name] optional value used in the error msg
*
*  Outputs: 
*
*  Returns: true if it is a valid date / time and false for anything else
*
************************************************************************/
function isDateTimeCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			if(!isDateTimeStr(ctrl.value))
			{
				alert(((isDateTimeCtrl.arguments.length > 1) ? isDateTimeCtrl.arguments[1] : "This") + " is not a valid date / time.");
				ctrl.value = "";
				ctrl.focus();
			}
		}
	}
}


/**********************************************************************
*
*  str_isDateTime()
*
*  Description: is it is real date time?
*
*  Inputs: this
*
*  Outputs: 
*
*  Returns: true if it is a valid date / time and false for anything else
*
************************************************************************/
function str_isDateTime()
{
	return(isDateTimeStr(this.toString()));
}


/**********************************************************************
*
*  isTimeCtrl()
*
*  Description: is it is real time?
*
*  Inputs: ctrl (js control) the text control
*
*  Outputs: 
*
*  Returns: true if it is a valid time and false for anything else
*
************************************************************************/
function isTimeCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			if(!isTimeStr(ctrl.value))
			{
				alert(((isTimeCtrl.arguments.length > 1) ? isTimeCtrl.arguments[1] : "This") + " is not a valid time.\nPlease Enter a valid time.");
				ctrl.value = "";
				ctrl.focus();
			}
		}
	}
}



/**********************************************************************
*
*  isTimeStr()
*
*  Description: is it is real time?
*
*  Inputs: str (string) the time text
*
*  Outputs: 
*
*  Returns: true if it is a valid time and false for anything else
*
************************************************************************/
function isTimeStr(str)
{
	var tmpSplit = "";

	if(str && typeof(str) == "string")
	{
		tmpSplit = str.split(":");

		for(var i = 0; i < tmpSplit.length; i++)
		{
			if(isNaN(tmpSplit[i]))
			{
				return(false);
			}
		}
		
		switch(tmpSplit.length)
		{
			case 1:
				if(tmpSplit[0] > 23 || tmpSplit[0] < 0)
				{
					return(false);
				}
			break;

			case 2:
				if((tmpSplit[0] > 23 || tmpSplit[0] < 0) ||
				   (tmpSplit[1] > 59 || tmpSplit[1] < 0))
				{
					return(false);
				}
			break;

			case 3:
				if((tmpSplit[0] > 23 || tmpSplit[0] < 0) ||
				   (tmpSplit[1] > 59 || tmpSplit[1] < 0) ||
				   (tmpSplit[2] > 59 || tmpSplit[2] < 0))
				{
					return(false);
				}
			break;

			case 4:
				if((tmpSplit[0] > 23 || tmpSplit[0] < 0) ||
				   (tmpSplit[1] > 59 || tmpSplit[1] < 0) ||
				   (tmpSplit[2] > 59 || tmpSplit[2] < 0) ||
				   (tmpSplit[3] > 999 || tmpSplit[3] < 0))
				{
					return(false);
				}
			break;

			default:
				return(false);
			break;
		}	
	}
	else
	{
		return(false);
	}
	
	return(true);
}

/**********************************************************************
*
*  getLastDayOfMonth()
*
*  Description: get the last day of the month
*
*  Inputs: year & month numbers
*
*  Returns: day number
*
************************************************************************/
function getLastDayOfMonth(nYear, nMonth)
{
	nYear = stripZero(nYear);
	nMonth = stripZero(nMonth);

    switch(parseInt(nMonth, 10))
    {
		//month with weird # of days
		case 2:
			if ((((parseInt(nYear, 10) % 4 == 0) && (parseInt(nYear, 10) % 100 !=0)) || (parseInt(nYear, 10) % 400 ==0)))
			{
                return(29);
			}
			else
			{
                return(28);
			}
        
		break;
        
		//months with 30 days
		case 4:
		case 6:
		case 9:
		case 11:
            return(30);
		break;
        
		//months with 31 days
		default:
            return(31);
		break; 
    }
}

/**********************************************************************
*
*  stripBlanksStr()
*
*  Description: removes blanks from the text
*
*  Inputs: str (text)
*
*  Outputs: 
*
*  Returns: str (text)
*
************************************************************************/
function stripBlanksStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = str.replace(/ /gi, '');
	}

	return(str);
}

/**********************************************************************
*
*  stripBlanksCtrl()
*
*  Description: removes blanks from the text
*
*  Inputs: ctrl (js control)
*
*  Outputs: ctrl.value - blanks
*
*  Returns: 
*
************************************************************************/
function stripBlanksCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = stripBlanksStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  str_stripBlanks()
*
*  Description: removes blanks from the text
*
*  Inputs: none
*
*  Outputs: 
*
*  Returns: 
*
************************************************************************/
function str_stripBlanks()
{
	stripBlanksStr(this.toString());
}

/**********************************************************************
*
*  parseName()
*
*  Description: if the name is over maxLength char, it puts out the first  
*				subLength and the last subLength of the string
*
*  Inputs: text (string), maxLength (int), subLength (int)
*
*  Outputs:
*
*  Returns: string
*
************************************************************************/
function parseName(text, maxLength, subLength)
{
	switch(parseName.arguments.length)
	{
		case 1:
			maxLength = text.length * .66;
			maxLength = Math.ceil(maxLength);
			subLength = (text.length / 3);
			subLength = Math.ceil(subLength);
		break;
		
		case 2:
			subLength = (text.length / 3);
			subLength = Math.ceil(subLength);
		break;

		case 3:
			//everything is passed in no problem
		break;
		
		default:
			return(text);
		break;
	}

	if(text && typeof(text) == "string")
	{
		if (parseInt(text.length, 10) > parseInt(maxLength, 10))
		{
			text = text.substring(0,parseInt(subLength, 10)) + "...." + text.substring((text.length-(parseInt(subLength, 10))),text.length);
		}
	}
	return(text);
}

/**********************************************************************
*
*  stripLeadingBlanksStr()
*
*  Description: strips the leading blanks off a field
*
*  Inputs: toStrip
*
*  Outputs:
*
*  Returns: toStrip
*
************************************************************************/
function stripLeadingBlanksStr(toStrip)
{
	if(toStrip && typeof(toStrip) == "string")
	{
		if(toStrip.length > 0)
		{
			if(stripLeadingBlanksStr.arguments.length == 1)
			{
				//this is a reg exp that says look for all leading white space
				//and replace it with nothing 
				toStrip = toStrip.replace(/^\s+/, '');
			}
			else
			{
				if(stripLeadingBlanksStr.arguments.length == 2)
				{
					if(typeof(stripLeadingBlanksStr.arguments[1]) == "string")
					{
						stripLeadingBlanksStr.arguments[1] = processSpecialChars(stripLeadingBlanksStr.arguments[1]);
						toStrip = eval("toStrip.replace(/^" + stripLeadingBlanksStr.arguments[1] + "+/, '')");
					}
				}
			}
		}
	}

	return(toStrip);
}

/**********************************************************************
*
*  stripLeadingBlanksCtrl()
*
*  Description: strips the leading blanks off a field
*
*  Inputs: ctrl (js control)
*
*  Outputs:	ctrl.value - leading white space
*
*  Returns: toStrip
*
************************************************************************/
function stripLeadingBlanksCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			switch(stripLeadingBlanksCtrl.arguments.length)
			{
				case 1:
					ctrl.value = stripLeadingBlanksStr(ctrl.value);
				break;
				
				case 2:
					ctrl.value = stripLeadingBlanksStr(ctrl.value, stripLeadingTrailingBlanksCtrl.arguments[1]);
				break;
				
				default:
				break;
			}
		}
	}
}

/**********************************************************************
*
*  stripTrailingBlanksStr()
*
*  Description: strips all trailing blanks off a string
*
*  Inputs: str
*
*  Outputs: 
*
*  Returns: str - trailing blanks
*
************************************************************************/
function stripTrailingBlanksStr(str)
{
	//strip blanks off the end of the string
	if(str && typeof(str) == "string")
	{
		if(str.length > 0)
		{
			if(stripTrailingBlanksStr.arguments.length == 1)
			{
				//this is a reg exp that says look for all leading white space
				//and replace it with nothing 
				str = str.replace(/\s+$/, '');
			}
			else
			{
				if(stripTrailingBlanksStr.arguments.length == 2)
				{
					if(typeof(stripTrailingBlanksStr.arguments[1]) == "string")
					{
						stripTrailingBlanksStr.arguments[1] = processSpecialChars(stripTrailingBlanksStr.arguments[1]);
						str = eval("str.replace(/" + stripTrailingBlanksStr.arguments[1] + "$/, '')");
					}
				}
			}
		}
	}

	return(str);
}

/**********************************************************************
*
*  stripTrailingBlanksCtrl()
*
*  Description: strips all trailing blanks off a string
*
*  Inputs: ctrl (js control)
*
*  Outputs: ctrl.value - trailing blanks
*
*  Returns: 
*
************************************************************************/
function stripTrailingBlanksCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			switch(stripTrailingBlanksCtrl.arguments.length)
			{
				case 1:
					ctrl.value = stripTrailingBlanksStr(ctrl.value);
				break;
				
				case 2:
					ctrl.value = stripTrailingBlanksStr(ctrl.value, stripTrailingBlanksCtrl.arguments[1]);
				break;
				
				default:
				break;
			}
		}
	}
}

/**********************************************************************
*
*  stripLeadingTrailingBlanksStr()
*
*  Description: strips leading and trailing blanks from a str
*
*  Inputs: str
*
*  Outputs: 
*
*  Returns: str - leading & trailing blanks
*
************************************************************************/
function stripLeadingTrailingBlanksStr(str)
{
	if(str && typeof(str) == "string")
	{
		if(stripLeadingTrailingBlanksStr.arguments.length == 1)
		{
			str = stripLeadingBlanksStr(str);
			str = stripTrailingBlanksStr(str);
		}
		else
		{
			if(stripLeadingTrailingBlanksStr.arguments.length == 2)
			{
				str = stripLeadingBlanksStr(str, stripLeadingTrailingBlanksStr.arguments[1]);
				str = stripTrailingBlanksStr(str, stripLeadingTrailingBlanksStr.arguments[1]);
			}
		}
	}

	return(str);
}

/**********************************************************************
*
*  stripLeadingTrailingBlanksCtrl()
*
*  Description: strips leading and trailing blanks from a ctrl
*
*  Inputs: ctrl (js control)
*
*  Outputs: ctrl.value - leading & trailing blanks
*
*  Returns: 
*
************************************************************************/
function stripLeadingTrailingBlanksCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			switch(stripLeadingTrailingBlanksCtrl.arguments.length)
			{
				case 1:
					ctrl.value = stripLeadingTrailingBlanksStr(ctrl.value);
				break;
				
				case 2:
					if(typeof(stripLeadingTrailingBlanksCtrl.arguments[1]) == "string")
					{
						ctrl.value = stripLeadingTrailingBlanksStr(ctrl.value, stripLeadingTrailingBlanksCtrl.arguments[1]);
					}
					else
					{
						ctrl.value = stripLeadingTrailingBlanksStr(ctrl.value);
					}
				break;
				
				default:
				break;
			}
		}
	}
}

/**********************************************************************
*
*  stripStr()
*
*  Description: strips pattern off of the leading or trailing ends or both
*
*  Inputs: str (string), pattern (string), ctrl (int)
*
*  Outputs: 
*
*  Returns: tmpStr - pattern on leading or trailing or both ends
*
*	pattern is the reg exp to remove from the string.
*
*	the ctrl values mean
*	0		strip leading blanks
*	1		strip trailing blanks
*	2		strip leading & trailing blanks
*	
************************************************************************/
function stripStr(tmpStr, pattern, ctrl)
{
	switch(stripStr.arguments.length)
	{
		case 0:
			pattern = "\s+";
			tmpStr = stripLeadingTrailingBlanksStr(tmpStr, pattern);
		break;

		case 1:
			tmpStr = stripLeadingTrailingBlanksStr(tmpStr, pattern);
		break;

		case 2:
			switch(parseInt(ctrl, 10))
			{
				case 0:
					tmpStr = stripLeadingBlanksStr(tmpStr, pattern);
				break;

				case 1:
					tmpStr = stripTrailingBlanksStr(tmpStr, pattern);
				break;

				case 2:
					tmpStr = stripLeadingTrailingBlanksStr(tmpStr);
				break;

				default:
					//do nothing;
				break;
			}
		break;

		default:
			//do nothing
		break;
	}

	return(tmpStr);
}
/**********************************************************************
*
*  stripCtrl()
*
*  Description: strips pattern off of the leading or trailing ends or both
*
*  Inputs: ctrl (js control), pattern (string), cntrl (int)
*
*  Outputs: 
*
*  Returns: tmpStr - pattern on leading or trailing or both ends
*
*	pattern is the reg exp to remove from the string.
*
*	the ctrl values mean
*	0		strip leading blanks
*	1		strip trailing blanks
*	2		strip leading & trailing blanks
*	
************************************************************************/
function stripCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			switch(stripCtrl.arguments.length)
			{
				case 1:
					ctrl.value = stripStr(ctrl.value);
				break;
				
				case 2:
					ctrl.value = stripStr(ctrl.value, stripCtrl.arguments[1]);
				break;
				
				case 3:
					ctrl.value = stripStr(ctrl.value, stripCtrl.arguments[1], stripCtrl.arguments[2]);
				break;
				
				default:
				break;
			}
		}
	}
}

/**********************************************************************
*
*  str_strip()
*
*  Description: strips pattern off of the leading or trailing ends or both
*
*  Inputs: this.value
*
*  Outputs: 
*
*  Returns: str - pattern on leading or trailing or both ends
*
*
*	the ctrl values mean
*	0		strip leading blanks
*	1		strip trailing blanks
*	2		strip leading & trailing blanks
*	
************************************************************************/
function str_strip()
{
	switch(str_strip.arguments.length)
	{
		case 0:
			return(stripStr(this.toString()));
		break;
		
		case 1:
			return(stripStr(this.toString(), str_strip.arguments[0]));
		break;

		case 2:
			return(stripStr(this.toString(), str_strip.arguments[0], str_strip.arguments[1]));
		break;
		
		default:
			return(this.toString());
		break;
	}
}

/**********************************************************************
*
*  processSpecialChars()
*
*  Description: returns special characters correctly
*
*  Inputs: val
*
*  Outputs: 
*
*  Returns: val
*
************************************************************************/
function processSpecialChars(val)
{
	if(val && typeof(val) == "string")
	{
		switch(val)
		{
			case "/":
				val = "\\/";
			break;

			case "[":
				val = "\\[";
			break;

			case "\\":
				val = "\\\\";
			break;

			case "^":
				val = "\\^";
			break;

			case "$":
				val = "\\$";
			break;

			case "*":
				val = "\\*";
			break;

			case "+":
				val = "\\+";
			break;

			case ".":
				val = "\\.";
			break;

			case "?":
				val = "\\?";
			break;

			case "|":
				val = "\\|";
			break;

			case "{":
				val = "\\{";
			break;

			case "}":
				val = "\\}";
			break;

			case "(":
				val = "\\(";
			break;

			case ")":
				val = "\\)";
			break;

			default:
			break;							
		}
	}

	return(val);
}


/**********************************************************************
*
*  parseTableText()
*
*  Description: returns a &nbsp; if the val is blank
*
*  Inputs: val
*
*  Outputs: 
*
*  Returns: val
*
************************************************************************/
function parseTableText(val)
{
	if(val && typeof(val) == "string")
	{
		if(isBlank(val))
		{
			val = "&nbsp;";
		}
	}
	else
	{
		val = "&nbsp;";
	}

	return(val);
}

/**********************************************************************
*
*  isDBDate()
*
*  Description: checks to see if the date is blank, if so it puts 01/01/1900 in the field
*
*  Inputs: ctrl, a control
*
*  Outputs: ctrl.value = 01/01/1900 if it is blank
*
*  Returns: 
*
************************************************************************/
function isDBDate(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		val = stripBlanksStr(ctrl.value);


		if(val.length == 0 || val.toLowerCase() == "tbd" || val.toLowerCase() == "&nbsp;" || val.length < 10)
		{
			ctrl.value = "null";
		}
	}
}


/**********************************************************************
*
*  parseSingleQuoteStr()
*
*  Description: changes single quotes to \' so it can be displayed
*
*  Inputs: str
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function parseSingleQuoteStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = str.replace(/'/gi, "\\'");
	}

	return(str);
}

/**********************************************************************
*
*  stripZero()
*
*  Description: remove leading zero
*
*  Inputs: toStrip
*
*  Outputs: 
*
*  Returns: toStrip
*
************************************************************************/
function stripZero(toStrip)
{
	if(toStrip && typeof(toStrip) == "string")
	{
		if(toStrip.length > 0)
		{
			toStrip = toStrip.replace(/^0+/gi, '');
		}
	}

	return(toStrip);
}

/**********************************************************************
*
*  validatePercentCtrl()
*
*  Description: calls validatePercentStr() passing the value of the control.
*
*  Inputs: ctrl (ctrl)
*
*  Outputs: 
*
*  Returns: true or false
*
************************************************************************/
function validatePercentCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			if(!validatePercentStr(ctrl.value))
			{
				alert(((validatePercentCtrl.arguments.length > 1) ? validatePercentCtrl.arguments[1] : "This") + " is not a valid percentage.\nPlease enter a valid Percentage between 0 and 100.");
				ctrl.value = "";
				ctrl.focus();
			}
		}
	}
}

/**********************************************************************
*
*  validatePercentStr()
*
*  Description: validates that the 100 <= percent >= 0
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: true or false
*
************************************************************************/
function validatePercentStr(str)
{
	if(str && typeof(str) == "string")
	{
		if(isDigitStr(str))
		{
			if(parseFloat(stripZero(str.value)) > 100 || parseFloat(stripZero(str.value)) < 0)
			{
				return(false);
			}
		}
		else
		{
			return(false);
		}
	}
	else
	{
		return(false);
	}

	return(true);
}

/**********************************************************************
*
*  stripPhoneFormatCtrl()
*
*  Description: strips out the () & - from a formatted phone string
*
*  Inputs: val (ctrl)
*
*  Outputs:	sets ctrl.value = phone - formatting
*
*  Returns: 
*
************************************************************************/
function stripPhoneFormatCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = stripPhoneFormatStr(ctrl.value);
		}
	}
}


/**********************************************************************
*
*  stripPhoneFormatStr()
*
*  Description: strips out the () & - from a formatted phone string
*
*  Inputs: val (string)
*
*  Outputs:
*
*  Returns: val
*
************************************************************************/
function stripPhoneFormatStr(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/[^0-9 x]/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  str_stripPhoneFormat()
*
*  Description: strips out the () & - from a formatted phone string
*
*  Inputs: val (string)
*
*  Outputs:
*
*  Returns: val
*
************************************************************************/
function str_stripPhoneFormat()
{
	return(stripPhoneFormatStr(this.toString()));
}

/**********************************************************************
*
*  formatPhoneNumStr()
*
*  Description: puts the () & - in a 10 digit phone num
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function formatPhoneNumStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = stripPhoneFormatStr(str);
		if(str.length == 10)
		{
			var newStr = "";

			newStr = "(";
			newStr += str.substr(0, 3);
			newStr += ")";
			newStr += str.substr(3, 3);
			newStr += "-";
			newStr += str.substr(6, 4);

			str = newStr;
		}
	}

	return(str);
}				

/**********************************************************************
*
*  str_formatPhoneNumStr()
*
*  Description: puts the () & - in a 10 digit phone num
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function str_formatPhoneNumStr()
{
	return(formatPhoneNumStr(this.toString()));
}				

/**********************************************************************
*
*  formatPhoneNumCtrl()
*
*  Description: formats the control and puts in the () & - when 
*				on field change
*
*  Inputs: ctrl (ctrl)
*
*  Outputs: 
*
*  Returns: nothing, but sets the ctrl to the phone num plus () & -
*
************************************************************************/
function formatPhoneNumCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = formatPhoneNumStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  formatDateSlashesCtrl()
*
*  Description: puts the / in a Date
*
*  Inputs: ctrl (javascript control)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function formatDateSlashesCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = formatDateSlashesStr(ctrl.value);
		}
	}
}				


/**********************************************************************
*
*  formatDateSlashesStr()
*
*  Description: puts the / in a Date
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function formatDateSlashesStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = stripDateSlashesFormatStr(str);
		if(str.length == 8)
		{
			var newStr = "";

			newStr += str.substr(0, 2);
			newStr += "/";
			newStr += str.substr(2, 2);
			newStr += "/";
			newStr += str.substr(4);

			str = newStr;
		}
	}

	return(str);
}				

/**********************************************************************
*
*  stripDateSlashesFormatCtrl()
*
*  Description: puts the / in a Date
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function stripDateSlashesFormatCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = stripDateSlashesFormatStr(ctrl.value);
		}
	}
}				

/**********************************************************************
*
*  stripDateSlashesFormatStr()
*
*  Description: puts the / in a Date
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function stripDateSlashesFormatStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = stripNonNumeric(str);
	}

	return(str);
}				

/**********************************************************************
*
*  formatSSNStr()
*
*  Description: puts the - in a SSN
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function formatSSNStr(str)
{
	if(str && typeof(str) == "string")
	{
		str = stripSSNFormatStr(str);
		if(str.length == 9)
		{
			var newStr = "";

			newStr += str.substr(0, 3);
			newStr += "-";
			newStr += str.substr(3, 2);
			newStr += "-";
			newStr += str.substr(5);

			str = newStr;
		}
	}

	return(str);
}				

/**********************************************************************
*
*  formatSSNCtrl()
*
*  Description: formats the control and puts in the - 
*
*  Inputs: ctrl (ctrl)
*
*  Outputs: 
*
*  Returns: nothing, but sets the ctrl to the SSN plus  -
*
************************************************************************/
function formatSSNCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = formatSSNStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  str_formatSSN()
*
*  Description: puts the - in a 9 digit SSN
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function str_formatSSN()
{
	return(formatSSNStr(this.toString()));
}				

/**********************************************************************
*
*  stripSSNFormatStr()
*
*  Description: strips out the - from a formatted SSN
*
*  Inputs: val (string)
*
*  Outputs:
*
*  Returns: val
*
************************************************************************/
function stripSSNFormatStr(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/[^0-9]/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  stripSSNFormatCtrl()
*
*  Description: formats the control and puts in the - 
*
*  Inputs: ctrl (ctrl)
*
*  Outputs: 
*
*  Returns: nothing, but sets the ctrl to the SSN minus the '-'
*
************************************************************************/
function stripSSNFormatCtrl(ctrl)
{
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = stripSSNFormatStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  str_stripSSNFormat()
*
*  Description: strips out the - in a ssn
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: str
*
************************************************************************/
function str_stripSSNFormat()
{
	return(stripSSNFormatStr(this.toString()));
}				


/**********************************************************************
*
*  stripTwoSingleQuotes()
*
*  Description: changes '' to '
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with all '' changed to '
*
************************************************************************/
function stripTwoSingleQuotes(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/''/gi, "'");
	}

	return(val);
}

/**********************************************************************
*
*  makeTwoSingleQuotes()
*
*  Description: changes ' to ''
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with all ' changed to ''
*
************************************************************************/
function makeTwoSingleQuotes(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/'/gi, "''");
	}

	return(val);
}

/**********************************************************************
*
*  zeroToBlank()
*
*  Description: changes 0 to a space
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with 0 changed to a space
*
************************************************************************/
function zeroToBlank(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		if(val == 0)
		{
			val = "";
		}
	}

	return(val);
}

/**********************************************************************
*
*  blankToZero()
*
*  Description: changes space to a 0
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with space changed to a 0
*
************************************************************************/
function blankToZero(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		if(isBlank(val))
		{
			val = 0;
		}
	}

	return(val);
}

/**********************************************************************
*
*  stripGarbage()
*
*  Description: strips out all non alphanumeric characters
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with only alpha numeric
*
************************************************************************/
function stripGarbage(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/[^a-zA-Z0-9_#'\ \-]/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  stripFileGarbage()
*
*  Description: strips out all non alphanumeric characters
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with only alpha numeric
*
************************************************************************/
function stripFileGarbage(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/[^a-zA-Z0-9_\-\.]/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  stripCommentGarbage()
*
*  Description: strips out stuff that makes html & db barf
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with only alpha numeric
*
************************************************************************/
function stripCommentGarbage(val)
{
	if(val && (typeof(val) == "string" || typeof(val) == "number"))
	{
		val = val.replace(/[^a-zA-Z0-9_#' \-\+,\\\.()\$\@\!\=\&\*;:\{\}\?\]\[\/\>\<\%\|]/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  str_stripGarbage()
*
*  Description: strips out stuff that makes html & db barf
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val with only alpha numeric
*
************************************************************************/
function str_stripGarbage(val)
{
	if(str_stripGarbage.arguments.length == 0)
	{
		return(stripGarbage(this.toString()));
	}
	else
	{
		switch(parseInt(val, 10))
		{
			case 0:
				return(stripGarbage(this.toString()));
			break;

			case 1:
				return(stripFileGarbage(this.toString()));
			break;
		
			case 2:
				return(stripCommentGarbage(this.toString()));
			break;

			default:
				return(this.toString());
			break;
		}
	}
}

/**********************************************************************
*
*  stripSingleQuote()
*
*  Description: strips out all singlequotes
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: val without single quotes
*
************************************************************************/
function stripSingleQuote(val)
{
	if(val && typeof(val) == "string")
	{
		val = val.replace(/'/gi, '');
	}

	return(val);
}

/**********************************************************************
*
*  deselectAll()
*
*  Description: deselects all selected in a multiple list box
*
*  Inputs: sel (listbox)
*
*  Outputs: deselects all selected in a multiple list box
*
*  Returns: 
*
************************************************************************/
function deselectAll(sel)
{
	//check to see if sel exists
	if(sel && typeof(sel) == "object")
	{
		if(sel.type.indexOf("select") != -1)
		{
			if(sel.selectedIndex != -1)
			{
				for(i = 0; i < sel.length; i++)
				{
					sel[i].selected = false;
				}
				sel.selectedIndex = -1;
			}
		}
	}
}

/**********************************************************************
*
*  multiSelected()
*
*  Description: returns true if there are multiple selections
*
*  Inputs: sel (listbox)
*
*  Outputs: 
*
*  Returns: true if more than one is selected in a multi select lb
*
************************************************************************/
function multiSelected(sel)
{
	var groupCnt = 0;

	//check to see if sel exists
	if(sel && typeof(sel) == "object")
	{
		if(sel.type.indexOf("select") != -1)
		{
			if(sel.selectedIndex != -1)
			{
				for(i = 0; i < sel.length; i++)
				{
					if(sel[i].selected)
					{
						groupCnt++;
						if(groupCnt > 1)
						{
							break;
						}
					}
				}
			}
		}
	}

	return((groupCnt > 1) ? true : false);
}

/**********************************************************************
*
*  selectAll()
*
*  Description: selects all in a listbox
*
*  Inputs: sel (listbox)
*
*  Outputs: everything in listbox selected
*
*  Returns: 
*
************************************************************************/
function selectAll(sel)
{
	//check to see if sel exists
	if(sel && typeof(sel) == "object")
	{
		if(sel.type.indexOf("select") != -1)
		{
			for(i = 0; i < sel.length; i++)
			{
				sel[i].selected = true;
			}
		}
	}
}

/**********************************************************************
*
*  deleteAll()
*
*  Description: deletes all items in listbox
*
*  Inputs: sel (listbox)
*
*  Outputs: everything in listbox deleted
*
*  Returns: 
*
************************************************************************/
function deleteAll(sel)
{
	//check to see if sel exists
	if(sel && typeof(sel) == "object")
	{
		if(sel.type.indexOf("select") != -1)
		{
			for(i = (sel.length -1); i >= 0 ; i--)
			{
				sel.options[i] = null;
			}
		}
	}
}

/**********************************************************************
*
*  deleteSelected()
*
*  Description: deletes all Selected items in listbox
*
*  Inputs: sel (listbox)
*
*  Outputs: selected items in listbox deleted
*
*  Returns: 
*
************************************************************************/
function deleteSelected(sel)
{
	//check to see if sel exists
	if(sel && typeof(sel) == "object")
	{
		if(sel.type.indexOf("select") != -1)
		{
			for(i = (sel.length -1); i >= 0 ; i--)
			{
				if(sel[i].selected)
				{
					sel.options[i] = null;
				}
			}
		}
	}
}

/**********************************************************************
*
*  moveSelected()
*
*  Description: moves all Selected items in listbox to the 2nd listbox
*
*  Inputs: source (select), target (select)
*
*  Outputs: selected items in select moved from source to target
*
*  Returns: 
*
************************************************************************/
function moveSelected(source, target)
{
	var tmpOption = "";

	//check to see if sel exists
	if((source && typeof(source) == "object") &&
	   (target && typeof(target) == "object"))
	{
		if((source.type.indexOf("select") != -1) &&
		   (target.type.indexOf("select") != -1))
		{
			for(i = (source.length -1); i >= 0 ; i--)
			{
				if(source[i].selected)
				{
					tmpOption = new Option(source[i].text, source[1].value, false, true);
					target.options[target.length] = tmpOption;
					source.options[i] = null;
				}
			}
		}
	}
}



/**********************************************************************
*
*  stripNonNumeric()
*
*  Description: deletes all non numeric content of the string
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: string - everything non numeric
*
************************************************************************/
function stripNonNumeric(str)
{
	//check to see if str exists
	if(str && typeof(str) == "string")
	{
		str = str.replace(/[^0-9 .-]/gi, '');
	}

	return(str);
}


/**********************************************************************
*
*  notImplemented()
*
*  Description: alerts the user that the function is not implemented yet
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: 
*
************************************************************************/
function notImplemented(str)
{
	//check to see if str exists
	if(str && typeof(str) == "string")
	{
		alert("function " + str + " is not implemented yet");
	}
	else
	{
		alert("function is not implemented yet");
	}
}

/**********************************************************************
*
*  formatZipCtrl()
*
*  Description: formats a zipcode ctrl when the user changes the value
*
*  Inputs: ctrl (control)
*
*  Outputs: 
*
*  Returns: zip code formatted
*
************************************************************************/
function formatZipCtrl(ctrl)
{
	//check to see if ctrl exists
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = formatZipStr(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  formatZipStr()
*
*  Description: formats a zipcode str with the - in the 9 digit zip
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: zip code formatted
*
************************************************************************/
function formatZipStr(str)
{
	//check to see if ctrl exists
	if(str && typeof(str) == "string")
	{
		str = stripZipFormat(str);

		if(str.length > 5)
		{
			str = str.substr(0, 5) + "-" + str.substr(5);
		}
	}

	return(str);
}

/**********************************************************************
*
*  str_formatZipStr()
*
*  Description: formats a zipcode str with the - in the 9 digit zip
*
*  Inputs: 
*
*  Outputs: 
*
*  Returns: zip code formatted
*
************************************************************************/
function str_formatZipStr()
{
	var str = "";
	//check to see if this str has anything in it
	if(this.length > 0)
	{
		str = formatZipStr(this.toString());
	}

	return(str);
}

/**********************************************************************
*
*  stripZipFormat()
*
*  Description: strips out the - in a 9 digit zip just returns 9 digits
*
*  Inputs: str (string)
*
*  Outputs: 
*
*  Returns: zip code stripped of formatting
*
************************************************************************/
function stripZipFormat(str)
{
	//check to see if ctrl exists
	if(str && typeof(str) == "string")
	{
		str = str.replace(/[^0-9]/gi, '');
	}

	return(str);
}


/**********************************************************************
*
*  stripZipFormatCtrl()
*
*  Description: strips out the - in a 9 digit zip just returns the 9 digits
*
*  Inputs: ctrl (control)
*
*  Outputs: 
*
*  Returns: zip code formatted
*
************************************************************************/
function stripZipFormatCtrl(ctrl)
{
	//check to see if ctrl exists
	if(ctrl && typeof(ctrl) == "object")
	{
		if(ctrl.type.indexOf("text") != -1)
		{
			ctrl.value = stripZipFormat(ctrl.value);
		}
	}
}

/**********************************************************************
*
*  str_stripZipFormat()
*
*  Description: strips out the - in a 9 digit zip just returns 9 digits
*
*  Inputs: 
*
*  Outputs: 
*
*  Returns: zip code stripped of formatting
*
************************************************************************/
function str_stripZipFormat()
{
	return(stripZipFormat(this.toString()));
}


/**********************************************************************
*
*  stripUidPwd()
*
*  Description: strips out all non uid & pwd allowed stuff
*
*  Inputs: val (text)
*
*  Outputs: 
*
*  Returns: 
*
************************************************************************/
function stripUidPwd(val)
{
	if(val && typeof(val) == "string")
	{
		val = stripGarbage(val);
		val = stripSingleQuote(val);
		val = stripBlanksStr(val);
	}

	return(val);
}

/**********************************************************************
*
*  checkLength()
*
*  Description: checks the length of any control
*				but commonly used with text area's.
*
*  Inputs: ctrl (contrl), length (number), ctrlName (text)
*
*  Outputs: pops up an information window if the user types too many
*			characters in the text area.  then limits the ctrl to 
*			the specified length
*
*  Returns: 
*
************************************************************************/
function checkLength(ctrl, length, ctlName)
{
	if(ctrl.value.length > length)
	{
		alert(ctlName + " is limited to " + length + " characters");
		ctrl.value = ctrl.value.substr(0, length);
	}
}


/**********************************************************************
*
*  makeTwoDigit()
*
*  Description: makes the input passed in return 2 digits
*
*  Inputs: inStr
*
*  Outputs: 
*
*  Returns: either inStr or 0 + instr
*
************************************************************************/
function makeTwoDigit(inStr)
{
	if(inStr && (typeof(inStr) == "string" || typeof(inStr) == "number"))
	{
		if(parseInt(stripBlanksStr(inStr), 10) < 10 && stripBlanksStr(inStr).length == 1)
		{
			return("0" + stripBlanksStr(inStr));
		}
		else
		{
			return(inStr);
		}
	}
	else
	{
		return(inStr);
	}
}


/**********************************************************************
*
*  date_formatDate()
*
*  Description: formats a date to match the input picture
*
*  Inputs: formatPic (the pic of the date format), [dateVal] (optional date...
*		   if not included, will use this) 
*
*  Outputs: 
*
*  Returns: formatted date string
*
*  DATE FORMAT OPTIONS:
* 
*  dd   = 1 or 2-digit Day
*  DD   = 2-digit Day
*  mm   = 1 or 2-digit Month
*  MM   = 2-digit Month
*  yy   = 2-digit Year
*  YY   = 4-digit Year
*  yyyy = 4-digit Year
*  month   = Month name in lowercase letters
*  Month   = Month name in initial caps
*  MONTH   = Month name in captital letters
*  mon     = 3-letter month abbreviation in lowercase letters
*  Mon     = 3-letter month abbreviation in initial caps
*  MON     = 3-letter month abbreviation in uppercase letters
*  weekday = name of week in lowercase letters
*  Weekday = name of week in initial caps
*  WEEKDAY = name of week in uppercase letters
*  wkday   = 3-letter weekday abbreviation in lowercase letters
*  Wkday   = 3-letter weekday abbreviation in initial caps
*  WKDAY   = 3-letter weekday abbreviation in uppercase letters
*
*  hh	= hours in 12 hour format
*  HH	= hours in 24 hour format
*  min	= minutes
*  MIN	= minutes
*  ss	= seconds
*  SS	= seconds
*  ms   = milliseconds
*  MS   = milliseconds
*  AMPM = either the am or pm symbol
*
*  utchh = hours in 12 hour format universal time
*  UTCHH = hours in 24 hour format universal time
*  utcmin = minutes in universal time
*  UTCMIN = minutes in universal time
*  utcss = seconds in universal time
*  UTCSS = seconds in universal time
*  utcms = milliseconds in universal time
*  UTCMS = milliseconds in universal time
* 
*  Examples:
* 
*  calDateFormat = "mm/dd/yy";
*  calDateFormat = "Weekday, Month dd, yyyy";
*  calDateFormat = "wkdy, mon dd, yyyy";
*
************************************************************************/
function date_formatDate(formatPic)
{
	if(isNaN(this))
	{
		return("Date isNaN");
	}

	// GET CURRENTLY SELECTED LANGUAGE
	var selectedLanguage = navigator.language;
	var monthArray = "";
	var weekdayList = "";
	var datePic = "";

    // IF FRENCH
    if (selectedLanguage == "fr") {
        monthArray = new Array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin',
                               'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
        weekdayList  = new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
		datePic = "dd.mm.yyyy HH:mm:ss";
    }
    // IF GERMAN
    else if (selectedLanguage == "de") {
        monthArray = new Array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
                               'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
        weekdayList  = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
		datePic = "dd.mm.yyyy HH:mm:ss";
    }
    // IF SPANISH
    else if (selectedLanguage == "es") {
        monthArray = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
                               'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
        weekdayList  = new Array('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado')
		datePic = "dd.mm.yyyy HH:mm:ss";
    }
    // DEFAULT TO ENGLISH
    else {
        monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
        weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
		datePic = "mm/dd/yyyy HH:mm:ss";
    }

    // SET THE DATE RETURNED TO THE USER
    var day           = this.getDate();
    var month         = parseInt(this.getMonth(), 10) + 1;
    month			  = month.toString();
    var year          = this.getFullYear();
	var yearStr		  = year.toString();
    var monthString   = monthArray[parseInt(this.getMonth(), 10)];
    var monthAbbrev   = monthString.substring(0,3);
    var weekday       = weekdayList[parseInt(this.getDay(), 10)];
    var weekdayAbbrev = weekday.substring(0,3);
	var HOURS		  = this.getHours();
	var hours		  = ((parseInt(HOURS, 10) > 12) ? (parseInt(HOURS, 10) - 12) : HOURS);
	var minutes		  = makeTwoDigit(this.getMinutes().toString());
	var seconds		  = makeTwoDigit(this.getSeconds().toString());
	var milliSeconds  = makeTwoDigit(this.getMilliseconds().toString());
	var UTCHOURS	  = this.getUTCHours();
	var utchours	  = ((parseInt(UTCHOURS, 10) > 12) ? (parseInt(UTCHOURS, 10) - 12) : UTCHOURS);
	var utcminutes	  = makeTwoDigit(this.getUTCMinutes().toString());
	var utcseconds    = makeTwoDigit(this.getUTCSeconds().toString());
	var utcmilliSeconds = makeTwoDigit(this.getUTCMilliseconds().toString());
	var AMPM          = ((parseInt(HOURS, 10) > 12) ? "PM" : "AM");
	var UTCAMPM		  = ((parseInt(UTCHOURS, 10) > 12) ? "PM" : "AM");
	var UTCFlag       = ((formatPic.toLowerCase().indexOf("utc")) ? true : false);


	if(date_formatDate.arguments.length != 0)
	{
		if(!isBlank(date_formatDate.arguments[0]))
		{
			datePic = formatPic;
		}
	}

	if(datePic.indexOf("DD") != -1)
	{
		datePic = datePic.replace(/DD/g, makeTwoDigit(day.toString()));
	}
	else
	{
		if(datePic.indexOf("dd") != -1)
		{
			datePic = datePic.replace(/dd/g, day);
		}
	}

	if(datePic.indexOf("MM") != -1)
	{
		datePic = datePic.replace(/MM/g, makeTwoDigit(month.toString()));
	}
	else
	{
		if(datePic.indexOf("mm") != -1)
		{
			datePic = datePic.replace(/mm/g, month);
		}
	}

	if(datePic.toUpperCase().indexOf("YYYY") != -1)
	{
		datePic = datePic.replace(/YYYY/gi, year);
	}
	else
	{
		if(datePic.indexOf("YY") != -1)
		{
			datePic = datePic.replace(/YY/g, year);
		}
		else
		{
			if(datePic.indexOf("yy") != -1)
			{
				datePic = datePic.replace(/yy/g, yearStr.substr(2));
			}
		}
	}

	if(datePic.indexOf("month") != -1)
	{
		datePic = datePic.replace(/month/g, monthString.toLowerCase());
	}
	else
	{
		if(datePic.indexOf("Month") != -1)
		{
			datePic = datePic.replace(/Month/g, monthString);
		}
		else
		{
			if(datePic.indexOf("MONTH") != -1)
			{
				datePic = datePic.replace(/MONTH/g, monthString.toUpperCase());
			}
		}
	}

	if(datePic.indexOf("mon") != -1)
	{
		datePic = datePic.replace(/mon/g, monthAbbrev.toLowerCase());
	}
	else
	{
		if(datePic.indexOf("Mon") != -1)
		{
			datePic = datePic.replace(/Mon/g, monthAbbrev);
		}
		else
		{
			if(datePic.indexOf("MON") != -1)
			{
				datePic = datePic.replace(/MON/g, monthAbbrev.toUpperCase());
			}
		}
	}

	if(datePic.indexOf("weekday") != -1)
	{
		datePic = datePic.replace(/weekday/g, weekday.toLowerCase());
	}
	else
	{
		if(datePic.indexOf("Weekday") != -1)
		{
			datePic = datePic.replace(/Weekday/g, weekday);
		}
		else
		{
			if(datePic.indexOf("WEEKDAY") != -1)
			{
				datePic = datePic.replace(/WEEKDAY/g, weekday.toUpperCase());
			}
		}
	}

	if(datePic.indexOf("wkday") != -1)
	{
		datePic = datePic.replace(/wkday/g, weekdayAbbrev.toLowerCase());
	}
	else
	{
		if(datePic.indexOf("Wkday") != -1)
		{
			datePic = datePic.replace(/Wkday/g, weekdayAbbrev);
		}
		else
		{
			if(datePic.indexOf("WKDAY") != -1)
			{
				datePic = datePic.replace(/WKDAY/g, weekdayAbbrev.toUpperCase());
			}
		}
	}

	if(datePic.indexOf("utchh") != -1)
	{
		datePic = datePic.replace(/utchh/g, utchours);
	}
	else
	{
		if(datePic.indexOf("UTCHH") != -1)
		{
			datePic = datePic.replace(/UTCHH/g, makeTwoDigit(UTCHOURS.toString()));
		}
	}

	if(datePic.indexOf("hh") != -1)
	{
		datePic = datePic.replace(/hh/g, hours);
	}
	else
	{
		if(datePic.indexOf("HH") != -1)
		{
			datePic = datePic.replace(/HH/g, makeTwoDigit(HOURS.toString()));
		}
	}

	if(datePic.toLowerCase().indexOf("utcmin") != -1)
	{
		datePic = datePic.replace(/utcmin/gi, utcminutes);
	}

	if(datePic.toLowerCase().indexOf("min") != -1)
	{
		datePic = datePic.replace(/min/gi, minutes);
	}

	if(datePic.toLowerCase().indexOf("utcss") != -1)
	{
		datePic = datePic.replace(/utcss/gi, utcseconds);
	}

	if(datePic.toLowerCase().indexOf("ss") != -1)
	{
		datePic = datePic.replace(/ss/gi, seconds);
	}

	if(datePic.toLowerCase().indexOf("utcms") != -1)
	{
		datePic = datePic.replace(/utcms/gi, utcmilliSeconds);
	}

	if(datePic.toLowerCase().indexOf("ms") != -1)
	{
		datePic = datePic.replace(/ms/gi, milliSeconds);
	}

	if(datePic.toUpperCase().indexOf("AMPM") != -1)
	{
		datePic = datePic.replace(/AMPM/gi, ((UTCFlag) ? UTCAMPM : AMPM));
	}

	return(datePic);
}

/******************************************************************************
* Here is where we set up the function prototypes
*
* date_formatDate will allow every date to have the format date function
* str_isBlank will put isBlank on every string
* str_stripBlanks will put stripBlanks on every string
* strip will put strip on every string
* str_stripGarbage will put stripGarbage on every string
* str_stripPhoneFormat will strip out the phone formatting
* str_formatPhoneNumStr will put in the phone num formatting
* str_formatZipStr will put in zip code formatting
* str_stripSSNFormat will strip out the ssn formatting
* str_formatSSN will format a ssn
* str_isDate will validate a date field in mm/dd/yyyy format
* str_isNumeric will validate that a field is numeric
* str_parseQuote will change " to '
* str_isFloat will test to see if the value contained is float.
******************************************************************************/

Date.prototype.formatDate = date_formatDate;
String.prototype.isBlank = str_isBlank;
String.prototype.stripBlanks = str_stripBlanks;
String.prototype.strip = str_strip;
String.prototype.stripGarbage = str_stripGarbage;
String.prototype.stripPhoneFormat = str_stripPhoneFormat;
String.prototype.formatPhoneStr = str_formatPhoneNumStr;
String.prototype.formatZip = str_formatZipStr;
String.prototype.stripZipFormat = str_stripZipFormat;
String.prototype.stripSSNFormat = str_stripSSNFormat;
String.prototype.formatSSN = str_formatSSN;
String.prototype.isDate = str_isDate;
String.prototype.isDigit = str_isNumeric;
String.prototype.parseQuote = str_parseQuote;
String.prototype.isFloat = str_isFloat;
/******************************************************************************
here is some code to get today's date in a good format
******************************************************************************/
//some code to get todays date in a string
var today = new Date();
var ltTime = today.formatDate("HH:MIN");
var ltDate = today.formatDate("MM/DD/YYYY");

