function show_hide(id) {
	el = document.getElementById(id);

	if(el.style.display == 'none') {
	   el.style.display = 'block'
	} else {
	   el.style.display = 'none'
	} 
}


function startAjax()
{
	Ajax.Responders.register({
	  // when an Ajax request is started, show the indicator
		onCreate: function() {
		if (Ajax.activeRequestCount > 0)
		  Element.show($("indicator"));
	  },
		// when an Ajax request is finished, hide the indicator
		onComplete: function() {
		if (Ajax.activeRequestCount == 0)
		  Element.hide($("indicator"));
	  }
	});
}

// add item to cart
function addToCart(id)
{
	new Ajax.Request(path_to_cart_scripts + "server.Cart.php?action=addToCart", {
		parameters: "id=" + id,
		onSuccess: function(resp) {
			//alert(resp.responseText);
			var cartUpdate = eval('(' + resp.responseText + ')');
			var isNew = cartUpdate['cartItemDetails'][0].isNew;
			// if this item is new in the cart, inject it inside, otherwise update the qty and subtotal
			if (isNew == 1)
			{
				var js_onclick = '';
				if(id == 4) { // INSTAL.
					js_onclick = 'if(confirm(\'Va recomandam ca, la cumpararea produsului, sa optati pentru montaj si instalare autorizata, pentru a beneficia de garantie.\')) { removeFromCart(' + id + ');return false; } else { return false; }';
				} else {
					js_onclick = 'return removeFromCart(' + id + ')';
				}
				var newItem = '<div id="cartItem_' + id + '" style="display:none" class="row">';
				newItem += '<div class="cell1" id="cartItemQty_' + id + '" valign="top">1</div>';
				newItem += '<div class="cell2">' + cartUpdate['cartItemDetails'][0].title + '</div>';
				newItem += '<div class="cell3" id="cartItemPrice_' + id + '">' + cartUpdate['cartItemDetails'][0].newPrice + ' RON</div>';
				newItem += '<div class="cell4"><a href="' + path_to_cart_scripts + 'server.Cart.php?action=removeFromCart&id=' + id + '" onclick="' + js_onclick + '">';
				newItem += '<img src="'+ site_url +'images/delete.gif" style="border: 0px" alt="Sterge" /></a></div><div class="clear"></div></div>';
				
				if ($("cartIsEmpty"))
					Element.hide($("cartIsEmpty"));

				new Insertion.Bottom("cartItems", newItem);	
				
				Effect.Appear("cartItem_" + id, { duration: 0.5 });
				Element.update($("cartTotalAmount"), "Total<small>(RON)</small>: <strong><br />" + cartUpdate['cartItemDetails'][0].total + "</strong>");
				new Effect.Highlight("cartTotalAmount", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
			}
			// so, the item already existed in the cart, therefore update its quantity and subtotal
			else
			{
				Element.update($("cartItemQty_" + id), cartUpdate['cartItemDetails'][0].newQty);
				Element.update($("cartItemPrice_" + id), cartUpdate['cartItemDetails'][0].newPrice + " RON");
				Element.update($("cartTotalAmount"), "Total<small>(RON)</small>: <strong><br />" + cartUpdate['cartItemDetails'][0].total + "</strong>");
				new Effect.Highlight("cartTotalAmount", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
				new Effect.Highlight("cartItemPrice_" + id, {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
				new Effect.Highlight("cartItemQty_" + id, {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
			}
		}
	});
	return false;
}

// remove an item from the cart
function removeFromCart(id)
{
	Effect.Fade("cartItem_" + id);
	new Ajax.Request(path_to_cart_scripts + "server.Cart.php?action=removeFromCart", {
		parameters: "id=" + id,
		onSuccess: function(resp) {
			var total = resp.responseText;
			if (total == 0)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Nici un produs in cos.</div>');
				Element.update($("cartTotalAmount"), "Total: 0.00 RON");
				new Effect.Highlight("cartIsEmpty", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
			}
			else
			{
				// update the cart's total amount
				Element.update($("cartTotalAmount"), "Total<small>(RON)</small>: <strong><br />" + total + "</strong>");
			}
			new Effect.Highlight("cartTotalAmount", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
		}
	});
	return false;
}

// empty the cart
function emptyCart()
{
	new Ajax.Request(path_to_cart_scripts + "server.Cart.php?action=emptyCart", {
		onSuccess: function(resp) {
			if (resp.responseText == 1)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Nici un produs in cos.</div>');
				Element.update($("cartTotalAmount"), "Total<small>(RON)</small>: <strong>0.00</strong>");
				new Effect.Highlight("cartIsEmpty", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
				new Effect.Highlight("cartTotalAmount", {startcolor:'#d6382f', endcolor:'#fdfdfd', restorecolor:'#fdfdfd'});
			}
		}
	});
	return false;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}	
Object.prototype.in_array = function(datum, strict) {
if (strict) function equals(a,b) { return a === b }
else function equals(a,b) { return a == b }
for (var i in this) {
	if (equals(this[i], datum)) return true;
}
return false;
}


function DisableEnableForm(xForm,xHow){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    objElems[i].disabled = xHow;
  }
}