var gdir, obszar, showimage;
var maxZoom = 15;

function setshowimage(val){
    showimage = val;
}

function createTable(){
    var tbody = document.createElement('tbody');
    var tr = document.createElement('tr');
    var td = document.createElement('td');
    td.setAttribute('rowSpan', 2);
    td.setAttribute('align', 'center');
    td.setAttribute('width', '24%');
    td.className = 'tablehead';
    td.innerHTML = 'Typ obiektu';
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('rowSpan', 2);
    td.setAttribute('align', 'center');
    td.setAttribute('width', '25%');
    td.className = 'tablehead';
    td.innerHTML = 'Adres';
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'center');
    td.setAttribute('width', '30%');
    td.setAttribute('colSpan', 2);
    td.className = 'tablehead';
    td.innerHTML = 'Godziny pracy';
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('rowSpan', 2);
    td.setAttribute('align', 'center');
    td.setAttribute('width', '24%');
    td.className = 'tablehead';
    td.innerHTML = 'Miejsce,<br /> Uwagi';
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('rowSpan', 2);
    td.setAttribute('align', 'center');
    td.setAttribute('width', '14%');
    td.className = 'tablehead';
    td.innerHTML = 'Pokaż na mapie';
    tr.appendChild(td);
	tbody.appendChild(tr);
	
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.setAttribute('width', '10%');
	td.setAttribute('align', 'center');
	td.className = 'tablehead';
	td.innerHTML = 'pn-pt';
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('width', '10%');
	td.setAttribute('align', 'center');
	td.className = 'tablehead';
	td.innerHTML = 'sob.';
	tr.appendChild(td);
    tbody.appendChild(tr);
	return tbody;
}

function createTableRow(tbody, i){
    tr = document.createElement('tr');
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = departementList[i]["typ_nazwa"]+((departementList[i]["typ"]==3)?','+departementList[i]["cat"]:'');
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = departementList[i]["adresshort"];
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = departementList[i]["wh"];
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = departementList[i]["fh"];
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = departementList[i]["place"]+'<br/>'+departementList[i]["uwagi"];
    tr.appendChild(td);
    td = document.createElement('td');
    td.setAttribute('align', 'left');
    td.className = 'tabledata';
    td.innerHTML = '<a onclick = "myclick('+i+');" href="#">Pokaż</a><br>';
    tr.appendChild(td);
    tbody.appendChild(tr);
}

function currentPage(countppage, count){
    $('currpage').innerHTML = '';
    for(i = 0; i < Math.ceil(count/countppage); i++){
        option = document.createElement("option");
        option.setAttribute("value", i+1);
        option.innerHTML = i+1;
        $('currpage').appendChild(option);
    }
}

