﻿function selTours() {
  vtt = document.getElementById("tt").value;
  vtdst = document.getElementById("reg").value;
  vrats = document.getElementById("rats").value;
  vln = document.getElementById("ln").value;
  vpers = document.getElementById("pers").value;
  vinter = document.getElementById("inter").value;
  var link = FX_WEBROOT + "/fx/" + lang + "/tourlist";
  if (vtt!="") link += "/tt-" + vtt;
  if (vrats!="") link += "/rats-" + vrats;
  if (vtdst!="") link += "/reg-" + vtdst;
  if (vln!="") link += "/ln-" + vln;
  if (vpers!="") link += "/pers-" + vpers;
  if (vinter!="") link += "/inter-" + vinter;
  link += "/tourlist.html";

  location.href = link;
}

function setAcDst(dst) {
	document.getElementById("acdst").value = dst;
	selAcc();
}


function selAttraction() {
  vat = document.getElementById("sTAttractions").value;
  var link = FX_WEBROOT + "/fx/" + lang + "/attractionlist/at-" + vat;
  location.href = link;
}

function selAcc() {
  vac = document.getElementById("ac").value;
  vacpc = document.getElementById("acpc").value;
  /*vst = document.getElementById("st").value;*/
  vacdst = document.getElementById("acdst").value;
  /*vacstyle = document.getElementById("acstyle").value;*/
  vacuisine = document.getElementById("acuisine").value;
  
  var link = FX_WEBROOT + "/fx/" + lang + "/accomodationlist/ac-" + vac + "/pc-" + vacpc + "/acdst-" + vacdst + "/acuisine-" + vacuisine;
  location.href = link;
}

function gallery(id) {
   var tit = document.getElementById("picgallery_" + id);
   var dv = document.getElementById("gal_" + id);
   if (dv) {
      if (dv.style.display == 'none') {
      	   dv.style.display = "block";
      	   tit.innerHTML = tit.getAttribute("close");
   } else {
      	   dv.style.display = "none";
      	   tit.innerHTML = tit.getAttribute("open");
   }

   if (dv.getAttribute('fst')=='1') {
    	   dv.style.display = "block";
    	   tit.innerHTML = tit.getAttribute("close");
     	   dv.setAttribute('fst','0');
   }	


 }
}

function changemainim(nim,tit) {
 var elm = document.getElementById("accmainim");
 if (elm) {
    var link = FX_WEBROOT + "/scripts/thumbnail.php?w=450&h=340&mode=0&down=1&img=" + nim
    elm.src = link;
    elm.alt = tit;
    elm.title = tit;
 }
} 
	

function urlize(str) {
  //to lowercase
  str = str.toLowerCase();
  
  //replace czech characters (more can be added)
  str = str_replace("ě","e",str);
  str = str_replace("š","s",str);
  str = str_replace("č","c",str);
  str = str_replace("ř","r",str);
  str = str_replace("ž","z",str);
  str = str_replace("ý","y",str);
  str = str_replace("á","a",str);
  str = str_replace("í","i",str);
  str = str_replace("é","e",str);
  str = str_replace("ú","u",str);
  str = str_replace("ů","u",str);
  str = str_replace("ó","o",str);
  str = str_replace("ď","d",str);
  str = str_replace("ť","t",str);
  str = str_replace("ň","n",str);
  
  
  //special chars replacement
  str = str_replace("<br>","_",str);
  str = str_replace(" ","_",str);
  str = str_replace("&","_",str);
  str = str_replace(",","_",str);
  str = str_replace("-","_",str);

  str = str_replace("__","_",str);
  
   
   //get rid of non ASCII chars
   var ret = "";
   var i;
   for (i=0;i<=str.length-1;i++){
		
		n = str.charCodeAt(i);
		if ((n>47 && n<58) ||  (n>64 && n<91) || (n>96 && n<123) || n == 95) ret+=str.charAt(i);
		else ret+="_";

   }
   str = ret;

  str = str_replace("__","_",str);
  str = str_replace("__","_",str);
  str = str_replace("__","_",str);
  str = str_replace("__","_",str);
  str = str_replace("__","_",str);

  
  str = trim(str);
  if (str == "_") str = "";
  return str;
}


/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ FUNCTIONS FOR ADVANCED EDITING FEATURES IN LIST MODE
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

