function OpenQuotesHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesAbout_Quotes.htm", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenNewUserHelp() {window.open("help/cs-help/WebHelp/stock_quotes/tell_me_about/QuotesWelcome.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenDetailedQuoteHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesDetailed_Quotes_Page.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenMultiQuotesHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesAbout_Quotes.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenLookupHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesQuotes_Ticker.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenQuoteIndexHelp() {window.open("help/cs-help/WebHelp/stock_quotes/tell_me_about/QuotesMarket_Indices_Page.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenPortfolioHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesAbout_Portfolio.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenEditPortfolioHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesAbout_Portfolio.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenDeletePortfolioHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/Quotes_Portfolio_Delete.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function FindTicker() {window.open("mini_lookup.jsp", "FindTicker", "width=477,height=300,menubar=0,toolbar=1,status=0,scrollbars=1")}

function checkQuotesInputBox () {
    var formObj = document.getquotes2;
    var inputtickers = formObj.TickerSymbols.value;
    inputtickers = inputtickers.replace(/^[ \t]* | [ \t]*$/g, "");
    if (inputtickers == "") {
        alert("Please enter a Ticker Symbol.");
        formObj.TickerSymbols.focus();
        return false;
    }
}

function OpenQuotesHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesAbout_Quotes.htm", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}
function OpenDetailedQuoteHelp() {window.open("help/cs-help/WebHelp/stock_quotes/how_do_i/QuotesDetailed_Quotes_Page.htm?include=0", "Help", "width=650,height=450,menubar=0,toolbar=1,status=0,scrollbars=yes,resizable=yes")}


//	Function:	hasValidTickerChars
//
//	Purpose:
//		Verifies that valid characters are used
//		for a ticker symbol.
//
//	Parameters:
//		ticker - stock ticker.
//
//	Return:
//		true (valid chars) or false (invalid chars).
//
function hasValidTickerChars(ticker)
{
	//	Make sure we got something.
	//
	if (ticker.length == 0)
		return false;

	//	Check for invalid characters.
	//
	var tickerFormat = /[^\w\*\.\:\@\+\$\ -]/;
	var tickerResult = ticker.match(tickerFormat);

	if (tickerResult != null)
		return false;

	//	Everything checks out.
	//
	return true;
}

//	Function:	isValidPortName
//
//	Purpose:
//		Verifies that valid characters are used
//		for a portfolio name.
//
//	Parameters:
//		name - a portfolio name.
//
//	Return:
//		true (valid chars) or false (invalid chars).
//
function isValidPortName(name)
{
	//	Make sure we got something.
	//
	if (name.length == 0)
		return false;

	//	Check for invalid characters.
	//
	var nameFormat = /[^'\w\(\)\:\*\.\$\/ -]/;
	var nameResult = name.match(nameFormat);

	if (nameResult != null)
		return false;

	//	Everything checks out.
	//
	return true;
}

//	Function:	validateNum
//
//	Purpose:
//		Verifies that input is a number and
//		is between 0.0 and 99999999.99999
//
//	Parameters:
//		num - a number to be validated.
//
//	Return:
//		true (valid number) or false (invalid number).
//
function validateNum(num)
{
	if (num.length == 0 || num.length > 14)
		return false;

	//	Make sure all numbers (or 1 period if a real) were used.
	//
	var numFormat = /^\d{0,8}\.\d{0,5}$|^\d{1,8}$/;
	var numResult = num.match(numFormat);

	if (numResult == null)
		return false;

	//	Everything checks out.
	//
	return true;
}

//	Function:	formatDate
//
//	Purpose:
//		Verifies that a date is valid and formats
//		it to mm/dd/yyyy or mm/dd/yy.
//
//	Parameters:
//		date - A date to be validated/formatted
//
//	Return:
//		Formatted date or empty string on error.
//
function formatDate(date)
{
	if (date.length == 0)
		return "";

	//	Create a date object with the user's entered date and
	//	retrieve the month, day and year.
	//
	var userDate = new Date(date);
	var month = userDate.getMonth();
	var day = userDate.getDate();
	//var year = userDate.getYear();
	var year = userDate.getFullYear();

	var count = date.lastIndexOf("/");
	
	if (count > 0)
	{
		var yearPiece = date.slice(count+1);
	}
	else
	{
		return "";
	}
	

	//	Define acceptable date formats.
	//
	var monthFormat = /^\d{1,2}$/;
	var dayFormat = /^\d{1,2}$/;
	var yearFormat = /^\d{2}$|^\d{4}$/;

	//	Check month.
	//
	var m = month + "";
	var monthResult = m.match(monthFormat);

	if (monthResult == null)
		return "";

	//	Check day of month.
	//
	var d = day + "";
	var dayResult = d.match(dayFormat);

	if (dayResult == null)
		return "";

	//	Check year.
	//

	if (year != yearPiece)
	{
		if (yearPiece.length == 1)
		{
			// User entered a single digit year

			yearPiece = "200" + yearPiece;

		}
		else if (yearPiece.length == 2)
		{
			// User entered a two digit year
			if (yearPiece <= 50)
				yearPiece = "20" + yearPiece;
			else
				yearPiece = "19" + yearPiece;
		}
		else
		{
			// User entered something else,
			// just go with the full year.
			yearPiece = year;
		}
	}
	var y = yearPiece + "";

	//	NOTE:  Netscape interprets the year
	//	differently than IE.
	//
	if (navigator.appName == "Netscape")
	{
		var yearResult = y.match(/^\d{1,4}$|^-\d{1,4}$/);

		if (yearResult == null)
			return "";
	}
	else
	{
		var yearResult = y.match(yearFormat);

		if (yearResult == null)
		{
			//	If the user put in 01 - 09 the getYear() method
			//	returns 1 digit.  Therefore, check again if it
			//	is 1 digit and add 2000.
			//
			yearResult = y.match(/^\d{1}$/);
			if (yearResult == null)
				return "";

		}
	}

	//	Build the date in mm/dd/yyyy.
	//	Add 1 to the month since getMonth() returns 0-11 for a month.
	//
	var fdate = new String();
	var mn = m - 0;
	mn = mn + 1;
	fdate = mn + "/" + d + "/" + y;

	//	Everything checks out.
	//
	return fdate;
}

function setCommas() {
    number = '' + number
    if (number.length > 3) {
        var mod = number.length%3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
                output+= ',' + number.substring(mod+3*i,mod+3*i+3);
        }
        return (output);
    }
    else return number;
}
