-+// Email Spam hiding.
function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}
function linkMail(host,user,cls) {
	document.write('<a href="javascript:popMail(\''+ host +'\',\''+ user +'\');"');
	if (cls) {
		document.write(' class="'+ cls +'"');
	}
	document.write('>');
	showMail(host,user);
	document.write('</a>');
}
function showMail(host,user) {
	var acct = user +'@'+ host;
	document.write(acct);
}

function start()
{
	pngFix();
	
	if($('banners') != null && banners != null)
	{
		loadBanners();
	}
}

function goToState()
{
	if($F('states') != 0)
	{
		var url = base_path + 'content/browse/state/' + $F('states') + '/type/' + $F('search_type');
		window.location = url;
	}
}

function loadBanners()
{
	var bannersHash = $H(banners);
	var content_height = $('body_content').getHeight();
	var banners_height = $('banners').getHeight();
	var count = banners.length;
	
	for(x = 0;x < count;x++)
	{
		var banner = banners[x];
		if(x == 0)
		{
			var banner_class = 'banner top';
			var div_height = banner['height'] + 20;
		} else {
			var banner_class = 'banner';
			var div_height = banner['height'] + 50;
		}
		var img = new Element('img', {	'src':		banner['img_src'],
										'width':	banner['width'],
										'height':	banner['height'],
										'alt':		banner['name'],
										'border':	0});
		var a = new Element('a', {	'href':		banner['url'],'target': '_blank'}).update(img);
		var div = new Element('div', { 'class':		banner_class}).update(a);
		
		if(div_height + $('banners').getHeight() < content_height)
		{
			$('banners').insert({bottom: div});
		} else {
			break;
		}
	}

}

var viewport = null;

function loadModal(url)
{
	var bodyTag = $$('body');
	var bodyElm = bodyTag[0];
	viewport = bodyElm.getDimensions();
	$('blackOut').setStyle({width: viewport.width + 'px',height: viewport.height + 'px'});
	
	var offset = bodyElm.cumulativeScrollOffset();
	var top = offset.top + 137;
	$('OuterContainer').setStyle({top: top + 'px'});
	
	$('blackOut').show();
	$('OuterContainer').show();
	new Ajax.Updater('InnerContainer', url);
}

function closeModal()
{
	$('blackOut').hide();
	$('OuterContainer').hide();
	$('InnerContainer').update('');
}

var t = setTimeout('',1);
var subNav_visible = null;

function activateNav(id)
{
	if(t != undefined)
	{
		clearTimeout(t);
	}
	if(subNav_visible != null)
	{
		hideNav(subNav_visible);
	}
	subNav_visible = id;
	if($('subNav_' + id) != null)
	{
		$('subNav_' + id).show();
	}
	if($('nav_' + id) != null)
	{
		$('nav_' + id).addClassName('over');
	}
}

function deActivateNav(id)
{
	t = setTimeout("hideNav('" + id + "')",500);
	navId = 'subNav_' + id;
	//$(navId).show();
	//navState = 1;
}

function hideNav(id)
{
	if($('subNav_' + id) != null)
	{
		$('subNav_' + id).hide();
	}
	if($('nav_' + id) != null)
	{
		$('nav_' + id).removeClassName('over');
	}
}

function reActivateNav()
{
	if(t != undefined)
	{
		clearTimeout(t);
	}
}

function blankField(elm,value)
{
	if($F(elm) == value)
	{
		$(elm).clear();
	}
	if(value == 'Password')
	{
		document.getElementById('password').type = 'password';
		//elm.type = 'password';
	}
}

function switchPassword()
{
	if($('login_password2').visible())
	{
		if($('password').value == '')
		{
			$('login_password2').hide();
			$('login_password1').show();
		}
	} else {
		$('login_password1').hide();
		$('login_password2').show();
		$('password').focus();
	}
}

function fillField(elm,value)
{
	if(!$(elm).present())
	{
		elm.type = 'text';
		$(elm).value = value;
	}
}

var currentMainImage = 1;
var main_image_fade_duration = 1.5;

