function open_window(url, name, x_size, y_size) {
	n = window.open(url, name, 'width=' + x_size + ',height=' + y_size + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');
	n.focus();
}
function open_window2(url, name, x_size, y_size) {
	n = window.open(url, name, 'width=' + x_size + ',height=' + y_size + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	n.focus();
}

var IE = document.all ? true:false;
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement && document.documentElement.clientWidth;

function showhide(level, shhi, text) {
        ob = document.getElementById(level);
        if (ob) {
                if (shhi == 1) {
                        ob.innerHTML = '<p class="help" style="width:175px;margin:0;">'+text+'<\/p>';
                        ob.style.display = "block";
                }
                else ob.style.display = "none";
                cbottom = has_inner ? pageYOffset + window.innerHeight : has_element ? document.documentElement.scrollTop + document.documentElement.clientHeight : document.body.scrollTop + document.body.clientHeight;
                cbottom = cbottom - parseInt(ob.offsetHeight + 0);
                ob.style.top = cbottom+'px';
        }
}

var addCart_timer;

function getPos(obj)
{
    var output = new Object();
    var mytop=0, myleft=0;

    //ie6, ie7, ie5 eseten
    if(/MSIE 6/i.test(navigator.userAgent) || /MSIE 7/i.test(navigator.userAgent) || /MSIE 5/i.test(navigator.userAgent))
    {
    		while(obj)
    		{
        	    mytop+= obj.offsetTop;
        	    myleft+= obj.offsetLeft;
        	    obj=obj.offsetParent;
    		}
    		output.left = myleft+document.body.scrollLeft - document.body.clientLeft;
    		output.top = mytop+document.body.scrollTop - document.body.clientTop;
    }
    else { //minden mas esetben
	obj.style.position='absolute';

    		output.left = obj.offsetLeft;
    		output.top = obj.offsetTop;

    		obj.style.position='static';
    }
    return output;
}
function showBasket() {
    objK=document.getElementById('kosarID');

    var divTag = document.getElementById("basketShow");
    var iFrameTag = document.getElementById("selblock");
    var contTag = document.getElementById("BStartalom");
    var ptop = 0; var pleft=0;

    if(/MSIE 6/i.test(navigator.userAgent) || /MSIE 7/i.test(navigator.userAgent) || /MSIE 5/i.test(navigator.userAgent)) { ptop=objK.offsetHeight+1; pleft=344; }
    else { ptop=(objK.offsetHeight/2); pleft=402; }

    divTag.style.left=(getPos(objK).left-pleft)+'px';
    divTag.style.top=(getPos(document.getElementById('kosarID')).top+ptop)+'px';

    divTag.style.display='block';

    divTag.style.height=contTag.offsetHeight+'px';

    iFrameTag.style.height = contTag.offsetHeight+'px';
    iFrameTag.style.zIndex = divTag.style.zIndex-1;

    contTag.style.zIndex = divTag.style.zIndex;
	makeAjaxCart('index.php?a=ax&f=listcart', 'BStartalom');
}
function hideBasket() {
    document.getElementById('basketShow').style.display='none';
}
function makeAjaxCart(url, ob, return_xml, return_func) {
	var http_request = false;
	var text = '';

	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				http_request = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {}
		}
	}

	if (!http_request) {
		return false;
	}

	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					text = http_request.responseXML;
				} else {
					text = http_request.responseText;
				}
				if (return_func) {
					eval(return_func);
				}
				else {
					var obj = document.getElementById(ob);
					if (obj) {
						obj.innerHTML = text;
					}
					else {
						if (text != '') eval(text);
					}
				}
			} else {
			}
		}
	}
	url = url + '&rand=' + Math.round(10000000 * Math.random());
	http_request.open('GET', url, true);
	http_request.send(null);
}

function addCart(cat, id) {
	var objOverlay = document.getElementById('Bodyoverlay');
	var divTag = document.getElementById('AddCartShow');
	var objBody = document.getElementsByTagName("body").item(0);
	var windowWidth, windowHeight;
	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;
	}

	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;
	}
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	if (!divTag) {
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','Bodyoverlay');
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '5000';
		objOverlay.style.width = '100%';
		objOverlay.style.opacity = '0.9';
		objOverlay.style.filter = 'Alpha(opacity=90)';
		objOverlay.onclick = function () { hideCart(); return false; }
		objBody.insertBefore(objOverlay, objBody.firstChild);
		var divTag = document.createElement('div');
		divTag.setAttribute('id', 'AddCartShow');
		divTag.style.display = 'none';
		divTag.style.position = "absolute";
		divTag.style.zIndex = 5001;
		document.body.appendChild(divTag);
	}
	if (divTag) {
		divTag.style.width = '534px';
		divTag.style.height = '265px';
		divTag.className = 'cartbox';
		divTag.style.display = 'block';
		objOverlay.style.width = pageWidth + "px";
		objOverlay.style.height = pageHeight + "px";
		selects = document.getElementsByTagName("select");
		for (i = 0; i < selects.length; i++) {
			selects[i].style.visibility = "hidden";
		}
		objOverlay.style.display = 'block';
		divTag.style.top = yScroll + (windowHeight / 2 - 75) + "px";
		divTag.style.left = pageWidth / 2 - 250 + "px";
		url = "index.php?a=ax&f=addcart&cat=" + cat + "&id=" + id;
		makeAjaxCart(url, "AddCartShow");
		clearTimeout(addCart_timer);
		addCart_timer = setTimeout("hideCart()", 6000);
		url = "index.php?a=ax&f=cartdiv";
		makeAjaxCart(url, "cart");
		url = "index.php?a=ax&f=cartdiv2";
		makeAjaxCart(url, "cart2");
		var obj = document.getElementById('cart2');
		if (obj) {
			obj.style.display = 'block';
		}
	}
}
function hideCart() {
	var objOverlay = document.getElementById('Bodyoverlay');
	var divTag = document.getElementById('AddCartShow');

	objOverlay.style.display = 'none';
	divTag.style.display = 'none';
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	url = "index.php?a=ax&f=cartdiv";
	makeAjaxCart(url, "cart");
	url = "index.php?a=ax&f=cartdiv2";
	makeAjaxCart(url, "cart2");
	var obj = document.getElementById('cart2');
	if (obj) {
		obj.style.display = 'block';
	}
}

function ShowCat(id) {
	var v = document.getElementById('down_' + id);
	if (v) {
		if (v.style.display=='none') v.style.display='block';
		else v.style.display='none';
	}
}

