// ** ********************************************** **
// ** AteDin CMS common.js file
// ** www.atedin.hu
// ** atedin@atedin.hu
// ** ********************************************** **

// alert ('include done');

	// TOOLTIP  and change content dinamicly
	var tooltipATD = {
 
		init : function () {
		 html_code = '<div id="TOOLTIP"></div><div id="TOOLTIParrow"></div>';
		 document.write(html_code);
		},

		move : function (parentOBJ,type) {		

				var winX = document.viewport.getWidth();

				var scrollbarpos = document.viewport.getScrollOffsets();
				var tooldims = $('TOOLTIP').getDimensions();

	
				switch (type) {
				case('fixedright'):
					var ppos = Position.page(parentOBJ);
					var pdims = parentOBJ.getDimensions();
					var x = ppos[0] + scrollbarpos[0] + pdims.width;
					var y = ppos[1] + scrollbarpos[1];
					break;
				case('float'):
				default:
					var x = xMousePos + 15;
					var y = yMousePos - 10;
				break;
				}
				
				if (xMousePos < winX - (pdims.width + tooldims.width + 20)) {			
					var obj = $('TOOLTIP');
					obj.style.left = x + 10 + "px";
					obj.style.top = y + "px";
	
					var obj = $('TOOLTIParrow');
					obj.style.left = x + "px";
					obj.style.top = y + "px";
				} else {
					
					var obj = $('TOOLTIP');
					obj.style.left = x - pdims.width - tooldims.width - 10 + "px";
					obj.style.top = y + "px";
	
					var obj = $('TOOLTIParrow');
					obj.style.left = x - pdims.width - 20 + "px";
					obj.style.top = y + "px";					
				}
						
				// parentOBJ.style.border = "2px solid #FF0000";
		},
		
		show : function(msg)																	// show and move TOOLTIP
		{
			if (msg) {$('TOOLTIP').update(msg);} else return;								// modify content if 'msg' set
			if ($('TOOLTIP').effectrun == true) return;
			else {
				// $('debug').update('start');
				$('TOOLTIP').style.display="block";
				$('TOOLTIParrow').style.display="block";	
				$('TOOLTIP').tipDim = $('TOOLTIP').getDimensions();
				$('TOOLTIP').cnt = 0;
				// setTimeout(alert('werh'),55000);
				tooltipATD.effect()
			}
		},

		effect : function(type)
		{
			$('TOOLTIP').effectrun = true;
			$('TOOLTIP').cnt = $('TOOLTIP').cnt + 5;
			// $('TOOLTIP').style.width = $('TOOLTIP').cnt+"px";
			// $('debug').update($('TOOLTIP').cnt+' * '+$('TOOLTIP').tipDim.width+' * '+$('TOOLTIP').style.width);
			if ($('TOOLTIP').cnt < $('TOOLTIP').tipDim.width) $('TOOLTIP').effect = setTimeout(tooltipATD.effect,50);
			else {
				$('TOOLTIP').effectrun = false;
				// $('debug').update('effect over');
				}
		},
	
		hide : function ()																		// hide TOOLTIP
		{
				// $('debug').update('hide tooltip');
				clearTimeout($('TOOLTIP').effect);
				$('TOOLTIP').style.display="none";
				$('TOOLTIParrow').style.display="none";
				$('TOOLTIP').effectrun = false;
		}
	}
	/**
	*
	* Custom DOM mod
	* make tooltip from title tag on DIV, IMG, input elements
	*
	*/


	function AteDinCustomDOMchanges() {	
		// custom functions DOM modify
		document.observe("dom:loaded", function() {
			AteDindoDOMmod();	
		})
	}
	
	function AteDindoDOMmod() {
		  // initially hide all containers for tab content
			var targets = $$('div,input,textarea,img,p,a');
			targets.each( function(item) {				
				var tooled = item.attributes["tooltip"];
				var titled = item.attributes["title"];
				var titleData = item.title.split("|");
				if (titleData[1]) var DisplayType = titleData[1];
				else var DisplayType = 'fixedright';
				if(item.hasAttribute['tooled']) var displaythis = item.tooltip;
				else var displaythis = titleData[0];
					if (titled) {
						item.onmousemove = function()
							{
							tooltipATD.move(item,DisplayType);
							};
						item.onmouseover = function()
							{
							tooltipATD.show(displaythis);
							};
						item.onmouseout = function()
							{
							tooltipATD.hide();
							};
					item.tooltip = item.title
					item.removeAttribute("title");
					} else {
						// alert ('no');
					}
				})	
	}
	
// ** file lib

function EDITfiles(ID) {
setLOADING("fl_displayDIV");
new Ajax.Updater("fl_displayDIV", "/system/file_library_showfile.php?fileID="+ID);
// YposLAYERtoTOP("fl_displayDIV",0);
}
function filterSEARCH() {
	extension = $F("select_types");
	searchTEXT = $F("search");
	setLOADING ("fl_listDIV");
	new Ajax.Updater("fl_listDIV", "/system/file_library_showlist.php?extension="+extension+"&STR="+searchTEXT);
}
function startUPLOADfilelib() {
	if ($F('uploadthis') == '') {
		systemFLOATmessage_show(text_select_file);
		return;
	}
	document.file_library_adminFORM.submit();
	$("screen_fade").setOpacity = ("0.8");
	setLOADING("fl_admin");
	showLAYER("screen_fade");
}
function startIMPORT() {
	if ($F('importthis') == false) {
	document.file_import_adminFORM.submit();
	$("screen_fade").setOpacity = ("0.8");
	setLOADING("fl_admin");
	showLAYER("screen_fade");
	} else {
		systemFLOATmessage_show(text_no_file_selected);
	}
}

// **

function click_it(button) {
	$(button).click();
}

// ** AteDin Clock

	function clock_init_display()
		{
		 html_code = '<div id="ATEDINclock">clock</div>';
		 document.write(html_code);
		 startTime();
		}
		
	function startTime()
		{
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		// add a zero in front of numbers<10
		m=checkTime(m);
		s=checkTime(s);
		timedisplay = h+":"+m+":"+s+"<br/>";
		$('ATEDINclock').update(timedisplay);
		t=setTimeout('startTime()',500);
		}
		
	function checkTime(i)
		{
		if (i<10)
		  {
		  i="0" + i;
		  }
		return i;
}

// *********************************
// ********* Count down clock
 
	function countdown_clock_session(timeleft)
		 {
		 html_code = '<div id="countdown"></div>';
		 document.write(html_code);
		 countdown(timeleft);                
		 }			 
		 
	function countdown(timeleft)
		 {	 
		storetime = timeleft;
		
		if(timeleft < 0)
			timeleft = 0;
		 
		days = Math.floor(timeleft / (60 * 60 * 24));
		timeleft %= (60 * 60 * 24);
		hours = Math.floor(timeleft / (60 * 60));
		timeleft %= (60 * 60);
		minutes = Math.floor(timeleft / 60);
		timeleft %= 60;
		seconds = timeleft;
		
		if (minutes < 10) mZero = '0'; else mZero = ""; 
		if (seconds < 10) sZero = '0'; else sZero = ""; 

		if (storetime == 60) {
			systemFLOATmessage_show(the_session_will_close_soon);
			$('countdown').className="adminsarga";
			}
		if (storetime == 30) {
			systemFLOATmessage_show(the_session_will_close_soon);
			$('countdown').className="adminpiros";
		}

		displayTIME = mZero + minutes + ':' + sZero + seconds;
		$('countdown').update(displayTIME);

		tickrate = 1000;
		storetime = storetime - tickrate / 1000;

		 //Recursive call, keeps the clock ticking.
		 setTimeout('countdown(storetime);', tickrate);
		 }	
	
