
function PreviewImage() {
	var oFReader = new FileReader();
	oFReader.readAsDataURL(document.getElementById("image").files[0]);

	oFReader.onload = function (oFREvent) {
		document.getElementById("uploadPreview").src = oFREvent.target.result;
	};
	$('#editPicForm').submit();
};

var Script = function () {

    $.validator.setDefaults({
        submitHandler: function() { 
           var newpass=$("#newpass").val();
           var oldpass=$("#oldpass").val();
           var dataString = 'newpass='+newpass+'&oldpass='+oldpass;
           
             $.ajax({
                type: "POST",
                url: "/profile/chpwd/update",
                data: dataString,
                cache: false,
                beforeSend: function(){ 
                    $("#submitpass").hide();
                    $("#waitingpass").show();
                    $("#suksesupdate").hide();
                    $("#gagalupdate").hide();
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#submitpass").show();
                        $("#waitingpass").hide();
                        $("#suksesupdate").show();
                        setTimeout(function() {
                            window.location.href=window.location.href + "?success=1";
                        }, 2000);
                    }else{
                        $("#submitpass").show();
                        $("#waitingpass").hide();
                        //$("#suksesupdate").show();
                        $("#gagalupdate").show();
                    }
                }
                
            }); 
        }
    });

    $().ready(function() {
        $("#chpwd").validate({
            rules: {
                newpass: {
                    required: true,
                },
                confirm_newpass: {
                    equalTo: "#newpass",
                },
                oldpass: {
                    required: true,
                },
            },
            messages: {
                
                newpass: {
                    required: "Please provide a new password",                    
                    
                },
                confirm_newpass: {
                    equalTo: "Please enter the same password as above"
                },
                oldpass: {
                    required: "Please provide your current password",                    
                },
                
            }
        });

        // propose username by combining first- and lastname
       
	   $().ready(function() {
        // validate the comment form when it is submitted
        $("#editForm").validate();
		if(window.location.search == '?success'){
			$("#suksesupdate").show();
		}else if(window.location.search == '?failed'){
			$("#gagalupdate").show();
		}
		setTimeout(
		  function() 
		  {
			$("#suksesupdate").hide();
			$("#gagalupdate").hide();
		  }, 2000);
    });
	   
    });


}();