var gFlag = true;
var productSelected = " > ";

function PopulateNext(id)
{
	switch (id)
	{
		case '':
			var obj = document.getElementById("selectVersion");
			for(var i=0;i < arrVersions.length;i++)
			{
				var item = arrVersions[i];
				option = document.createElement("OPTION");
				option.value = item.split("#")[0];
				option.text = item.split("#")[1];
				obj.options[obj.options.length] = option;
			}
			var btn = document.getElementById("butSubmit");
			btn.disabled = true;
			btn.className = "buttonDis";	
			break;
		case 'selectVersion':
			var obj = document.getElementById("selectProd");
			obj.options.length = 0;
			document.getElementById("selectPlatform").options.length = 0;;
			document.getElementById("selectHost").options.length = 0;;
			document.getElementById("selectAPA").options.length = 0;;
			var val = document.getElementById(id).value;
			if (val == "" || val == 0) return;
			var item = arrProducts[val];
			if(item == null) return;
			var arr = item.split("$");
			for(var i =0; i < arr.length; i++)
			{
				var values = arr[i];
				option = document.createElement("OPTION");
				option.value = values.split("#")[0];
				option.text = values.split("#")[1];
				obj.options[obj.options.length] = option;
			}
			var btn = document.getElementById("butSubmit");
			btn.disabled = true;
			btn.className = "buttonDis";	
			break;
		case 'selectProd':
			var obj = document.getElementById("selectPlatform");
			obj.options.length = 0;
			document.getElementById("selectHost").options.length = 0;;
			document.getElementById("selectAPA").options.length = 0;;
			var val = document.getElementById(id).value;
			if (val == "" || val == 0) return;
			var item = arrPlatforms[val];
			if(item == null) return;
			var arr = item.split("$");
			for(var i =0; i < arr.length; i++)
			{
				var values = arr[i];
				option = document.createElement("OPTION");
				option.value = values.split("#")[0];
				option.text = values.split("#")[1];
				obj.options[obj.options.length] = option;
			}
			var btn = document.getElementById("butSubmit");
			btn.disabled = true;
			btn.className = "buttonDis";	
			break;
		case 'selectPlatform':
			var obj = document.getElementById("selectHost");
			obj.options.length = 0;
			document.getElementById("selectAPA").options.length = 0;;
			var val = document.getElementById(id).value;
			if (val == "" || val == 0) return;
			var item = arrHosts[val];
			if(item == null) return;
			var arr = item.split("$");
			for(var i =0; i < arr.length; i++)
			{
				var values = arr[i];
				option = document.createElement("OPTION");
				option.value = values.split("#")[0];
				option.text = values.split("#")[1];
				obj.options[obj.options.length] = option;
			}
			var btn = document.getElementById("butSubmit");
			btn.disabled = true;
			btn.className = "buttonDis";	
			break;
		case 'selectHost':
			var obj = document.getElementById("selectAPA");
			obj.options.length = 0;
			var val = document.getElementById(id).value;
			if (val == "" || val == 0) return;
			var item = arrAPA[val];
			if(item == null) return;
			var arr = item.split("$");
			for(var i =0; i < arr.length; i++)
			{
				var values = arr[i];
				option = document.createElement("OPTION");
				option.value = values.split("#")[0];
				option.text = values.split("#")[1];
				obj.options[obj.options.length] = option;
				
			}
			var btn = document.getElementById("butSubmit");
			btn.disabled = true;
			btn.className = "buttonDis";	
			break;
		default:
			var btn = document.getElementById("butSubmit");
			btn.disabled = false;
			btn.className = "buttonEn";
			btn.focus();
			break;
	}
	
	var qs = new Querystring();
		
	if(qs.get("hidSubmit") == "true" && gFlag)
	{
		gFlag = false;
	
		document.getElementById("selectVersion").value = qs.get("selectVersion");
		document.getElementById("selectVersion").onchange();
	
		document.getElementById("selectProd").value = qs.get("selectProd");
		document.getElementById("selectProd").onchange();
		
		document.getElementById("selectPlatform").value = qs.get("selectPlatform");
		document.getElementById("selectPlatform").onchange();
		
		document.getElementById("selectHost").value = qs.get("selectHost");
		document.getElementById("selectHost").onchange();
		
		document.getElementById("selectAPA").value = qs.get("selectAPA");	
	}
	
}

function ValidateFilterForm()
{
	if(document.getElementById("selectVersion").value == "" || document.getElementById("selectProd").value == "" || document.getElementById("selectPlatform").value == "" || document.getElementById("selectHost").value == "" || document.getElementById("selectAPA").value == "")
	{
		alert("You must choose all filter values");
		return;
	}
	
	document.getElementById('hidSubmit').value = 'true'
	document.getElementById("formFilter").submit();
}

function ShowContent(id)
{
	var tr = document.getElementById("trContent" + id);

	if(tr.style.display == 'none')
		tr.style.display = '';
	else
		tr.style.display = 'none';	
}

function RenderLabels()
{
	var qs = new Querystring();
	
	var versId = qs.get("selectVersion");
	var prodId = qs.get("selectProd");
	var platId = qs.get("selectPlatform");
	var hostId = qs.get("selectHost");
	var apaId = qs.get("selectAPA");
	
	for(var i=0; i < arrVersions.length; i++)
	{
		if(arrVersions[i].split("#")[0] == versId)
		{
			//document.getElementById("tdProd").innerText = arrProducts[i].split("#")[1];	
		//	document.getElementById("tdPath").innerText = "abc";
	     	productSelected += 	arrVersions[i].split("#")[1]+" , ";
		//	document.getElementById("productSelectedHtm").innerText = productSelected;
		}
	}
	
	var prodArray = arrProducts[versId].split("$");
	for(var i=0; i < prodArray.length; i++)
	{
		if(prodArray[i].split("#")[0] == prodId)
		{
			//document.getElementById("tdProd").innerText = arrProducts[i].split("#")[1];	
		//	document.getElementById("tdPath").innerText = "abc";
	     	productSelected += 	prodArray[i].split("#")[1]+" , ";
		//	document.getElementById("productSelectedHtm").innerText = productSelected;
		}
	}
	
	var platArr = arrPlatforms[prodId].split("$");
	for(var i=0; i < platArr.length; i++)
	{
		if(platArr[i].split("#")[0] == platId)
		{
			//document.getElementById("tdPlatform").innerText = platArr[i].split("#")[1];	
			productSelected +=platArr[i].split("#")[1]+" , ";	
		}
	}
	
	var hostArr = arrHosts[platId].split("$");
	for(var i=0; i < hostArr.length; i++)
	{
		if(hostArr[i].split("#")[0] == hostId)
		{
			//document.getElementById("tdHost").innerText = hostArr[i].split("#")[1];	
			productSelected += hostArr[i].split("#")[1]+" , ";		
		}	
	}		
	
	var apaArr = arrAPA[hostId].split("$");
	for(var i=0; i < apaArr.length; i++)
	{
		if(apaArr[i].split("#")[0] == apaId)
		{
			//document.getElementById("tdAPA").innerText = apaArr[i].split("#")[1];	
			productSelected += apaArr[i].split("#")[1]+"";
		}	
	}
	
	document.getElementById("tdPath").innerHTML += productSelected;

}

