function setCurrency()
{
	document.frmValuta.submit();
}

function hideMessage()
{
	if(this.location.href.indexOf("?") >= 0)
	{
		url = "&delay=1";
	}
	else
	{
		url = "?delay=1";
	}

	this.location.href = this.location.href + url;
}

function resetBox(obj)
{
	if(getElementByID(obj).value == "cauta produs")
	{
		getElementByID(obj).value = "";
	}
}

function showAgreement()
{
	if(getElementByID("ckbAcord").checked == false)
	{
		if(confirm("Sunteti de acord cu Termeni si Conditii?"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}

function setDeliveryDay(i)
{
	getElementByID("radZi").value = i;
}

function addToFavorites(logged, id)
{
	if(logged == "false")
	{
		if(window.opener != null && window.opener != "undefined")
		{
			if(window.opener.top.listare != null && window.opener.top.listare != "undefined")
			{
				window.opener.top.listare.location.href = "login.php";
			}
		}
		else if(top != null && top != "undefined")
		{
			if(top.listare != null && top.listare != "undefined")
			{
				top.listare.location.href = "login.php";
			}
		}

		self.close();
	}
	else
	{
		this.location.href = "adaugafavorite.php?idf=" + id;
	}

	return true;
}

function changeSubmitClassName(obj)
{
	getElementByID(obj).className = "submit2";
}

function resetSubmitClassName(obj)
{
	getElementByID(obj).className = "submit";
}

function resetTabs()
{
	var aTabs = new Array("Categorii", "CosRapid", "ContulMeu", "Favorite", "VeziCos", "Ajutor", "Oferte");

	for(i = 0; i < aTabs.length; i++)
	{
		if(getTopElementByID("img" + aTabs[i]) != null && getTopElementByID("img" + aTabs[i]) != undefined)
		{
			getTopElementByID("img" + aTabs[i]).src = "images/tabs/" + aTabs[i] + "_off.gif";
		}
	}
}

function showScreenShot(url)
{
	window.open(url, 'screenshot', 'top=100,left=' + (screen.width/2 - 200) + ',width=450,height=450,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0,location=0');
}

function showDetails(url)
{
	window.open(url, 'detalii', 'top=90,left=' + (screen.width/2 - 235) + ',width=470,height=550,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0,location=0');
}

function showDetails2(url)
{
	window.open(url, 'detalii2', 'top=100,left=' + (screen.width/2 - 275) + ',width=550,height=430,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0,location=0');
}

function highlightTab(tab)
{
	resetTabs();
	
	if(getTopElementByID("img" + tab) != null && getTopElementByID("img" + tab) != undefined)
	{
		getTopElementByID("img" + tab).src = "images/tabs/" + tab + "_on.gif";
	}
}

function updateTotal(price)
{
	getElementByID("divTotal").innetHTML += price;
}

function refreshTotal()
{
	top.total.location.href = top.total.location.href;
}

function addToCart(id)
{
	if(getElementByID("txtQty" + id).value == "")
	{
		getElementByID("txtQty" + id).value = 0;
	}

	qty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(qty))
	{
		qty = 0;
	}

	if(qty >= 0 && qty < 99)
	{
		getElementByID("txtQty" + id).value = qty + 1;
	}
	else if(qty >= 99)
	{
		getElementByID("txtQty" + id).value = 99;
	}

	curqty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(curqty))
	{
		curqty = 0;
	}
	
	if(getElementByID("imgCart" + id) != null && getElementByID("imgCart" + id) != "undefined")
	{
		if(curqty > 0)
		{
			getElementByID("imgCart" + id).src = "images/cart.gif";
		}
		else
		{
			getElementByID("imgCart" + id).src = "images/spacer.gif";
		}
	}

	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.cos != null && window.opener.top.cos != "undefined")
		{
			window.opener.top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.cos != null && top.cos != "undefined")
		{
			top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}

	refreshListare();
}

