var DEBUG = false;
var principleGroup = null;
var principlesGroup = new Array();

//''*******************************************************************
//''*******************************************************************
//''******* CONFIRMPARTNERLEVEL ***************************************
//''*******************************************************************
//''*******************************************************************
//''
function confirmPartnerLevel()
{
  principleGroup = getSelectedRadioGroupObject("field_Plan_Principle");
  var partnerGroup = getSelectedRadioGroupObject("field_Plan_Partner");

  if(partnerGroup && (principleGroup==null || (principleGroup && partnerGroup.value>principleGroup.value)))
  {
		return "Please note that in order to be entitled to the 50% discount your spouse / partner must be on either the same or a lower level of cover than you. Please check that you have selected the correct cover levels before continuing your application.\n\n";
//    alert("Please note that in order to be entitled to the 50% discount your spouse / partner must be on either the same or a lower level of cover than you. Please check that you have selected the correct cover levels before continuing your application.");
//    document.MM_returnValue = false;
//    return false;
  }

	return "";
//  return true;
}

//''*******************************************************************
//''*******************************************************************
//''******* DEBUGALERT ************************************************
//''*******************************************************************
//''*******************************************************************
//''
function debugAlert(str)
{
  if (DEBUG)
    alert(str);
}

//''*******************************************************************
//''*******************************************************************
//''******* GETSELECTEDRADIOGROUPOBJECT *******************************
//''*******************************************************************
//''*******************************************************************
//''
function getSelectedRadioGroupObject(groupName,formName)
{
	var form = document.forms[0];

	if(formName > "")
		eval("var form = document."+formName);

	eval("var group = form."+groupName);

	if(group)
  {
		for(var i=0;i<group.length;i++)
    {
			if(group[i].checked)
				return group[i];
		}
	}

	return null;
}



function gotoTop(){
	window.location.href = "#top";
}


//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_VALIDATEANDCHECKFORM *****************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_validateAndCheckForm(form)
{

	var rVal = "";
	
	var partnerRVal = longford_checkPartnerDetails(form);
	
	rVal += partnerRVal;
//	if(partnerRVal>""){
//		rVal += longford_checkIndJointCoverPartnerUnder21();
//	}
	
	rVal += longford_checkIndJointCoverPrincipleCover();
	rVal += confirmPartnerLevel();
	rVal += longford_checkIndJointCoverPrincipleUnder21();
	rVal += longford_checkIndJointCoverPrinciplePenaltyPoints();
	

	if(rVal > ""){
//		alert(rVal);
//		document.MM_returnValue2 = false;
	} else {
//		document.MM_returnValue = true;
	}
	document.PNP_validationMessage = rVal;
	
	return true;
	
	
}



function longford_validateAndCheckRequestABrochureForm()
{
	if(!longford_checkRequestABrochureCheckBoxes())
		return false;

  return true;
}


function longford_checkRequestABrochureCheckBoxes()
{
  var functionName = "longford_checkRequestABrochureCheckBoxes -->\n";
  debugAlert("IN .. "+functionName);
  if (document.getElementById("ind_joint_broch").checked || document.getElementById("group_broch").checked)
    return true;
  else
  {
    alert("Please select wether you want an individual and/or group brochure.");
    return false;
  }
}

