/**
 * @author Peter Pajchl
 * @copyright Peter Pajchl
 * All Rights Reserved
 */

// Function creates new ajax object, returns object on success
function createPajaxRequest()
{
	if (typeof XMLHttpRequest !== 'undefined') 
	{
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		// Microsft xmlHTTP objects
		var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"];
		
		// get latest Microsoft xmlHTTP available
		for (var i = avers.length - 1; i >= 0; i--)
		{
			try 
			{
				var httpObj = new ActiveXObject(avers[i]);
				return httpObj;
			} 
			catch (e)
			{
			}
		}
	}
	
	throw new Error('XMLHttp (AJAX) not supported');
}

// function updates shopping cart information on the page
function pajaxUpdateCart()
{
	var shoppingCart=document.getElementById('shoppingCart');
	var totalAmount=document.getElementById('shoppingCartTotal');
	
}

// function ads product into a shopping cart and re-new in real-time
// document id -> shoppingCart
function pajaxAddItem(itemId) {
	
	try
	{
		var item = itemId;
		var serverpage = '/cloud/cart.php?do=2&item=' + item;
	
		var xmlhttp = createPajaxRequest();
	
		xmlhttp.open("GET", serverpage, true);
		xmlhttp.onreadystatechange = function ()
		{
		
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				pajaxUpdateCart(items, Count, items, total);
			}
		};
		
		xmlhttp.send(null);
	}
	catch (e)
	{
		throw new Error('Unable to add item');
	}
}

jQuery(document).ready( function() {
	
	$('a[rel="external"]').bind("click", function() {
		window.open($(this).attr('href'));
		return false;
	});
	
});

