function delete_item(id, formId, msg) {

	if (!msg) msg = "Do you want to delete this item (id = " + id + ")?";
	input_box=confirm(msg);
	if (input_box==true) {
		var el = document.getElementById(formId);
		if (!el) alert("Warning! Wrong form ID!");
		else {
			if (el.action) el.action.value = "delete";
			if (el.primary) el.primary.value = id;
			el.submit();
		}
	}
}

function edit_item(id, formId) {
	var el = document.getElementById(formId);
	if (el) {
		if (el.action) el.action.value = "edit";
		if (el.primary) el.primary.value = id;
		el.submit();
	}
}

function add_item(formId) {
	var el = document.getElementById(formId);
	if (el) {
		if (el.action) el.action.value = "add";
		el.submit();
	}
}
function view_model(model_name, formId) {
	var el = document.getElementById(formId);
	if (el) {
		if (el.action) el.action.value = "view";
		if (el.model) el.model.value = model_name;
		el.submit();
	}
}

function verify_submit(obj_name){
	var el = document.getElementById(obj_name);
	if (!el) {
		return false;
	} else {
		switch (el.type) {
			case "checkbox":
				if (!el.checked) alert(el.alt);
				return el.checked;
				break;
			case "text":
				return true;
				break;
		}
		return false;
	}
}

function check_username(obj_name, form_id, activate_obj){
	var el = document.getElementById(obj_name);
	if (!el) {
		return false;
	} else {
		if (el.type != "text" || !el.value) {
			alert(el.alt);
			return false;
		} else {
			try {
				if (activate_obj) activate_obj.checked = true;
			} catch (err) {
			} 
			if (form_id) {
				el = document.getElementById(form_id);
				if (el.action) el.action.value = "check_username";
				el.submit();
			} 
		}
	}
}

function postBBCountry(){
	var form = document.getElementById('blackBookForm');
	if (form) {
		form.submit();
	}
}

function selectAdminProfile(select, id){
	var form = document.getElementById('adminSearchForm');
	var selector2 = document.getElementById('selector2');
	var form2 = document.getElementById('form_navigationbar');
	if (form) {
		if (select) selector2.value = id;
		else selector2.value = -id;
		if (form2) {
			form.start_page.value = form2.start.value;
		}
		form.submit();
	}
}

function selectAdminBlackBookProfile(select, id){
	var selector3 = document.getElementById('selector3');
	if (selector3) {
		selector3.value = 1;
	}
	selectAdminProfile(select, id);
}

function approveProfile(select, id){
	
	var form = document.getElementById('approveForm');
	var selector2 = document.getElementById('selector2');
	var reason_id = document.getElementById('reason_' + id);
	var reason = document.getElementById('reason');
	var form2 = document.getElementById('form_navigationbar'); 
	//alert(select + " id: " + id + " sel2: " + selector2.value + " " + form.action);
	//+ " reason: " + reason.value + " reason_id: " + reason_id.value);
	if (form) { 
		if (select) {
			selector2.value = id;
		} else {
			selector2.value = -id;
		}
		if (reason && reason_id){
			reason.value = reason_id.value;
		}
		if (form2) {
			form.start_page.value = form2.start.value;
		}
		form.submit();
	}
}

function denyPicture(id){
	approvePicture(id, false);
}

function approvePicture(id, approve){
	
	var form = document.getElementById('approvePicForm');
	
	var picID = document.getElementById('pictureID');
	var approveElem = document.getElementById('approve');
	
	var approveLocal = approve;
	if (approveLocal == null) approveLocal = true;
	if (form){
		if (picID){
			picID.value = id;
			if (approveElem) {
				approveElem.value = approveLocal;
				form.submit();
			}
		}
		
	}
}