<!--

//This file contains functions used to validate form input 
//for various forms on the EPSON UK website.

function mailer_form_validation(form){
	//Used on /reseller/mailer_subscribe.htm
	name_field = findObj2("name");
	email_field = findObj2("email");
	opt_in_mail_field = findObj2("opt_in_mail");
	opt_in_email_field = findObj2("opt_in_email");
	
	if (name_field.value == ""){
		alert("Please complete the 'Name' field before submitting this form.");
		return false;
	}
	
	if (email_field.value == ""){
		alert("Please complete the 'Email' field before submitting this form.");
		return false;
	}
	
	if (opt_in_mail_field.checked == true){
		addr1_field = findObj2("addr1");
		town_field = findObj2("town");
		postcode_field = findObj2("postcode");
		
		if (addr1_field.value == "" || town_field.value == "" || postcode_field.value == ""){
			alert("You've opted to receive material from EPSON via post, so we need your address.  Please complete the Address, Town and Postcode fields as a minimum.");
			return false;
		}
	}
	
	return true;

}

function check_required_fields(fields, form){
	//Used for most instances of generic_email.pl forms
	//fields variable is comma-separated list of fields that are required.
	
	var list = fields.split(",");//Makes 'list' an array of fields
	
	for(i=0;i<list.length;i++){
		field = findObj2(list[i]);
		if(field.value == ""){
			alert("Please complete the required fields before submitting this form.  Field '" + list[i] + "' is empty.");
			return false;
		}
	}
	return true;
}

// Example: obj = findObj("image1");
function findObj2(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}
//-->