// *********************************
// ********* AJAX based - required prototype.js

	// visszaforditja az XML ben levo tombot tombbe
	function XML2array(xml) {
		var root = xml.documentElement;
		var result = new Array();
//alert ("rt:"+root);
		for(var i=0;i<root.childNodes.length;i++) {
			var itm = root.childNodes[i];
//alert(itm);		
			var chitm_list = itm.getElementsByTagName('item');
			var	key = getChildNodeText(itm,'key');
			if (chitm_list.length == 0) {
				var val = getChildNodeText(itm,'val');
//				alert ("var1: "+key+" => "+val);	
				result[key] = val;
			} else {
				var ar_ch = new Array();
//				alert ("arr:"+itm.childNodes);
				for(var j=1;j<itm.childNodes.length;j++) {
//				alert("j:"+j);	
					var chitm = itm.childNodes[j];
					var chkey = getChildNodeText(chitm,'key');
					var chval = getChildNodeText(chitm,'val');
					ar_ch[chkey] = chval;
//				alert ("chvar"+j+": "+chkey+" => "+chval);	
//				alert (ar_ch[chkey]);
				}
				result[key] = ar_ch;
//				alert ("var2: "+key+" => "+ar_ch);	
			}
		}
		return result;
	}

	function getChildNodeText(element, childTagName) {
		var elements = element.getElementsByTagName(childTagName);
		if (elements.length == 0) {
			return '';
		}
		else if (elements.item(0).textContent) {
			return elements.item(0).textContent;
		}
		else {
			return elements.item(0).text;
		}
	}
	
	//############################################################################################	
	// altalanos refresh - ajax fugveny elrejtese
	function refreshTHIS(divID,path) {
		// setLOADING(divID);
		new Ajax.Updater(divID, path);
	}
	
	//############################################################################################	
	// ** Postafiok jelszo csere SUBMIT	
	function GOchange(formID) {
		if ($F('jelszo1') == $F('jelszo2') && $F('jelszo1') !== "") {
			$(formID).submit();
		} else {
			alert ('Nem egyezik a ket jelszo, a jelszo nem lehet ures');
		}
	}
	
	
	function is_numeric(myvar) {
    return !isNaN(myvar * 1);
	}
	

	//############################################################################################
	// articles
	
	function article_create_AJAX() {
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
									  {method: 'get', 
									  parameters: {
									  	ajax_cmd: 'CreateNewArticle'
										}, 
									  onComplete: article_createDONE} );
	}

	function article_createDONE(originalRequest) {
		
		var xml = originalRequest.responseXML;
		res = XML2array(xml);

		setLOADING("at_admin");
		setLOADING("at_list");	
		systemFLOATmessage_show('article created');
		new Ajax.Updater("at_list", "/system/CMS/CMS_article_list.php");	
		new Ajax.Updater("at_admin", "/system/CMS/CMS_article_admin.php?article=res['new']");
	}
	
	function article_delete_AJAX(aid) {
		if (!confirm('Are you sure? / Biztos?')) return;
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
									 		ajax_cmd: 'DeleteArticle',
											aid: aid
											}, 
									  onComplete: article_deleteDONE} );
	}	
	
	function article_deleteDONE(originalRequest) {
		
		setLOADING("at_admin");
		setLOADING("at_list");	
		systemFLOATmessage_show('article deleted');
		new Ajax.Updater("at_list", "/system/CMS/CMS_article_list.php");	
		new Ajax.Updater("at_admin", "/system/CMS/CMS_article_admin.php");
	}	

	function articlePREVIEW(article) {
		updateSUBpage('/system/CMS/CMS_article_preview.php?article='+article);
	}
	
	function topicsfilter() {
		setLOADING("at_list");
		topicFILTER = $F('topic');
		new Ajax.Updater('at_list','/system/CMS/CMS_article_list.php?topic='+topicFILTER);	
	}

	function article_public_switch(aid) {
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
							  {method: 'get', 
							  parameters: {
								ajax_cmd: 'ChangeArticlePublic',
								aid: aid
								}, 
							  onComplete: article_public_switchDONE} );
	}
	
	function article_public_switchDONE(originalRequest) {
		setLOADING("at_admin");
		setLOADING("at_list");
		// systemFLOATmessage_show('status changed');	
		new Ajax.Updater("at_list", "/system/CMS/CMS_article_list.php");	
		new Ajax.Updater("at_admin", "/system/CMS/CMS_article_admin.php");
}

	//############################################################################################
	//############################################################################################
	//############################################################################################
	//############################################################################################
	//## MENU 
	
	function openmenu(menuID,level,parents,childs) {			
		divIDg = 'MENUgDIV' + menuID;
		divIDi = 'MENUiDIV' + menuID;
		divIDiDIMENSION = $(divIDi).getDimensions();
		divIDgDIMENSION = $(divIDg).getDimensions();

		if ($(divIDg).style.display == "block" && $(divIDg).animVAR == 0) return;
		else showLAYER(divIDg);

		// ** INIT MENU		
		clearTimeout($(divIDg).menuANIMtimer);
		clearTimeout($(divIDg).menuKEEPtimer);
		clearTimeout($(divIDg).menuCLOSEtimer);
		clearTimeout($(divIDg).menuWAITtimer);
		
		$(divIDg).style.zIndex=50;
		$(divIDg).style.overflow = 'visible';
		$(divIDg).setOpacity = ("1");
		

		if ($(divIDi).className.include('_keephover')) {
			var len = $(divIDi).className.length;
			// $(divIDi).className = $(divIDi).className.substr(0,len-10);
		} else {
			$(divIDi).className = $(divIDi).className+'_keephover';
		}
		
		if ($(divIDg).origheight) {
			$(divIDg).style.height = $(divIDg).origheight + 'px';
		} else {
			$(divIDg).origheight = divIDgDIMENSION.height; 
		}
		
		if (level < 2) $(divIDg).clonePosition(divIDi, {setWidth: false,setHeight: false,offsetTop:divIDiDIMENSION.height})
		else $(divIDg).clonePosition(divIDi, {setWidth: false,setHeight: false,offsetLeft:divIDiDIMENSION.width})

		if ($(divIDg).animVAR) $(divIDg).animVAR = -1;

		$(divIDg).menuKEEPtimer = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 50);
	}

	// -----
	
	function menukeep(menuID,level,parents,childs) {
		scrollbarpos = document.viewport.getScrollOffsets();
		var xMoff =  (Number(xMousePos) - Number(scrollbarpos[0]));
		var yMoff =  (Number(yMousePos) - Number(scrollbarpos[1]));
		var divIDg = 'MENUgDIV' + menuID;
		var divIDi = 'MENUiDIV' + menuID;

		clearTimeout($(divIDg).menuKEEPtimer);
		clearTimeout($(divIDg).menuANIMtimer);
		clearTimeout($(divIDg).menuCLOSEtimer);
		
		var mouseoverDIVg = Position.within($(divIDg), xMousePos, yMousePos);
		var mouseoverDIVi = Position.within($(divIDi), xMousePos, yMousePos);		
		var mouseoverDIVgMoff = Position.within($(divIDg), xMoff, yMoff);
		var mouseoverDIViMoff = Position.within($(divIDi), xMoff, yMoff);

		// $('debug').update(yMousePos+'keepstart');

		if (childs !== "" || childs !== undefined) {
			childsARRAY = childs.split(',');
			while (divID = childsARRAY.pop()) {
				divIDgP = 'MENUgDIV' + divID;
				mouseoverDIVgP = Position.within($(divIDgP), xMousePos, yMousePos);
				mouseoverDIVgPMoff = Position.within($(divIDgP), xMoff, yMoff);
					if (mouseoverDIVgP || mouseoverDIVgPMoff) {
						clearTimeout($(divIDg).menuCLOSEtimer);
						// $('debug').update(yMousePos+'submenu');
						$(divIDg).menuWAITtimer = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 60);
						return;
					}
			}
		}

		if (mouseoverDIVi || mouseoverDIVg || mouseoverDIViMoff || mouseoverDIVgMoff) {
			$(divIDg).style.zIndex= 10;
			clearTimeout($(divIDg).menuCLOSEtimer);
			// $('debug').update(yMousePos+'menu');
			$(divIDg).waitmenuTIMER = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 60);
		} else {
		// $('debug').update(yMousePos+'close');
		$(divIDg).style.zIndex= 1;
		// $(divIDg).menuWAITtimer = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 60);
		// $(divIDg).menuCLOSEtimer = setTimeout('menuCLOSEslideoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 60);
		$(divIDg).menuCLOSEtimer = setTimeout('menuCLOSEsimple(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 340);

		}
	}
	
	// -----

	function menuCLOSEsimple(menuID,level,parents,childs) {
		var divIDg = 'MENUgDIV' + menuID;
		var divIDi = 'MENUiDIV' + menuID;

		clearTimeout($(divIDg).menuWAITtimer);

		if ($(divIDi).className.include('_keephover')) {
			len = $(divIDi).className.length;
			$(divIDi).className = $(divIDi).className.substr(0,len-10);
		}
		var childsARRAY = childs.split(',');
		while (divID = childsARRAY.pop()) {
		var divIDgc = 'MENUgDIV' + divID;
		hideLAYER(divIDgc);
		}
		hideLAYER(divIDg);
	}

	// -----

	function menuCLOSEslideoff(menuID,level,parents,childs)
		{
			var ANIMspeed = 20;
			
			var divIDg = 'MENUgDIV' + menuID;
			var divIDi = 'MENUiDIV' + menuID;

			clearTimeout($(divIDg).waitmenuTIMER);

			var DIMENSIONg = $(divIDg).getDimensions(); 

			$(divIDg).style.overflow = "hidden";

			if ($(divIDg).animVAR < 0 || $(divIDg).animVAR == undefined || $(divIDg).animVAR == NaN)
			{
				$(divIDg).animVAR = ANIMspeed;
			}

			closeSTEPnext = Math.ceil(DIMENSIONg.height - Math.abs(DIMENSIONg.height / $(divIDg).animVAR));
			if (closeSTEPnext > DIMENSIONg.height) closeSTEPnext = DIMENSIONg.height;

			if ($(divIDg).animVAR > 1)
			{
				$(divIDg).animVAR = $(divIDg).animVAR - 1;
				$(divIDg).menuANIMtimer = setTimeout('menuCLOSEslideoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 10);
				$(divIDg).style.height = closeSTEPnext + 'px';
			}
			else
			{
			if ($(divIDi).className.include('_keephover'))
				{
					var len = $(divIDi).className.length;
					$(divIDi).className = $(divIDi).className.substr(0,len-10);
				}
				childsARRAY = childs.split(',');
				while (divID = childsARRAY.pop()) {
				var divIDgc = 'MENUgDIV' + divID;
				$(divIDgc).style.overflow = "visible";
				hideLAYER(divIDgc);
				}
				$(divIDg).style.overflow = "visible";
				hideLAYER(divIDg);
			}
	}
	
	function menuCLOSEfadeoff(menuID,level,parents,childs)
		{
			var ANIMspeed = 10;

			var divIDg = 'MENUgDIV' + menuID;
			var divIDi = 'MENUiDIV' + menuID;
			var DIMENSIONg = $(divIDg).getDimensions(); 

			clearTimeout($(divIDg).waitmenuTIMER);

			if ($(divIDg).animVAR < 0 || $(divIDg).animVAR == undefined || $(divIDg).animVAR == NaN)
			{
				$(divIDg).animVAR = ANIMspeed;
			}

			var closeSTEPnext = Math.ceil((99 / ANIMspeed) * $(divIDg).animVAR);
			
			if ($(divIDg).animVAR > 1)
			{
				$(divIDg).animVAR = $(divIDg).animVAR - 1;
				$(divIDg).menuANIMtimer = setTimeout('menuCLOSEfadeoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 40);

				$(divIDg).style.opacity = closeSTEPnext / 100;
				$(divIDg).style.filter = "alpha(opacity="+closeSTEPnext+")";
			}
			else
			{
			if ($(divIDi).className.include('_keephover'))
				{
					var len = $(divIDi).className.length;
					$(divIDi).className = $(divIDi).className.substr(0,len-10);
				}
				var childsARRAY = childs.split(',');
				while (divID = childsARRAY.pop()) {
				var divIDgc = 'MENUgDIV' + divID;
				$(divIDgc).style.opacity = "1";
				$(divIDgc).style.filter = "";
				hideLAYER(divIDgc);
				}
				$(divIDg).style.opacity = "1";
				$(divIDg).style.filter = "";
				hideLAYER(divIDg);
			}
	}	
	
	// ** menuedit drag drop

        var MenuEdit = {
     
        obj : null,
		myclone : null,
 
        init : function(o,oRoot) {
       	o.onmousedown	= MenuEdit.start;
        o.root = oRoot && oRoot != null ? oRoot : o ;
        o.root.onMenuEditStart	= new Function();
        o.root.onMenuEditEnd	= new Function();
        o.root.onMenuEdit		= new Function();
        },
        
        start : function(e)
        {
		    var o = MenuEdit.obj = this;		
			var mover = MenuEdit.obj.down('.imgbuttonmenumove');
            var root = MenuEdit.obj.up('.textmenuDIVadminROOT');
            var container = MenuEdit.obj.up('.container');

		   	mymouseover = Position.within(mover, xMousePos, yMousePos);
		   	if (!mymouseover) return;

			if (MenuEdit.obj.hasClassName('group')) { 
				var parent = container.ancestors();
			    // MenuEdit.myclone =  parent[0].clone(20);
				MenuEdit.myclone =  container.clone(10);
				MenuEdit.myclone.clonePosition(container, {setWidth: true,setHeight: true});
			} else {
				var parent = MenuEdit.obj.ancestors();
			    // MenuEdit.myclone =  parent[0].clone(20);
				MenuEdit.myclone =  MenuEdit.obj.clone(3);
				MenuEdit.myclone.clonePosition(MenuEdit.obj, {setWidth: true,setHeight: true});
			}

			document.body.appendChild(MenuEdit.myclone);
			MenuEdit.myclone.absolutize(); 
			MenuEdit.myclone.toggleClassName('round');
			
            document.onmousemove	= MenuEdit.drag;
            document.onmouseup		= MenuEdit.end;
            return false;
        },
    
        drag : function(e)
        {
            var root = MenuEdit.obj.up('.textmenuDIVadminROOT');
            var container = MenuEdit.obj.up('.container');

			// MenuEdit.myclone.class = 'adminkek';
			MenuEdit.myclone.style.left = xMousePos - 50 + "px";
			MenuEdit.myclone.style.top = yMousePos - 20 + "px";
			   
            var type =  MenuEdit.obj.classNames;
			
            var type = MenuEdit.obj.hasClassName('group');
            if (type) {
                if (container != 'undefined') container.setStyle({ opacity: 0.2 });
            } else {
                if (MenuEdit.obj != 'undefined') MenuEdit.obj.setStyle({ opacity: 0.2 });
            }
            
            var targets = $$('#MENUadminDIV div.item','#MENUadminDIV div.group');
            targets.each(function(item) {					
                mymouseover = Position.within(item, xMousePos, yMousePos);
                if (mymouseover) {
					item.setStyle({ 
						 borderBottom: '4px solid #000000'
						});
				} else item.setStyle({ borderBottomStyle: 'none' });
            })			
            
            var o = MenuEdit.obj;
            return false;
        },
    
        end : function()
        {
            document.onmousemove = null;
            document.onmouseup   = null;
            var root = MenuEdit.obj.up('.textmenuDIVadminROOT');
            var container = MenuEdit.obj.up('.container');
    
            if (MenuEdit.obj) MenuEdit.obj.setStyle({ opacity: 1 });
            if (root) root.setStyle({ opacity: 1 });
            if (container) container.setStyle({ opacity: 1 });
                    
            var targets = $$('#MENUadminDIV div.item','#MENUadminDIV div.group');
            targets.each(function(item) {					
                mymouseover = Position.within(item, xMousePos, yMousePos);
                item.setStyle({ backgroundColor: '' });
                if (mymouseover && item.id !== '') {
                    // alert (item.id);
                    MenuEdit.move(item);
                    return;
                }
    
            })	
    
            MenuEdit.obj = null;
			document.body.removeChild(MenuEdit.myclone);
			MenuEdit.myclone = null;
       
	    },	
    
        move : function(item)
        {
                screenFADE_on();
                var root = MenuEdit.obj.up('.textmenuDIVadminROOT');
                var container = MenuEdit.obj.up('.container');
				    
				var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'menu_move',
											what: MenuEdit.obj.id,
											where: item.id
											}, 	
										onComplete: MenuEdit.movedone} );
		
				 // setTimeout('MenuEdit.movedone()',50);
		},
		
		movedone : function(originalRequest) {
			screenFADE_off();				
			var xml = originalRequest.responseXML;		
			res = XML2array(xml);
			$('MENUadminDIV').update(res['loadedcontent']);
		}	
				
    }
	
	
    
	//############################################################################################
	//############################################################################################
	//############################################################################################	

	function systemSCREENfade_init()
		{
 		 html_code = '<div name="screen_fade" id="screen_fade"></div>';
		 document.write(html_code);
		}

		function screenFADE_on()
		{
			showLAYER("screen_fade");
			$("screen_fade").style.opacity = "0.8";
			$("screen_fade").style.filter = "alpha(opacity=80)";
		}

		function screenFADE_off()
		{
			hideLAYER("screen_fade");
			$("screen_fade").style.opacity = "";
			$("screen_fade").style.filter = "";
		}

	//############################################################################################
	
		function update_security () {
			new Ajax.Updater('securitycodeDIV', '/system/update_security_code.php')
		}


	//############################################################################################
	//	Change object class
		function change_class(obj,style)	// obj = object /this/   style = new style name 
		{
			obj.className=style;
		}

	//############################################################################################
	//	AteDin sub page
		function writeSUBpage(src) 
		{
			screenFADE_on();
			sText = '<div id="sub_page" onmouseup="DIV_closebutton(this)"><div id="sub_page_handler"></div><div id="subpageCONTENTframe">'+src+'</div></div>';
			$('sub_page').update(sText);
			setTimeout('XposLAYERtoMIDDLE("sub_page")',100);
			setTimeout('XposLAYERtoMIDDLE("sub_page")',200);
			setTimeout('showLAYER("sub_page")',250);
			setTimeout('XposLAYERtoMIDDLE("sub_page")',500);
			YposLAYERtoTOP("sub_page",100);
			}
		
		
		function updateSUBpage(src) 
		{
			screenFADE_on();
			var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
											{method: 'get', 
												parameters: {
												ajax_cmd: 'loadSUBpage',
												myfile: src
												}, 
											onComplete: updateSUBpage_done} );	
		}

		function updateSUBpage_done(originalRequest) {			
				var xml = originalRequest.responseXML;		
				res = XML2array(xml);
				$('subpageCONTENTframe').update(res['loadedcontent']);
				setTimeout('XposLAYERtoMIDDLE("sub_page")',100);
				setTimeout('XposLAYERtoMIDDLE("sub_page")',200);
				setTimeout('showLAYER("sub_page")',250);
				setTimeout('XposLAYERtoMIDDLE("sub_page")',500);
				YposLAYERtoTOP("sub_page",100);		
				AteDindoDOMmod();
		}	

		
		function SubPage_initDD()
		{
			// html_code = '<div id="sub_page" onmouseup="DIV_closebutton(this)"></div>';
			html_code = '<div id="sub_page" onmouseup="DIV_closebutton(this)"><div id="sub_page_handler"><div class="close"></div></div><div id="subpageCONTENTframe">content</div></div>';
			document.write(html_code);
			// Drag.init($('sub_page'));
			Drag.init($('sub_page_handler'),$('sub_page'));
			setLOADING ('subpageCONTENTframe');			
		}

		function closeSUBpage() 
		{
			hideLAYER("sub_page");
			screenFADE_off();
		}


	//############################################################################################

	function chboxSHdivFT(chkID, divID,FT)
	{
		if (chkID.checked == FT) {
		divID.className='div_hide';
		} else {
		divID.className='div_show'; 
		}
	}
	
	//############################################################################################
	// return the value of the radio button that is checked
	// return an empty string if none are checked, or
	// there are no radio buttons
	function getCheckedValue(radioObj) {
		if(!radioObj)
			return "";
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				return radioObj.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
	}
	
	//############################################################################################
	// set the radio button with the given value as being checked
	// do nothing if there are no radio buttons
	// if the given value does not exist, all the radio buttons
	// are reset to unchecked
	function setCheckedValue(radioObj, newValue) {
		if(!radioObj) return;
		var radioLength = radioObj.length;
		
		alert(radioLength);
		
		if(radioLength == undefined) {
			radioObj.checked = (radioObj.value == newValue.toString());
			return;
		}
		
		for(var i = 0; i < radioLength; i++) {
			radioObj[i].checked = false;
			if(radioObj[i].value == newValue.toString()) {
				radioObj[i].checked = true;
			}
		}
	}

	//############################################################################################

	function checkBOXinvert(id) {
		if ($(id).checked == false) $(id).checked = true;
		else  $(id).checked = false;
	}
	
		
	//############################################################################################
	// ** DIV Manipulations
	function layerCONTROL_init(id,title,state) {
		
		controlDIVid = id+'_control';
				
		if (state == 'open') {
			html_code = '<div id="'+controlDIVid+'" style="background-image: url(/system/images/divCONTROLclose.jpg); display: block;" class="systemLAYERcontrol" onclick="showhideLAYERcontrol(\''+id+'\')" >'+title+'</div>';
		// $(id).style.display = 'block';
		} else {
			html_code = '<div id="'+controlDIVid+'" style="background-image: url(/system/images/divCONTROLopen.jpg); display: block;" class="systemLAYERcontrol" onclick="showhideLAYERcontrol(\''+id+'\')">'+title+'</div>';
		        //$(id).style.display = 'none';
		}
		document.write(html_code);
	}

	function showhideLAYERcontrol(DIVid)																// show hide layer
	{
		if ($(DIVid) == null) {
			// systemFLOATmessage_show('showhideLAYERcontrol error, ' + DIVid + 'object is null'); // ERROR MESSAGE
			return;
		}
			
			controlDIVid = DIVid+'_control';
							
			if ($(DIVid).style.display == "block" || $(DIVid).style.display == "" || $(DIVid).style.display == null) {
				$(controlDIVid).style.backgroundImage="url(/system/images/divCONTROLopen.jpg)";		
				$(DIVid).style.display="none";
			} else {
				$(controlDIVid).style.backgroundImage="url(/system/images/divCONTROLclose.jpg)";
				$(DIVid).style.display="block";
			}
	}
	
	function showLAYERcontrol(DIVid)																// show hide layer
	{
			controlDIVid = DIVid+'_control';
			$(DIVid).style.display="block";
			$(controlDIVid).style.backgroundImage="url(/system/images/divCONTROLclose.jpg)";
	}	

	function showhideLAYER(DIVid)																// show hide layer
	{
			if ($(DIVid).style.display == "none" || $(DIVid).style.display == "") {
				$(DIVid).style.display="block";
			} else {
				$(DIVid).style.display="none";
			}
	}

	function showLAYER(DIVid)																// show layer
	{
			$(DIVid).style.display="block";
	}

	function hideLAYER(DIVid)																// hide layer
	{
			$(DIVid).style.display="none";
	}
	
	function DIV_closebutton(div) {
		var obj = $(div);
		Position.cumulativeOffset(obj);
		oDIMs = obj.getDimensions();
		ppos = Position.page(obj);
		scrollbarpos = document.viewport.getScrollOffsets();
		CLOSEspotSIZE = 30;
		CLOSEspotX = scrollbarpos[0] + oDIMs.width + ppos[0] - CLOSEspotSIZE;
		CLOSEspotY = scrollbarpos[1] + ppos[1] + CLOSEspotSIZE;
		if (xMousePos > CLOSEspotX && yMousePos < CLOSEspotY) {
			setLOADING ('subpageCONTENTframe');
			hideLAYER(div);
			hideLAYER("screen_fade");
		}
			
	}

	function layerFADE_on(id)
	{
		$(id).style.opacity = "0.4";
		$(id).style.filter = "alpha(opacity=40)";
	}

	function layerFADE_off(id)
	{
		$(id).style.opacity = "";
		$(id).style.filter = "";
	}

	
	// ** TAB cloud 
	function tabswitch(tabs,active) {
		tabsARRAY = tabs.split(',');
		swon = tabsARRAY[active];
		while (divID = tabsARRAY.pop())
		{
			hideLAYER(divID);
			$('button'+divID).className="passivebutton";
		}
		showLAYER(swon);
		$('button'+swon).className="";
}
	
	// **

	function div_alfa_fade(divID,from,to,steps)
		{
			var divOBJ = $(divID);
			var ANIMspeed = steps;

			if (divOBJ.animVAR < 0 || divOBJ.animVAR == undefined || divOBJ.animVAR == NaN)
			{
				divOBJ.animVAR = ANIMspeed;
			}

			var closeSTEPnext = Math.ceil((99 / ANIMspeed) * divOBJ.animVAR);
			
			if (divOBJ.animVAR > 1)
			{
				divOBJ.animVAR = divOBJ.animVAR - 1;
				divOBJ.menuANIMtimer = setTimeout('div_alfa_fade(\''+divID+'\',\''+from+'\',\''+to+'\',\''+steps+'\')', 40);

				divOBJ.style.opacity = closeSTEPnext / 100;
				divOBJ.style.filter = "alpha(opacity="+closeSTEPnext+")";
			}
			else {
				divOBJ.style.opacity = 0;
				divOBJ.style.filter = "alpha(opacity=0)";
			}
	}
	
	function set_object_visibility(id,value) {
		if (value) $(id).style.visibility = "visible";
		else $(id).style.visibility = "hidden";
	}	

	// #################################################################################################
	function YposLAYERtoTOP(DIVid,Yoffset)																// hide layer
	{
			obj = $(DIVid);
			scrollbarpos = document.viewport.getScrollOffsets();
			maxY = winY = document.viewport.getHeight() + scrollbarpos[1];
			newY = scrollbarpos[1] + Yoffset;
			mouseY = yMousePos + Yoffset;
			// alert (Yoffset + " hmm " + newY + " / " + mouseY);
			if (newY > mouseY) newY = mouseY;
			obj.style.top = newY + "px";
			// alert (newY + " / " + mouseY);
	}

	function YposLAYERtoMOUSE(DIVid,Yoffset)																// hide layer
	{
			obj = $(DIVid);
			scrollbarpos = document.viewport.getScrollOffsets();
			newY = yMousePos + Yoffset;
			obj.style.top = newY + "px";
	}

	function XposLAYERtoMIDDLE (divID) {

			scrollbarpos = document.viewport.getScrollOffsets();
			winX = document.viewport.getWidth();
			divIDdimension = $(divID).getDimensions();
			x = divIDdimension.width;
			newX = winX/2 - x/2 + "px";
			$(divID).style.left = newX;	
	}


	//############################################################################################
	// SIDE slider

	function moveSLIDESIDE()																	// SLIDESIDE
    {	
		ID = 'USERFLOAT';
		goalXscreen = 0;
		goalYscreen = 0;
		speedfactor = 6;
		dir = 'xy';
		slide_calc(ID,goalXscreen,goalYscreen,speedfactor,dir);	
		setTimeout('moveSLIDESIDE()', 25);
	}

	// ** 
	// slide calc
	
	function slide_calc(ID,goalXscreen,goalYscreen,speedfactor,dir)
    {	
			scrollbarpos = document.viewport.getScrollOffsets();

			offsetX = 0;
			offsetY = 0;

			goalX = scrollbarpos[0] + goalXscreen;
			goalY = scrollbarpos[1] + goalYscreen;
			obj = $(ID);
			
			oldX = Math.round(obj.style.left.replace("px",""));
			oldY = Math.round(obj.style.top.replace("px",""));

			if (oldX > goalX) { dirX = -1; } else { dirX = 1; }
			if (oldY > goalY) { dirY = -1; } else { dirY = 1; }
			
			chkX = Math.abs(oldX - goalX);
			if (chkX >= 1) {
				offsetX = Math.round(chkX / speedfactor * dirX);
				if (Math.abs(offsetX) < 1) {
				offsetX = dirX;
				}
			} else {
				offsetX = 0;
			}

			chkY = Math.abs(oldY - goalY);
			if (chkY >= 1) {
				offsetY = Math.round(chkY / speedfactor * dirY);
				if (Math.abs(offsetY) < 1) {
				offsetY = dirY;
				}
				
			} else {
				offsetY = 0;
			}
			
			newX = oldX + offsetX + "px";
			newY = oldY + offsetY + "px";
			
			if (dir == "x" || dir == "xy") obj.style.left = newX;
			if (dir == "y" || dir == "xy") obj.style.top = newY;		

			if (offsetY == 0) return false;
			else return true;
}


	// ******************************************************
	// ** system float message box

	function systemFLOATmessage_initDD() // drag and drop
		{
		html_code = '<div id="systemFLOATmessage" onmouseup="DIV_closebutton(this)"></div>';
		document.write(html_code);
		Drag.init($('systemFLOATmessage'));		 
		}

	function systemFLOATmessage_init()
		{
		 // html_code = '<div id="systemFLOATmessage" onmouseup="systemFLOATmessage_click()" onmouseup="systemFLOATmessage_hide()" onkeypress="systemFLOATmessage_hide()" ></div>';
 		 html_code = '<div id="systemFLOATmessage" onmouseup="DIV_closebutton(this)"></div>';
		 document.write(html_code);
		}


	function systemFLOATmessage_show(msg)																// show systemfloater
    {
			$('screen_fade').onmouseup =  systemFLOATmessage_hide;
			
			screenFADE_on();
			systemFLOATcenterpos();
			$('systemFLOATmessage').update(msg);
			obj.style.display="block";
			systemFLOATmessage_float();

	// setTimeout( 'systemFLOATcenterpos()', 1 * 1000);
	// setTimeout( 'systemFLOATcenterpos()', 2 * 1000);
	clearTimeout($('systemFLOATmessage').closetimer);
	$('systemFLOATmessage').closetimer = setTimeout( 'systemFLOATmessage_hide()', 10 * 1000);
	}
	
	function systemFLOATmessage_float()																	// SLIDESIDE
    {	
		ID = 'systemFLOATmessage';
		goalXscreen = 0;
		goalYscreen = 350;
		speedfactor = 5;
		dir = 'y';
		done = slide_calc(ID,goalXscreen,goalYscreen,speedfactor,dir);	
		if (done) setTimeout('systemFLOATmessage_float()', 25);
	}	

	function systemFLOATmessage_hide()																		// hide systemfloater
    {
			obj = $('systemFLOATmessage');	
			clearTimeout($('systemFLOATmessage').closetimer);
			obj.style.display="none";
			screenFADE_off();
			$('screen_fade').onmouseup = null;
    }
	
	function systemFLOATcenterpos()																		// hide systemfloater
    {
			scrollbarpos = document.viewport.getScrollOffsets();
			winX = document.viewport.getWidth();
			winY = document.viewport.getHeight();
			x = 360;
			y = 80;
			newX = winX/2 - x/2 - 20 + "px";
			newY = winY/2 - y/2 + scrollbarpos[1] - 80 + "px";
			obj = $('systemFLOATmessage');
			obj.style.left = newX;	
			obj.style.top = newY;
    }	
	
	/*
	function systemFLOATmessage_click() {
			obj = $('systemFLOATmessage');
			ppos = Position.page(obj);
			xOFF = ppos[0] - xMousePos;
			yOFF = ppos[1] - yMousePos;
			systemFLOATmessage_drag(xOFF,yOFF);
	}
	*/
	
	/*
	function systemFLOATmessage_drag(Xoff,Yoff) {
			sXoff = Xoff;
			sYoff = Yoff;
			obj = $('systemFLOATmessage');
			scrollbarpos = document.viewport.getScrollOffsets();
			x = xMousePos + Xoff + "px";
			y = yMousePos + Yoff + "px";
			obj.style.left = x;
			obj.style.top = y;
		 setTimeout("systemFLOATmessage_drag(sXoff,sYoff)", 2);
	}	
	*/
			
	//############################################################################################
	// *** SET LOADing image
	
	function setLOADING (ID) {
		// sText = '<center><img src="/system/images/atd-loadinganim.gif" alt="loading" width="32" height="32"/></center>';
		sText = '<center><img src="/system/images/ajax_load_02.gif" alt="loading" /></center>';
		$(ID).update(sText);
	}

	//############################################################################################
	// change status message
	function StatusMsg(msgStr) {
		status=msgStr;
		document.returnValue = true;
	}

	//############################################################################################
	// simple js alert popup message

	function popupMsg(msg) {
		alert(msg);
		}
		

	//############################################################################################
	// put this there
	
	function putTHISthere(thisx,therex) {
		$(therex).value = thisx.value;
	}

	function addTHISthere(thisx,therex) {
		$(therex).value += thisx.value;
	}
	function addTHISthereWITHseparator(thisx,therex,separator) {
		if ($(therex).value == "") {
		$(therex).value = thisx.value;
		} else {
		$(therex).value += separator + thisx.value;
		}
	}
	
	function addTHISthereWITHseparatorUNIQUE(thisx,therex,separator) {
		var splitted = $(therex).value.split(",");
		var check = splitted.indexOf(thisx.value);
		if (check < 0) {
			if ($(therex).value == "") {
			$(therex).value = thisx.value;
			} else {
			$(therex).value += separator + thisx.value;
			}
		}
	}	
	
	function clearVAL(obj) {
		obj.value = "";
	}
	
	function changeVALUE(myVAL,therex) {
		$(therex).value = myVAL;
	}	
	
	function changeVALUEcalc(myVAL,therex) {
		var newVAL = Number(myVAL) + Number($F(therex));
		if (newVAL < 0) newVAL = 0;
		$(therex).value = newVAL;
	}
	
	function VALUEcalc(myVAL,change) {
		var newVAL = Number(myVAL) + Number(change);
		if (newVAL < 0) newVAL = 0;
		return newVAL;
	}			
	
	//############################################################################################
	// restrict input in IE
	
		var phone = "()- 0123456789";
		var numb = "0123456789.";
		var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ őúűáéöüóíŐŰÚ";
		var mailad = "abcdefghijklmnopqrstuvwxyz@.0123456789-_";	
		var username = "abcdefghijklmnopqrstuvwxyz0123456789";
		var pass = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		var arr = " abcdefghijklmnopqrstuvwxyz0123456789,";
		var IDarr = "0123456789,";		
		var filename = "abcdefghijklmnopqrstuvwxyz0123456789-";
		var url = "abcdefghijklmnopqrstuvwxyz0123456789-/";		

		function restrict_input(t,v) {

		var w = "";
			for (i=0; i < t.value.length; i++) {
			x = t.value.charAt(i);
			if (v.indexOf(x,0) != -1)
			w += x;
			}
		t.value = w;
		}
	
	function pwstrchk(pw) {
		
		var numb = "0123456789";
		var lowcase = "abcdefghijklmnopqrstuvwxyz";
		var upwcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		var w = new Number(0);
		for (i=0; i < numb.length; i++) {
			x = numb.charAt(i);
			if (pw.indexOf(x,0) != -1) {
				w = w + 1;
				break;
				}
			
		}

		for (i=0; i < lowcase.length; i++) {
			x = lowcase.charAt(i);
			if (pw.indexOf(x,0) != -1) {
				w = w + 1;
				break;
				}
		}
		for (i=0; i < upwcase.length; i++) {
			x = upwcase.charAt(i);
			if (pw.indexOf(x,0) != -1) {
				w = w + 1;
				break;
				}
		}	
		passwordSTR = new Array('-','<span class="adminpiros">poor</div>','<span class="adminsarga">avarage</div>','<span class="adminzold">strong</div>');
		$("pwstrchk").update(passwordSTR[w]);
	}
	
	function newuserchk(newuser) {
		new Ajax.Updater('newuserchk', '/system/include/userCHK.php?user='+newuser , { method: 'get' });
	}
	
	//############################################################################################
	// jump to a place
	function relocate(url) {
	document.location = (url);
	}

	//############################################################################################

	function logoff() {
	document.location = ('/system/logoff.php');
	}

	//############################################################################################

	function submitTHIS(formID) {
		// alert (formID);
		if ($(formID) == null) {
			// systemFLOATmessage_show('submitTHIS error, ' + DIVid + 'object is null'); // ERROR MESSAGE
			return;
		}
		// show_object_props($(formID));	
		screenFADE_on();
		$(formID).submit();
	}
	


	//############################################################################################
	// open browser window
	function openWindow(url,name,features) {
	  window.open(url,name,features);
	}	

	//############################################################################################
	//	Confirm and go to location

