// Returns true if the element's reverse index is (n * a) + b for a given integer value of n.
bool StyleSheetNodeSelectorNthLastChild::IsApplicable(const Element* element, int a, int b)
{
	Element* parent = element->GetParentNode();
	if (parent == NULL)
		return false;

	// Start counting elements until we find this one.
	int element_index = 1;
	for (int i = parent->GetNumChildren() - 1; i >= 0; --i)
	{
		Element* child = parent->GetChild(i);

		// Skip text nodes.
		if (dynamic_cast< ElementText* >(child) != NULL)
			continue;

		// If we've found our element, then break; the current index is our element's index.
		if (child == element)
			break;

		if (child->GetDisplay() == DISPLAY_NONE)
			continue;

		element_index++;
	}

	return IsNth(a, b, element_index);
}
// Returns true if the element index is (n * a) + b for a given integer value of n.
bool StyleSheetNodeSelectorNthOfType::IsApplicable(const Element* element, int a, int b)
{
	Element* parent = element->GetParentNode();
	if (parent == NULL)
		return false;

	// Start counting elements until we find this one.
	int element_index = 1;
	for (int i = 0; i < parent->GetNumChildren(); ++i)
	{
		Element* child = parent->GetChild(i);

		// If we've found our element, then break; the current index is our element's index.
		if (child == element)
			break;

		// Skip nodes that don't share our tag.
		if (child->GetTagName() != element->GetTagName() ||
			child->GetProperty< int >(DISPLAY) == DISPLAY_NONE)
			continue;

		element_index++;
	}

	return IsNth(a, b, element_index);
}