//===================================================
function TrimStr(str)
{
	while(str.indexOf(" ") == 0 && str.length > 0)
		str = str.substr(1);

	while(str.lastIndexOf(" ") == str.length - 1 && str.length > 0)
		str = str.substr(0, str.length - 1);

	return str;
}

//=== Forms ==========================================

function ValidateAction(action, display)
{
	action = ReplaceStr("~#~", "'", action);
	display = ReplaceStr("~#~", "'", display);
	result = confirm("{VALIDATION_ValidateAction}");

	return result
}

function ValidateActionThenHREF(action, display, linkname, hrefyes, hrefno)
{
	result = confirm("{VALIDATION_ValidateAction}");

	if (result)
		window.document.link[linkname].href = hrefyes;
	else
		window.document.link[linkname].href = hrefno;
}

function PopValidationError(field, msg)
{
	alert(field + ": " + msg)
}


//=============================================


function IsLetter(c)
{
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function IsDigit(c)
{
	return ((c >= "0") && (c <= "9"));
}

function IsLetterOrDigit(c)
{
	return (IsLetter(c) || IsDigit(c));
}


function ValidateInteger(str)
{
	var i;
	var c;

    for (i = 0; i < str.length; i++)
    {
        c = str.charAt(i);
        if (!IsDigit(c))
			return false;
    }

    return true;
}


function ValidateMask(str, mask)
{
	var i;
	var c;

	if(str == "")
		return true;

	if(str.length != mask.length)
		return false;

    for (i = 0; i < str.length; i++)
    {
        c = str.charAt(i);

		switch(mask.charAt(i))
		{
			case '9':	if(!IsDigit(c))
							return false;
						break;
			case 'L':	if(!IsLetter(c))
							return false;
						break;
			case 'A':	if(!IsLetterOrDigit(c))
							return false;
						break;
		}
    }

    return true;
}





//=== Radio Stuff ==========================================

function RadioSelectedValue(radio)
{
	var checkedRadioValue = "";

	for (i = 0; i < radio.length; i++)
	{
		if (radio[i].checked == "1")
			checkedRadioValue = radio[i].value;
	}

	return (checkedRadioValue);
}

function RadioSelected(radio)
{
	var checkedRadio = "";

	for (i = 0; i < radio.length; i++)
	{
		if (radio[i].checked == "1")
			checkedRadio = i;
	}

	return (checkedRadio);
}

//===================================================
function SubmitForm(form, a, o, t, vt, k) {
	form.a.value = a;
	form.o.value = o;
	form.t.value = t;
	form.vt.value = vt;
	form.k.value = k;
	form.submit();
	return false;
}

