function checkForm(objForm) {
	var fieldId = new Array();
	var mandatoryField = new Array();
	fieldId[0]  = "The Contact Name";
	fieldId[1]  = "The Company Name"
	fieldId[2]  = "The First line of the Address";
	fieldId[3]  = "The Second line of the Address";
	fieldId[4]  = "The Third line of the Address";
	fieldId[5]  = "The Fourth line of the Address";
	fieldId[6]  = "The Postcode";
	fieldId[7]  = "The Phone Number";
	fieldId[8]  = "The Email Address";
//9-12 emptype
	fieldId[9] = "*";
	fieldId[10] = "*";
	fieldId[11] = "*";
	fieldId[12] = "*";

//13-16 nmr emp radio

	fieldId[13] = "*";
	fieldId[14] = "*";
	fieldId[15] = "*";
	fieldId[16] = "*";

// 17 no of delegatess	
	fieldId[17] = "The Number of Delegates";

// 18 & 19 session radio
	fieldId[18]  = "*";
	fieldId[19] = "*";

// 20 disability	
	fieldId[20] = "*";

// 21- 27 survey
	fieldId[21] = "*";
	fieldId[22] = "*";
	fieldId[23] = "*";
	fieldId[24] = "*";
	fieldId[25] = "*";
	fieldId[26] = "*";
	fieldId[27] = "Other Additional Information";

//28-29 survery contact radio	
	fieldId[28] = "*";
	fieldId[29] = "*";

	mandatoryField[0]  = true; // Contact Name
	mandatoryField[1]  = false; // Company name
	mandatoryField[2]  = true; // Addr 1
	mandatoryField[3]  = true; //Addr 2
	mandatoryField[4]  = false; // Addr 3
	mandatoryField[5]  = false; // Addr 4
	mandatoryField[6]  = true; // pcode
	mandatoryField[7]  = true;  //phone
	mandatoryField[8]  = true;  //email


	mandatoryField[9] = "*";  //emp type check
	mandatoryField[10] = "*";  //emp type check
	mandatoryField[11] = "*";  //emp type check
	mandatoryField[12] = "*";  //emp type check

	mandatoryField[13] = "*";  //emp nmr radio
	mandatoryField[14] = "*";  //emp nmr radio
	mandatoryField[15] = "*";  //emp nmr radio
	mandatoryField[16] = "*";  //emp nmr radio

	mandatoryField[17] = true; // nmr delegates

	mandatoryField[18] = "*";  // session radio
	mandatoryField[19] = "*";  // session radio
	
	mandatoryField[20] = "*"; // disab
	
	mandatoryField[21] = "*"; // survey bulletin
	mandatoryField[22] = "*"; // postal invite
	mandatoryField[23] = "*"; // survey internet
	mandatoryField[24] = "*"; // survey CD rom
	mandatoryField[25] = "*"; // survey leaflet
	mandatoryField[26] = "*"; // survey other
	mandatoryField[27] = false; // survey specifyother

	mandatoryField[28] = false; // survey contact radio
	mandatoryField[29] = false; // survey contact radio	

	var arClass, bValid;
	var objField = document.getElementsByTagName('input');
	cumulativeErrorMessage = ""   // build this as we go along
	var istart = 4 //  force for header include, etc. 6 hidden inputs removed from header inc (ND 31/8/2010)
	//var istart = 10 //  force for header include, etc. Can only work server side
	/* alert(objField[8].value)
	debugStr = ""     DEBUG SCRIPT START * 

	for (var iFieldCounter=istart; iFieldCounter<objField.length; iFieldCounter++) {
		var ij = iFieldCounter - istart
		var ik = ij
		debugStr = debugStr + "\n" + " fieldId[" + ik + "]=" + fieldId[ik] + " objField[" + iFieldCounter + "]=" + objField[iFieldCounter].value
	}
	  alert(debugStr)          DEBUG SCRIPT END */
	for (var iFieldCounter=istart; iFieldCounter<objField.length; iFieldCounter++) {
		var ij = iFieldCounter - istart
		var ik = ij
		// Allow for multiple values being assigned to the class attribute
		arClass = objField[iFieldCounter].className.split(' ');
		for (var iClassCounter=0; iClassCounter<arClass.length; iClassCounter++) {
			switch (arClass[iClassCounter])
			{
		        case 'string':
			   if (objField[iFieldCounter].value == "") {
				   if (mandatoryField[ik]) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] +  " is missing"}
	                   }
			   else {
			      bValid = isString(objField[iFieldCounter].value.replace(/^\s*|\s*$/g, ''));
		              if (!bValid) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is invalid"}
			    }
	                   break;

		        case 'number' :
				   if (objField[iFieldCounter].value == "") {
				   	if (mandatoryField[ik]) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is missing"}
	                   }
			   else {
			      bValid = isNumber(objField[iFieldCounter].value);
			      if (!bValid) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is invalid"}
			   }
		           break;

		        case 'from' :
				   if (objField[iFieldCounter].value == "") {
				   	if (mandatoryField[ik]) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is missing"
				   }
	                   }
			   else {
			      bValid = isEmail(objField[iFieldCounter].value);
			      if (!bValid) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is invalid"}
			   }
		           break;
			   
			case 'postcode' :
				   if (objField[iFieldCounter].value == "") {
				   	if (mandatoryField[ik]) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik]  + " is missing"
				   }
	                   }
			   else {
			      bValid = isPcode(objField[iFieldCounter].value);
			      if (!bValid) {cumulativeErrorMessage = cumulativeErrorMessage + "\n" + fieldId[ik] + " is invalid"}
			   }
		           break;

			default:
		           bValid = true;
		      	}
		}

	}

	// validate radio button groups
	var btn = valButton(document.empTalkForm.session);
	if (btn == null) {cumulativeErrorMessage = cumulativeErrorMessage + "\nPlease select a Session"}

        //check if chorley/belfast/coleraine am/pm is ok
	if((btn == "afternoon") && (objField[8].value == "ET_CHORLEY2008_2")) {cumulativeErrorMessage = cumulativeErrorMessage + "\nYou cannot book the Chorley afternoon event on this form"}
	if((btn == "morning") && (objField[8].value == "ET_CHORLEY2008_1")) {cumulativeErrorMessage = cumulativeErrorMessage + "\nYou cannot book the Chorley morning event on this form"}
	if((btn == "afternoon") && (objField[8].value == "ET_BELFAST2008")) {cumulativeErrorMessage = cumulativeErrorMessage + "\nPlease note Belfast is a morning only event"}
	if((btn == "afternoon") && (objField[8].value == "ET_COLERAINE2008")) {cumulativeErrorMessage = cumulativeErrorMessage + "\nPlease note Coleraine is a morning only event"}

	var btn = valButton(document.empTalkForm.nmremp);
	if (btn == null) {cumulativeErrorMessage = cumulativeErrorMessage + "\nPlease select Number of Employees"}
	if (cumulativeErrorMessage != "") {
		cumulativeErrorMessage = "Please check the following items on the form:\n" + cumulativeErrorMessage
		alert(cumulativeErrorMessage)
		return false;
	}
	else {
		//alert("Form validates")
		return true;
	}
}


function isString(strValue)
{
  return (typeof strValue == 'string' && isNaN(strValue));
}

function isNumber(strValue)
{
// remove non-numerics normally allowed in a phone number
  strValue = strValue.replace(/ /g,"")
  strValue = strValue.replace(/-/g,"")
  strValue = strValue.replace(/-/g,"")
  strValue = strValue.replace(/\(/g,"")
  strValue = strValue.replace(/\)/g,"")
  strValue = strValue.replace(/\+/g,"") 
  return (!isNaN(strValue) && strValue != '');
}

function isEmail(strValue)
{
  var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
  return (strValue != '' && objRE.test(strValue));
}


function isPcode(toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}


function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
                  



