
function createRequestObject()
{
	if (window.XMLHttpRequest)
  	{
 		xmlhttp=new XMLHttpRequest();
 	}
 	else if (window.ActiveXObject)
    {
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}

function getFormField(f, field)
{
	var formField;
	
	for (i = 0; i < f.elements.length; i++)
	{
		if (f.elements[i].name.indexOf(field) >= 0)
		{
			formField = f.elements[i];
			break;
		}
	}
	
	return formField;
}

function setEngineCategory(f, Tech, PreEngineCat, PreBoatType, PreBrand, bRunAll)
{
	var ddlEngineCategory = getFormField(f, 'ddlEngineCategory');
	
	var EngineCat = "0";
	if (ddlEngineCategory && ddlEngineCategory.selectedIndex > 0)
		EngineCat = ddlEngineCategory.options[ddlEngineCategory.selectedIndex].value;
	if (PreEngineCat != null && PreEngineCat.length > 0)
		EngineCat = PreEngineCat;
		
	EngineCat = EngineCat.replace('&', '#amp');
	
	if(Tech!="0")
	{
		setStepImage(2);
	
		if (ddlEngineCategory)
		{
			ddlEngineCategory.length=0;
			ddlEngineCategory[ddlEngineCategory.length]=new Option("Loading...","0");
			ddlEngineCategory.disabled = true;
			ddlEngineCategory.className = "commontext";
		}
	
		var httpobj=createRequestObject();
		httpobj.onreadystatechange=function()
		{
			if(httpobj.readyState==4)
			{						
				if(httpobj.status==200)
				{
					var str=httpobj.responseXML;
					var doc=str.documentElement;
					var enginecat=doc.getElementsByTagName('enginecat')
					var len=enginecat.length;
					
					if (ddlEngineCategory)
					{
						ddlEngineCategory.length=0;
						for(var i=0;i<len;i++)
						{
							var txt=enginecat[i].firstChild.nodeValue;
							txt.replace('#amp', '&');
							
							var val=enginecat[i].attributes[0].value;
							val.replace('#amp', '&');
							
							ddlEngineCategory.disabled = false;
							ddlEngineCategory[ddlEngineCategory.length]=new Option(txt,val);
							
							var bSelected = false;
							if (enginecat[i].attributes[1] && enginecat[i].attributes[1].value.length > 0 && enginecat[i].attributes[1].value == "true")
								bSelected = true;
								
							ddlEngineCategory[ddlEngineCategory.length - 1].selected = bSelected;
							
							if (enginecat[i].attributes[2] && enginecat[i].attributes[2].value.length > 0)
							{
								ddlEngineCategory.className = enginecat[i].attributes[2].value;
							}
						}
					}
					
					var ddlBoatType = getFormField(f, 'ddlBoatType');
					if (ddlBoatType)
					{
						ddlBoatType.length = 0;
						ddlBoatType[ddlBoatType.length]=new Option("Select a boat type...","0");
						ddlBoatType.disabled = true;
						ddlBoatType.className = "commontext";
					}
					
					var ddlBrand = getFormField(f, 'ddlBrand');
					if (ddlBrand)
					{
						ddlBrand.length = 0;
						ddlBrand[ddlBrand.length]=new Option("Select a boat manufacturer...","0");
						ddlBrand.disabled = true;
						ddlBrand.className = "commontext";
					}
					
					if (bRunAll && ddlEngineCategory != null && ddlEngineCategory.selectedIndex != null && ddlEngineCategory.selectedIndex > 0)
					{
						setBoatType(f, ddlEngineCategory.options[ddlEngineCategory.selectedIndex].value, PreBoatType, PreBrand, true);
					}
				}
			}
		}
		//alert("perfbullvalues.aspx?t=enginecat&tech="+Tech+"&enginecat="+EngineCat);
		httpobj.open("GET","/outboard/products/perfbullvalues.aspx?t=enginecat&tech="+Tech+"&enginecat="+EngineCat,true);
		httpobj.send(null);
	}
	else
	{
		setStepImage(1);
	
		if (ddlEngineCategory)
		{
			ddlEngineCategory.length = 0;
			ddlEngineCategory.disabled = true;
			ddlEngineCategory[ddlEngineCategory.length]=new Option("Select a horsepower range...","0");
			ddlEngineCategory.className = "commontext";
		}
	}
}

function setBoatType(f, EngineCat, PreBoatType, PreBrand, bRunAll)
{
	var ddlTechnology = getFormField(f, 'ddlTechnology');
	
	var Tech = "0";
	if (ddlTechnology && ddlTechnology.selectedIndex > 0)
		Tech = ddlTechnology.options[ddlTechnology.selectedIndex].value;
	
	var ddlBoatType = getFormField(f, 'ddlBoatType');
	
	var BoatType = "0";
	if (ddlBoatType && ddlBoatType.selectedIndex > 0)
		BoatType = ddlBoatType.options[ddlBoatType.selectedIndex].value;
	if (PreBoatType != null && PreBoatType.length > 0)
		BoatType = PreBoatType;
	
	EngineCat = EngineCat.replace('&', '#amp');
	
	if(EngineCat!="0")
	{
		setStepImage(3);
	
		if (ddlBoatType)
		{
			ddlBoatType.length=0;
			ddlBoatType[ddlBoatType.length]=new Option("Loading...","0");
			ddlBoatType.disabled = true;
			ddlBoatType.className = "commontext";
		}
	
		var httpobj=createRequestObject();
		httpobj.onreadystatechange=function()
		{
			if(httpobj.readyState==4)
			{						
				if(httpobj.status==200)
				{
					var str=httpobj.responseXML;
					var doc=str.documentElement;
					var boattype=doc.getElementsByTagName('boattype')
					var len=boattype.length;
					
					if (ddlBoatType)
					{
						ddlBoatType.length=0;
						for(var i=0;i<len;i++)
						{
							var txt=boattype[i].firstChild.nodeValue;
							txt.replace('#amp', '&');

							var val=boattype[i].attributes[0].value;
							val.replace('#amp', '&');
							
							ddlBoatType.disabled = false;
							ddlBoatType[ddlBoatType.length]=new Option(txt,val);
							
							var bSelected = false;
							if (boattype[i].attributes[1] && boattype[i].attributes[1].value.length > 0 && boattype[i].attributes[1].value == "true")
								bSelected = true;
								
							ddlBoatType[ddlBoatType.length - 1].selected = bSelected;
							
							if (boattype[i].attributes[2] && boattype[i].attributes[2].value.length > 0)
							{
								ddlBoatType.className = boattype[i].attributes[2].value;
							}
						}
					}
					
					var ddlBrand = getFormField(f, 'ddlBrand');
					if (ddlBrand)
					{
						ddlBrand.length = 0;
						ddlBrand[ddlBrand.length]=new Option("Select a boat manufacturer...","0");
						ddlBrand.disabled = true;
						ddlBrand.className = "commontext";
					}
					
					if (bRunAll && ddlBoatType != null && ddlBoatType.selectedIndex != null && ddlBoatType.selectedIndex > 0)
					{
						setBrand(f, ddlBoatType.options[ddlBoatType.selectedIndex].value, PreBrand);
					}
				}
			}
		}
		//alert("perfbullvalues.aspx?t=boattype&tech="+Tech+"&enginecat="+EngineCat+"&boattype="+BoatType);
		httpobj.open("GET","/outboard/products/perfbullvalues.aspx?t=boattype&tech="+Tech+"&enginecat="+EngineCat+"&boattype="+BoatType,true);
		httpobj.send(null);
	}
	else
	{
		setStepImage(2);
	
		if (ddlBoatType)
		{
			ddlBoatType.length = 0;
			ddlBoatType.disabled = true;
			ddlBoatType[ddlBoatType.length]=new Option("Select a boat type...","0");
			ddlBoatType.className = "commontext";
		}
	}
}

function setBrand(f, BoatType, PreBrand)
{
	var ddlTechnology = getFormField(f, 'ddlTechnology');
	
	var Tech = "0";
	if (ddlTechnology && ddlTechnology.selectedIndex > 0)
		Tech = ddlTechnology.options[ddlTechnology.selectedIndex].value;
	
	var ddlEngineCat = getFormField(f, 'ddlEngineCat');
	
	var EngineCat = "0";
	if (ddlEngineCat && ddlEngineCat.selectedIndex > 0)
		EngineCat = ddlEngineCat.options[ddlEngineCat.selectedIndex].value;
	
	EngineCat = EngineCat.replace('&', '#amp');
	
	var ddlBrand = getFormField(f, 'ddlBrand');
	
	var Brand = "0";
	if (ddlBrand && ddlBrand.selectedIndex > 0)
		Brand = ddlBrand.options[ddlBrand.selectedIndex].value;
	if (PreBrand != null && PreBrand.length > 0)
		Brand = PreBrand;
	
	if(BoatType!="0")
	{
		setStepImage(4);
	
		if (ddlBrand)
		{
			ddlBrand.length=0;
			ddlBrand[ddlBrand.length]=new Option("Loading...","0");
			ddlBrand.disabled = true;
			ddlBrand.className = "commontext";
		}
	
		var httpobj=createRequestObject();
		httpobj.onreadystatechange=function()
		{
			if(httpobj.readyState==4)
			{						
				if(httpobj.status==200)
				{
					var str=httpobj.responseXML;
					var doc=str.documentElement;
					var brand=doc.getElementsByTagName('brand')
					var len=brand.length;
					
					if (ddlBrand)
					{
						ddlBrand.length=0;
						for(var i=0;i<len;i++)
						{
							var txt=brand[i].firstChild.nodeValue;
							txt.replace('#amp', '&');

							var val=brand[i].attributes[0].value;
							val.replace('#amp', '&');
							
							ddlBrand.disabled = false;
							ddlBrand[ddlBrand.length]=new Option(txt,val);
							
							var bSelected = false;
							if (brand[i].attributes[1] && brand[i].attributes[1].value.length > 0 && brand[i].attributes[1].value == "true")
								bSelected = true;
								
							ddlBrand[ddlBrand.length - 1].selected = bSelected;
							
							if (brand[i].attributes[2] && brand[i].attributes[2].value.length > 0)
							{
								ddlBrand.className = brand[i].attributes[2].value;
							}
						}
					}
				}
			}
		}
		//alert("perfbullvalues.aspx?t=brand&tech="+Tech+"&enginecat="+EngineCat+"&boattype="+BoatType+"&brand="+Brand);
		httpobj.open("GET","/outboard/products/perfbullvalues.aspx?t=brand&tech="+Tech+"&enginecat="+EngineCat+"&boattype="+BoatType+"&brand="+Brand,true);
		httpobj.send(null);
	}
	else
	{
		setStepImage(3);
	
		if (ddlBrand)
		{
			ddlBrand.length = 0;
			ddlBrand.disabled = true;
			ddlBrand[ddlBrand.length]=new Option("Select a boat manufacturer...","0");
			ddlBrand.className = "commontext";
		}
	}
}

function setStepImage(Step)
{
	for (i = 1; i <= 4; i++)
	{
		if (document.images['imgStep' + i])
		{
			if (Step == i)
				document.images['imgStep' + i].src = '/assets/common/step-' + i + '-blk.gif';
			else
				document.images['imgStep' + i].src = '/assets/common/step-' + i + '-gry.gif';
		}
	}
}

function addAdditionalLoadEvent(func) {
	var oldonload = window.onload;
	if (window == null || window.onload == null || window.onload.length <= 0) {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func;
		}
	}
	/*
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func;
		}
	}
	*/
}