function create_hidden() {
  var tab=document.getElementById('nocform2');
  newHidden = document.createElement('INPUT');
  newHidden.setAttribute('type','hidden');
  newHidden.setAttribute('name','pokracovat');
  newHidden.setAttribute('value','ne');
  tab.appendChild(newHidden);
}

function preload_images() 
  {
    img = new Image();
    img.src = "images/menu/cz-activ.jpg";
    img2 = new Image();
    img2.src = "images/menu/de-activ.jpg";
    img3 = new Image();
    img3.src = "images/menu/en-activ.jpg";
  }
  
function image_new_window(src,alt,width,height) {

  var scbr = 'no';
  var w = width;
  var h = height;

  if (width>=(document.body.clientWidth-20)) {
	w = document.body.clientWidth-20;
	scbr = 'yes';
  }

  if (height>=(document.body.clientHeight-20)) {
	h = document.body.clientHeight-20;
        if (w<(document.body.clientWidth-20)) w = w-0+16;
	scbr = 'yes';
  }

  image = window.open('','','left=10,top=10,toolbar=no,width='+w+',height='+h+',resizable=no,scrollbars='+scbr+',status=no,menubar=no,dialog=yes');
  image.focus();
  image.document.write('<html><head><title>HOTEL ADAM Hradec Králové</title></head><body style="cursor: hand; cursor: pointer; margin: 0px; padding: 0px; background: url(\'images/engine/loading.jpg\') center center no-repeat #ffffff;"><img id="img" src="'+src+'" width="'+width+'" height="'+height+'" alt="'+alt+'" border="0" onClick="window.close();"></body></html>');
  image.document.close();
  
}

function Open_page(source,width,height) {

  page = window.open(source,'','left=100, top=100, toolbar=no, width='+width+', height='+height+', resizable=no, scrollbars=no, status=no');
  page.focus();
  page.document.close();
}

function Open_page_bars(source,width,height) {

  page = window.open(source,'','left=70, top=70, toolbar=no, width='+width+', height='+height+', resizable=no, scrollbars=yes, status=no');
  page.focus();
  page.document.close();
}

function scroluj() {
  window.scrollTo(0,640);
}

function scroluj2() {
  window.scrollTo(0,655);
}

