// ** ********************************************** **
// ** AteDin CMS common.js file
// ** www.atedin.hu
// ** atedin@atedin.hu
// ** ********************************************** **

// alert ('include done');

// ** 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 startUPLOAD() {
	if ($F('uploadthis') == '') {
	alert ('válassz file-t!');
	return;
	}
	document.file_library_adminFORM.submit();
	$("screen_fade").style.opacity = "0.8";
	$("screen_fade").style.filter = "alpha(opacity=80)";
	setLOADING("fl_admin");
	showLAYER("screen_fade");
}
function startIMPORT() {
	document.file_import_adminFORM.submit();
	$("screen_fade").style.opacity = "0.8";
	$("screen_fade").style.filter = "alpha(opacity=80)";
	setLOADING("fl_admin");
	showLAYER("screen_fade");
}

// **

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/>";
		WriteLayer ('ATEDINclock',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) $('countdown').className="adminsarga";
		if (storetime < 30) $('countdown').className="adminpiros";

		displayTIME = mZero + minutes + ':' + sZero + seconds;
		WriteLayer ('countdown',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).menukeepTIMER);
		clearTimeout($(divIDg).menuCLOSEtimer);
		clearTimeout($(divIDg).menuANIMtimer);
		$(divIDg).style.zIndex=50;
		$(divIDg).style.overflow = 'visible';
		$(divIDg).style.opacity = "1";
		$(divIDg).style.filter = "";
		

		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 =  xMousePos; // + scrollbarpos[0];
		var yMoff =  yMousePos; // + scrollbarpos[1];
		var divIDg = 'MENUgDIV' + menuID;
		var divIDi = 'MENUiDIV' + menuID;

		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) {
							$(divIDg).waitmenuTIMER = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 45);
							return;
						}
			}
		}

		$(divIDg).style.zIndex= 10;
		
		if (scrollbarpos[0] == 0 && scrollbarpos[1] == 0) {
		var mouseoverDIVg = Position.within($(divIDg), xMousePos, yMousePos);
		var mouseoverDIVi = Position.within($(divIDi), xMousePos, yMousePos);
		} else {
		var mouseoverDIVg = Position.within($(divIDg), xMoff, yMoff);
		var mouseoverDIVi = Position.within($(divIDi), xMoff, yMoff);		
		// mouseoverDIVgMoff = Position.within($(divIDg), xMoff, yMoff);
		// mouseoverDIViMoff = Position.within($(divIDi), xMoff, yMoff);		
		}

		if (mouseoverDIVi || mouseoverDIVg) divIDg.waitmenuTIMER = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 35);
		// if (mouseoverDIViMoff || mouseoverDIVgMoff || mouseoverDIVi || mouseoverDIVg) divIDg.waitmenuTIMER = setTimeout('menukeep(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 65);
		else {
		$(divIDg).style.zIndex= 1;
		
		// $(divIDg).menuCLOSEtimer = setTimeout('menuCLOSEsimple(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 25);
		// $(divIDg).menuCLOSEtimer = setTimeout('menuCLOSEslideoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 5);
		$(divIDg).menuCLOSEtimer = setTimeout('menuCLOSEfadeoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 5);

		}
	}
	
	// -----

	function menuCLOSEsimple(menuID,level,parents,childs) {
		var divIDg = 'MENUgDIV' + menuID;
		var divIDi = 'MENUiDIV' + menuID;
		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 = 12;
			
			var divIDg = 'MENUgDIV' + menuID;
			var divIDi = 'MENUiDIV' + menuID;
			var DIMENSIONg = $(divIDg).getDimensions(); 

			$(divIDg).style.overflow = "hidden";

			if ($(divIDg).animVAR < 0 || $(divIDg).animVAR == undefined || $(divIDg).animVAR == NaN)
			{
				$(divIDg).animVAR = ANIMspeed;
			}

			// closeSTEPnext = $(divIDg).origheight / ANIMspeed * $(divIDg).animVAR;

			closeSTEPnext = Math.ceil(DIMENSIONg.height / (ANIMspeed - $(divIDg).animVAR));
			
			// closeSTEPsize = 1;
			// closeSTEPnext = $(divIDg).origheight / Math.ceil(closeSTEPsize * (ANIMspeed - $(divIDg).animVAR));

			// closeSTEPsize = 1.2;
			// closeSTEPnext = DIMENSIONg.height / closeSTEPsize;
			
			// closeSTEPnext = DIMENSIONg.height - 10;

			if ($(divIDg).animVAR > 1)
			{
				$(divIDg).animVAR = $(divIDg).animVAR - 1;
				$(divIDg).menuANIMtimer = setTimeout('menuCLOSEslideoff(\''+menuID+'\',\''+level+'\',\''+parents+'\',\''+childs+'\')', 20);
				$(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(); 

			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);
			}
	}	

	//############################################################################################
	//############################################################################################
	//############################################################################################	

	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();
			YposLAYERtoTOP("sub_page",100)
			XposLAYERtoMIDDLE("sub_page");		
			showLAYER("sub_page");
			sText = '<div id="sub_page" onmouseup="DIV_closebutton(this)"><div id="sub_page_handler"></div><div id="subpageCONTENTframe">'+src+'</div></div>';
			WriteLayer("sub_page",sText);
		}
		
		
		function updateSUBpage(src) 
		{
			screenFADE_on();
			YposLAYERtoTOP("sub_page",100);
			showLAYER("sub_page");
			XposLAYERtoMIDDLE("sub_page");
			new Ajax.Updater("subpageCONTENTframe", src);
		}
		
		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><div id="subpageCONTENTframe">content</div></div>';
			document.write(html_code);
			Drag.init($('sub_page'));
			Drag.init($('sub_page_handler'),$('sub_page'));
			setLOADING ('subpageCONTENTframe');
		}


	//############################################################################################

	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="inline";
	}

	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 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();
			WriteLayer ('systemFLOATmessage',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);
	}	
	*/
	
	//############################################################################################
	//############################################################################################
	//############################################################################################
	//############################################################################################	
	// TOOLTIP  and change content dinamicly

	function tooltip_init()
	{
	 html_code = '<div id="TOOLTIP"></div>';
	 document.write(html_code);
	}


	function moveTOOLTIP(parentOBJ,type)																	// show and move TOOLTIP
    {		
			scrollbarpos = document.viewport.getScrollOffsets();

			switch (type) {
			case('fixedright'):
			ppos = Position.page(parentOBJ);
			pdims = parentOBJ.getDimensions();
			x = ppos[0] + scrollbarpos[0] + pdims.width + "px";
			y = ppos[1] + scrollbarpos[1] + "px";
			break;
			default:
			x = xMousePos + 15 + "px";
			y = yMousePos - 10 + "px";
			break;
			}
			
			obj = $('TOOLTIP');
			obj.style.left = x;
			obj.style.top = y;
					
			// parentOBJ.style.border = "2px solid #FF0000";
	}
	
	function showTOOLTIP(msg)																	// show and move TOOLTIP
    {
		if (msg) {WriteLayer ('TOOLTIP',msg);} else return;								// modify content if 'msg' set
			$('TOOLTIP').style.display="block";
	}	

	function hideTOOLTIP()																		// hide TOOLTIP
    {
			$('TOOLTIP').style.display="none";
    }


	//############################################################################################
	// replace DIV/layer content
	
	function WriteLayer(ID,sText) {													// modify layer content
	
		if ($(ID) == null) {
			// systemFLOATmessage_show('WriteLayer error, ' + ID + 'object is null'); // error message
			return;
		}
	
	 if (document.layers) { 
	   var oLayer; 
	   oLayer = $(ID); 
	   oLayer.open(); 
	   oLayer.write(sText); 
	   oLayer.close(); 
	 } 
	 else if (parseInt(navigator.appVersion)>=5&&navigator. 
	appName=="Netscape") { 
	   document.getElementById(ID).innerHTML = sText; 
	 } 
	 else if (document.all) document.all[ID].innerHTML = sText;
	}
	
	//############################################################################################
	// *** 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>';
		WriteLayer(ID,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;
	}		
	
	//############################################################################################
	// 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,";
		
		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;
		}
	
	//############################################################################################
	// 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_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_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()} );
		*/
		
	}
	
	// ** filter SQL record list
	
	function SQL_filter_list(ID,makelist,SQLtable,SQLdisplay,SQLkey,filterlink,filtersearch) {
		// if (filtersearch == "") return;
		setLOADING (ID);
		var sqlrec = new Ajax.Updater( ID,'/system/SQL/SQL_record_list.php', 
								  {method: 'get', 
								 	parameters: {
									makelist: makelist,
								  	SQLtable: SQLtable,
									SQLdisplay: SQLdisplay,
									SQLkey: SQLkey,
									filterlink:filterlink,
									filtersearch: filtersearch
								  }, 
								  onComplete: null} );
	}
	
	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 SQL_imagesBYcell_add(cell) {
		changeVALUEcalc(1,$(cell));
		imagesBYcellDISPLAYupdate();
	}
	function SQL_imagesBYcell_subst(cell) {
		changeVALUEcalc(-1,$(cell));
		imagesBYcellDISPLAYupdate();
	}
	
	// **
	
	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);
		}
	}	