// do a check to see if the user is using SSL, if not, send them there
(function($) {
		  
var loc = new String(window.parent.location);
if (loc.indexOf("https://") != -1) {
	// check to see if we are using www.
	if (loc.indexOf("www.") != -1) {
//		console.log("url: "+ loc);
		var url = loc.replace("https://", "https://www.");
//		window.location = url;
	}
	else {
		
	}
}
else {
	// check to see if there is the www. in the url (needed for the certificate)
	if (loc.indexOf("www.") != -1) {
		var url = loc.replace("http://", "https://");
	}
	else {
		var url = loc.replace("http://", "https://www.");	
	}
	// send them to the secure page
	// window.location = url;
//	console.log('sending the user to: '+ url);
	window.location = url;
}

})(jQuery);

var $j = jQuery.noConflict();

$j(document).ready(function(){
//login stuff follows			
	$j('#login_form').hide();

	$j("#loginLink, #loginTopNav").click(function(event){
	 event.preventDefault();
		login();
		$j('#login_form').css('z-index',5000);
		});
	
	$j("#cancel").click(function(event){
		event.preventDefault();
		$j('#login_form').fadeOut('slow');
		});

// When the form is submitted
$j("#status > form").submit(function(){  
	$j('#login_response').html('');
	$j('#submit').hide();
	$j('#ajax_loading').show();
// 'this' refers to the current submitted form
	var str = $j(this).serialize();  
// -- Start AJAX Call --
$j.ajax({
    type: "POST",
    url: "/Login/index.cfm",
    data: str,
    success: function(msg){  
		$j("#status").ajaxComplete(function(event, request, settings){  
		$j('#ajax_loading').hide();  
	var err='';
	if(msg.indexOf('EducationDirector failed to recognize')!= -1){
	err = "<p>Sorry, we failed to recognize your username or password.</p><p><a href='http://www.ism-knowledgecenter.ws/Login/remindme.cfm'>Did you forget your username or password?</a></p>";
	}else if( msg.indexOf('Sorry, your session timed out or was not initialized.')!= -1  ){
		err='<p>Sorry, your session timed out or was not initialized. Please log in again.</p>';
	}else if( msg.indexOf('Use your designated username and password to enter.')!= -1  ){	
		err="<p>Please enter both a username and a password.</p><p><a href='http://www.ism-knowledgecenter.ws/Login/remindme.cfm'>Did you forget your username or password?</a></p>";
	}else{
		err='';
	}
 		if(err==''){
			// LOGIN OK
		$j('#login_response').html('<p>Successfully logged in!</p>');
		$j('#login_form').delay(1000).fadeOut('slow');
		setTimeout("gotoHome()",2000);
		}else{
	 // ERROR????
 		$j('#login_response').html("<h3>Problem:</h3>"+err);
  		// Show 'Submit' Button
		$j('#submit').show();
 		}  
//end ajax complete
 	});  
//end success
 }  
// -- End AJAX Call --
});  
return false;
}); // end submit event

function login(f){
	$j('#login_response').html('');	
	$j('#Username').focus()
	$j('#ajax_loading').hide();				  
	$j('#login_form').fadeIn('fast');
}

});
function gotoHome(){
	window.location = '/Home/index.cfm';
}

