function updateSection(f){
	np=f.newspaper.selectedIndex-1;
	opts=f.section.options;
	while(opts.length>1){opts[opts.length-1]=null;};
	for(i=1;i<sections[np].length;i++){
		f.section.options[f.section.options.length]=new Option(sections[np][i], i-1);
	};
	updateCost(f);
	updateDatePicker(f);
}
function updateCost(f){
	np=f.newspaper.selectedIndex-1;
	sc=f.section.selectedIndex-1;
	sz=(new Number(document.forms[0].blocksize.value));
	op=(np>=0 && sc>=0)?op=prices[np][sc]*((sz%3)+2)*(1+Math.floor(sz/3)):0;
	f.cost.value=(np<0 ||sc<0) ? "" : "£"+op;
	f.amount_1.value=op;
	f.item_name_1.value=document.forms[0].blocksize.options[document.forms[0].blocksize.selectedIndex].text+" ("+f.newspaper.options[f.newspaper.selectedIndex].text+", "+f.section.options[f.section.selectedIndex].text+" section)";
	if (op==0){f.action="./nopayment.php";} else {f.action=paypal;}
}
function updateDatePicker(f){
	f.date.value='';
	np=f.newspaper.selectedIndex-1;
	sc=f.section.selectedIndex-1;
	allowdays=(np>=0 && sc>=0)?validdays[np][sc].days:'0000000';
	cutoffday=(np>=0 && sc>=0)?validdays[np][sc].cutoff:0;
}
function validateForm(f){
	msg = "";
	if (f.cost.value==""){
		msg +="choose a newspaper and section";
	}
	if (f.date.value==""){
		if (msg != "") msg += ", ";
		msg +="choose a date";
	}
	r=/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	ret=(r.test(f.email.value)&&f.email.value!='')?true:false;
	if(!ret){
		if (msg != "") msg += ",and ";
		msg +="enter a valid email address";
	}
	if (msg != ""){
		alert("Please "+msg);
		return false;
	} else {
		f.custom.value=sid+"%26"+f.newspaper.selectedIndex+"%26"+f.section.selectedIndex+"%26"+f.date.value+"%26"+f.phone.value.split("&").join("%2526")+"%26"+f.name.value.split("&").join("%2526");
		return true;
	}
}