// proxy_set is used for the purpose of display error messages in a better position 
function proxy_set(from, to) {
	var innerHTML = document.getElementById(from).innerHTML;
	document.getElementById(to).innerHTML = innerHTML;
	document.getElementById(from).innerHTML = '';
}

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

function PDF7_print_name() {
	var name = document.getElementById('input_PDF7_NAME').value;
	document.getElementById('input_PDF7_PRINT_NAME').value = name;
}	

function PDF7_checkbox_with_effect (id) {
	var name = document.getElementById(id).name;
	if(document.getElementById(id).checked) 
	{ 
		document.getElementById('label_'+name+'_no').innerHTML ="";	// clear the no label
		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"; 
	} else {
		document.getElementById('label_'+name+'_yes').innerHTML ="";	// clear the yes label
		getSessionVar(name+'_no', 'label_'+name+'_effect')	
		setSessionVar(id, "no");	// not yes; need to circumvent post values
		document.getElementById(id).value ="no"; 
	}
}

var forms;
var form;
var elem;
function validate_PDF7() {
	//confirm('validate_PDF7')
	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_PDF7_NAME
input_PDF7_NAME = function() {
	var name = document.getElementById('input_PDF7_NAME').value;
	// the printed name is empty fill
	if(document.getElementById('input_PDF7_PRINT_NAME').value == '') {
		document.getElementById('input_PDF7_PRINT_NAME').value = name;
	}
	tabbing = false;
	//valueChange('input_PDF3_PRINTED_NAME');	// not id sent
}

var input_PDF7_NAME_error
input_PDF7_NAME_error = function() {
	document.getElementById('input_PDF7_NAME').focus();
}

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

var input_PDF7_STREET_error
input_PDF7_STREET_error = function() {
	document.getElementById('input_PDF7_STREET').focus();
}	

var input_PDF7_DRIVERS_LICENSE
input_PDF7_DRIVERS_LICENSE = function() {
	proxy_clear('input_PDF7_NAME_error');
	tabbing = false;
}	

var input_PDF7_DRIVERS_LICENSE_error
input_PDF7_DRIVERS_LICENSE_error = function() {
	proxy_set('input_PDF7_DRIVERS_LICENSE_error', 'input_PDF7_NAME_error');
	document.getElementById('input_PDF7_DRIVERS_LICENSE').focus();
}	

var select_PDF7_DRIVERS_LICENSE_STATE
select_PDF7_DRIVERS_LICENSE_STATE = function() {
	proxy_clear('input_PDF7_NAME_error');	
	tabbing = false;
}

var select_PDF7_DRIVERS_LICENSE_STATE_error
select_PDF7_STATE_error = function() {
	proxy_set('select_PDF7_DRIVERS_LICENSE_STATE_error', 'input_PDF7_DRIVERS_LICENSE_STATE_error');
	document.getElementById('select_PDF7_DRIVERS_LICENSE_STATE').focus();
}

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

var input_PDF7_DRIVERS_LICENSE_EXPIRATION_error
input_PDF7_DRIVERS_LICENSE_EXPIRATION_error = function() {
	document.getElementById('input_PDF7_DRIVERS_LICENSE_EXPIRATION').focus();
}	

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

var input_PDF7_BUSINESS_NAME_error
input_PDF7_BUSINESS_NAME_error = function() {
	document.getElementById('input_PDF7_BUSINESS_NAME').focus();
}	

var input_PDF7_CITY
input_PDF7_CITY = function() {
	proxy_clear('input_PDF7_STREET_error');	
	tabbing = false;
}	

var input_PDF7_CITY_error
input_PDF7_CITY_error = function() {
	proxy_set('input_PDF7_CITY_error', 'input_PDF7_STREET_error');
	document.getElementById('input_PDF7_CITY').focus();
}	

var select_PDF7_STATE
select_PDF7_STATE = function() {
	proxy_clear('input_PDF7_STREET_error');	
	tabbing = false;
}

var select_PDF7_STATE_error
select_PDF7_STATE_error = function() {
	proxy_set('select_PDF7_STATE_error', 'input_PDF7_STREET_error');
	document.getElementById('select_PDF7_STATE').focus();
}

var input_PDF7_ZIP
input_PDF7_ZIP = function() {
	proxy_clear('input_PDF7_STREET_error');	
	tabbing = false;
}	

var input_PDF7_ZIP_error
input_PDF7_ZIP_error = function() {
	proxy_set('input_PDF7_ZIP_error', 'input_PDF7_STREET_error');
	document.getElementById('input_PDF7_ZIP').focus();
}	

var input_PDF7_PHONE
input_PDF7_PHONE = function() {
	proxy_clear('input_PDF7_FAX_error');	
	tabbing = false;
}	

var input_PDF7_PHONE_error
input_PDF7_PHONE_error = function() {
	proxy_set('input_PDF7_PHONE_error', 'input_PDF7_FAX_error');
	document.getElementById('input_PDF7_PHONE').focus();
}	

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

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

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

var input_PDF7_EMAIL_error
input_PDF7_EMAIL_error = function() {
	document.getElementById('input_PDF7_EMAIL').focus();
}	

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

var input_PDF7_PRODUCT_error
input_PDF7_PRODUCT_error = function() {
	document.getElementById('input_PDF7_PRODUCT').focus();
}	

function PDF7_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_PDF7_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_PDF7_SIGNATURE').innerHTML ="By checking this box, in lieu of my signature, I approve of this transaction."; 
	}
}