function addMarkers(placowki){
    if(placowki == null)return false;
    //$('nofound').style.display = 'none';
    var adres = placowki[0];
	var serwisy = placowki[1];
	var lat = placowki[2];
	var long1 = placowki[3];
	var sciezka = placowki[4];
	var wh = placowki[5];
	var fh = placowki[6];
	var nh = placowki[7];
    var typ = placowki[8]; 
    var uwagi = placowki[10];
    var place = placowki[9];
    var adresshort=placowki[11]; 
    var opis;
    var old_table = $('departementTable');
    var table = document.createElement('table');
    table.id = "departementTable";
    table.style.width = '50%';
    table.setAttribute('border', 0);
    table.setAttribute('cellpadding', 0);
    table.setAttribute('cellspacing', 0);
    table.setAttribute('align', 'center');
    var typ_nazwa = placowki[12];
    var cat = placowki[13];
    var markerIcon = placowki[14];
    var kategorie = new Array();
    kategorie['bz'] = 'BZWBK';
    kategorie['e'] = 'Euronet';
    var tbody = createTable(/*typ_nazwa*/);
    if(typ_nazwa == undefined)typ_nazwa = new Array();
    departementList = new Array();
    var countppage = $('countppage').value;
    for(i = 0; i < lat.length; i++){
        departementList[i] = new Array();
        departementList[i]["adresshort"] = adresshort[i];
        departementList[i]["wh"] = wh[i];
        departementList[i]["fh"] = fh[i];
        departementList[i]["place"] = place[i];
        departementList[i]["uwagi"] = uwagi[i];
        departementList[i]["typ"] = typ[i];
        if(typ_nazwa[i] == undefined)
            typ_nazwa[i] = $('s_type').options[$('s_type').selectedIndex].text;
        departementList[i]["typ_nazwa"] = typ_nazwa[i];
        departementList[i]["cat"] = kategorie[cat[i]];
        if(i < countppage)createTableRow(tbody, i);
        opis = '';
        if ( (wh[i] == fh[i]) && (fh[i] == nh[i]) && fh[i] == 0 ) {
            opis = '<div id="cloud_content" style="width:280px; height:180px; font-family:Verdana,Arial; font-size:10px; line-height:13px; color:black; text-align: center;"><div style="padding:10px 10px 0px 10px; font-weight:bold"><span style="display:block;font-size:10px;text-align:left;">'+typ_nazwa[i]+((typ[i]==3)?(','+kategorie[cat[i]]):'')+'</span><span style="display: block; text-align: left; margin-left: 27px;">'+adres[i]+'</span></div><div style="float:left; width:144px; padding: 5px 6px 15px 0px;"><span style="color:#979797;">godziny otwarcia</span><br />'+wh[i];
        }
        else {
            opis = '<div id="cloud_content" style="width:280px; height:180px; font-family:Verdana,Arial; font-size:10px; line-height:13px; color:black; text-align: center;"><div style="padding:10px 10px 0px 10px; font-weight:bold"><span style="display:block;font-size:10px;text-align:left;">'+typ_nazwa[i]+((typ[i]==3)?(','+kategorie[cat[i]]):'')+'</span><span style="display: block; text-align: left; margin-left: 27px;">'+adres[i]+'</span></div><div style="float:left; width:144px; padding: 5px 6px 15px 0px;"><span style="color:#979797;">godziny otwarcia</span><table><tr><td style="font-weight:bold; text-align:center;">pn-pt:</td><td style="text-align:center;">'+wh[i]+'</td></tr><tr><td style="font-weight:bold; text-align:center;">sob:</td><td style="text-align:center;">'+fh[i]+'</td></tr><tr><td style="font-weight:bold; text-align:center;">nd:</td><td style="text-align:center;">'+nh[i]+'</td></tr></table>';  
        }
        opis += '<span id="direction" style="display: inline; font-size: 9px">Dojedź <a id="toDir" href="javascript:tohere('+i+');">do</a> / <a id="fromDir" href="javascript:fromhere('+i+');">z</a> tego miejsca</span><br/><a id="back" href="javascript:hideDirection();" style="display: none; align: left; font-size: 9px">&lt;Cofnij</a>'; 
        adresshort[i] = adresshort[i].replace('<br />','');
        opis += '<div id="direction_form" style="display: none; text-align: left; font-size: 9px; width: 200px">Opis<form onsubmit="return getDirection(this);" style="margin: 0 padding: 0"><input type="text" id="input_city"  style="width: 80px; font-size: 10px;" onfocus="clearInput(this);" title="Miasto"/>&nbsp;<input type="text" id="input_street"  style="width: 80px; font-size: 10px;" onfocus="clearInput(this);" title="Ulica nr"/><input type="hidden" id="hid" value="'+typ_nazwa[i]+','+adresshort[i]+'@'+lat[i]+','+long1[i]+'"/><input type="submit" value="OK" style="width: 26px; font-size: 10px;"/></form></div>';
        if( showimage == 1 && sciezka[i] != '' && isThere(sciezka[i])) {
            opis += '<span id="min" style="display: none" ><br/><a href="#" onclick="map.getInfoWindow().restore(); return false;">pomniejsz zdjęcie</a></span></div><div style="float:left; padding:0px 0px;">';
            index = sciezka[i].lastIndexOf('.');
            var path = new Array();
            path['filename'] = sciezka[i].substring(0,index);
            path['ext'] = sciezka[i].substring(index);
            opis += '<img id="image" width="130px" height="85px" src="'+path['filename']+'_small'+path['ext']+'" style="display:block;" /><a id="max" style="display: inline" href="#" onclick="map.getInfoWindow().maximize(); hideDirection(); return false;">powiększ zdjęcie</a>';
        }
        opis += '</div></div>';
        if(serwisy[i] == '') {
            uslugi = '';       
        }
        else {
            uslugi = '<div style="width:280px; height:150px; font-family:Verdana,Arial; text-align:left; font-size:12px; line-height:18px; color:black;"><div style="height:150px; width:270px; overflow:auto;"><ul style="list-style-image:url(./images/point.gif); font-size:11px;">'+serwisy[i]+'</ul></div></div>';
        }
        icon = new GIcon();
        if(markerIcon[i] != '' /*&& isThere('markerIcon/'+urlencode(markerIcon[i]))*/){
		  icon.image = 'http://placowki.pl/markerIcon/'+markerIcon[i];
		}
		else
		  icon.image = 'http://maps.google.com/intl/pl_ALL/mapfiles/marker.png';
		//icon.iconSize = new GSize(12, 20);
		//icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		punkt = new GLatLng(lat[i],long1[i]);
        map.addOverlay(createMarker(punkt, icon, opis, uslugi,i,adresshort[i]));
        obszar.extend(punkt);
    }
    if(lat.length > 0){
        var nowyZoom = map.getBoundsZoomLevel(obszar);//ustal zoom
        if(nowyZoom > maxZoom)nowyZoom = maxZoom; 
        var nowyPunkt = obszar.getCenter();  
        map.setCenter(nowyPunkt,nowyZoom);
        table.appendChild(tbody);
	    $('tab1').replaceChild(table, old_table);
	    currentPage(countppage, i);
	    $('tablefotter').style.display = "inline";
	    changeTab(1);
	    $('tab2').innerHTML = '';
    }
}

