/******************************************************************************
 PURPOSE: Determines if the argument is an email address.
 RETURNS: True if the argument is an email address; false otherwise.
 AUTHOR:  John Berberich
 HISTORY:
 
 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 08/01/2006  JAB  Initial version
******************************************************************************/
function isEmailAddress(email)
{
  // Matches:    "e@ee.com", "eee@e-e.com", "eee@ee.eee.museum"
  // Nonmatches: ".@eee.com", "eee@e-.com", "eee@ee.eee.eeeeeeeeee"
  var reEmail = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
  return reEmail.test(email);
}  // isEmailAddress(email)


/******************************************************************************
 PURPOSE: Determines if the argument is a phone number.
 RETURNS: True if the argument is a phone number; false otherwise.
 AUTHOR:  John Berberich
 HISTORY:
 
 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 08/01/2006  JAB  Initial version
******************************************************************************/
function isPhoneNumber(phone)
{
  // Matches:    "5305551212", "(530) 555-1212", "530-555-1212"
  // Nonmatches: "0010011212", "1991991212", "123) not-good"
  var rePhoneNo = /^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/;
  return rePhoneNo.test(phone);
}  // isPhoneNumber(phone)


/******************************************************************************
 PURPOSE: 
 RETURNS: 
 AUTHOR:  John Berberich
 HISTORY:
 
 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 10/24/2006  JAB  Initial version (adapted from vpdclient.vbs)
******************************************************************************/
function doSpanRotationAll()
{
	var groups;
	
	groups = document.getElementsByTagName("div");
	//groups = document.getElementsByName("span-rotate");
	if(groups != null)
	{
		var i;
		for(i = 0; i < groups.length; i++)
		{
			if(groups[i].name = "span-rotate")
			{
				doSpanRotation(groups[i]);
			}
		}
	}
}  // doSpanRotationAll()


/******************************************************************************
 PURPOSE: 
 RETURNS: 
 AUTHOR:  John Berberich
 HISTORY:
 
 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 10/24/2006  JAB  Initial version (adapted from vpdclient.vbs)
******************************************************************************/
function doSpanRotation(group)
{
	var iNextIndex = 0;
	var spans;
	var i;
	
	spans = group.getElementsByTagName("span");
	
	// This function is pointless if we don't have at least two elements
	//Since having only 1 causes reference issues, just bail out
	if(spans.length < 2) return;
	
	// Find the next index to display.
	for(i = 0; i < spans.length; i++)
	{
		if(spans[i].style.display == "")
		{
			if(i == spans.length - 1)
			{
				iNextIndex = 0;
			}
			else
			{
				iNextIndex = i + 1;
			}
			break;
		}
	}
	
	// Set the display property.
	for(i = 0; i < spans.length; i++)
	{
		if(i == iNextIndex)
		{
			spans[i].style.display="";
		}
		else
		{
			spans[i].style.display="none";
		}
	}
}

var reloadInterval = 60000;
var rotateInterval = 4000;


/******************************************************************************
 PURPOSE: Runs on page load.
 AUTHOR:  John Berberich
 HISTORY:

 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 08/01/2006  JAB  Initial version
******************************************************************************/
  function startup()
  {
	//setFooterText("tableGrid");
    window.setTimeout("reloadFlights()", reloadInterval);
	window.setInterval("doSpanRotationAll()", rotateInterval);
  }


/******************************************************************************
 PURPOSE: Reloads flights and resets timer.
 AUTHOR:  John Berberich
 HISTORY:

 DATE        WHO  NOTES
 ----------  ---  ------------------------------------------------------------
 08/01/2006  JAB  Initial version
******************************************************************************/
  function reloadFlights()
  {
    document.location.reload();
    window.setTimeout("reloadFlights()", reloadInterval);
  }


  function setFooterText(Table)
  {
  	// Get the table
  	Table = document.getElementById(Table);
  	// Get the number of table rows
  	var nRows = Table.rows.length;
  	// Set the footer hidden tag with the value
  	if(nRows > 2)
  	{
  		// Show the table
  		//Table.style.display = "block";
  		// Subtract the header and footer from the total
  		nRows -= 2;
  		// Set the footer
  		if(nRows == 1)
  			document.getElementById("spanFooter").innerText = "Showing 1 Flight";
  		else
  			document.getElementById("spanFooter").innerText = "Showing "+nRows+" Flights";
  		// Set the flight total for other functions
  		document.getElementById("hidFlightTotal").value = nRows;
  	}
  	else
  	{
  		// Do not show the tabe until there are results
  		//Table.style.display = "none";
  		document.getElementById("spanFooter").innerText = "No Flights";
  	}
  } // SetFooterText()
