$(document).ready(function() {
	var checkLogin = function (parentid) {
		//remove all the class add the messagebox classes and start fading
		$("#logmsgbox").removeClass().addClass('messagebox').text('шалгаж байна...').fadeIn("slow");
		var parentid = $('#parentid').val();
		$.post(
			"validForm.php",
			{check: 'parentid', parent: parentid},
			function(data) {
				if(data=='yes') { //if loginname not avaiable
				  	$("#logmsgbox").fadeTo(200,0,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  		//$(this).html('Зөв нэр!').addClass('messageboxok').fadeTo(900,1);
						
					});		
          		}
		  		else {
		  			$("#logmsgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('Код буруу байна!').addClass('messageboxerror').fadeTo(900,1);	
					});
		  		}
			}			
		)
	}
//new pass checking
	var checkPass = function (password) {
		$("#pmsgbox").removeClass().addClass('messagebox').text('шалгаж байна...').fadeIn("slow");
		var password = $('#password').val();
		var cpassword = $('#cpassword').val();
		if(password != cpassword) {
			$("#pmsgbox").fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html('Уучлаарай. шинэ нууц үг адил биш байна!').addClass('messageboxerror').fadeTo(900,1);
				document.frm.btnUpdate.disabled=true;
			});
		}
		else {
			$("#pmsgbox").fadeTo(200,0,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				//$(this).html('Passwords match!').addClass('messageboxok').fadeTo(900,0);
				document.frm.btnUpdate.enabled=false;
				document.frm.btnUpdate.disabled=false;
			});	
		}		
	}
//oldpassword check
	var checkOldPass = function (oldpass) {
		//remove all the class add the messagebox classes and start fading
		$("#opmsgbox").removeClass().addClass('messagebox').text('шалгаж байна...').fadeIn("slow");
		var oldpass = $('#oldpass').val();
		$.post(
			"validForm.php",
			{check: 'oldpass', oldpassword: oldpass},
			function(data) {
				if(data=='no') { //if loginname not avaiable
				  	$("#opmsgbox").fadeTo(200,0,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  		//$(this).html('Зөв нууц үг!').addClass('messageboxok').fadeTo(900,1);
					document.frm.btnUpdate.disabled=true;
						
					});		
          		}
		  		else {
		  			$("#opmsgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('Таны хуучин нууц үг буруу байна!').addClass('messageboxerror').fadeTo(900,1);	
						document.frm.btnUpdate.disabled=true;
					});
		  		}
			}			
		)
	}
//Register check
	var checkRegister = function (letter3) {
		//remove all the class add the messagebox classes and start fading
		$("#regmsgbox").removeClass().addClass('messagebox').text('шалгаж байна...').fadeIn("slow");
		var letter3 = $('#letter3').val();
		$.post(
			"validForm.php",
			{check: 'letter3', regname: letter3},
			function(data) {
				if(data=='yes') { //if loginname not avaiable
				  	$("#regmsgbox").fadeTo(200,0,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  		//$(this).html('Зөв нэр!').addClass('messageboxok').fadeTo(900,1);
					//document.frm.subname.disabled=false;
						
					});		
          		}
		  		else {
		  			$("#regmsgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('Регистерийн дугаар бүртгэлтэй байна!').addClass('messageboxerror').fadeTo(900,1);	
						//document.frm.subname.enabled=false;
						//document.frm.subname.disabled=true;
					});
		  		}
			}			
		)
	}
	$("#parentid").blur(checkLogin);
	$("#letter3").blur(checkRegister);
	$("#cpassword").blur(checkPass);
	$("#oldpass").blur(checkOldPass);

	//$("#email").blur(checkEmail);
});

