var popupTimeout = 3000;

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function removeShippingOptions() {
          	if (document.getElementById('shippingpayment')!='undefined') document.getElementById('shippingpayment').outerHTML = "";
          	if (document.getElementById('shippingaddress')!='undefined') document.getElementById('shippingaddress').outerHTML = "";
          	if (document.getElementById('paymentaddress')!='undefined') document.getElementById('paymentaddress').outerHTML = "";
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function getQueryValues(url, exclude) {
	var args = new Object();
	if (exclude==undefined) exclude = "";
	if ((url==undefined) || (url=="")) {
		var query = location.search.substring(1);
		var rurl = "";
	} else {
		var q = url.split("?");
		var rurl = q[0];
		(q.length>1) ? query = q[q.length-1] : query = "";
	}
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		if (exclude!=argname) {
			var value = pairs[i].substring(pos+1);
			args[argname] = unescape(value);
		}
	}
	if (rurl!="") {
		var qs = "";
		for (var i in args)	{
			if (qs.length>0) qs = qs + '&';
			qs = qs + i+"="+args[i];
		}
		if (qs.length>0) qs = "?"+qs;
		return rurl+qs;
	} else {
		return args;
	}
}

function getElementLeft(elem) {
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function popupY() {
	var y = 335;
	if( typeof( window.pageYOffset ) == 'number' ) {
		y = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		y = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		y = document.documentElement.scrollTop;
	}
	if (y>335) {
		return y;
	} else {
		return 335;
	}
}

function updateCartPopupPosition() {
	document.getElementById("popup_cart").style.top = popupY()+"px";
	if (document.getElementById("popup_cart").style.visibility == 'visible') setTimeout("updateCartPopupPosition()", 50);
}

function showCartPopup() {
	document.getElementById("popup_cart").style.left = (getElementLeft(document.getElementById("top2"))+13)+"px";
	document.getElementById("popup_cart").style.visibility = 'visible';
	document.getElementById("popup_cart").style.display = 'block';
	document.getElementById("popup_cart").style.zindex = 6;
	document.getElementById("popup_cart").style.top = popupY()+"px";
	setTimeout("updateCartPopupPosition()", 50);
	setTimeout("hideCartPopup()", popupTimeout);
}

function hideCartPopup() {
	document.getElementById("popup_cart").style.visibility = 'hidden';
	document.getElementById("popup_cart").style.display = 'none';
}

function updateWishlistPopupPosition() {
	document.getElementById("popup_wishlist").style.top = popupY()+"px";
	if (document.getElementById("popup_wishlist").style.visibility == 'visible') setTimeout("updateWishlistPopupPosition()", 50);
}

function showWishlistPopup() {
	document.getElementById("popup_wishlist").style.left = (getElementLeft(document.getElementById("wishlistimage"))+13)+"px";
	document.getElementById("popup_wishlist").style.visibility = 'visible';
	document.getElementById("popup_wishlist").style.display = 'block';
	document.getElementById("popup_wishlist").style.top = popupY()+"px";
	setTimeout("updateWishlistPopupPosition()", 50);
	setTimeout("hideWishlistPopup()", popupTimeout);
}

function hideWishlistPopup() {
	document.getElementById("popup_wishlist").style.visibility = 'hidden';
	document.getElementById("popup_wishlist").style.display = 'none';
}

function removeFromCart(productid, amount) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top2.main.shippingpayment&mode=remove&productid='+productid+'&amount='+amount);
}

function increaseCartAmount(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top2.cart.shippingpayment&mode=increase&productid='+productid);
}

function decreaseCartAmount(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top2.cart.shippingpayment&mode=decrease&productid='+productid);
}

function addToWishList(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top1.popup_wishlist&mode=addtowishlist&productid='+productid, true, showWishlistPopup);
}

function addToWishList2(productid) {
	var e = document.getElementById("sizeselector");
	if ((e != 'undefined') && (e != null)) {
		loadXMLDoc(currentpageurl+'?requestedcontentid=top1.popup_wishlist&mode=addtowishlist&productid='+e.value, true, showWishlistPopup);
	} else {
		addToWishList(productid);
	}
}

function removeFromWishList(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top1.top2.main&mode=removefromwishlist&productid='+productid);
}

function removeAllFromWishList() {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top1.top2.main&mode=removeallfromwishlist');
}

function toggleWishListNotify(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top1.main&mode=togglenotify&productid='+productid);
}

function moveAllFromWishListToCart() {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top2.popup_cart&mode=addallfromwishlist', false);
	removeAllFromWishList();
}

function moveFromWishListToCart(productid) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=top2.popup_cart&mode=add&productid='+productid+'&amount=1', false, showCartPopup);
	removeFromWishList(productid);
}

function handleSPE(event) {
	var e = document.elementFromPoint(event.clientX, event.clientY);
	enableproductlink = (e.name!='cartbutton');
}

function submitshipping() {
	var radios = document.getElementsByName("shippingid");
	var rad_val = '';
	for (var i=0; i < radios.length; i++) {
	if (radios[i].checked) {
			rad_val = radios[i].value;
		}
	}
	
	if (rad_val!='') loadXMLDoc(currentpageurl+'?requestedcontentid=cart&mode=changeshipping&spid='+rad_val);
}

var strUserAgent = navigator.userAgent.toLowerCase(); 
var isIE = strUserAgent.indexOf("msie") > -1;
var cyclehotproducts = true;
 
function raiseEvent(object, event) {
	if (isIE) {
		object.fireEvent("on"+event);
	} else {
		var e = document.createEvent('HTMLEvents');
		e.initEvent(event, false, false);
		object.dispatchEvent(e);
	}
}

function addProductToCart(id, amount) {
	loadXMLDoc(currentpageurl+'?requestedcontentid=topcart&mode=add&productid='+id+'&amount='+amount, true, showCart);
	document.getElementById('sclf').scrollIntoView(true);
}

function addToCart(productid, amount, variations) {
	if (variations>1) {
		loadXMLDoc(currentpageurl+'?requestedcontentid=main&product='+productid);
	} else {	
		loadXMLDoc(currentpageurl+'?requestedcontentid=top2.popup_cart&mode=add&productid='+productid+'&amount='+amount, true, showCartPopup);
	} 
}

function addVariToCart() {
	var x = $('input.productc');
	var v = false;
	for (i=0; i<x.length; i++) {
		if (x[i].value > 0) {
			v = true;
			loadXMLDoc(currentpageurl+'?requestedcontentid=top2.popup_cart&mode=add&productid='+x[i].name+'&amount='+x[i].value, true, showCartPopup);
			x[i].value = '';
		}
	}
	if (!v) {
		alert('Nem adta meg a kosárba teendő mennyiséget!');
	} else {
		//document.getElementById('sclf').scrollIntoView(true);
	}
}

function addVariToWishList() {
	var x = $('input.productc');
	for (i=0; i<x.length; i++) {
		if (x[i].value > 0) {
			loadXMLDoc(currentpageurl+'?requestedcontentid=top1.popup_wishlist&mode=addtowishlist&productid='+x[i].name, true, showWishlistPopup());
			x[i].value = '';
		}
	}
}

function addToCart2(productid, amount) {
	var e = document.getElementById("sizeselector");
	if ((e != 'undefined') && (e != null)) {
		loadXMLDoc(currentpageurl+'?requestedcontentid=top2.popup_cart&mode=add&productid='+e.value+'&amount='+amount, true, showCartPopup);
	} else {
		addToCart(productid, amount);
	}
}


