function rozbalZabal(ref, obj, refid) {
  if(refid) {
    ref=$(refid);
  }
  if($(obj).style.display=="none") {
    Effect.BlindDown(obj);
    ref.innerHTML = 'Skrýt kompletní kalkulaci'
  } else {
    Effect.BlindUp(obj);
    ref.innerHTML = 'Zobrazit kompletní kalkulaci'
  }
}

function zaskrknout(co) {
  for(i=0; i<co.length; i++ ) {
    try{
      if (document.getElementById(co[i]).checked == true) {
        document.getElementById(co[i]).checked = false;
      } else {
        document.getElementById(co[i]).checked = true;
      }
    } catch(e) {}
  }
  return false;
}


function calcIt(iscount, numreq) {	
 	var chyba = 'Nebyl zvolen počet osob \n';
 	for(i=0; i<iscount.length; i++ ) {
    prvek = document.getElementById(iscount[i]);
    if(prvek.value > 0) {
      chyba = false;
    }
  }
  
  
  for(i=0; i<numreq.length; i++ ) {
 	  prvek = document.getElementById(numreq[i]);
    if(prvek.value <= 0 || prvek.value == '-') {
      if(chyba == false) {
        chyba = 'Musíte vybrat způsob dopravy a tím i cenu pobytu \n';
      } else {
        chyba = chyba + 'Musíte vybrat způsob dopravy a tím i cenu pobytu \n';
      }
    }
  }
 	
 	if(chyba == false) {
    ajaxpaste(); 
  } else {
    alert(chyba);
  }
 	
  return false;
}


function ajaxpaste() {
  hideFlsh();
  var arrayPageSize = getPgSize();
  $('calcoverlay').style.width = arrayPageSize[0]+'px';
  $('calcoverlay').style.height = arrayPageSize[1]+'px';
  var arrayPageScroll = getPgScroll();
	$('calcoverlayInner').style.paddingTop = (arrayPageScroll[1] + (arrayPageSize[3] / 2) - 40)+'px';
  $('calcoverlay').style.display = 'block';	
  
  
  //console.log($('rezervacniFormId'));
  
  new Ajax.Request('/kalkulace/'+idterminu+'/',
  {
    method:'post',
    parameters: $('rezervacniFormId').serialize(true),
    onSuccess: function(transport){
      var response = transport.responseText || "Nastala chyba při zpracování Vašeho požadavku.";
      $('vypocet').innerHTML = response;
      $('calcoverlay').style.display = 'none';
      showFlsh();
      
    },
    onFailure: function(){ 
      var response = "Nastala chyba při zpracování Vašeho požadavku.";
      $('vypocet').innerHTML = response;
      $('calcoverlay').style.display = 'none';
      showFlsh();
     }
  });
}


function showFlsh(){
  	var flashObjects = document.getElementsByTagName("object");
  	for (i = 0; i < flashObjects.length; i++) {
  		flashObjects[i].style.visibility = "visible";
  	}
  	var flashEmbeds = document.getElementsByTagName("embed");
  	for (i = 0; i < flashEmbeds.length; i++) {
  		flashEmbeds[i].style.visibility = "visible";
  	}
}

function hideFlsh(){
  	var flashObjects = document.getElementsByTagName("object");
  	for (i = 0; i < flashObjects.length; i++) {
  		flashObjects[i].style.visibility = "hidden";
  	}
  
  	var flashEmbeds = document.getElementsByTagName("embed");
  	for (i = 0; i < flashEmbeds.length; i++) {
  		flashEmbeds[i].style.visibility = "hidden";
  	}
}


function getPgScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}


function getPgSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}





