$(document).ready(function() {

	$('#browserNew').trigger(function() {
    	$('#browserNewDiv').show();
    	});


	$('#addPhotos').click(function() {
    	$('#addPictureForm').slideDown();
    	});

	$('#addPictureFormLoggedUserFormClose').click(function() {
    	$('#addPictureForm').slideUp();
		return false;
    	});

	//start div comentarii
    $('#addCommentForm').click(function() {
    	$('#addCommentNew').slideDown();
    	});
     $('#resetComment').click(function() {
    	$('#addCommentNew').slideUp();
		return false;
    	});
	//end div comentarii

    $('a#headerButton4').click(function() {
    	$('#userManageWrapper').show();
    	});

    $('a#headerButton4members').click(function() {
    	$('#userManageWrapper').show();
    	});

    $('#buttonClose').click(function() {
		$('#userManageWrapper').fadeOut('normal');
		});

	 $('#continuaNavigarea').click(function() {
		$('#registerForm').hide('fast');
		$('#loginForm').show('normal');
		});

	$('#registerNewUser').click(function() {
		$('#registerForm').show('slow');
		$('#loginForm').hide('normal');
		});


	$("#login_form").validate({
		rules: {
		userName: "required",
		},
        messages: {
	      userName: "Numele introdus este invalid." ,
	    }
	});

	$("#login_form").submit(function()
		{

			$("#msgbox").text('Validare in curs...').fadeIn(1000);
			$.post("index.php?action=loginUser",
				{ userName:$('#userName').val(),
				  userPassword:$('#userPassword').val() }
				,function(data)
	        {
			  if(data=='yes') //if correct login detail
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('<font color="lightgreen">Inregistrare in curs ...</font>').fadeTo(900,1,
	              function()
				  {
				  	 //redirect to secure page
					window.location.reload(false);
				  });

				});
			  }
			  else if(data=='disable')
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Acest cont a fost dezactivat! ').fadeTo(900,1);
				});
			  }
			  else
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Parola sau nume utilizator incorect!').fadeTo(900,1);
				});
	          }

	        });
	 		return false; //not to post the  form physically
		});
		//now call the ajax also focus move from
		$("#userPassword").blur(function()
		{
			$("#login_form").trigger('submit');
		});


	$("#register_form").validate({
			rules: {
				registerUserName: "required",
				registerUserPassword: "required",
				registerUserPasswordConfirm: "required",
				captcha: "required",
				userEmail: {
			      required: true,
			      email: true
			    }
			},

	        messages: {
		      registerUserName: "Numele introdus este invalid." ,
		      registerUserPassword: "Campul nu poate sa fie gol!" ,
		      registerUserPasswordConfirm: "Campul nu poate sa fie gol!",
		      userEmail: "Format e-mail incorect!",
		      captcha: "Campul nu poate sa fie gol",

		    }

	});

	$("#register_form").submit(function()
		{

			$("#msgbox").html('<font color="lightgreen">Inregistrare in curs...</font>').fadeIn(1000);
			$.post("index.php?action=registerUser",
				{ registerUserName:$('#registerUserName').val(),
				  registerUserPassword:$('#registerUserPassword').val(),
				  registerUserPasswordConfirm:$('#registerUserPasswordConfirm').val(),
				  userEmail:$('#userEmail').val(),
				  captcha:$('#captcha').val(),
				 }
				,function(data)
	        {
			  if(data=='yes') //if correct login detail
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('<font color="lightgreen">Inregistrarea a fost facuta cu succes!. Va multumim :) <br/> Folositi formularul de login pentru a va identifica.</font>').fadeTo(900,1,
	              function()
				  {
				  	 //redirect to secure page
				//	window.location.reload(false);
					$('#registerForm').hide('fast');
			    	$('#loginForm').show('normal');
				  });

				});
			  }
			 else if(data=='utilizatorExistent') //if correct login detail
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Utilizatorul exista deja in baza de date.').fadeTo(900,1);
				});
			  }
			  else if(data=='captcha')
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Textul de verificare este incorect!').fadeTo(900,1);
				});
			  }
			   else if(data=='parola')
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Va rugam sa confirmati parola dvs!').fadeTo(900,1);
				});
			  }

			   else if(data=='emailExists')
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('E-mail introdus exista deja in baza de date!').fadeTo(900,1);
				});
			  }
			  else
			  {
			  	$("#msgbox").fadeTo(200,0.1,function()
				{
				  $(this).html('Eroare la inregistrare. Va rugam sa incercati mai tarziu!').fadeTo(900,1);
				});
	          }

	        });
	 		return false; //not to post the  form physically
		});


/////////////////

 $("#displayPhotoMessage").mouseout(function(){

    }).mouseover(function(){
		$('#popupPhoto').slideDown();
		$('#popupPhoto').css('display','block');
    });

 $("#displayInfoStar").mouseout(function(){

    }).mouseover(function(){
		$('#popupObj').slideDown();
		$('#popupObj').css('display','block');
    });



/*
	$("#foto_form").submit(function(){

			$("#mbPhoto").text('Validare in curs...').fadeIn(1000);
			$.post("index.php?action=addPictureFormLoggedUserForm",

				{
			      photoCategoryId:$('#photoCategoryId ').val(),
				  photoName:$('#photoName').val(),
				  photoDescription:$('#photoDescription').val() }
				,function(data)
	        {
	        	alert(data);

			  if(data=='yes') //if correct login detail
			  {
			 	$("#mbPhoto").fadeTo(200,0.1,function()
				{
				  $(this).html('Done ..!').fadeTo(900,1);
				});
			  }
			  else
			  {
			 $("#mbPhoto").fadeTo(200,0.1,function()
				{
				  $(this).html('Error ..!').fadeTo(900,1);
				});
	          }

	        });
	 		return false; //not to post the  form physically
		});

*/

});

