
var listing_price = pc['DANZ_Directory_listing'];

function format_money(val){

	var money_value = "$" + val;
	var point = money_value.indexOf(".");
	var strlen = money_value.length;

	if (point == -1){
		money_value = money_value + ".00";
	} else {
		if (strlen - point > 3){
			trunc = point + 3;
			money_value = money_value.substring(0, trunc);
		}
		if (money_value.length - point == 2)
			money_value = money_value + "0";
	}
	return(money_value);
}

function add_money(val1, val2){
	re = /^\$|,/g;
	val1 = val1.replace(re, "");
	val2 = val2.replace(re, "");	
	return(format_money(parseFloat(val1) + parseFloat(val2)));

}
function subtract_money(val1, val2){
	re = /^\$|,/g;
	val1 = val1.replace(re, "");
	val2 = val2.replace(re, "");	
	return(format_money(parseFloat(val1) - parseFloat(val2)));

}


function toggle_lp(tf, lc){

var td  = document.getElementById('ListingPrice');
if (lc) { 
	pc['DANZ_Directory_listing'] = listing_price;
	td.innerHTML = '$' + listing_price;
} else {
	pc['DANZ_Directory_listing'] = 0;
	td.innerHTML = 'free';

}
return(true);
}


function total_fields(){
	re = /^\$|,/g;

	tv = "0.00";
	var field = "";

	var cat = document.JoinDanzForm['Category'];
	var member_type = '';
	for (c =0; c < cat.length; c++){
		if (cat[c].checked) member_type = cat[c].value;
	
	}
	if (member_type){
		var ma = mt[member_type];
		tv = add_money(tv, format_money(ma));
	}
	

	for(key in pc){
	
		if (document.JoinDanzForm[key].checked){
			v = pc[key];
			if (parseFloat(v)){
				tv = add_money(tv, format_money(v));
			}		
		}
	}
	
	var don = document.JoinDanzForm['Donation_Amount'].value;
	
   	if (parseFloat(don) > 0){
 		tv = add_money(tv, format_money(don));
   	}


	document.JoinDanzForm['Total_Amount'].value = tv;
	document.JoinDanzForm['Total_Amount_Display'].value = tv;



/*
	document.JoinDanzForm['Subtotal_for_costs'].value = tv;

	v = document.JoinDanzForm['Discount_amount'].value;
	v = v.replace(re, "");

	if (parseFloat(v)){
		tv = subtract_money(tv, v);
	}
	v = document.JoinDanzForm['Plus_Member_fee'].value;
	v = v.replace(re, "");
	if (parseFloat(v)){
		tv = add_money(tv, v);
	}
	document.JoinDanzForm['Total_Amount'].value = tv;
	document.JoinDanzForm['Display_Total_Amount'].value = tv;

	document.JoinDanzForm['Grand_Total_Amount'].value = tv;
	document.JoinDanzForm['Transaction_Fee'].value = "";
	var ntv = tv.replace(re, "");
	
	if (parseFloat(ntv) > 0){

		var lonline_fee = format_money(online_fee);
		var gtv = add_money(tv,lonline_fee);

		document.JoinDanzForm['Transaction_Fee'].value = lonline_fee;
		document.JoinDanzForm['Grand_Total_Amount'].value = gtv;
	}
*/

}

function add_gst(value){
	re = /^\$|,/g;
	value = value.replace(re, "");

	var gstvalue = parseFloat(value) * 1.15;
	gstvalue = Math.ceil(gstvalue * 100) / 100;
	return(gstvalue);
}
function remove_gst(value){
	re = /^\$|,/g;
	value = value.replace(re, "");
	gstvalue = parseFloat(value) * 3 / 23;
	gstvalue = Math.floor(gstvalue * 100) / 100;
	return(gstvalue);
}

function gst_component(value){
	ev = remove_gst(value);
	re = /^\$|,/g;
	value = value.replace(re, "");
	value = parseFloat(value);
	sv = value;
	var gstcomp = (sv - ev) * 100;
	gst = Math.ceil(gstcomp) / 100;
	return(gst);
	
}


