function showLocals(id)
{


    $(visibleLocal).className = 'invisible'
    $(visibleCity).className = 'tag';
    $("local"+id).className = 'visible';
    $("city"+id).className = 'tag active';
    visibleLocal = "local"+id;
    visibleCity = "city"+id;
}

function showZapytanie(obj,polec_name,zapytanie_name)
{   
    if($('zapytaniediv').className == 'visible') {
	$('zapytaniediv').className = 'invisible';
	$('polecdiv').className = 'visible';
	obj.innerHTML = zapytanie_name;
    } else if($('zapytaniediv').className == 'invisible') {
	$('zapytaniediv').className = 'visible';
	$('polecdiv').className = 'invisible';
	obj.innerHTML = polec_name;
    }
}


function countCheckboxes(obj,city_id)
{
    if(obj.checked == true) {
	 $("span"+city_id).innerHTML = parseInt($("location_number"+city_id).value) + 1;
	 $("location_number"+city_id).value = parseInt($("location_number"+city_id).value) + 1;
    } else {
	$("span"+city_id).innerHTML = parseInt($("location_number"+city_id).value) - 1;
	$("location_number"+city_id).value = parseInt($("location_number"+city_id).value) - 1;
    }
    
    if($("location_number"+city_id).value != 0) {
	$("span"+city_id).innerHTML = "(" + $("span"+city_id).innerHTML + ")";
    } else {
	$("span"+city_id).innerHTML = "";
    }
}

function checkByLink(location_id,city_id) {

	if($("location"+location_id).checked == false) {
	    $("location"+location_id).checked = true;
	    countCheckboxes($("location"+location_id),city_id);
	} else {
	    $("location"+location_id).checked = false;
	    countCheckboxes($("location"+location_id),city_id);
	}
    
}

function checkLocation(id_str) {
    var id = id_str.split(",");
    for (i = 0; i < id.length; i++) {
	if($("location"+id[i]).checked == false) {
	    $("location"+id[i]).checked = true;
	    countCheckboxes($("location"+id[i]),$("city_location"+id[i]).value);
	}
    }
}

function uncheckLocation(id_str) {
    var id = id_str.split(",");
    for (i = 0; i < id.length; i++) {
	if($("location"+id[i]).checked == true) {
	    $("location"+id[i]).checked = false;
	    countCheckboxes($("location"+id[i]),$("city_location"+id[i]).value);
	}
    }
}

function checkAll(location_string,city_id,checkflag) {
    
    var fields = location_string.split(",");

if (checkflag == "false") {
  for (i = 0; i < fields.length; i++) {
  $("location"+fields[i]).checked = true;}
  //$("checkAllLink"+city_id).className = 'invisible';
  //$("uncheckAllLink"+city_id).className = 'visible';
  $("span"+city_id).innerHTML = "(" + fields.length + ")";
  $("location_number"+city_id).value = fields.length;
   }
else {
  for (i = 0; i < fields.length; i++) {
  $("location"+fields[i]).checked = false; }
  //$("checkAllLink"+city_id).className = 'visible';
  //$("uncheckAllLink"+city_id).className = 'invisible';
  $("span"+city_id).innerHTML = '';
  $("location_number"+city_id).value = '0';
 }
}

function changePriceField(obj) {
    if(obj.value == 'sprzedaz') {
	$('price1_field').className = 'visible';
	$('price2_field').className = 'invisible';
    } else {
	$('price1_field').className = 'invisible';
	$('price2_field').className = 'visible';
    }
}

function generatePDF(url, name)
{       
	xajax_updatePostElement(url, name, postData);
}
  