function confirmGO(msg,url) // msg = message , url = place to go
	  {
	  var r=confirm(msg)
	  if (r==true)
		{
		document.location = (url);
		return;
		}
	  else
		{
		return;
		}
	  }
	  
	function confirmGOpassSTATE(state,msg,url) // msg = message , url = place to go
	  {
		var newurl = url+"&state="+state
		var r=confirm(msg+" "+state)
	  if (r==true)
		{
		document.location = (newurl);
		return;
		}
	  else
		{
		return;
		}
	  }	  	  


	//############################################################################################
	//	Mouse position

	var xMousePos = window.xMousePos;
	var yMousePos = window.yMousePos;
	
	Event.observe(document, 'mousemove', getmouse);
	
	function getmouse(event) {
		scrollbarpos = document.viewport.getScrollOffsets();
		// window.xMousePos = Event.pointerX(event)+scrollbarpos[0];
		// window.yMousePos = Event.pointerY(event)+scrollbarpos[1];
		window.xMousePos = Event.pointerX(event);
		window.yMousePos = Event.pointerY(event);
	}

//############################################################################################
	// DEGUB

	function show_object_props(obj) {
		var str='';
			for(prop in obj)
			{
			str+=prop + " value :"+ obj[prop]+"\n";//Concate prop and its value from object
			}
		alert(str); //Show all properties and its value
	}
	

