$(document).ready(function() {
	$('#xtemplates img.button').qtip({
		position: {
			corner: {
				tooltip: 'bottomLeft',
				target: 'topRight'
			}
		},
		style: {
			border: {
				width: 1,
				radius: 2,
				color: '#D2DCEA'
			},
			padding: 3,
			textAlign: 'center',
			tip: true,
			background: '#ffffff',
			color: '#333333',
			name: 'cream'
		}
	});
});

function xmessage_new(xtemplate_id, xtemplate_db) {
	_isDirty = false;
	
	var form = document.getElementById('form');

	form.xtemplate_id.value = xtemplate_id;
	form.xtemplate_db.value = xtemplate_db;

	if (form.onsubmit()==true)
		form.submit();
}

function xtemplate_delete(xtemplate_id, xtemplate_name) {
	$("#dialog .todelete").text(xtemplate_name);
	$("#dialog").dialog({
		beforeclose: function(event, ui) {
			$(this).dialog('destroy');
		},
		bgiframe: true,
		resizable: true,
		modal: true,
		title: 'מחק תבנית אישית',
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'מחק את התבנית': function() {
				xtemplate_submit(xtemplate_id, null, false, '/xtemplates/delete_xtemplate.php');
				$(this).dialog('destroy');
			},
			'בטל': function() {
				$(this).dialog('destroy');
			}
		}
	});
}

function xtemplate_submit(xtemplate_id, xtemplate_db, xtemplate_new, form_action) {
	var form = document.getElementById('xtemplates');

	form.xtemplateid.value = xtemplate_id;
	form.xtemplatedb.value = xtemplate_db;
	form.newxtemplate.value = xtemplate_new;

	if (form_action)
		form.action = form_action;

	form.submit();
}
