// Get base url
var url = document.location.href;
var xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

var ajax_get_error = false;

function ajax_do(type) {
        var statetext="";
        if(type == 'filter'){
		url='storefilter.html';
	}

        var countryobj = document.getElementById('storecountry');
        var country = countryobj.options[countryobj.selectedIndex].value;

        var brandobj = document.getElementById('brand');
        var brand = brandobj.options[brandobj.selectedIndex].value;

        if(document.getElementById('storestate')) {
	var stateobj = document.getElementById('storestate');
        var state = stateobj.options[stateobj.selectedIndex].value;
        statetext = "&store_state="+state;
	}

	if(type=='update') {
		document.location.href ='/corporate/storefinder.html?cval='+country+'&brand='+brand+'&state='+state;
	}

        // Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}
        
         // get the form detail

        var cityobj = document.getElementById('storecity');
        var city = cityobj.options[cityobj.selectedIndex].value;
        
	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url+"?store_city="+city+"&store_country="+country+statetext+"&brand="+brand;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
    
	return true;
}