//############################################################################################


	function cloneVALUES(target,args) {
		
		savetarget = target;
		saveargs = args;

		output = '';
		
		initarray = args.split(',');
		
		// alert (savetarget + ' => ' + saveargs);

		for( var i =0; i < initarray.length; i++) {
				if ($(initarray[i]) !== null) {
					output += $(initarray[i]).value + ' ';
					// alert (initarray[i] + ' - ' + i + ' * ' + $F(initarray[i]));
				}
		}
	
	$(target).value = output;
	
	// alert ('done - ' + savetarget + ' - ' + saveargs);
	
	$(savetarget).timeout = setTimeout('cloneVALUES(savetarget,saveargs)',100);
	}


	// ** SQL ********************************


	function sql_record_insert(SQLtable,cell,value) {

	var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'sql_record_insert',
											SQLtable: SQLtable,
											cell: cell,
											value: value
											}, 
										onComplete: sql_record_insert_done} );

	}
	
	function sql_record_insert_done(originalRequest) {
		var xml = originalRequest.responseXML;
		res = XML2array(xml);
		lastid = res['lastid'];
	}

	// **

	function sql_record_create(SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch) {

		ID = 'SQL_rec_' + SQLtable + '_' + SQLkey;
		setLOADING (ID);

	var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'sql_record_create',
											sql_add_a_recod: SQLtable,
											SQLkey: SQLkey,
											SQLdisplay: SQLdisplay,
											filterlink: filterlink,
											filtersearch: filtersearch											
											}, 
										onComplete: sql_record_created(SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch)} );

	}

	function sql_record_created(SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch) {
		ID = 'SQL_rec_' + SQLtable + '_' + SQLkey;
		makelist = 'ajax';
		if ($(ID) !== null) setTimeout("SQL_filter_list('"+ID+"','"+makelist+"','"+SQLtable+"','"+SQLdisplay+"','"+SQLkey+"','"+filterlink+"','"+filtersearch+"')",350);
	}
	
	// **

	function sql_record_edit(SQLtable,SQLdisplay,SQLkey,SQLkeyvalue) {
		
		if (SQLtable == '' || SQLkey == '') {
			alert ('JS ERROR: sql_record_edit() -> emtry call');
			return false;	
		}
		
		// alert (SQLtable+' , '+SQLdisplay+' , '+SQLkey+' , '+SQLkeyvalue);

		ID = 'SQL_rec_' + SQLtable + '_' + SQLkey;
		updateSUBpage('/system/SQL/SQL_record_show.php?SQLtable='+SQLtable+'&SQLdisplay='+SQLdisplay+'&SQLkey='+SQLkey+'&SQLkeyvalue='+SQLkeyvalue);
	}
	
	// **

	
	function sql_record_delete(SQLtable,SQLdisplay,SQLkey,SQLkeyvalue,filterlink,filtersearch) {

		if (!confirm('Are you sure? / Biztos?')) return;

		ID = 'SQL_rec_' + SQLtable + '_' + SQLkey;

		// alert (SQLtable+','+SQLdisplay+','+SQLkey);

		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'sql_record_delete',
											SQLtable: SQLtable,
											SQLkey: SQLkey,
											SQLdisplay: SQLdisplay,
											SQLkeyvalue: SQLkeyvalue,
											filterlink: filterlink,
											filtersearch: filtersearch
											}, 
										onComplete: sql_record_deleted(SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch)} );

	}
	
	function sql_record_deleted(SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch) {
		ID = 'SQL_rec_' + SQLtable + '_' + SQLkey;
		setLOADING (ID);
		if ($(ID) !== null) setTimeout("SQL_filter_list('"+ID+"','ajax','"+SQLtable+"','"+SQLdisplay+"','"+SQLkey+"','"+filterlink+"','"+filtersearch+"')",350);
	}

	function sql_delete_button(formID) {
		var boxes = $$('input:all([name~=rce_])');	
		var result = false;
		for(var obj in boxes)
			{
				if (boxes[obj].checked == true) result = true;
			}
		
		if (result) {
			if (confirm(text_are_you_sure)) $(formID).submit();
		}
		else systemFLOATmessage_show(text_nothing_to_delete);
	}


	// **
	
	function SQL_record_SelectAll(ident) {

		myselection = $$('input:all([name~=rcb_ident])');	
		for(var obj in myselection)
			{
				myselection[obj].checked = true;
			}
		
		$('rce_'+ident+'_selectall').checked = false;
		$('rce_'+ident+'_selectnone').checked = false;
	}

	function SQL_record_SelectNone(ident) {

		myselection = $$('input:all([name~=rcb_ident])');	
		for(var obj in myselection)
			{
				myselection[obj].checked = false;
			}
		$('rce_'+ident+'_selectall').checked = false;
		$('rce_'+ident+'_selectnone').checked = false;
	}


	
	function sql_add_rec_jointable(SQLtable,name,id,arg1,arg2,arg3) {
		
		// őúűáéáűé
        alert('fejelsztés alatt' + SQLtable + ',' + name + ',' + id + ',' + arg1 + ',' + arg2 + ',' + arg3);
		
		/*
		var addrec = new Ajax.Request( '/system/mailer/mailer_recipliens_list.php', 
						  {method: 'post', 
						  parameters: 'r='+$F('recipliens[]'), 
						  onSuccess: mailerWRITErecipliensENABLE()} );
		*/
		
	}
		
	// *****************************************************************************************************************************************
	// LAYER UPDATE + SQL FILTER
	// *****************************************************************************************************************************************


	function updateLAYER(id,src) 
	{
		layerFADE_on(id);
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'loadSUBpage',
											myfile: src,
											id: id
											}, 
										onComplete: updateLAYER_done} );	
	}

	function updateLAYER_done(originalRequest) {			
			var xml = originalRequest.responseXML;		
			var res = XML2array(xml);
			var id = res['id'];
			var newcontent = res['loadedcontent'];
			$(id).update(newcontent);
			layerFADE_off(id);
			AteDindoDOMmod();
				
	}	

	function SQL_filter_list(ID,makelist,SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch) {
		// if (filtersearch == "") return;
		// setLOADING (ID);
		updateLAYER(ID,'/system/SQL/SQL_record_list.php?page=1&makelist=simple&SQLtable='+SQLtable+'&SQLdisplay='+SQLdisplay+'&SQLkey='+SQLkey+'&filterlink='+filterlink+'&filtersearch='+filtersearch);
		
		
		/*
		var sqlrec = new Ajax.Updater( ID,'/system/SQL/SQL_record_list.php?page=1', 
								  {method: 'get', 
								 	parameters: {
									makelist: makelist,
								  	SQLtable: SQLtable,
									SQLdisplay: SQLdisplay,
									SQLkey: SQLkey,
									filterlink:filterlink,
									filtersearch: filtersearch
								  }, 
								  onComplete: null} );
		*/
	}
	
	// *****************************************************************************************************************************************
	// TEMPLATE
	// *****************************************************************************************************************************************

	function SQL_template_create(tpriv,button,SQLtable,SQLkey,SQLkeyvalue,title) {
				
		if (!confirm('[ ' + tpriv + SQLtable+','+SQLkey+','+SQLkeyvalue+','+title + ' ] - Are you sure? / Biztos?')) return;
		
		button.style.display = 'none';
		
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'sql_template_create',
											tpriv: tpriv,
											SQLtable: SQLtable,
											SQLkey: SQLkey,
											SQLkeyvalue: SQLkeyvalue,
											title: title
											}, 
										onComplete: SQL_template_created} );
	}	
	
	function SQL_template_created() {
		location.reload();
	}
	
	function SQL_template_delete(button,template) {
		
		if (!confirm('Are you sure? / Biztos?')) return;
		
		button.style.display = 'none';
		
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'sql_template_delete',
											template: template
											},
										onComplete: SQL_template_deleted} );
	}	
	
	function SQL_template_deleted() {
		location.reload();
	}
		

	
	
	

	// **
	
	function systm_signup_check() {

		Usertext = $F('usertext');
		User = $F('newuser');
		Email = $F('email');

		if (Email == '')  set_object_visibility('semail',true);
		else set_object_visibility('semail',false);
		
		if (User == '')  set_object_visibility('snewuser',true);
		else set_object_visibility('snewuser',false);

		if (User == "") alert('user name error');
		else if (Email == "") alert('email error');
		else if (Usertext == "") alert('code error');		
		else {
			var atsign = Email.substring(0,Email.lastIndexOf('@')+1);
			var domain = Email.substring(atsign.length,Email.length+1);
						
			var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
												{method: 'get', 
													parameters: {
													ajax_cmd: 'check_mx_record',
													email: Email
													}, 
												onComplete: systm_signup_analise} );
		}
	}
	
	function systm_signup_analise(originalRequest) {
		var xml = originalRequest.responseXML;
		res = XML2array(xml);
		if (res['isvalid']) $('signupform').submit();
		else {
			alert ('invalid e-mail address');
			set_object_visibility('semail',true);
		}
	}	
	
	
	// **** HTML EDITOR ajax
	function htmlditorSAVE(edit) {
		var ed = tinyMCE.get('htmleditoutput');
		ed.setProgressState(1); // Show progress
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
										{method: 'get', 
											parameters: {
											ajax_cmd: 'saveSQLpage',
											htmleditoutput: ed.getContent(),
											edit: edit
											}, 
										onComplete: htmlditorSAVE_done} );	
	}

	function htmlditorSAVE_done(originalRequest) {			
			var ed = tinyMCE.get('htmleditoutput');
			ed.setProgressState(0); // Hide progress
			var xml = originalRequest.responseXML;		
			res = XML2array(xml);
	}
	
	// cookies
	
	function Set_Cookie( name, value, expires, path, domain, secure )
		{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		
		/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
		*/
		if ( expires )
		{
		expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	}

	// this fixes an issue with the old method, ambiguous values
	// with this test document.cookie.indexOf( name + "=" );
	function Get_Cookie( check_name ) {
		// first we'll split this cookie up into name/value pairs
		// note: document.cookie only returns name=value, not the other components
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f
	
		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );
	
	
			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
			// if the extracted name matches passed check_name
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
	}

	// this deletes the cookie when called
	function Delete_Cookie( name, path, domain ) {
		if ( Get_Cookie( name ) ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}


	function change_select_option_status(inputselect,changethis,newstatus) {	
		if (!$(inputselect)) return;
		cnt = $(inputselect).length;
		while (cnt--) {
			string = $(inputselect).options[cnt].text;
			value = $(inputselect).options[cnt].value;

		// alert (changethis + ' ` ' + string + ' * ' + value + ' cnt: ' + cnt);

			// $('debug').update(changethis + ' ` ' + string + ' * ' + value + ' cnt: ' + cnt);

			if (value ==changethis) {
				$(inputselect).options[cnt].selected = newstatus;
				// alert (changethis + ' ` ' + string + ' * ' + value + ' cnt: ' + cnt);
			}
		}
	}
		
	function selectALLinSELECT(id) {
		cnt = $(id).length;
		allOPTIONS = new Array();
		while (cnt--) {
		$(id).options[cnt].selected = true;
		}
	}

	// ** IMAGES BY CELL
	
	function SQL_imagesBYcell_add(id,ident,table,count) {
		changeVALUEcalc(1,$(id));
		imagesBYcellDISPLAYupdate(id,ident,table,VALUEcalc(count,1));
	}
	function SQL_imagesBYcell_subst(id,ident,table,count) {
		changeVALUEcalc(-1,$(id));
		imagesBYcellDISPLAYupdate(id,ident,table,VALUEcalc(count,-1));
	}
	
	// function imagesBYcellDISPLAYupdate(id,args,thumbDIV,imgpath,sizeX,sizeY) {
	function imagesBYcellDISPLAYupdate(id,ident,table,count) {
		
		var div = "thumbnails"+ident;
		new Ajax.Updater(div, "/system/SQL/SQL_imagesBYcellDISPLAY.php?id="+id+"&ident="+ident+"&table="+table+"&count="+count);

	}
	
	function multiFILEidDISPLAYupdate(id,fileIDarray) {
		
		var div = "multiFILEidSHOW"+id;
		new Ajax.Updater(div, "/system/SQL/SQL_multiFILEidDISPLAY.php?id="+id+"&fileIDarray="+fileIDarray);

	}
	
	
