var top_box = new Array('top_stories', 'videos', 'blogs');
var top_stories = new Array('story_1', 'story_2', 'story_3');
var videos = new Array('video_1', 'video_2', 'video_3');
var blogs = new Array('blog_1', 'blog_2', 'blog_3');
var community = new Array('trip_photos', 'gear_reviews', 'forums');
var featured_trips = new Array('backpacker_trips', 'community_trips', 'post_trip');
var destination_trips = new Array('featured_hikes', 'reader_trips','post_trip');
var extra = new Array('most_viewed', 'most_emailed', 'related');
var featured_reviews = new Array('gear_review', 'reader_reviews', 'post_a_review');
var profile_saved = new Array('trip_reports', 'gear_review', 'bookmarks', 'ratings', 'forum_posts');
var tg = new Array('tgstories', 'tgvideos', 'tgblogs');
var tgs = new Array('tgs1', 'tgs2', 'tgs3');
var tgv = new Array('tgv1', 'tgv2', 'tgv3');
var tgb = new Array('tgb1', 'tgb2', 'tgb3');
var ts = new Array('tsstories', 'tsvideos', 'tsblogs');
var tss = new Array('tss1', 'tss2', 'tss3');
var tsv = new Array('tsv1', 'tsv2', 'tsv3');
var tsb = new Array('tsb1', 'tsb2', 'tsb3');
var boletin = new Array('todo', 'editorial', 'tuvoz', 'cortos', 'calendario', 'bitacora', 'desafio', 'deportes');
var desafio = new Array('todo', 'desafio1', 'desafio2', 'desafio3', 'desafio4', 'desafio5');
var inicio = new Array('bienvenida', 'unete', 'curriculum', 'perfil', 'patrocinadores');
var featured_nature = new Array('fsall', 'fswildlife', 'fsweather', 'fsthreats', 'fsplants', 'fsenvironment');
var forum_categories = new Array(
	'trailheadregister', 'storytelling', 'political_arena', 'photo_gallery', 'how_to', 'backcountry_cooking', 
	'hiking_partner', 'gear', 'books_reports', 'health_fitness', 'backpacking_kids', 'ultralight_forum',
	'mountaineering', 'women', 'international', 'midatlantic', 'midwest', 'southwest', 'southern', 
	'rockymountains', 'pacificnorthwest', 'northeast'
);
//var videos_archive = new Array('va_destinations', 'va_gear', 'va_skills', 'va_nature', 'va_features', 'va_adventures');
var videos_archive = new Array('va_all', 'va_destinations', 'va_gear', 'va_skills', 'va_nature');
var community_regions = new Array('midatlantic', 'midwest', 'mountainswest', 'northwest', 'south', 'southeast', 'southwest', 'international', 'forumshome');
var community_gear = new Array('backpacks', 'sleeping_bags', 'bivy_sacks', 'tents', 'boots', 'forums_home');

var keep_rotating = 1;

function click_tab(list, show, opt, stop_rotating) {
	if (stop_rotating) {
		keep_rotating = 0;
	}
	for (var i=0; i<list.length; i++) {
		if (show == list[i]) {
			document.getElementById('tab_'+list[i]).className += ' current';
			document.getElementById('panel_'+list[i]).style.display = 'block';
		} else {
			document.getElementById('tab_'+list[i]).className = document.getElementById('tab_'+list[i]).className.replace(/\s*current/ig, '');
			document.getElementById('panel_'+list[i]).style.display = 'none';
		}
	}
	if (opt != null) {
		for (var i=0; i<list.length; i++) {
			if (show == list[i]) {
				document.getElementById(opt+list[i]).style.display = 'block';
			} else {
				document.getElementById(opt+list[i]).style.display = 'none';
			}
		}
	}
}

function subscription_form(type) {
	var sf = document.getElementById('subscription_form');
	var ct = document.getElementById('cds_country');
	
	if (type == 'us') {
		sf.action = 'https://admin.buysub.com/servlet/PrePopGateway';
		ct.value = 'United States';
	} else {
		sf.action = 'https://w1.buysub.com/pubs/X8/BPK/18412_clone.jsp';
		if (type == 'canada') {
			ct.value = 'Canada';
		} else {
			ct.value = '';
		}
	}
	
	sf.submit();
}

function quicklink(obj) {
	if (obj.options[obj.selectedIndex].value != '') {
		window.location.href = obj.options[obj.selectedIndex].value;
	}
}

