// common function used to check input field against default value and clean the field
function clean_login(field, value)
{
	if (field.value==value)
	{
		field.value="";
	}
	return true;
} // clean_login(field, value)

// main login form validation
function validate_login()
{
	if (document.login.bcode.value=="Beat Code" || document.login.bcode.value=="")
	{
		alert("Please enter your Beat Code!");
		document.login.bcode.value="";
		document.login.bcode.focus();
		return false;
	}
	if (document.login.email.value=="Email" || document.login.email.value=="")
	{
		alert("Please enter your email address!");
		document.login.email.value="";
		document.login.email.focus();
		return false;
	}
	if (document.login.password.value=="Password" || document.login.password.value=="")
	{
		alert("Please enter your password!");
		document.login.password.value="";
		document.login.password.focus();
		return false;
	}
	return true;
} // validate_login()

function validate_registration_customer_1()
{
	if (document.register.bbcode.value=="Beat Code" || document.register.bbcode.value=="")
	{
		alert("Please enter your Beat Code!");
		document.register.bbcode.value="";
		document.register.bbcode.focus();
		return false;
	}
	return true;
} // validate_registration_customer_1()

function validate_registration_customer_2()
{
	if (document.register.eemail.value=="Email" || document.register.eemail.value=="")
	{
		alert("Please enter your email address!");
		document.register.eemail.value="";
		document.register.eemail.focus();
		return false;
	}
	if (document.register.name1.value=="First Name" || document.register.name1.value=="")
	{
		alert("Please enter your first name!");
		document.register.name1.value="";
		document.register.name1.focus();
		return false;
	}
	if (document.register.name2.value=="Last Name" || document.register.name2.value=="")
	{
		alert("Please enter your last name!");
		document.register.name2.value="";
		document.register.name2.focus();
		return false;
	}
	if (document.register.postcode.value=="Post Code" || document.register.postcode.value=="")
	{
		alert("Please enter your post code!");
		document.register.postcode.value="";
		document.register.postcode.focus();
		return false;
	}
	if(document.register.tac.checked!=true)
	{
		alert("You must agree to terms and conditions to be able to use BeatBobby!");
		document.register.tac.focus();
		return false;
	}
	return true;
} // validate_registration_customer_2()

function validate_registration_business_1()
{
	if (document.register.bbcode.value=="Beat Code" || document.register.bbcode.value=="")
	{
		alert("Please enter your Beat Code!");
		document.register.bbcode.value="";
		document.register.bbcode.focus();
		return false;
	}
	return true;
} // validate_registration_business_1()

function validate_registration_business_2()
{
	if (document.register.eemail.value=="Email" || document.register.eemail.value=="")
	{
		alert("Please enter your email address!");
		document.register.eemail.value="";
		document.register.eemail.focus();
		return false;
	}
	if (document.register.company.value=="Company Name" || document.register.company.value=="")
	{
		alert("Please enter the company name!");
		document.register.company.value="";
		document.register.company.focus();
		return false;
	}
	if(document.register.tac.checked!=true)
	{
		alert("You must agree to terms and conditions to be able to use BeatBobby!");
		document.register.tac.focus();
		return false;
	}
	return true;
} // validate_registration_business_2()

function validate_registration_business_3()
{
	if (document.profile.btype.value=='' && (document.profile.new_type_id.value=='' || document.profile.new_type_id.value=='optional'))
	{
		alert('Please select business type or type the kind of your business in the box!');
		document.profile.new_type_id.value='';
		document.profile.btype.focus();
		return false;
	}
	if (document.profile.company.value=='' || document.profile.company.value=='Company Name')
	{
		alert('Please enter company name!');
		document.profile.company.value='';
		document.profile.company.focus();
		return false;
	}
	if (document.profile.admin_first_name.value=='' || document.profile.admin_first_name.value=='First Name')
	{
		alert("Please enter first name!");
		document.profile.admin_first_name.value='';
		document.profile.admin_first_name.focus();
		return false;
	}
	if (document.profile.admin_last_name.value=='' || document.profile.admin_last_name.value=='Last Name')
	{
		alert("Please enter last name!");
		document.profile.admin_last_name.value='';
		document.profile.admin_last_name.focus();
		return false;
	}
	if (document.profile.address_1.value=='optional')
	{
		document.profile.address_1.value='';
	}
	if (document.profile.address_2.value=='optional')
	{
		document.profile.address_2.value='';
	}
	if (document.profile.town.value=='optional')
	{
		document.profile.town.value='';
	}
	if (document.profile.postcode.value=='' || document.profile.postcode.value=='Postcode')
	{
		alert('Please enter postal code!');
		document.profile.postcode.value='';
		document.profile.postcode.focus();
		return false;
	}
	if (document.profile.phone_code.value=='' || document.profile.phone_code.value=='Area Code')
	{
		alert('Please enter phone area code!');
		document.profile.phone_code.value='';
		document.profile.phone_code.focus();
		return false;
	}
	if (document.profile.phone_number.value=='' || document.profile.phone_number.value=='Phone Number')
	{
		alert('Please enter business phone number!');
		document.profile.phone_number.value='';
		document.profile.phone_number.focus();
		return false;
	}
	if (document.profile.fax_number.value=='optional')
	{
		document.profile.fax_number.value='';
	}
	if (document.profile.mobile_phone.value=='optional')
	{
		document.profile.mobile_phone.value='';
	}
	if (document.profile.eemail.value=='' || document.profile.eemail.value=='Email')
	{
		alert("Please enter business email!");
		document.profile.eemail.value='';
		document.profile.eemail.focus();
		return false;
	}
	else if ( (document.profile.eemail.value.indexOf("@")== -1) || (document.profile.eemail.value.indexOf(".")== -1) || (document.profile.eemail.value.indexOf(",")!= -1) || (document.profile.eemail.value.indexOf(":")!= -1) || (document.profile.eemail.value.indexOf(";")!= -1))
	{
		alert ("Please enter valid email address!")
		document.profile.eemail.focus();
		return false;
	}
	if (document.profile.website.value=='optional')
	{
		document.profile.website.value='';
	}
	return true;
} // validate_registration_business_3
		
