function isSet( variable ){
  return( typeof( variable ) != 'undefined' );
}

function isInt (i) {
	var n = trim(i);
	return n.length>0 && (n % 1) == 0;
}

function isFloat(s)
{	var n = trim(s);
	return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
}

function isArray(obj) {
    return obj.constructor == Array;
}


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"), "");
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}





function checkContactForm()
{
	mail_wzor=/^([0-9a-zA-Z\._-]+)@(([0-9a-zA-Z_-]+)\.){1,5}[a-zA-Z]{2,3}$/;
	sender_wzor=/^.+/;
	text_wzor=/^.+/;

	if (sender_wzor.test(document.contact_form.contact_sender.value)==false)
	{
		alert("NiewĹ‚aĹ›ciwy nadawca");
		return false;
	}
	if (mail_wzor.test(document.contact_form.contact_mail.value)==false)
	{
		alert("NiewĹ‚aĹ›ciwy adres mailowy");
		return false;
	}
	if (mail_wzor.test(document.contact_form.contact_what.value)==false)
	{
		alert("Wybierz adresata wiadomoĹ›ci");
		return false;
	}
	if (text_wzor.test(document.contact_form.contact_text.value)==false)
	{
		alert("Wpisz wiadomoĹ›Ä‡");
		return false;
	}
	alert("DziÄ™kujemy za wysĹ‚anie wiadomoĹ›ci.");
	return true;
}

function checkSearchForm()
{
	text_wzor=/^.+/;

	if (text_wzor.test(document.search_form.search_string.value)==false)
	{
		alert("Wpisz frazÄ™, ktĂłrÄ… chcesz wyszukaÄ‡");
		return false;
	}
	return true;
}

function checkSharedPricesForm(form, field_prefix, message)
{
	var fields_exist = false;
	var regexp = new RegExp((getCheckedValue(form.ceny_wybor) == 1) ? 'ceny(.*)' : 'cena_(.*)');
	for(i=0; i<form.elements.length; i++)
	{
		if (regexp.test(form.elements[i].name))
		{ 
			if (!isFloat(form.elements[i].value) &&
				!isInt(form.elements[i].value))
				{
					form.elements[i].style.backgroundColor = '#ff0000';
					alert(message);
					return false;
				}
				else 
					form.elements[i].style.backgroundColor = '#ffffff';
				fields_exist = true;
		}
	}
	return fields_exist;
}

function checkBookingForm(message)
{
	if (!isChecked(document.getElementById('regulamin'),message, document.getElementById('radio_user_exists_1').checked)) 
		return false;
	document.getElementById('booking_btn').style.display='none'; 
	document.getElementById('booking_loader').style.display='inline';	
	return true;
}


function clearFormField(obj)
{
	obj.value = '';
}

/*  okienko z ezdjeciem  */
function showGallery(aldu, f, p, lu, la, li) {
    windowprops = "left=100,top=50,scrollbars=yes";
    preview = window.open(aldu +'/photo.php?f=' + f + '&lu=' + lu + '&p=' + p + '&la=' + la + ((li)?'&li=' + li : '') , "", windowprops);
}


function ShowImage(ID, WIDTH, HEIGHT, URL) {
windowprops = "left=100,top=50,width=" + (WIDTH+20) + ",height=" + (HEIGHT+30) + ",scrollbars=yes";


preview = window.open(URL + "/photo/id,"+ID, "", windowprops);
}

function OtworzDoDruku(URL) {
	windowprops = "width=750,scrollbars=yes";
	preview = window.open(URL, "", windowprops);
}

function Drukuj(p1, p2, p3, geo_id, cat_id, loc_id, drag) {
	if (p1) {
	if(GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById('map'));		
		/*
		if (!map)
			var map=new GMap2(document.getElementById('map'));
			
		var mt=map.getMapTypes();
		*/
		map.setCenter(new GLatLng(p1,p2),p3);			

		loadMapData(geo_id, cat_id, loc_id, drag);					
		if (drag)
			fillGForm(map.getCenter(),map.getZoom());		 
	}
	}
    window.print();
}


function redirect(where)
{
	window.location = where;
}


function timeoutRedirect(where,secs)
{
	setTimeout("redirect('" + where + "')",secs);
}

function timeoutSubmit(form,where,secs)
{
	var name = form + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 
	formularz.action = where;
	setTimeout("document.forms." + name + ".submit()",secs);
}

function timeoutHistoryGo(steps,secs)
{
	setTimeout("history.go("+steps+")",secs);
}

