var	gWemisphereButtons = ["wifi", "maps", "news", "wem", "flh", "wemisphere"];
var gWemisphereIESpecialHack = false;

function wemisphereButtonMouseOver( image, name )
{
	wemisphereButtonReset();
	wemisphereSetButtonWith( name + "-button", name + "_over_image" );
}

function wemisphereButtonReset()
{
	var	i;
	for( i=0; i<gWemisphereButtons.length; ++i )
		wemisphereSetButtonWith( gWemisphereButtons[i] + "-button", gWemisphereButtons[i] + "_normal_image" );
}

function wemisphereSetButtonWith( buttonId, imageId )
{
	var	button = document.getElementById( buttonId );
	if( null != button )
		{
			var	image = document.getElementById( imageId );
			if( null != image )
				{
					button.src = image.src;
				}
		}
}

function wemisphereShowMore( input )
{
	wemisphereHideElement( "enter_here_image" );
	wemisphereShowElement( "access-popup" );
	
	if( gWemisphereIESpecialHack )
	    wemisphereHideElement( "access-plan-sub" );
	
	input.style.color = "black";
	if( "Type Code" == input.value )
		input.value = "";
}

function wemisphereHideElement( elementId )
{
	var	element = document.getElementById( elementId );
	if( null == element )
		return;
	element.style.display = "none";
}

function wemisphereShowElement( elementId )
{
	var	element = document.getElementById( elementId );
	if( null == element )
		return;
	element.style.display = "block";
}

function wemisphereStringEmpty( input )
{
	if( null == input )
		return true;
	if( null == input.value )
		return true;
	if( input.value.length < 1 )
		return true;
	return false;
}

function wemisphereCheckCodeBad( input )
{
	if( wemisphereStringEmpty( input ) )
		return true;
	
	var	num = "";
	var	i;
	var	ch0 = "0".charCodeAt(0);
	var	ch9 = "9".charCodeAt(0);
	for( i=0; i<input.value.length; ++i )
		{
			var	ch = input.value.charCodeAt( i );
			if( (ch0 <= ch) && ( ch<=ch9 ) )
				num += input.value.charAt(i);
		}
	
	input.value = num;
	
	if( input.value.length < 7 )
		return true;
	if( input.value.length > 9 )
		return true;
	
	return false;
}

function wemisphereCheckAccess( theForm )
{
	
	if( wemisphereCheckCodeBad( theForm.accessCode ) )
		{
			alert( "Sorry, the provided access code is not valid." );
			return false;
		}
		
	if( !theForm.agreeAUP.checked )
		{
			alert( "Sorry, you need to agree to \"Acceptable Use Policy\" to use our service." );
			return false;
		}

	if( !theForm.agreeSILD.checked )
		{
			alert( "Sorry, you need to agree to \"Security Information and Liability Disclaimer\" to use our service." );
			return false;
		}

		
	return true;
}

var gWemisphereBruteDisabled = false;
function wemisphereBruteLoad()
{
    if( gWemisphereBruteDisabled )
        return;
	wemisphereHideElement( "brute-under" );
	window.setTimeout( "wemisphereBruteDone()", 60000 );
}

function wemisphereBruteDone()
{
    if( gWemisphereBruteDisabled )
        return;
	wemisphereHideElement( "brute_wrapper" );
	wemisphereShowElement( "brute-under" );
}

function wemisphereTokenExpiration( seconds, destination )
{
    var element = document.getElementById( "token_expired_link" );
    element.href = destination;
    
    if( seconds > 0 )
    {
        wemisphereHideElement( "token_expired" );
        window.setTimeout( "wemisphereDoTokenExpired()", seconds * 1000 );
    }
    else
    {
        wemisphereDoTokenExpired();
    }
}

function wemisphereDoTokenExpired()
{
    gWemisphereBruteDisabled = true;
    wemisphereShowElement( "token_expired" );
	wemisphereHideElement( "brute-under" );
}

function wemisphere_fixBrainDeadIE()
{
  // hates IE
  //wemisphere_makeItGif( "home-feature-overlay-back" );
  //wemisphere_makeItGif( "home-feature-insert-tween" );
  //wemisphere_makeItGif( "home-feature-overlay-fore" );
  //wemisphere_makeItGif( "home-feature-insert-over" );
}

function wemisphere_makeItGif( imageId )
{
  var image = document.getElementById( imageId );
  if( null != image )
    {
      image.src = image.src.substring( 0, image.src.length - 4 ) + ".gif";
      image.style.display = "none";
    }  
}