function lc_oc(elm)
{		
	var myQS = location.href;
	myQS = setURLParm(myQS,"sfx", base64Encode(elm.getAttribute("sortfield")));
	myQS = setURLParm(myQS,"smx", base64Encode(elm.getAttribute("sortmethod")));
	location.href = myQS;
}

function setURLParm(qs,key,val)
{ 
	
//	key = key.replace("=","%3D");
//	key = key.replace("=","");
	qs = qs.replace("php#","php");
	var keypos = qs.indexOf("&" + key);
	if (keypos == -1) keypos = qs.indexOf("?" + key);
	if (keypos == -1) {
		fkeypos = qs.indexOf("#");
		if (fkeypos == -1) {
		   if (qs.indexOf("?") == -1) return (qs + "?" + key + "=" + escape(val));
		   else return (qs + "&" + key + "=" + val);
		} else {
		   if (qs.indexOf("?") == -1) return (qs.substr(0,fkeypos) + "?" + key + "=" + escape(val) + qs.substr(fkeypos));
		   else return (qs.substr(0,fkeypos) + "&" + key + "=" + val + qs.substr(fkeypos));
		   
		}
	}
	else {
		var keypos2 = qs.indexOf("&", keypos + 1);
		if (keypos2 == -1) return (qs.substr(0, keypos + 1) + key + "=" + escape(val));
		else return (qs.substr(0, keypos + 1) + key + "=" + val + qs.substr(keypos2));
	}

}

/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ END
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

function checkUID(fm) {
	var extra = "";
	purpose = fm.getAttribute('purpose');
        if (purpose = "referer") {
           extra = "&purpose=referer";
        }
	
	
 	var link = FX_WEBROOT + "/index.php/public/ws.php?method=checkUID&uid=" + fm.value + extra + "&rnd="+Math.random();
	var xmlhttp = Sarissa.getXmlHttpRequest();
	xmlhttp.open("GET", link, false);
	xmlhttp.send(null);

	var xmldoc = Sarissa.getDomDocument();
	xmldoc.loadXML(xmlhttp.responseXML.xml);
	var rootNode = xmldoc.getElementsByTagName("uid")[0];
	var ret = rootNode.getAttribute("exist");

	if (ret == "YES") {
		alert(fm.getAttribute('msg'));
 	        fm.setAttribute('valid','no');
	} else {
	      fm.setAttribute('valid','yes');
	}
	

}

function checkPWD(fm) {
   if (fm.value.length > 4) {
      fm.setAttribute('valid','yes');
   } else {
     alert(fm.getAttribute('msg'));
     fm.setAttribute('valid','no');
   }
}

function regsubmit(frm) {
	ok = true;
	if (frm.reg_pwd.getAttribute('valid') != 'yes') {alert(frm.reg_pwd.getAttribute('msg')); ok=false;}
	if (frm.reg_uid.getAttribute('valid') != 'yes') {alert(frm.reg_uid.getAttribute('msg')); ok=false;}
	if (ok == true) frm.submit();
}

function toDate(str) {
	var aDate = str.split("-");
	aDate[1] = aDate[1] - 1;
	var ret = new Date(aDate[0],aDate[1],aDate[2]);
	return ret;
}

function toStrDate(dte) {
	var month = dte.getMonth() + 1;
	if (month < 10) month = "0" + month;
	var ret = dte.getFullYear() + "-" + month + "-" + dte.getDate();
	return ret;
}



function isFreeAccomodation(ac_id,res_from,res_to,res_persons,res_type){
	var link = FX_WEBROOT + "/index.php/public/ws.php?method=isFree&res_from="+res_from+"&res_to="+res_to+"&res_type="+res_type+"&ac_id=" + ac_id + "&res_persons="+res_persons+"rnd="+Math.random();
	var xmlhttp = Sarissa.getXmlHttpRequest();
	xmlhttp.open("GET", link, false);
	xmlhttp.send(null);
	//alert(xmlhttp.responseXML.xml);
	//alert(link);
	
	/* xml is DOM document */
	var xmldoc = Sarissa.getDomDocument();
	xmldoc.loadXML(xmlhttp.responseXML.xml);
	var rootNode = xmldoc.getElementsByTagName("reservationstatus")[0];
	var ret = parseInt(rootNode.getAttribute("free"));
	var rooms = parseInt(rootNode.getAttribute("rooms"));
	if (rooms == "0") return -1;
	
	if (ret > res_persons) return 1;
	else return 0;
}