function switchBlock(img,id)
{
  block = document.getElementById(id);
  image = document.getElementById(img);  
  if (block.style.display == 'none')
  {
    image.src = '/files/gfx/main/strzalka_w_dol.gif'; 
    block.style.display = 'block'; 
  }
  else
  {
    image.src = '/files/gfx/main/strzalka5.gif';
    block.style.display = 'none';   
  }
}

function switchBg(img, id)
{
  block = document.getElementById(id);
  image = document.getElementById(img);

  if (block.style.display == 'none')
  {
    block.style.display = 'block';
    image.style.background = 'url(/files/gfx/main/strzalka_w_dol.gif) no-repeat 9px 3px';
  }
  else
  {
    block.style.display = 'none';
    image.style.background = 'url(/files/gfx/main/strzalka5.gif) no-repeat 9px 3px';
  }
}

function switchBlockKaz(img,id)
{
  block = document.getElementById(id);
  image = document.getElementById(img);  
  if (block.style.display == 'none')
  {
    image.src = 'http://img.nocowanie.pl/gfx/kazimierzdolny_pl/strzalka_kaz_dol.gif'; 
    block.style.display = 'block'; 
  }
  else
  {
    image.src = 'http://img.nocowanie.pl/gfx/kazimierzdolny_pl/strzalka_kaz.gif';
    block.style.display = 'none';   
  }
}


function switchAllBlocks(img,id)
{
  regexp = /^services.+/;
  blocks = document.getElementsByTagName('div');
  image = document.getElementById(img);  
  for (i=0; i<blocks.length; i++)
  {	
  	if (regexp.test(blocks[i].id))
  	{
	  if (blocks[i].style.display == 'none')
	  {
	    image.src = '/files/gfx/minus.gif'; 
	    blocks[i].style.display = 'block'; 
	  }
	  else
	  {
	    image.src = '/files/gfx/plus.gif';
	    blocks[i].style.display = 'none';   
	  }
  	}
  }
}


function isChecked(obj, message, no_check)
{
	if (!obj.checked && !no_check)
	{
		alert(message);
		return false;
	}
	return true;
}

/* ********************************************************************************** */

function New(WHAT)
{

	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	for (i = 0; i < formularz.length; i++)
	{
		var pole = formularz.elements[i];
		pole.disabled = false;
		if (pole.type == "text" || pole.type == "password" || pole.type == "textarea" || pole.type == "hidden")
			pole.value = "";
	}
	formularz.command.value = 'add_' + WHAT;
	return false;
}

function Command(FORM,COMMAND,ID, ACTION)
{
	var formularz=document.getElementById? document.getElementById(FORM) : FORM; 

	if (ACTION)
		formularz.action = ACTION;	
	formularz.command.value = COMMAND;
	if (ID)
		formularz.id.value = ID;
	formularz.submit();
}

function CommandConfirm(FORM,COMMAND,ID,MESSAGE)
{
	var formularz=document.getElementById? document.getElementById(FORM) : FORM; 
	if (confirm(MESSAGE))
	{
		formularz.command.value = COMMAND;
		formularz.id.value = ID;
		formularz.submit();
	}		
}

function Edit(WHAT,ID)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	formularz.command.value = 'edit_' + WHAT;
	formularz.id.value = ID;
	formularz.submit();
}

function Delete(WHAT,ID,MESSAGE)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	if (confirm(MESSAGE))
	{
		formularz.id.value = ID;
		formularz.command.value='delete_' + WHAT;
		formularz.submit();
	}
} 

function Reload(WHAT)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 
	formularz.command.value = '';
	formularz.submit();
}

function changeStatus(WHAT,ID,ACTION)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	formularz.command.value = 'change_' + WHAT + '_status';
	formularz.id.value = ID;
	if (ACTION)
		formularz.action = ACTION;	
	formularz.submit();
}

function changeLocationStatus(WHAT,ID)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	formularz.command.value = 'change_location_status';
	formularz.id.value = ID;
	formularz.submit();
}

function changeLocationActivity(WHAT,ID)
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	formularz.command.value = 'change_location_activity';
	formularz.id.value = ID;
	formularz.submit();
}

function Move(WHAT,ID,WHERE, ACTION)	// np zdjecie gora/dol
{
	var name = WHAT + "_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 

	formularz.command.value = 'move_' + WHAT + '_' + WHERE;
	formularz.id.value = ID;
	if (ACTION)
		formularz.action = ACTION;
	formularz.submit();
} 