function delete_business()
{
	if ( confirm("This will cancel your registration and delete all information stored!\nAre you sure?") )
	{
		document.profile.mode.value='delete';
		document.profile.submit();
	}
	else return false;
} // delete_business()

function validate_bb_1()
{
	if (document.bb_register.pin.value=="Registration Code" || document.bb_register.pin.value=="")
	{
		alert("Please enter your registration code!");
		document.bb_register.pin.value="";
		document.bb_register.pin.focus();
		return false;
	}
	return true;
} // validate_bb_1()

function validate_bb_2()
{
	if (document.bb_register.company.value=='' || document.bb_register.company.value=='Community Name')
	{
		alert('Please enter community name!');
		document.bb_register.company.value='';
		document.bb_register.company.focus();
		return false;
	}
	if (document.bb_register.admin_first_name.value=='' || document.bb_register.admin_first_name.value=='First Name')
	{
		alert("Please enter first name!");
		document.bb_register.admin_first_name.value='';
		document.bb_register.admin_first_name.focus();
		return false;
	}
	if (document.bb_register.admin_last_name.value=='' || document.bb_register.admin_last_name.value=='Last Name')
	{
		alert("Please enter last name!");
		document.bb_register.admin_last_name.value='';
		document.bb_register.admin_last_name.focus();
		return false;
	}
	if (document.bb_register.eemail.value=='' || document.bb_register.eemail.value=='Email')
	{
		alert("Please enter your email address!");
		document.bb_register.eemail.value='';
		document.bb_register.eemail.focus();
		return false;
	}
	else if ( (document.bb_register.eemail.value.indexOf("@")== -1) || (document.bb_register.eemail.value.indexOf(".")== -1) || (document.bb_register.eemail.value.indexOf(",")!= -1) || (document.bb_register.eemail.value.indexOf(":")!= -1) || (document.bb_register.eemail.value.indexOf(";")!= -1))
	{
		alert ("Please enter valid email address!")
		document.bb_register.eemail.focus();
		return false;
	}
	if (document.bb_register.mobile_phone.value=='optional')
	{
		document.bb_register.mobile_phone.value='';
	}
	if (document.bb_register.police_number.value=='' || document.bb_register.police_number.value=='Police Number')
	{
		alert("Please enter your police number!");
		document.bb_register.police_number.value='';
		document.bb_register.police_number.focus();
		return false;
	}
} // validate_bb_2()

function validate_password_reminder()
{
	if (document.password_reminder.yemail.value=="Your Email" || document.password_reminder.yemail.value=="")
	{
		alert("Please enter your email address!");
		document.password_reminder.yemail.value="";
		document.password_reminder.yemail.focus();
		return false;
	}
	return true;
} // validate_password_reminder()

function validate_tell_a_friend()
{
	if (document.tell_a_friend.yname.value=="Your Name" || document.tell_a_friend.yname.value=="")
	{
		alert("Please enter your name!");
		document.tell_a_friend.yname.value="";
		document.tell_a_friend.yname.focus();
		return false;
	}
	if (document.tell_a_friend.yemail.value=="Your Email" || document.tell_a_friend.yemail.value=="")
	{
		alert("Please enter your email address!");
		document.tell_a_friend.yemail.value="";
		document.tell_a_friend.yemail.focus();
		return false;
	}
	if (document.tell_a_friend.fname.value=="Friends Name" || document.tell_a_friend.fname.value=="")
	{
		alert("Please enter friends name!");
		document.tell_a_friend.fname.value="";
		document.tell_a_friend.fname.focus();
		return false;
	}
	if (document.tell_a_friend.femail.value=="Friends Email" || document.tell_a_friend.femail.value=="")
	{
		alert("Please enter friends email address!");
		document.tell_a_friend.femail.value="";
		document.tell_a_friend.femail.focus();
		return false;
	}
//	document.tell_a_friend.action = "mailto:" + document.tell_a_friend.femail.value + "?subject=Great%20website&body=Hi%20" + document.tell_a_friend.fname.value + ",%0D%0AThere%20is%20a%20great%20site%20that%20helps%20us%20to%20help%20our%20Beat%20Bobby%20make%20where%20we%20live%20a%20safer%20place.%0D%0ATake%20a%20look%20at%20www.beatbobby.co.uk%0D%0ARegards%0D%0A" + document.tell_a_friend.yname.value + "";
//	alert(document.tell_a_friend.action);
//	document.tell_a_friend.target="_blank";
//	document.tell_a_friend.submit();
//	return false;
	return true;
} // validate_tell_a_friend()

