// CALCULATE MEMBERSHIP TYPE TOTALS
function calcTotal(formJoin) {
	var total_val = 0;
	var collectorItem1 = 0;
	var collectorItem3 = 0;
	var resale_merchant_total = 0;
	var resale_merchant_mul_total = 0;
	var pac_total = 0;
	var quantity;
	
	// INDIVIDUAL COLLECTOR TOTALS
	if (document.formJoin.individual_collector.checked == true) {
		document.formJoin.individual_collector_total.value = 35;
		collectorItem1 = parseInt(formJoin.individual_collector.value);
	} else {
		collectorItem1 = 0;
		document.formJoin.individual_collector_total.value = 0;
	}
	
	// RESALE MERCHANT TOTALS
	if (document.formJoin.resale_merchant.checked) {
		// CHECK NUMBER OF LOCATIONS
		quantity = parseInt(document.formJoin.resale_num_locations.value);
	
		// IS NOT A NUMBER
		if(isNaN(quantity)) {
			document.formJoin.resale_num_locations_total.value = 0;
		// IS A NUMBER
		} else {
			resale_merchant_total = 95 * parseInt(quantity);
			document.formJoin.resale_num_locations_total.value = resale_merchant_total;			
		}
	
		quantity = parseInt(document.formJoin.resale_mul_locations.value);
		// IS NOT A NUMBER
		if(isNaN(quantity)) {
			document.formJoin.resale_mul_locations_total.value = 0;
		// IS A NUMBER
		} else {
			resale_merchant_mul_total = 76 * parseInt(quantity);
			document.formJoin.resale_mul_locations_total.value = resale_merchant_mul_total;			
		}
	} else {
		document.formJoin.resale_num_locations_total.value = 0;
		document.formJoin.resale_mul_locations_total.value = 0;
	}
	
	// MAJOR MERCHANT TOTALS
	if(document.formJoin.major_merchant.checked == true) {
		document.formJoin.major_total.value = 195;
		collectorItem3 = parseInt(formJoin.major_merchant.value);
	} else {
		collectorItem3 = 0;
		document.formJoin.major_total.value = 0;
	}
	
	// PAC TOTALS
	if(document.formJoin.pac_donation.checked) {
		pac_total = parseFloat(document.formJoin.pac_donation_value.value);
		// IS NOT A NUMBER
		if( isNaN(pac_total)) {	
			pac_total = 0;
		}
	} else {
		pac_total = 0;
	}
	
	total_val = collectorItem1 + collectorItem3 + resale_merchant_total + resale_merchant_mul_total + pac_total;
	document.formJoin.total.value = total_val;
	return;
}


// VALIDATE FORM
function validateForm(formJoin) {
	// VALIDATE FULL NAME
	if (document.formJoin.firstname.value == "" || document.formJoin.lastname.value == "") {
		if (document.formJoin.firstname.value == "") {
			document.formJoin.firstname.focus(); 
		} else {
			document.formJoin.lastname.focus();
		}
		alert("Your first and last name is required.");
		return false;
	}

	// VALIDATE STREET ADDRESS
	if (document.formJoin.streetAddress.value == "" || document.formJoin.stAddress_city.value == "" || document.formJoin.stAddress_state.value == "" || document.formJoin.stAddress_zipcode.value == "") { 
		if (document.formJoin.streetAddress.value == "") {
			document.formJoin.streetAddress.focus();
		} else if (document.formJoin.stAddress_city.value == "") {
			document.formJoin.stAddress_city.focus();
		} else if (document.formJoin.stAddress_state.value == "") {
			document.formJoin.stAddress_state.focus();
		} else if (document.formJoin.stAddress_zipcode.value == "") {
			document.formJoin.stAddress_zipcode.focus();
		}
		alert("Your full Street Address information is required.");
		return false; 
	}

	// VALIDATE MEMBERSHIP CATEGORY NOT CHECKED
	if (!document.formJoin.individual_collector.checked && !document.formJoin.resale_merchant.checked && !document.formJoin.major_merchant.checked && !document.formJoin.benefactor.checked) {
		alert("You must select a membership category.");
		return false; 
	}

	// VALIDATE CC INFO
	if (document.formJoin.ccNum.value == "" || document.formJoin.ccCode.value == "" ) {
		if (document.formJoin.ccNum.value == "") {
			document.formJoin.ccNum.focus();
		} else {
			document.formJoin.ccCode.focus();
		}
		alert("Please complete your credit card information.");
		return false; 
	}

	// VALIDATE ACKNOWLEDGEMENT
	if (!document.formJoin.ack.checked) { 
		alert("Please check mark Acknowledgement agreement."); 
		return false; 
	}

}


// STANDARD POPUP WINDOW
function showinfo(filename,width,height) {
	openCenteredWindow(filename, width, height, 'viewer','');
}


// CENTER POPUP WINDOW
function openCenteredWindow(url, width, height, name, params) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( ((screen.height-35) - height) / 2);
   if (top < 0) top = 0
	   var winparams = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (params) { winparams += "," + params; }
	   var win = window.open(url, name, winparams);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	   return win;
}
