
/******************************************************************************************************************************************************************************/
/*	Author:	Greg Rechtin
/*	Create:	04/21/2008
/*	App:		Everything Greg Does
/*	includes general variables and functions. Mostly manages formatting of text
/******************************************************************************************************************************************************************************/
/******************************************************************************************************************************************************************************/
/*	NOTE: Naming conventions for variables "global/page"-"datatype"-"VariableName" 
/*		global/page
/*			"p"		global variables declared in page
/*			"g"		global variables declared in include file
/*		datatype
/*			"ary"	array
/*			"b"		boolean
/*			"chr"	single character string
/*			"dt"		date/time
/*			"int"		integer
/*			"str"		string
/*		VariableName
/*			names cleary describe variable use; initial caps, no space, no underscore
/******************************************************************************************************************************************************************************/


/******************************************************************************************************************************************************************************/
/*					standard constants																					*/
/******************************************************************************************************************************************************************************/


/******************************************************************************************************************************************************************************/
/*					standard variables																					*/
/******************************************************************************************************************************************************************************/

var garyMonths		= ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var garyDays			= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var gstrURLParams		= document.location.search.substring(1);																	//	capture any parameters that might be in a query string


/******************************************************************************************************************************************************************************/
/*					standard files																						*/
/******************************************************************************************************************************************************************************/

//document.write('<SCRIPT LANGUAGE="JavaScript" SRC="/include/js/date-picker.js"></SCRIPT>');									//	Location of pop-up calendar/date picker


/******************************************************************************************************************************************************************************/
/*					standard functions																					*/
/******************************************************************************************************************************************************************************/
/*
function list()																											//	for easy documentation
{
	function dateString(dateObj,style)																						//	returns date in specified  format
	function numValue(strValue)																							//	convert field string to integer
	function formatText(strValue,style)																						//	format text in certain style
	function noSpace(frmField)																							//	removes all blank space from string
	function trimNCap(frmField)																							//	call trim and capitalize functions
	function trim(frmField)																								//	trims blank space at beginning and end of string
	function capitalize(str)																								//	format string with Initial Caps
	function selectOption(ddlField,strValue)																					//	select drop down box to preset value
	function trimToLower(frmField)
	function trimToUpper(frmField)
}	
*/

function dateString(dateObj,style)
{
	var temp	= "";
	var day	= dateObj.getDate();
	var month	= dateObj.getMonth()+1;

	if (month < 10)
		month	= "0" + month;
	if (day < 10)
		day		= "0" + day;

	switch(style)
	{
		case "short":
			temp = month + "/" + day + "/" + dateObj.getFullYear();
			break;
		case "long":
			temp = garyDays[dateObj.getDay()] + ", " + garyMonths[dateObj.getMonth()] + " " + dateObj.getDate() + ", " + dateObj.getFullYear();
			break;
		case "foot":
			temp = dateObj.getDate() + " " + garyMonths[dateObj.getMonth()] + " " + dateObj.getFullYear();
			break;
		default:
			temp = garyMonths[dateObj.getMonth()].substring(0,3) + " " + dateObj.getDate() + ", " + dateObj.getFullYear();
			break;
	}

	return(temp);
}

function numValue(strValue)
{
	if (strValue.indexOf(".") != -1)
		return 0;

	var intReturnVal	= parseInt(strValue,10);
		
	if (!isNaN(intReturnVal))
		return intReturnVal;
	else
		return 0;
}

function formatText(strValue,style)
{
	var strTemp	= "";

	switch(style)
	{
		case "$":													//	money
			strTemp	= ".00";
			if(strValue == "")
				strTemp = "0" + strTemp;
			else
				for(var i = strValue.length; i > 0; --i)
				{
					if(i != strValue.length && (strValue.length - i) % 3 == 0)	//	not before ones and every 3 places
						strTemp = "," + strTemp;
					strTemp = strValue.charAt(i-1) + strTemp;
				}
			if(parseInt(strTemp) < 0)
				strTemp.fontcolor("#FF0000")
			break;
		case "%":													//	percent
			var intTemp =	Math.round(strValue * 10000) / 100;
			if(intTemp > 100)
				strTemp.fontcolor("#FF0000")
			strTemp = intTemp + " %";
			break;
		default:													//	alpha-numeric
			break;
	}
	return strTemp;
}

function noSpace(frmField)
{
	var str	= frmField.value;
	var temp	= "";

	for(var i = 0; i < str.length; i++)
		if(str.charAt(i) != " ")
			temp += str.charAt(i);
	frmField.value = temp;
}

function trimNCap(frmField)
{
	trim(frmField);
	frmField.value	= capitalize(frmField.value);
}

function trimToUpper(frmField)
{
	trim(frmField);
	frmField.value	= frmField.value.toUpperCase();
}

function trimToLower(frmField)
{
	trim(frmField);
	frmField.value	= frmField.value.toLowerCase();
}

function trim(frmField)
{
	var str = frmField.value;

	while(str.length > 0 && str.charAt(0) == " ")							//	trim leading space
		str = str.substring(1);
	while(str.length > 0 && str.charAt(str.length-1) == " ")					//	trim trailing space
		str = str.substring(0,str.length-1);
	frmField.value = str;
}

function capitalize(str)
{
//	and, of toLowerCase
//	VP, CEO, CFO, COO, EVP, NA toUpperCase
	var tmp	= str.charAt(0).toUpperCase();

	for(var i = 1; i < str.length; i++)
	{
		if(str.charAt(i-1) == " ")
			tmp	+= str.charAt(i).toUpperCase();
		else
			tmp	+= str.charAt(i).toLowerCase();
	}

	return tmp;
}

function selectOption(ddlField,strValue)
{
	var count	= 0;
	var flag	= false;
	while(count < ddlField.options.length && ddlField.options[count].value != strValue)
		count++;
	if(count == ddlField.options.length)
		count = 0;
	else
		flag = true;

	ddlField.selectedIndex	= count;
	return flag;
}

