    var map = null;
    var geocoder = null;
	
	var lat=52.173931692568;
	var lng=18.8525390625;
	var zoom=6;


    function initialize() {
	    if (GBrowserIsCompatible()) {
		    map = new GMap2(document.getElementById("map_canvas"));
		    map.setCenter(new GLatLng(lat,lng),zoom);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
		   	geocoder = new GClientGeocoder();
      
	  	
			GEvent.addListener(map, "click", function(overlay, point) {	   
				map.clearOverlays();
				map.addOverlay(new GMarker(point));
				document.fo.wsp.value = point.y + '+' + point.x;      		 
			});
	  
	  }
		//po odswiezeniu jesli sa wypelnione pola to ustawiamy mape
		if(document.fo.wsp.value != '' )  showAddress(document.fo.wsp.value); 
	}
	
	
	function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " nie istnieje");
            } else {

            
	      map.setCenter(point, 10);
              map.clearOverlays();
	    
		var marker = new GMarker(map.getCenter());
             map.addOverlay(marker);			
			document.fo.wsp.value = marker.getLatLng().lat() + '+' + marker.getLatLng().lng();

	
            }
          }
        );
      }
    }
	
	
	
	



function setDane(f) {
	f.odbierajacy_f.value = f.odbierajacy.value;
	f.kod_p_f.value = f.kod_p.value;
	f.miejscowosc_f.value = f.miejscowosc.value;
	f.ulica_f.value = f.ulica.value;
 return;
}




function rodzajGarazu(f) {
	
	
	if (f.garaz.options[f.garaz.selectedIndex].value == 'a') {
		f.szerokosc.readOnly=true;
		f.szerokosc.value=szerokosc;
		f.szerokosc.style.backgroundColor="silver";
		
		f.dlugosc.readOnly=true;
		f.dlugosc.value=dlugosc;
		f.dlugosc.style.backgroundColor="silver";
		
		f.wysokosc.readOnly=true;
		f.wysokosc.value=wysokosc;
		f.wysokosc.style.backgroundColor="silver";
		
	} else {
		f.szerokosc.readOnly=false;
		f.szerokosc.style.backgroundColor="white";
		f.dlugosc.readOnly=false;
		f.dlugosc.style.backgroundColor="white";
		f.wysokosc.readOnly=false;
		f.wysokosc.style.backgroundColor="white";
	}
 return;
}

function rodzajBlachy(f) {
	if (f.blacha.options[f.blacha.selectedIndex].value == 'd') {
		document.getElementById('kolory').style.display="inline";
	}else{
		document.getElementById('kolory').style.display="none";	
	}
 return;
}





function menu(id) {
  if (document.getElementById(id).style.display=="none") {
    document.getElementById(id).style.display="inline";
  } else {
    document.getElementById(id).style.display="none";
  }
}

