


function ShowHide()

{ var obj =    document.getElementById('delivSame');

	   if(!obj.checked) {
			 document.getElementById('address2').style.display = 'none';
			 document.getElementById('address2').style.visibility="hidden";
	   }
	   else {
			 document.getElementById('address2').style.display = '';
			 document.getElementById('address2').style.visibility ="visible";
	  }
}

var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_form(form_name) {
	
  error = false;
  form = form_name;
  error_message = "You have selected a book from the Qty menu but some of the required information has not been entered. If you do not want to purchase a book, please set the Qty to 0, otherwise, please make the following corrections:\n\n";

  check_input("firstName", 1, "First Name cannot be empty.");
  check_input("lastName", 1, "Last Name cannot be empty.");

  check_input("email", 6, "E-Mail Address must contain a minimum of 6 characters.");
  check_input("phone", 7, "Phone Number must contain a minimum of 7 characters.");
  
  check_input("add1", 1, "Street Address 1 cannot be empty.");
  check_input("add2", 1, "Street Address 2 cannot be empty.");

  check_input("town", 1, "Town cannot be empty.");
  check_input("county_state", 1, "County / State cannot be empty.");


  check_select("country", 0, "Country cannot be empty.");

  	if (document.orderForm.delivSame.checked == true)
		{
		  check_input("firstName_d", 1, "Delivery First Name cannot be empty.");
		  check_input("lastName_d", 1, "Delivery Last Name cannot be empty.");
		
		  check_input("phone_d", 7, "Delivery Phone Number must contain a minimum of 7 characters.");
		  
		  check_input("add1_d", 1, "Delivery Street Address 1 cannot be empty.");
		  check_input("add2_d", 1, "Delivery Street Address 2 cannot be empty.");
		
		  check_input("town_d", 1, "Delivery Town cannot be empty.");
		  check_input("county_state_d", 1, "Delivery County / State cannot be empty.");
		
		  check_select("country_d", 0, "Delivery Country cannot be empty.");

		}





if ((document.orderForm.qty.value > 0) && (error == true)) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function refresh_form(form_name) {
   form_name.action.value = 'refresh';
   form_name.submit();
   return true;
   }