function closeDetails(id)
{
	curqty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(curqty))
	{
		curqty = 0;
	}

	oldqty = parseInt(getElementByID("txtOldQty" + id).value);

	if(isNaN(oldqty))
	{
		oldqty = 0;
	}

	if(oldqty != curqty)
	{
		refreshListare2();
	}

	self.close();
	return true;
}

function submitToCart(id)
{
	if(getElementByID("txtQty" + id).value == "")
	{
		getElementByID("txtQty" + id).value = 0;
	}

	qty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(qty))
	{
		qty = 0;
	}

	if(qty > 0 && qty < 99)
	{
		getElementByID("txtQty" + id).value = qty;
	}
	else if(qty >= 99)
	{
		getElementByID("txtQty" + id).value = 99;
	}
	else
	{
		getElementByID("txtQty" + id).value = "";
	}

	curqty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(curqty))
	{
		curqty = 0;
	}

	oldqty = parseInt(getElementByID("txtOldQty" + id).value);

	if(isNaN(oldqty))
	{
		oldqty = 0;
	}
	
	if(getElementByID("imgCart" + id) != null && getElementByID("imgCart" + id) != "undefined")
	{
		if(curqty > 0)
		{
			getElementByID("imgCart" + id).src = "images/cart.gif";
		}
		else
		{
			getElementByID("imgCart" + id).src = "images/spacer.gif";
		}
	}

	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.cos != null && window.opener.top.cos != "undefined")
		{
			window.opener.top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.cos != null && top.cos != "undefined")
		{
			top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}

	refreshListare();
}