//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_VALIDATEANDCHECKGROUPFORM ************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_validateAndCheckGroupForm(noOfMembers)
{
  var chk = true;
  var memberNoArray = new Array();


	if(!longford_checkGroupPenaltyPoints(noOfMembers))
		return false;


	//'' check each member has selected a plan
	if(!longford_checkGroupPlansSelected(noOfMembers))
		return false;

  //''*****************************************************************
  //''* START -> CHECK each group member is over 21
  //''
  for (var i=0; i<noOfMembers; i++)
  {
    if(!longford_checkGroupCoverMemberUnder21(i+1))
    {
      memberNoArray.push(i+1);
      chk = false;
    }
  }

  if (!chk)
  {
    var msg = "According to the information supplied ";

    if (memberNoArray.length == 1)
      msg += "'Group Member' ";
    else
      msg += "'Group Members' ";

    for (var i=0; i<memberNoArray.length; i++)
    {
      if ((memberNoArray.length > 1) && (i == memberNoArray.length - 1))
        msg +=" and ";

      msg += new String(memberNoArray[i]);

      if ((memberNoArray.length > 1) && (i < memberNoArray.length - 1))
        msg +=", ";
    }

    if (memberNoArray.length == 1)
      msg +=" is under 21 ";
    else
      msg +=" are under 21 ";

    alert(msg + "years of age.\n\nChauffeurplan does not cover drivers that are under 21.\nPlease check that you have entered the correct information.\nIf you are aged under 21 we are sorry that we cannot progress with\n your application at this time.");
    return false;
  }
  //''
  //''* END -> CHECK each group member is over 21
  //''*******************************************



  //''*****************************************************************
  //''* START -> CHECK each group member has COVER
  //''
  for (var i=0; i<noOfMembers; i++)
  {
    if(!longford_checkGroupCoverMemberUnder21(i+1))
    {
      memberNoArray.push(i+1);
      chk = false;
    }
  }

  if (!chk)
  {
    var msg = "According to the information supplied ";

    if (memberNoArray.length == 1)
      msg += "'Group Member' ";
    else
      msg += "'Group Members' ";

    for (var i=0; i<memberNoArray.length; i++)
    {
      if ((memberNoArray.length > 1) && (i == memberNoArray.length - 1))
        msg +=" and ";

      msg += new String(memberNoArray[i]);

      if ((memberNoArray.length > 1) && (i < memberNoArray.length - 1))
        msg +=", ";
    }

    if (memberNoArray.length == 1)
      msg +=" is under 21 ";
    else
      msg +=" are under 21 ";

    alert(msg + "years of age.\nChauffeurplan does not cover drivers that are under 21.\nPlease check that you have entered the correct information.\nIf you are aged under 21 we are sorry that we cannot progress with\n your application at this time.");
    return false;
  }
  //''
  //''* END -> CHECK each group member has COVER
  //''******************************************

	return true;
}



//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKPARTERDETAILS *******************************
//''*******************************************************************
//''*******************************************************************
//''

function longford_checkPartnerDetails(form){

	// go through the form and find all principle&partner fields
	var msg = "";
	var rVal = "";
	var principleFields = new Array();
	var partnerFields = new Array();


	if(navigator.appName != 'Netscape'){
		for(i=0;i<document.forms.length;i++){
			for(j=0;j<document.forms[i].elements.length;j++){
				var formObj=document.forms[i].elements[j];
				if(longford_isValidFormObj(formObj)){
					if(formObj.name.match(/_principle/i))
						principleFields.push(formObj);
					if(formObj.name.match(/_partner/i) && !formObj.name.match(/occupation/i))
						partnerFields.push(formObj);
				}
			}
		}
	}


	// see if any of the partner fields are populated
	var requirePartnerFields = false;
	for(var i in partnerFields){
		if(longford_isFieldPopulated(partnerFields[i])){
			requirePartnerFields = true;
		}
	}


	//'' if partner fields are required, make sure all are completed
	var allPartnerFieldsOK = true;
	if(requirePartnerFields){
		//'' keep a list of fields that have been checked
		//'' so that we don't get duplcates of radio groups
		var checkedPartnerFields = String(" ");
		for(var i in partnerFields){
			if(!longford_isFieldPopulated(partnerFields[i])){
				var myRE = new RegExp(" "+partnerFields[i].name+" ");
				if(!checkedPartnerFields.match(myRE)){
					checkedPartnerFields += partnerFields[i].name+" ";
					var fieldName = String(partnerFields[i].name);
					fieldName = fieldName.substr(0,1).toUpperCase()+fieldName.substr(1);
					fieldName = fieldName.replace(/_partner/i,"");
					fieldName = fieldName.replace(/field_/i,"");

					msg += "The partner's "+ fieldName+" must be completed.\n";
					allPartnerFieldsOK = false;
				}
			}
		}
	}

	rVal += longford_checkIndJointCoverPartnerUnder21(form);

	if(!allPartnerFieldsOK)
		 rVal += "Partner details required:\n\n"+msg+"\n\n";


	return rVal;
}



