function rand ( n )

{

  return ( Math.floor ( Math.random ( ) * n + 1 ) );

}

var http_request = false;

   function makePOSTRequest(url, parameters) {

      http_request = false;

      if (window.XMLHttpRequest) { // Mozilla, Safari,...

         http_request = new XMLHttpRequest();

         if (http_request.overrideMimeType) {

         	// set type accordingly to anticipated content type

            //http_request.overrideMimeType('text/xml');

            http_request.overrideMimeType('text/html');

         }

      } else if (window.ActiveXObject) { // IE

         try {

            http_request = new ActiveXObject("Msxml2.XMLHTTP");

         } catch (e) {

            try {

               http_request = new ActiveXObject("Microsoft.XMLHTTP");

            } catch (e) {}

         }

      }

      if (!http_request) {

         alert('Cannot create XMLHTTP instance');

         return false;

      }



      url=url+"&amp;time="+rand(1000);

      http_request.onreadystatechange = alertContents;

      http_request.open('POST', url, true);

      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

      http_request.setRequestHeader("Content-length", parameters.length);

      http_request.setRequestHeader("Connection", "close");

      http_request.send(parameters);

   }



   function alertContents() {

      if (http_request.readyState == 4) {

         if (http_request.status == 200) {

            //alert(http_request.responseText);

            result = http_request.responseText;

            document.getElementById('cena').innerHTML = result;            

         } else {

            alert('There was a problem with the request.');

         }

      }

   }



function get_voucher(obj) {

   	  if(document.getElementById("name").value == 0) alert("Nezadali jste jmeno!");

	  else {

	  	  var poststr = "name=" + encodeURI( document.getElementById("name").value ) +

		  				"&tel=" + encodeURI( document.getElementById("tel").value ) +

		  				"&osoby=" + encodeURI( document.getElementById("osoby").value ) +

						"&email=" + encodeURI( document.getElementById("email").value ) +

						"&od=" + encodeURI( document.getElementById("od").value ) +

						"&do=" + encodeURI( document.getElementById("do").value ) +

						"&jed_poc=" + encodeURI( document.getElementById("jed_poc").value ) +

						"&dve_poc=" + encodeURI( document.getElementById("dve_poc").value ) +

						"&apartmanpoc=" + encodeURI( document.getElementById("apartmanpoc").value ) +

						"&indpohosteni=" + encodeURI( document.getElementById("indpohosteni").value ) +

					/*	"&golf=" + encodeURI( document.getElementById("golf").value ) +

						"&balon=" + encodeURI( document.getElementById("balon").value ) +

						"&motokary=" + encodeURI( document.getElementById("motokary").value ) +

						"&4koly=" + encodeURI( document.getElementById("4koly").value ) +

						"&strelba=" + encodeURI( document.getElementById("strelba").value ) +

						"&kun=" + encodeURI( document.getElementById("kun").value ) +

						"&kolo=" + encodeURI( document.getElementById("kolo").value ) +

						"&sauna=" + encodeURI( document.getElementById("sauna").value ) +

						"&fitness=" + encodeURI( document.getElementById("fitness").value ) +

						"&masaze=" + encodeURI( document.getElementById("masaze").value ) +*/

						"&text=" + encodeURI( document.getElementById("text").value );

		  if(document.voucher.jed.checked  == true) poststr += "&jed=1";

		  	else poststr += "&jed=0";

		  if(document.voucher.dve.checked  == true) poststr += "&dve=1";

		  	else poststr += "&dve=0";

		  if(document.voucher.apartman.checked  == true) poststr += "&apartman=1";

		  	else poststr += "&apartman=0";

		  for (i=0;i<document.voucher.pohosteni.length;i++){

			if (document.voucher.pohosteni[i].checked==true)

			poststr += "&pohosteni=" + encodeURI( document.voucher.pohosteni[i].value );

		  }

		  if(document.voucher.golf.checked  == true) poststr += "&golf=1";

		  	else poststr += "&golf=0";

		  if(document.voucher.balon.checked  == true) poststr += "&balon=1";

		  	else poststr += "&balon=0";

		  if(document.voucher.motokary.checked  == true) poststr += "&motokary=1";

		  	else poststr += "&motokary=0";

		  if(document.voucher.koly.checked  == true) poststr += "&koly=1";

		  	else poststr += "&koly=0";

		  if(document.voucher.strelba.checked  == true) poststr += "&strelba=1";

		  	else poststr += "&strelba=0";

		  if(document.voucher.kun.checked  == true) poststr += "&kun=1";

		  	else poststr += "&kun=0";

		  if(document.voucher.kolo.checked  == true) poststr += "&kolo=1";

		  	else poststr += "&kolo=0";

		  if(document.voucher.sauna.checked  == true) poststr += "&sauna=1";

		  	else poststr += "&sauna=0";

		  if(document.voucher.fitness.checked  == true) poststr += "&fitness=1";

		  	else poststr += "&fitness=0";

		  if(document.voucher.masaze.checked  == true) poststr += "&masaze=1";

		  	else poststr += "&masaze=0";

		  makePOSTRequest('email.php?action=voucher', poststr);

	  }

   }

   

