/* áldalános tinymce init admin oldal összes tinymce beviteli mezőjéhez */
function tiny_init() {
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		theme_advanced_buttons1_add_before : "nc_insert_document,nc_insert_image,save,newdocument,separator",
		theme_advanced_toolbar_location : "top",
		theme_advanced_resizing : true, 
		plugins : "table, nc_insert_image,nc_insert_document",
		language : "hu", 
		theme_advanced_buttons2_add : "tablecontrols, nc_insert_image,nc_insert_document",
		theme_advanced_disable : "anchor",
		auto_reset_designmode : true,
		inline_styles : false,
		entity_encoding : "raw",
		width : "100%",
		height: "300px",
		cleanup : true,
		encoding : 'xml',
		relative_urls : true,
		remove_script_host : false
	});
}

/* framework.js */
function toggle_admin_loader(s) {
	var item = document.getElementById('admin_loader');
	if (!item) return;
	s == true ? item.style.display="" : item.style.display="none";
}


/*
*  ajax hívás
*  @param sMethod - 'GET' vagy 'POST'
*  @param sUrl    - a meghívandó php oldal, GET esetén az átadandó paraméterekkel kiegészítve
*  @param func    - onreadystatechange-et megvalósító callback függvény
*  @param params  - egyéb adatok, POST esetén az átadandó paraméterek
*/
function ajaxRequest( sMethod, sUrl, func, params ) {
	var oRequest = null;
	var i;
	var sUrlTail = '';
	sMethod = sMethod || 'GET';
	params = params || '';
	//sUrl = sUrl.htmlEntities();
	try 
	{
		// Firefox, Opera 8.0+, Safari, IE7+
		oRequest = new XMLHttpRequest();
		if ( oRequest.overrideMimeType ) {
			oRequest.overrideMimeType( 'text/html' );
		}
	} 
	catch ( e ) 
	{
		// Internet Explorer
		try {
			oRequest = new ActiveXObject( "Msxml2.XMLHTTP" );

		} catch ( e ) {
			try {
				oRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( e ) { }
		}
	}
	if ( sMethod == 'GET' ) {
		if ( document.all ) {
			nocache = Math.random();
			oRequest.open( 'GET', sUrl + '&nocache=' + nocache+"&site="+global_site+"&lang="+global_lang, true );
		}
		else {
			oRequest.open( 'GET', sUrl + "&site="+global_site+"&lang="+global_lang, true );
		}
		oRequest.send( null );
	}
	else {
		oRequest.open("POST", sUrl+ "&site="+global_site+"&lang="+global_lang, true);
		oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oRequest.setRequestHeader("Content-length", params.length);
		oRequest.setRequestHeader("Connection", "close");
		oRequest.send( /*encodeURI(*/params/*)*/ || null ); 
	 	toggle_admin_loader(true);
	}
	
	

	oRequest.onreadystatechange = function() {
/*	    if ( oRequest.readyState == 1 ) {
			loadingIn();
		}*/
		//alert(oRequest.status+':'+oRequest.readyState);
		if ( oRequest.readyState == 4 ) {

			
//			setTimeout( 'loadingOut()', 1000 ); // k├ęsleltetve tesztel├ęs idej├ęre
		   try { // In some instance, status cannot be retrieve and will produce an error (ex: Port is not responsive)
			  if (oRequest.status == 200) {
				 //Set the main HTML of the body to the info provided by the AJAX Request
			   	toggle_admin_loader(false);
				func( oRequest.responseText, params );
			  }
		   } catch (e) {
				//alert('resp_errorcatch:'+func+' : '+params);
		   }
		}
	};
}


function sendPublicAJAXMessage( message, fReadyState, content )
{
	ajaxRequest( 'POST', global_site_host + 'index.php?' + message, fReadyState, content );
}



function sendFunctionAJAXMessage( message, fReadyState, content )
{
//	ajaxRequest( 'GET', 'admin/index.php?' + message, fReadyState );
	ajaxRequest( 'POST', global_site_host + 'index.php?' + message, fReadyState, content );
//	ajaxRequest( 'POST', 'index.php', fReadyState, message );
}


function sendGetAJAXMessage( message, fReadyState, content )
{
/*	var client = new XMLHttpRequest();
	client.open("GET", "index.php?system_function=get_ajax&" + message );
	client.send( null );
	
	response_text = client.responseText;
	
	if( response_text == -1 )
	{
		return false;
	}
	else
	{
		return response_text;
	}*/
	//ajaxRequest( 'GET', 'admin/index.php?system_function=get_ajax&' + message, fReadyState );
	ajaxRequest( 'POST', global_site_host + 'index.php?system_function=get_ajax&' + message, fReadyState, content );

}

function sendAJAXMessage( message, fReadyState, content ) // A control által összeállított üzenetet küldi el
{
	function fReadyStateCompleted( sResponse ) {
		if( sResponse == -1 )
		{
			return false;
		}
		var str_split = sResponse.split( '<#>' );
		for( i=0; i < str_split.length; i++ )
		{
			str = str_split[i].split( '|' );
			
			param = '';
			for( j = 0; j < str.length; j++ )
			{
				if( j == 0 ) // modul; melyik modultól jön
				{
					modul = str[j];
				}
				if( j == 1 ) // control; melyik controltól jött
				{
					control_from = str[j];
				}

				if( j == 2 ) // control; melyik controlnak megy
				{
					control = str[j];
				}
				
				
				if( j == 3 ) // funkció
				{
					func = str[j];
				}
				if( j == 4 ) // egyedi név
				{
					name = str[j];
				}
				if( 4 < j )
				{
					param += str[j] + '|';
				}
			}
			
//			alert( control_from );
			if ( control ) {
//				call_function = control + "( '" + modul + "', '" + name + "', '" + func + "', '" + param + "');";
				call_function = control + "( '" + modul + "', '" + name + "', '" + func + "', '" + param + "', '" + control_from + "');";

//				alert( call_function )
				eval( call_function );
			}
//			console.debug( 'valami' );
		}
		fReadyState( sResponse ); // ??? 

	}

	//ajaxRequest( 'GET', 'admin/index.php?system_function=ajax&' + message, fReadyStateCompleted );
	ajaxRequest( 'POST', global_site_host + 'index.php?system_function=ajax&' + message, fReadyStateCompleted, content );


	return false;
}

function insertContent( sResponseText, sDestinationID ) {
		var item = document.getElementById( sDestinationID );
		if ( item && sResponseText ) {
			item.innerHTML = sResponseText;
		}
}

function openWindowByParam( param )
{
	var url = global_site_host +  "index.php?site=public&lang=hu&" + param;
	var newwindow = window.open(url,'name','height=640,width=480,scrollbars=yes');
	if (window.focus)
	{
		newwindow.focus();
	}
	return false;
}

function hideByElementID( element )
{
	var item = document.getElementById( element );
	item.style.display = 'none';
}


String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};

function modul_article_show_ncimage(width, height, g, i) {
	w = width;
	h = height;
	title = ( typeof( title ) == 'undefined' ) ? 'Hungerit' : title;
	leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	topPosition = (screen.height) ? (screen.height-h)/2 : 0;

	settings = 'height=' + h +',width=' + w + ',innerWidth=' + w + ',innerHeight=' + h + ',top=' + topPosition + ',left=' + leftPosition + ',scrollbars=0,resizable=0';
//	win = window.open('http://w3.szeged.nexum.hu/hungerit/web/hu/dolgozo/index.php?lang=hu&mod=image_gallery&group_id='+g+'&windowed', 'WindowImg', settings)
	win = window.open('dolgozo/index.php?lang=hu&mod=image_gallery&group_id='+g+'&image_id='+i+'&windowed', 'WindowImg', settings); /* általánosabb */

}