function Sort(field,direction,form)
{
	var formularz = (document.forms[form]) ? document.forms[form] : document.sort_form; 
	formularz.field.value = field;
	formularz.direction.value = direction;	
	formularz.submit();
}

function writeSubmitButton(VALUE)
{
	document.write("<INPUT type='submit' class='button' value='" + VALUE + "'/>");
}

function writeNewButton(WHAT,VALUE)
{
	document.write("<INPUT type='reset' name='new_btn' class='button' value='" + VALUE + "' onClick=\"return New('" + WHAT + "')\"/>");
}

function writeReloadButton(WHAT,VALUE)
{
	document.write("<INPUT type='reset' name='new_btn' class='button' value='" + VALUE + "' onClick=\"Reload('" + WHAT + "')\"/>");
}

function Disable(obj,do_it)
{
	document.getElementById(obj).disabled = do_it;
}

function Display(obj,how)
{
	document.getElementById(obj).style.display = how;
}

function Switch(id, value, bool)
{
	obj = document.getElementById(id);
	if (value && (!isSet(bool) || bool))
		obj.style.display = value;
	else if (obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';
}

function switchByCheckbox(box,id,rev,group)
{
	obj = document.getElementById(id);
	if (box.checked)
		obj.style.display = (rev) ? 'block' : 'none';
	else
		obj.style.display = (rev) ? 'none' : 'block';
		
	var id_last_part = id.substr(id.lastIndexOf('_')+1);
	if (group && isInt(id_last_part))
	{
		var id_first_part = id.substr(0,id.lastIndexOf('_')+1);
		var next_id_last_part = 0; /*(parseInt(id_last_part) == 1) ? 0 : 1;*/
		var next_id = (document.getElementById(id_first_part + next_id_last_part)) ? id_first_part + next_id_last_part : ((document.getElementById(id_first_part + next_id_last_part + 1)) ? id_first_part + next_id_last_part + 1 : false);
		while (document.getElementById(next_id))
		{
			if (next_id != id)
				document.getElementById(next_id).style.display = 'none';
			next_id_last_part++;
			next_id = id_first_part + next_id_last_part;			
		}
	}
}


function Preview(URL)
{
	windowprops = "left=100,top=50,width=1040,height=600, scrollbars=yes";
	preview = window.open("offer_preview", "", windowprops);	
	preview.location.href=URL;
}

function urlWindow(URL,WIDTH,HEIGHT,NAME)
{
	var preview = window.open("url_window", NAME, "left=100,top=50,width="+WIDTH+",height="+HEIGHT+", scrollbars=yes");	
	preview.location.href=URL;	
}

/* ************************************ jezyki ****************************************** */


function setEditorLanguage(LANG)
{
	document.forms.editor_language_form.action.value = 'set_editor_language';
	document.forms.editor_language_form.language_id.value = LANG;
	document.forms.editor_language_form.submit();
} 

/*
function setCookie(nazwa, wartosc, waznosc)
{
  Teraz=new Date();
  var exp = (waznosc) ? waznosc : (24*60*60*1000);
  Teraz.setTime(Termin = exp + Teraz.getTime());
  Termin= (Teraz.toGMTString());
  document.cookie= nazwa+"=" + escape(wartosc) + "; expires="+Termin;
}
*/

function setCookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

expires = (( expires ) ? expires : 1) * 1000 * 60 * 60 * 24;

var expires_date = new Date( today.getTime() + (expires) );

var cook = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
document.cookie = cook;

}

function getCookie(nazwa)
 {
  nazwa+="="; //uzupeĹ‚nia nazwÄ™
  startCookie=document.cookie.indexOf(nazwa); //sprawdza czy istnieje cookie o podanej nazwie
  if (startCookie==-1) {return ""} //jeĹĽeli nie istnieje
  startCookie+=nazwa.length; //poczÄ…tek treĹ›ci cookie
  if (document.cookie.indexOf(";",startCookie)==-1) //jeĹĽeli jest wiÄ™cej cookie
   {
    koniecCookie=document.cookie.length; //jeĹĽeli nie ma podstawia jako koniec cookie, koniec caĹ‚ego tekstu
   }
  else
   {
    koniecCookie=document.cookie.indexOf(";",startCookie); // podstawia pod koniec miejsce wystÄ™powania ";" (czyli poczÄ…tek nastÄ™pnego cookie)
   }
  textCookie=document.cookie.substring(startCookie,koniecCookie); //kopiuje treĹ›Ä‡ cookie
  textCookie=unescape(textCookie); //rozkodowuje treĹ›Ä‡
  return textCookie; //zwraca wartoĹ›Ä‡
}

