
function urlCheck(form,str,reqList) {
	//box = form['TERMS'];
	//if (box.type != 'fsdf') { alert('Box ' + box.type + ' = ' + ( ! box.checked ) );  return false; }
	for (i=2; i < urlCheck.arguments.length; i+=2) {
		same = urlCheck.arguments[i].split('|');
		if (same.length == 3) {
			if (form[same[1]].value != form[same[2]].value || form[same[1]].value.length < same[0]) {
				alert(str + urlCheck.arguments[i+1]);
				form[urlCheck.arguments[i]].focus();
//				form[urlCheck.arguments[i]].select();
				return false;
			}
		} 
		if (form[urlCheck.arguments[i]]) {
			box = form[urlCheck.arguments[i]];
			if ( (box.type == 'text' && box.value == '') 
			||(box.type == 'checkbox' && ( ! box.checked )) 
			||(box.type == 'select-one' && box.options[box.selectedIndex].value == 'nil') 
			||(box.type == 'textarea' && box.value == '')) {
				alert(str + urlCheck.arguments[i+1]);
				form[urlCheck.arguments[i]].focus();
//				form[urlCheck.arguments[i]].select();
				return false;
			}
		}
	}
	return true;    
}

function urlCheckIF(form,field,str,reqList) {
	if (field == '' || form[field].value != '') {
		for (i=3; i < urlCheckIF.arguments.length; i++) {
			same = urlCheckIF.arguments[i].split('|');
			if (same.length == 3) {
				if (form[same[1]].value != form[same[2]].value || form[same[1]].value.length < same[0]) {
					alert(str + ' Password');
					return false;
				}
			} 
			if (form[urlCheckIF.arguments[i]]) {
				box = form[urlCheckIF.arguments[i]];
				if ( (box.type == 'text' && box.value == '') 
				||(box.type == 'select-one' && box.options[box.selectedIndex].value == 'nil')) {
					alert(str + urlCheckIF.arguments[i]);
					return false;
				}
			}
		}
	}
	return true;    
}

function getCost(str) {
	num = parseFloat(str.substring(str.indexOf(",")+1));
	if (isNaN(num)) num = "0";
	return num;
}

// Pass first the box to do, then any it clashes with.
// ie (Box, Clash1, Clash2, ....).
function checkChoice(whichbox) { 
	var form = whichbox.form;
	var total = parseFloat(form.hiddentotal.value.toString().replace(/\$|,/,''));
	var boxCost = getCost(whichbox.value);
// alert(total+' -- '+boxCost);

// Uncheck any clashes and remove.
	for (i = 1; i < checkChoice.arguments.length; i++) {
		clash = checkChoice.arguments[i];
		if (clash.checked) {
			clash.checked = false; 
			form.hiddenCountChosen.value--;
			total -= getCost(clash.value);
		}
	}
 
	if (whichbox.checked) {
		form.hiddenCountChosen.value++;
		total += boxCost;
	} else {
		form.hiddenCountChosen.value--;
		total -= boxCost;
	}
		form.hiddentotal.value = formatCurrency(total);
		return form.hiddentotal.value;
}

function checkboxClash(box,clash) {
// Uncheck any clashes and remove.
	for (i = 1; i < checkboxClash.arguments.length; i++) {
		clash = checkboxClash.arguments[i];
		if (clash.checked) {
			clash.checked = false; 
		}
	}
	return formTotal(box.form);
}

function formTotal(form) {
	var total = 0;
	for (i=0; i < form.length; i++) {
		box = form[i];
		if ((form[i].type == 'radio' || form[i].type == 'checkbox') && form[i].checked) {
			total += getCost(form[i].value);
		}
	}
	form.hiddentotal.value = total;
	return formatCurrency(form.hiddentotal.value);
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|,/g,'');
	if(isNaN(num)) 
	num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) 
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

	val = num + "." + cents;
	val = val.substr(0,val.indexOf(".")+3);
	return (val);
}

function emptyField(field) {
	field.value = "";
}
