function validateRequiredFields(fields_array)
{	
	var i;
	
	for(i=0; i<fields_array.length; i++)
	{
		document.getElementById(fields_array[i]).style.backgroundColor = "white";
	}
	
	for(i=0; i<fields_array.length; i++)
	{
		var haystack = document.getElementById(fields_array[i]).value;
		haystack = stripWhitespace(haystack," ","");
		
		if(haystack.length == 0)
		{
			showFlashMessage("You must complete all required fields.");
			document.getElementById(fields_array[i]).style.backgroundColor = "red";
			window.scrollTo(0,0);
			return false;
		}
	}
	return true;
}

function stringReplaceAll(haystack, needle, new_needle)
{
	haystack = new String(haystack);
	var re = new RegExp(needle,"g");
	haystack = haystack.replace(re,new_needle);
	return haystack;
}

function stripWhitespace(str){
	str = new String(str);
	return str.replace(/\s+/g,'');
}
