function clearText(obj)
{
	if (obj.value == obj.title)
	{
		obj.value = ''
	}
	else if(obj.value == '')
	{
		obj.value = obj.title;
	}
}
function emailCheck(str){
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	// check if string contains @sign
	if (str.indexOf(at)==-1){
	   return false
	}
	// check if @sign not at beginning of string
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	// check if period not at beginning of string
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}

	 return true					
}// end function emailCheck
function submit_oilspill_form(id)
{
	var error = '';
	var propert_dmg = '';
	var business_aff = '';
	var myForm = document.getElementById(id);
	
	for (i = 0; i < myForm.property_dmg.length; i++)
	{
		if (myForm.property_dmg[i].checked == true)
		{
			propert_dmg = myForm.property_dmg[i].value;
			break;
		}
	}
	for (i = 0; i < myForm.affected_by_oil.length; i++)
	{
		if (myForm.affected_by_oil[i].checked == true)
		{
			business_aff = myForm.affected_by_oil[i].value;
			break;
		}
	}
	
	
	
	
	if (myForm.name.value == myForm.name.title || myForm.name.value == '') error += " - Name\n"; 
	if (myForm.phone.value == myForm.phone.title || myForm.phone.value == '') error += " - Phone\n";
	if (emailCheck(myForm.email.value) == false) error += " - Email\n";
	if (myForm.address.value == myForm.address.title || myForm.address.value == '') error += " - Address\n";
	if (myForm.city.value == myForm.city.title || myForm.city.value == '') error += " - City\n";
	if (myForm.phone.value == myForm.phone.title || myForm.phone.value == '') error += " - Phone\n";
	if (myForm.state.value == myForm.state.title || myForm.state.value == '') error += " - State\n";
	if (myForm.zipcode.value == myForm.zipcode.title || myForm.zipcode.value == '') error += " - Zipcode\n";
	if (myForm.comments.value == myForm.comments.title || myForm.phone.value == '') error += " - Comments\n";
	if (error != '')
	{
		alert("Please fill in the required fields:\n"+error);
	}
	else
	{
		$.post('/includes/send_email.php', {
		name:			myForm.name.value,
		phone:			myForm.phone.value,
		email:			myForm.email.value,
		address:		myForm.address.value,
		suite:			myForm.suite.value,
		city:			myForm.city.value,
		state:			myForm.state.value,
		zipcode:		myForm.zipcode.value,
		business_aff:	business_aff,
		propert_dmg:	propert_dmg,
		comments:		myForm.comments.value,
		captcha_code:	myForm.captcha_code.value,
		method_type: 	'contact'
		}, function(data){
			if (data != '') 
			{
				if (data.result == 'true')
				{
					document.getElementById('replace_text').innerHTML = '<div class="thankyou">Your contact has been submitted<br />Thank you.</div>';
				}
				else
				{
					alert("Captcha is incorrect.  Please re-enter  the captcha code below.");
					document.getElementById('captcha_image').src = '/captcha/securimage_show.php?sid=' + Math.random();
				}
			}
		},'json');
	}
}