function getReservations(tgobj,ac_id,res_from,res_to,res_type,res_id){
	var link = FX_WEBROOT + "/index.php/public/ws.php?method=getRes&res_from="+res_from+"&res_to="+res_to+"&res_type="+res_type+"&ac_id=" + ac_id + "&res_id=" + res_id + "&rnd="+Math.random();
	var xmlhttp = Sarissa.getXmlHttpRequest();
	xmlhttp.open("GET", link, false);
	xmlhttp.send(null);
	//alert(xmlhttp.responseXML.xml);
	//alert(link);
	
	/* xml is DOM document */
	var xmldoc = Sarissa.getDomDocument();
	xmldoc.loadXML(xmlhttp.responseXML.xml);

	tgobj.innerText="";

	
	/* prepare dates */		
	var one_day=1000*60*60*24
	var three_hours=1000*60*60*3

	var lastday = toDate(res_to);
	/*to be in middle of the day - posun hodin*/
	lastday.setTime(lastday.getTime() + three_hours);
	var firstday = toDate(res_from);
	if (firstday > lastday) return;
	var dates = Array();

	/* prepare rooms */
	var rootNode = xmldoc.getElementsByTagName("reservations")[0];
	var rooms = rootNode.selectNodes("rooms/room");

        rtable = document.createElement("table");
        tgobj.appendChild(rtable);


	/*table header */
	rtr = document.createElement("tr");
	rtr.setAttribute('id','header');
	rtable.appendChild(rtr);
	rtd = document.createElement('td');
	rtd.appendChild(document.createTextNode("pokoj (lůžek)"));
	brx = document.createElement("br");
	rtd.appendChild(brx);
	rtd.appendChild(document.createTextNode("rezervovat lůžek"));
	 
	rtr.appendChild(rtd);
	
	var days = 0;
	var curday = new Date();
	curday.setTime(firstday.getTime() + three_hours);
	while (curday <= lastday) {
		month = curday.getMonth() + 1;
		day = curday.getDate() + "." + month + "." + curday.getFullYear();
		curday.setTime(curday.getTime() + one_day);
		
		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(day));
		rtr.appendChild(rtd);
		days ++;
	}
	acOrder.days = days;

	var allrooms = Array();
	var fullrooms = Array();
	/* iterate all rows = rooms */
	for (var i=0; i<rooms.length; i++) {	
		
	 
		room_id = rooms[i].getAttribute("id");
		room_beds = rooms[i].getAttribute("beds");
		room_name = rooms[i].getAttribute("name");
		
		allrooms.push(room_id);

		rtr = document.createElement("tr");
		rtr.setAttribute('name','roomlist');
		rtr.setAttribute('capacity',room_beds);
		rtable.appendChild(rtr);

		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(' ' + room_name + ' ('+room_beds+')    '));
		rtd.setAttribute('class','rname');
		rtd.setAttribute('id','room' + room_id);

		rtr.appendChild(rtd);


		
		/* iterate all days */
		curday.setTime(firstday.getTime() + three_hours);
		while (curday <= lastday) {
			month = curday.getMonth() + 1;
			day = curday.getFullYear() + "-" + month + "-" + curday.getDate();
			curday.setTime(curday.getTime() + one_day);
			colid = room_id + "_" + day; 
			rtd = document.createElement('td');
			rtd.setAttribute('id',colid);

			inpd = document.createElement('div');
			inpd.setAttribute("class","freeRoom");
			inpd.style.cssText = "background-color:#00ff66; color:#00ff66;"; 
			inpd.appendChild(document.createTextNode("****"));
			inpd.setAttribute("title","Volno");
			inpd.setAttribute("alt","Volno");
			rtd.appendChild(inpd);			  

			rtr.appendChild(rtd);

		}
		
		
	}
	/* append info about price & persons */
	calc = document.createElement('div');
	calc.setAttribute('id','resresume');
	tgobj.appendChild(calc);
	

	/* now we have the table, fill with reservations */
	var ress = rootNode.selectNodes("reservation");
	for (var i=0; i<ress.length; i++) {	
	  xres_id = ress[i].getAttribute("id");
	  xres_from = ress[i].getAttribute("from");
	  xres_to = ress[i].getAttribute("to");
	  xres_room_id = ress[i].getAttribute("room_id");
	  xres_desc = ress[i].getAttribute("desc");
	  xres_status = ress[i].getAttribute("status");

	  fullrooms.push(xres_room_id);
	
	  /* go for all days and search for ids*/
	  var lastday = toDate(xres_to);
	  lastday.setTime(lastday.getTime() + three_hours);
	  var firstday = toDate(xres_from);
	  curday.setTime(firstday.getTime() + three_hours);
	  while (curday <= lastday) {
	  	month = curday.getMonth() + 1;
		day = curday.getFullYear() + "-" + month + "-" + curday.getDate();
		curday.setTime(curday.getTime() + one_day);
		colid = xres_room_id + "_" + day; 

		/* colid has this reservation */
		var coll = document.getElementById(colid);
		if (coll) {
			//coll.setAttribute('class','resfull');
			//coll.className = 'resfull';

			inpd = coll.firstChild;
			if (xres_status == "prijata") color = "#ff6666";
			if (xres_status == "potvrzena") color = "#cc0000";
			
			inpd.style.cssText = " background-color:"+color+"; color:"+color+";"; 
			inpd.appendChild(document.createTextNode("****"));
			inpd.setAttribute("title",xres_desc);
			inpd.setAttribute("alt",xres_desc);

		}
		
		}
		
	} 

	  /* append checkboxes to available rooms*/
	  /* allrooms : all, fullrooms: full */
         for (var ii=0; ii<allrooms.length; ii++) {
         	full = false;
         	for (var j=0; j<fullrooms.length; j++) {if (allrooms[ii]==fullrooms[j]) full = true;}
         	if (!full) {
         		
         		var elm = document.getElementById('room' + allrooms[ii]);
         		if (elm) {
         		  /* elm is TD with name, create checkbox here */
         		  brx = document.createElement("br");
			  elm.appendChild(brx);

         		  inp = document.createElement('input');
			  inp.setAttribute('purpose','roomboxes');
			  inp.setAttribute('id','room_'+allrooms[ii]);
			  inp.setAttribute('type','text');
			  inp.setAttribute('class','reserveinput');
			  inp.setAttribute('size','2');
			  inp.setAttribute('onchange','checkRoom(this);');
			  
			  var xroom = rootNode.selectNodes("rooms/room[@id="+allrooms[ii]+"]");
			  if (xroom.length > 0) {
			  	inp.setAttribute('beds',xroom[0].getAttribute('beds'));
			  	inp.setAttribute('prices',xroom[0].getAttribute('prices'));
			  	inp.setAttribute('desc',xroom[0].getAttribute('name'));
			  	
			   }
			  
			  elm.appendChild(inp);
         		}
         	}
         }
		
	/* retrieve and set DIV*/
	if (_SARISSA_IS_IE) {
		cont = tgobj.innerHTML;
		tgobj.innerText="";
        	tgobj.insertAdjacentHTML("AfterBegin",cont);
        }

        

	
}


