function viewgeography(gid,gtype,lng){
  
  if (gtype=="country"){
    pgid = encodeURIComponent(document.reg.country_id.options[document.reg.country_id.selectedIndex].value);
    cgtype = "region";
  }
  if(gtype=="region"){
    pgid = encodeURIComponent(document.reg.region_id.options[document.reg.region_id.selectedIndex].value);
    cgtype = "town";
  }
  
  //alert(pgid);   
  str = 'ajax/aj_viewgeography.php?pgid='+pgid+'&gtype='+gtype+'&lng='+lng;  
  to = 'sel'+cgtype;
  
  ajaxLoad(to,str,'загрузка..');
  d = 'l'+cgtype;
  dv = document.getElementById(d);
  dv.style.display = 'block';
  d = 'sel'+cgtype;
  dv = document.getElementById(d);
  dv.style.display = 'block';
  return false;
}//viewgeography

function getgeohit(id,country_name,lng){  
  country_id = $('#'+id+' :selected').val(); 
  ajaxLoad('geohit','ajax/getgeohit.php?country_id='+country_id,'загрузка...', '');  
  getgeodistrictbycountry(country_id);
}

function getgeodistrictbycountry(id){   
  ajaxLoad('geodistrict','ajax/getgeodistrict.php?id='+id,'загрузка...', '');
}


function getgeodistrict(id,gname,lng){  
  gid = $('#'+id+' :selected').val();    
  ajaxLoad('geodistrict','ajax/getgeodistrict.php?id='+gid,'загрузка...', '');
  $('#georegion').hide();
  $('#geocity').hide();
}

function getgeoregion(id,gname,lng){  
  gid = $('#'+id+' :selected').val(); 
  $('#georegion').show();
  ajaxLoad('georegion','ajax/getgeoregion.php?id='+gid,'загрузка...', '');   
  $('#geocity').hide();
}

function getgeocity(id,gname,lng){  
  gid = $('#'+id+' :selected').val(); 
  $('#geocity').show();
  ajaxLoad('geocity','ajax/getgeocity.php?id='+gid,'загрузка...', '');
}

function getgeobcity(id,gname,lng){  
  gid = $('#'+id+' :selected').val(); 
  $('#geocity').show();
  ajaxLoad('geocity','ajax/getgeobcity.php?id='+gid,'загрузка...', '');
}//getgeobcity

function setgeographybyid(gid,gname){
  $('#geography_id').val(gid);
  $('#geography_name').html(gname);    
  $.fancybox.close(); 
  $('#formsearchcompany').submit(); 
}//setgeographybyid

function setgeography(){

  if ($('#city_id').is(':visible') && $("#city_id").val()!=0){
    gid = $("#city_id").val();
    gname = $("#city_id option:selected").text();
  }
  else{
    if ($('#region_id').is(':visible') && $("#region_id").val()!=0){
      gid = $("#region_id").val();
      gname = $("#region_id option:selected").text();
    }
    else{
      if ($('#district_id').is(':visible') && $("#district_id").val()!=0){
        gid = $("#district_id").val();
        gname = $("#district_id option:selected").text();
      }
      else{
        if ($('#country_id').is(':visible') && $("#country_id").val()!=0){
          gid = $("#country_id").val();
          gname = $("#country_id option:selected").text();
        }
      }
    }
  }

  $('#geography_id').val(gid);
  $('#geography_name').html(gname);
  $.fancybox.close();
  $('#formsearchcompany').submit(); 
}//setgeographybyid


