function email_user_subscribe() {
	$("#email_widget_message").html("Processing Subscription...");
		var email_address = $('#email_address').val();
		var post_url = "/ajax/core/email_user_subscribe";
		$.post(post_url, {email: ""+email_address+""}, function(data){
			if(data.message.length > 0 ) {
				$('#email_widget_message').html(data.message);
			}
			if(data.success == "true") {
				$('#email_widget_form').hide("slow");
			}
		}, "json");
}

function email_member_subscribe() {
	$("#email_widget_message").html("Adding Your Subscription...");
		var post_url = "/ajax/core/email_member_subscribe";
		$.post(post_url, '', function(data){
			if(data.message.length > 0 ) {
				$('#email_widget_message').html(data.message);
			}
			if(data.success == "true") {
				$('#email_widget_form').hide("slow");
			}
		}, "json");
}

function email_member_unsubscribe() {
	$("#email_widget_message").html("Removing Your Subscription...");
		var post_url = "/ajax/core/email_member_unsubscribe";
		$.post(post_url, '', function(data){
			if(data.message.length > 0 ) {
				$('#email_widget_message').html(data.message);
			}
			if(data.success == "true") {
				$('#email_widget_form').hide("slow");
			}
		}, "json");
}


function write_country_select( sel_type, sel_country ) {
  	var sel = '<select class="short" name="' + sel_type + '[country]" id="country_select" onchange="update_locations_by_country(\'' + sel_type + '\')">';
	sel += '<option value="">Select a Country</option>';
	$.each( countries, function(i, country) {
		( sel_country == country.id ) ? is_sel = " selected" : is_sel = "";
		sel += '<option value="' + country.id + '"' + is_sel + '>' + country.name + '</option>';
	});
	sel += '</select>';
	document.write(sel);
}	
  
function write_region_select( sel_type, sel_region, sel_country ) {
	var c_region = 0;
	var f_region = 0;
  	var sel = '<select class="short" name="' + sel_type + '[region]" id="region_select" onchange="update_locations_by_region(\'' + sel_type + '\')">';
	sel += '<option value="">Select a State / Region</option>';
	$.each( regions, function(i, region) {
		is_sel = "";
		if (sel_region == region.id) {
			f_region = 1;
			is_sel = " selected";
		}
		if (sel_region > 0) {
			if (sel_country > 0) {
				if (sel_country == region.cid) {
					sel += '<option value="' + region.id + '"' + is_sel + '>' + region.name + '</option>';
					c_region++;
				}
			}
		}
	});
	sel += '</select>';
	document.write(sel);
	if ( f_region == 0 ) {
		$('#region_select').attr('disabled', true);
	}
	if (sel_country > 0) {
		if (c_region == 0) {
			$('#select_region').html('');
			$('#region_section').hide();
		}
	}	
}	

function build_region_select_by_country( sel_type, sel_country ) {
	var c_region = 0;
  	var sel = '<select class="short" name="' + sel_type + '[region]" id="region_select" onchange="update_locations_by_region(\'' + sel_type + '\')">';
	sel += '<option value="">Select a State / Region</option>';
	$.each( regions, function(i, region) {
		if (sel_country == region.cid) {
			sel += '<option value="' + region.id + '">' + region.name + '</option>';
			c_region++;
		}
	});
	sel += '</select>';
	if ( c_region > 0 ) {
		$('#select_region').html(sel);
		$('#region_select').removeAttr('disabled');
		$('#region_section').show();
		$('#city_select').attr('disabled', true);
	} else {
		$('#select_region').html('');
		$('#region_section').hide();
		$('#city_select').removeAttr('disabled');
	}
}

function update_locations_by_country( sel_type ) {
	sel_country = $("#country_select").val();
	if ( sel_country == "" ) {
		$('#region_select').attr('disabled', true);
		$('#city_select').attr('disabled', true);
	} else {
		build_region_select_by_country( sel_type, sel_country );
	}
	
}

function update_locations_by_region( sel_type ) {
	sel_region = $("#region_select").val();
	if ( sel_region == '') {
		$('#city_select').attr('disabled', true);
	} else {
		$('#city_select').removeAttr('disabled');
	}
}