// *****************************************************************
// **************************** GLOBAL VARIABLES *******************
// *****************************************************************
var Makes = new Array();




// *****************************************************************
// **************************** FUNCTIONS **************************
// *****************************************************************

// ************************* GENERAL **********************************
function handleOnChange(objSrc,bvdid)
{
	switch(objSrc.name)
	{
		case "cid":
			if ((objSrc.selectedIndex != 0) && (objSrc.options[objSrc.selectedIndex].value != 0))
			{
				if (document.Search.hidLayout.value != "dts")
					document.getElementById("divCo").className = 'divShow';
				else
					document.getElementById("divCo").className = 'bsYearList';
				
				if (document.Search.hidLayout.value != "dts")
					document.getElementById("divProdCat").className = 'divHide';
				if (((bvdid == "2341") || (bvdid == "1501") || (bvdid == "1661") || (bvdid == "1601") || (bvdid == "1621")) && (objSrc.options[objSrc.selectedIndex].value == "2309"))
				{
					LoadModelYr(document.Search.co_modeldd, objSrc.options[objSrc.selectedIndex].value, 0, '2005');
				}
				else
					LoadModelYr(document.Search.co_modeldd, objSrc.options[objSrc.selectedIndex].value);
				if (document.Search.hidLayout.value != "dts")
				{
					if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2"))
						document.getElementById("SearchResult").innerHTML = "";
					else {
						if (document.Search.hidLayout.value == "ultimate")
							document.getElementById("SearchResult").innerHTML = MakeStory(objSrc.options[objSrc.selectedIndex].value);
						else
							document.getElementById("SearchResult").innerHTML = "&nbsp;<font size='2' face='Arial'><i>Use the controls to the left to narrow your search.</i></font>";
					}
				}
				else
				{
					document.Search.co_modeldd.options[1].selected = true;
					document.Search.action = window.location.href; 
					document.Search.submit();
				}

			}
			else
			{
				if (document.Search.hidLayout.value != "dts")
				{
					document.getElementById("companyLogo").innerHTML = "<img src='/cgi-bin/boatsearch/images/nopic.gif' border=0>";
					if (document.getElementById("companyStory") != null)
						document.getElementById("companyStory").innerHTML = "";
					document.getElementById("divCo").className = 'divHide';
					document.getElementById("divProdCat").className = 'divHide';
					if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2") || (document.Search.hidLayout.value == "ultimate"))
						document.getElementById("SearchResult").innerHTML = "";
					else
						document.getElementById("SearchResult").innerHTML = "&nbsp;<font size='2' face='Arial'><i>Use the controls to the left to narrow your search.</i></font>";
				}
				else
				{
					document.Search.co_modeldd.options[0].selected = true;
					document.getElementById("divCo").className = 'divHide';
					document.Search.action = window.location.href; 
					document.Search.submit();
				}
			}
			break;
		case "co_modeldd":
			if ((objSrc.selectedIndex != 0) && (objSrc.options[objSrc.selectedIndex].value != 0))
			{
				if (document.Search.hidLayout.value != "dts")
				{
					document.getElementById("divProdCat").className = 'divShow';
					LoadPc(document.Search.prodcat, document.Search.cid.options[document.Search.cid.selectedIndex].value, objSrc.options[objSrc.selectedIndex].value);
					if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2"))
						document.getElementById("SearchResult").innerHTML = "";
					else {
						if (document.Search.hidLayout.value == "ultimate")
							document.getElementById("SearchResult").innerHTML = MakeStory(document.Search.cid.options[document.Search.cid.selectedIndex].value);
						else
							document.getElementById("SearchResult").innerHTML = "&nbsp;<font size='2' face='Arial'><i>Use the controls to the left to narrow your search.</i></font>";
					}
				}
				else
				{
					document.Search.action = window.location.href; 
					document.Search.submit();
				}
			}
			else
			{
				if (document.Search.hidLayout.value != "dts")
				{
					document.getElementById("divProdCat").className = 'divHide';
					if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2"))
						document.getElementById("SearchResult").innerHTML = "";
					else {
						if (document.Search.hidLayout.value == "ultimate")
							document.getElementById("SearchResult").innerHTML = MakeStory(document.Search.cid.options[document.Search.cid.selectedIndex].value);
						else
							document.getElementById("SearchResult").innerHTML = "&nbsp;<font size='2' face='Arial'><i>Use the controls to the left to narrow your search.</i></font>";
					}
				}
				else
				{
					objSrc.options[1].selected = true;
					document.Search.action = window.location.href; 
					document.Search.submit();
				}
			}
			break;
		case "prodcat":
			if ((objSrc.selectedIndex != 0) && (objSrc.options[objSrc.selectedIndex].value != 0)) 
			{
				document.Search.action = window.location.href; 
				document.Search.submit();
			}
			else
			{
				if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2"))
					document.getElementById("SearchResult").innerHTML = "";
				else {
					if (document.Search.hidLayout.value == "ultimate")
						document.getElementById("SearchResult").innerHTML = MakeStory(document.Search.cid.options[document.Search.cid.selectedIndex].value);
					else
						document.getElementById("SearchResult").innerHTML = "&nbsp;<font size='2' face='Arial'><i>Use the controls to the left to narrow your search.</i></font>";
				}
			}
	}
}