function getReservationsList(tgobj,ac_id,res_from,res_to,res_type,res_id){
	var link = FX_WEBROOT + "/index.php/public/ws.php?method=getRes&res_from="+res_from+"&res_to="+res_to+"&res_type="+res_type+"&ac_id=" + ac_id + "&res_id=" + res_id + "&rnd="+Math.random();
	var xmlhttp = Sarissa.getXmlHttpRequest();
	xmlhttp.open("GET", link, false);
	xmlhttp.send(null);
	//alert(xmlhttp.responseXML.xml);
	//alert(link);
	
	/* xml is DOM document */
	var xmldoc = Sarissa.getDomDocument();
	xmldoc.loadXML(xmlhttp.responseXML.xml);

	tgobj.innerText="";

	
	/* prepare dates */		
	var one_day=1000*60*60*24
	var three_hours=1000*60*60*3

	var lastday = toDate(res_to);
	/*to be in middle of the day - posun hodin*/
	lastday.setTime(lastday.getTime() + three_hours);
	var firstday = toDate(res_from);
	if (firstday > lastday) return;
	var dates = Array();

	/* prepare rooms */
	var rootNode = xmldoc.getElementsByTagName("reservations")[0];
	var rooms = rootNode.selectNodes("rooms/room");

        rtable = document.createElement("table");
        tgobj.appendChild(rtable);


	/*table header */
	rtr = document.createElement("tr");
	rtr.setAttribute('id','header');
	rtable.appendChild(rtr);
	rtd = document.createElement('td');
	rtd.appendChild(document.createTextNode("pokoj (lůžek)"));
	 
	rtr.appendChild(rtd);
	
	var days = 0;
	var curday = new Date();
	curday.setTime(firstday.getTime() + three_hours);
	while (curday <= lastday) {
		
		day = curday.getDate();
		if (day < 10) day = "0" + day;
		curday.setTime(curday.getTime() + one_day);
		
		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(day));
		rtr.appendChild(rtd);
		days ++;
	}
	acOrder.days = days;

	var allrooms = Array();
	var fullrooms = Array();
	/* iterate all rows = rooms */
	for (var i=0; i<rooms.length; i++) {	
		
	 
		room_id = rooms[i].getAttribute("id");
		room_beds = rooms[i].getAttribute("beds");
		room_name = rooms[i].getAttribute("name");
		
		allrooms.push(room_id);

		rtr = document.createElement("tr");
		rtr.setAttribute('name','roomlist');
		rtr.setAttribute('capacity',room_beds);
		rtable.appendChild(rtr);

		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(' ' + room_name + ' ('+room_beds+')    '));
		rtd.setAttribute('class','rname');
		rtd.setAttribute('id','room' + room_id);
		rtr.appendChild(rtd);


		
		/* iterate all days */
		curday.setTime(firstday.getTime() + three_hours);
		while (curday <= lastday) {
			month = curday.getMonth() + 1;
			day = curday.getFullYear() + "-" + month + "-" + curday.getDate();
			curday.setTime(curday.getTime() + one_day);
			colid = room_id + "_" + day; 
			rtd = document.createElement('td');
			rtd.setAttribute('id',colid);
			
			inpd = document.createElement('div');
			inpd.setAttribute("class","freeRoom");
			inpd.style.cssText = "cursor:hand; background-color:#00ff66; color:#00ff66;"; 
			inpd.appendChild(document.createTextNode("_"));
			inpd.setAttribute("title","Rezervovat");
			inpd.setAttribute("alt","Rezervovat");
			inpd.setAttribute("onClick","reserve('"+day+"','"+room_id+"')");

			rtd.appendChild(inpd);			  

			rtr.appendChild(rtd);

		}
		
		
	}
	/* append info about price & persons */
	calc = document.createElement('div');
	calc.setAttribute('id','resresume');
	tgobj.appendChild(calc);
	

	/* now we have the table, fill with reservations */
	var ress = rootNode.selectNodes("reservation");
	for (var i=0; i<ress.length; i++) {	
	  xres_id = ress[i].getAttribute("id");
	  xres_from = ress[i].getAttribute("from");
	  xres_to = ress[i].getAttribute("to");
	  xres_room_id = ress[i].getAttribute("room_id");
	  xres_desc = ress[i].getAttribute("desc");
	  xres_status = ress[i].getAttribute("status");

	  fullrooms.push(xres_room_id);
	
	  /* go for all days and search for ids*/
	  var lastday = toDate(xres_to);
	  lastday.setTime(lastday.getTime() + three_hours);
	  
	  var firstday = toDate(xres_from);
	  curday.setTime(firstday.getTime() + three_hours);
	  while (curday <= lastday) {
	  	month = curday.getMonth() + 1;
		day = curday.getFullYear() + "-" + month + "-" + curday.getDate();
		curday.setTime(curday.getTime() + one_day);
		colid = xres_room_id + "_" + day; 

		/* colid has this reservation */
		var coll = document.getElementById(colid);
		if (coll) {
			inpd = coll.firstChild;
			if (xres_status == "prijata") color = "#ff6666";
			if (xres_status == "potvrzena") color = "#cc0000";
			
			inpd.style.cssText = "cursor:hand; background-color:"+color+"; color:"+color+";"; 
			inpd.appendChild(document.createTextNode("_"));
			inpd.setAttribute("title",xres_desc);
			inpd.setAttribute("alt",xres_desc);
			inpd.setAttribute("onClick","reserve('"+day+"','"+room_id+"','"+xres_id+"')");
			
			
		}
		
		}
		
	} 

	//alert(tgobj.innerHTML);
		
	/* retrieve and set DIV*/
	if (_SARISSA_IS_IE) {
		cont = tgobj.innerHTML;
		tgobj.innerText="";
        	tgobj.insertAdjacentHTML("AfterBegin",cont);
        }

        

	
}


