var common = {

	init:function(){

		function initSearchInput(){
			var input = document.getElementById('searchinput');
			if(input.value == ''){
				input.value = input.title;
				common.addClassName('standby', input);

			}
			input.onfocus = function(){
				if(this.value == this.title){
					this.value = '';
					common.removeClassName('standby', input);
				}
			}
			input.onblur = function(){
				if(this.value == ''){
					this.value = this.title;
					common.addClassName('standby', input);
				}
			}
		}
		
		function initAnchors(){
			var anchors = document.getElementsByTagName('a');
			
			for(var i=0; i<anchors.length; i++){
				if(common.hasClassName('anchor', anchors[i])){
					anchors[i].onmouseover = function(){
						this.innerHTML = '{'+this.href.toString().substring(this.href.toString().lastIndexOf('#'))+'}';
						this.parentNode.style.color = 'white';
					}
					anchors[i].onmouseout = function(){
						this.innerHTML = '{#}';
						this.parentNode.style.color = '';
					}
				}
			}
		}

		function initRoundedBoxes(){

			var elements = new Array('div', 'img', 'p', 'form', 'pre', 'table');
			var boxes;
			var i;

			for(var e=0; e<elements.length; e++){
				boxes = document.getElementsByTagName(elements[e]);
				for(i=0; i<boxes.length; i++){
					if(common.hasClassName('frame',boxes[i]) || elements[e] == 'pre' || elements[e] == 'table'){
						boxes[i].style.backgroundImage = 'url('+common.getMetaContent('basehref')+'shell/layout/box'+boxes[i].offsetWidth+'x'+boxes[i].offsetHeight+'.png)';
					}
				}
			}
		}

		common.addEvent(window,'load',initSearchInput);
		common.addEvent(window,'load',initRoundedBoxes);
		common.addEvent(window,'load',initAnchors);

	},
	parseInt:function(value){
		var intval = parseInt(value);
		return 	isNaN(intval) ? 0 : intval;
	},
	addEvent:function(element, eventName, func){
		if(element.addEventListener){
			element.addEventListener(eventName, func, false);
		}else if (element.attachEvent){
			element.attachEvent('on'+eventName, func);
		}
	},
	removeClassName:function(cName,node){
		node.className = node.className.replace(new RegExp("\\s?"+cName+"\\b"), "");
	},
	addClassName:function(cName,node){
		if(common.hasClassName(cName,node)){1
			return;
		}
		node.className += (node.className == "" ? cName : " "+cName);
	},
	hasClassName:function(cName,node){
		return (node.className.match(new RegExp("\\s?"+cName+"\\b")));
	},
	getFirstChildByName:function(cName,node){
		var nodes = node.childNodes;
		for(var j=0;j<nodes.length;j++){
			if(nodes[j].nodeName == cName){
				return nodes[j];
			}
		}
		return false;
	},
	strReplace:function(search,replace,subject){
		var arr = subject.split(search);
		return arr.join(replace);
	},
	getMetaContent:function(name){
		var arr = document.getElementsByTagName('meta');

		for(var i=0; i<arr.length; i++){
			if(arr[i].name == name){
				return arr[i].content;
			}
		}
		return '';
	}
}

common.init();