

/*
 * Set the options for city, when the selection from state drop down is changed.
 */
function selectCity(ctresult)
{
	var para = document.StateForm.state.value;

	var city_id='';
	var state_id='';
	var city='';
	var str='';
	var i=0;
	var j=0;

	var theCityList = window.document.StateForm.city;
	var optionCounter;
	var counter;

	var knollLocation;
	
	
	knollLocation = document.LocationForm.knollLocation.value;
	
	if (knollLocation == "4") 
	{ 
		
		
		document.StateForm.submit();

	}


	if (document.StateForm.state.value=="")
	{
		for (optionCounter = theCityList.length - 1; optionCounter >= 0 ; optionCounter --)
		{
			theCityList.options[optionCounter] = null;
		}

		var option = new Option("Select City...","");
		theCityList.options[0] = option;
	}
	else
	{
		// Clear existing values from the City List

		for (optionCounter = theCityList.length - 1; optionCounter >= 0 ; optionCounter --)
		{
			theCityList.options[optionCounter] = null;
		}

		// Add values in the city dropdown

		str = ctresult.split("/");

		for (counter=0 ; counter<str.length ; counter++)
		{
			var arrCityList = str[counter].split(",");

			if (arrCityList.length>0)
			{
				state_id=arrCityList[1];

				if (j==0)
				{
					var option = new Option("Select City...","");
					theCityList.options[j] = option;
				}

				if (state_id==para)
				{
					var option = new Option(arrCityList[2],arrCityList[0]);
					theCityList.options[j+1] = option;
					j=j+1;
				}
			}// end of outer if condition
		}//end of for loop
	}
}

/*
* on change event sets the value of Knoll Location to StateForm
*/
function setKnollLocation()
{
	var knollLocation;

	knollLocation = document.LocationForm.knollLocation.value;

	document.StateForm.knollLocation.value = knollLocation;
	//	document.DealerForm.user.value = youare;

	if (knollLocation == "6")
	{
		gotoKT();
	}

	if (knollLocation == "7")
		{
			gotoKT();
	}


	if (knollLocation == "5")
	{
		gotoEtail();
	}
}

/*
* Check the value of Location Type, and country
*/
function gotoEtail()
{
	window.location.href = "/locations/knollspace_etailers.jsp";
}
function gotoKT()
{
	window.location.href = "/products/kt_locations.jsp";
}


function gotoEtailNoResult()
{
	window.location.href = "/locations/na_knollspace_etailers.jsp";
}

function checkValue1()
{

//     if (document.LocationForm.knollLocation.value=="etail")
//     {
//         gotoetail();
//     }

	if (document.LocationForm.knollLocation.value=="")
	{
		alert("Please Select Knoll Location");

		return false;
	}
	else
	{
		if (document.LocationForm.cntry.value=="")
		{
			alert("Please Select Country");

			return false;
		}
		else
		{
			return true;
		}
	}
}

/*
* Check the value of Location Type, and state, city
*/
function checkValue2()
{
	if (document.StateForm.knollLocation.value=="")
	{
		alert("Please Select Knoll Location");
		return false;
	}
	else
	{
		if (document.StateForm.state.value=="")
		{
			alert("Please Select State");
			return false;
		}
		else
		{
			if (document.StateForm.city.value=="")
			{
				alert("Please Select City");
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}

/*
* Check the value of Location Type, and country
*/
function checkValue3(knollLocation)
{
	var knollLocation = knollLocation;

	document.LocationForm.knollLocation.value = knollLocation;
	document.StateForm.knollLocation.value = knollLocation;
	document.DealerForm.knollLocation.value = knollLocation;

	if (document.LocationForm.cntry.value=="")
	{
		alert("Please Select Country");
		return false;
	}
	else
	{
		return true;
	}
}

/*
* Check the value of Location Type, and state, city
*/
function checkValue4(knollLocation)
{
	var knollLocation = knollLocation;

	document.LocationForm.knollLocation.value = knollLocation;
	document.StateForm.knollLocation.value = knollLocation;
	document.DealerForm.knollLocation.value = knollLocation;

	if (document.StateForm.state.value=="")
	{
		alert("Please Select State");
		return false;
	}
	else
	{
		if (document.StateForm.city.value=="")
		{
			alert("Please Select City");
			return false;
		}
		else
		{
			return true;
		}
	}
}


/*
   PURPOSE: Check for the blank dealer value and alert the user.
*/
function SelectDealer()
{
	if ((document.DealerForm.dname.value=="")||(document.DealerForm.dname.value==null))
	{
		alert("Please enter Dealership Name");
		document.DealerForm.dname.value="";
		return false;
	}
	else
	{
		var str = document.DealerForm.dname.value;
		var tmp = LTrim(str);

		if (tmp==""||tmp==" ")
		{
			alert("Please enter valid Dealership Name");
			document.DealerForm.dname.value="";
			return false;
		}
		else
		{
			return true;
		}

	}
}

/*
   PURPOSE: Check for the user & blank dealer value and alert the user.
*/
function SelectDealer1(knollLocation)
{
	var knollLoc = knollLocation;

	document.LocationForm.knollLocation.value = knollLoc;
	document.StateForm.knollLocation.value = knollLoc;
	document.DealerForm.knollLocation.value = knollLoc;

	if ((document.DealerForm.dname.value=="")||(document.DealerForm.dname.value==null))
	{
		alert("Please enter Dealership Name");
		document.DealerForm.dname.value="";
		return false;
	}
	else
	{
		var str = document.DealerForm.dname.value;
		var tmp = LTrim(str);

		if (tmp==""||tmp==" ")
		{
			alert("Please enter valid Dealership Name");
			document.DealerForm.dname.value="";
			return false;
		}
		else
		{
			return true;
		}

	}
}

/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
function LTrim(str)
{
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1)
	{
		// We have a string with leading blank(s)...

		var j=0, i = s.length;

		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;

		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = s.substring(j, i);
	}
	return s;
}