function AJ() {
	var obj;
	if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
	else if (window.ActiveXObject){
		try{
			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
		}
		catch(er){
			try{
				obj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(er){
				obj= false;
			}
		}
	}
	return obj;
}

function isThere(url) {
	var req= new AJ(); // XMLHttpRequest object
	try {
		req.open("HEAD", url, false);
		req.send(null);		
		return req.status== 200 ? true : false;
	}
	catch (er) {
		return false;
	}
}

function urlencode(str) {
    str = escape(str);
    str = str.replace('+', '%2B');
    str = str.replace('%20', '+');
    str = str.replace('*', '%2A');
    str = str.replace('/', '%2F');
    str = str.replace('@', '%40');
    return str;
}

function clearInput(input){
    if(input.title != input.value)return;
    input.value = '';
    input.style.fontSize = '10px';
    input.style.color = '';
}

function tohere(nr){
    $('direction').style.display = 'none';
    $('back').style.display = 'inline';
    $('direction_form').innerHTML = $('direction_form').innerHTML.replace(/Opis/, 'Skąd');
    $('input_city').name = 'from_city';
    $('input_city').value = $('input_city').title;
    $('input_city').style.fontSize = '9px';
    $('input_city').style.color = '#979797';
    $('input_street').name = 'from_street';
    $('input_street').value = $('input_street').title;
    $('input_street').style.fontSize = '9px';
    $('input_street').style.color = '#979797';
    $('hid').name = 'to';
    $('direction_form').style.display = 'block';
}

function fromhere(nr){
    $('direction').style.display = 'none';
    $('back').style.display = 'inline';
    $('direction_form').innerHTML = $('direction_form').innerHTML.replace(/Opis/, 'Dokąd');
    $('input_city').name = 'to_city';
    $('input_city').value = $('input_city').title;
    $('input_city').style.fontSize = '9px';
    $('input_city').style.color = '#979797';
    $('input_street').name = 'to_street';
    $('input_street').value = $('input_street').title;
    $('input_street').style.fontSize = '9px';
    $('input_street').style.color = '#979797';
    $('hid').name = 'from';
    $('direction_form').style.display = 'block';
}

function hideDirection(){
    $('direction').style.display = 'inline';
    $('back').style.display = 'none';
    $('direction_form').style.display = 'none';
    $('direction_form').innerHTML = $('direction_form').innerHTML.replace(/Skąd/, 'Opis');
    $('direction_form').innerHTML = $('direction_form').innerHTML.replace(/Dokąd/, 'Opis');
}

function getDirection(formularz){
    for(var i = 0; i < formularz.childNodes.length; i++){
        switch(formularz.childNodes[i].name){
            case 'from':
                var from = formularz.childNodes[i].value;
                break;
            case 'to':
                var to = formularz.childNodes[i].value;
                break;
            case 'from_city':
                var from = 'city: '+formularz.childNodes[i].value+' street: '+formularz.childNodes[i+2].value;
                break;
            case 'to_city':
                var to = 'city: '+formularz.childNodes[i].value+' street: '+formularz.childNodes[i+2].value;
                break;
        }
    }
    gdir.load("from: "+from+" to: "+to);
    return false;
}

function onGDirectionsLoad(){
    $('tabTitle2').style.display = 'inline';
    changeTab(2);
}

function handleErrors(){
    $('tabTitle2').style.display = 'none';
    changeTab(1);
    showWindow(WINDOW_GEOCODE);
}

function search_radius(){
    var form = $('myform');
    var radius_val = $('radius').value;
    var miasto_val = form.miasto.value;
    var wojewodztwo_val = form.wojewodztwo.value;
    if(radius_val > 0){
        var geoc = new GClientGeocoder();
        if($('state').checked)
            tmp = 'province: '+wojewodztwo_val;
        else
            tmp = 'city: '+miasto_val;
        geoc.getLatLng('PL, '+tmp, getLatLng);/*getLatLng*/
    }
}

function getLatLng(response){
    if(response == null)return false;
    search_click($('myform'), $('radius').value, response.lat(), response.lng())
}

function getStreets(city_val){
    city_val = city_val.substr(0, city_val.search(/,/));
    var myAjax = new Ajax.Request(
          'getdata.php', {
            method: 'post', 
            parameters: {city: city_val},
            onSuccess: function(transport){
                var result = new Array();
                result = transport.responseText.evalJSON();
                html = '';
                aktualnaPodpowiedz = new Array();
                if(result != null){
                    for(var i=0; i<result.length; i++) {
                      result[i] = city_val + ',' + result[i];
                      /*if(!result[i].search(re)) */{
                        aktualnaPodpowiedz.push(result[i]);
                        /*if( result[i].toLowerCase() == cos.toLowerCase() ) 
                          continue;*/
                        //alert(result[i]);
                        html += '<div id="'+result[i]+'" ';
                        html += 'style="cursor:pointer; margin-left:5px; margin-bottom:2px;" ';
                        html += 'onclick="$(\'miasto\').value=\''+result[i]+'\'; if(document.forms[\'myform\'].onsubmit())document.forms[\'myform\'].submit(); $(\'podpowiedz\').style.display = \'none\';"';
                        html += 'onmouseover="document.getElementById(\''+result[i]+'\').style.background=\'#FFFF00\'"';
                        html += 'onmouseout="$(\''+result[i]+'\').style.background=\'#FFB623\'"> '+result[i]+'</div>';
                       }
                    }
                    html = "<span style=\"margin-left:5px; font-weight:bold;\">Wybierz miasto:</span>" + html;
                    $("podpowiedz").innerHTML = html;
                }
            },
            onFailure: function() {
              alert('W tej chwili wyszukanie ulic jest niemożliwe. Proszę spróbować ponownie.');
            }
          }
    );
}

function search_click(form, radius_val, lat_val, lng_val){
    hideWindow();
    if(radius_val == undefined)radius_val = 0;
    if(lat_val == undefined)lat_val = 0;
    if(lng_val == undefined)lng_val = 0;
    var group_val = ((form.group[0].checked)?form.group[0].value:form.group[1].value);
    var search_val = ((form.search[0].checked)?form.search[0].value:form.search[1].value);
    var s_type_val = form.s_type.value;
    var s_services_val = form.s_services.value;
    var miasto_val = form.miasto.value;
    var wojewodztwo_val = form.wojewodztwo.value;
    $('loading').style.display = 'block';
    $('s_services').style.visibility = 'hidden';
    $('s_type').style.visibility = 'hidden';
    $('wojewodztwo').style.visibility = 'hidden';
    var myAjax = new Ajax.Request(
          'getdata.php', {
            method: 'post', 
            parameters: {group: group_val, search: search_val,
                s_type: s_type_val, s_services: s_services_val, miasto: miasto_val, wojewodztwo: wojewodztwo_val,
                radius: radius_val, lat: lat_val, lng: lng_val
            },
            onSuccess: function(transport){
                var placowki = transport.responseText.evalJSON();
                window.setTimeout(function() {
                    $('tablefotter').style.display = "none";
                    $('departementTable').style.display = "none";
                    $('table_place').style.display = "none";
                    map.clearOverlays();
                    obszar = new GLatLngBounds();
                    if(placowki != null){
                        $('table_place').style.display = "block";
                        $('tabTitle2').style.display = "none";
                        if(radius_val > 0){
                            //alert(lat_val + ' ' + lng_val);
                            punkt = new GLatLng(lat_val,lng_val);
                            var marker = new GMarker(punkt);
                            map.addOverlay(marker);
                            obszar.extend(punkt);
                        }
                    addMarkers(placowki);
                    }
                    else if( ($('city').checked && $('miasto').value != '') || !$('city').checked){
                        //$('radius').value = '10';
                        var geoc = new GClientGeocoder();
                        if($('state').checked)
                            tmp = 'province: '+$('wojewodztwo').value;
                        else
                            tmp = 'city: '+$('miasto').value;
                        geoc.getLocations('PL, '+tmp, function(result){
                            var content = '';
                            if (result.Status.code == G_GEO_SUCCESS){
                                if($('services').checked) 
                                    content += 'oferujące usługę<br/>'+$('s_services').options[$('s_services').options.selectedIndex].text;
                                else
                                    content += 'typu<br/>'+$('s_type').options[$('s_type').options.selectedIndex].text;
                                $('user_choice').innerHTML = content;
                                var lat_val = result.Placemark[0].Point.coordinates[1];
                                var lng_val = result.Placemark[0].Point.coordinates[0];
                                var punkt = new GLatLng(lat_val,lng_val);
                                var marker = new GMarker(punkt);
                                map.addOverlay(marker);
                                obszar.extend(punkt);
                                var nowyZoom = map.getBoundsZoomLevel(obszar);//ustal zoom
                                if(nowyZoom > maxZoom)nowyZoom = maxZoom;   
                                var nowyPunkt = obszar.getCenter();  
                                map.setCenter(nowyPunkt,nowyZoom);
                                showWindow(WINDOW_DIALOG);
                            }
                            else{
                                showWindow(WINDOW_ALERT);
                            }
                        });
                        /*$('nofound').style.display = 'inline';
                        $('table_place').style.display = "none";*/
                    }
            });
                $('loading').style.display = 'none';
                $('s_services').style.visibility = 'visible';
                $('s_type').style.visibility = 'visible';
                $('wojewodztwo').style.visibility = 'visible';
            },
            onFailure: function() {
              alert('Błąd, spróbuj ponownie...');
              $('loading').style.display = 'none';
              $('s_services').style.display = 'inline';
              $('s_type').style.display = 'inline';
              $('wojewodztwo').style.display = 'inline';
            }
          }
    );
    return false;
    //s_type: s_type_value, s_services: s_services_val, miasto: miasto_val, wojewodztwo: wojewodztwo_val
}

function createMarker(point, icon, html1, html2,nr, adres) {
	var marker = new GMarker(point, {icon: icon, title: adres.replace(/<br \/>/, ''), icon: icon});
	
	GEvent.addListener(marker, "click", function() {
      var point = marker.getPoint();
      var bounds = map.getBounds();
      var southWest = bounds.getSouthWest();
      var size = bounds.toSpan();
      var center = map.getCenter();
      var xDisLat = center.lat() + (point.lat() - (southWest.lat() + (size.lat() / 12)));
      var yDisLng = center.lng() + (point.lng() - (southWest.lng() + ((size.lng() / 16) * 6)));
      var tab1 = document.createElement("div");
      var tab2 = document.createElement("div");
      var tab3 = document.createElement("div");
      tab3.style.width = "280px";
      tab3.style.height = "180px";
      //html1 += '<a href="#" onclick="map.showMapBlowup(point);">Lupa</a>';
      tab1.innerHTML = html1;
      tab2.innerHTML = html2;
      if(html2 == '')
    	 var infoTabs = [
            new GInfoWindowTab("Opis", tab1),
            new GInfoWindowTab("Minimapa", tab3)
            ];
      else 
          var infoTabs = [
            new GInfoWindowTab("Opis", tab1),
            new GInfoWindowTab("Usługi", tab2),
            new GInfoWindowTab("Minimapa", tab3)
          ];
      var map2 = new GMap2(tab3,{size:new GSize(280,180)});
      map2.addControl(new GSmallZoomControl());
      map2.setCenter(point,15);
      var mark2 = new GMarker(point, {icon: icon, title: adres.replace(/<br \/>/, '')}); 
      map2.addOverlay(mark2);
      tab3.firstChild.nextSibling.style.display = 'none';  
      tab3.firstChild.nextSibling.nextSibling.style.display = 'none';
      map.setCenter(new GLatLng(xDisLat, yDisLng));
      if(html1.search("img") != -1){
          var maxHtml1 = html1;
          maxHtml1 = maxHtml1.replace(/<div id="cloud_content" style="width:280px; height:180px;/, "<div style=\"width:auto; height:auto;");
          maxHtml1 = maxHtml1.replace(/<img id="image" width="130px" height="85px"/, "<img width=\"380px\" height=\"290px\"");
          maxHtml1 = maxHtml1.replace(/_small/, "");
          maxHtml1 = maxHtml1.replace(/id="max" style="display: inline"/, "id=\"max\" style=\"display: none\"");
          maxHtml1 = maxHtml1.replace(/id="min" style="display: none"/, "id=\"min\" style=\"display: inline\"");
          //html1 = html1.replace(/id="direction" style="display: inline"/, "id=\"direction\" style=\"display: none\"");
          var maxTab1 = document.createElement("div");
          maxTab1.innerHTML = maxHtml1;
    	  marker.openInfoWindowTabs(infoTabs, {maxContent: maxTab1});
      }
      else marker.openInfoWindowTabs(infoTabs);
    	});
    GEvent.addListener(marker, "infowindowbeforeclose", function(){
        hideDirection();
    });
    	//dodane PK
    	// save the info we need to use later for the side_bar
    gmarkers[nr] = marker;
    // add a line to the side_bar html
    
    //i++;
    	//end
    return marker;
}

function changePage(page){
    page = parseInt(page);
    var old_table = $('departementTable');
    var table = document.createElement('table');
    table.id = "departementTable";
    table.style.width = '50%';
    table.setAttribute('border', 0);
    table.setAttribute('cellpadding', 0);
    table.setAttribute('cellspacing', 0);
    table.setAttribute('align', 'center');
    var tbody = createTable(departementList[0]["typ_nazwa"]);        
    var countppage = parseInt($('countppage').value);
    for(i = 0; i < countppage; i++){
        if(departementList.length == (page-1)*countppage+i)break;
        createTableRow(tbody, (page-1)*countppage+i);
    }
    table.appendChild(tbody);
	$('tab1').replaceChild(table, old_table);
}

function changePPage(count){
    changePage(1);
    currentPage(count, departementList.length);
}

function onlyNum(evt,param){
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event){ // IE
	  	keynum = evt.keyCode;
	}
	else if(evt.which){  // Netscape/Firefox/Opera
	  keynum = evt.which;
	}
	keychar = String.fromCharCode(keynum);
	if(keynum == 13){
	   search_radius();
	   return true;
	}
	if(keynum == undefined)return true;
	if(param == undefined)numcheck = /[0-9\b\n]/;
	else numcheck = /[0-9.\b\n]/;
	return numcheck.test(keychar);
}

function changeTab(nr){
    var currentTab = $('tab'+nr);
    var otherTab = $('tab'+(3-nr));
    currentTab.style.display = 'block';
    otherTab.style.display = 'none';
    $('tabTitle'+nr).className = 'tab-head-act';
    $('tabTitle'+(3-nr)).className = 'tab-head';
}
