// ** ********************************************** **
// ** AteDin CMS common.js file
// ** www.atedin.hu
// ** atedin@atedin.hu
// ** ********************************************** **

// alert ('include done');

function gologin() {
	$('kuld').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');
		}
	}
	
	//############################################################################################
	// ** USERS ADMINISTRATION

	function users_EDITuser(ID) {
		users_FILTERsearch();
		setLOADING("user_adminDIV");
		new Ajax.Updater("user_adminDIV", "/system/user_administration_edit.php?w-user_id="+ID);
		showLAYERcontrol("user_adminDIV");
	}
	
	function users_DELETEselected() {
		if (!confirm('are you sure?')) return false;
		else  {
		$('action').value = 'deleteselected';
		$('UserAdmin').submit();
		}
	}	
	
	function users_FILTERsearch() {
		// $('search').disabled = 1;
		searchTEXT = $F("search");
		setLOADING ("user_listDIV");

		/*
		var myAjax = new Ajax.Request( '/system/user_administration_list.php', 
									  {method: 'get', 
									  parameters: 'searchTEXT='+searchTEXT, 
									  onComplete: users_FILTERsearchENABLE} );
		
		WriteLayer("user_listDIV",myAjax);
		*/
		
		new Ajax.Updater("user_listDIV", "/system/user_administration_list.php?searchTEXT="+searchTEXT);
	}	
	// **
	function users_FILTERsearchENABLE() {
		$('search').disabled = 0;
		$('search').focus();
	}

	//############################################################################################
	// articles
	
	function article_create_AJAX() {
		var myAjax = new Ajax.Request( '/system/AJAX_server.php', 
									  {method: 'get', 
									  parameters: 'ajax_cmd=CreateNewArticle', 
									  onComplete: articleNEWrefresh} );
	}

	function articleNEWrefresh(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: articleDELrefresh} );
	}	
	
	function articleDELrefresh(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);	
	}

	//############################################################################################
	//############################################################################################
	//############################################################################################
	//############################################################################################
	//## 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 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;
		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 showhideLAYERcontrol(DIVid)																// show hide layer
	{
			controlDIVid = DIVid+'_control';
		
			if ($(DIVid).style.display == "none" || $(DIVid).style.display == "") {
				$(DIVid).style.display="block";
				$(controlDIVid).style.backgroundImage="url(/system/images/divCONTROLclose.jpg)";
			} else {
				$(DIVid).style.display="none";
				$(controlDIVid).style.backgroundImage="url(/system/images/divCONTROLopen.jpg)";				
			}
	}
	
	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 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
    {	
			scrollbarpos = document.viewport.getScrollOffsets();

			goalXscreen = 5;
			goalYscreen = 7;

			offsetX = 0;
			offsetY = 0;
			speedfactor = 6; // tobb - lasabb			

			goalX = scrollbarpos[0] + goalXscreen;
			goalY = scrollbarpos[1] + goalYscreen;
			obj = $('USERFLOAT');
			
			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";
			
			obj.style.left = newX;
			obj.style.top = newY;

		setTimeout('moveSLIDESIDE()', 25);
		
	}

	// ******************************************************
	// ** 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>';
		 document.write(html_code);
		}


	function systemFLOATmessage_show(msg)																// show systemfloater
    {
			screenFADE_on();
			systemFLOATcenterpos();
			WriteLayer ('systemFLOATmessage',msg);
			obj.style.display="block";

	// setTimeout( 'systemFLOATcenterpos()', 1 * 1000);
	// setTimeout( 'systemFLOATcenterpos()', 2 * 1000);
	clearTimeout($('systemFLOATmessage').closetimer);
	$('systemFLOATmessage').closetimer = setTimeout( 'systemFLOATmessage_hide()', 10 * 1000);
	}

	function systemFLOATmessage_hide()																		// hide systemfloater
    {
			obj = $('systemFLOATmessage');	
			clearTimeout($('systemFLOATmessage').closetimer);
			obj.style.display="none";
			screenFADE_off();
    }
	
	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 (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 clearVAL(obj) {
	obj.value = "";
	}
	
	function changeVALUE(myVAL,therex) {
		$(therex).value = myVAL;
	}	
	
	//############################################################################################
	// restrict input in IE
	
	var phone = "()- 0123456789";
		var numb = "0123456789";
		var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		var mailad = "abcdefghijklmnopqrstuvwxyz@.0123456789";	
		var username = "abcdefghijklmnopqrstuvwxyz0123456789";
		var pass = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";	
		
		function res(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 submitTHIS(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
	}
	
//############################################################################################
	//	Mailer
	
	function mailerWRITErecipliens () {
		$('recipliens[]').disabled = 1;
		setLOADING("letter_recipliens_list");
		// WriteLayer('letter_recipliens_list',$F('recipliens[]'));
		

		var myAjax = new Ajax.Updater( 'letter_recipliens_list','/system/mailer/mailer_recipliens_list.php', 
								  {method: 'get', 
								  parameters: 'r='+$F('recipliens[]'), 
								  onComplete: mailerWRITErecipliensENABLE()} );
		
		/*
		var myAjax = new Ajax.Request( '/system/mailer/mailer_recipliens_list.php', 
								  {method: 'get', 
								  parameters: 'r='+$F('recipliens[]'), 
								  onSuccess: mailerWRITErecipliensENABLE()} );

		*/
		
		// show_object_props(myAjax);
		// WriteLayer("letter_recipliens_list",myAjax);
	}
	
	function mailerWRITErecipliensENABLE() {
		// refreshTHIS('letter_recipliens_list','/system/mailer/mailer_recipliens_list.php?r='+$F('recipliens[]'));
		$('recipliens[]').disabled = 0;
	}