var VerifyFormWarning = false;

function VerifyForm(Form, WarningMessage, EmptyMessage, WarningClass, EmptyClass)
{
	ReturnValue = true;
	EmptyValue = false;
	WarningValue = false;

	for(LoopElement=0;LoopElement<Form.length;LoopElement++)
	{
		Value = false;
		switch(Form.elements[LoopElement].type)
		{
			case "select-one":
				Value = Form.elements[LoopElement].options[Form.elements[LoopElement].selectedIndex].value;
				break;

			case "select-multiple":
				for(Loop=0;Loop<Form.elements[LoopElement].length;Loop++)
					if (Form.elements[LoopElement].options[Loop].selected)
						Value = true;
				break;

			case "radio":
				if (Form.elements[Form.elements[LoopElement].name].length)
				{
					for(Loop=0;Loop<Form.elements[Form.elements[LoopElement].name].length;Loop++)
						if (Form.elements[Form.elements[LoopElement].name][Loop].checked)
							Value = Form.elements[Form.elements[LoopElement].name][Loop].value;
				}
				else
					Value = Form.elements[LoopElement].value;
				break;

			default:
				Value = Form.elements[LoopElement].value;
				break;
		}

		if (Form.elements[LoopElement].type!="submit")
		{
			switch(Form.elements[LoopElement].getAttribute("verify"))
			{
				case "Empty":
					if (!Value)
					{
						if (VerifyFormEmptyActionFalse)
							VerifyFormEmptyActionFalse(Form.elements[LoopElement], EmptyClass);
						EmptyValue = true;
					}
					else
						if (VerifyFormEmptyActionTrue)
							VerifyFormEmptyActionTrue(Form.elements[LoopElement]);
					break;

				case "Warning":
					if (!Value)
					{
						if (VerifyFormWarningActionFalse)
							VerifyFormWarningActionFalse(Form.elements[LoopElement], WarningClass);
						WarningValue = true;
					}
					else
						if (VerifyFormWarningActionTrue)
							VerifyFormWarningActionTrue(Form.elements[LoopElement]);
					break;
			}
		}
	}

	Message = "";

	if (EmptyValue)
		Message = EmptyMessage;

	if ((WarningValue)&&(!VerifyFormWarning))
	{
		if (EmptyValue)
			Message += "\r\n\r\n";
		Message += WarningMessage;
		VerifyFormWarning = true;
	}

	if (Message)
	{
		alert(Message);
		ReturnValue = false;
	}
	return(ReturnValue);
}

function VerifyFormEmptyActionFalse(Item, CSSClass)
{
	if (!Item.classNameOut)
	{
		Item.classNameOut = Item.className;
		Item.className = Item.className + CSSClass;
	}
}

function VerifyFormEmptyActionTrue(Item)
{
	if (Item.classNameOut)
	{
		Item.className = Item.classNameOut;
		Item.classNameOut = null;
	}
}

function VerifyFormWarningActionFalse(Item, CSSClass)
{
	if (!Item.classNameOut)
	{
		Item.classNameOut = Item.className;
		Item.className = Item.className + CSSClass;
	}
}

function VerifyFormWarningActionTrue(Item)
{
	if (Item.classNameOut)
	{
		Item.className = Item.classNameOut;
		Item.classNameOut = null;
	}
}

function FormSubmit(Object, Page, Variable, Method, Verify)
{
	if (typeof(Verify)=="undefined")
		Verify = true;
	if (typeof(Method)=="undefined")
		Method = null;

	while ((Object)&&(Object.nodeName != "FORM"))
		Object = Object.parentNode;

	if ((Object)&&((!Verify)||(Object.onsubmit())))
	{
		if (Method)
			Object.method = Method;

		if (Page)
		{
			if (Object.action.indexOf("?")==-1)
				Object.action = Page;
			else
				Object.action = Page + Object.action.substr(Object.action.indexOf("?"));
		}

		if (Variable)
		{
			if (Object.action.indexOf("?")==-1)
				Object.action += "?"+Variable;
			else
				Object.action += "&"+Variable;
		}

		Object.submit();
	}
	else alert('oooooo');
}

function FormSubmit2(Object, Page, Variable, Method, Verify)
{
	if (typeof(Verify)=="undefined")
		Verify = true;
	if (typeof(Method)=="undefined")
		Method = null;

	while ((Object)&&(Object.nodeName != "FORM"))
		Object = Object.parentNode;

	if ((Object)&&((!Verify)||(Object.onsubmit())))
	{
		if (Method)
			Object.method = Method;

		if (Page)
		{
			Object.action = Page;
		}

		if (Variable)
		{
			if (Object.action.indexOf("?")==-1)
				Object.action += "?"+Variable;
			else
				Object.action += "&"+Variable;
		}

		Object.submit();
	}
	else alert('oooooo');
}