function longford_isFieldPopulated(formObj){

	if(formObj.type.toLowerCase() == "text" || formObj.type.toLowerCase	() == "password" || formObj.type.toLowerCase() == "textarea"){
		if(formObj.value > "")
			return true;
	}

	if(formObj.type.toLowerCase() == "checkbox"){
		if(formObj.checked)
			return true;
	}

	if(formObj.type.toLowerCase() == "radio"){
		var radioObj = getSelectedRadioGroupObject(formObj.name,formObj.form.name);
		if(radioObj && radioObj.value)
			return true;
	}

	return false;
}



function longford_isValidFormObj(formObj){
	if(formObj.type.toLowerCase() == "text" || formObj.type.toLowerCase	() == "password" || formObj.type.toLowerCase() == "checkbox" || formObj.type.toLowerCase() == "textarea" || formObj.type.toLowerCase() == "radio")
		return true;

	return false;
}


//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CONVERTYEAR **************************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_convertYear(yearStr)
{
	var yearStr = yearStr || "January";

  switch (yearStr.toLowerCase())
  {
    case "january":
      return 0;
      break;

    case "febuary":
      return 1;
      break;

    case "march":
      return 2;
      break;

    case "april":
      return 3;
      break;

    case "may":
      return 4;
      break;

    case "june":
      return 5;
      break;

    case "july":
      return 6;
      break;

    case "august":
      return 7;
      break;

    case "september":
      return 8;
      break;

    case "october":
      return 9;
      break;

    case "november":
      return 10;
      break;

    case "december":
      return 11;
      break;

    default:
      return 0;
  }
}

//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKINDJOINTCOVERUNDER21 ************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_checkGroupCoverMemberUnder21(memberNum)
{
  var memberNumStr = (memberNum > 0)?new String(memberNum):"1";
  var birthDay = document.getElementById("field_Member_"+memberNumStr+"_DoB_Day").value;
  var birthMonth = longford_convertYear(document.getElementById("field_Member_"+memberNumStr+"_DoB_Month").value);
  var birthYear = "19"+document.getElementById("field_Member_"+memberNumStr+"_DoB_Year").value;
  var age = longford_getAgeInYears(new Date(birthYear, birthMonth, birthDay));

  //''debugAlert("longford_checkGroupCoverMemberUnder21() -->\n birthDay == "+birthDay+", birthMonth == "+birthMonth+", birthYear == "+birthYear+", age == "+age);

  if (age >= 21)
    return true;
  else
    return false;
}


//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKINDJOINTCOVERPENALTYPOINTS ******************
//''*******************************************************************
//''*******************************************************************
//''
/*
function longford_checkCompanyGroupPrincipleCover(memberNum)
{

  if (aNum < 1)
    return false;

  for (var i=0; i<memberNum.length; i++)
  {
    var found = false;
    for (var j=0; j<principlesGroup.length; j++)
    {
      if (principlesGroup[j] == i)
      {
        found
      }
    }
  }
  //''debugAlert("longford_checkGroupCoverMemberUnder21() -->\n birthDay == "+birthDay+", birthMonth == "+birthMonth+", birthYear == "+birthYear+", age == "+age);

  if (age >= 21)
    return true;
  else
    return false;
}
*/

//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_GROUPCOVERRADIOBTNCLICKED ************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_groupCoverRadioBtnClicked(aNum)
{
  if (aNum > 0)
    principlesGroup.push(aNum);
}

