function mainmenu(){
  $(" #nav ul ").css({display: "none"}); // Opera Fix
  $(" #nav li").hover(function(){
		//$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		$(this).find('ul:first').show(400);
  },function(){
		//$(this).find('ul:first').css({visibility: "hidden"});
		$(this).find('ul:first').hide();
  });
}
function processpreset(){   
	 var dat = $("#forgot-form").serialize();
	// console.debug(dat);
	 
     $.ajax({
	   type: "POST",
	   url: "/ws/users/reqpass",
	   data: dat,
	   dataType: "json",
	   success: function(data){
         var msg='';											 
         if(true !== data.success) {
            var errs='';
			if(data.errors.length>1){
				for(var x=0;x<data.errors.length;x++){
                  msg += "+ "+ String(data.errors[x]) + "<br />";
		    	}
			}else{
				msg = '<div style="text-align:center;"><b>'+ String(data.errors[0]) +'</b></div>';
			}   		     
           
 	        $('#forgot-msg').html(msg);														   
		 }else{
 	        msg = '<div style="text-align:center;"><b>'+ String(data.msg) +'</b></div>';
 	        $("#forgot-msg").html(msg);
			$("#forgot-inner").hide();
		 }
	   }
	 });
}
function forgotfunc(){
	
	 $('#loading-small').ajaxStart(function(){
			$(this).show();
		    $("#email-preset").attr("disabled",true);
			$('#forgot-msg').html('');
		    $("#forgot-but").attr({"value":"Processing.."}).attr({"disabled":"disabled"});	
		    $("#backtologin-holder").hide();
	 }).ajaxError(function(evt,req,set){
            $('#forgot-msg').html('<div style="text-align:center;font-weight:bold;">An error ocurred while executing request. Please try again..</div>');
	 }).ajaxComplete(function(evt,xhr,opts){
	 	    $(this).hide();	             
        	$("#backtologin-holder").show('fast',function(){
	        	$('#forgot-but').attr({"value":"Send"}).removeAttr("disabled");  				 
		       
        	});  
       	    $("#email-preset").attr("disabled",false).focus();	  
	                   			                
	});
	
	$("#forgot-form :text").keydown(function(event){
		if(event.keyCode == 13){
	 	  processpreset();
		}
	});

	$('#forgot-but').click(function(){
	     processpreset();
	});

}
 
$(document).ready(function(){					
	mainmenu();
	forgotfunc();
	$('a#forgotpass').click(function(){
		$("#email-preset").val('');
	    $('#forgot-msg').html('');
       	$('#login-part').slideUp('fast',function(){
			$('#form-title').text('RESET PASSWORD');
			$('#forgotpass-part').slideDown('fast',function(){
			    $("#forgot-inner").show();
				$("#email-preset").focus();
			});
		});   
	});
	$('a#backtologin').click(function(){
       $("#loading-small").hide();   
	   $('#forgotpass-part').slideUp('fast',function(){
	   	    $('#form-title').text('MEMBERS LOGIN');
			$('#login-part').slideDown('fast');
		});  
	});

});