$(document).ready(function(){

    $('#typ').change(function(e){
          var typ = $('#typ option:selected').val();
          if(typ>0) {
              $.get('/funkce/ajax2.php?karoserie='+typ+'&karoserie_s='+httpGetVars["karoserie"], function(data){
                  $('#karoserie').show().html(data); 
              });
          }

    }).change();

    $('#typ').change(function(e){
          var typ = $('#typ').val();
          if(typ>-1) {
              $.get('/funkce/ajax.php?vybava='+typ, function(data){
                  $('#vybava').show().html(data); 
              });
          } else {
              $('#vybava').hide();
          }

    }).change();
    
    
    $('#stav').change(function(e){
          var stav = $('#stav option:selected').val();
          if(stav>-1) {
              $.get('/funkce/ajax.php?stav='+stav, function(data){
                  $('#stav_sport').show().html(data); 
              });
          }

    }).change();
        
    
    $('#typ').change(function(e){
          var typ = $('#typ option:selected').val();
          if(typ>0) {
              $.get('/funkce/ajax2.php?typ='+typ+'&znacka='+httpGetVars["znacka"], function(data){
                  $('#znacky').show().html(data); 
              });
          }

    }).change();


    $('#znacky').change(function(e){
      var znacky = $('#znacky option:selected').val();
    
        if(znacky>0) {
          $.get('/funkce/ajax2.php?modely='+znacky, function(data){
            $('#modely').show().html(data);
            });
        }
    });
    
    
    
    if (httpGetVars["znacka"] != "")
    {  
        $.get('/funkce/ajax2.php?modely='+httpGetVars["znacka"]+"&model="+httpGetVars["model"], function(data){
            $('#modely').show().html(data);
            });
            
     
    }
    
    
     

    $('#kraj').change(function(e){
          var kraj = $('#kraj option:selected').val();
          if(kraj>0) {
              $.get('/funkce/ajax2.php?kraj='+kraj, function(data){
                  $('#okres').show().html(data); 
              });
          }

    }).change();

    $('#krajprodejce').change(function(e){
          var kraj = $('#krajprodejce option:selected').val();
          if(kraj>0) {
              $.get('/funkce/ajax2.php?kraj='+kraj, function(data){
                  $('#okresprodejce').show().html(data); 
              });
          }

    });

    $('#krajregistrace').change(function(e){
          var kraj = $('#krajregistrace option:selected').val();
          if(kraj>0) {
              $.get('/funkce/ajax2.php?kraj='+kraj, function(data){
                  $('#okresregistrace').show().html(data); 
              });
          }

    }).change();

});


var pole = window.location.search.substr(1).split("&"); 
	// location.search je ta zajímavava cast adresy za otaznikem, 
	// substr(1) odebere nulty znak (otaznik), split("&") to rozseká podle &

var httpGetVars = new Array(); 
for(i = 0; i < pole.length; i++){
	httpGetVars[pole[i].split("=")[0]] = unescape(pole[i].split("=")[1]); 
		// v pole[i] je treba jidlo=ryby, rozsekam to splitem podle rovnitka. 
		// Poli httpGetVars do [indexu] pridam to, co je pred rovnitkem [0], do hodnoty to, co je za rovnitkem [1]
		// takze pak treba httpGetVars["jidlo"] = "ryby"
		// unescape pochopi znaky procent
}

var httpGet = new Array(); 
for(i = 0; i < pole.length; i++){
	httpGetVars[pole[i].split("/i")[0]] = unescape(pole[i].split("/i")[1]); 
}

function new_image()
{
	var div1 = document.createElement('div');

	div1.innerHTML = document.getElementById('newimagetpl').innerHTML;

	//var test1 = document.getElementById('newimagetpl').getElementsByTagName('table')[0];

	document.getElementById('newimage').appendChild(div1);

}

function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

function zobrazSkryj(idecko){
el=document.getElementById(idecko).style;
el.display=(el.display == 'block')?'none':'block';
}