function SearchBox(){} SearchBox.prototype.printSearchBox = function() { //css styles var style = '#oasearchbox446 * {margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;font-weight:700}#oasearchbox446 #form-search-apartment {word-wrap:normal;position:relative;top:0px;left:0px;width:236px;min-width:236px;padding:10px 0px 10px 6px;background-color:#dbdbdb;color:#ffffff;margin-top:0;-moz-border-radius:10px;-webkit-border-radius:10px;-khtml-border-radius:10px;border-radius:10px;font-size:15px;height:222px;min-height:222px;}#oasearchbox446 .dest {font-size:18px}#oasearchbox446 .floatl {float:left;}#oasearchbox446 .floatr {float:right;}#oasearchbox446 .mopt {margin:13px 7% 0 0;width:80px;}/** html .mopt {padding:13px 7% 0 0;margin:0px;}*/#oasearchbox446 #fPax, #oasearchbox446 .day, #oasearchbox446 .datem {font-size:11px;height:19px;font-weight:400;}#oasearchbox446 .datem {margin-left:10px;width:64%}#oasearchbox446 .day {width:24%}#oasearchbox446 .ac_input {width:93%;}#oasearchbox446 .txtlink {font-size:17px;text-align:center;padding-top:10px;float:left;width:93%;}#oasearchbox446 .link {color:#FFF;text-decoration:none}#oasearchbox446 .link:hover {color:#FFF;text-decoration:underline}#oasearchbox446 .btnsrch {background-image:url("http://www.rbookings.com/searchbox/img/srch.png");background-position:center center;text-align:center;display:block;line-height:30px;background-repeat:no-repeat;font-size:14px}#oasearchbox446 .btnsrch:hover {text-decoration:none}#oasearchbox446 .pdform {padding-top:3%;height:8%;width:40px;}#oasearchbox446 .a1 {height:15.8%;padding-top:10px;}#oasearchbox446 .a2 {padding-top:1%;height:22%}'; var o = window.ooasearchbox446; //print form o.printS(style); //initialize dates o.initDates(); } SearchBox.prototype.printS = function(style){ var txt = ""; //ghost form! txt += '
'; txt += '
'; txt += '
'; txt += 'Destination
'; txt += ''; txt += '
'; txt += '
Arrival
'; txt += ''; txt += '
'; txt += '
Departure
'; txt += ''; txt += '
'; txt += '
Search
'; txt += '
People'; txt += '
'; txt += '
'; txt += ''; document.getElementById("oasearchbox446").innerHTML = txt; this.createForm(); } SearchBox.prototype.createForm = function(){ //the real form var form = document.createElement("form"); form.method = "post"; form.action = "http://www.only-apartments.com/affiliate/b-booking_495/SearchResultList.aspx#utm_souce=b-booking&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; form.id="frmSearchBox446226"; form.setAttribute("target","_blank"); var txtForm = ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; txtForm += ''; document.body.appendChild(form); //append as the last element document.getElementById("frmSearchBox446226").innerHTML = txtForm; } SearchBox.prototype.addLoadEvent = function(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } SearchBox.prototype.printL = function(style){ var txt = ""; txt += '
'; txt += '
'; txt += '
'; txt += '
Destination
'; txt += '
'; txt += '
Arrival
'; txt += ''; txt += '
'; txt += '
Departure
'; txt += ''; txt += '
'; txt += '
People
'; txt += '
'; txt += '
'; txt += 'Search
'; txt += '
'; txt += '
'; txt += ''; document.getElementById("oasearchbox446").innerHTML = txt; this.createForm(); } SearchBox.prototype.arrivalMonthChange = function(ev){ var v = document.getElementById("ArrivalDayID446226").value var value; if (ev.srcElement) value= ev.srcElement.value; if (ev.target) value = ev.target.value; var s = value.split("-"); var d = this.daysInMonth(s[1]-1,s[0]); this.fillDropDownInt("ArrivalDayID446226",d); if(v>d) this.setSelectedValue("ArrivalDayID446226",d); else this.setSelectedValue("ArrivalDayID446226",v); this.datesChanged(); } SearchBox.prototype.departureMonthChange = function(ev){ var v = document.getElementById("DepartureDayID446226").value var value; if (ev.srcElement) value= ev.srcElement.value; if (ev.target) value = ev.target.value; var s = value.split("-"); var d = this.daysInMonth(s[1]-1,s[0]); this.fillDropDownInt("DepartureDayID446226",d); if(v>d) this.setSelectedValue("DepartureDayID446226",d); else this.setSelectedValue("DepartureDayID446226",v); this.datesChanged(); } SearchBox.prototype.datesChanged = function(){ var arrMonth = document.getElementById("ArrivalMonthID446226").value; var depMonth = document.getElementById("DepartureMonthID446226").value; var arrDay = document.getElementById("ArrivalDayID446226").value; var depDay = document.getElementById("DepartureDayID446226").value; document.getElementById("fcal-arr446226").value = arrMonth +"-"+ arrDay; document.getElementById("fcal-go446226").value = depMonth +"-"+ depDay; } SearchBox.prototype.fillDropDownInt0 = function(list,max) { var ddl = document.getElementById(list); ddl.innerHTML = ""; for(var i = 0; i < max+1; i++) { var op = new Option; op.text = i; op.value = i; ddl.options[i] = op; } } SearchBox.prototype.fillDropDownInt = function(list,maxDays) { var ddl = document.getElementById(list); ddl.innerHTML = ""; for(var i = 1; i <= maxDays; i++) { var op = new Option; op.text = i; op.value = i; ddl.options[i-1] = op; } } SearchBox.prototype.fillDropDownArray = function(list,ar) { var ddl = document.getElementById(list); ddl.innerHTML = ""; for(var i = 0; i < ar.length; i++) { var op = new Option; op.text = ar[i].text; op.value = ar[i].value; ddl.options[i] = op; } } SearchBox.prototype.setSelectedValue = function(id,v) { var osel = document.getElementById(id); for(index = 0; index < osel.length; index++) { if(osel[index].value == v) osel.selectedIndex = index; } } SearchBox.prototype.daysInMonth = function(iMonth, iYear) { return 32 - new Date(iYear, iMonth, 32).getDate(); } SearchBox.prototype.initDates = function() { var arrTime = new Date(); var depTime = new Date(); depTime.setDate(arrTime.getDate() + 2); var arrDay = arrTime.getDate(); var arrMonth = arrTime.getMonth(); var arrYear = arrTime.getFullYear(); var depDay = depTime.getDate(); var depMonth = depTime.getMonth(); var depYear = depTime.getFullYear(); this.fillDropDownInt("ArrivalDayID446226",this.daysInMonth(arrMonth,arrYear)); this.fillDropDownInt("DepartureDayID446226",this.daysInMonth(depMonth,depYear)); this.fillDropDownInt("fPax446226",20); var calendarDates = [{"value":"2012-2","text":"February 2012"},{"value":"2012-3","text":"March 2012"},{"value":"2012-4","text":"April 2012"},{"value":"2012-5","text":"May 2012"},{"value":"2012-6","text":"June 2012"},{"value":"2012-7","text":"July 2012"},{"value":"2012-8","text":"August 2012"},{"value":"2012-9","text":"September 2012"},{"value":"2012-10","text":"October 2012"},{"value":"2012-11","text":"November 2012"},{"value":"2012-12","text":"December 2012"},{"value":"2013-1","text":"January 2013"},{"value":"2013-2","text":"February 2013"}]; this.fillDropDownArray("ArrivalMonthID446226", calendarDates); this.fillDropDownArray("DepartureMonthID446226", calendarDates); this.setSelectedValue("ArrivalDayID446226",arrDay); this.setSelectedValue("DepartureDayID446226",depDay); var ar = arrMonth+1; var de = depMonth+1; this.setSelectedValue("ArrivalMonthID446226",arrYear + "-" + ar); this.setSelectedValue("DepartureMonthID446226",depYear + "-" + de); this.datesChanged(); } SearchBox.prototype.submitForm = function(){ //get destination & id var destinyId = document.getElementById("txtfdestinationName446226").value.substring(0, document.getElementById("txtfdestinationName446226").value.indexOf("|")); var destiny = document.getElementById("txtfdestinationName446226").value.substring(document.getElementById("txtfdestinationName446226").value.indexOf("|")+1); var destinyBarcelona = "http://www.apartmentsramblas.com/affiliate/b-booking_495/SearchResultList.aspx#utm_souce=b-booking&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; //check if change form action if (destinyId=="42") document.getElementById("frmSearchBox446226").action = destinyBarcelona; //replace utm_term document.getElementById("frmSearchBox446226").action = document.getElementById("frmSearchBox446226").action.replace("#utm_term#", destiny); //update form document.getElementById("fdestinationName446226").value = destiny; document.getElementById("hfPax446226").value = document.getElementById("fPax446226").value; //get dates var arrMonth = document.getElementById("ArrivalMonthID446226").value.split("-"); var depMonth = document.getElementById("DepartureMonthID446226").value.split("-"); var arrDay = document.getElementById("ArrivalDayID446226").value; var depDay = document.getElementById("DepartureDayID446226").value; var arrivalDate = new Date(); arrivalDate.setFullYear(arrMonth[0],arrMonth[1]-1,arrDay); var departureDate = new Date(); departureDate.setFullYear(depMonth[0],depMonth[1]-1,depDay); //check errors var err = ""; if(arrivalDate>=departureDate) err += "Searchbox.err_ArrivalLessDeparture\n"; if(arrivalDate<(new Date())) err += "Searchbox.err_ArrivalGreaterToday\n"; if(document.getElementById("fdestinationName446226").value =="0") err += "The destination can't be empty\n"; if(err!="") { alert(err); return false; }else{ document.getElementById("frmSearchBox446226").submit(); return true; } return false; } window.ooasearchbox446 = new SearchBox(); window.ooasearchbox446.addLoadEvent(window.ooasearchbox446.printSearchBox);