/* -------------------------------------------------------
 :: wcms.js 1.0 :: wCMS functions set
                                                            
-------------------------[ (c)2006 webmaster@gry.o2.pl ]--- */
var active_ajax = 0;

function ShowHideNode(ID)
{
	if(document.getElementById(ID))
	{
		if(document.getElementById(ID).style.display == 'none' || document.getElementById(ID).style.display == '')
		{
			document.getElementById(ID).style.display = 'block';
			if($(ID + '_IMG'))
			{
				$(ID + '_IMG').src = '../img/navi/minus.gif';	
			}
		}	
		else
		{
			document.getElementById(ID).style.display = 'none';
			if($(ID + '_IMG'))
			{
				$(ID + '_IMG').src = '../img/navi/plus.gif';	
			}
		}
	}
}

function CreateURL(page, action, vars)
{
	var url;
	
	if(ModRewriteOn == 1)
	{
		url = rootURL + lang + ',' + page + ',' + action + ',' + vars + '.html';
	}
	else
	{
		url = rootURL + 'lang=' + lang + '&page=' + page + '&action' + action + '&vars=' + vars;
	}
	alert(url);
	return url;
}

function ShowObj(pObj)
{
	_obj = document.getElementById(pObj);
	_obj.style.display = 'block';
}

function HideObj(pObj)
{
	_obj = document.getElementById(pObj);
	_obj.style.display = 'none';
}


function DisableObj(pObj)
{
	pObj.readOnly = true;
	pObj.style.color = '#ACA899';
	pObj.style.backgroundColor = '#F3F5F6';
}

function EnableObj(pObj)
{
	pObj.readOnly = false;
	pObj.style.color = '';
	pObj.style.backgroundColor = '';
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function confirmAction(question)
{
var agree=confirm(question);
if (agree)
	return true ;
else
	return false ;
}

	LoadAjaxPage  = function(url, pars, div)
	{
		if($('WCMS_EDITOR'))
		{
			$('WCMS_EDITOR').style.display = 'none';
			$('WCMS_EDITOR_CONTENT_VALUE').value = '';
		}
		
		if($('loading'))
		{
			//$('loading').style.display = 'inline';
			$(div).innerHTML = '<div class="loading">' + $('loading').innerHTML + '</div>';
			HideFullInfo();
			active_ajax += 1;
		}
		
		if($('messages'))
		{
			$('messages').innerHTML = '';
		}
		
		
		
		var myAjax = new Ajax.Updater(
					{success: div}, 
					url, 
					{
						method: 'get', 
						parameters: pars, 
						onFailure: reportError,
						evalScripts: true,
						onException: hideLoading,
						onComplete: hideLoading
					});
				
	}
	
	UpdateEachSeconds  = function(url, div, secs)
	{	
		var myAjax = new Ajax.PeriodicalUpdater(
					{success: div}, 
					url, 
					{
						method: 'get', 
						onFailure: reportError,
						evalScripts: true,
						onException: hideLoading,
						onComplete: hideLoading,
						frequency: secs
					});
				
	}
	
	Link = function(url, div)
	{
		LoadAjaxPage(url, '', div);
	}
	
	SubmitAjaxForm  = function(url, pars, div)
	{
		if($('WCMS_EDITOR'))
		{
			$('WCMS_EDITOR').style.display = 'none';
			$('WCMS_EDITOR_CONTENT_VALUE').value = '';
		}
		
		if($('loading'))
		{
			
			//$('loading').style.display = 'inline';
		}
		if($('loading'))
		{
			$(div).innerHTML = '<div class="loading">' + $('loading').innerHTML + '</div>';
			HideFullInfo();
		}
		active_ajax += 1;
		var myAjax = new Ajax.Updater(
					{success: div}, 
					url, 
					{
						method: 'post', 
						postBody: pars, 
						onFailure: reportError,
						evalScripts: true,
						onException: hideLoading,
						onComplete: hideLoading
					});
		
	}
	
	hideLoading = function(xxx)
	{
		if($('show_test'))
		{
			$('show_test').value = xxx.responseText;
		}
	}
	
	
	reportError = function(request)
	{
		hideLoading();
		//alert('Sorry. There was an error.');
	}
	
	Confirm = function(confirm)
	{
		var x=window.confirm(confirm)
		if (x)
		return true;
		else
		return false;
	}
	
	popUp = function(URL, width, height, top, left, toolbar, scrollbars, location, statusbar, menubar, resizable) {
		day = new Date();
		id = day.getTime();
		if(!width) width = 800;
		if(!height) height = 600;
		if(!top) top = 0;
		if(!left) left = 0;
		if(!toolbar) toolbar = 0;
		if(!scrollbars) scrollbars = 1;
		if(!location) location = 0;
		if(!statusbar) statusbar = 1;
		if(!menubar) menubar = 0;
		if(!resizable) resizable = 1;
		
		if(URL.toLowerCase().match(/\.(jpg|gif|png|bmp|ico)$/))
		{
			URL = URL + '?id=' + id;
		}
		eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",location=" + location + ",statusbar=" + statusbar + ",menubar=" + menubar + ",resizable=" + resizable + ",width=" + width + ",height=" + height + ",left = " + left + ",top = " + top + "');");
	}
	
	CharToCode = function(txt)
	{
		txt = txt.replace(/\./g, '|dot|');
		txt = txt.replace(/\,/g, '|coma|');
		txt = txt.replace(/\:/g, '|colon|');
		txt = txt.replace(/\;/g, '|semicolon|');
		txt = txt.replace(/ /g, '|space|');
		txt = txt.replace(/\//g, '|bs|');
		return txt;
	}
	
	CodeToChar = function(txt)
	{
		txt = txt.replace(/\|dot\|/g, '.');
		txt = txt.replace(/\|coma\|/g, ',');
		txt = txt.replace(/\|colon\|/g, ':');
		txt = txt.replace(/\|semicolon\|/g, ';');
		txt = txt.replace(/\|space\|/g, ' ');
		
		return txt;
	}
	
	function SetCookie(cookie, date) 
	{
	 var today = new Date();
	 var the_date = date;
	 var the_cookie_date = the_date.toGMTString();
	 var the_cookie = cookie;
	 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
	 document.cookie=the_cookie
	}
	
	function roundNumber(num, dec) 
	{
		var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
		return result;
	}