var profile=(function(){
	var mode=0;
	return{
		
		load:function(){
			$("#btpass2").hide();
			$("#box_password").hide();
			document.getElementById("btpass1").onclick=function(){
				if(mode==0){
					$("#btpass2").show();
					$("#box_password").show();
					document.getElementById("btpass1").className="btmerah medium";
					document.getElementById("btpass1").innerHTML="BATAL";
					mode=1;
				}else{
					$("#btpass2").hide();
					$("#box_password").hide();
					document.getElementById("btpass1").className="bthijau medium";
					document.getElementById("btpass1").innerHTML="UBAH PASSWORD";
					mode=0;
				}
			};
			
			document.getElementById("btpass2").onclick=function(){
				if(mode!=1) return;
				profile.simpan();
			};
		},
		
		simpan:function(){
			var passlama=$("#passlama").val();
			var pass1=$("#passbaru").val();
			var pass2=$("#passulang").val();
			
			
			var err="";
			if(passlama=="") err+="Password lama salah.</br>";
			if(pass1==""){
				err+="Password baru belum diisi.</br>";
			}else{
				if(pass1!=pass2){
					err+="Password dan Ulang password tidak sama.</br>";
				}
			}
			
			if(err!=""){
				var ps={"title":"Peringatan","pesan":err};
				boxpesan.peringatan(ps);
				return;
			}
			
			mload.sh();
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "profile",
				ikdata: {0:"ubahpassword",1:passlama,2:pass1}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					mload.hd();
					if(e==1){
						alert("Ubah password berhasil");
						document.location=lokal+"member/mod/profile";
					}else if(e==2){
						alert("Password lama salah.");
					}
				}
			});
		},
		
	};
})();