// IN_ARRAY -------------------------------------------------------------------------------------------------------------------------------
// standard in_array function that javascript seems to lack
function in_array(current_value, used_array)
{
	for (var i=0; i<used_array.length; i++)
	{
		if (used_array[i] == current_value)
		{
			return true;
		}
	}
	return false;
}
			
			
			
// POP_UP ----------------------------------------------------------------------------------------------------------------------------------
// Opens our little popup window
function pop_up(page, x, y)
{
	var popup;
	popup = window.open(page, "popup", "height="+y+", width="+x+", menubar=0, resizable=1, scrollbars=1, status=1, toolbar=0");
}



// TRIM --------------------------------------------------------------------------------------------------------------------------------------
// like spiderman, only this does whatever a trim function can.
function trim(text_string) 
{
	if(text_string != '' && text_string != null && text_string != undefined)
	{
		// Remove leading spaces and carriage returns
		while ((text_string.substring(0,1) == ' ') || (text_string.substring(0,1) == '\n') || (text_string.substring(0,1) == '\r'))
		{
			text_string = text_string.substring(1,text_string.length);
		}
		
		// Remove trailing spaces and carriage returns
		while ((text_string.substring(text_string.length-1,text_string.length) == ' ') || (text_string.substring(text_string.length-1,text_string.length) == '\n') || (text_string.substring(text_string.length-1,text_string.length) == '\r'))
		{
			text_string = text_string.substring(0,text_string.length-1);
		}
	}
	return text_string;
}



// VALIDATE EMAIL ---------------------------------------------------------------------------------------------------------------
// just makes sure people are adding in a valid address when subscribing to our newsletter
function validate_email(email_address)
{
	if (email_address) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (reg.test(email_address) == false) 
		{
			alert('Sorry, this email address ('+email_address+') seems to be invalid.');
			return false;
		}
		return true;
	}
	return false;
}



