$(document).ready(function() { 
	$(".deleteObjectAjax").click(deleteObject);
	$("div#notice[hidden='1']").hide();
	
}); 

function deleteObject() {
    var object = $(this).get(0).id;
    if (object.substr(6,25) == "PapersToPersonalDataTable"){
    	var entries = document.getElementsByClassName('tableEntry');
    	if(entries.length == 1){
    		alert(translation["deleteLastAuthorLabel"]);
    		//location.reload();
    		return;
    	}
    }
	if(object.search(/Delete/)==0) {
		object = object.substr(6,object.length);
		action="delete";
	};
	if(confirm(translation["confirmDeleteLabel"])){
		$.ajax({url: "indexAjax.php",type: "GET",data: "object0="+object+"&action0="+action});
		UnTip();
		// decrement counter
		textArray = $("div#tableSummary").text().split(" ");
		textArray[0]--;
		$("div#tableSummary").text(textArray.join(" "));
		$(this).parents("tr").fadeOut("slow",removeElement);
	}
}

function removeElement() {
	$(this).remove();
	location.reload();
}

function changeBool(object, fieldName, form) {
	var boolValue= 0;
	if(form.bool.checked)
		boolValue= 1;
	var action = "editValue:fieldName="+fieldName+",value="+boolValue+"";
	$.ajax({url: "indexAjax.php",type: "GET",data: "object0="+object+"&action0="+action, dataType: "json", success:processResponse, error:alertAndReload});
}

function changeString(object, fieldName, form) {
	var stringValue= form.string.value;
	stringValue = stringValue.replace(/:/,"--colon--"); //this is temporary
	stringValue = stringValue.replace(/,/,"--comma--"); //this is temporary
	stringValue = stringValue.replace(/=/,"--equal--"); //this is temporary
	stringValue = stringValue.replace(/&/,"--amp--"); //this is temporary
	var action = "editValue:fieldName="+fieldName+",value="+stringValue+"";
	//alert("object0="+object+"&action0="+action);
	$.ajax({url: "indexAjax.php",type: "GET", data: "object0="+object+"&action0="+action, dataType: "json", success:processResponse});
}

function processResponse(data,status){
	if(data.status!="1"){
		alertAndReload();
	}
}

function alertAndReload(){
	alert(translation["disconectionLabel"]);	
	location.reload();
}


