// JavaScript Document
var tempProdList = new Array();
var tempProdURL = new Array();
var tempCountry = new Array();

//Get all the countrynames.
tempCountry = countryName.split(';');

//Select products and product urls
for(i=0;i<tempCountry.length;i++){
	tempProdList[tempCountry[i]] = eval('Country'+(i+1)+'Products').split(';');
	tempProdURL[tempCountry[i]] = eval('Country'+(i+1)+'ProductsURL').split(';');
	//alert(tempProdList[tempCountry[i]].length);
}

//Objects for dropdowns and values
var oList1 = null;
var oList2 = null;
var arrList = tempProdList;
var arrListURL = tempProdURL; 
 
//Called onload of body
function initParentDD(){
 	//Initialize objects for parentand child drop downs
	oList1 = document.forms["dropDownForm"].elements["parentDD"]
	oList2 = document.forms["dropDownForm"].elements["childDD"]
	
	//Add options in the parent drop down
	 for(i=0;i<tempCountry.length;i++){
		 oList1.options[i+1] = new Option(tempCountry[i], tempCountry[i]);
	 }
	 
	 setDynaList();
}

function setDynaList(){
	//Clear all the values in the child drop down
	clearDynaList(oList2);

	 if (oList1.selectedIndex == -1 || oList1.selectedIndex == 0){
		 
		// If "Select" option is selected in parent then same for child
		oList1.selectedIndex = 0;
		  //var selArray = new Array();
		  //selArray[0] = new Array("Select Product");
		 // populateDynaList(oList2, 0, selArray);
		 oList2.selectedIndex = 0;
	}
	else{
	 //alert("  oList1[oList1.selectedIndex].value = " +  oList1[oList1.selectedIndex].value + "  arrList = "  + arrList)
	 //alert("Selected Index Value = " + oList1[oList1.selectedIndex].value);
		populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList, arrListURL);
	}
	return true;
}
 
function clearDynaList(oList){
	 for (var i = oList.options.length; i > 0; i--){
	 	oList.options[i] = null;
	 }
 
 oList.selectedIndex = -1;
}
 
function populateDynaList(oList, nIndex, aArray, aArrayURL){
//alert("oList = " + oList + " nIndex = " + nIndex + " aArray = " + aArray[nIndex] + " length = " + aArray[nIndex].length);
 for (var i = 0; i < aArray[nIndex].length; i++){
   oList.options[oList.options.length] = new Option(aArray[nIndex][i], aArrayURL[nIndex][i]);
 }
 if (oList.options.length == 0){
  oList.options[oList.options.length] = new Option("[none available]",0);
 }
 
 oList.selectedIndex = 0;

}

function gotoURL(){
	try{
		if(0 !=  oList2.selectedIndex){
			window.location = oList2.value;
			//alert(oList2.value)
		}
	}catch(e){}
}

function gotoCountryProduct(){
	try{
		URL = document.forms['dropDownForm'].elements['parentDD'].value
		//alert(URL)
		if(0 !=  URL){
			window.location = URL;
			//alert(oList2.value)
		}
		else{
			document.forms['dropDownForm'].elements['parentDD'].selectedIndex = 0;
		}
	}catch(e){}
}
