/* ---------------------------------------------------------------------
COPYRIGHT LINCS MEDIA LTD. ALL RIGHTS RESERVED.
ALL CODE IS FULLY PROTECTED BY COPYRIGHT LAWS AND INTERNATIONAL TREATY
PROVISIONS AND IS CONSIDERED A TRADE SECRET BELONGING TO THE COPYRIGHT HOLDER.

ANY UNAUTHORIZED REPRODUCTION OR DISTRIBUTION OF THIS CODE IN PART
OR IN ITS ENTIRETY IS STRICTLY PROHIBITED.
----------------------------------------------------------------------*/

function getXMLHTTP()
{
	var type = null;
	try
	{
		type = new ActiveXObject("Msxml2.XMLHTTP");
 	}
 	catch(e)
 	{
		try
		{
			type = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			type = null;
		}
	}

	if(!type && typeof XMLHttpRequest != "undefined")
	{
		type = new XMLHttpRequest();
	}
	return type;
}

function getModels(make, loc)
{
	with(document.getElementById('model'))
	{
		for(i = options.length - 1; i >= 0; i--)
		{
			options[i] = null;
		}
		options[options.length] = new Option('Please wait', '');
		options[options.length] = new Option('----------------------', '');
	}
	
	_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
		_xmlHttp.open("GET", document.location.protocol + '//www.sportsbikeshop.co.uk/get_model_data.php?loc=' + loc + '&getdata=model&make=' + make, true);
	}
	else
	{
		alert('We\'re sorry but your browser does not support this function.');
	}

	_xmlHttp.onreadystatechange = function()
	{
		if(_xmlHttp.readyState == 4)
		{
			eval('models = Array(' + _xmlHttp.responseText + ')');
			
			with(document.getElementById('model'))
			{
				for(i = options.length - 1; i >= 0; i--)
				{
					options[i] = null;
				}
				
				options[options.length] = new Option('Please select model', '');
				options[options.length] = new Option('----------------------', '');
				
				for(i = 0; i < models.length - 1; i++)
				{
					options[options.length] = new Option(models[i + 1], models[i]);
					i++;
				}
			}
		}
	}
	_xmlHttp.send(null);
}

function getYears(model, loc)
{
	with(document.getElementById('year'))
	{
		for(i = options.length - 1; i >= 0; i--)
		{
			options[i] = null;
		}
		options[options.length] = new Option('Please wait', '');
		options[options.length] = new Option('----------------------', '');
	}
				
	_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
		_xmlHttp.open("GET", document.location.protocol + '//www.sportsbikeshop.co.uk/get_model_data.php?loc=' + loc + '&getdata=year&model=' + model, true);
	}
	else
	{
		alert('We\'re sorry but your browser does not support this function.');
	}

	_xmlHttp.onreadystatechange = function()
	{
		if(_xmlHttp.readyState == 4)
		{
			eval('years = Array(' + _xmlHttp.responseText + ')');
			with(document.getElementById('year'))
			{
				for(i = options.length - 1; i >= 0; i--)
				{
					options[i] = null;
				}
				
				options[options.length] = new Option('Please select year', '');
				options[options.length] = new Option('----------------------', '');
				
				for(i = 0; i < years.length - 1; i++)
				{
					options[options.length] = new Option(years[i + 1], years[i]);
					i++;
				}
			}
		}
	}
	_xmlHttp.send(null);
}

function getProductData(class_id, model_id)
{
_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
		_xmlHttp.open("GET", document.location.protocol + '//www.sportsbikeshop.co.uk/get_product_data.php?class=' + class_id + '&model=' + model_id, true);
	}
	else
	{
		alert('We\'re sorry but your browser does not support this function.');
	}

	_xmlHttp.onreadystatechange = function()
	{
		if(_xmlHttp.readyState == 4)
		{
			document.getElementById("container_" + class_id).innerHTML = _xmlHttp.responseText;
		}
	}
	_xmlHttp.send(null);
}

function checkModel()
{
	if(document.getElementById('make').value == '')
	{
		alert('Please select motorcycle make.');
		document.getElementById('make').focus();
		return false;
	}
	else if(document.getElementById('model').value == '')
	{
		alert('Please select motorcycle model.');
		document.getElementById('model').focus();
		return false;
	}
	else if(document.getElementById('year').value == '')
	{
		alert('Please select model year.');
		document.getElementById('year').focus();
		return false;
	}
	else
	{
		return true;
	}
}

function showBikeSelect()
{
	document.getElementById('model_filter').style.display = 'none';
	document.getElementById('model_select').style.display = 'block';
}

function hideBikeSelect()
{
	document.getElementById('model_filter').style.display = 'block';
	document.getElementById('model_select').style.display = 'none';
}
