function AddLink(fileUrl) {
	window.location.href = encodeURI(fileUrl) ;
}

function addPage(title_str, url) {
	win = new Window({
		className: "royal", 
		title: title_str, 
		height: 200, width: 400, 
		destroyOnClose: true,
		showEffectOptions: {duration:0.3}, 
		hideEffectOptions: {duration:0.2}});
	win.setAjaxContent(url, {}, true, true);
	{ 
		try { 
			$('page_23_container').style.backgroundColor = 'transparent';
		} 
		catch(err) {
		}
	}
}

function editPage(id, public) {
	win = new Window({
		className: "royal", 
		height: 80, 
		width: 350, 
		destroyOnClose: true, 
		showEffectOptions: {duration:0.3}, 
		hideEffectOptions: {duration:0.2}});
	win.setAjaxContent('ajax/editmenu.php', {method: 'get', parameters: {'id':id, 'public':public}}, true, true);
}

function pagePublic(id, pub) {
	new Ajax.Request('ajax/publicpage.php', {
		method: 'post',
		parameters: {
			page_id: id,
			public: pub
		},
		asynchronous: false
	});
	window.location.href = window.location.href;
}

function confirm2(question, url) {
	Dialog.confirm(question, {
		width:300, 
		okLabel: "Jah",
		cancelLabel: "Ei",
		cancel:function(win) {},
		className: 'royal',
		ok:function(win) {window.location.href = url;},
		showEffectOptions: {duration:0.3}, 
		hideEffectOptions: {duration:0.2}
	});
}

function myFileBrowser (field_name, url, type, win) {
    var cmsURL = 'http://localhost/Royal%20CMS/select.php?module=select';    // script URL - use an absolute path!
    cmsURL = cmsURL + "&type=" + type;

    tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'FileBrowser',
        width : 420,  // Your dimensions may differ - toy around with them!
        height : 400,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
    return false;
  }
  
  
function setCal(year, month) {
	new Ajax.Updater('calendar_container', 'ajax/calendar.php', {
		method: 'get',
		parameters: {
			y: year,
			m: month
		}
	});
}

function updatePage(full_url, element) {
	new Ajax.Updater(element, full_url+'include/');
	return false;
}

function updatePageStatus(page_id) {
	new Ajax.Updater('page_status', 'admin.php?module=pages&event=ajax_change_active', {
		method: 'post',
		parameters: {id: page_id},
		onSuccess: function() {
			var hidebtn = $('hidebtn');
			if (hidebtn.innerHTML == 'Avalikusta') {
				hidebtn.innerHTML = 'Peida';
			} else {
				hidebtn.innerHTML = 'Avalikusta';
			}
			setMessage('Lehe staatuse muutmine õnnestus!');
			showMessage();
		}
	});
}

function submitForm(form_id, page_id) {
	var form = $(form_id);
	var formvalues = form.serialize(true);
	formvalues.content = tinyMCE.get('content').getContent();
	formvalues.id = page_id
	
	new Ajax.Request('admin.php?module=pages&event=ajax_save', {
		method: 'post',
		parameters: formvalues,
		onSuccess: function(result) {
			setMessage(result.responseText);
			showMessage();
		}
	});
}

function setMessage(txt) {
	$('message').firstDescendant().innerHTML = txt;
}

function showMessage() {
	Effect.SlideDown('message', { queue: 'end', transition: Effect.Transitions.sinoidal });
	setTimeout(function() {
		Effect.SlideUp('message', { queue: 'end', transition: Effect.Transitions.sinoidal });
	}, 2000);
}