/* check validity of input value */
function checkRoom(inp) {
	max = inp.getAttribute('beds');
	
	if (inp.value != "") {
	val = parseInt(inp.value);
	num = true;
	if (val + 1 - 1 != val) num = false;
	if (val > max || !num) {
		alert("Hodnota je neplatna - není číslo, nebo je větší nez maximální počet lůžek.");
		inp.focus();
		return;
	}
	}
     countReservation();
} 

/* calculate price and number of persons */
function countReservation() {
		var price = 0;
		var persons = 0;
		acOrder.clearbasket();
		var days = acOrder.days;
		
	        var boxes = document.getElementsByTagName('input');
		for (var i=0; i<boxes.length; i++) {
  	  	    if (boxes[i].value!="" && boxes[i].getAttribute('purpose') == 'roomboxes') {
		  		/* input of reservation */
		  		roomid = boxes[i].getAttribute("id");
		  		roomids = roomid.split("_");
		  		
		  		room_id = roomids[1];
		  		room_prices = boxes[i].getAttribute('prices');
		  		room_persons = boxes[i].value;
		  		desc = boxes[i].getAttribute('desc') + ", osob: " + room_persons;
		  		tprice = priceOfRoom(room_prices,room_persons);
		  		persons += parseFloat(room_persons);
		  		
		  		acOrder.addtobasket(days,tprice,desc);
		  	}
		}
		
		acOrder.persons = persons;
		
		
		var prs = document.getElementById("resresume");
		if (prs) prs.innerHTML = acOrder.createHTMLform();
		
	
	
}

