function News() {
	// current nodeIDX from getvars, if get var is not setted then CONTENT_ROOT
	var iNodeIDX = 0;
	
	this.init = function(iNodeIDX) {
		this.iNodeIDX = iNodeIDX;
	}
	
	this.add_category = function(){
		window.open("index.php?name=ContentManagement&method=insert&parentIDX="+this.iNodeIDX+"&blocks=bn","categoryInputForm","width=800,height=600,resizable=yes,scrollbars=yes");
	}
	
	this.update_category = function(iNodeIDX){
		window.open("index.php?name=ContentManagement&method=update&nodeIDX="+iNodeIDX+"&blocks=bn","categoryInputForm","width=800,height=600,resizable=yes,scrollbars=yes");
	}
}

var News = new News();

function saveNewsForm(strSaveOK) {
    /*
    *	tinyMCE.triggerSave()
    *		Makes a cleanup and moves the contents from the editor to the form field.
    *		This method is automatically called by tinyMCE by adding a trigger on the forms submit method.
    *
    *		Must be called manually in AJAX forms!
    */
    tinyMCE.triggerSave();
	var newsForm = $j("#insertForm :input").serialize(); // serialize() drops off all unchecked checkboxes, radiobuttons etc..

	$j.ajax({
		url: "index.php?name=News&method=save&blocks=ah",
		type: "POST",
		data:newsForm,
		dataType: "html",
  		success: function(msg){
  			if(msg == 'notitle'){
  				Common.showMessage('error',Common.getLocale(objLC.js_noTitleError,'js_noTitleError'));
  			}
  			else{
				if(window.location.href.match("method=insert")) {
					window.location.href = "index.php?name=News&method=update&nodeIDX="+parseInt(msg);
				}
				else {
					Common.showMessage('success',strSaveOK);
				}
			}
		}
	});
}

var dlg_tellafriend = "";

function tellAFriend(data, header){
	if(document.getElementById('dlg_tellafriend'))
		var dlg_tellafriend = $j("#dlg_tellafriend");
	else
		var dlg_tellafriend = $j("<div id='dlg_tellafriend'></div>");
	dlg_tellafriend.appendTo("#body");
	dlg_tellafriend.load("index.php?name=News&method=tellAFriend&blocks=ah&data="+data);

	dlg_tellafriend = $j("#dlg_tellafriend").modal({
		onClose: function(dialog){
			dialog.data.fadeOut('fast', function () {
				dialog.container.hide('fast', function () {
					$j.modal.close();
				});
			});
		},
		containerHeaderText: header
	});
}

function changeParent(parentIDX) {
	$j("#parentIDX").val(parentIDX);
}

function closeNewsForm(){
	window.opener.location.reload();
	window.close();
}

function deleteNews(nodeIDX, elementIDX, confirmText, successMessage) {
	if(confirm(confirmText)) {
		window.location = "index.php?name=News&method=delete&nodeIDX="+nodeIDX+"&useAjax=false";
	}
}

function openPagePicker(field_name, win){
	tinyMCE.activeEditor.windowManager.open({
        file : "index.php?name=News&method=getPagePicker&blocks=bn",
        title : 'Page picker',
        width : 350,  // Your dimensions may differ - toy around with them!
        height : 250,
        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 pagePickerOk(){
	var page = $j('input[name=pagePickerValue]').val();
	var win = tinyMCEPopup.getWindowArg("window");
	win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = page;
	tinyMCEPopup.close();
}


