// proxy_clear is used for clearing the error message created by the benefactor 
function proxy_clear(to) {
	document.getElementById(to).innerHTML = '';
}

function PDF5_clicked_claim (id, label, dest) {
	if(document.getElementById(id).checked) 
	{ 
		document.getElementById(id).value ="yes"; 
		document.getElementById('div_'+dest).innerHTML ="<label id='label_"+dest+"'>"+label+"</label>"; 
	} else {
		var name = document.getElementById(id).name; 
		setSessionVar(name, "no");	// not yes; need to circumvent post values
		document.getElementById(id).value ="no"; 
		document.getElementById('div_'+dest).innerHTML =""; 
	}
}

function PDF5_print_name() {
	var name = document.getElementById('input_PDF5_NAME').value;
	document.getElementById('input_PDF5_PRINT_NAME').value = name;
}	

var forms;
var form;
var elem;
function validate_PDF5() {
	//confirm('validate_PDF5')
	forms = document.forms;
	for (var i = 0; i < forms.length; i++) { 
		form = document.getElementById(forms[i].id)
		form.length
		for(var e = 0; e < form.length; e++) {
			elem = form.elements[e];
			if(elem.type == 'text') {
				//confirm(elem.value);	
				if(elem.value == '') {
					// FF hack: title='optional' prevents hidden fields from getting focus 
					if(elem.title != 'optional') {
						elem.focus();	// go to element 
						return false;
					}
				}
			}
			var en;
			var enc;
			var fe;
			if(elem.type == 'radio') {
				// ARGH!  This won't catch the last set
				//confirm(elem.name+'; '+elem.checked);
				if(!en) {
					//confirm('en empty first time');
					fe = elem;
					en = elem.name;
					enc = elem.checked;
				}
				if(en == elem.name) {
					//confirm('en == elem.name');
					enc = (enc || elem.checked);
				} else {
					//confirm('en != elem.name');
					if(!enc) {
						fe.focus(); 
						return false;	// nothing selected
					}
				}
			}
			if(elem.type == 'select-one') {
				//confirm(elem.id);	
				//confirm(elem.selectedIndex);	
				if(elem.selectedIndex == 0) {
					elem.focus();	// go to element 
					return false;
				}
			}
		}
	}
}

var input_PDF5_NAME
input_PDF5_NAME = function() {
	var name = document.getElementById('input_PDF5_NAME').value;
	// the printed name is empty fill
	if(document.getElementById('input_PDF5_PRINT_NAME').value == '') {
		document.getElementById('input_PDF5_PRINT_NAME').value = name;
	}
	tabbing = false;
	//valueChange('input_PDF3_PRINTED_NAME');	// not id sent
}

var input_PDF5_NAME_error
input_PDF5_NAME_error = function() {
	document.getElementById('input_PDF5_NAME').focus();
}

var input_PDF5_BUSINESS_NAME
input_PDF5_BUSINESS_NAME = function() {
	tabbing = false;
}	

var input_PDF5_BUSINESS_NAME_error
input_PDF5_BUSINESS_NAME_error = function() {
	document.getElementById('input_PDF5_BUSINESS_NAME').focus();
}	

var input_PDF5_STREET
input_PDF5_STREET = function() {
	tabbing = false;
}	

var input_PDF5_STREET_error
input_PDF5_STREET_error = function() {
	document.getElementById('input_PDF5_STREET').focus();
}	

var input_PDF5_CITY
input_PDF5_CITY = function() {
	proxy_clear('input_PDF5_STREET_error');
	tabbing = false;
}	

var input_PDF5_CITY_error
input_PDF5_CITY_error = function() {
	proxy_set('input_PDF5_CITY_error','input_PDF5_STREET_error');
	document.getElementById('input_PDF5_CITY').focus();
}	

var select_PDF5_STATE
select_PDF5_STATE = function() {
	proxy_clear('input_PDF5_STREET_error');
	tabbing = false;
}

var select_PDF5_STATE_error
select_PDF5_STATE_error = function() {
	proxy_set('select_PDF5_STATE_error','input_PDF5_STREET_error');
	document.getElementById('select_PDF5_STATE').focus();
}

var input_PDF5_ZIP
input_PDF5_ZIP = function() {
	proxy_clear('input_PDF5_STREET_error');
	tabbing = false;
}	

var input_PDF5_ZIP_error
input_PDF5_ZIP_error = function() {
	proxy_set('input_PDF5_ZIP_error','input_PDF5_STREET_error');
	document.getElementById('input_PDF5_ZIP').focus();
}	

var input_PDF5_PHONE
input_PDF5_PHONE = function() {
	proxy_clear('input_PDF5_FAX_error');
	tabbing = false;
}	

var input_PDF5_PHONE_error
input_PDF5_PHONE_error = function() {
	proxy_set('input_PDF5_PHONE_error','input_PDF5_FAX_error');
	document.getElementById('input_PDF5_PHONE').focus();
}	

var input_PDF5_FAX
input_PDF5_FAX = function() {
	tabbing = false;
}	

var input_PDF5_FAX_error
input_PDF5_FAX_error = function() {
	// not required
	//document.getElementById('input_PDF5_FAX').focus();
	var innerHTML = document.getElementById('input_PDF5_FAX_error').innerHTML;
	document.getElementById('input_PDF5_FAX_error').innerHTML = 'Optional: '+innerHTML;
	tabbing = false;
}	

