
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 first_name=$("#first_name").val();
            var last_name=$("#last_name").val();
            var email=$("#email").val();
            var website=$("#website").val();
            var position=$("#position").val();
            var dataString = 'first_name='+first_name+'&last_name='+last_name+'&email='+email+'&website='+website+'&position='+position;
           
             $.ajax({
                type: "POST",
                url: "/profile/edit/update",
                data: dataString,
                cache: false,
                beforeSend: function(){ 
                    $("#submitprofile").hide();
                    $("#waiting").show();
                    $("#suksesupdate").hide();
                    $("#gagalupdate").hide();
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        $("#suksesupdate").show();
                        //$("#gagalupdate").hide();
                    }
                    else if(e.status === 304){
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        $("#update-unchanged").show();
                        //$("#gagalupdate").hide();
                    }
                    else{
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        //$("#suksesupdate").show();
                        $("#gagalupdate").show();
                    }
                }
                
            });
        
        return false;
        }
    });

    $().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);
    });


}();