function refreshListare()
{
	if(this.location.pathname.indexOf(escape("listare[bottom].php")) < 0)
	{
		if(this.location.pathname.indexOf(escape("listare2[bottom].php")) < 0)
		{
			if(this.location.pathname.indexOf(escape("ofertespeciale[bottom].php")) < 0)
			{
				if(this.location.pathname.indexOf(escape("vezicos.php")) < 0)
				{
					if(this.location.pathname.indexOf(escape("detalii.php")) < 0)
					{
						if(this.location.pathname.indexOf(escape("detalii2.php")) < 0)
						{
							if(window.opener != null && window.opener != "undefined")
							{
								if(window.opener.top.listare != null && window.opener.top.listare != "undefined")
								{
									if(window.opener.top.listare.location.pathname.indexOf(escape("vezicos.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("detalii.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("detalii2.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("listare.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("listare2.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("ofertespeciale.php")) >= 0)
									{
										window.opener.top.listare.location.href = window.opener.top.listare.location.href;
									}
								}
							}
							else if(top != null && top != "undefined")
							{
								if(top.listare != null && top.listare != "undefined")
								{
									if(top.listare.location.pathname.indexOf(escape("vezicos.php")) >= 0 || top.listare.location.pathname.indexOf(escape("detalii.php")) >= 0 || top.listare.location.pathname.indexOf(escape("detalii2.php")) >= 0 || top.listare.location.pathname.indexOf(escape("listare.php")) >= 0 || top.listare.location.pathname.indexOf(escape("listare2.php")) >= 0 || top.listare.location.pathname.indexOf(escape("ofertespeciale.php")) >= 0)
									{
										top.listare.location.href = top.listare.location.href;
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function refreshListare2()
{
	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.listare != null && window.opener.top.listare != "undefined")
		{
			if(window.opener.top.listare.location.pathname.indexOf(escape("vezicos.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("detalii.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("detalii2.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("listare.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("listare2.php")) >= 0 || window.opener.top.listare.location.pathname.indexOf(escape("ofertespeciale.php")) >= 0)
			{
				window.opener.top.listare.location.href = window.opener.top.listare.location.href;
			}
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.listare != null && top.listare != "undefined")
		{
			if(top.listare.location.pathname.indexOf(escape("vezicos.php")) >= 0 || top.listare.location.pathname.indexOf(escape("detalii.php")) >= 0 || top.listare.location.pathname.indexOf(escape("detalii2.php")) >= 0 || top.listare.location.pathname.indexOf(escape("listare.php")) >= 0 || top.listare.location.pathname.indexOf(escape("listare2.php")) >= 0 || top.listare.location.pathname.indexOf(escape("ofertespeciale.php")) >= 0)
			{
				top.listare.location.href = top.listare.location.href;
			}
		}
	}
}

function removeFromCart(id)
{
	if(getElementByID("txtQty" + id).value == "")
	{
		getElementByID("txtQty" + id).value = 0;
	}

	qty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(qty))
	{
		qty = 0;
	}

	if(qty > 1 && qty <= 99)
	{
		getElementByID("txtQty" + id).value = qty - 1;
	}
	else if(qty <= 1)
	{
		getElementByID("txtQty" + id).value = "";
	}

	curqty = parseInt(getElementByID("txtQty" + id).value);

	if(isNaN(curqty))
	{
		curqty = 0;
	}

	if(getElementByID("imgCart" + id) != null && getElementByID("imgCart" + id) != "undefined")
	{
		if(curqty > 0)
		{
			getElementByID("imgCart" + id).src = "images/cart.gif";
		}
		else
		{
			getElementByID("imgCart" + id).src = "images/spacer.gif";
		}
	}

	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.cos != null && window.opener.top.cos != "undefined")
		{
			window.opener.top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.cos != null && top.cos != "undefined")
		{
			top.cos.location.href = 'cart.php?idf=' + getElementByID("hidID" + id).value + "&qty=" + curqty + "&cod=" + getElementByID("hidCod" + id).value + "&btnAddQty=OK";
		}
	}

	refreshListare();
}

function removeAllFromCart(id, code)
{
	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.cos != null && window.opener.top.cos != "undefined")
		{
			window.opener.top.cos.location.href = 'cart.php?idf=' + id + "&qty=0&cod=" + code + "&btnAddQty=OK";
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.cos != null && top.cos != "undefined")
		{
			top.cos.location.href = 'cart.php?idf=' + id + "&qty=0&cod=" + code + "&btnAddQty=OK";
		}
	}

	refreshListare();

	self.close();
	return true;
}

function compareTo(id1, id2)
{
	if(window.opener != null && window.opener != "undefined")
	{
		if(window.opener.top.listare != null && window.opener.top.listare != "undefined")
		{
			window.opener.top.listare.location.href = "comparare.php?id1=" + id1 + "&id2=" + id2;
		}
	}
	else if(top != null && top != "undefined")
	{
		if(top.listare != null && top.listare != "undefined")
		{
			top.listare.location.href = "comparare.php?id1=" + id1 + "&id2=" + id2;
		}
	}

	self.close();
	return true;
}

function showWeRecommend()
{
	top.recomandari.location.href = top.recomandari.location.href;
}

function showPrintVersion()
{
	window.open('print.php', '_blank', '');
}

function showThankYouForShopping()
{
	top.location.href = 'htm/thankyouforshopping.htm';
}

function showComment(id)
{
	window.open("comentarii.php?id=" + id, 'comentarii', 'top=100,left=' + (screen.width/2 - 200) + ',width=400,height=250,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0,location=0');
}


function getElementByID(idVal)
{
	if (document.getElementById != null)
	{
		return document.getElementById(idVal);
	}
	
	if(document.all != null)
	{
		return document.all.item(idVal);
	}

	return null;
}

function getTopElementByID(idVal)
{
	if (document.getElementById != null)
	{
		return top.document.getElementById(idVal);
	}
	
	if(document.all != null)
	{
		return top.document.all.item(idVal);
	}

	return null;
}

function setBackground(startcolor, endcolor, gradient)
{
	document.body.style.filter="progid:DXImageTransform.Microsoft.Gradient(startColorstr="+startcolor+", endColorstr="+endcolor+", GradientType="+gradient+")";
}