function okno(url, width, height) {
        var win = window.open(url,"okienko",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no' );
}


function FontSize(size, wyb) {
	document.getElementById("srodek").style.fontSize = size;	
	document.getElementById("size1").style.color = "black";
	document.getElementById("size2").style.color = "black";
	document.getElementById("size3").style.color = "black";
	document.getElementById(wyb).style.color = "#FF6805";	
}

function antyspam(t) {
  t.spam.value=9;
 
  return true;
}


function empty(elem, helperMsg){
	if(document.getElementById(elem).value.length == 0){		
		document.getElementById(elem).focus(); // set the focus to this input
		document.getElementById(elem + "v").innerHTML = helperMsg;
		return true;
	}
	document.getElementById(elem + "v").innerHTML = '';
	return false;
}

function emptyTwo(elem1, elem2, helperMsg){
	if(document.getElementById(elem1).value.length == 0 && document.getElementById(elem2).value.length == 0){
		document.getElementById(elem1 + "v").innerHTML = helperMsg;
		document.getElementById(elem1).focus(); // set the focus to this input
		return true;
	}
	document.getElementById(elem1 + "v").innerHTML = '';
	return false;
}

function lengthMinMax(elem, min, max){
	var uInput = document.getElementById(elem).value;
	if(uInput.length >= min && uInput.length <= max){
		document.getElementById(elem + "v").innerHTML = '';
		return true;
	}else{
		document.getElementById(elem + "v").innerHTML = "Pole powinno zawierać od " +min+ " do " +max+ " znaków.";
		document.getElementById(elem).focus();
		return false;
	}
}

function lengthMax(elem, max){
	var uInput = document.getElementById(elem).value;
	if(uInput.length <= max){
		document.getElementById(elem + "v").innerHTML = '';
		return true;
	}else{
		document.getElementById(elem + "v").innerHTML = "Pole powinno zawierać maksymalnie do " +max+ " znaków.";
		document.getElementById(elem).focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var Input = document.getElementById(elem).value;
	if(Input.length > 0) //jesliwypelnione pole mail to wtedy sprawdzamy
	{
		var Exp = /^[0-9a-z_.-]+@([0-9a-z-]+\.)+[a-z]{2,6}$/;
		if(document.getElementById(elem).value.match(Exp)){
			document.getElementById(elem + "v").innerHTML = '';
			return true;
		}else{
			document.getElementById(elem + "v").innerHTML = helperMsg;
			document.getElementById(elem).focus();
			return false;
		}
	}return true;
}

function telValidator(elem, helperMsg){
	var Input = document.getElementById(elem).value;
	if(Input.length > 0) //jesliwypelnione pole mail to wtedy sprawdzamy
	{
		var Exp = /^\+?[0-9- ]+$/;
		if(document.getElementById(elem).value.match(Exp)){
			document.getElementById(elem + "v").innerHTML = '';
			return true;
		}else{
			document.getElementById(elem + "v").innerHTML = helperMsg;
			document.getElementById(elem).focus();
			return false;
		}
	}return true;
}


function isSelection(elem, helperMsg){
	if (document.getElementById(elem).options[document.getElementById(elem).selectedIndex].value == 0){
		document.getElementById(elem + "v").innerHTML = helperMsg;
		document.getElementById(elem).focus();
		return false;
	}else{
		document.getElementById(elem + "v").innerHTML = '';
		return true;
	}
}

function isNumeric(elem, helperMsg, idMsg){
	var numericExpression = /^[0-9]+$/;
	if(document.getElementById(elem).value.match(numericExpression)){
		return true;
	}else{
		document.getElementById(idMsg).innerHTML = helperMsg;
		document.getElementById(elem).focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg, idMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(document.getElementById(elem).value.match(alphaExp)){
		return true;
	}else{
		document.getElementById(idMsg).innerHTML = helperMsg;
		document.getElementById(elem).focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg, idMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(document.getElementById(elem).value.match(alphaExp)){
		return true;
	}else{
		document.getElementById(idMsg).innerHTML = helperMsg;
		document.getElementById(elem).focus();
		return false;
	}
}

//======================================================================================================
Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=parseFloat(this[i++]));
	return sum;
}
function kolor_over(kolor,dd){
	var kolory = {
		1 : '#dbbe60',
		2 : '#f4de0e',
		3 : '#71141e',
		4 : '#7e191d',
		5 : '#1b3486',
		6 : '#317f43',
		7 : '#293133',
		8 : '#cfd6ce',
		9 : '#8a3d29',
		10 : '#31221d',
		11 : '#e7ecd8',
		12 : '#a3a8ab',
		13 : '#f7f8f2'
	}
	var kol;
	
	$(dd.parentNode.parentNode).appendChild($('probnik_cont'));
	
	if(kol = $H(kolory).get(kolor))
	{
		$('probnik_cont').show();
		$('probnik').show();
		$('probnik').morph('background:' + kol,{duration:0.4});
	}
	else
	{
		$('probnik_cont').hide();
	}
	return false;

}

function show_form_zamow(link){
var f = $('form_zamow');
if(f.visible()) return;
$(link).hide();
Effect.Appear(f,{duration:0.5,afterFinish:function(){
		var m = $('nag_dodatki').cumulativeOffset().top - f.cumulativeOffset().top - 10;
		if(m < 0) m = 0;
		f.morph('margin-top:'+ m + 'px',{duration:0.7,afterFinish:function(){new Effect.ScrollTo(f);}});
	}});
	
	
//Effect.Appear('strzalka_zamow',{duration:0.5});

}
function wysokosc()
{
	$A($$('.o_wysokosc')).each(Element.hide);
	var aktywne = $A($$('.' + $A(arguments).join('.')));

	var selektorRadio = function(o){
		var ob = o.firstDescendant();
		if(ob.type == 'radio') return ob;
	}	
	
	var selektorRadioByWys = function(o){ //znajdź opcje z wysokością domyślną
		//if(parseInt($H(o.value.split(',')).get(3)) == parseInt(f.garaz.wysokosc_def + (f.garaz.typ_bramy.include('uchylna') ? 10 : 0))) return true;
		if(parseInt($H(o.value.split(',')).get(3)) == parseInt(f.garaz.wysokosc_def)) return true;
	}

	var listaRadio = aktywne.collect(selektorRadio);

	if(!listaRadio.pluck('checked').any()) 
	{
		var doZaznaczenia = listaRadio.find(selektorRadioByWys) || listaRadio.first(); //wybrany wg wysokości domyślnej lub pierwszy
		doZaznaczenia.checked = true;

	}
	
	aktywne.each(Element.show);
	
}

function konstrukcja()
{
	
	$A($$('.o_konstrukcja')).each(Element.hide);
	var aktywne = $A($$('.' + $A(arguments).join('.')));

	var selektorRadio = function(o){
		var ob = o.firstDescendant();
		if(ob.type == 'radio') return ob;
	}	

	var selektorRadioByKon = function(o){ //znajdź opcje z wysokością domyślną
		if($H(o.value.split(',')).get(3) == f.garaz.typ_konstrukcji ) return true;
	}
	
	var listaRadio = aktywne.collect(selektorRadio);

	if(!listaRadio.pluck('checked').any()) 
	{
		var doZaznaczenia = listaRadio.find(selektorRadioByKon) || listaRadio.first();; //zaznacz pierwszy
		doZaznaczenia.checked = true;

	}
	
	aktywne.each(Element.show);
	
}


function ocynkowana_konstrukcja()
{
	
	$A($$('.o_ocynkowana_konstrukcja')).each(Element.hide);
	var aktywne = $A($$('.' + $A(arguments).join('.')));

	var selektorRadio = function(o){
		var ob = o.firstDescendant();
		if(ob.type == 'radio') return ob;
	}	
	
	
	var selektorRadioByOcynk = function(o){ //znajdź opcje z wysokością domyślną
		if($H(o.value.split(',')).get(3) == f.garaz.typ_ocynku ) return true;
	}
	
	var listaRadio = aktywne.collect(selektorRadio);

	//if(!listaRadio.pluck('checked').any()) 
	//{
		var doZaznaczenia = listaRadio.find(selektorRadioByOcynk) || listaRadio.first();; //zaznacz pierwszy
		doZaznaczenia.checked = true;

	//}
	
	aktywne.each(Element.show);
	
}




function form_zam(f,garaz)
{
	f = $(f);
	f.garaz = garaz;
	window.f = f;
	parametryGarazu();
	
	
	Element.observe(f,'submit',function(event){
		if(f.woj.selectedIndex == 0)
		{
			hsAlert('<b>Wybierz miejsce transportu</b><br /><br />Przejdź do zakładki &quot;transport do województwa&quot; w&nbsp;konfiguratorze po lewej i&nbsp;wybierz województwo, w którym mamy zamontować Twój garaż.');
			event.stop();
		}
	});

	var evHandle = function(ob)
	{
		var eventName; 
		if(ob.type == 'select-one')		eventName = 'change';
		else if(ob.type == 'checkbox') 	eventName = 'click';
		else if(ob.type == 'radio') 	eventName = 'click';
		else return;
		
		if(ob.checked && ob.alt) eval(ob.alt);
		
		//Element.observe(ob,eventName,.bindAsEventListener());
		Element.observe(ob,eventName,function(){
			var v = $H(ob.value.split(','));
			var k = parseFloat(v.get(0)).toFixed(2);
			var typ = v.get(1);
			
			if(typ == 'i') hsAlert('<b>Cena za wybraną opcję obliczana jest indywidualnie.</b><br /><br />Po złożeniu zamówienia nasz konsultant skontaktuje się z Państwem, by poinformować o dokładnych kosztach.');
			
			parametryGarazu(); 
			if(ob.alt) eval(ob.alt); 
			cena(null,f);
		});
		//Element.observe(ob,eventName,cena.bindAsEventListener(this,f));
		
	}
	
	f.getElements().each(evHandle);
	document.observe('dom:loaded',cena.bindAsEventListener(this,f));
}
function parametryGarazu()
{

	try
	{
		f.garaz.typ_dachu = $H(f.getElements().find(function(ob){ if(ob.name == 'opcja:dach' && ob.checked) return true; }).value.split(',')).get(3);
	}
	catch(e){ } //jeśli nie ma opcji dodatkowych	
	
	try
	{
		f.garaz.typ_bramy = $H(f.getElements().find(function(ob){ if(ob.name == 'opcja:brama' && ob.checked) return true; }).value.split(',')).get(3).strip();
	}
	catch(e){ } //jeśli nie ma opcji dodatkowych	
	
	try
	{
		f.garaz.typ_konstrukcji = $H(f.getElements().find(function(ob){ if(ob.name == 'opcja:konstrukcja' && ob.checked) return true; }).value.split(',')).get(3).strip();
	}
	catch(e){ } //jeśli nie ma opcji dodatkowych	
	
	try
	{
		f.garaz.typ_ocynku = $H(f.getElements().find(function(ob){ if(ob.name == 'opcja:ocynkowana-konstrukcja' && ob.checked) return true; }).value.split(',')).get(3).strip();
	}
	catch(e){ } //jeśli nie ma opcji dodatkowych
}
function cena(event,f)
{
/*
	var cenaObliczona = $('cena_obliczona');
	cenaObliczona.kosztyIndywidualne = new Array();
	
	//parametryGarazu();
	try
	{
	var wspWym = f.garaz.typ_dachu.include('tylu') ? f.garaz.dlugosc : f.garaz.szerokosc; //do liczenia np. świetlika
	var wspRyn = f.garaz.typ_dachu.include('tylu') ? f.garaz.szerokosc + 0.2 : (f.garaz.typ_dachu.include('bok') ? f.garaz.dlugosc + 0.2 : 2 * (f.garaz.dlugosc + 0.2)); //rynny

	
		f.garaz.wysokosc = parseFloat($H(f.getElements().find(function(ob){ if(ob.name == 'opcja:wysokosc' && ob.checked) return true; }).value.split(',')).get(3))/100; //wysokość wybrana
	}
	catch(e){} //jeśli nie ma opcji dodatkowych

	var koszt = function(ob)
	{
		var v = $H(ob.value.split(','));
		var k = parseFloat(v.get(0)).toFixed(2);
		var typ = v.get(1);
		
		if(ob.name.include('ocynkowana-konstrukcja') && f.garaz.wysokosc != f.garaz.wysokosc_def/100 && k > 0) typ = 'i'; //ocynkowana konstrukcja tylko dla podstawowej wysokości
		
	
		if(typ == 'm') 			k *= wspWym; //razy metr blachy na dachu - zależnie od rodzaju dachu liczenie wg długości lub szerokości
		else if(typ == 'r') 	k *= wspRyn; //rynny
		else if(typ == 'p') 	k *= ( (2 * ( f.garaz.dlugosc + f.garaz.szerokosc ) * f.garaz.wysokosc)  + (f.garaz.dlugosc * f.garaz.szerokosc));
		else if(typ == 'i' && ob.checked) 	
		{
			
			//cenaObliczona.kosztyIndywidualne.push('+ dopłata za: ' + ob.name.replace('-',' ').replace('opcja:',''))
			cenaObliczona.kosztyIndywidualne.push('+ dopłata za: ' + ob.title)
			return 0;
		}
		
		if(ob.type == 'radio' && ob.checked) return k;
		if(ob.type == 'select-one') return k;
		if(ob.type == 'checkbox' && ob.checked) return k;
		return 0.00;
	}
	
	cenaObliczona.cena = (f.garaz.cena + f.getElements().collect(koszt).sum());
	
	cenaObliczona.cena = (cenaObliczona.cena == 0) ? '<em style="font-size:12px">do uzgodnienia<br />z konsultantem</em>' : cenaObliczona.cena + ' zł';
	
	cenaObliczona.update(cenaObliczona.cena + '<br /><span onmouseover="tooltip.show(\'Koszty ustalane indywidualnie. Po złożeniu zamówienia nasz konsultant skontaktuje się z&nbsp;Państwem, aby poinformować o końcowej cenie.\')" onmouseout="tooltip.hide()">'+cenaObliczona.kosztyIndywidualne.join('<br />')+'</span>');
*/
}
function hsAlert(tekst)
{
	var d = new Element('div',{'class':'highslide-html-content'});
	document.body.appendChild(d);
	d.update('' + tekst + '<br /><br /><input type="button" name="zamknij" value="OK" onclick="hs.close(this)" style="padding:5px 20px;border:1px outset black" />');
	var a = new Element('a',{'href':'#','class':'highslide-html-content','style':'display:none;'});
	document.body.appendChild(a);
	hs.htmlExpand(a,{contentId: d.identify(), dimmingOpacity: 0.75});
}
function selecty(ob)
{
	
	ob = $(ob);
	
	var cont = new Element('span');
	var inputh = new Element('input',{'type':'hidden','name':ob.name});
	var input = new Element('input',{'type':'text','readonly':'readonly'});
	var lista = new Element('ul');
	
	inputh.onchange = Object.isFunction(ob.onchange) ? ob.onchange : function(){};
	
	
	var focusInput = function(event){
		lista.show();
	}	
	
	var blurInput = function(event){
		lista.hide();
	}	
	
	var clickInput = function(event){
		lista.toggle();
	}
	
	var clickLi = function(event,ob){
		input.value = ob.innerHTML;
	
		inputh.value = ob.wart;
		
		inputh.onchange();
		
		lista.hide();
	}	
	
	
	var option2li = function(ob)
	{
	
		var li = new Element('li');
		li.wart = ob.value;
		li.update(ob.text);
		lista.appendChild(li);
		Element.observe(li,'click',clickLi.bindAsEventListener(this,li));
		
	}
	
	$A(ob.options).each(option2li);
	
	cont.addClassName('selecty');
	input.clonePosition(ob,{setLeft:false,setTop:false,setHeight:false});
	input.value = ob.options[ob.selectedIndex].text;
	inputh.value = ob.value;
	cont.appendChild(input);
	cont.appendChild(inputh);
	cont.appendChild(lista);
	//cont.style.height = input.getHeight() + 'px';
	lista.hide();
	ob.replace(cont);
	
	
	Element.observe(input,'click',clickInput.bindAsEventListener(this));
	Element.observe(lista,'mouseover',focusInput.bindAsEventListener(this));
	Element.observe(lista,'mouseout',blurInput.bindAsEventListener(this));
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = false; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
//if((getInternetExplorerVersion() || 8) > 7) document.observe('dom:loaded',function(){$A($$('select')).each(selecty);});
