//----------------------------
// Date Validation Functions
//----------------------------
//Include the datevalidate javascript file for date validations.
//document.write('<script type="text/javascript" src="/javascript/datevalidate.js"></script>'); 

//--------------------
// Version Functions
//--------------------
// return the version number times 1000 (to compensate for rounding errors).
function _get_version()
{
   return Math.round(parseFloat(navigator.appVersion) * 1000);
}


//------------------
// Browser Support
//------------------
// Check for browser that supports frames.
// create the "browser" object to store browser information
var browser = new Object();

// Check for a Netscape browser
if (navigator.appName.substring(0,8) == "Netscape")
{
	browser.name = "NN";
	browser.version = _get_version();
}
// Check for a Microsoft browser
else if (navigator.appName.substring(0,9) == "Microsoft")
{
   browser.name = "MSIE";
   // Only MSIE for Windows 95 can read this code.
   // Navigator.appVersion returns 2.0 rather than 3.0, but we don't care,
   //we're checking for 4.0 now
   browser.version = _get_version();
}
// Check for other browser that supports JavaScript, assuming that this
// browser stores the information in the same format as Navigator.
else
{
   browser.name = navigator.appName;
   browser.version = _get_version();
}

// Set variable for browser
if (((browser.name == "NN")   && (browser.version >= 3000)) || 
	((browser.name == "MSIE") && (browser.version >= 4000)))
{
   version = "Rollovers";
}
else
{
   version = "other";
}


//--------------------   
// Display Functions
//--------------------   
//Turn on or off graphic
function rollover(changeImage, changeImageTo){
	if (version == "Rollovers")
	{
		window.document[changeImage].src = changeImageTo;
	}
}
function hoverTD(strColor, name, imagerollover, nameofrolloverimage){
	document.all[name].style.background = '#' + strColor;
	if (navigator.appName.substring(0,9) == "Microsoft")
	{
		window.document[imagerollover].src = nameofrolloverimage;
	}
}

function hoverTD1(strColor, name)
{
	document.all[name].style.background = '#' + strColor;
}

function ToggleDisplay(objItems)
{
	if (document.getElementById)
	{
			displayType = (document.getElementById(objItems).style.display == 'none') ? 'block' : 'none';
			document.getElementById(objItems).style.display = displayType;
	}
	else if (document.layers)
	{
			displayType = (document.layers(objItems).style.display == 'none') ? 'block' : 'none';
			document.layers(objItems).style.display = displayType;
	}
	else if (document.all)
	{
			displayType = (document.all(objItems).style.display == 'none') ? 'block' : 'none';
			document.all(objItems).style.display = displayType;
	}
}

function checkStatus(chkName) 
{
	var form = document.forms[0];

	if (chkName.checked == true)
	{
		document.forms[0].chkTravelco0.checked = false;
		document.forms[0].chkTravelco0.disabled = true;		
	}
	else
	{
		if ((form.chkTravelco1.checked != true) && 
			(form.chkTravelco2.checked != true) && 
			(form.chkTravelco3.checked != true) && 
			(form.chkTravelco4.checked != true) && 
			(form.chkTravelco5.checked != true))
	    {
	        form.chkTravelco0.disabled = false;			
		}
	}
}

//----------------------
// Zip Code Validation
//----------------------
function isZipCode(val)
{
	str = val.value;
	len = str.length;
	if ((len != 5) && (len != 10))
	{
		alert('ZIP code is invalid. Please check the ZIP code');
		val.focus();
		return false;
	}
	    
	for (i = 0; i < len; i++)
	{
		c = str.charAt(i);
		if ((len == 10) && (i == 5))
		{
			if (c != "-")
			{
				alert('ZIP code is invalid. Please check the ZIP code');
				val.focus();
				return false;
			}
		} 
		else 
		{
			if ((c < "0") || (c > "9"))
			{
				alert('ZIP code is invalid. Please check the ZIP code');
				return false;
				val.focus();
			}
		} 
	}
  
  AlertLeavingSite('http://yp109.superpages.com/giemap/map-based/map.cgi?rtd=yp109.superpages.com&amp;zip=' + str);
  //window.open('http://yp109.superpages.com/giemap/map-based/map.cgi?rtd=yp109.superpages.com&amp;zip=' + str);
  return false;
	val.focus();
}


//----------------
// Session Timer
//----------------
function CheckTimer(timerMinutes, redirectToPage) 
{
	// If current page does not require a redirect.
	if (!isPageRedirected)
	{
		StopTimer()
		return;
	}

	if (!startTime)
	{
		startTime = new Date();
	}

	var currentTime = new Date();
	var milliseconds = currentTime.getTime() - startTime.getTime();
	//alert("CheckTimer(timerMinutes = "+timerMinutes+", redirectToPage = '"+redirectToPage+"')\n\nTimer in Milliseconds = "+timerMinutes*60000+"\nElapsed Milliseconds = " + milliseconds);

	// If timer has expired, navigate to the redirectToPage.
	if (milliseconds >= (timerMinutes * 60000))
	{
		window.focus();
		window.location = redirectToPage;
	}
}

function StartTimer(timerMinutes, redirectToPage)
{
	//alert("StartTimer(timerMinutes = "+timerMinutes+", redirectToPage = '"+redirectToPage+"')");
	StopTimer();
	startTime = new Date();
	timerID = window.setInterval("CheckTimer("+timerMinutes+", '"+redirectToPage+"')", 1000);
}

function StopTimer()
{
   if (timerID)
   {
			//alert("StopTimer()\nwindow.clearInterval(timerID = "+timerID+")");
			window.clearInterval(timerID);
      timerID = null;
   }
}

function ResetTimer()
{
   startTime = new Date();
   //alert("ResetTimer()\nstartTime = " + startTime);
}

var timerID = null;
var startTime = null;
StartTimer(sessionTimeout, '/inactivity.aspx');


//---------------------
// Leaving TSC Alerts
//---------------------
function AlertLeavingSite(URL)
{
	alert("You are accessing content outside of 'The Service Connection'.");
	window.open(URL);
}

function AlertLeavingSiteLogoff(URL)
{
	window.open(URL);
	parent.window.location.href = "/login.aspx";
}