function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



// 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 "";
}

// ============= rejestracja =============

function registrationStepBack()
{
	var name = "registration_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 
	formularz.command.value = '';
	formularz.registration_step.value = formularz.registration_step.value - 2;
	formularz.submit();
}

function registrationStepForward()
{
	var name = "registration_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 
	formularz.command.value = '';
	formularz.submit();
}

function writeStepBackButton(VALUE)
{
	document.write("<INPUT type='submit' class='button' onclick='registrationStepBack();' value='" + VALUE + "'\"/>");
}

function writeStepForwardButton(VALUE)
{
	document.write("<INPUT type='submit'class='button' onclick='registrationStepForward();' value='" + VALUE + "'\"/>");
}

function chmurka(e,v){
  if(v.title){
    var t=document.createElement("div");
    t.className="chmurka";
    t.innerHTML=v.title;v.title="";
    v.move=function(e){
      e=e||event;
      t.style.left=e.clientX+20+"px";
      t.style.top=e.clientY+20+"px";
    }
    v.move(e);
    document.body.appendChild(t);
    v.onmousemove=function(e){v.move(e)}
    v.onmouseout=function(e){
      v.title=t.innerHTML;
      document.body.removeChild(t);
    }
  }
}

function popup_rezerwacja(IDLIMBA,IDSTRANKY,IDJAZYKA) {
	windowprops = "left=200, top=200,width=1000 ,height=560, menubar=no, toolbar=no, status=no, resizable=no ";
	preview = window.open("/rezerwacja/?idobjektu="+IDLIMBA+"&idjaz="+IDJAZYKA+"&idstranky="+IDSTRANKY,'', windowprops);
}

function popup_cennik(IDLIMBA,IDSTRANKY,IDJAZYKA) {
	windowprops = "left=200, top=200,width=700 ,height=250, menubar=no, toolbar=no, status=no, resizable=no, scrollbars=auto ";
	preview = window.open("/cennik/?idobjektu="+IDLIMBA+"&idjaz="+IDJAZYKA+"&idstranky="+IDSTRANKY,'', windowprops);
}


function Pretend(ID,URL, FORM)
{

	var name = (FORM) ? FORM : "user_form";
	var formularz=document.getElementById? document.getElementById(name) : name; 
	if (URL)
		formularz.action = URL;    
	formularz.id.value = ID;
	formularz.command.value = 'pretend_to_be_user';
	formularz.submit();
	

}

function KeszowanieMetatagow(MESSAGE)
{
	if (confirm(MESSAGE))
	{
		document.getElementById('meta_form2').submit();
	}
}

function simpleSwitchBlock(id)
{
  block = document.getElementById(id);
  if (block.style.display == 'none')
  {
    block.style.display = 'block'; 
  }
  else
  {
    block.style.display = 'none';   
  }
}


function closeBox(id) {
  block = document.getElementById(id+'_box');
  if (block) block.style.display = 'none';   
  czekbox = document.getElementById(id+'_check');
  if (czekbox) czekbox.checked=false;
}

function openBox(id) {
  block = document.getElementById(id+'_box');
  if (block) block.style.display = 'block';   
}

function CommentsBoxes(box1,box2,box3) {
    block = document.getElementById(box3+'_box');
    if (block.style.display == 'none')
    {
        closeBox(box1);   
        closeBox(box2); 
        openBox(box3);
    } else {
        closeBox(box3);
        openBox(box1);
    }
}

function ShowSubMenu(kat_lp,kat_back_lp){
	   var lp=1;
	   while (document.getElementById('nagl_men_'+lp)) {
   		if (lp==kat_lp) {
   			document.getElementById('nagl_men_'+lp).className='poziom1on';
   		} else {
   			document.getElementById('nagl_men_'+lp).className='poziom1off';
   		}
    	    	lp++;
	   }
	   var lp=1;
	   while (document.getElementById('sub_men_'+lp)) {
   		if (lp==kat_lp) {
   			document.getElementById('sub_men_'+lp).style.display='block';
   		} else {
   			document.getElementById('sub_men_'+lp).style.display='none';
   		}
    	    	lp++;
	   }
	   if (kat_back_lp)
	   	setTimeout("ShowSubMenu("+kat_back_lp+",0)",1250);
			
}

