function f_clientWidth() { return f_filterResults ( window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0 ); } function f_clientHeight() { return f_filterResults ( window.innerHeight ? window.innerHeight : 0, document.documentElement ? document.documentElement.clientHeight : 0, document.body ? document.body.clientHeight : 0 ); } function f_scrollLeft() { return f_filterResults ( window.pageXOffset ? window.pageXOffset : 0, document.documentElement ? document.documentElement.scrollLeft : 0, document.body ? document.body.scrollLeft : 0 ); } function f_scrollTop() { return f_filterResults ( window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0 ); } function f_filterResults(n_win, n_docel, n_body) { var n_result = n_win ? n_win : 0; if (n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel; return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result; } // AJAX var XMLHttpFactories = [ function () {return new XMLHttpRequest()}, function () {return new ActiveXObject("Msxml2.XMLHTTP")}, function () {return new ActiveXObject("Msxml3.XMLHTTP")}, function () {return new ActiveXObject("Microsoft.XMLHTTP")} ]; function createXMLHTTPObject() { var xmlhttp = false; for (var i=0;if_clientWidth()+f_scrollLeft()){ //left -= left+precartbox.offsetWidth-(f_clientWidth()+f_scrollLeft()); scroll(left+precartbox.offsetWidth-f_clientWidth(),f_scrollTop()); } if(top<3){ top=3; }else if(top+precartbox.offsetHeight>f_clientHeight()+f_scrollTop()){ //top -= top+precartbox.offsetHeight-(f_clientHeight()+f_scrollTop()); scroll(f_scrollLeft(),top+precartbox.offsetHeight-f_clientHeight()); } precartbox.style.top = top+'px'; precartbox.style.left = left+'px'; precartbox.innerHTML = '
\ \ How do you want to proceed?\
\
\ \ Proceed to Booking\ \
\ \ Add to My Itinerary\ \
\
'; return false; } function close_precartbox(){ document.body.removeChild(precartbox); precartbox = null; } function set_precartform(f){ // if user tries to submit form f if(document.getElementById("container").offsetWidth<=600) return true; precartform = f; return false; } function proceed_submit(){ // if user clicks "proceed to booking" precartform.submit(); } function add_form_to_cart(proceed_to_booking){ // if user clicks "add to shopping cart" if(proceed_to_booking && cartitems.length==0){ precartform.submit(); return; } var stayAdded = false; with(precartform){ var day,month,year,nightsValue; if(typeof(month_a)!="undefined"){ var monthString = month_a.value; while (monthString.charAt(0)=='0' && monthString.length>1) monthString = monthString.substring(1,monthString.length); month = parseInt(monthString) + 1; nightsValue = nights.value; day = day_a.value; year = year_a.value; }else{ var arr = new Date(); arr.setDate(arr.getDate()+1); month = arr.getMonth()+1; year = arr.getFullYear(); day = arr.getDate(); nightsValue = 1; } var date = year + "-" + month + "-" + day; if(typeof(male)!="undefined") cartMen = parseInt(male.value); if(typeof(female)!="undefined") cartWomen = parseInt(female.value); if(isoverlapping(date,nightsValue)){ proceed_to_booking = proceed_to_booking && stayExists(house.value,nightsValue,date); if(!proceed_to_booking){ alert("You have entered the same date for more than 1 hostel. Please review your dates to proceed."); } }else{ stayAdded = addStay(house.value,nightsValue,date); } } close_precartbox(); if(proceed_to_booking){ redrawCart(); document.cartform.submit(); } scroll(0,0); } function initCart(){ // when page loads houses = new Array(); parseCartContent(); cartbox = document.getElementById("cartbox"); cartinfo = document.getElementById("cartinfo"); cartbutton_text = document.getElementById("cartbutton_text"); cartbutton = document.getElementById("cartbutton"); cartboxHTML = cartbox.innerHTML; for(var i=0; i0){ for(var i=0; i""){ houses[housesArray[i].split(',')[0]] = housesArray[i].split(',')[1]; } } redrawCart(); } function redrawCart(){ var htmlString = ""; parseCartContent(); htmlString = ""; for(var i=0; i'+houses[house]+'
'+arrString+' - '+depString+' = '+nights+''; htmlString += ''; htmlString += ''; htmlString += ''; htmlString += ''; htmlString += ''; } htmlString += ''; htmlString += ''; if(cartitems.length>0){ cartinfo.style.display = "none"; document.getElementById("cartitems").style.display="block"; cartbutton_text.innerHTML = "Proceed to Booking"; cartbutton.setAttribute("href", "javascript:document.cartform.submit();"); }else{ cartinfo.style.display = "block"; document.getElementById("cartitems").style.display="none"; cartbutton_text.innerHTML = "Search hostels"; cartbutton.setAttribute("href", "/web/hostels.en.htm"); } if(cartbox.style.display != "block"){ cartbox.style.display = "block"; } document.getElementById("cartitems").innerHTML = htmlString; } function addStay(house,nights,startdate){ cartitems[cartitems.length] = Array(house,nights,startdate); sortCartItems(); updateCartContent(cartitems); updateCartCountry(current_cart_country); document.cartform.country.value = current_cart_country; if(typeof(houses)!="undefined"){ if(typeof(houses[house])=="undefined") houses[house] = house; } getHouseNames(); return true; } function stayExists(house,nights,startdate){ for(var i=0; iarr)||(checkarr>=arr && checkarr=dateB){ k++; temp[j] = out[j]; }else{ temp[j+1] = out[j]; } } temp[k] = input[i]; out = temp; } cartitems = out; } function parseCartPersons(){ var cookieString = readCartCookie(); var out; if(cookieString.indexOf('||')>-1){ out = cookieString.split('||'); out[0] = out[0].split('|'); cartMen = parseInt(out[0][0]); cartWomen = parseInt(out[0][1]); }else{ cartMen = 0; cartWomen = 0; } } function parseCartContent(){ cartitems = new Array(); var out = new Array(); var itemsArray = new Array(); var cookieString = readCartCookie(); if(cookieString.indexOf('||')>-1){ out = cookieString.split('||'); out[0] = out[0].split('|'); if(out[1]>"") itemsArray = out[1].split('|'); }else{ itemsArray = cookieString.split('|'); } for(var i=0; i""){ cartitems[i] = itemsArray[i].split(','); } } if(cartitems==""){ cartitems = new Array(); } sortCartItems(); } function updateCartCountry(country){ writeCookie(country,"cartcountry"); } function updateCartContent(inputArray){ var out = new Array(); for(var i=0; i