var selIndex;

function EvaluateSub(obj)
{
	var subObj = document.getElementById('subcategory');

	selIndex = obj.selectedIndex;

	removeAllOptions(subObj);
	
	if(selIndex==0)
	{
		addOption(subObj, "Please select a category first", "", 0)
	}
	else if(selIndex==1)
	{		
		addOption(subObj, "Select a topic", "", 0)

		if(topic != "Training/General")
			addOption(subObj, "Training/General", "Training/General", 0);
		else
			addOption(subObj, "Training/General", "Training/General", 1);
			
		if(topic != "Nutrition")
			addOption(subObj, "Nutrition", "Nutrition", 0);
		else
			addOption(subObj, "Nutrition", "Nutrition", 1);
			
		if(topic != "Supplements")
			addOption(subObj, "Supplements", "Supplements", 0);
		else
			addOption(subObj, "Supplements", "Supplements", 1);
			
		if(topic != "Motivational")
			addOption(subObj, "Motivational", "Motivational", 0);
		else
			addOption(subObj, "Motivational", "Motivational", 1);
			
		if(topic != "Six_Pack_Ab/Belly_Fat_Loss")
			addOption(subObj, "Six Pack Ab/Belly Fat Loss", "Six_Pack_Ab/Belly_Fat_Loss", 0);
		else
			addOption(subObj, "Six Pack Ab/Belly Fat Loss", "Six_Pack_Ab/Belly_Fat_Loss", 1);
	}
	else if (selIndex==2)
	{
		addOption(subObj, "Select a topic", "", 0)

		if(topic != "Training/General")
			addOption(subObj, "Training/General", "Training/General", 0);
		else
			addOption(subObj, "Training/General", "Training/General", 1);
			
		if(topic != "Nutrition")
			addOption(subObj, "Nutrition", "Nutrition", 0);
		else
			addOption(subObj, "Nutrition", "Nutrition", 1);
			
		if(topic != "Supplements")
			addOption(subObj, "Supplements", "Supplements", 0);
		else
			addOption(subObj, "Supplements", "Supplements", 1);
			
		if(topic != "Motivational")
			addOption(subObj, "Motivational", "Motivational", 0);
		else
			addOption(subObj, "Motivational", "Motivational", 1);
	}
	else
	{
		addOption(subObj, "No need to select topic", "", 0)
	}
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}

function addOption(selectbox,text,value, selected)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	if(selected==1)
		optn.selected = true;
	selectbox.options.add(optn);
	
}

function fnSelect(objId)
{
   fnDeSelect();
   if (document.selection) 
   {
      var range = document.body.createTextRange();
      range.moveToElementText(document.getElementById(objId));
      range.select();
   }
   else if (window.getSelection) 
   {
      var range = document.createRange();
      range.selectNode(document.getElementById(objId));
      window.getSelection().addRange(range);
   }
}

function fnDeSelect() 
{
   if (document.selection)
             document.selection.empty();
   else if (window.getSelection)
              window.getSelection().removeAllRanges();
} 