// ************************* MAKE **********************************
//Main class
function Make()
{
	var args = Make.arguments;
	this.modelYrs = new Array();
	this.id = args[0];
	this.name = args[1];
	this.path = args[2];
	this.filename = args[3];
	this.addYears = AddModelYears;
	this.Build = buildMake;
	Makes[Makes.length] = this;
}

//Add model years to Make
function AddModelYears()
{
	var args = AddModelYears.arguments;
	for (var i=0; i< args.length; i++) {
		this.modelYrs[this.modelYrs.length] = args[i];
		args[i].Make = this;
	}
}

function buildMake()
{}

//Load Company dropdown
function LoadMakes()
{
	var args = LoadMakes.arguments;
	var defaultOpt;
	var isValid;
	var optIndex = 1;

	args[0].length = 0;
	if (document.Search.hidLayout.value == "ultimate")
		defaultOpt = new Option("Company", "0");
	else {
		if (document.Search.hidLayout.value == "dts") 
			defaultOpt = new Option("- Select a Make -", "0");
		else
			defaultOpt = new Option("Please Select a Company", "0");
	}
		
	args[0].options[0] = defaultOpt;
	args[0].options[0] = defaultOpt;

	if (Makes.length > 0)
	{
		for (var i = 0; i < Makes.length; i++)
		{
			isValid = true;
			if (args[1] != null && args[1] != "0")
			{
				args[1] = ',' + args[1] + ',';

				if (args[1].search(',' + Makes[i].id + ',') == -1)

					isValid = false;
			}
			if (isValid)
			{
				eval("var option" + i + " = new Option('" + Makes[i].name.replace("\'", "\\'") + "', '" + Makes[i].id + "')");
				eval("args[0].options[optIndex]=option" + i);
				if (args[2] != null && args[2] > 0 && Makes[i].id == args[2])
					args[0].options[optIndex].selected = true;
				optIndex += 1;
			}
		}
	}
	else
	{
		var option1 = new Option("*** No Companies found for this Dealer in database ***", "0");
		args[0].options[1]=option1;
	}
}