function priceOfRoom(prices,persons) {
	var ret = 0;
	var pricelist = prices.split("||");
	for (var i=0; i<pricelist.length; i++) {
	   var pItems = pricelist[i].split("|");
	   if (pItems[0] == persons) ret = pItems[1];
	   }
	return parseFloat(ret);

}



/* ORDER OF ACCOMODATION CLASS */
	function Order() {
   
   	this.days = 0;
   	this.persons = 0;
    	this.jmeno = "";
    	this.firma = "";
    	this.adresa_fakt = "";
    	this.adresa_dod = "";
    	this.ico = "";
    	this.dic = "";
    	this.tel = "";
    	this.email = "";
    	this.message = "";
    	this.ware = new Array();
    	} 
    	
    	Order.prototype.addtobasket = function (pieces, price, ware) {
    	
    		var nw = new Ware(pieces, price, ware);
    		this.ware[this.ware.length] = nw;
    	}
    	
    	Order.prototype.clearbasket = function (){
    		
    		for (var ci=0;ci< this.ware.length-1; ci++) this.ware[ci] = null;
    		this.ware = null;
    		this.ware = new Array();
    	}
	
	Order.prototype.countPrice = function (){
		var suma = 0;
		for (var ci=0;ci< this.ware.length; ci++)
    		{
    			suma += (this.ware[ci].pcs * this.ware[ci].price);
    		}
    		return suma;
			
    	}
    	
    	Order.prototype.createHTMLform = function (){

		var thisprice;
		ret = "<h4>SOUHRN</h4><table>";
		ret +="<tr><td class='light'>Pokoj</td><td class='light'>Cena/noc</td><td class='light'>Noci</td><td class='light'>Celkem</td></tr>";
		
		for (var ci=0;ci< this.ware.length; ci++)
    		{
    			
    			thisprice = this.ware[ci].pcs * this.ware[ci].price;
    			ret +="<tr><td class='light'>"+ this.ware[ci].ware +"</td><td class='light'>"+ this.ware[ci].price +"</td><td class='light'>"+ this.ware[ci].pcs +"</td><td class='light'>"+ thisprice +"</td></tr>";
    		}
    		
		ret += "<tr><td class='light'><b>Celkem</b></td><td class='light' colspan=3 align=right><b>"+ this.countPrice() +"</b></td></tr>";		
		ret += "</table>";
		return ret;
	}
	
	function Ware(pieces, price, ware){
	this.pcs = pieces;
	this.price = price;
	this.ware = ware;
	}

var acOrder = new Order();



