/**
 * @author bnelson
 */
jQuery( document ).ready( function()
{
	jQuery( "#login-help" ).click( function(){ jQuery.prompt('<strong>Instruction for Logging In:</strong> <p class="normal">NOTE: Logging in is for registered users ONLY. If you\'d like to register, please click the APPLY NOW button at the far right of the navigation menu.</p><p class="normal">You may access your CTE account information by logging in to the membership area using the form on the upper left of this page.</p> <p class="normal">Your <b>username</b> is the email address you used to enroll at CTE and your <b>authorization code</b> is normally the last four digits of your social security number.</p>', { prefix: identity, loaded: function(){ jQuery('#flash-sponsers').hide(); }, callback: function(){ jQuery('#flash-sponsers').show(); } }); } );
	jQuery( "#login" ).click( login );
});

function login()
{
	var nIdentity = "mp";

	jQuery.ajax(
	{
		type: "POST",
		dataType: "xml",
		url: "/CTE/services/cte-services.php?cachebust=" + new Date().getTime(),
		data: {	method: "Login", 
				salt: jQuery( "#salt" ).val(), 
				hash: jQuery( "#hash" ).val(), 
				username: jQuery("#username").val(),
			  	password: jQuery("#password").val()
			  },
		success: function( xml )
		{
			var type = jQuery( xml ).find( "type:first" ).text();
			var sessid = jQuery( xml ).find( "sessid:first" ).text();
			if( type == "failure" )
				jQuery.prompt('<strong>' + jQuery( xml ).find( "title:first" ).text() + '</strong> <p>' + jQuery( xml ).find( "body:first" ).text() + '</p>', { prefix: nIdentity } );
			else if( type == "success" )
				window.location = '/CTE/index.php/member-area.html?sid=' + sessid;		
		},
		error: function( XMLHttpRequest, textStatus, errorThrown )
		{
			alert( "ERROR: [sidebar|login] " + textStatus + ": " + errorThrown );
		}
	});
}
