function makeHttpRequest(url, callback_function, return_xml)
{
  var http_request, response, i;

  var activex_ids = [
    'MSXML2.XMLHTTP.3.0',
    'MSXML2.XMLHTTP',
    'Microsoft.XMLHTTP'
  ];

  if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) { // IE6 and older
    for (i = 0; i < activex_ids.length; i++) {
      try {
        http_request = new ActiveXObject(activex_ids[i]);
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Unfortunatelly you browser doesn\'t support this feature.');
    return false;
  }

  http_request.onreadystatechange = function() {
    if (http_request.readyState !== 4) {
        // not ready yet
        return;
    }
    if (http_request.status !== 200) {
      // ready, but not OK
      alert('There was a problem with the request.(Code: ' + http_request.status + ')');
      return;
    }
    if (return_xml) {
      response = http_request.responseXML;
    } else {
      response = http_request.responseText;
    }
    // invoke the callback
    callback_function(response);
  };

  http_request.open('GET', url, true);
  http_request.send(null);
}

function is_at_least_one_checkbox_checked(){
	var checked_exists = false;
	var elLength = document.cart_add.elements.length;
	for (i=0; i<elLength; i++){
        var type = document.cart_add.elements[i].type;
        if (type=="checkbox" && document.cart_add.elements[i].checked){
        	checked_exists = true;
        }
    }
	return checked_exists;
}

function get_first_checkbox_checked_size(){
	var isnext = false;
	var elLength = document.cart_add.elements.length;
	for (i=0; i<elLength; i++){
        var type = document.cart_add.elements[i].type;
        if(isnext)	{
        	return document.cart_add.elements[i].value;
        }
        if (type=="checkbox" && document.cart_add.elements[i].checked){
        	isnext = true;
        }
    }
	return false;
}


function check_items(){
	if(is_at_least_one_checkbox_checked()) {
		document.cart_add.submit();
	} else {
		alert("Select at least one product to add to your cart");
	}
}

function check_items_and_set_value(part1,part2){
	if(is_at_least_one_checkbox_checked()) {
		// alert(get_first_checkbox_checked_size());
		document.cart_add.action = part1 + get_first_checkbox_checked_size() + part2;
		//alert(document.cart_add.action);
		document.cart_add.submit();
	} else {
		alert("Select at least one product to add to your cart");
	}
}

function check_items_and_set_value_nocheck(url){
		document.cart_add.action = url;
		document.cart_add.submit();
}







function Popup_roadhazard(url) {
	window.open( url, "RoadHazardProgramPopup", "status = 1, height = 600, width = 461, resizable = 0" )
}

function Popup_shippingquote(url,check_checkboxes) {
	var proceed = false;
	
	if(check_checkboxes){
		
		proceed = is_at_least_one_checkbox_checked();
	} else {
		proceed = true;
	}    
	
    if(proceed){
	    var orig_action=document.cart_add.action;
		window.open( "", "ShippingquotePopup", "status = 1, height = 400, width = 461, resizable = 0,scrollbars=1" );
		document.cart_add.action=url;
		document.cart_add.target='ShippingquotePopup';
		document.cart_add.submit();
		document.cart_add.action=orig_action;
		document.cart_add.target='';
	} else {
		alert("Please select at least one item to get a shipping quote");	
	}
}

function showThing(obj) {
	var el = document.getElementById(obj);
	el.style.display = "block";
	//needed for Safari 2.0.2
    //	window.resizeTo(self.outerWidth + 1, self.outerHeight);    
    //	window.resizeTo(self.outerWidth - 1, self.outerHeight);                
}

function hideThing(obj)	{
    var el = document.getElementById(obj); 
	el.style.display = "none";
	//needed for Safari 2.0.2
    //    window.resizeTo(self.outerWidth + 1, self.outerHeight);    
    //    window.resizeTo(self.outerWidth - 1, self.outerHeight);               		
	
}

function showStaggered(){
        document.forms.sizeRearSearch.width.selectedIndex=document.forms.sizeSearch.width.selectedIndex;
        document.forms.sizeRearSearch.diameter.selectedIndex=document.forms.sizeSearch.diameter.selectedIndex;
        document.forms.sizeRearSearch.ratio.selectedIndex=document.forms.sizeSearch.ratio.selectedIndex;
	showThing('staggered');
	hideThing('single');
}

function showSingle(){
        document.forms.sizeSearch.width.selectedIndex=document.forms.sizeRearSearch.width.selectedIndex;
        document.forms.sizeSearch.diameter.selectedIndex=document.forms.sizeRearSearch.diameter.selectedIndex;
        document.forms.sizeSearch.ratio.selectedIndex=document.forms.sizeRearSearch.ratio.selectedIndex;
	showThing('single');
	hideThing('staggered');
}

function checkClear(Ax,B){
	if(Ax.value==B){
		Ax.value="";
		Ax.style.color="black";
		Ax.style.fontSize="12px";
	}
}

function Delete_Cookie( name ) {
	//path = '/onlinetires/';
	path = '/';
	document.cookie = name + "=;path=" + path + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}