 Element.addMethods ({ scrollToSide : function (element, side) { element = $(element) ; if (side == 'top') { element.scrollTop = 0 ; return true ; } else if (side == 'right') { element.scrollLeft = element.scrollWidth ; } else if (side == 'bottom') { element.scrollTop = element.scrollHeight ; return true ; } else if (side == 'left') { element.scrollLeft = 0 ; } return false ; }, disabledClass : function (element, dir) { element = $(element) ; if (dir == null) { return element.hasClassName('disabled') ; } if (dir === true) { element.addClassName('disabled') ; } if (dir === false) { element.removeClassName('disabled') ; } }, readonlyClass : function (element, dir) { element = $(element) ; if (dir == null) { return element.hasClassName('readonly') ; } if (dir === true) { element.addClassName('readonly') ; } if (dir === false) { element.removeClassName('readonly') ; } }, checkedClass : function (element, dir) { element = $(element) ; if (dir == null) { return element.hasClassName('checked') ; } if (dir === true) { element.addClassName('checked') ; return true ; } if (dir === false) { element.removeClassName('checked') ; return true ; } } }) ; function setcookie(c_name, c_value, c_expire, c_path, c_domain, c_secure) { cookie_value = c_name+"="+escape(c_value) ; if (c_expire != null) { c_expire = c_expire / (60*60*24) ; var exdate = new Date() ; exdate.setDate(exdate.getDate()+c_expire) ; cookie_value += ";expires="+exdate.toGMTString() ; } if (c_path != null) { cookie_value += ";path="+escape(c_path) ; } if (c_domain != null) { cookie_value += ";domain="+escape(c_domain) ; } if (c_secure != null && c_secure != false && c_secure != 'false') { cookie_value += ";secure" ; } document.cookie = cookie_value ; } function getcookie(c_name) { if (document.cookie.length>0) { c_start = document.cookie.indexOf(c_name + "=") ; if (c_start != -1) { c_start = c_start + c_name.length+1 ; c_end = document.cookie.indexOf(";",c_start) ; if (c_end == -1) { c_end = document.cookie.length ; } return unescape(document.cookie.substring(c_start,c_end)); } } return null; } function replaceAll(find, replace, string) { while (string.search(find) >= 0) { string = string.replace(find, replace) ; } return string ; } function validateFile(e, ext) { var ok = false ; var ext_str = '' ; $A(ext).each(function(i) { ext_str = ext_str+"."+i+"\r\n" ; if (e.value.toLowerCase().search("."+i) != -1) { ok = true ; } }) ; if (ok != true) { alert("This file must be in one of the following formats:\r\n"+ext_str) ; regenInput(e) ; } } function regenInput(e) { e.value = "" ; var n = e.cloneNode(true); e.parentNode.insertBefore(n, e) ; e.parentNode.removeChild(e) ; } function urlencode( str ) { var histogram = {}, tmp_arr = []; var ret = str.toString(); var replacer = function(search, replace, str) { var tmp_arr = []; tmp_arr = str.split(search); return tmp_arr.join(replace); }; histogram["'"] = '%27'; histogram['('] = '%28'; histogram[')'] = '%29'; histogram['*'] = '%2A'; histogram['~'] = '%7E'; histogram['!'] = '%21'; histogram['%20'] = '+'; ret = encodeURIComponent(ret); for (search in histogram) { replace = histogram[search]; ret = replacer(search, replace, ret) } return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) { return "%"+m2.toUpperCase(); }); return ret; } var windows = {} ; function popup(url, win_name) { url = url.replace('-thumb.', '-full.') ; if (!win_name) { win_name = "popupwin" ; } if (windows[win_name]) { windows[win_name].close() ; } win = window.open('', win_name, "resizable=1,scrollbars=0,location=0,status=0,toolbar=0,menubar=0,width=350,height=350") ; windows[win_name] = win ; var img = new Image() ; img.src = url ; if (img.complete == true) { resize() ; } else { img.onload = function () {resize() ;} ; } function resize() { win.location = url ; var w = img.width - win.document.body.clientWidth + 0 ; var h = img.height - win.document.body.clientHeight + 0 ; win.resizeBy(w, h) ; win.focus() ; win.document.close() ; img.onload = null ; } ; return false ; } function preview(file, nw, nh, win_name, win_title) { file = file.replace('https://', '') ; file = file.replace('http://', '') ; file = file.replace('www.farmerdoodles.com', '') ; file = file.replace('-thumb.', '-full.') ; if (!nw) { nw = '' ; } if (!nh) { nh = '' ; } if (!win_title) { win_title = '' ; } if (!win_name) { win_name = "preview" ; } if (windows[win_name]) { windows[win_name].close() ; } preview_window = window.open("/common/preview.php?file="+urlencode(file)+"&width="+nw+"&height="+nh+"&win_title="+win_title, win_name, "resizable=1,scrollbars=0,location=0,status=0,toolbar=0,menubar=0,width=350,height=350") ; windows[win_name] = preview_window ; preview_window.focus() ; return false ; } /* Processing function */ var procWin = { img : new Image(), src : '/common/images/loading.gif', show : function () { if (!$('procWin')) { $(document.body).insert(' <table id=\"procWin\" cellspacing=\"0\" cellpadding=\"0\" style=\"position: fixed; z-index: 1000; width: 100%; height: 100%; top: 0px; left: 0px; \"> <tr> <td style=\"vertical-align: middle; text-align: center; background-image: none; \"> <table cellspacing=\"0\" cellpadding=\"0\" style=\"margin: auto; \"> <tr> <td> <div style=\"padding: 45px 75px; background-color: #eee; border: solid 6px #d5d5d5; border-radius: 20px; box-shadow: 0px 0px 20px #666; \"> <p style=\"margin-top: 0px; color: #777; font-size: 20px; font-weight: normal; ; \">Processing</p> <img src=\"/common/images/loading.gif\" id=\"procWin_img\" alt=\"Loading\" /> </div> </td> </tr> </table> </td> </tr> </table> ') ; } }, hide : function () { if ($('procWin')) { $('procWin').remove() ; } }, init : function () { procWin.img.src = procWin.src ; } } ; procWin.init() ; HTMLElement.prototype.click = function() { var evt = this.ownerDocument.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); this.dispatchEvent(evt); } ; function fail(message) { procWin.hide() ; if (message) { alert(message) ; } return false ; } /* Give checkbox an off value */ /* example <input type="checkbox" name="cb" id="cb" value="onvalue" off="offvalue" /> */ function formSubmitCallback() { var hcb ; var hr ; $$("form").each (function(f) { Event.observe(f, 'submit', function(ev) { $$('input[type="checkbox"][off]').each(function (e) { var name_attr = e.readAttribute('name') ; if (e.checked == true) { var value_attr = e.value ; } else { var value_attr = e.readAttribute('off') ; } hcb = new Element('input', { 'type' : 'hidden', 'name' : name_attr, 'value' : value_attr }) ; e.insert({'after':hcb}) ; e.name = '' ; }) ; $$('input[type="radio"][on]').each(function (e) { var name_attr = evaluate_template(e.readAttribute('name'), {'value' : e.value}) ; var on = e.readAttribute('on') ; var off = e.readAttribute('off') ; if (e.checked == true) { var value_attr = on ; } else { var value_attr = off ; } if (off || e.checked == true) { hr = new Element('input', { 'type' : 'hidden', 'name' : name_attr, 'value' : value_attr }) ; e.insert({'after':hr}) ; } e.name = '' ; }) ; }) ; }) ; } Event.observe(window, 'load', function () {formSubmitCallback();}) ; /* get radio button group value. returns value or null */ function radio(fn) { var r = document.getElementsByName(fn) ; var v = null ; $A(r).each(function(e) { if (e.checked == true) { v = e.value ; } }) ; return v ; } function session(post, red) { if (typeof post === "string") { var q = post.indexOf('?') ; if (q !== false) { if (!red) { red = post.substring(0, q) ; } post = post.parseQuery() ; } } post.ajax = 1 ; var url = "/common/session.php" ; new Ajax.Request(url, { parameters : post, asynchronous : false, onSuccess: function(r) { if (red) { if (red === '') { red = location ; } location = red ; } }, onFailure: function() { alert("Your request has failed") ; } }) ; } function evaluate_template(str, replacements) { var template = new Template(str) ; return template.evaluate(replacements) ; } 
