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('&'); }; } }; 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; }; function getRandom(){ return Number.prototype.getRandom(); }; function isDefined(obj){ return typeof(obj) == 'undefined' || obj == null ? false : true; }; 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('Popup blocked'); } }; function preload(){ hl_images = preload.arguments; for(i=0; i<hl_images.length; i++){ imghl[(hl_images[i])]=new Image; imghl[(hl_images[i])].src=''+hl_images[i]; } }; function swap(n,i){ try{ if(!swap.arguments.length){ d[r_n].src=r_s; }else{ r_s=d[n].src; r_n=n;d[n].src=imghl[i].src } }catch(e){} }; function reloadCaptcha(){ document.images.captchaImg.src = '/captcha.php?rnd=' + getRandom(); }; var active = false; function sendContactsForm(frm){ if(active) return alert('Sending your message, please wait.'); active = true; res = Ajax.Request('/posts.php',false,false,'POST',frm).trim(); if(res=='PARAMS_ERROR'){ document.getElement('invalid').style.display='block'; document.getElement('mailer_error').style.display='none'; } else if(res=='MAILER_ERROR') { document.getElement('invalid').style.display='none'; document.getElement('mailer_error').style.display='block'; } else if(res=='SUCCESS'){ document.getElement('contact_us').style.display='none'; document.getElement('message_sent').style.display='block'; } active = false; }; 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; } }; 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; } } }; Number.prototype.toColorPart = function(){ var digits = this.toString(16); if (this < 16) return '0' + digits; return digits; }; Number.prototype.getRandom = function(){ randomNum = ''; for (i=0; i<2; ++i) { tmp = Math.random()*8; randomNum += tmp.toString().replace(".",""); } return randomNum; };