// returns the script element matching the current script's name (based on params[:action]) function selfLocate() { var scriptName = "widget_small", hostName = "www.ridecharge.com", scripts = document.getElementsByTagName("script"), script, src; for(i = 0, j = scripts.length; i < j; ++i) { script = scripts[i]; src = script.getAttribute("src"); if(src && (src.indexOf(scriptName) != -1) && (src.indexOf(hostName) != -1) ) return script; } return false; } // inserts markup before some element, first wrapping it in a div function injectBefore(origNode, content) { var parent = origNode.parentNode, wrapper = document.createElement("div"); wrapper.innerHTML = content; parent.insertBefore(wrapper, origNode); return wrapper; } function emptyElement(elem) { while(elem.firstChild) elem.removeChild(elem.firstChild); } function replaceText(elem, txt) { txt = document.createTextNode(txt); emptyElement(elem); elem.appendChild(txt); } function addEvent(elem, evt, func, bind) { if(bind) { var oldFunc = func; func = function() { oldFunc.apply(bind, Array.prototype.slice.call(arguments)); }; } if(elem.addEventListener) elem.addEventListener(evt, func, false); else if(elem.attachEvent) elem.attachEvent("on" + evt, func); } function delegateListener(elem, childTagName, evt, func, bind) { } function preventEventDefault(evt) { if(evt.preventDefault) evt.preventDefault(); else evt.returnValue = false; } function getTarget(evt) { return (evt.target) ? evt.target : window.event.srcElement; } function clickIsWithin(elem, container) { if(elem == container) return true; var parent, success = false; while(elem.parentNode) { elem = elem.parentNode; if(elem == container) return true; } return false; } // !!!depends on events partial!!! function DateMgr(field) { // set field to today's date this.d = new Date; this.now = new Date; this.massageDate(); this.field = field; this.addIcon(); this.addCalendar(); this.setupMonth(); } DateMgr.prototype = { calendarDayBGColor: "white", calendarSelectedDayBGColor: "#ccc", // ensure date's minutes are multiple of 5, always round up massageDate: function() { var minutes = this.d.getMinutes(), diff; if(! ((minutes % 5) == 0)) { diff = minutes % 5; minutes = minutes + 5 - diff; this.d.setMinutes(minutes); } }, // add icon beside field, make clickable addIcon: function() { var fieldRow = this.field.parentNode, link = document.createElement("a"), img = document.createElement("img"); img.src = "http://www.gocurb.com/stylesheets/images/calendar_icon.gif"; img.style.border = "none"; img.style.position = "relative"; img.style.top = "0px"; img.style.left = "0px"; link.href="#"; link.style.position = "absolute"; link.style.left = "25px"; this.link = link; this.icon = img; fieldRow.insertBefore(link, this.field); this.field.previousSibling.appendChild(img); addEvent(img, "click", this.showCalendar, this); }, // add calendar element (initially hidden) beside field addCalendar: function() { this.calendar = document.createElement("div"); var fieldRow = this.field.parentNode, cal = this.calendar, s = cal.style, tables, navLinks, selectBoxes; s.display = "none"; s.position = "absolute"; s.left = (parseInt(this.link.style.left, 10) + 20) + "px"; s.width = "260px"; s.zIndex = "5000"; cal.innerHTML = "
Curb<\/p>\n
3 FREE AND EASY ways to book a taxi.<\/p>\n\n
1: Book online right here<\/p>\n\n
Examples:<\/p>\n
2: Book, track & pay with Curb<\/p>\n
3: Book via text message<\/p>\n\n
<\/p>\n \n\n <\/div>\n <\/div>\n <\/div>\n<\/div>", wrapper = injectBefore(thisScript, markup), inputs = wrapper.getElementsByTagName("input"), // look for date field within wrapper dateField = inputs[2], whereField = inputs[3], nowRadio = inputs[0], laterRadio = inputs[1], whenSpan = wrapper.getElementsByTagName("span")[0], hideDate = function() { dateField.parentNode.style.display = "none"; dateField.value = ""; if(whenSpan.shouldHide) whenSpan.style.display = "none"; }; var dm = new DateMgr(dateField); addEvent(nowRadio, "click", hideDate); addEvent(laterRadio, "click", function() { dateField.parentNode.style.display = "block"; dm.updateField(); if(whenSpan.style.display == "none") { whenSpan.shouldHide = true; whenSpan.style.display = "block"; } }); addEvent(whereField, "focus", function() { if(this.value == this.defaultValue) { this.style.color = "black"; this.value = ""; } }, whereField); addEvent(whereField, "blur", function() { if(!this.value) { this.style.color = "#999"; this.value = this.defaultValue; } }, whereField); hideDate(); }