function start() {
	//start
	
	if(jskomShow&&$('komunikat')) {
		jskomAppear();
		$('komunikat').observe('click',jskomFadeOut);
	}
	if($('slowo')) {
		var opts = {
			//script: "autosuggest_backend.php?",
			script: function (input) { return "autosuggest_backend.php?json=1&limit=100&sektor_id="+sektor_id+"&input="+input;},
			varname: "input",
			json: true,
			cache: false,
			maxresults: 100,
			delay: 350,
			noresults: 'brak wyników!'
		};
		var as = new bsn.AutoSuggest('slowo', opts);
	}
}
window.onload = start;

function popupClose() {
	if($('bannerCenter')) $('bannerCenter').hide();
}
function popupMore() {
	window.location='aktualnosci,41,fuzja_asseco_poland_sa_i_abg_sa';
}

var peMenu;
var aktMenu;
//			var aktMenu;
//			var aktMenu;	
for (var k=1;k<=4;k++) newImage('images/pl_menu_images/menu_'+k+'.gif');
for (var k=1;k<=4;k++) newImage('images/pl_menu_images/menu_'+k+'_active.gif');
for (var k=1;k<=4;k++) newImage('images/en_menu_images/menu_'+k+'.gif');
for (var k=1;k<=4;k++) newImage('images/en_menu_images/menu_'+k+'_active.gif');
function showMenu(i,la) {
	aktMenu = i;
	for (var j=1;j<=4;j++) if (i!=j) $('menu_drop_'+j).hide();				
	$('menu_drop_'+i).show();
	$('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'_active.gif')
	//Effect.BlindDown('menu_drop_'+i, { duration: 0.5 });
	//peMenu = new PeriodicalExecuter(hideMenu,1);
}
function hideMenuOne(i,j,la) {			
	$('menu_drop_'+i).hide();	
	if (i!=j) $('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'.gif')
	//Effect.BlindUp('menu_drop_'+i, { duration: 0.5 });				
}
function highlightMenu(i,la) {
	aktMenu = i;
	for (var j=1;j<=4;j++) if (i!=j) $('menu_drop_'+j).hide();				
	
	$('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'_active.gif')
	//Effect.BlindDown('menu_drop_'+i, { duration: 0.5 });
	//peMenu = new PeriodicalExecuter(hideMenu,1);
}
function dishighlightMenu(i,j,la) {			
	$('menu_drop_'+i).hide();	
	if (i!=j) $('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'.gif')
	//Effect.BlindUp('menu_drop_'+i, { duration: 0.5 });				
}

function mapaHide() {
	$('mapa_google_container').hide();
}
function test(adres) {
	var txt=new RegExp(' ');
	while(adres.indexOf(' ')>=0) adres=adres.replace(txt,'+');
	$('mapa_google').update('');
	iframe = '<iframe width="475" height="477" src="http://maps.google.com/maps/api/staticmap?center='+adres+', '+
		'Poland&zoom=14&size=475x477&maptype=roadmap'+
		'&markers=color:red|label:.|'+adres+'&sensor=false&'+
			'key=ABQIAAAAwehqEs9Dj5TRKKOf_g5n8RSsbF_9fZuTV1QQDHHEMS3wFtFBzRStBmeBt-p4SVaHLaRwYBy4wKYjYQ"></iframe>';
	$('mapa_google').update(iframe);
	$('mapa_google_container').show();
	return false;
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

var aktGrupa=0;
var tabGrupy=Array();
function declareGrupa(num) {
	tabGrupy.push(num);
}
function toggleSubmenu(num) {
	if (aktGrupa!=num) {
		for (var i=0;i<(tabGrupy.length);i++) $('menu_sektory_grupy_'+tabGrupy[i]).hide();
		$('menu_sektory_grupy_'+num).show();
	}
	aktGrupa=num;
}

var contentIds=Array();
function showContentBig(id) {
	for(i=0;i<contentIds.length;i++) if (contentIds[i]!=id) {
		$('content_'+contentIds[i]).hide();
		$('leftnav_'+contentIds[i]).removeClassName('leftnav_element_big_a');
		$('leftnav_'+contentIds[i]).addClassName('leftnav_element_big');
	}
	$('content_'+id).show();
	$('leftnav_'+id).removeClassName('leftnav_element_big');
	$('leftnav_'+id).addClassName('leftnav_element_big_a');
	toggleBIR(1);
	aktBIR=id;
}
function showContent(id) {
	for(i=0;i<contentIds.length;i++) if (contentIds[i]!=id) {
		$('content_'+contentIds[i]).hide();
		$('leftnav_'+contentIds[i]).removeClassName('leftnav_element_a');
		$('leftnav_'+contentIds[i]).addClassName('leftnav_element');
	}
	$('content_'+id).show();
	$('leftnav_'+id).removeClassName('leftnav_element');
	$('leftnav_'+id).addClassName('leftnav_element_a');
}
function declareContent(id) {
	contentIds.push(id);
}

function setText(oTextInput) {
	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;
}
function clearText(oTextInput) {
	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';
}

function isEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return(reg.test(address));
}

var okno = null;
function window_open(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus();
  okno = null;
}
function window_open_scroll(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function selectedRadioValue(oForm, sRadioName) {
	var retval = '';
	for(var i=0;i<oForm.elements.length;i++) {
		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;
		if(oForm.elements[i].checked) retval = oForm.elements[i].value;
	}
	return retval;
}

var jskomShow=false;
var jskomZostaw=true;
var peJskom;
function jskomAppear() {
	try{
		//Effect.Appear('jskom');
		$('komunikat').show();
	}
	catch (exc) {
		$('komunikat').show();
	}
	if(!jskomZostaw) peJskom = new PeriodicalExecuter(function(peJskom) {
			jskomFadeOut();
		}, 4);
}
function jskomFadeOut() {
	try{
		Effect.Fade('komunikat');
		}
	catch (exc) {
		$('komunikat').hide();
	}
	//$('komunikat').update('');
	if(peJskom) peJskom.stop();
}

var img;
function pokazFoto(fot) {
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	$('bigFotoContainer').show();
	//$('main').hide();
}
function showimg(evt) {
	$('bigFotoImg').hide();
	$('bigFotoImg').update(img);
	$('bigFotoImg').show();
	var dim = document.viewport.getDimensions();
	if(img.width>dim.width||img.height>dim.height-160) {
		var new_size = image_small_maker(img.width, img.height, dim.width, dim.height-160)
		img.setStyle({'width':new_size[0]+'px','height':new_size[1]+'px'});
	}
}
function wywalFoto() {
	$('bigFotoContainer').hide();
	$('bigFotoImg').hide();
	//$('main').show();
}
function image_small_maker(orig_width, orig_height, max_width, max_height) {
	var xRatio = max_width / orig_width; 
	var yRatio = max_height / orig_height; 
	var new_width = 0;
	var new_height = 0;
	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 
	 new_width = orig_width; 
	 new_height = orig_height; 
	} 
	else if ((xRatio * orig_height) < max_height) { 
	 new_height = Math.ceil(xRatio * orig_height); 
	 new_width = max_width; 
	} 
	else { 
		new_width = Math.ceil(yRatio * orig_width); 
		new_height = max_height; 
		}
	var output = [];
	output.push(Math.round(new_width));
	output.push(Math.round(new_height));
	return output;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}