/********************************* AJAX - ZAKLAD ******************************/
function vytvorXMLHttpRequest2(handler) {
  if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (error) {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}
/****************************** KONEC AJAX - ZAKLAD ***************************/

/***************************** V PREHLEDU PRODUKTU ****************************/
function regenerate_atributes(id_zbozi, rozmery) {
  var xmlHttp = vytvorXMLHttpRequest2();

  xmlHttp.onreadystatechange = function () {
    vrat_generovane_atributy(id_zbozi);
  };
  xmlHttp.open('GET','exec/ajax-regenerare-atributes.php?id_zbozi='+id_zbozi+'&rozmery='+rozmery, true);
  xmlHttp.send(null);
}

function vrat_generovane_atributy(id_zbozi) {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      document.getElementById('td_'+id_zbozi).innerHTML = xmlHttp.responseText;
    } else {
      alert('UNCRIPTED ERROR 0x458');
    }
  }
}

//funkce pro select, zmena
function zasli_pozadavek_na_zmenu(id_zbozi) {
  var sel = document.getElementById('select_'+id_zbozi);
  
  var vybrany_rozmer = sel.options[sel.selectedIndex].value;
  regenerate_atributes(id_zbozi, vybrany_rozmer);
}


/***************************** V DETAILU PRODUKTU *****************************/
function regenerate_atributes_detail(id_zbozi, rozmery) {
  var xmlHttp2 = vytvorXMLHttpRequest2();

  xmlHttp.onreadystatechange = function () {
    vrat_generovane_atributy_detail(id_zbozi);
  };
  xmlHttp.open('GET','exec/ajax-vrat-obrazek.php?soubor='+id_zbozi, true);
  xmlHttp.send(null);
}

function zmen_nahled_obrazku(soubor) {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      //location.href= 'mailto:' + xmlHttp.responseText;
      //document.write('mailto:' + xmlHttp.responseText);
      document.getElementById('img_to_show').innerHTML = xmlHttp.responseText;
    } else {
      alert('UNCRIPTED ERROR 0x458');
    }
  }
}

//funkce pro select, zmena
function zasli_pozadavek_na_zmenu_detail(soubor) {
  regenerate_atributes_detail(soubor);
}



function zmen_obrazek(soubor) {
  document.getElementById('img_to_show').innerHTML = '<img src="' + soubor+ '" alt="" title="" class="inzerat_detail_foto_stredni" />';
}