function GetForm(Object)
{
	while ((Object)&&(Object.nodeName != "FORM"))
		Object = Object.parentNode;

	if ((Object)&&(Object.nodeName == "FORM"))
		return(Object);
	else
		return(null);
}

function GetFormItemValue(Object, Item)
{
	Form = GetForm(Object);

	Value = "";
	switch(Form.elements[Item].type)
	{
		case "select-one":
			Value = Form.elements[Item].options[Form.elements[Item].selectedIndex].value;
			break;

		case "select-multiple":
			for(Loop=0;Loop<Form.elements[Item].length;Loop++)
				if (Form.elements[Item].options[Loop].selected)
				{
					Value = Form.elements[Item].options[Loop].value;
					break;
				}
			break;

		case "radio":
			for(Loop=0;Loop<Form.elements[Item].length;Loop++)
				if (Form.elements[Item][Loop].checked)
					Value = Form.elements[Item][Loop].value;
			break;

		default:
			Value = Form.elements[Item].value;
			break;
	}

	return(Value);
}

/*
function ActionRefresh(Form, Scroll)
{
	Form.form.ActionSubmit.value = '1';
	Form.form.ActionPage.value = '';
	Form.form.ActionSave.value = '';
	Form.form.ActionRedirect.value = '';
	Form.form.ActionMultiple.value = '';
	Form.form.ActionScroll.value = Scroll;
	Form.form.submit();
}

function ActionNextPage(Form, Page, Submit)
{
	if (typeof(Submit)=="undefined")
		Submit = true;

	if (typeof(Form.multi)!="undefined")
		Form.form.ActionMultiple.value = Form.multi;
	else
		Form.form.ActionMultiple.value = '';

	Form.form.ActionPage.value = Page;
	Form.form.ActionSave.value = '';
	Form.form.ActionRedirect.value = '';

	if (Submit)
	{
		Form.form.ActionSubmit.value = true;
		Form.form.submit();
	}
}

function ActionSavePage(Form, Redirect)
{
	Form.form.ActionSave.value = 1;
	Form.form.ActionRedirect.value = Redirect;
}

function DropDownVerifyAction(Form)
{
	if (Form.selectedIndex>=0)
	{
		if (typeof(Form.options[Form.selectedIndex].refresh)!="undefined")
			ActionRefresh(Form, FindPosition(Form)[1]);

		if (typeof(Form.options[Form.selectedIndex].page)!="undefined")
			ActionNextPage(Form, Form.options[Form.selectedIndex].page);
	}
}

function CheckBoxVerifyAction(Form)
{
	if (typeof(Form.refresh)!="undefined")
		if (Form.checked)
			ActionRefresh(Form, Form.style.top);

	if (typeof(Form.page)!="undefined")
		if (Form.checked)
			ActionNextPage(Form, Form.page);
}

function FindPosition(Object)
{
	var PositionLeft = PositionTop = 0;
	if (Object.offsetParent)
	{
		PositionLeft = Object.offsetLeft;
		PositionTop = Object.offsetTop;
		while (Object = Object.offsetParent)
		{
			PositionLeft += Object.offsetLeft;
			PositionTop += Object.offsetTop;
		}
	}

	return [PositionLeft, PositionTop];
}

function ScrollWindow(Position)
{
	if (document.readyState=="complete")
		window.scrollTo(0, Position);
	else
		window.attachEvent('onload', function() {window.scrollTo(0, Position)});

}

function GetAdjacentInputName(Object)
{
	while(Object.parentNode)
	{
		Object = Object.parentNode;
		for (Loop=0;Loop<Object.childNodes.length;Loop++)
			if ((Object.childNodes[Loop].nodeName=="INPUT")&&(Object.childNodes[Loop].type=="text"))
				return(Object.childNodes[Loop].name);
	}
}

function GetAdjacentInputValue(Object)
{
	while(Object.parentNode)
	{
		Object = Object.parentNode;
		for (Loop=0;Loop<Object.childNodes.length;Loop++)
			if ((Object.childNodes[Loop].nodeName=="INPUT")&&(Object.childNodes[Loop].type=="text"))
				return(Object.childNodes[Loop].value);
	}
}

function SetInputValue(Value, InputName)
{
	if (document.forms[0].elements[InputName])
		document.forms[0].elements[InputName].value = Value;
}

function GetFormItemValue(Item)
{
	Value = "";
	switch(Item.type)
	{
		case "select-one":
			Value = Item.options[Item.selectedIndex].value;
			break;

		case "select-multiple":
			for(Loop=0;Loop<Item.length;Loop++)
				if (Item.options[Loop].selected)
				{
					Value = Item.options[Loop].value;
					break;
				}
			break;

		case "radio":
			for(Loop=0;Loop<Form.elements[Item.name].length;Loop++)
				if (Form.elements[Item.name][Loop].checked)
					Value = Form.elements[Item.name][Loop].value;
			break;

		default:
			Value = Item.value;
			break;
	}

	return(Value);
}
*/