function swapMainImage(id,continue_rotation)
{
	if(continue_rotation != true)
	{
		clearTimeout(pt);
	}
	if(id != currentMainImage)
	{
		Effect.Appear('main_body_image_home_' + id, { duration: main_image_fade_duration });
		Effect.Fade('main_body_image_home_' + currentMainImage, { duration: main_image_fade_duration });
		$('main_body_image_home_link_' + currentMainImage).removeClassName('on');
		$('main_body_image_home_link_' + id).addClassName('on');
		currentMainImage = id;
	}
}

function downloadPDF()
{
	file = $F('chapters_select');
	if(file != 0)
	{
		window.location = file;
	}
}

function contact()
{
	loadModal('/contact/contact/');
}

function submitContactForm()
{
	$('submit').disable();
	$('submit').value = 'Please Wait';
	new Ajax.Updater('InnerContainer', '/contact/submit/', {
		  parameters: $('contact_form').serialize(true) 
		});

}

function loadMemberApplication()
{
	setForeign();
	setDues();
}

function setForeign()
{
	if(($F('country') != 'USA' && $F('country') != 0) ||
	   ($F('country_mailing') != 'USA' && $F('country_mailing') != 0) ||
	   ($F('country_billing') != 'USA' && $F('country_billing') != 0))
	{
		$('foreign').value = 20;
		$('foreign_div').innerHTML = '$20.00';
	} else {
		$('foreign').value = 0;
		$('foreign_div').innerHTML = '$0.00';
	}
	updateTotal();
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
	{
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

var biz_types = new Array();
biz_types['Manufacturer_Distributor'] = 'general';
biz_types['Travel_Agency'] = 'general';
biz_types['Retailer'] = 'general';
biz_types['Sales_Rep'] = 'individual';
biz_types['Outdoor_Ed_Rec_Center'] = 'general';
biz_types['Supplier'] = 'general';
biz_types['Media_Consumer'] = 'associate';
biz_types['Media_Trade'] = 'associate';
biz_types['Nonprofit'] = 'associate';
biz_types['PR_Marketing'] = 'associate';
biz_types['Guide'] = 'individual';
biz_types['Shop_Staff'] = 'individual';

var fee_structure = new Array();
fee_structure['<$250,000'] = new Array();
fee_structure['$250,000_$500,000'] = new Array();
fee_structure['$500,000_$750,000'] = new Array();
fee_structure['$750,000_$1M'] = new Array();
fee_structure['$1M_$2M'] = new Array();
fee_structure['$2M_$5M'] = new Array();
fee_structure['$5M_$10M'] = new Array();
fee_structure['$10M_$20M'] = new Array();
fee_structure['$20M_$30M'] = new Array();
fee_structure['$30M_$50M'] = new Array();
fee_structure['>$50M'] = new Array();

fee_structure['<$250,000']['general'] = 75;
fee_structure['<$250,000']['associate'] = 100;
fee_structure['<$250,000']['individual'] = 25;
fee_structure['$250,000_$500,000']['general'] = 100;
fee_structure['$250,000_$500,000']['associate'] = 100;
fee_structure['$250,000_$500,000']['individual'] = 25;
fee_structure['$500,000_$750,000']['general'] = 200;
fee_structure['$500,000_$750,000']['associate'] = 100;
fee_structure['$500,000_$750,000']['individual'] = 50;
fee_structure['$750,000_$1M']['general'] = 300;
fee_structure['$750,000_$1M']['associate'] = 100;
fee_structure['$750,000_$1M']['individual'] = 25;
fee_structure['$1M_$2M']['general'] = 400;
fee_structure['$1M_$2M']['associate'] = 100;
fee_structure['$1M_$2M']['individual'] = 25;
fee_structure['$2M_$5M']['general'] = 1000;
fee_structure['$2M_$5M']['associate'] = 100;
fee_structure['$2M_$5M']['individual'] = 25;
fee_structure['$5M_$10M']['general'] = 2000;
fee_structure['$5M_$10M']['associate'] = 100;
fee_structure['$5M_$10M']['individual'] = 25;
fee_structure['$10M_$20M']['general'] = 3000;
fee_structure['$10M_$20M']['associate'] = 100;
fee_structure['$10M_$20M']['individual'] = 25;
fee_structure['$20M_$30M']['general'] = 4000;
fee_structure['$20M_$30M']['associate'] = 100;
fee_structure['$20M_$30M']['individual'] = 25;
fee_structure['$30M_$50M']['general'] = 5000;
fee_structure['$30M_$50M']['associate'] = 100;
fee_structure['$30M_$50M']['individual'] = 25;
fee_structure['>$50M']['general'] = 6000;
fee_structure['>$50M']['associate'] = 100;
fee_structure['>$50M']['individual'] = 25;

var biz_type,biz_cat,sales,dues;
              
function setDues()
{
	if($F('biz_type') != 0 && $F('biz_type') != 1 && $F('sales') != 0)
	{
		biz_type = $F('biz_type').replace(/ - /g,"_");
		biz_type = biz_type.replace(/ /g,"_");
		biz_type = biz_type.replace(/\//g,"_");
		biz_cat = biz_types[biz_type];
		sales = $F('sales').replace(/ - /g,"_");
		sales = sales.replace(/ /g,"_");
		dues = fee_structure[sales][biz_cat];
//alert(biz_type + ' :: ' + biz_cat + ' :: ' + sales + ' :: ' + dues);
		$('dues').value = dues;
		$('dues_div').innerHTML = '$' + addCommas(dues) + '.00';
	} else {
		if($F('biz_type') == 0)
		{
			$('dues').value = 0;
			$('dues_div').innerHTML = '$0.00';
		} else if($F('biz_type') == 1) {
			$('biz_type').selectedIndex = 0;
			alert("Affiliate memberships cannot be completed online.\nPlease contact AFFTA at 303-604-6132 to register for an Affiliate membership.");
		}
	}
	updateTotal();
}

function updateTotal()
{
	var want_cd = 0;
	if($F('cd') == 'yes')
	{
		want_cd = 10;
	}
	var total = parseFloat($F('dues')) + parseFloat($F('dff_contrib')) + want_cd + (parseFloat($F('tactics')) * 70) + parseFloat($F('foreign'));
	//total = total.toPrecision(2);
	$('total').value = total;
	$('total_div').innerHTML = '$' + addCommas(total) + '.00';
}

function copyAddress(address)
{
	if(address == 'mailing')
	{
		//$('copy_companyMailing').checked = false;
		var append = '_' + address;
	} else if(address == 'company') {
		//$('copy_company').checked = false;
		var append = '';
	} else {
		$('address1_billing').value = '';
		$('city_billing').value = '';
		$('state_billing').value = 0;
		$('zip_billing').value = '';
		$('country_billing').value = 0;
	}
	
	$('address1_billing').value = $F('address1' + append);
	$('city_billing').value = $F('city' + append);
	$('state_billing').value = $F('state' + append);
	$('zip_billing').value = $F('zip' + append);
	$('country_billing').value = $F('country' + append);
}

var pt = setTimeout('',1);
var p_start = 1;

function startImageRotation()
{
	if(num_main_body_images < 2)
	{
		alert('none');
		return '';
	}
	
	pt = setTimeout('autoSwapMainImage();',5000);
	
}

function autoSwapMainImage()
{
	p_start++;
	if(p_start > num_main_body_images)
	{
		swapMainImage(1,true);
	} else {
		swapMainImage(p_start);
		pt = setTimeout('autoSwapMainImage();',5000 + (main_image_fade_duration * 1000));
	}
}

function subscribe()
{
	var url = 'ajax/subscribe/?newsletter=' + $F('newsletter_field');
	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function() {
			$('footer_newsletter').setStyle({width: $('footer_newsletter').getWidth() + 'px',
											 textAlign: 'center'});
			$('footer_newsletter').innerHTML = 'Thank You';
		},
		onFailure: function() {
			alert('Error. Please try again.');
		}
	});

	return false;
}
