function onAffChange()
{ 
	var instructions = jQuery("div#instructions");
	var espninstructions = jQuery("div#espninstructions");
	espninstructions.hide();
	instructions.hide();

	var elem = jQuery("select#selAffiliate");	
	if( elem.val().toLowerCase() == "comcast" )
	{
		instructions.html('<p><a href="#" onclick="comcastLogin();">Sign-in using your Comcast.net account to access ESPN360.com</a></p>');
		instructions.show();
	}
	else if( elem.val().toLowerCase() == "verizon" )
	{
		instructions.html('<p><a href="#" onclick="verizonLogin();">Sign-in using your Verizon Surround account to access ESPN360.com</a></p>');
		instructions.show();
	}
	else if( elem.val().toLowerCase() == "cox" )
	{
		instructions.html('<p></p>');
		instructions.show();
	}
	else if( elem.val().toLowerCase() == "notfound" )
	{
		instructions.html('<p>Switch to an ESPN360.com affiliated internet service provider or to contact your internet service provider and request ESPN360.com. <a href="#" onclick="clickLink(\'closeLightbox1Link\');clickLink(\'lightbox2Link\');">Click here</a> to enter your ZIP code and find out which providers in your area carry offer ESPN360.com</p>');
		instructions.show();
	}
	else if( elem.val() != "" )
	{
		espninstructions.show();
	}

}

function outJS_BeginAgain() {
	clickLink('closeLightbox2Link');
	openLightBox();
}

function outJS_RemAccess() {
	verizonLogin();
}

function outJS_Help() {
	clickLink('closeLightbox2Link');
	launchFaq();
}

function outJS_CloseAll() {
	clickLink('closeLightbox2Link');
}
function verizonLogin() 
{
	window.open("https://www.verizon.net/ssowebapp/protected/ContentPartnerIntegrator?src=espn&target=http%3A%2F%2Fbroadband.espn.go.com%2Fespn360%2Fverizon%2Fgateway4","lWin","status=no,height=480,width=640,top=0,left=0");
}

function comcastLogin()
{
	var link = "https://broadband.espn.go.com/opensso/saml2/jsp/spSSOInit.jsp?metaAlias=/sp&idpEntityID=https://sso.comcast.net/Comcast/IdP/sso&binding=HTTP-POST&reqBinding=urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST&NameIDFormat=urn:oasis:names:tc:SAML:2.0:nameid-format:transient&RelayState=http%3A%2F%2Fespn.go.com%2Fbroadband%2Fespn360%2Findex";
	if( gGameId != "null" && gGameId != "" )
	{
		link += "%3FgameId%3d" + gGameId;
	}
	else
	{
		link += "%3FgameId%3d0";
	}

	window.location = link;
}

function submitGetAccess()
{
	jQuery.getJSON(BASE_URL + "util/addSsoToken?jsoncallback=?", function(data){
		
		jQuery('div#dynamic_message').html('');
		if( data.success == false )
		{
			jQuery('div#dynamic_message').html('<br/><div style="text-align:center">'+data.errorMessage+'</div>');
		}
		else
		{
			showRemoteAccessActivated();
			mn_movie.add(ud.username);
		}
	});
	
	jQuery('div#dynamic_message').html('<br/><div style="text-align:center"><b>Please wait...this could take up to a few minutes.</b></div>');
}

function showRemoteAccessActivated()
{
	jQuery('div#drawercontainer_aff').show();
	jQuery('h2#getaccess_header').html("Your Remote Access is Activated");
	jQuery('div#drawercontainer_aff').html("<p>When you are away from home, just sign in with your ESPN.com account to access ESPN360.com.</p><br/>");
}

function closeRemoteAccess()
{
	clickLink('closeLightbox1Link');
	set_cookie("360remoteAccessShown");
}