/*SPORT FIELDS RESERVATIONS */
function getSportFieldReservations(tgobj,sf_id,day,sfres_id) {

	var link = FX_WEBROOT + "/index.php/public/ws.php?method=getSFRes&day="+day+"&sf_id=" + sf_id + "&sfres_id=" + sfres_id + "&rnd="+Math.random();
	var xmlhttp = Sarissa.getXmlHttpRequest();
	xmlhttp.open("GET", link, false);
	xmlhttp.send(null);
	//alert(xmlhttp.responseXML.xml);
	//alert(link);
	
	/* xml is DOM document */
	var xmldoc = Sarissa.getDomDocument();
	xmldoc.loadXML(xmlhttp.responseXML.xml);

	tgobj.innerText="";

	
	/* prepare sportfields */
	var rootNode = xmldoc.getElementsByTagName("reservations")[0];
	var sfplaces = rootNode.selectNodes("sfplaces/sfplace");
        rtable = document.createElement("table");
        tgobj.appendChild(rtable);


	/*table header */
	rtr = document.createElement("tr");
	rtr.setAttribute('id','header');
	rtable.appendChild(rtr);
	rtd = document.createElement('td');
	rtd.appendChild(document.createTextNode("Hřiště"));
	 
	rtr.appendChild(rtd);
	
	for (var i=0; i<24; i++) {
		j = i+1;
		title = i + ":00";
		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(title));
		rtr.appendChild(rtd);
	}

	var alltimes = Array();
	var fulltimes = Array();


	/* iterate all rows = sfplaces */
	for (var z=0; z<sfplaces.length; z++) {	
		

		sfp_id = sfplaces[z].getAttribute("id");
		sfp_name = sfplaces[z].getAttribute("name");

		rtr = document.createElement("tr");
		rtable.appendChild(rtr);

		rtd = document.createElement('td');
		rtd.appendChild(document.createTextNode(sfp_name));
		rtd.setAttribute('class','rname');
		rtd.setAttribute('id','sfplace' + sfp_id);
		rtr.appendChild(rtd);


		/* iterate all hours */
		for (var i=0; i<24; i++) {
		   j = i+1;
		   title = i + " - " + j;
		   rtd = document.createElement('td');
		   //rtd.appendChild(document.createTextNode(title));
		   colid = sfp_id + "_" + i;
		   alltimes.push(colid);
		   rtd.setAttribute('id',colid);
		   rtr.appendChild(rtd);
		}


		
		
	}

	/* now we have the table, fill with reservations */
	var ress = rootNode.selectNodes("reservation");
	for (var i=0; i<ress.length; i++) {	
	  xres_id = ress[i].getAttribute("id");
	  xres_desc = ress[i].getAttribute("desc");
	  xres_status = ress[i].getAttribute("status");
	  xres_data = ress[i].getAttribute("data");
          
          /* go for the data and set reserved fields*/
	  var resers = xres_data.split("||");
	  for (var rs=0; rs<resers.length; rs++) {
		 var tres = resers[rs].split("|");
		 sfplace_id = tres[0];
		 time = tres[1];
		 colid = sfplace_id + "_" + time; 
		 fulltimes.push(colid);
 		 var coll = document.getElementById(colid);
		 if (coll) {
			coll.appendChild(document.createTextNode(xres_desc));
			coll.setAttribute('class','resfull');
			coll.className = 'resfull';
		 }
		 
	  }
		
	} 

	/* append checkboxes to available hours*/
	  /* alltimes : all, fulltimes: full */
         for (var ii=0; ii<alltimes.length; ii++) {
         	full = false;
         	for (var j=0; j<fulltimes.length; j++) {if (alltimes[ii]==fulltimes[j]) full = true;}
         	if (!full) {
         		
         		var elm = document.getElementById(alltimes[ii]);
         		if (elm) {
         		  /* elm is TD with name, create checkbox here */
			  vls = alltimes[ii].split("_");
			  sfp_id = vls[0];
			  time = vls[1];

         		  inp = document.createElement('input');
			  inp.setAttribute('type','checkbox');
			  inp.setAttribute('purpose','sfboxes');
			  inp.setAttribute('id','sfres_'+alltimes[ii]);
			  inp.setAttribute('class','reserveinput');
			  inp.setAttribute('sfp_id',sfp_id);
			  inp.setAttribute('time',time);
			  elm.appendChild(inp);
         		}
         	}
         }
		
	/* retrieve and set DIV*/
	if (_SARISSA_IS_IE) {
		cont = tgobj.innerHTML;
		tgobj.innerText="";
        	tgobj.insertAdjacentHTML("AfterBegin",cont);
        }
}


