function updateTyres(loggedin, currency) {
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			$('#tyre_products').html(ajaxRequest.responseText );
		}
	}
	
	var params = 	"?w="			+	$('#width').val();
	params +=		"&p="			+	$('#profile').val();
	params +=		"&r="			+	$('#rim').val();
	params +=		"&s="			+	$('#speed').val();	
	params +=		"&l="			+	loggedin;		
	params +=		"&c="			+	currency;			
	
	
	ajaxRequest.open("GET", "/js/tyre.php" + params, true);

	ajaxRequest.send(null); 
		
}

$(document).ready ( function() {			 
	$('ul.express_list li').bind('click', navExpress);					 
	$('#express_shopper').bind('blur', toList);
	$(".express_shopper").tooltip({
		tip: '.exp',
		position: "bottom center"
	});
});

function expressShopper(direction) {
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			window.location = ajaxRequest.responseText;
		}
	}

	if (direction == 1) { 
		$('#express_changed').val("prev");
	}
	if (direction == 2) {
		$('#express_changed').val("co_prev");	
	}
	
	
	var lastitem = "";
	if ($('ul.express_list li.express_searched').size() > 0) {
		lastitem = $('ul.express_list li.express_searched')[$('ul.express_list li.express_searched').length - 1].innerHTML;
	}
	
	var selected = ($('ul.express_list li.selected').text()) ? $('ul.express_list li.selected').text() : lastitem;
	var params = "?xCmd=" + $('#express_changed').val() + "&t="	+ getTerms() + "&c=" + selected;	
	ajaxRequest.open("GET", "/express.php" + params, true);
	ajaxRequest.send(null); 
		
}

function navExpress(term) {
		
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			window.location = ajaxRequest.responseText;
		}
	}

	var xCmd = ($('#express_changed').val() == "add") ? "addjump" : "jump";
	var params = "?xCmd=" + xCmd + "&t="	+ getTerms() + "&c=" + $(this).text();	
	ajaxRequest.open("GET", "/express.php" + params, true);
	ajaxRequest.send(null); 
}

function toList() {	
	
	if ( $('#express_shopper').val() == "") { $('#express_shopper').val('e.g. Valves\nWeights\nPatches'); }
	
	var html = "<ul class=\"express_list\">";	
	var search_list = $('#express_shopper').val().split("\n");	
	for (i = 0; i < search_list.length; i++) {
		if (search_list[i] != "") {
			html += "<li>" + search_list[i] + "</li>";
		}
	}
	html += "</ul>";
	$('.terms_list').html(html);
	$('div.express_shopper .buttons').html("<div class=\"prev\"></div><div class=\"next\"><a onClick=\"expressShopper(0);\" title=\"Find First\" alt=\"Find First\"><img src=\"/images/2010/images/dashboard_15.png\" border=\"0\"/></a></div><div class=\"edit\"><a onClick=\"toText();\" title=\"Edit Your Express Shopping List\" alt=\"Edit Your Express Shopping List\"><img src=\"/images/2010/images/dashboard_19.png\" border=\"0\"/></a></div>");
	$('ul.express_list li').bind('click', navExpress);	
	$('#express_changed').val('add'); 
	
	
}
function toText() {	
	var html = "<textarea id=\"express_shopper\" cols=\"12\" rows=\"3\">";
	if ($('ul.express_list li').first().text().indexOf("e.g.") < 0) {
		$('ul.express_list li').each( function (index, value) { if (value.innerHTML.replace("\n") != "") { html += value.innerHTML + "\n"; } });
	}
	html += "</textarea><input id=\"express_changed\" type=\"hidden\" value=\"0\" />";
	$('.terms_list').html(html);

	$('div.express_shopper .buttons').html("<div class=\"prev\"></div><div class=\"next\"><a onClick=\"expressShopper(0);\" title=\"Find First\" alt=\"Find First\"><img src=\"/images/2010/images/dashboard_15.png\" border=\"0\"/></a></div><div class=\"edit\"></a></div>");
	$('#express_shopper').bind('blur', toList);

}
function getTerms() {
	var terms="";
	if ($('#express_shopper') === undefined) {
		terms = $('#express_shopper').val();
	} else {
		$('ul.express_list li').each( function (index, value) { if (value.innerHTML.replace("\n") != "") { terms += value.innerHTML + "\n"; } });
	}
	return escape(terms);
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );


}

function processlayers(){
Set_Cookie( '__utmb', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utmc', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utmz', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utma', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__test', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
}

function processlayersnew(){
Set_Cookie( '__utmb', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utmc', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utmz', 'it works', '-11', '/', '.tyrebaydirect.com', '' );
Set_Cookie( '__utma', 'it works', '-11', '/', '.tyrebaydirect.com', '' );

}

