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();
};
function PreviewImage2() {
	var oFReader = new FileReader();
	oFReader.readAsDataURL(document.getElementById("image2").files[0]);

	oFReader.onload = function (oFREvent) {
		document.getElementById("uploadPreview2").src = oFREvent.target.result;
	};
	$('#editPicForm2').submit();
};
var Script = function () {

    $.validator.setDefaults({
        submitHandler: function() { 
            var name              = $("#name").val();
            var tax_no            = $("#tax_no").val();
            var company_no        = $("#company_no").val();
            var company_fax       = $("#company_fax").val();
            var address           = $("#address").val();
            var city              = $("#city").val();
            var zip               = $("#zip").val();
            var state             = $("#state").val();
            var country           = $("#country").val();
            var reg_no            = $("#reg_no").val();
            var contact_person    = $("#contact_person").val();
            var contact_person_no = $("#contact_person_no").val();
			
			var dataString ='name='+name+
							'&tax_no='+tax_no+
							'&company_no='+company_no+
							'&company_fax='+company_fax+
							'&address='+address+
							'&city='+city+
							'&zip='+zip+
							'&state='+state+
							'&country='+country+
							'&reg_no='+reg_no+
							'&contact_person='+contact_person+
							'&contact_person_no='+contact_person_no;
           
             $.ajax({
                type: "POST",
                url: "/company/edit/update",
                data: dataString,
                cache: false,
                beforeSend: function(){ 
					$(".scroll-to-top").trigger('click');
                    $("#submitprofile").hide();
                    $("#waiting").show();
                    $("#suksesupdate").hide();
                    $("#gagalupdate").hide();
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        $("#suksesupdate").show();
						setTimeout(function(){
							location.reload();
						},2000);
                        //$("#gagalupdate").hide();
                    }else{
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        //$("#suksesupdate").show();
                        $("#gagalupdate").show();
						setTimeout(function(){
							location.reload();
						},2000);
                    }
                }
                
            });
        
        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);
    });
	

}();