function getSFres () {
	var sfres = "";
	var boxes = document.getElementsByTagName('input');
	for (var i=0; i<boxes.length; i++) {
	  	if (boxes[i].checked && boxes[i].getAttribute('purpose') == 'sfboxes') {
	  		sfp_id = boxes[i].getAttribute("sfp_id");
	  		time = boxes[i].getAttribute("time");
			sfres += sfp_id + "|" + time + "||";
	  	}
	}
      return sfres;
}

function setSFres(str) {
   var ress = str.split("||");
   for (var i=0; i<ress.length; i++) {
	var roomVals = ress[i].split("|");
	var sfp_id = roomVals[0];
	var time = roomVals[1];
	var elm = document.getElementById("sfres_"+sfp_id + "_" + time);
	if (elm) {
		elm.checked = true;
	}
   }

}

function getHours(from,to) {
	var aDate = from.split(" ");var hFrom = aDate[1];
	var hhFrom = hFrom.split(":");var FROM = hhFrom[0];
	
	var aDate = to.split(" ");var hFrom = aDate[1];
	var hhFrom = hFrom.split(":");var TO = hhFrom[0];
	
	var ret = Array();
	for (i=FROM; i<=TO; i++) {		
		ret.push(i);
	}
	return ret;

}


/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ SWITCH CUSTOM DIVs
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
function switchCard(prefix, id)
{
	var card;
	var tab;
        
        var sw = document.getElementById(prefix + "switchedCard");
        if (!sw) return;
        var switchedCard = sw.value;

	if (switchedCard != 0) {
		card = document.getElementById(prefix + "card" + switchedCard);
		tab = document.getElementById(prefix + "tab" + switchedCard);
		
		tab.className = prefix +  "tab" + "ON";
		
		card.style.display = 'none';
	}
	switchedCard = id;
	

	if (switchedCard != 0) {
		card = document.getElementById(prefix + "card" + switchedCard);
		tab = document.getElementById(prefix + "tab" + switchedCard);
		card.style.display = 'block';
		tab.className = prefix +  "tab" + "OFF";
		
	}								
	
	sw.value = id;
}
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ END
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ BASE64 ENCODING JS FUNCTION
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

function base64Encode(p_str)
{ 
	
	var BaseTable = new Array(	"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
						"Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f",
						"g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v",
						"w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/");

	var out = "";
	var c1, c2, c3;
	var b1, b2, b3, b4;

	var n			= p_str.length;
	var n3byt		= parseInt(n / 3);     	/* how 3 bytes groups? */
	var nrest		= n % 3;     			/* the remaining bytes from the grouping */
	var k			= n3byt * 3; 			/* we are doing 3 bytes at a time */
	var linelength 	= 0;         			/* current linelength */
	var i          	= 0;         			/* index */

	/* do the 3-bytes groups ... */

	while ( k > i )
	{

		c1 = p_str.charCodeAt(i);
		c2 = p_str.charCodeAt(i + 1);
		c3 = p_str.charCodeAt(i + 2);

		out += BaseTable[((c1 & 0xFC) >> 2)];
		out += BaseTable[(((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4))];
		out += BaseTable[(((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6))];
		out += BaseTable[(c3 & 0x3F)];

		if ((linelength += 4) >= 76)
		{
			out += "\r\n";
			linelength = 0;
		}

		i += 3;
	}

	if (nrest > 0)
	{
		if ((linelength += 4) >= 76) out += "\r\n";

		c1 = p_str.charCodeAt(k);
		if (n > (k + 1)) c2 = p_str.charCodeAt(k + 1);

		if (nrest==2)
		{
			/* 2 bytes left */

			out += BaseTable[(( c1 & 0xFC) >> 2)];
			out += BaseTable[(((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4))];
			out += BaseTable[(( c2 & 0x0F) << 2)];
			out += "=";
		}
		else
		{
			if (nrest==1)
			{
				/* 1 byte left */

				out += BaseTable[((c1 & 0xFC) >> 2)];
				out += BaseTable[((c1 & 0x03) << 4)];
				out += "==";
			}
		}
	}

	return out;

}

