function SearchBox(){} SearchBox.prototype.printSearchBox = function() { //css styles var style = '#oasearchbox296 #logo_oa{display:none} #oasearchbox296 .cont * {margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;font-weight:700}#oasearchbox296 .floatl {float:left;}#oasearchbox296 .floatr {float:right;}#oasearchbox296 .m{margin-left:22px;}#oasearchbox296 .w3{margin-right:4px;margin-top:15px;width:95px;}#oasearchbox296 #logo_oa {height:41%;margin:0 15px 0 5px;text-align:right;}#oasearchbox296 #form-search-apartment {word-wrap:normal;background-color:#ffffff;color:#00007f;font-size:15px;height:72px;min-height:72px;margin-top:0;padding:5px 0 10px 6px;width:724px;min-width:724px;-moz-border-radius:10px;-webkit-border-radius:10px;-khtml-border-radius:10px;border-radius:10px;font-size:15px}#oasearchbox296 .dest {font-size:18px}#oasearchbox296 #fPax, #oasearchbox296 .day, #oasearchbox296 .datem{font-size:13px;font-weight:400;height:23px;}#oasearchbox296 .datem {margin-left:5px;}#oasearchbox296 .day {width:40px;}#oasearchbox296 .ac_input {width:148px;}#oasearchbox296 .txtlink {font-size:18px; padding-right:10px; text-align:right}#oasearchbox296 .link {color:#FFF;text-decoration:none}#oasearchbox296 .link:hover {color:#FFF;text-decoration:underline}#oasearchbox296 .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}#oasearchbox296 .btnsrch:hover {text-decoration:none}#oasearchbox296 .pdform {line-height:21px;}'; var o = window.ooasearchbox296; //print form o.printL(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("oasearchbox296").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/lolaguillen_199/SearchResultList.aspx#utm_souce=lolaguillen&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; form.id="frmSearchBox29639"; 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("frmSearchBox29639").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("oasearchbox296").innerHTML = txt; this.createForm(); } SearchBox.prototype.arrivalMonthChange = function(ev){ var v = document.getElementById("ArrivalDayID29639").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("ArrivalDayID29639",d); if(v>d) this.setSelectedValue("ArrivalDayID29639",d); else this.setSelectedValue("ArrivalDayID29639",v); this.datesChanged(); } SearchBox.prototype.departureMonthChange = function(ev){ var v = document.getElementById("DepartureDayID29639").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("DepartureDayID29639",d); if(v>d) this.setSelectedValue("DepartureDayID29639",d); else this.setSelectedValue("DepartureDayID29639",v); this.datesChanged(); } SearchBox.prototype.datesChanged = function(){ var arrMonth = document.getElementById("ArrivalMonthID29639").value; var depMonth = document.getElementById("DepartureMonthID29639").value; var arrDay = document.getElementById("ArrivalDayID29639").value; var depDay = document.getElementById("DepartureDayID29639").value; document.getElementById("fcal-arr29639").value = arrMonth +"-"+ arrDay; document.getElementById("fcal-go29639").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("ArrivalDayID29639",this.daysInMonth(arrMonth,arrYear)); this.fillDropDownInt("DepartureDayID29639",this.daysInMonth(depMonth,depYear)); this.fillDropDownInt("fPax29639",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("ArrivalMonthID29639", calendarDates); this.fillDropDownArray("DepartureMonthID29639", calendarDates); this.setSelectedValue("ArrivalDayID29639",arrDay); this.setSelectedValue("DepartureDayID29639",depDay); var ar = arrMonth+1; var de = depMonth+1; this.setSelectedValue("ArrivalMonthID29639",arrYear + "-" + ar); this.setSelectedValue("DepartureMonthID29639",depYear + "-" + de); this.datesChanged(); } SearchBox.prototype.submitForm = function(){ //get destination & id var destinyId = document.getElementById("txtfdestinationName29639").value.substring(0, document.getElementById("txtfdestinationName29639").value.indexOf("|")); var destiny = document.getElementById("txtfdestinationName29639").value.substring(document.getElementById("txtfdestinationName29639").value.indexOf("|")+1); var destinyBarcelona = "http://www.apartmentsramblas.com/affiliate/lolaguillen_199/SearchResultList.aspx#utm_souce=lolaguillen&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; //check if change form action if (destinyId=="42") document.getElementById("frmSearchBox29639").action = destinyBarcelona; //replace utm_term document.getElementById("frmSearchBox29639").action = document.getElementById("frmSearchBox29639").action.replace("#utm_term#", destiny); //update form document.getElementById("fdestinationName29639").value = destiny; document.getElementById("hfPax29639").value = document.getElementById("fPax29639").value; //get dates var arrMonth = document.getElementById("ArrivalMonthID29639").value.split("-"); var depMonth = document.getElementById("DepartureMonthID29639").value.split("-"); var arrDay = document.getElementById("ArrivalDayID29639").value; var depDay = document.getElementById("DepartureDayID29639").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("fdestinationName29639").value =="0") err += "The destination can't be empty\n"; if(err!="") { alert(err); return false; }else{ document.getElementById("frmSearchBox29639").submit(); return true; } return false; } window.ooasearchbox296 = new SearchBox(); window.ooasearchbox296.addLoadEvent(window.ooasearchbox296.printSearchBox);