function get_voucher_mail(obj) {

   	  if(document.getElementById("name").value == 0) alert("Nezadali jste jmeno!");

	  else {

	  	  var poststr = "name=" + encodeURI( document.getElementById("name").value ) +

		  				"&tel=" + encodeURI( document.getElementById("tel").value ) +

		  				"&osoby=" + encodeURI( document.getElementById("osoby").value ) +

						"&email=" + encodeURI( document.getElementById("email").value ) +

						"&od=" + encodeURI( document.getElementById("od").value ) +

						"&do=" + encodeURI( document.getElementById("do").value ) +

						"&jed_poc=" + encodeURI( document.getElementById("jed_poc").value ) +

						"&dve_poc=" + encodeURI( document.getElementById("dve_poc").value ) +

						"&apartmanpoc=" + encodeURI( document.getElementById("apartmanpoc").value ) +

						"&indpohosteni=" + encodeURI( document.getElementById("indpohosteni").value ) +

					/*	"&golf=" + encodeURI( document.getElementById("golf").value ) +

						"&balon=" + encodeURI( document.getElementById("balon").value ) +

						"&motokary=" + encodeURI( document.getElementById("motokary").value ) +

						"&4koly=" + encodeURI( document.getElementById("4koly").value ) +

						"&strelba=" + encodeURI( document.getElementById("strelba").value ) +

						"&kun=" + encodeURI( document.getElementById("kun").value ) +

						"&kolo=" + encodeURI( document.getElementById("kolo").value ) +

						"&sauna=" + encodeURI( document.getElementById("sauna").value ) +

						"&fitness=" + encodeURI( document.getElementById("fitness").value ) +

						"&masaze=" + encodeURI( document.getElementById("masaze").value ) +*/

						"&text=" + encodeURI( document.getElementById("text").value );

		  if(document.voucher.jed.checked  == true) poststr += "&jed=1";

		  	else poststr += "&jed=0";

		  if(document.voucher.dve.checked  == true) poststr += "&dve=1";

		  	else poststr += "&dve=0";

		  if(document.voucher.apartman.checked  == true) poststr += "&apartman=1";

		  	else poststr += "&apartman=0";

		  for (i=0;i<document.voucher.pohosteni.length;i++){

			if (document.voucher.pohosteni[i].checked==true)

			poststr += "&pohosteni=" + encodeURI( document.voucher.pohosteni[i].value );

		  }

		  if(document.voucher.golf.checked  == true) poststr += "&golf=1";

		  	else poststr += "&golf=0";

		  if(document.voucher.balon.checked  == true) poststr += "&balon=1";

		  	else poststr += "&balon=0";

		  if(document.voucher.motokary.checked  == true) poststr += "&motokary=1";

		  	else poststr += "&motokary=0";

		  if(document.voucher.koly.checked  == true) poststr += "&koly=1";

		  	else poststr += "&koly=0";

		  if(document.voucher.strelba.checked  == true) poststr += "&strelba=1";

		  	else poststr += "&strelba=0";

		  if(document.voucher.kun.checked  == true) poststr += "&kun=1";

		  	else poststr += "&kun=0";

		  if(document.voucher.kolo.checked  == true) poststr += "&kolo=1";

		  	else poststr += "&kolo=0";

		  if(document.voucher.sauna.checked  == true) poststr += "&sauna=1";

		  	else poststr += "&sauna=0";

		  if(document.voucher.fitness.checked  == true) poststr += "&fitness=1";

		  	else poststr += "&fitness=0";

		  if(document.voucher.masaze.checked  == true) poststr += "&masaze=1";

		  	else poststr += "&masaze=0";

		  makePOSTRequest('email.php?action=voucher_mail', poststr);

	  }

   }
