document.extend = function(destination, source) { for (property in source) destination[property] = source[property]; return destination; }; document.getElement = function (name){return document.getElementById ? document.getElementById(name) : document.all ? document.all(name) : null;}; document.getObject = document.getElement; var $ = function (element){ if (typeof element == 'string') return document.getElement(element); else if (typeof element == 'object') return element; else return null; }; 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; } }; 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; } } }; document.resizeToContent = function(move) { pSize = document.getPageSize(); window.resizeBy(pSize[0]-pSize[2], pSize[1]-pSize[3]); if(move!==undefined){ x = parseInt(screen.width / 2.0) - (pSize[0] / 2.0); y = parseInt(screen.height / 2.0) - (pSize[1] / 2.0); window.moveTo(x, y); } }; document.getPageSize = function() { var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) ; return arrayPageSize; }; if (!window.Event) var Event = new Object(); document.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) {} } } }); Event.observe(window, 'unload', Event.unloadCache, false); 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; }; 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; }; if (location.replace == null){ location.replace = location.assign; } var Location = { replace : function(url){ location.replace(url); return false; }, redirect : function (url){ location.href=url; return false; }, back : function (){ history.back(); return false; } }; var msgWindow; function openWindow(url, _w, _h, scroll){ posX = (screen.width) ? (screen.width - _w)/ 2 : 0; posY = (screen.height) ? (screen.height - _h)/ 2 : 0; window.focus(); try{if( typeof(msgWindow)=='object') msgWindow.close();}catch(e){} msgWindow = open('','window1','top='+posY+', left='+posX+', width='+_w+', height='+_h+', menubar=no, status=yes, location=no, toolbar=no, scrollbars='+scroll); msgWindow.location.href = url; if(msgWindow.opener==null) msgWindow.opener=self; msgWindow.focus(); }; function popup(url,width,height) { mywindow = window.open (url,'window1','location=0,status=0,scrollbars=0,width='+width+',height='+height); mywindow.moveTo(300,180); }; function tooltip(o,m){ f = getOffset(o); reBr = /<br \/>/i; return reBr.test(m) ? overlib( m, FIXX,f.x + 2, FIXY,f.y - 32, WRAP ) : overlib( m, FIXX,f.x + 2, FIXY,f.y - 20, WRAP ); }; function getOffset(o){ f={}; f.x=o.offsetLeft; f.y=o.offsetTop; p=o.offsetParent; while(p !=null){ f.y+=p.offsetTop; f.x+=p.offsetLeft; p=p.offsetParent; } return f; }; function strmaxlen(sender,len){ if(sender.value.length>len) sender.value = sender.value.substr(0, len); }; function addOption(target, option){ tlength = target.options.length - 1; for(toc=tlength;toc>=0;--toc) if(target.options[toc].value==option.value) return false; target.options[target.options.length] = new Option(option.text, option.value); return true; }; function oldEmoticon(text) { txtarea = document.forms.addCommentFrm.elements.comment; return insertAtCursor(txtarea, ' ' + text + ' '); }; function emoticon(frm, element, text) { txtarea = eval('document.forms.' + frm + '.elements.' + element); return insertAtCursor(txtarea, ' ' + text + ' '); }; function insertAtCursor(myField, myValue) { if (document.selection) { var temp; myField.focus(); sel = document.selection.createRange(); temp = sel.text.lenght; sel.text = myValue; if (myValue.length == 0) { sel.moveStart('character', myValue.length); sel.moveEnd('character', myValue.length); } else { sel.moveStart('character', -myValue.length + temp); } sel.select(); } else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.selectionStart = startPos + myValue.length; myField.selectionEnd = startPos + myValue.length; } else { myField.value += myValue; } }; function showSearchFrm(frm){ if(target = $(frm)){ target.style.display = target.style.display == 'none' ? 'block' : 'none'; } }; function showCommentsFrm(){ if(target = $('addComment')){ target.style.display = 'block'; } }; function validateCommentsFrm(sender){ if(!sender.elements.comment.value){ alert('Моля, въведете коментар!'); return false; } return true; };