var $ = function (element){ if (typeof element == 'string') return document.getElementById ? document.getElementById(element) : ( document.all ? document.all(element) : null ); else if (typeof element == 'object') return element; else return null; }; var Extend = function(destination, source) { for (property in source) destination[property] = source[property]; return destination; }; var Try = { these: function() { var returnValue; for (var i = 0, length = arguments.length; i < length; i++) { var lambda = arguments[i]; try { returnValue = lambda(); break; } catch (e) {} }; return returnValue; } }; var Random = function(){ return Number.prototype.Random(); }; var isDefined = function(obj){ return typeof(obj) == 'undefined' || obj == null ? false : true; }; var functionExists = function(name){ return typeof(name) == 'function'; }; function newWindow(file,top,left,width,height,opts,name){ window.focus(); if( typeof(msgWindow) == 'object' ) msgWindow.close(); name = isDefined(name) ? name : 'window1'; args = 'left='+left+',top='+top+',width='+width+',height='+height; if(opts = (isDefined(opts) ? opts : 'scrollbars=0,resizable=0,status=1')) args += ',' + opts; var msgWindow = open('',name,args); try{ msgWindow.location.href = file; if(msgWindow.opener == null) msgWindow.opener = self; msgWindow.focus(); } catch (e) { alert('You have to enable popups to view this window'); } }; function setCookie(name, value, expires, path, domain, secure) { if( ! isDefined(expires) || expires == 0 ) { today = new Date(); expires = new Date(); expires.setTime(today.getTime() + 3600000*24*365); } var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); document.cookie = curCookie; } function preload(){ imghl = preload.arguments; for(i=0; i<imghl.length; i++){ imghl[(imghl[i])]=new Image; imghl[(imghl[i])].src=''+imghl[i]; } }; function swap(n,i){ try{ if(!swap.arguments.length){ document[r_n].src=r_s; }else{ r_s=document[n].src; r_n=n; document[n].src=imghl[i].src } }catch(e){} }; Number.prototype.toColorPart = function(){ var digits = this.toString(16); if (this < 16) return '0' + digits; return digits; }; Number.prototype.Random = function(){ randomNum = ''; for (i=0; i<2; ++i) { tmp = Math.random()*8; randomNum += tmp.toString().replace(".",""); } return randomNum; }; document.getElement = function (name){ return document.getElementById ? document.getElementById(name) : document.all ? document.all(name) : null; }; document.getObject = document.getElement; document.getDocumentElement = function () { return this.documentElement; }; document.selectDropMenuByVal = function(dropmenu,value){ if( typeof(dropmenu) == 'object' ) dropObject = dropmenu; else dropObject = document.getElement(dropmenu); try{ dropLength = dropObject.options.length; }catch(e){ alert('selectDropMenuByVal:\ninvalid target control \'' + dropmenu + '\''); return; } for( counter = 0; counter < dropLength; ++counter ){ if(dropObject.options[counter].value == value){ dropObject.selectedIndex = counter; return; } } }; if (!window.Event) var Event = new Object(); Extend(Event, { KEY_BACKSPACE: 8, KEY_TAB: 9, KEY_RETURN: 13, KEY_ESC: 27, KEY_LEFT: 37, KEY_UP: 38, KEY_RIGHT: 39, KEY_DOWN: 40, KEY_DELETE: 46, KEY_HOME: 36, KEY_END: 35, KEY_PAGEUP: 33, KEY_PAGEDOWN: 34, observers: false, element: function(event) { return event.target || event.srcElement; }, isLeftClick: function(event) { return (((event.which) && (event.which == 1)) || ((event.button) && (event.button == 1))); }, pointerX: function(event) { return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)); }, pointerY: function(event) { return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); }, stop: function(event) { if (event.preventDefault) { event.preventDefault(); event.stopPropagation(); } else { event.returnValue = false; event.cancelBubble = true; } }, findElement: function(event, tagName) { var element = Event.element(event); while (element.parentNode && (!element.tagName || (element.tagName.toUpperCase() != tagName.toUpperCase()))) element = element.parentNode; return element; }, _observeAndCache: function(element, name, observer, useCapture) { if (!this.observers) this.observers = []; if (element.addEventListener) { this.observers.push([element, name, observer, useCapture]); element.addEventListener(name, observer, useCapture); } else if (element.attachEvent) { this.observers.push([element, name, observer, useCapture]); element.attachEvent('on' + name, observer); } }, unloadCache: function() { if (!Event.observers) return; for (var i = 0, length = Event.observers.length; i < length; i++) { Event.stopObserving.apply(this, Event.observers[i]); Event.observers[i][0] = null; } Event.observers = false; }, observe: function(element, name, observer, useCapture) { element = $(element); useCapture = useCapture || false; if (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.detachEvent)) name = 'keydown'; Event._observeAndCache(element, name, observer, useCapture); }, stopObserving: function(element, name, observer, useCapture) { element = $(element); useCapture = useCapture || false; if (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.detachEvent)) name = 'keydown'; if (element.removeEventListener) { element.removeEventListener(name, observer, useCapture); } else if (element.detachEvent) { try { element.detachEvent('on' + name, observer); } catch (e) {} } } }); String.prototype.strPad = function(side, len, chr) { if (!chr) chr = ' '; var s = this; var left = side.toLowerCase()=='left'; while (s.length<len) s = left ? chr + s : s + chr; return s; }; String.prototype.strPadLeft = function(len, chr) { return this.strPad('left',len,chr); }; String.prototype.strPadRight = function(len, chr) { return this.strPad('right',len,chr); }; String.prototype.zeroFill = function(len) { return this.strPadLeft(len,'0'); }; String.prototype.truncate = function(length, truncation) { length = length || 30; truncation = truncation === undefined ? ' ...' : truncation; return this.length > length ? this.slice(0, length - truncation.length) + truncation : this; }; String.prototype.trim = function(mask) { tmp = this.rtrim(mask); return tmp.ltrim(mask); }; String.prototype.ltrim = function(mask) { if( mask === undefined ) re = new RegExp("^\\s+"); else re = new RegExp("^("+mask+")+"); return this.replace(re, ''); }; String.prototype.rtrim = function(mask) { if( mask === undefined ) re = new RegExp("\\s+$"); else re = new RegExp("("+mask+")+$"); return this.replace(re, ''); }; String.prototype.stripTags = function() { return this.replace(/<\/?[^>]+>/gi, ''); }; String.prototype.toArray = function() { return this.split(''); }; String.prototype.dumpExtended = function(){ for(key in this){ if(key.inPrototype(this)) document.write("\/\/ String."+key+"\n<br>"); } }; String.prototype.inPrototype = function(obj){ try{ proto=obj.constructor.prototype; if( proto!=null && proto!=undefined ) return proto[this] && proto[this] == obj[this]; else return false; }catch(e){ return false; } }; function foreach(arr, callback) { for(key in arr){ callback(key, arr[key]); } }; function inArray(arr, value){ for(key in arr){ if(value==arr[key]) return true; } return false; }; function arrayKeys(arr, needle){ found = []; for ( key in arr ) { if( typeof needle != 'undefined' ){ if( arr[key] == needle ) found.push(key); } else { found.push(key); } } return found; }; function arrayKeyExists(arr, needle){ for ( key in arr ) { if( key == needle ) return true; } return false; }; function arrayValues(arr){ values = []; for ( key in arr ) { values.push(arr[key]); } return values; }; function first(arr){ first=null; for(key in arr) { first = arr[key]; break; } return first; }; function last(arr){ last=null; for(key in arr){ last = arr[key]; } return last; }; function count(arr){ i=0; for(key in arr) ++i; return i; }; function clear(arr){ return []; }; function hasNegative(arr){ for(key in arr){ if(arr[key]<0) return true; } return false; }; var df = document.forms; function reloadCaptcha(){ document.images.captchaImg.src = '/captcha.php?rnd=' + Random(); }; function setActiveImage(sender, sourse){ $('galleryActive').src = sourse; for(sta=0;sta<gallerylen;++sta) $('galleryThumbnail'+sta).className = 'normal'; sender.className = 'active'; }; function loadLocations(sender){ iDistrict = df.advSearchFrm.elements.district; iLocation = df.advSearchFrm.elements.asearch_location; aDistrict = df.advSearchFrm.elements['asearch_district[]']; clearMenu(aDistrict); clearMenu(iDistrict); clearMenu(iLocation); if(parseInt(sender.value)){ addOption(iLocation, [0,'-- All cities --']); loadMenu(sender, iLocation, 1); } } function loadDistricts(sender){ iDistrict = df.advSearchFrm.elements.district; aDistrict = df.advSearchFrm.elements['asearch_district[]']; clearMenu(aDistrict); clearMenu(iDistrict); loadMenu(sender, iDistrict, 2); } function loadMenu(sender, target, type){ if(sender.value){ if(res = Ajax.Request('/ajax.php?cs='+type+'&id='+sender.value+'&rnd='+Random(), false, false)){ foreach(res.split(';'), function(key, val){ addOption(target, val.split('=')) }); } } } function notebookAdd(sender,id){ if(res = Ajax.Request('/ajax.php?cs=4&id='+id+'&rnd='+Random(), false, false)){ sender.onclick=function(){return false;}; sender.style.color = '#cacaca'; alert(res); } } function notebookDelete(sender,id,key){ if(res = Ajax.Request('/ajax.php?cs=5&id='+id+'&rnd='+Random(), false, false)){ $('notebookitem_'+key).style.display='none'; alert(res); } } function nextListing(){ if(res = Ajax.Request('/ajax.php?cs=3&rnd='+Random(), false, false)){ document.getElement('toplisting').innerHTML = res; } } function clearMenu(target){ for(icl=target.options.length-1;icl>=0;--icl) { target.options[icl] = null; } } function addOption(target, data){ for(tcl=target.options.length-1;tcl>=0;--tcl) if(target.options[tcl].value==data[0]) return; target.options[target.options.length] = new Option(data[1], data[0]); target.selectedIndex = 0; } function addDistrict(sender){ iDistrict = df.advSearchFrm.elements.district; aDistrict = df.advSearchFrm.elements['asearch_district[]']; for(icl=iDistrict.options.length-1;icl>=0;--icl) { if(iDistrict.options[icl].selected&&iDistrict.options[icl].value){ addOption(aDistrict, [iDistrict.options[icl].value,iDistrict.options[icl].text]); } } } function rmDistrict(sender){ aDistrict = df.advSearchFrm.elements['asearch_district[]']; for( icl=aDistrict.options.length-1; icl>=0; --icl ) { if(aDistrict.options[icl].selected) aDistrict.options[icl] = null; } } function districtCheckAll(){ aDistrict = df.advSearchFrm.elements['asearch_district[]']; for( icl=aDistrict.options.length-1; icl>=0; --icl ) { aDistrict.options[icl].selected = true; } } function typeCheckAll(sender){ for(tca=0; tca<df.advSearchFrm.elements.length; ++tca) if(df.advSearchFrm.elements[tca].type=='checkbox') df.advSearchFrm.elements[tca].checked=true; } function typeCheckNone(sender){ for(tca=0; tca<df.advSearchFrm.elements.length; ++tca) if(df.advSearchFrm.elements[tca].type=='checkbox') df.advSearchFrm.elements[tca].checked=false; } var Ajax = { Request : function (url, callback, asynchronous, method, params) { if(asynchronous === undefined) asynchronous = false; if(method === undefined) method = 'GET'; if(callback === undefined) callback = false; if(params === undefined) params = ""; ai = new Ajax.AJAXInteraction(url, callback, asynchronous, params); if(method == 'GET') return ai.doGet(); else if(method == 'POST') return ai.doPost(); else alert("'method' must be 'GET', 'POST', or 'HEAD'."); }, AJAXInteraction : function(url, callback, asynchronous, params) { var req = init(); if(!req) alert('XMLHTTPRequest is not supported by the browser.'); if(asynchronous) req.onreadystatechange = processRequest; function init() { try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { try { return new XMLHttpRequest(); } catch (e) { try{ return window.createRequest(); } catch (e) { return false; } } } } }; function processRequest () { if (req.readyState == 4) { if (req.status == 200) { if (callback) callback(req.responseText); else if(!asynchronous) return req.responseText; } } }; this.doGet = function() { if(!req) return null; req.open("GET", url, asynchronous); req.send(null); if(!asynchronous) return processRequest(req); }; this.doPost = function() { if(!req) return null; req.open("POST", url, asynchronous); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(this.params2queryString(params)); if(!asynchronous) return processRequest(req); }; this.params2queryString = function(obj){ if(typeof obj == 'string') { return obj; } else if(typeof obj.elements != 'undefined') { return this.form2queryString(obj); } else { return this.object2queryString(obj); } }; this.object2queryString = function(obj){ ar = []; for(x in obj){ ar[ar.length] = x+'='+obj[x]; } return ar.join('&'); }; this.form2queryString = function (form){ obj = new Object(); ar = new Array(); for(i=0;i<form.elements.length;i++){ try { elm = form.elements[i]; nm = elm.name; if(nm != ''){ switch(elm.type.split('-')[0]){ case "select": for(var s=0;s<elm.options.length;s++){ if(elm.options[s].selected){ if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array(); obj[nm][obj[nm].length] = escape(elm.options[s].value); } } break; case "radio": if(elm.checked){ if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array(); obj[nm][obj[nm].length] = escape(elm.value); } break; case "checkbox": if(elm.checked){ if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array(); obj[nm][obj[nm].length] = escape(elm.value); } break; default: if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array(); obj[nm][obj[nm].length] = escape(elm.value); break; } } }catch(e){} } for(x in obj) ar[ar.length] = x+'='+obj[x].join(','); return ar.join('&'); }; } };
