function checkSecure () {
	if (document.location.protocol != "https:") {
		var x = document.location.href.split (":");
		if (!x[1].match(/^\/\/www/i)) x[1] = x[1].replace(/^\/\/(.*)/, "//www.$1");
		document.location.href = "https:" + x[1];
	}
}
function checkCampaign (id) {
	var params = document.location.href.toQueryParams();
	if (params['campaign']) {
		new Ajax.Updater (id, '/ajax/jointrupro_campaign.asp', {parameters:{'campaign':params['campaign']}});
	}
}
function loadForm (id, path) {
	var args = document.location.href.toQueryParams();
	new Ajax.Updater (id, path, {method:'GET', parameters:args, evalScripts:true});
}
function submitForm (id, f) {
	var args = Form.serialize(f);
	new Ajax.Updater (id, f.action, {method:f.method, parameters:args, evalScripts:true});
}
function setBilling (obj) {
	if (obj.checked == true) {
		$('BillName').value = $('FirstName').value + ' ' + $('LastName').value;
		$('BillAddress').value = $('Address').value;
		$('BillCity').value = $('City').value;
		$('BillState').value = $('State').value;
		$('BillZIP').value = $('ZIP').value;
	}
}
	function calc_update() {
		var personal_income = parseInt(getInt('PersonalCommission') * getInt('PersonalSales') * 0.8);
		var avg_comm = getInt('ProfitCommission') * getInt('ProfitSales');
		var ag1 = getInt('Agents1'), ag2 = getInt('Agents2'), ag3 = getInt('Agents3');
		var subtotal1 = parseInt(avg_comm * ag1 * 0.04);
		var subtotal2 = parseInt(avg_comm * ag1 * ag2 * 0.04);
		var subtotal3 = parseInt(avg_comm * ag1 * ag2 * ag3 * 0.04);
		$('PersonalIncome').value = addCommas(personal_income);
		$("Subtotal1").value = addCommas(subtotal1);
		$("Subtotal2").value = addCommas(subtotal2);
		$("Subtotal3").value = addCommas(subtotal3);
		$("TotalAgents").value = addCommas(ag1 + (ag1 * ag2) + (ag1 * ag2 * ag3));
		$("ProfitIncome").value = addCommas(subtotal1 + subtotal2 + subtotal3);
		$("TotalIncome").value = addCommas(subtotal1 + subtotal2 + subtotal3 + personal_income);
	}
	function calc_clear() {
		$('PersonalCommission').value = '';
		$('PersonalSales').value = '';
		$('ProfitCommission').value = '';
		$('ProfitSales').value = '';
		$('Agents1').value = '';
		$('Agents2').value = '';
		$('Agents3').value = '';
		calc_update();
	}
	function getInt (obj) {
		return (i = parseInt($(obj).value.replace(/[^\d\.]/g, '')))? i: 0;
	}
	function valInt (obj) {
		obj.value = addCommas(getInt(obj));
	} 
	function valFloat (obj) {
		var v = parseFloat(obj.value.replace(/[^\d\.]/g, ''));
		obj.value = addCommas(v);
		return v;
	} 
	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;
	}
	function val_number (ev,obj) {
		var e = ev || window.event;
		var k = e.keyCode;
		e.returnValue = false;
		if (k == 13 || k == 44 || k == 46 || (k >= 48 && k < 58)) {
			e.returnValue = true;
		}
		return e.returnValue;
	}
