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 ( document.getElementById('interest_bus').checked ) {
		if ( IsEmpty(document.membership_submit_form.company) )
			msg += "-Please fill in your company 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 += "- Do not fill out this form if your company is outside US territory";
		
		if ( IsEmpty(document.membership_submit_form.address) )
			msg += "-Please fill out the address\n";
		if ( IsEmpty(document.membership_submit_form.city) )
			msg += "-Please fill out the city\n";
		if ( document.membership_submit_form.state.value=='' )	
			msg += "-Please select the state\n";
		if ( IsEmpty(document.membership_submit_form.zip) )
			msg += "-Please fill out the zip code\n";
			
		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";
		}
	} else { //ind
		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 += "- Do not fill out this form if your company is outside US 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 ( msg.length > 1 ) {
		alert ( msg );
		return false;
	}
	return true;	
}
