var formSubmitted = false;

function verifyDelete(name)
{
	return confirm('Are you sure that you want to delete the member '+name+'?');
}

// String all white spaces
function Trim(obj)
{
	obj.value = obj.value.replace(/\s/g, '');
}

// Right strip whitespaces
// Variables: strMyString - String to strip white space from
function RTrim(strMyString)
{
    return (strMyString.replace(/^\s*/,""));
}

// Left strip whitespaces
// Variables: strMyString - String to strip white space from
function LTrim(strMyString)
{
    return (strMyString.replace(/\s*$/,""));
}

// Left & Right strip whitespaces
// Variables: strMyString - String to strip white space from
function LRTrim(strMyString)
{
    return (RTrim(LTrim(strMyString)));
}

//ensures that a url containts http:// or https://, this is sued for
//adding links etc so they are treated as relative links
function validateURL(obj)
{
	rehttp = new RegExp("http:\/\/", "i")
	rehttps = new RegExp("https:\/\/", "i")

	url = LRTrim(obj.value);

	if (url != "")
	{
		if (!rehttp.test(url) && !rehttps.test(url))
		{
			obj.value = "http://"+url;
		}
	}
}

//searches a form for check boxes, takes their values and initiates
//an email to the values
function emailSelected(obj)
{
	var emailAddresses = "";
	var first = 1;
	for (var i=0;i<obj.elements.length;i++)
	{
		if (obj.elements[i].type == "checkbox")
		{
			if (obj.elements[i].checked)
			{
				if (first == 1)
				{
					emailAddresses += obj.elements[i].value;
					first = 2;
				}
				else
				{
					emailAddresses += ",";
					emailAddresses += obj.elements[i].value;
				}

   			}
		}
	}

	if (LRTrim(emailAddresses).length > 0)
	{
		window.location = "mailto:"+emailAddresses;
	}
}

//searches a form for check boxes, takes their values and initiates
//an email to the values
function selectAll(obj)
{
	for (var i=0;i<obj.elements.length;i++)
	{
		if (obj.elements[i].type == "checkbox")
		{
			obj.elements[i].checked = true;
		}
	}
}

function validateSend() {
	
	//check for recipients
	if (! document.faqSend.toChair.checked
		&& ! document.faqSend.toSecretary.checked
		&& ! document.faqSend.toTreasurer.checked
		&& ! document.faqSend.toIslandRep.checked)
	{
		alert("Please select someone to send this message to.");
		return false;
	}
	
	
	if (LRTrim(document.faqSend.email.value).length == 0) {
		alert("Please enter an email address.");
		return false;
	} else if (LRTrim(document.faqSend.message.value).length == 0) {
		alert("Please enter a question.");
		return false;
	} else {
		return true;
	}
}

