/////////////////////////////////////////////////////////////////////////////
//
//                       Copyright (c) 2008
//                       Stanley Adams Group, Inc.
//                       USA
//
//                       All Rights Reserved
//
//   This source file is subject to the terms and conditions of the
//   Stanley Adams Group Software License Agreement which restricts the manner
//   in which it may be used.
//   It's strictly forbidden to copy or use without 
//	 written permission unless viewed from the following web sites:
//		www.theothersolutions.com
//		www.stanleyadamsgroup.com
//   Mail: contact@StanleyAdamsGroup.com
//
/////////////////////////////////////////////////////////////////////////////
//
// Module name     :   wf_common.js
// Module ID Nbr   :   
// Description     :   Javascript common function
// --------------------------------------------------------------------------
// Change Record   :   
//
// Version	Author/Date		Description of changes
// -------  -------------	----------------------
// 01.01	HVE/2006-Dec-29	Initial release
// 01.02 	HVE/2007-Apr-04	wf_initbrand always initialize selectedIndex to zero
// 01.03	HVE/2007-Apr-19	Check for correct instanceof Class
// End of Change Record
//
/////////////////////////////////////////////////////////////////////////////

function wf_initbrand(form,discon)
	{
	form.Brand.options.length=1;
	get_brand_info();
	for(var i in brand_data) if(brand_data[i] instanceof Brand) 
			{var s=i;
			if(s=="gtco calcomp") s="gtco"; 
			if(String(document.title).search(new RegExp(s,"i"))!=-1||String(document.location).search(new RegExp(s,"i"))!=-1) 
				form.Brand.options[form.Brand.options.length]=new Option(brand_data[i].brand,brand_data[i].brand.toLowerCase(),true,true);
			}
				
	if(form.Brand.options.length==1) // Init all brands if limited selection has not been found
		{
		for(var i in brand_data) if(brand_data[i] instanceof Brand)
			{ /*alert("Brand add:"+i);*/ form.Brand.options[form.Brand.options.length]=new Option(brand_data[i].brand,brand_data[i].brand.toLowerCase(),true,true);}
		}
   form.Brand.selectedIndex=0;
	var dflag=false;
	if(arguments.length==2) dflag=discon;
	wf_brandchange(form,dflag);
	}
	
function wf_brandchange(form,discon)
	{
	var sc, dflag=false;
	if(arguments.length==2) dflag=discon;
	if(form.Brand.selectedIndex==0||form.Brand.options[form.Brand.selectedIndex ].value=="") { return;} // Nothing selected
	sc=get_brand_info(form.Brand.options[form.Brand.selectedIndex ].value);
	if(form.Picturebrand!=undefined) form.Picturebrand.src=sc.picture;
	get_model_info("");
	// Change model list based on brands
	if(form.Model!=undefined)
		{
		form.Model.options.length=1;
		for(var i in model_data) if(instanceof_model(model_data[i]))
			if((dflag==-1||model_data[i].discontinued==dflag) && model_data[i].brand.toLowerCase()==form.Brand.options[form.Brand.selectedIndex ].value.toLowerCase())
				form.Model.options[form.Model.options.length]=new Option(model_data[i].name,i,false,false);	
		}				
	}
	
function wf_setdefault_brand(form,brand)
	{
	if(brand!=undefined)
		for(var i=0;i<form.Brand.options.length;i++)
			if(form.Brand.options[i].value==brand) { form.Brand.selectedIndex=i; return true; }
	return false;
	}
	
function wf_setdefault_model(form,model)
	{
	if(model!=undefined)
		for(var i=0;i<form.Model.options.length;i++)
			if(form.Model.options[i].value==model) { form.Model.selectedIndex=i; return true; }
	return false;
	}