function SearchBox(){} SearchBox.prototype.printSearchBox = function() { //css styles var style = '#oasearchbox387 * {margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;font-weight:700}#oasearchbox387 #form-search-apartment {word-wrap:normal;position:relative;top:0px;left:0px;width:276px;min-width:276px;padding:10px 0px 10px 6px;background-color:#edbc36;color:#333333;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;}#oasearchbox387 .dest {font-size:18px}#oasearchbox387 .floatl {float:left;}#oasearchbox387 .floatr {float:right;}#oasearchbox387 .mopt {margin:13px 7% 0 0;width:80px;}/** html .mopt {padding:13px 7% 0 0;margin:0px;}*/#oasearchbox387 #fPax, #oasearchbox387 .day, #oasearchbox387 .datem {font-size:11px;height:19px;font-weight:400;}#oasearchbox387 .datem {margin-left:10px;width:64%}#oasearchbox387 .day {width:24%}#oasearchbox387 .ac_input {width:93%;}#oasearchbox387 .txtlink {font-size:17px;text-align:center;padding-top:10px;float:left;width:93%;}#oasearchbox387 .link {color:#FFF;text-decoration:none}#oasearchbox387 .link:hover {color:#FFF;text-decoration:underline}#oasearchbox387 .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}#oasearchbox387 .btnsrch:hover {text-decoration:none}#oasearchbox387 .pdform {padding-top:3%;height:8%;width:40px;}#oasearchbox387 .a1 {height:15.8%;padding-top:10px;}#oasearchbox387 .a2 {padding-top:1%;height:22%}'; var o = window.ooasearchbox387; //print form o.printS(style); //initialize dates o.initDates(); } SearchBox.prototype.printS = function(style){ var txt = ""; //ghost form! txt += '
'; txt += '
'; txt += '
'; txt += 'Destino
'; txt += ''; txt += '
'; txt += '
Entrada
'; txt += ''; txt += '
'; txt += '
Salida
'; txt += ''; txt += '
'; txt += '
Buscar
'; txt += '
Personas'; txt += '
'; txt += '
'; txt += ''; document.getElementById("oasearchbox387").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.es/affiliate/abeldueas_447/SearchResultList.aspx#utm_souce=abeldueas&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; form.id="frmSearchBox387539"; 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("frmSearchBox387539").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 += '
Destino
'; txt += '
'; txt += '
Entrada
'; txt += ''; txt += '
'; txt += '
Salida
'; txt += ''; txt += '
'; txt += '
Personas
'; txt += '
'; txt += '
'; txt += 'Buscar
'; txt += '
'; txt += '
'; txt += ''; document.getElementById("oasearchbox387").innerHTML = txt; this.createForm(); } SearchBox.prototype.arrivalMonthChange = function(ev){ var v = document.getElementById("ArrivalDayID387539").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("ArrivalDayID387539",d); if(v>d) this.setSelectedValue("ArrivalDayID387539",d); else this.setSelectedValue("ArrivalDayID387539",v); this.datesChanged(); } SearchBox.prototype.departureMonthChange = function(ev){ var v = document.getElementById("DepartureDayID387539").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("DepartureDayID387539",d); if(v>d) this.setSelectedValue("DepartureDayID387539",d); else this.setSelectedValue("DepartureDayID387539",v); this.datesChanged(); } SearchBox.prototype.datesChanged = function(){ var arrMonth = document.getElementById("ArrivalMonthID387539").value; var depMonth = document.getElementById("DepartureMonthID387539").value; var arrDay = document.getElementById("ArrivalDayID387539").value; var depDay = document.getElementById("DepartureDayID387539").value; document.getElementById("fcal-arr387539").value = arrMonth +"-"+ arrDay; document.getElementById("fcal-go387539").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("ArrivalDayID387539",this.daysInMonth(arrMonth,arrYear)); this.fillDropDownInt("DepartureDayID387539",this.daysInMonth(depMonth,depYear)); this.fillDropDownInt("fPax387539",20); var calendarDates = [{"value":"2012-2","text":"febrero 2012"},{"value":"2012-3","text":"marzo 2012"},{"value":"2012-4","text":"abril 2012"},{"value":"2012-5","text":"mayo 2012"},{"value":"2012-6","text":"junio 2012"},{"value":"2012-7","text":"julio 2012"},{"value":"2012-8","text":"agosto 2012"},{"value":"2012-9","text":"septiembre 2012"},{"value":"2012-10","text":"octubre 2012"},{"value":"2012-11","text":"noviembre 2012"},{"value":"2012-12","text":"diciembre 2012"},{"value":"2013-1","text":"enero 2013"},{"value":"2013-2","text":"febrero 2013"}]; this.fillDropDownArray("ArrivalMonthID387539", calendarDates); this.fillDropDownArray("DepartureMonthID387539", calendarDates); this.setSelectedValue("ArrivalDayID387539",arrDay); this.setSelectedValue("DepartureDayID387539",depDay); var ar = arrMonth+1; var de = depMonth+1; this.setSelectedValue("ArrivalMonthID387539",arrYear + "-" + ar); this.setSelectedValue("DepartureMonthID387539",depYear + "-" + de); this.datesChanged(); } SearchBox.prototype.submitForm = function(){ //get destination & id var destinyId = document.getElementById("txtfdestinationName387539").value.substring(0, document.getElementById("txtfdestinationName387539").value.indexOf("|")); var destiny = document.getElementById("txtfdestinationName387539").value.substring(document.getElementById("txtfdestinationName387539").value.indexOf("|")+1); var destinyBarcelona = "http://www.apartmentsramblas.com/affiliate/abeldueas_447/SearchResultList.aspx#utm_souce=abeldueas&utm_medium=affiliate&utm_term=#utm_term#&utm_content=box&utm_campaign=affiliate-standard"; //check if change form action if (destinyId=="42") document.getElementById("frmSearchBox387539").action = destinyBarcelona; //replace utm_term document.getElementById("frmSearchBox387539").action = document.getElementById("frmSearchBox387539").action.replace("#utm_term#", destiny); //update form document.getElementById("fdestinationName387539").value = destiny; document.getElementById("hfPax387539").value = document.getElementById("fPax387539").value; //get dates var arrMonth = document.getElementById("ArrivalMonthID387539").value.split("-"); var depMonth = document.getElementById("DepartureMonthID387539").value.split("-"); var arrDay = document.getElementById("ArrivalDayID387539").value; var depDay = document.getElementById("DepartureDayID387539").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("fdestinationName387539").value =="0") err += "El destino no puede estar vacío\n"; if(err!="") { alert(err); return false; }else{ document.getElementById("frmSearchBox387539").submit(); return true; } return false; } window.ooasearchbox387 = new SearchBox(); window.ooasearchbox387.addLoadEvent(window.ooasearchbox387.printSearchBox);