﻿function pop_file(f, w, h, scroll) {
	var temp_url = f;
	if (scroll)
		var new_win = window.open(temp_url, 'pop' + h + w, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + w + ',height=' + h + ',alwaysRaised=yes');
	else
		var new_win = window.open(temp_url, 'pop' + h + w, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + w + ',height=' + h + ',alwaysRaised=yes');
	new_win.focus();
}

function check_search_form(opt) {
	form = document.search_form;
	if (form.SearchTerm.value == '') {
		alert('Please enter a term to search on and then click "SEARCH".');
		if (opt == 0) return false;
	} else {
		if (opt == 0) {
			return true;
		} else if (opt == 1) {
			form.submit();
		}
	}
}

function check_nl_form(opt) {
	form = document.nl_form;
	var el = '';
	if (form.ea.value == '') el += 'Enter a value for "Email" \n';
	if (el != '') {
		alert('Please address the following and then click "Click to Sign Up" again. \n \n' + el);
		if (opt == 0) return false;
	} else {
		if (opt == 0) {
			return true;
		} else if (opt == 1) {
			form.submit();
		}
	}
}

function new_member_search(num) {
	form = document.member_search_form;
	form.SearchResultsStart.value = num;
	form.submit();
}

function return_to_member_search() {
	form = document.member_search_form;
	form.SearchResultsStart.value = 0;
	form.submit();
}

function business_details(pid, bid) {
	form = document.member_search_form;
	form.action = '/default.aspx?ID=' + pid + '&BusinessID=' + bid;
	form.method = 'post';
	form.submit();
}

function return_to_search_results() {
	form = document.member_search_form;
	form.submit();
}

var ImageSwitch = 0;

function rollover(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_on.src;');
}

function rolloff(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_off.src;');
}

function preload_images() {
	top_tab_chamber_on = new Image;
	top_tab_chamber_off = new Image;
	top_tab_chamber_on.src = '/images/page/top_tabs/chamber_on.png';
	top_tab_chamber_off.src = '/images/page/top_tabs/chamber_off.png';
	top_tab_licensing_on = new Image;
	top_tab_licensing_off = new Image;
	top_tab_licensing_on.src = '/images/page/top_tabs/licensing_on.png';
	top_tab_licensing_off.src = '/images/page/top_tabs/licensing_off.png';
	top_tab_visitors_on = new Image;
	top_tab_visitors_off = new Image;
	top_tab_visitors_on.src = '/images/page/top_tabs/visitors_on.png';
	top_tab_visitors_off.src = '/images/page/top_tabs/visitors_off.png';
	locate_business_on = new Image;
	locate_business_off = new Image;
	locate_business_on.src = '/images/page/left_nav/locate_a_business_ro.gif';
	locate_business_off.src = '/images/page/left_nav/locate_a_business.gif';
	nl_signup_on = new Image;
	nl_signup_off = new Image;
	nl_signup_on.src = '/images/home/butt_signup_ro.gif';
	nl_signup_off.src = '/images/home/butt_signup.gif';
	ImageSwitch = 1;
}

function format_money(passed) {
	if (!isNaN(passed)) {
		p = new String(passed);
		if (p.indexOf('.') < 0) {
			p += '.00';
		} else {
			p = Math.round(p * 100) / 100;
			p = p.toString();
			if (p.indexOf('.') < 0) {
				p += '.00';
			} else {
				if (p.substr(p.indexOf('.') + 1).length == 0) p += '00';
				if (p.substr(p.indexOf('.') + 1).length == 1) p += '0';
			}
		}
		return('$' + p);
	} else {
		return(passed);
	}
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		EventCache.add(elm, evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

addEvent(window, 'load', preload_images, false);
addEvent(window, 'unload', EventCache.flush, false);