var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {
  if (document.getElementById('addCount').value <= arrInput.length)
    return;
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  display();
}

function display() {
  if (arrInput.length == 3) {
    document.getElementById('additionalperson').style.display="none";
  }else{
    document.getElementById('additionalperson').style.display="block";
  }
  document.getElementById('row2add').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('row2add').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
  if (arrInput.length == 0) {
    document.getElementById('row2add').style.display="none";
  }else{
    document.getElementById('row2add').style.display="block";
  }
  
  document.getElementById('addCount').value = arrInput.length + 1;
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
  return "Person " + (id+2) + ":&nbsp;<input type='text' id='Person "+ (id+2) +"' name='Person" + (id+2) + "' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'>&nbsp;&nbsp;<input type='button' onclick='javascript:deleteInput()' value='DEL'><br>";
}

function ChangeAddCount() {
 if (document.getElementById('Person1').value != "") {
    if (document.getElementById('addCount').value <= 0) {
        document.getElementById('addCount').value = "1";
    }
 }else{
    document.getElementById('addCount').value = "0";
 }
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}

function validateInput() {
 
  if (document.od_form.firstname.value == "") {
     alert("Missing Value. First name is mandatory.");
     document.od_form.firstname.focus();
     return false;
  }else if (document.od_form.lastname.value == "") {
     alert("Missing Value. Last name is mandatory.");
     document.od_form.lastname.focus();
     return false;
  }else if (document.od_form.address.value == "") {
     alert("Missing Value. Address is mandatory.");
     document.od_form.address.focus();
     return false;
  }else if (document.od_form.organisation.value == "") {
     alert("Missing Value. Organisation is mandatory.");
     document.od_form.organisation.focus();
     return false;
  }else if (document.od_form.phone.value == "") {
     alert("Missing Value. Phone is mandatory.");
     document.od_form.phone.focus();
     return false;
  }else if (document.od_form.email.value == "") {
     alert("Missing Value. Email is mandatory.");
     document.od_form.email.focus();
     return false;
  }else if (document.od_form.dateofmeeting.selectedIndex == 0) {
     alert("Missing Value. Select date of meeting.");
     document.od_form.dateofmeeting.focus();
     return false;
  }else if (!document.od_form.regtype[0].checked && !document.od_form.regtype[1].checked) {
     alert("Missing value. Registration type is mandatory.");
     return false;
  }else if (document.getElementById('addCount').value >= 1) {
    if (document.getElementById('Person1').value == "") {
      alert("Missing value. Additional person name is missing.");
      document.getElementById('Person1').focus();
      return false;
    }
  }
  
  if (arrInput.length > 0) {
    for (idx=0; idx<arrInput.length;idx++) {
      if(arrInputValue[idx] == "") {
         alert("Missing value. Provide Additional Person " + (idx+2) + " value.");
         return false;
      }
    }
  }
  return true;
}