function MakeStory(p_Cid)
{
	var strStory;
	switch(p_Cid)
	{	
		case "710": //Crownline
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" + 
							"<span class='textnormal'>" + 
							"Crownline was established nearly a dozen years ago on three very simple and practical principles that from that time on became a Crownline way of life:" + 
							"<ul>" + 
							"<li>Build stern-drive sport boats of the highest possible quality" + 
							"<li>Provide buyers with the flexibility to customize these boats to their individual tastes with an abundant offering of interior, exterior, electronic and mechanical options. " + 
							"<li>Bring these boats to the marketplace at very competitive prices." +
							"</ul>" + 
							"At Crownline we know what boaters want first and foremost: A totally seaworthy craft they can depend on. Then they want that craft fitted to meet their needs whether bowrider, deck boat, cuddy or cruiser. In living by these principles, we have gone from our start-up to become one of the largest builders of stern-drive sport boats in the industry." + 
							"</span>";
					break;
		case "1027": //Four WInns
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" +
							"<span class='textnormal'>" + 
							"The name Four Winns? has become synonymous with quality craftsmanship, trustworthiness, and loads of fun.  Just mention Four Winns to any knowledgeable recreational boater and you’ll receive nods of admiration and smiles of appreciation.  A Four Winns boat is prized as one of the finest examples of recreational marine quality and manufacturing ingenuity in the marketplace today." + 
							"</span>";
					break;
		case "1729": //Sea Ray
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" + 
							"<span class='textnormal'>Every Sea Ray boat is a reflection of our commitment to precision, innovation and craftmanship.  Spacious cockpits flow into thoughtfully designed cabins.  The design, details and materials are tested and approved by the most dedicated group of professionals in the marine industry.  The result is a line of boats, from 17 to 68 feet, that continues to set higher standards when it comes to aesthetics, engineering and technology.  Based on the responses from our owners, J.D. Power and Associates ranked us highest in customer satisfaction.  That's what you can expect from Sea Ray.</span>";
					break;
		case "2046": //MasterCraft
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" + 
							"<span class='textnormal'>" +
							"MasterCraft has been shaping the boating industry since 1968. More than three decades after the original MasterCraft made its debut, our goal remains the same - to continue building the world's best ski, wakeboard and luxury performance powerboats, year after year. Our Vonore, Tennessee plants are staffed with dedicated professionals, working on your next boat. " +
							"</span>";
					break;
		case "2146": //SeaSwirl
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" + 
							"<span class='textnormal'>" +
							"Are you ready? Ready to break from the mundane and grab for the sense of adventure and freedom that a Seaswirl Boat has to offer. The versatility of the Seaswirl line offers something for every boating enthusiast. Of course whatever your preference, you'll benefit from over 49 years of boat building excellence. Doing things right is the only way at Seaswirl.  From durable construction, sensible design and personal comfort, no detail is overlooked.  Seaswirl makes it easy to enjoy your boating experiences because of what goes into every Seaswirl Boat. Design, innovation, quality materials and a dedicated team of knowledgeable professionals are a part of each boat we build. Your boat is crafted to provide you with years of memorable experiences for family and friends. At Seaswirl, we believe that's what boating is all about." +
							"</span>";
					break;
		case "4425": //Tracker
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" +
							"<span class='textnormal'>" +
							"Year after year, more people buy TRACKER® Boats than any other brand because we offer the best choice in quality, full-featured aluminum fishing boats with nationally advertised, consistent, no-hassle value pricing.  We have a twenty-five year heritage of innovation and devotion to meeting the needs of fishermen and your families. Our boats were the first to be offered as a complete ready-to-fish package, with all the important components matched to one another at the factory. We introduced the concept of straight-forward, no-hassle pricing and we remain unique as the only manufacturer to offer this benefit." +
							"</span>";
					break;
		case "4429": //Sun Tracker
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" +
							"<span class='textnormal'>" +
							"Fishing. Lounging. Entertaining. No matter what your favorite activity is, there’s a Sun TRACKER® pontoon boat that’s perfect for the occasion. There are many reasons why Sun TRACKER has been the world’s number-one selling pontoon boat for nearly two decades, but they all add up to one thing – value. Sun TRACKER customers understand the value of a boat that offers so much luxury, comfort, quality craftsmanship, reliability and so many standard features – especially when it’s wrapped into such cost-effective packages. Our success is based on the fundamental principle of listening to our customers and building the boats they want at a price they can afford – it’s that simple." + 
							"</span>";
					break;
		case "4433": //Nitro
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>" + 
							"<span class='textnormal'>" +
							"NITRO® offers the best combination of style, layout design, ride and handling, performance, and standard features for the money. NITRO® is the \"thinking angler's\" choice in an all-around high performance fishing and multi-purpose recreational boat. In the past 10 years, more non-sponsored amateur fishermen bought NITRO® than any other brand. At the top of the line-up, NITRO® 9 Series tournament boats, first introduced in 1999, were designed with input from the world’s best professional anglers to be the best-in-class in every important area. NITRO® 9 Series are now the choice of some of the worlds best fishermen—winners like Rick Clunn, Kevin VanDam, Woo Daves, and Tommy Martin. The entire 2003 NITRO® lineup reflects a new attention to detail produced by a top-to-bottom manufacturing quality improvement effort. We challenge you to look for yourself. When you are finished, no doubt your choice will be NITRO®... and your friends will say, \"Now you’re thinkin’.\"" +
							"</span>";
					break;
		default:
					strStory = "<img src='images/ebsplash_" + p_Cid + ".jpg' width='533' height='253' border='0'><br>";
					break;
	}
	return strStory;
}

// ********************* END OF MAKE *******************************




