/*******************************************************************************/
/*                                                                             */
/*                               Ajax Functions                                */
/*		                         Jaime. 01/07/2010                             */
/*                                                                             */
/*******************************************************************************/
var xmlHttp = new Array(1);
var items = new Array(1);
items[0] = 0;
items[1] = 0;

//basket: op = 0; wishlist: op = 1
function add(op, id, format, num_items){
    if (items[op] == 0) items[op] = num_items;	
    
	xmlHttp[op] = GetXmlHttpObject();
	
	if (xmlHttp[op]==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	xmlHttp[op].onreadystatechange = function(){updateButton(op)};
    xmlHttp[op].open("GET","ajaxqueries.aspx?op="+op+"&id="+id+"&format="+format+"&seed="+Math.floor(Math.random()*1000000),true);
	xmlHttp[op].send(null);
}

function updateButton(op){
	if (xmlHttp[op].readyState==4){	
		var result = xmlHttp[op].responseText;
		xmlHttp[op] = null;
		
		var id = (op==0?'#Top1_lnkBasket':'#Top1_lnkWishlist'); 

		if (result == 'success') {
		    jQuery(id).html(jQuery(id).html().replace(items[op], ++items[op]));

            jQuery(id).animate({
                fontSize: "14px"
            }, 200);

            jQuery(id).animate({
                fontSize: "12px"
            }, 200);
            
            document.location.href = (op==0?'basket.aspx':'wish_list.aspx');
		}
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