function refreshIt(delay,img) {
 if (!document.getElementById('myCam')) return;
 var img=document.getElementById('plik_kamery').value;
 document.images['myCam'].src = img + '?' + Math.random();
 setTimeout('refreshIt('+delay+',"' + img + '")',delay);
}

function ShowCam(img,lp){
	document.getElementById('plik_kamery').value=img + '?' + Math.random(); 
	document.getElementById('myCam').src=img + '?' + Math.random();
	if (lp==1) var lpoff=2; else lpoff=1;
	document.getElementById('k'+lp+'l').className='actl';
   	document.getElementById('k'+lp+'s').className='actinc';
	document.getElementById('k'+lp+'p').className='actr';
	/*document.getElementById('strz'+lp).src='http://img.nocowanie.pl/gfx/kazimierzdolny_pl/strzala2.gif';*/
	
	document.getElementById('k'+lpoff+'l').className='nonactl';
   	document.getElementById('k'+lpoff+'s').className='nonactin';
	document.getElementById('k'+lpoff+'p').className='nonactr';
	/*document.getElementById('strz'+lpoff).src='http://img.nocowanie.pl/gfx/kazimierzdolny_pl/strzala1.gif';*/
}


function sumFields(field, value_field_id, sum_container)
{
	/*
	var sum = 0;
	for (i = 0; i < box_field.length; i++)
	{
		if (box_field[i].checked)
			sum += parseFloat(document.getElementById(value_field_id + box_field[i].value).value);
	}
	sum_container.innerHTML = sum;
	*/
	sum_container.innerHTML = roundNumber(parseFloat(sum_container.innerHTML) + parseFloat(document.getElementById(value_field_id + field.value).value)*((field.checked) ? 1 : (-1)),2);
}
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function uzupelnijCiastkiemZapytanie()
{
	if (getCookie('form_zapytanie[stat]') && getCookie('form_zapytanie[stat]') > 1 && document.getElementById('blokuj_ciastko').value != 1)
	{
		document.getElementById('nazwisko').value = getCookie('form_zapytanie[nazwisko]');
		document.getElementById('od').value = getCookie('form_zapytanie[od]');
		document.getElementById('do').value = getCookie('form_zapytanie[do]');
		document.getElementById('telefon').value = getCookie('form_zapytanie[telefon]');
		document.getElementById('email').value = getCookie('form_zapytanie[email]');
		document.getElementById('tresc').innerHTML = getCookie('form_zapytanie[tresc]');
	
		document.getElementById('nazwisko1').value = getCookie('form_zapytanie[nazwisko]');
		document.getElementById('od1').value = getCookie('form_zapytanie[od]');
		document.getElementById('do1').value = getCookie('form_zapytanie[do]');
		document.getElementById('telefon1').value = getCookie('form_zapytanie[telefon]');
		document.getElementById('email1').value = getCookie('form_zapytanie[email]');
		document.getElementById('tresc1').innerHTML = getCookie('form_zapytanie[tresc]');
	}
	
	if (getCookie('form_zapytanie[stat]') && getCookie('form_zapytanie[stat]') > 1)
	{
		document.getElementById('kod_token').innerHTML = '<div style="height: 62px; width: 10px; float: left"></div>';
		document.getElementById('kod_token1').innerHTML = '<div style="height: 62px; width: 10px; float: left"></div>';
	}
}


function groupSelection(obj, name, id_arr)
{
	 for (i in id_arr)
	 {
	 	var str = name + id_arr[i];
	 	if (document.getElementById(str))
	 		document.getElementById(str).checked = (obj.checked) ? true : false;
	 }
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}

function pokazNews(id)
{
	id_pokazane = document.getElementById('news_id_pokazane').value;

	if (id_pokazane != id)
	{
		document.getElementById('box_news_id_'+id_pokazane).style.display = 'none';
		document.getElementById('box_news_id_'+id).style.display = 'block';
	
		document.getElementById('guzik_id_'+id).className = 'on';
		document.getElementById('guzik_id_'+id_pokazane).className = '';
		
		document.getElementById('news_id_pokazane').value = id;
		document.getElementById('guzik_stat').value = id;
	}
}

function zmienNews(id, max)
{
	guzik_s = document.getElementById('guzik_stat').value;
	if (guzik_s != 'off') id = guzik_s;

	pokazNews(id);
	id++;
	if (id > max-1) id = 0;
	document.getElementById('guzik_stat').value = 'off';
	setTimeout("zmienNews("+id+", "+max+")", 6000);
}