Validator = new Object();



Validator.initialize = function(formId, fieldNum, submitId)

{

	Validator.currentSelector = '';

	Validator.currentForm = formId;

	Validator.fieldNumToValidate = fieldNum;

	Validator.submitId = submitId;

}



Validator.validate = function(selector, value)

{

	if(selector && value)

	{

		Validator.currentSelector = selector;

		AjaxUpdater.Update("GET", "services/users.xml", Validator.onValidation);

	}

}



Validator.onValidation = function()

{

	if(Ajax.checkReadyState('loading') == "OK")

	{

		var users = Ajax.getResponse().getElementsByTagName('user');

		for(var i=0; i<users.length; i++)

		{

			var value = users[i].getAttribute(Validator.currentSelector.id);

			if(value.toLowerCase() == Validator.currentSelector.value.toLowerCase())

			{

				Validator.currentSelector.style.borderColor = "#ff0000";

			}

			else

			{

				if(Validator.currentSelector.style.borderColor != "#009900")

				{

					Validator.currentSelector.style.borderColor = "#009900";

					Validator.fieldNumToValidate--;

				}

			}

			Validator.currentSelector.style.borderWidth = "2px";

		}

		

		if(Validator.fieldNumToValidate == 0)

		{

			document.getElementById( Validator.submitId ).disabled = false;

		}

	}

}