function $(id) {
    return document.getElementById( id );
}

function popup(url,name,width,height,position,wplus,hplus,focus,left,top,menubar,status,toolbar,scrollbar,resizable,scrx,scry,directories,loc) {
	if ( !url ) return false;
	if ( !name ) name = 'popupWin';
	if ( !width ) width = '';
	if ( !height ) height = '';
	if ( !directories ) directories = 'no';
	if ( !loc ) loc = 'no';
	if ( !menubar ) menubar = 'no';
	if ( !status ) status = 'no';
	if ( !toolbar ) toolbar = 'no';
	if ( !scrollbar ) scrollbar = 'no';
	if ( !resizable ) resizable = 'no';
	if ( !scrx ) scrx = '100';
	if ( !scry ) scry = '100';
	if ( !left ) left = '100';
	if ( !top ) top = '100';
	if ( wplus ) width  += wplus;
	if ( hplus ) height += hplus;

		var winleft = (screen.width - width) / 2;
		var wintop = (screen.height -  height) / 2;

    var popupWin = window.open(url,name,'width='+width+'px,height='+height+'px,left='+winleft+',top='+wintop+',menubar='+menubar+',status='+status+',toolbar='+toolbar+',scrollbars='+scrollbar+',resizable='+resizable+',screenX='+scrx+',screenY='+scry+'directories='+directories+',location='+loc);

	if ( focus ) popupWin.focus();
}

function changeImage(img, img_src) {
  img.src = img_src;
}

function confirmMsg(msg) {
	var con = confirm(msg);
	if (con) return true;
	else return false;
}

function addEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType,fn,useCapture);
		return true;
	} else if(obj.attachEvent){
		return obj.attachEvent("on"+evType,fn);
	} else {
		return false;
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = '*';
	var elems = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	var i = 0;
	for (var j = 0; j < elems.length; j++) {
		if ( pattern.test(elems[j].className) ) {
			classElements[i++] = elems[j];
		}
	}
	return classElements;
}

function collapsible() {
	var collap = getElementsByClass("collapsible",null,"div");
	if (collap) {
		for(i in collap) {
			var dt = collap[i].getElementsByTagName("dt");
			for(j in dt) {
				dt[j].onclick = function() {
					this.parentNode.className = this.parentNode.className?'':'active';
					return false;
				}
			}
		}
	}
}

addEvent(window, 'load', collapsible);

function InputTipp() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}

	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}

}

addEvent(window, 'load', InputTipp);

function innerDimension() {
	var x,y;

	// all except Explorer
	if (self.innerHeight)
	{
		x = self.innerWidth;
		y = self.innerHeight;

	// Explorer 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	
	// other Explorers
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	return {width: x, height: y};
}

function offsetDimension() {
	var x,y;

	// all except Explorer
	if (self.pageYOffset)
	{
		x = self.pageXOffset;
		y = self.pageYOffset;

	// Explorer 6 Strict
	} else if (document.documentElement && document.documentElement.scrollTop) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;

	// all other Explorers
	} else if (document.body) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	return {x: x, y: y}
}

function changeBigPic(bigpic) {
  document.getElementById('changebigpic').src = "images/ingatlan/" + bigpic;
}

function rpc(str){
    head = document.getElementsByTagName('head').item(0);
    script=document.createElement('script');
    script.src= str;
    script.type='text/javascript';
    script.defer=true;
    void(head.appendChild(script));
}