//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKINDJOINTCOVERPRINCIPLEUNDER21 ***************
//''*******************************************************************
//''*******************************************************************
//''
function longford_checkIndJointCoverPrincipleUnder21(form)
{
  var funcName = "longford_checkIndJointCoverPrincipleUnder21() -->\n";
  var birthDay = document.getElementById("field_DoB_Day_Principle").options[document.getElementById("field_DoB_Day_Principle").selectedIndex].value;
  var birthMonth = longford_convertYear(document.getElementById("field_DoB_Month_Principle").options[document.getElementById("field_DoB_Month_Principle").selectedIndex].value);
  var birthYear = "19"+document.getElementById("field_DoB_Year1_Principle").options[document.getElementById("field_DoB_Year1_Principle").selectedIndex].value;
  var age = longford_getAgeInYears(new Date(birthYear, birthMonth, birthDay));

  if (age >= 21){
  	return "";
//    return true;
  } else {
  	return "According to the information supplied you are under 21 years of age.\nChauffeurplan does not cover drivers that are under 21.\nPlease check that you have entered the correct information.\nIf you are aged under 21 we are sorry that we cannot progress with\n your application at this time.\n\n";
//    alert("According to the information supplied you are under 21 years of age.\nChauffeurplan does not cover drivers that are under 21.\nPlease check that you have entered the correct information.\nIf you are aged under 21 we are sorry that we cannot progress with\n your application at this time.");
 //   return false;
  }
}




function longford_checkIndJointCoverPartnerUnder21(form)
{
  var funcName = "longford_checkIndJointCoverPartnerUnder21() -->\n";
  var birthDay = document.getElementById("field_DoB_Day_Partner").options[document.getElementById("field_DoB_Day_Partner").selectedIndex].value;
  birthDay = (parseInt(birthDay)>0)?birthDay:1;
  var birthMonth = longford_convertYear(document.getElementById("field_DoB_Month_Partner").options[document.getElementById("field_DoB_Month_Partner").selectedIndex].value);
  var birthYear = "19"+document.getElementById("field_DoB_Year1_Partner").options[document.getElementById("field_DoB_Year1_Partner").selectedIndex].value;
  var age = longford_getAgeInYears(new Date(birthYear, birthMonth, birthDay));


  if (age >= 21){
  	return "";
  } else {
  	return "According to the information supplied your partner is under 21 years of age.\nChauffeurplan does not cover drivers that are under 21.\nPlease check that you have entered the correct information.\nIf your parnter is aged under 21 we are sorry that we cannot progress with\n your application at this time.\n\n";
  }
}


//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKINDJOINTCOVERPENALTYPOINTS ******************
//''*******************************************************************
//''*******************************************************************
//''
function longford_checkIndJointCoverPrinciplePenaltyPoints()
{
  var principlePoints = document.getElementById("prin_penalty_points").value;

  //debugAlert("principlePoints == "+principlePoints);

  if (principlePoints < 8){
  	return "";
    //return true;
  }else
  {
  	return "According to the information supplied you have more than 7 points on your license.\nIn order to be covered for 'totting up' disqualification\n benefits you must have no more than 7 points on your\n licence actual, possible and/or pending when you apply.\n\n";
//    alert("According to the information supplied you have more than 7 points on your license.\nIn order to be covered for 'totting up' disqualification\n benefits you must have no more than 7 points on your\n licence actual, possible and/or pending when you apply.");
//    return false;
  }
}


function longford_checkGroupPenaltyPoints(noOfMembers)
{



	if(noOfMembers){
		for(var i=1;i<=noOfMembers;i++){

			var principlePoints = document.getElementById("field_Member_"+i+"_Penalty_Points").value;

			if (!(principlePoints < 8)){
				alert("According to the information supplied some members have more than 7 points on their license.\nIn order to be covered for 'totting up' disqualification\n benefits you must have no more than 7 points on your\n licence actual, possible and/or pending when you apply.");
				return true;
			}

		}
	}

	return true;

}