var input_PDF5_PRODUCTS
input_PDF5_PRODUCTS = function() {
	tabbing = false;
}	

var input_PDF5_PRODUCTS_error
input_PDF5_PRODUCTS_error = function() {
	document.getElementById('input_PDF5_PRODUCTS').focus();
}	

var input_PDF5_LOCATION_NAME
input_PDF5_LOCATION_NAME = function() {
	tabbing = false;
}	

var input_PDF5_LOCATION_NAME_error
input_PDF5_LOCATION_NAME_error = function() {
	document.getElementById('input_PDF5_LOCATION_NAME').focus();
}	

var input_PDF5_LOCATION_STREET
input_PDF5_LOCATION_STREET = function() {
	tabbing = false;
}	

var input_PDF5_LOCATION_STREET_error
input_PDF5_LOCATION_STREET_error = function() {
	document.getElementById('input_PDF5_LOCATION_STREET').focus();
}	

var input_PDF5_LOCATION_CITY
input_PDF5_LOCATION_CITY = function() {
	proxy_clear('input_PDF5_LOCATION_STREET_error');
	tabbing = false;
}	

var input_PDF5_LOCATION_CITY_error
input_PDF5_LOCATION_CITY_error = function() {
	proxy_set('input_PDF5_LOCATION_CITY_error','input_PDF5_LOCATION_STREET_error');
	document.getElementById('input_PDF5_LOCATION_CITY').focus();
}	

var select_PDF5_LOCATION_STATE
select_PDF5_LOCATION_STATE = function() {
	proxy_clear('input_PDF5_LOCATION_STREET_error');
	tabbing = false;
}	

var select_PDF5_LOCATION_STATE_error
select_PDF5_LOCATION_STATE_error = function() {
	proxy_set('select_PDF5_LOCATION_STATE_error','input_PDF5_LOCATION_STREET_error');
	document.getElementById('select_PDF5_LOCATION_STATE').focus();
}	

var input_PDF5_LOCATION_ZIP
input_PDF5_LOCATION_ZIP = function() {
	proxy_clear('input_PDF5_LOCATION_STREET_error');
	tabbing = false;
}	

var input_PDF5_LOCATION_ZIP_error
input_PDF5_LOCATION_ZIP_error = function() {
	proxy_set('input_PDF5_LOCATION_ZIP_error','input_PDF5_LOCATION_STREET_error');
	document.getElementById('input_PDF5_LOCATION_ZIP').focus();
}	

var input_PDF5_LOCATION_PHONE
input_PDF5_LOCATION_PHONE = function() {
	proxy_clear('input_PDF5_LOCATION_FAX_error');
	tabbing = false;
}	

var input_PDF5_LOCATION_PHONE_error
input_PDF5_LOCATION_PHONE_error = function() {
	proxy_set('input_PDF5_LOCATION_PHONE_error','input_PDF5_LOCATION_FAX_error');
	document.getElementById('input_PDF5_LOCATION_PHONE').focus();
}	

var input_PDF5_LOCATION_FAX
input_PDF5_LOCATION_FAX = function() {
	tabbing = false;
}	

var input_PDF5_LOCATION_FAX_error
input_PDF5_LOCATION_FAX_error = function() {
	// not required
	//document.getElementById('input_PDF5_FAX').focus();
	var innerHTML = document.getElementById('input_PDF5_LOCATION_FAX_error').innerHTML;
	document.getElementById('input_PDF5_LOCATION_FAX_error').innerHTML = 'Optional: '+innerHTML;
	tabbing = false;
}	

var input_PDF5_OPERATIONS
input_PDF5_OPERATIONS = function() {
	tabbing = false;
}	

var input_PDF5_OPERATIONS_error
input_PDF5_OPERATIONS_error = function() {
	var innerHTML = document.getElementById('input_PDF5_OPERATIONS_error').innerHTML;
	document.getElementById('input_PDF5_OPERATIONS_error').innerHTML = 'Optional: '+innerHTML;
	tabbing = false;
}	

function PDF5_clicked_signature (id) {
	if(document.getElementById(id).checked) 
	{ 
		setSessionVar(id, "yes");	// not yes; need to circumvent post values
		document.getElementById(id).value ="yes"; 
		document.getElementById('label_SIGNATURE').innerHTML ="I approve of this transaction."; 
	} else {
		setSessionVar(id, "no");	// not yes; need to circumvent post values
		document.getElementById(id).value ="no"; 
		document.getElementById('label_SIGNATURE').innerHTML ="By checking this box, in lieu of my signature, I approve of this transaction."; 
	}
}

function PDF5_checkbox_with_effect (id) {
	var name = document.getElementById(id).name;
	if(document.getElementById(id).checked) 
	{ 
		getSessionVar(name+'_yes', 'label_'+name+'_effect')	// performs innerHTML on arg 2
		setSessionVar(id, "yes");	// not yes; need to circumvent post values
		document.getElementById(id).value ="yes";
		document.getElementById(id+'_EFFECT').focus();	// i.e. input_PDF5_LARGER_FUNCTION_EFFECT
	} else {
		getSessionVar(name+'_no', 'label_'+name+'_effect')	
		setSessionVar(id, "no");	// not yes; need to circumvent post values
		document.getElementById(id).value ="no"; 
	}
}

