var PreviousStatusErrorCondition = 0
var CurrentStatusErrorCondition = 0


function formAction(listObjName){

//0 - no select
//1 - no error. all error statuses is disabled
//2 - all error. all error statuses is disabled
//3 - select only error status
    var listObj = document.getElementById(listObjName);
	var listLength = listObj.length
	var currSelected = listObj.selectedIndex

  getCurrentErrorCondition(listObj);
  setErrorCondition(listObj);
  PreviousStatusErrorCondition = CurrentStatusErrorCondition;
}


function getPreviousErrorCondition(listObjName)
{
    var listObj = document.getElementById(listObjName);
	for (var i = 0; i < listObj.length; i++) 
  {
		if (listObj.options[i].text.toLowerCase() == 'all errors' && listObj.options[i].selected == true)
		{
			 PreviousStatusErrorCondition = 2;
			 break;
		}else if (listObj.options[i].text.toLowerCase() == 'no errors' && listObj.options[i].selected == true)
		{
			PreviousStatusErrorCondition = 1;
			break;
		}else if (listObj.options[i].text.toLowerCase() != 'no errors' && listObj.options[i].text.toLowerCase() != 'all errors' && listObj.options[i].selected == true)
		{
			PreviousStatusErrorCondition = 3;
			break;
		}else if (listObj.selectedIndex==-1)
		{
			PreviousStatusErrorCondition = 0;
			break;
		}
  }
  
}

function getCurrentErrorCondition(listObj)
{
	for (var i = 0; i < listObj.length; i++) 
  {
		if ((PreviousStatusErrorCondition==1 || PreviousStatusErrorCondition==0 || PreviousStatusErrorCondition==3) && listObj.options[i].text.toLowerCase() == 'all errors' && listObj.options[i].selected == true)
		{
			 CurrentStatusErrorCondition = 2
		}else if ((PreviousStatusErrorCondition==2 || PreviousStatusErrorCondition==0 || PreviousStatusErrorCondition==3) && listObj.options[i].text.toLowerCase() == 'no errors' && listObj.options[i].selected == true)
		{
			CurrentStatusErrorCondition = 1
		}else if (listObj.selectedIndex==-1)
		{
			CurrentStatusErrorCondition = 0
		}
  }
}

function setErrorCondition(listObj)
{
	for (var i = 0; i < listObj.length; i++) 
  {
		if (CurrentStatusErrorCondition == 1)
		{
			if (listObj.options[i].text.toLowerCase() != 'no errors')
			{
				listObj.options[i].selected = false;
				setErrorConditionDisableStyle(listObj.options[i], 'gray');
			}else
			{
				listObj.options[i].selected = true;
			}
		}
		if (CurrentStatusErrorCondition == 2)
		{
			if (listObj.options[i].text.toLowerCase() != 'all errors')
			{
				listObj.options[i].selected = false;
				setErrorConditionDisableStyle(listObj.options[i], 'gray');
			}else
			{
				listObj.options[i].selected = true;
			}
			
		}
		if (CurrentStatusErrorCondition == 0)
		{
			setErrorConditionDisableStyle(listObj.options[i], 'black');
		}
		
  }
}

function setErrorConditionDisableStyle(obj, color)
{
	if (obj.text.toLowerCase() != 'all errors' && obj.text.toLowerCase() != 'no errors')
	{
		obj.style.color = color;
	}
		
}






