// JavaScript Document
//============================obsługa szablonów===============================
var templates = new Templates(reviewCallback);

//============================obsługa programu================================
function showtemplates(ord, ser, ret){
	if (action != templates_action){
		action = templates_action;
		resetvariables();
	}
	else {
		order = ord;
		search_ = ser;
	}
	action = templates_action;
	showloading();
	templates.showtemplates(order, search_, ret);
}
function standard_templates_perform(result){
	hideloading();
	if (result == '0') showtemplates(order, search_);
	else alertmsg(result);
}
function showtemplates_find(){
	showtemplates(order, $('search_us').value);
}
function addtemplate(ret){
	showloading();
	templates.addtemplate(ret);
}
function doaddtemplate(form){
	if (check_template()){
		showloading();
		templates.doaddtemplate(getPayload(form));
	}
}
function locktemplate(id){
	showloading();
	templates.locktemplate(id);
}
function unlocktemplate(id){
	showloading();
	templates.unlocktemplate(id);
}
function edittemplate(id, ret){
	showloading();
	templates.edittemplate(id, ret);
}
function doedittemplate(form){
	if (check_template()){
		showloading();
		templates.doedittemplate(getPayload(form));
	}
}
function remtemplate(id){
	var answer = confirm("Na pewno chcesz usunąć szablon?");
	if (answer){
		showloading();
		templates.remtemplate(id);
	}
}
function check_template(){
	if ($('name').value == ''){
		alertmsg('Podaj nazwę szablonu');
		$('name').focus();
		return false;
	}
	return true;
}
