// JavaScript Document
//============================obsługa stron statycznych================================
var static_sites = new Static_sites(reviewCallback);

//============================obsługa programu================================
function standard_site_perform(result){
	hideloading();
	if (result == '0') showsites(order, search_);
	else alertmsg(result);
}
function showsites(ord, ser, ret){
	if (action != sites_action){
		action = sites_action;
		resetvariables();
	}
	else search_ = ser;

	order = ord;
	action = sites_action;
	showloading();
	static_sites.showsites(order, search_, ret);
}
function showsites_find(){
	showsites(order, $('search_us').value);
}
function addsite(ret){
	showloading();
	static_sites.addsite(ret);
}
function doaddsite(form){
	showloading();
	static_sites.doaddsite(getPayload(form));
}
function locksite(id){
	showloading();
	static_sites.locksite(id);
}
function unlocksite(id){
	showloading();
	static_sites.unlocksite(id);
}
function editsite(id, ret){
	showloading();
	static_sites.editsite(id, ret);
}
function doeditsite(form){
	showloading();
	static_sites.doeditsite(getPayload(form));
}
function remsite(id){
	var answer = confirm("Na pewno chcesz usunąć stronę?");
	if (answer){
		showloading();
		static_sites.remsite(id);
	}
}
function setmainpage(ret){
	showloading();
	static_sites.setmainpage(ret);
}
function dosetmainpage(form){
	showloading();
	static_sites.dosetmainpage(getPayload(form));
}
function manageposition(id, ret){
	showloading();
	static_sites.manageposition(id, ret);
}
function domanageposition(form){
	var payload = getPayload(form);
	showloading();
	var txt = '';
	$$('.sortme').each(function(el){
		if (txt == '') txt = el.id;
		else txt += '|'+el.id;
	});
	payload['list'] = txt;
	static_sites.domanageposition(payload);
}
function filtersites(){
	if ($('upperlevel').value == '0' || $('upperlevel').value == '-1') $('lowerlevelcontainer').innerHTML = '';
	else static_sites.filtersites($('upperlevel').value);
}
function updatemainmodule(){
	if ($('mainmodule').value != '0') $('link').value = $('mainmodule').value;
	else $('link').value = '';
}
function changesitetype(){
	if ($('status').value == 'external'){
		$('dynamiccontent').disabled = true;
		$('mainmodule').disabled = true;
		$('title').disabled = true;
		$('subtitle').disabled = true;
		$('link').disabled = true;
		$('titletag').disabled = true;
		$('metakeys').disabled = true;
		$('metadescription').disabled = true;
		$('external').disabled = false;
		$('top').disabled = true;
		$('mainmenu').disabled = true;
		$('topmenu').disabled = true;
		$('leftmenu').disabled = true;
		$('rightmenu').disabled = true;
		$('bottommenu').disabled = true;
		$('footer').disabled = true;
		$('mainmodule_txt').removeClass('marked');
		$('dynamic_txt').removeClass('marked');
		$('title_txt').removeClass('marked');
		$('subtitle_txt').removeClass('marked');
		$('link_txt').removeClass('marked');
		$('titletag_txt').removeClass('marked');
		$('metakeys_txt').removeClass('marked');
		$('metadescription_txt').removeClass('marked');
		$('external_txt').addClass('marked');
		$('top_txt').removeClass('marked');
		$('topmenu_txt').removeClass('marked');
		$('leftmenu_txt').removeClass('marked');
		$('rightmenu_txt').removeClass('marked');
		$('bottommenu_txt').removeClass('marked');
		$('footer_txt').removeClass('marked');
		
		if (editor == 'FCKeditor') toggleFCKeditor(FCKeditorAPI.GetInstance('FCKeditor1'));
		else $('FCKeditor1').disabled = true;
		editor_disabled = true;
	}
	else {
		if ($('status').value == 'module'){
			$('mainmodule').disabled = false;
			$('dynamiccontent').disabled = true;
			$('mainmodule_txt').addClass('marked');
			$('dynamic_txt').removeClass('marked');
			$('link').disabled = true;
			$('link_txt').removeClass('marked');
		}
		else {
			$('mainmodule').disabled = true;
			$('dynamiccontent').disabled = false;
			$('mainmodule_txt').removeClass('marked');
			$('dynamic_txt').addClass('marked');
			$('link').disabled = false;
			$('link_txt').addClass('marked');
		}
		$('title').disabled = false;
		$('subtitle').disabled = false;
		$('titletag').disabled = false;
		$('metakeys').disabled = false;
		$('metadescription').disabled = false;
		$('external').disabled = true;
		$('top').disabled = false;
		$('mainmenu').disabled = false;
		$('topmenu').disabled = false;
		$('leftmenu').disabled = false;
		$('rightmenu').disabled = false;
		$('bottommenu').disabled = false;
		$('footer').disabled = false;
		$('title_txt').addClass('marked');
		$('subtitle_txt').addClass('marked');
		$('titletag_txt').addClass('marked');
		$('metakeys_txt').addClass('marked');
		$('metadescription_txt').addClass('marked');
		$('external_txt').removeClass('marked');
		$('top_txt').addClass('marked');
		$('topmenu_txt').addClass('marked');
		$('leftmenu_txt').addClass('marked');
		$('rightmenu_txt').addClass('marked');
		$('bottommenu_txt').addClass('marked');
		$('footer_txt').addClass('marked');
		if (editor_disabled == true) {
			if (editor == 'FCKeditor') toggleFCKeditor(FCKeditorAPI.GetInstance('FCKeditor1'));
			else $('FCKeditor1').disabled = false;
		}
		editor_disabled = false;
	}
}
