// checks form required fields by elements id
function required_fields(frm, str)
{
	var i, j, el, add, id;
	var radio = new Array();
	for (i = 0; i < frm.elements.length; i++)
	{
		el = frm.elements[i];
		if (el.id.indexOf(str) == -1 || el.style.display == 'none')
		{
			continue;
		}
		if ((el.type == "text" || el.type == "textarea") && !el.value)
		{
			return false;
		}
		if (el.type == "checkbox" && !el.checked)
		{
			return false;
		}
		if ((el.type == "select-one" || el.type == "select-multiple") && !el.selectedIndex)
		{
			return false;
		}
		if (el.type == "radio")
		{
			add = true;
			for (j = 0; j < radio.length; j++)
			{
				if (radio[j][0] == el.name)
				{
					if (radio[j][1] == false)
					{
						radio[j][1] = el.checked;
					}
					add = false;
				}
			}
			if (add)
			{
				radio[radio.length] = new Array(el.name, el.checked);
			}
		}
	}
	for (i = 0; i < radio.length; i++)
	{
		if (radio[i][1] == false)
		{
			return false;
		}
	}
	return true;
}
// checks if value is numberic
function is_numeric(str_in)
{
	var str = str_in.replace(/ /g, "");
	var valid = "0123456789";
	var is_valid = true;
	var i, char;
	for (i = 0; i < str.length && is_valid == true; i++)
	{
		char = str.charAt(i);
		if (valid.indexOf(char) == -1)
		{
			return false;
		}
	}
	return is_valid;
}

// checks if email address is valid
function valid_email(email)
{
	var at_pos, stop_pos;
	at_pos = email.indexOf("@");
	stop_pos = email.lastIndexOf(".");
	if (at_pos < 1 || stop_pos < 1 || stop_pos < at_pos || (stop_pos - at_pos) == 1 || ((email.length - stop_pos) - 1 < 2 || (email.length - stop_pos) - 1 > 4))
	{
		return false;
	}
	else {
		return true;
	}
}

