﻿// JScript File


function SuperCatChange(obj){
	CreateArray(obj);
	var selSuperCat = document.all.frm.test_SuperCatSelect.value;
	 var choice = document.frm.test_CatSelect;
    var selCat = choice.options[choice.selectedIndex].text;
	//alert('selCat:'+selSuperCat);
	var SubCat = '';
	SetSelect(selSuperCat, selCat, SubCat);
}
function CatChange()
{
	var selSuperCat = document.all.frm.test_SuperCatSelect.value;
	 var choice = document.frm.test_CatSelect;
    var selCat = choice.options[choice.selectedIndex].text;
	//alert ('category:'+ selCat);
	var SubCat = '';
	SetSelect(selSuperCat, selCat, SubCat);
}
function SetSelect(supercat, cat, subcat)
{
	if (supercat == "")	
		supercat = "0";
	if (cat == "")
		cat = "0";
	var Sel = 'supercat:' + supercat + ';cat:' + cat + ';subcat:' + subcat;
	//alert('Selection:'+Sel);
	document.getElementById('hideSelCat').value = Sel;
}

function CreateArray(objName)
{
	var	obj=document.getElementById(objName);
	var s = objName;
	obj.innerHTML =" ";
	var i = document.all.frm.test_SuperCatSelect.selectedIndex; 
	//alert('index'+i);
	var arr = GetArray(i);
	//alert('creatCat'+arr);
	if (arr != null)
	{
	var l = arr.length;
	for (i=0;i<l;i++)
	
	{
		var Option = document.createElement("OPTION");
		Option.text=arr[i];
		Option.value=i;
		obj.add(Option);
	}
	}
	else 
	{
		Option.text="";
		Option.value=0;
		obj.add(Option);
	}
	
}
function Selection(objName,SelectValue)
{ 
	var	obj=document.getElementById(objName); 
	obj.options[obj.selectedIndex].text = SelectValue;
}


////***FileEdit***////

function CreateCatArray()
{
	var	obj=document.getElementById('test:CatSelect');
	obj.innerHTML =" ";
	var i = document.all.frm.test_SuperCatSelect.selectedIndex;
	//i = i+ 1;
	//alert('index : ' +i);
	var arr = GetCategoryArray(i);
	//alert('categoryFile:'+arr);
	var l = arr.length;
	if (l != null)
	{
		for (i=0;i<l;i++)
		{
			var Option = document.createElement("OPTION");
			Option.text=arr[i];
			Option.value=i;
			obj.add(Option);
		}
	}
	else 
	{
		Option.text="";
		Option.value=0;
		obj.add(Option);
	}
}

function CreateSubCatArray(objName)
{
	var	obj=document.getElementById(objName);
var s = objName;
	obj.innerHTML =" ";
	var i = document.all.frm.test_SuperCatSelect.selectedIndex; 
	//i= i + 1;
	var j = document.all.frm.test_CatSelect.selectedIndex;
	//alert('i:'+i+' j:'+j); 
	var arr = GetsubcatArray(i,j);
	
	//alert ('getSubcat'+arr);
	var l = arr.length;
	if (l != null)
	{
	for (i=0;i<l;i++)
	
	{
		var Option = document.createElement("OPTION");
			Option.text=arr[i];
		Option.value=i;
		obj.add(Option);
		
	}
	}
	else 
	{
		Option.text="";
		Option.value=0;
		obj.add(Option);
	}
}
function SuperCatArrayChange(){
	CreateCatArray();
	CreateSubCatArray('test_SubCatSelect');
	var selSuperCat = document.all.frm.test_SuperCatSelect.value;
	 var choice = document.frm.test_CatSelect;
    var selCat = choice.options[choice.selectedIndex].text;
	//alert ('category:'+ selCat);
	 var subCatchoice = document.frm.test_SubCatSelect;
	var selSubCat = subCatchoice.options[subCatchoice.selectedIndex].text;
	SetSelect(selSuperCat, selCat, selSubCat);
}
function catArrayChange(obj){
	CreateSubCatArray(obj);
	var selSuperCat = document.all.frm.test_SuperCatSelect.value;
	//alert('supercat:'+selSuperCat);
	 var choice = document.frm.test_CatSelect;
    var selCat = choice.options[choice.selectedIndex].text;
	//alert ('category:'+ selCat);
	 var subCatchoice = document.frm.test_SubCatSelect;
	// alert('subcatChoice'+subCatchoice);
	 if (subCatchoice.selectedIndex != null)
	 {
		var selSubCat = subCatchoice.options[subCatchoice.selectedIndex].text;
	 }
	//alert('subcategory'+selSubCat);
	//alert('sup,cat,sub:'+selSuperCat+selCat+selSubCat);
	SetSelect(selSuperCat, selCat, selSubCat);
}
function subcatArrayChange()
{
var selSuperCat = document.all.frm.test_SuperCatSelect.value;
	 var choice = document.frm.test_CatSelect;
    var selCat = choice.options[choice.selectedIndex].text;
	//alert ('category:'+ selCat);
	 var subCatchoice = document.frm.test_SubCatSelect;
	var selSubCat = subCatchoice.options[subCatchoice.selectedIndex].text;
	SetSelect(selSuperCat, selCat, selSubCat);
}