// Created by: David Doan Ngo
// Created on: Oct 12, 2004
// Purpose: House variuous tasks for use within a web site.
// Contact: ngodavid@sbcglobal.net

/* Re-install the three select script from already run online */
/* 5. This block is for the left panel select boxes.  The block ahead of this block is in the application page */
// Function to fill the second (the Cate select box) based on the first (the Brand select box's value)
	function generateCate()
	{
		// get the currently selected BrandID from the Brand (the first) select box
		with (document.searchrecord.BrandID)
		{
			var brandID = options[selectedIndex].value;
		}
		
		// if there is no selected Brand
		if (brandID == "")
		{
			return;
		}
		
		// Remove all options from the second select box
		document.searchrecord.CateID.options.length = 0;
		
		//document.searchrecord.ModelID.options.length = 0; // add this to have the third box empty if second empty based on first box's selection
		
		// For each item in the Cate array
		for (var i = 0; i < arCate.length; i++)
		{
			// If the brand's is the same as the currently selected rating
			if(arCate[i].brandID == brandID)
			{
				// create a new visual <option> to place in the second select box
				var objOption = new Option(arCate[i].cateName, arCate[i].cateID);
				
				// place the new option in the second select box
				with(document.searchrecord.CateID)
				{
					options[options.length] = objOption;
				}
			}
		}
	}
	
	
	
	// Function to fill the second (the Model select box) based on the first (the Brand select box's value)
	function generateModel()
	{
		// get the currently selected BrandID from the Brand (the first) select box
		with (document.searchrecord.CateID)
		{
			var cateID = options[selectedIndex].value;
		}
		
		// if there is no selected Brand
		if (cateID == "")
		{
			return;
		}
		
		// Remove all options from the second select box
		document.searchrecord.ModelID.options.length = 0;
		
		// For each item in the model array
		for (var i = 0; i < arModels.length; i++)
		{
			// If the brand's is the same as the currently selected rating
			if(arModels[i].cateID == cateID)
			{
				// create a new visual <option> to place in the second select box
				var objOption = new Option(arModels[i].modelName, arModels[i].modelID);
				
				// place the new option in the second select box
				with(document.searchrecord.ModelID)
				{
					options[options.length] = objOption;
				}
			}
		}
	}
	

//2. for collapsible menu list and customer service
// Row Hide function.
function expandcontract(tbodyid,imagename) 
{
	if (document.getElementById(tbodyid).style.display == '')
	{
		document.getElementById(tbodyid).style.display = 'none';
		document.getElementById(imagename).src = "images/sitegraphics/c.gif";
	} 
	else 
	{
		document.getElementById(tbodyid).style.display = '';
		document.getElementById(imagename).src = "images/sitegraphics/e.gif";
	}
}

//3. for textbox validating in search forms
/*
function validate_bar_search()
{
	if (document.searchrecord_bar.OEMPartOrProductName.value == "" || document.searchrecord_bar.OEMPartOrProductName.value == null)
	{
		alert ("Please enter a word to search.");
		return false;
	}
}
*/ 
// for quick search right panel
function validate_quick_search()
{
	if(document.searchrecord.BrandID.selectedIndex == 0)
	{
		alert ("Please select a brand, a category, and a model.");
		return false;
	}
}

// for store care shipping method.  customer must select a shipping method
function validate_shipping_method()
{
	if(document.shippingoption.ShippingRatePK.selectedIndex == 0)
	{
		alert ("Please select a Shipping Method.");
		return false;
	}
}

// for customer registering.  customer must select a state
function validate_state()
{
	if(document.customercontact.state.selectedIndex == 0)
	{
		alert ("Please select a State.");
		return false;
	}
}

// for customer registering.  customer must select a state
function validate_textarea()
{
	if(document.customerservie.message.value == "")
	{
		alert ("Please enter your request or comment.");
		return false;
	}
}

//4. for no click : don't want people to look at View Source by right-clicking
function disable()
{
	if (event.button == 2)
	{
		alert("No View Source is avail.");
	}
}



//5. this is just like the #2 for customer service but for the Admin left panel 
//2. for collapsible menu list and customer service
// Row Hide function.
function expandcontractAdmin(tbodyid,imagename) 
{
	if (document.getElementById(tbodyid).style.display == '')
	{
		document.getElementById(tbodyid).style.display = 'none';
		document.getElementById(imagename).src = "../images/sitegraphics/c.gif";
	} 
	else 
	{
		document.getElementById(tbodyid).style.display = '';
		document.getElementById(imagename).src = "../images/sitegraphics/e.gif";
	}
}

// open window for what is this at store cart
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}