$(document).ready(function(){
	$('a[href^="http://"]').attr({
		target: "_blank",
		title: "Opens in a new window"
	}).append(' ^');

	$("#loginFrm").submit(function(){
		var user_name = $('#username').val();
		var password = $('#password').val();
		user_name = $.trim(user_name);
		password = $.trim(password);
		if ((user_name == '') || (password == '')){
			$("#msgbox").removeClass().addClass('messageboxerror').text('Please log in first and then we\'ll send you right along!').fadeIn(1000);
			return false;
		}
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('authenticating...').fadeIn(1000);

		//check the username exists or not from ajax
		$.post(ajaxSiteUrl+"login/login.php",{
			user_name:$('#username').val(),password:hex_md5($('#password').val()),rand:Math.random()
				},
		function(data){
		  if(data=='yes') {
				$("#msgbox").fadeTo(200,0.1,function() {
				  //add message and change the class of the box and start fading
				  $(this).html('User verified! Logging in...').addClass('messageboxok').fadeTo(900,1,
				  function(){
					 //redirect to index page
					 document.location='index.php';
				  });
				});
		  } else {
				$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
				  //add message and change the class of the box and start fading
				  $(this).html('Invalid login credentials!').addClass('messageboxerror').fadeTo(900,1);
				});
		  }
	   });
	   return false;//not to post the  form physically
	});
});