//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_CHECKINDJOINTCOVERPENALTYPOINTS ******************
//''*******************************************************************
//''*******************************************************************
//''
function longford_checkIndJointCoverPrincipleCover()
{
  //''debugAlert("principleGroup == "+principleGroup);

  if (principleGroup != null){
	return "";
//	return true;
  }else
  {
    return "According to the information supplied you have not chosen a cover plan.\nPlease select a cover plan to continue.\n\n";
//    alert("According to the information supplied you have not chosen a cover plan.\nPlease select a cover plan to continue.");
//    return false;
  }
}

//''*******************************************************************
//''*******************************************************************
//''******* LONGFORD_GETAGEINYEARS ************************************
//''*******************************************************************
//''*******************************************************************
//''
function longford_getAgeInYears(birthDate)
{
  var today = new Date();
  var diff = today-birthDate;  //difference in milliseconds
  if (diff < 0)
    return 0;
  var diffDays = new String(diff/86400000);
  var daysStr=diffDays.substring(0,diffDays.indexOf(".")); //get just the whole days
  var yearsStr=new String(parseInt(daysStr)/365);
  yearsStr=yearsStr.substring(0,yearsStr.indexOf("."));
  return yearsStr;
}


function longford_checkGroupPlansSelected(noOfMembers){

	if(noOfMembers){
		for(var i=1;i<=noOfMembers;i++){
			var radioGroup = getSelectedRadioGroupObject("field_Member_"+i+"_Plan");
			if(!radioGroup || !radioGroup.value){
				alert("Please ensure that you have selected a plan for each member.");
				return false;
			}
		}
	}
	return true;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


//''*******************************************************************
//''*******************************************************************
//''******* MM_OPENBRWINDOW *******************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}

//''*******************************************************************
//''*******************************************************************
//''******* MM_PRELOADIMAGES ******************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//''*******************************************************************
//''*******************************************************************
//''******* MM_RELOADPAGE *********************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


//''*******************************************************************
//''*******************************************************************
//''******* MM_SWAPIMGRESTORE *****************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//''*******************************************************************
//''*******************************************************************
//''******* MM_SWAPIMAGE **********************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; if(a[i+2]!="/locations/x.gif"){x.src=a[i+2];}}
}

//''*******************************************************************
//''*******************************************************************
//''******* MM_VALIDATEFORM *******************************************
//''*******************************************************************
//''*******************************************************************
//''
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  }
  if (errors){
  	if(document.formMessage>""){
		alert(document.formMessage);
	} else {
		alert('The following error(s) occurred:\n'+errors);
	}
  }
  document.MM_returnValue = (errors == '');
}

//''*******************************************************************
//''*******************************************************************
//''******* YY_CHECKFORM **********************************************
//''*******************************************************************
//''*******************************************************************
//''
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){
      //s+='* '+a[i+3]+'\n';
      err=false;
      var displayName = String(a[i]);
      displayName = displayName.replace(/field_/,"");
      displayName = displayName.replace(/_Name/,"Name");
      displayName = displayName.replace(/Name/," Name");
      displayName = displayName.replace(/Required/," Required");

      //'' make all Telephone fields into Tel, and then all Tel's into Telephone
      displayName = displayName.replace(/Telephone/,"Tel");
      displayName = displayName.replace(/Tel/,"Telephone");

      if(displayName.match(/Email/)){
            s+='* Please enter a valid email address\n';
      } else if(displayName.match(/Terms/)){
            s+='* You must agree to the Terms and Conditions before proceeding\n';
      } else {
            s+='* '+displayName+' is a mandatory field\n';
      }
    }
  }
  if (s!=''){
  	//if(document.formMessage>""){
	if(false){
		alert(document.formMessage);
	} else {
		alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s);
	}
  }
  //'' the MM_returnValue might be false already
  if(s=='')
	  document.MM_returnValue = true;
	  
	alert(document.MM_returnValue);
}