if(ud.affvalid == "true")
{
	jQuery('div#drawercontainer_nonaff').hide();
	
	// User is logged in, did not abuse SSO, has SSO access
	if( ud.sso == "true" )
	{
		showRemoteAccessActivated();
	}
	// Limit the remote access
	else if( ud.canaddsso == "true" )
	{
		var showBox = false;
		
		jQuery('div#drawercontainer_aff').show();
		
		var elem = jQuery('div#drawercontainer_aff');
		elemHtml = '';
		
		// Limits the remote access to certain affiliates
		if( ud.a.indexOf("verizon") == 0 )
		{
			elemHtml += '<p>You can access ESPN360.com remotely using your Verizon Surround account.</p>';
		}
		else if( ud.a.indexOf("comcast") == 0 )
		{
			elemHtml += '<p>You can access ESPN360.com remotely using your Comcast.net account.</p>';
		}
		else if( ud.a.indexOf("cox") == 0 )
		{
			elem.innerHTML += '<p></p>';
		}		
		// User is not logged in
		else if( ud.isLoggedIn == "false" )
		{
			showBox = true;
			elemHtml += '<p>Your internet service provider offers ESPN360.com.</p>';
			elemHtml += '<p>Did you know you can access ESPN360.com away from home with a free ESPN.com account?</p>';
			elemHtml += '<p>If you already have an ESPN.com account:</p>';
			elemHtml += '<p>1.  Sign in using the myESPN link in the upper right hand corner.</p>';
			elemHtml += '<p>2.  After successfully signing in, click Remote Access again and follow the instructions.</p>';
			
			elemHtml += '<br/><p>If you do not have an ESPN.com account, please <a target="_blank" href="https://r.espn.go.com/members/register?registrationFormId=espn&appRedirect=http%3A%2F%2Fespn.go.com%2Fbroadband%2Fespn360%2Findex">click here</a> to register for a new account.</p>';
		}
		// User is logged in and abused SSO
		else if( ud.ssoabuse == "true" )
		{
			elemHtml = '<br/><br/>Remote access is not available at this time.  You have exceeded the number of logins allowed.  It will be available again after 5AM Eastern.<br/>  Please contact our Customer Care Team at 888-549-ESPN if you have any questions.<br/>';
		}
		else if( ud.useraccountvalid == "false" )
		{
			elemHtml = '<br/><br/>Remote access is not availabe for your account on this computer.  This computer has assigned remote access to the maximum number of accounts.<br/><br/>  Please contact our Customer Care Team at 888-549-ESPN if you have any questions.<br/>';
		}
		// User is logged in and did not abuse SSO and does not have SSO
		else if( ud.sso == "false" )
		{
			showBox = true;
			elemHtml += '<p>Your internet service provider offers ESPN360.com.</p>';
			elemHtml += '<p>Did you know you can access ESPN360.com away from home with your ESPN.com account?</p>';
			elemHtml += '<p>Just click on the button below to sync your account.</p>';
			elemHtml += '<div id="drawercontainer_message">';
			elemHtml += '<div style="text-align:center;"><input type="submit" value="Sync My Account" onClick="submitGetAccess();" /></div>';
			elemHtml += '</div>';
		}
		elem.html(elemHtml);
		
		var remoteAccessShown = get_cookie("360remoteAccessShown");
		if( showBox == true && remoteAccessShown == null  )
		{
			Event.observe(window, 'load', openLightBox);
		}
	}
	// No access for this affiliate
	else
	{
		jQuery('div#drawercontainer_aff').show();
					
		var elem = jQuery('div#drawercontainer_aff');
		elem.html('<p>Remote access is not available from your internet service provider.</p>');
	}
}
else
{
	jQuery('h2#getaccess_header').html("How to Get Access to ESPN360.com");
	
	jQuery('div#drawercontainer_aff').hide();
	jQuery('div#drawercontainer_nonaff').show();
	
	var elem = jQuery('div#espninstructions');
	var elemHtml = '';
	// User is not logged in
	if( ud.isLoggedIn == "false" )
	{
		elemHtml = "<p>If you already get ESPN360.com at home and activated remote access, sign in using the myESPN link in the upper right hand corner.  In order to activate remote access, you must sign in through your ESPN360.com affiliate Internet Service Provider.</p>";
	}
	// User is logged in, abused SSO
	else if( ud.ssoabuse == "true" )
	{
		jQuery('div#drawercontainer_nonaff').html("<br/><br/>Remote access is not available at this time.  You have exceeded the number of logins allowed.  It will be available again after 5AM Eastern.<br/>  Please contact our Customer Care Team at 888-549-ESPN if you have any questions.<br/>");
	}
	// User is logged in, no abuse, has SSO access
	else if( ud.sso == "true" )
	{
		elemHtml = "<p>If you already get ESPN360.com and activated remote access, sign in using the myESPN link in the upper right hand corner.  In order to activate remote access, you must sign up when using your ESPN360.com affiliate internet service provider.</p>";
	}
	// User is passively logged in
	else if( ud.isPassive == "true" )
	{
		elemHtml = "<p>If you already get ESPN360.com and activated remote access, sign in below.  In order to activate remote access, you must sign up when using your ESPN360.com affiliate internet service provider.<br/>";
		elemHtml += '<form class="user-info" action="https://r.espn.go.com/members/login" method="post" name="form-signin" accept-charset="utf-8"><input type="hidden" name="count" value="0"><input type="hidden" name="SUBMIT" value="1"><input type="hidden" name="language" value="en"/><input type="hidden" name="affiliateName" value="espn"/><input type="hidden" name="regFormId" value="espn"/><input type="hidden" name="appRedirect" value="http://espn.go.com/broadband/espn360/index?showRemoteAccess=true"/>'
											+'<div class="row ">'
											+'<label class="info-type">Member Name/Email: </label>'
											+'<span class="info-user">'
											+'<input class="info-entry" type="text" id="username" name="username" value="' + ud.username +'"/>'
											+'</span>'
											+'</div>'
											+'<div class="row ">'
											+'<label class="info-type">Password: </label>     '
											+'<span class="info-user">'
											+'<input class="info-entry" type="password" id="password" name="password" value="" />'
											+'</span>'
											+'</div>'
											+'</form>'
											+'<div class="row">'
											+'<input type="image" onclick="document.forms[\'form-signin\'].submit();" src="https://a248.e.akamai.net/f/12/621/5m/proxy.espn.go.com/prod/assets/btn_signin.png" height="18" width="64" alt="sign in" />'
								+'</div></p>';
	}
	// User is logged in, no abuse, does not have SSO access
	else
	{
		elemHtml = "<p>If you already get ESPN360.com and activated remote access, sign in below with your ESPN.com member name and password.  In order to activate remote access, you must sign up when using your ESPN360.com affiliate internet service provider.</p>";
	}
	elem.html(elemHtml);
	
}