function x_save_note(left, top, width, height) {
    noteTxt = document.getElementById(PhotoNotes.txtareaId);
    
    if (!noteTxt) {
        return 0;
    }
    txt = noteTxt.value;
    txt_clean = txt.replace(/(<([^>]+)>)/ig,""); 
    if (txt != txt_clean) {
        alert('No html tags please, I will clean it out for you');
        noteTxt.value = txt_clean;
        return 0;
    }
    if (txt == '') {
        return 0;
    }
    
	var img_id   = document.getElementById('img_id');
	var img_type = document.getElementById('img_type');

	if (!img_id || !img_type) {
	   return 0;
	}
	
    var options = {
        method: 'post',
        asynchronous: false,
        postBody: 'img_id='+img_id.value+'&img_type='+img_type.value+'&left='+left+'&top='+top+'&width='+width+'&height='+height+'&txt='+txt,
        // Handle successful response
        onSuccess: function(t) {},
        // Handle other errors
        onFailure: function(t) {
            alert('Error ' + t.status + ' -- ' + t.statusText);
        }
    }
    
    var request = new Ajax.Request('ajax_photo_notes/new_note.php', options);
    response = request.transport.responseText;
    
    if (response.match(/^\d+$/)) {
        return response;
    } else {
        alert(response);
        return 0;
    }
}

function x_edit_note(id, left, top, width, height) {
    noteTxt = document.getElementById(PhotoNotes.txtareaId);
    
    if (!noteTxt) {
        return 0;
    }
    txt = noteTxt.value;
    txt_clean = txt.replace(/(<([^>]+)>)/ig,""); 
    if (txt != txt_clean) {
        alert('No html tags please, I will clean it out for you');
        noteTxt.value = txt_clean;
        return 0;
    }
    if (txt == '') {
        return 0;
    }

    if (!id) {
	   return 0;
	}

    var options = {
        method: 'post',
        asynchronous: false,
        postBody: 'id='+id+'&left='+left+'&top='+top+'&width='+width+'&height='+height+'&txt='+txt,
        // Handle successful response
        onSuccess: function(t) {},
        // Handle other errors
        onFailure: function(t) {
            alert('Error ' + t.status + ' -- ' + t.statusText);
        }
    }
    
    var request = new Ajax.Request('ajax_photo_notes/edit_note.php', options);
    response = request.transport.responseText;
    
    if (response.match(/^\d+$/)) {
        return response;
    } else {
        alert(response);
        return 0;
    }
}

function x_delete_note(id) {
	if (!id) {
	   return 0;
	}

    var options = {
        method: 'post',
        asynchronous: false,
        postBody: 'id='+id,
        // Handle successful response
        onSuccess: function(t) {},
        // Handle other errors
        onFailure: function(t) {
            alert('Error ' + t.status + ' -- ' + t.statusText);
        }
    }
    
    var request = new Ajax.Request('ajax_photo_notes/delete_note.php', options);
    response = request.transport.responseText;
    
    if (response.match(/^\d+$/)) {
        return response;
    } else {
        alert(response);
        return 0;
    }
}


