var ajaxPath="";

function setAjaxPath( path )
{
	ajaxPath=path;
}

function onBasketRemove( sender, contentId, title, input )
{
	if (!confirm('Remove '+title+' from basket?'))
	{
		return false;
	}
	input.value=0;
	return onBasketUpdateQuantity( this, contentId, 0, "" );
}

function onBasketUpdateQuantity( sender, contentId, quantity, urlAppend )
{

	var xmlhttp;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        xmlhttp = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) { // IE
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                        try {
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                            } 
                            catch (e) {}
                        }
                                    }

    if (!xmlhttp) {
		//If a input field is disabled/readonly and the form uses post back and not ajax then firefox doesnt update the field before posting back. Going to quickly enable the field! But in theory this shouldnt be called anyway as if no ajax then generally this JS wont run anyway ... fun !
		document.getElementById("quantity_"+contentId).disabled = false;
        return true;
    }

	//document.all.basketform.basketcheckout.disabled=true;
	document.getElementById("basketcheckout").disabled = true;
	sender.disabled=true;
	
	xmlhttp.open("GET", ajaxPath+"BasketUpdate.aspx?contentId="+escape( contentId )+"&quantity_"+contentId+"="+escape( quantity )+urlAppend+"&ajax="+new Date(),true);
	
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4) 
		{
			document.getElementById("basketform").innerHTML = xmlhttp.responseText;
			var row = document.getElementById("basketitemrow"+contentId)
			if (row!=null)
				row.className='basketitemhi';
				
			window.location.reload();
		}
	}
	
	xmlhttp.send(null);
	return false;
}

function onBasketUpdateCountry( sender, select )
{
	var xmlhttp=false;
	try 
	{
	 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
		return true;
	}

	sender.disabled=true;
	sender.form.basketcheckout.disabled=true;	
	//sender.basketform.basketcheckout.disabled=true;	
	countryId=select.options[ select.selectedIndex ].value;

	xmlhttp.open("GET", ajaxPath+"BasketUpdate.aspx?countryId="+escape( countryId )+"&ajax="+new Date(),true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4) 
		{
			document.all.basketform.innerHTML=xmlhttp.responseText;
			document.all.basketcarriagerow.className='basketcarriagehi';
		}
	}
	xmlhttp.send(null);
	return false;
}
function flashAlert( id )
{
	clearAlert( id, 4 );
}
function clearAlert( id, count )
{
	var control=eval('document.all.'+id);
	if (--count%2==0)
		control.className='value';
	else
		control.className='valuehi';
		
	if (count>0)
		setTimeout( "clearAlert('"+id+"',"+count+")", 500 );
}
function captureLink( )
{
	var xmlhttp=false;
	try 
	{
	 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
		return true;
	}

	xmlhttp.open("GET", "LogEscape.aspx?href="+escape( this.href )+"&referer="+escape(window.location)+"&text="+escape(this.innerText),true);
	xmlhttp.send(null);
}
function captureLinks()
{
	var basehref=window.location.protocol+"//"+window.location.host;
	for (i=0; i<document.links.length ; i++) 
	{
		var link=document.links[i];
		var href=link.href;
		if (link.href.indexOf('http')==0 && href.indexOf(basehref)==-1 && link.onclick==null)
		{
			link.onclick=captureLink;
		}
	}
}
setTimeout("captureLinks()",1000);