// ************************* YEAR **********************************
//Year Class
function Year()
{
	var args = Year.arguments;
	this.PCs = new Array();
	this.id = args[0];
	this.name = args[1];
	this.addPCs = AddProductCategories;
}

//Add Product Categories to model year
function AddProductCategories()
{
	var args = AddProductCategories.arguments;
	for (var i=0; i< args.length; i++) {
		this.PCs[this.PCs.length] = args[i];
		args[i].ModelYr = this;
	}
}

//Load Model Year dropdown
function LoadModelYr()
{
	var args = LoadModelYr.arguments;
	var objMake = eval("Make" + args[1]);
	var defaultOpt;
	var isValid;


	args[0].length = 0;
	if (document.Search.hidLayout.value == "ultimate")
		defaultOpt = new Option("Year", "0");
	else {
			if (document.Search.hidLayout.value == "dts")
				defaultOpt = new Option("- Select a Year - ", "0");
			else
				defaultOpt = new Option("Please Select a Model Year", "0");
	}
	args[0].options[0] = defaultOpt;

	if (objMake.modelYrs[0].name != null)
	{
		for (var i = 0; i < objMake.modelYrs.length; i++)
		{
			isValid = true;
			if (args[3] != null && args[3] != "0")
			{
				if (args[3].search(objMake.modelYrs[i].name) == -1)
					isValid = false;
			}
			if (isValid)
			{
				eval("var option" + i + " = new Option('" + objMake.modelYrs[i].name + "', '" + objMake.modelYrs[i].id + "')");
				eval("args[0].options[i+1]=option" + i);
				if (args[2] != null && args[2] > 0 && objMake.modelYrs[i].id == args[2])
					args[0].options[i+1].selected = true;		
			}
		}
		if ((args[2] == null) && (document.Search.hidLayout.value == "dts"))  
			args[0].options[1].selected = true;
	}
	else
	{
		var option1 = new Option("*** No Years found for this Company in database ***", "0");
		args[0].options[1]=option1;
	}
	// Company Story and logo
	//Logo
	if (document.Search.hidLayout.valu != "dts")
	{
		if ((document.Search.hidLayout.value == "1") || (document.Search.hidLayout.value == "2"))
		{
			document.getElementById("companyLogo").innerHTML = "<img src='http://media.channelblade.com/boat_graphics/logos/logo_" + objMake.id + ".jpg' border=0>";
		}
		else
		{
			if (document.getElementById("companyLogo") != null)
			{
				if (objMake.path!= null && objMake.path != "" && objMake.filename != null && objMake.filename != "")
				{
					document.getElementById("imgLnk").href = '/' + objMake.path + '/' + objMake.filename;
					document.getElementById("imgCompanyLogo").src = 'http://media.channelblade.com/boat_graphics/logos/logo_' + objMake.id + '.jpg';
				}
				else
					document.getElementById("companyLogo").innerHTML = "<img src='http://media.channelblade.com/boat_graphics/logos/logo_" + objMake.id + ".jpg' border=0>";
			}
			
			// Company story	
			if (document.getElementById("companyStory") != null)
			{
				if (objMake.path!= null && objMake.path != "" && objMake.filename != null && objMake.filename != "")
				{
					document.getElementById("companyStory").innerHTML = "<font size='4' face='Arial' color='#000000'><b>" + objMake.name + " Online Brochure</b></font><P>";
					document.getElementById("companyStory").innerHTML += "<a href='/" + objMake.path + "/" + objMake.filename + "' target='_blank' class='SearchLink'>Click Here To Learn More About " + objMake.name + "</a>";
				}
				else
				{
					document.getElementById("companyStory").innerHTML = "<font size='4' face='Arial' color='#000000'><b>" + objMake.name + " Online Brochure</b></font><P>";
				}
			}
		}
	}

}


// ********************* END OF YEAR *******************************




// ******************** PRODUCT CATEGORY ***************************
// Product Category Class
function ProductCategory()
{
	var args = ProductCategory.arguments;
	this.Prod = new Array();
	this.id = args[0];
	this.name = args[1];
	this.addProd = AddProducts;
}

//Add Products to product category
function AddProducts()
{
	var args = AddProducts.arguments;
	for (var i=0; i< args.length; i++) {
		this.Prod[this.Prod.length] = args[i];
		args[i].PC = this;
	}
}