function get_cookie(check_name) {
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for (var i=0; i<a_all_cookies.length; i++) {
		a_temp_cookie = a_all_cookies[i].split('=');
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		if (cookie_name == check_name) {
			b_cookie_found = true;
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}

function is_logged() {
	if ((session == null) || (session == '')) { return 0; }
	if ((user_id == null) || (user_id == '') || (user_id == 0)) { return 0; }
	return 1;
}

var session = get_cookie('sessionid');
var user_id = get_cookie('user_id');
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;

var rotate = new Array(
	new Array(top_stories, 'story_1'),
	new Array(top_box, 'top_stories'),
	new Array(top_stories, 'story_2'),
	new Array(top_stories, 'story_3'),
	new Array(videos, 'video_1'),
	new Array(top_box, 'videos'),
	new Array(videos, 'video_2'),
	new Array(videos, 'video_3'),
	new Array(blogs, 'blog_1'),
	new Array(top_box, 'blogs'),
	new Array(blogs, 'blog_2'),
	new Array(blogs, 'blog_3')
);
var rotate_index = 1;

function auto_rotate() {
	if (!keep_rotating) {
		return 0;
	}
	click_tab(rotate[rotate_index][0], rotate[rotate_index][1]);
	rotate_index++;
	if (rotate_index >= rotate.length) {
		rotate_index = 0;
	}
	if (rotate_index % 4 == 0) {
		auto_rotate();
	} else {
		setTimeout("auto_rotate()", 5000);
	}
}

function close_floater(id) {
	document.getElementById(id).style.display = 'none';
}

function create_cookie(name,value,days,date) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

//configuration
var print_first = 2;
var print_each = null;
var renew_days = 1;

//check the control cookies
var pages;
var exp = get_cookie('expire');
if ((exp == null) || (exp == '')) {
	create_cookie('expire', 'no', renew_days); 
} else {
	pages = parseInt(get_cookie('pages'));
}
if ((pages == null) || (isNaN(pages)) || (pages <= 1)) {
	pages = 1;
}

//logic
var floater = 0;
if (pages == print_first) {
	floater = 1;
} else if ((print_each != null) && ((pages - print_first) % print_each == 0)) {
	floater = 1;
}

//update control cookie
create_cookie('pages', pages+1, renew_days);


var formSubmitted = false;   // global variable to track successful submit
var ccLink = '<a href="https://www.neodata.com/ITPS2.cgi">'

function submitBM(f) {
	f.action="https://www.neodata.com/ITPS2.cgi";
	f.iResponse.value="BPKZ.NEW_CONFIRM";
	f.OrderType.value="New Order";
	now = new Date();
	if (f.id == 'subscription_form') {
		monthly_codes = new Array("8APA1","8BPA1","8CEA1","8DEA1","8EEA1","8FEA1","8GEA1","8HEA1","8JEA1","8KEA1","8LEA1","8MEA1");
		f.KeyCode.value=monthly_codes[now.getMonth()];
//		f.KeyCode.value='EA1';
	} else {
		monthly_codes = new Array("8APA1","8BPA1","8CPA1","8DPA1","8EPA1","8FPA1","8GPA1","8HPA1","8JPA1","8KPA1","8LPA1","8MPA1");
		f.KeyCode.value=monthly_codes[now.getMonth()];
//		f.KeyCode.value='PA1';
	}
	f.submit();
}

function submitCC(f) {
	f.action="https://www.neodata.com/ITPS2.cgi";
	f.iResponse.value="BPKZ.NEW_SUB";
	f.OrderType.value="Reply Only";
//	now = new Date();
	if (f.id == 'subscription_form') {
//		monthly_codes = new Array("8APB1","8BPB1","8CEB1","8DEB1","8EEB1","8FEB1","8GEB1","8HEB1","8JEB1","8KEB1","8LEB1","8MEB1");
//		f.KeyCode.value=monthly_codes[now.getMonth()];
		f.KeyCode.value='EB1';
	} else {
//		monthly_codes = new Array("8APB1","8BPB1","8CPB1","8DPB1","8EPB1","8FPB1","8GPB1","8HPB1","8JPB1","8KPB1","8LPB1","8MPB1");
//		f.KeyCode.value=monthly_codes[now.getMonth()];
		f.KeyCode.value='PB1';
	}
	f.submit();
}