function on_blur_text(obj, v) {
	if (obj.value == '') obj.value = v;
}

function on_focus_text(obj, v) {
	if (obj.value == v) obj.value = '';
}

function check_country() {
	if ( document.membership_submit_form.country.value != '' && document.membership_submit_form.country.value != 'United States' )
		alert ( '- Do not fill out this form if your company is outside US territory' );
}

function IsEmpty(aTextField) {
	if ( (aTextField.value.length==0 ) || (aTextField.value==null) ) 
		return true;
	else
		return false;
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function check_membership() {
	var msg="";
	
	if ( IsEmpty(document.membership_submit_form.company) )
		msg += "-Please fill in your company name.\n";
	if ( IsEmpty(document.membership_submit_form.first_name) )
		msg += "-Please fill in your first name.\n";
	if ( IsEmpty(document.membership_submit_form.last_name) )
		msg += "-Please fill in your last name\n";
		
	if ( document.membership_submit_form.country.value=='' )	
		msg += "-Please select your current country\n";
	else
		if ( document.membership_submit_form.country.value != 'United States' )
			msg += "- This website is managed by ICE Los Angeles. Our territory of competence is USA: if your company is based outside the USA, please refer to the ICE office assigned to your territory.";
		
	if ( IsEmpty(document.membership_submit_form.email) )
		msg += "-Please fill in your email address.\n";
	else {
		if ( !isValidEmailAddress(document.membership_submit_form.email.value) )
			msg += "-Please fill in a valid email address.\n";
	}
	if ( IsEmpty(document.membership_submit_form.web_url) )
		msg += "-Please fill in your website URL.\n";
	
	if ( msg.length > 1 ) {
		alert ( msg );
		return false;
	}
	return true;	
}