//Load Model Year dropdown
function LoadPc()
{
	var args = LoadPc.arguments;
	var objYear = eval("Year" + args[2]);
	var defaultOpt;
	
	if (objYear.PCs[0].name != null)
	{
		if (objYear.PCs.length > 1)
		{
			document.Search.hidProdCat.value = "";
			args[0].length = 0;
			if (document.Search.hidLayout.value == "ultimate")
				defaultOpt = new Option("Category", "0");
			else
				defaultOpt = new Option("Please Select a Product Category", "0");
			args[0].options[0] = defaultOpt;

			for (var i = 0; i < objYear.PCs.length; i++)
			{
				eval("var option" + i + " = new Option('" + objYear.PCs[i].name + "', '" + objYear.PCs[i].id + "')");
				eval("args[0].options[i+1]=option" + i);
				if (args[3] != null && args[3] > 0 && objYear.PCs[i].id == args[3])
					args[0].options[i+1].selected = true;		
			}
			if (document.getElementById("spanProd") != null)
				document.getElementById("spanProd").innerHTML = "<b>Select Category</b>";
		}
		else
		{
			document.Search.hidProdCat.value = objYear.PCs[0].id;
			LoadProd(args[0], args[1], args[2], objYear.PCs[0].id);
			if (document.getElementById("spanProd") != null)
				document.getElementById("spanProd").innerHTML = "<b>Select Product</b>";
		}
	}
	else
	{
		var option1 = new Option("*** No Category found for this Year in database ***", "0");
		args[0].options[1]=option1;
	}
}

// ****************** END OF RODUCT CATEGORY ***********************


// ******************** PRODUCTS ***************************
// Product Category Class
function Product()
{
	var args = Product.arguments;
	this.id = args[0];
	this.name = args[1];
}

//Load Model Year dropdown
function LoadProd()
{
	var args = LoadProd.arguments;
	var objPc = eval("PC" + args[2] + args[3]);
	var defaultOpt = new Option("Please Select a Product", "0");
	
	args[0].length = 0;
	if (document.Search.hidLayout.value == "ultimate")
		defaultOpt = new Option("Product", "0");
	else
		defaultOpt = new Option("Please Select a Product", "0");
	args[0].options[0] = defaultOpt;
	if (objPc.Prod[0].name != null)
	{
		for (var i = 0; i < objPc.Prod.length; i++)
		{
			eval("var option" + i + " = new Option('" + objPc.Prod[i].name + "', '" + objPc.Prod[i].id + "')");
			eval("args[0].options[i+1]=option" + i);
			if (args[4] != null && args[4] > 0 && objPc.Prod[i].id == args[4])
				args[0].options[i+1].selected = true;		
		}
	}
	else
	{
		var option1 = new Option("*** No Products found in database ***", "0");
		args[0].options[1]=option1;
	}
	
}

// ****************** END OF RODUCTS ***********************


function showManufacturers(bvdid, cidList)
{
	var result = "";

	if(cidList=="" || cidList=="0")
	{
		// IF NO CID LIST IS PASSED, SHOW ALL LOGOS
	
		for (var i=0; i < Makes.length; i++)
		{
			result = result +  "<div class='bsLogoList'><a href='javascript:LoadMake(" + Makes[i].id + ", " + bvdid + ");'><IMG src='http://media.channelblade.com/boat_graphics/logos/logo_" + Makes[i].id + ".jpg' border=0 width=125 alt='" + Makes[i].name + "'></a></div>";
		}
	
	}
	else
	{

		// IF CID LIST IS PASSED, SHOW ONLY MATCHING LOGOS

		cidList = "," + cidList + ",";

		for (var i=0; i < Makes.length; i++)
		{
	
			if(cidList.indexOf(','+Makes[i].id+',') > -1)
			{

				result = result +  "<div class='bsLogoList'><a href='javascript:LoadMake(" + Makes[i].id + ", " + bvdid + ");'><IMG src='http://media.channelblade.com/boat_graphics/logos/logo_" + Makes[i].id + ".jpg' border=0 width=125></a></div>";
			}
	
		}
	
	}
	
	
	
	return result;
}


function LoadMake(MakeId,bvdid)
{
	var isValidId = false;

	if (MakeId > 0)
	{
		for (var i=0; i< document.Search.cid.length; i++)
		{	
			if (document.Search.cid.options[i].value == MakeId)
			{
				document.Search.cid.options[i].selected = true;
				isValidId = true;
			}
		}
		if (isValidId)
			handleOnChange(document.Search.cid, bvdid)
	}
}
