$.fn.disable = function() {
	return this.each(function() {
		if (typeof this.disabled != "undefined")
			this.disabled = true;
	});
}

$.fn.enable = function() {
	return this.each(function() {
		if (typeof this.disabled != "undefined")
			this.disabled = false;
	});
}

$(function() {

	$("#send").focus();
	
	$("#cleanbutton").click(function(event) {
                alert("herrrra");
		cleanForm();
	});

	toggler();

	$("#korr").keyup(function(event) {
		$("#send").disable();
		$("#reciever").disable();

		if ($("#korr").val().length == 0) {
			$("#send").enable();
			$("#reciever").enable();
		}
	});

	$("#send").keyup(function(event) {
		toggler();
	});

	$("#reciever").keyup(function(event) {
		toggler();
	});
});

function clear_form_elements(ele) {

    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}



function cleanForm(){
    alert("hera");
    $("#korr").val() = "";
    $("#send").val() = "";
    $("#reciever").val() = "";
}

function toggler() {
	$("#korr").disable();

	if ($("#send").val().length == 0 && $("#reciever").val().length == 0) {
		$("#korr").enable();
		if ($("#korr").val().length > 0) {
			$("#send").disable();
			$("#reciever").disable();
		}
	}

}