function createRequestObject(){
	if (window.XMLHttpRequest) {
   http_request = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (eror) {
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
 }
	return http_request;
}

/*function createRequestObject(){
	var request_o;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
		
	}else{
		request_o = new XMLHttpRequest();
	}
	if (request_o == '') {
            alert('Nastala chyba. Zkuste operaci znovu.');
            return false;
        }
  else
	return request_o;
}*/


function makemyselect(month,year,day,typ_pokoje,i){
  var promena1 = month;
  var promena2 = year;
  var promena3 = day;
  var promena4 = typ_pokoje;
  var promena8 = i;
  var http_request = false;
  
  http_request = createRequestObject(); 
  
  if (!http_request) 
  {
    alert('Nastala chyba. Zkuste operaci znovu.');
  }
  
	http_request.onreadystatechange = function() { vhandleansw(http_request); };
	//http_request.open('get', 'write.php?komodita=' + hkomodita + '&selected=' + selected);
	http_request.open('get', 'http://localhost/b-w/hoteladam/write.php?month='+month+'&year='+year+'&day='+day+'&typ_pokoje='+typ_pokoje);
	http_request.send(null);
  
  //var hkomodita=document.getElementById('komodita').value;
  var vypis;
  vypis = '<a class="jedenodkaz" href="javascript:unmakemyselect(' + promena1 + ',' + promena2 + ',' + promena3 + ',' + promena4 + ',' + promena8 + ');">&nbsp;</a>';
  //alert(vypis);
	document.getElementById(i).className = 'tabulka-objednavky-zelena';
	document.getElementById(i).innerHTML = vypis;
  
	
  
}

function unmakemyselect(month,year,day,typ_pokoje,i){
  var promena1 = month;
  var promena2 = year;
  var promena3 = day;
  var promena4 = typ_pokoje;
  var promena8 = i;
  var http_request = false;
  
  http_request = createRequestObject(); 
  
  if (!http_request) 
  {
    alert('Nastala chyba. Zkuste operaci znovu.');
  }
  
	http_request.onreadystatechange = function() { vhandleansw(http_request); };
	//http_request.open('get', 'write.php?komodita=' + hkomodita + '&selected=' + selected);
	http_request.open('get', 'http://localhost/b-w/hoteladam/delete.php?month='+month+'&year='+year+'&day='+day+'&typ_pokoje='+typ_pokoje);
	http_request.send(null);
  
  //var hkomodita=document.getElementById('komodita').value;
  var vypis;
  vypis = '<a class="jedenodkaz" href="javascript:makemyselect(' + promena1 + ',' + promena2 + ',' + promena3 + ',' + promena4 + ',' + promena8 + ');">&nbsp;</a>';
	document.getElementById(i).className = 'tabulka-objednavky-anchor';
	document.getElementById(i).innerHTML= vypis;
  
  
}

function get_price(){

  var http_request = false;
  
  http_request = createRequestObject(); 
  
	http_request.onreadystatechange = function() { vhandleansw_price(http_request); };
	http_request.open('get', 'http://localhost/b-w/hoteladam/price.php');
	http_request.send(null);
  
  //document.getElementById('celkovacena3').innerHTML = 'čekejte';
  
  
  
}

function show_cont(){
  var http_request = false;
  http_request = createRequestObject(); 
	http_request.onreadystatechange = function() { vhandleansw_show(http_request); };
	http_request.open('get', 'http://localhost/b-w/hoteladam/show.php');
	http_request.send(null);
}

function vhandleansw(http_request){
	if(http_request.readyState == 4){
		var response = http_request.responseText;
  		  //document.getElementById('celkovacena3').innerHTML=response;
  		  get_price();
	}
}

function vhandleansw_price(http_request){
	if(http_request.readyState == 4)
  {
		var response = http_request.responseText;
    document.getElementById('celkovacena3').innerHTML=response;
    show_cont();
	}
}

function vhandleansw_show(http_request){
	if(http_request.readyState == 4)
  {
		var response = http_request.responseText;
    document.getElementById('pokracovat').innerHTML=response;
	}
}






/*  vytvoření proměnných hidden do formuláře pro příjezd a odjezd  */

function create_vars() {

  var check_in = document.getElementById('check_in_check_out').data1.value;
  var check_out = document.getElementById('check_in_check_out').data2.value;
  
  var day = check_in.substring(0,2);
  var month = check_in.substring(3,5);
  var year = check_in.substring(6,10);
  
  var daya = check_out.substring(0,2);
  var montha = check_out.substring(3,5);
  var yeara = check_out.substring(6,10);
  
  var tab=document.getElementById('check_in_check_out');
  
  day_hidden = document.createElement('INPUT');
  day_hidden.setAttribute('type','hidden');
  day_hidden.setAttribute('name','day');
  day_hidden.setAttribute('value',day);
  tab.appendChild(day_hidden);
  
  month_hidden = document.createElement('INPUT');
  month_hidden.setAttribute('type','hidden');
  month_hidden.setAttribute('name','month');
  month_hidden.setAttribute('value',month);
  tab.appendChild(month_hidden);
  
  year_hidden = document.createElement('INPUT');
  year_hidden.setAttribute('type','hidden');
  year_hidden.setAttribute('name','year');
  year_hidden.setAttribute('value',year);
  tab.appendChild(year_hidden);
  
  daya_hidden = document.createElement('INPUT');
  daya_hidden.setAttribute('type','hidden');
  daya_hidden.setAttribute('name','daya');
  daya_hidden.setAttribute('value',daya);
  tab.appendChild(daya_hidden);
  
  montha_hidden = document.createElement('INPUT');
  montha_hidden.setAttribute('type','hidden');
  montha_hidden.setAttribute('name','montha');
  montha_hidden.setAttribute('value',montha);
  tab.appendChild(montha_hidden);
  
  yeara_hidden = document.createElement('INPUT');
  yeara_hidden.setAttribute('type','hidden');
  yeara_hidden.setAttribute('name','yeara');
  yeara_hidden.setAttribute('value',yeara);
  tab.appendChild(yeara_hidden);
}