// JavaScript Document

var nominatorfn = "";
var nominatorln = "";
var submit_by = "";
var nomsection = "";
var nomaddress1 = "";
var nomaddress2 = "";
var nomcity = "";
var nomstate = "";
var nomzip = "";       
var nomcountry = "";

function InitSaveVariables(form) {
nominatorfn = form.nominatorfn.value;
nominatorln = form.nominatorln.value;
submit_by = form.submit_by.value;
nomsection = form.nomsection.value;
nomaddress1 = form.nomaddress1.value;
nomaddress2 = form.nomaddress2.value;
nomcity = form.nomcity.value;
nomstate = form.nomstate.value;
nomzip = form.nomzip.value;
nomcountry = form.nomcountry.value;
}

function NomineeCopy(form) {
if (form.copy.checked) {
//if (nominations_form.NominationType[0].checked) {
InitSaveVariables(form);
form.nominatorfn.value = form.nomineefn.value;
form.nominatorln.value = form.nomineeln.value;
form.submit_by.value = form.nomeemail.value;
form.nomsection.value = form.section.value;
form.nomaddress1.value = form.address1.value;
form.nomaddress2.value = form.address2.value;
form.nomcity.value = form.city.value;
form.nomstate.value = form.state.value;
form.nomzip.value = form.zip.value;
form.nomcountry.value = form.country.value;

}
else{
form.nominatorfn.value = nominatorfn;
form.nominatorln.value = nominatorln;
form.submit_by.value = submit_by;
form.nomsection.value = nomsection;
form.nomaddress1.value = nomaddress1;
form.nomaddress2.value = nomaddress2;
form.nomcity.value = nomcity;
form.nomstate.value = nomstate;
form.nomzip.value = nomzip;       
form.nomcountry.value = nomcountry;
      
   }
}

//function validateCheckBoxes() {
//  var errors = '';
//  var RequiredResponsesCheckbox = window.document.FormName.CheckboxField;
//
//	if (RequiredResponsesCheckbox == null || !RequiredResponsesCheckbox.checked) {
//		errors += '- Entered Required Responses is not checked.\n';
//	}
//
//	return errors;
//}

 function validateRadios() {
 var errors = '';
 // Nomination Type
 var count = -1;
   for (i = window.document.nominations_form.NominationType.length-1; i > -1; i--) {
     if (window.document.nominations_form.NominationType[i].checked) {
       count = i; i = -1;
     }    
   }
   if (count == -1)  {
    errors += '- Please specify who is being nominated.\n';   
   }   
     
   return errors;
 }

function validateDropDowns() {
  var errors = '';
  var selectedElement = window.document.nominations_form.recposition.options[window.document.nominations_form.recposition.selectedIndex].value;
 
	if (selectedElement == "") {
		errors += '- You have not selected a Recommended Position.\n';
	}

	return errors;
}

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;
}

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 (window.document.nominations_form.nomineefn.value == "") {
		  errors += '- Nominee First Name is required.\n';
		  }

  if (window.document.nominations_form.nomineeln.value == "") {
		  errors += '- Nominee Last Name is required.\n';
		  }
		  
dropDownErrors = validateDropDowns();
if (dropDownErrors != null && dropDownErrors != '') {
	errors += dropDownErrors;
}		  

  radioErrors = validateRadios();
  if (radioErrors != null && radioErrors != '')  {
    errors += radioErrors;
  }

     if (window.document.nominations_form.NominationType[1].checked) {
//       window.document.nominations_form.textarea.value == "";
       if (window.document.nominations_form.additional.value == "") {
       errors += '- Please fill in the Recommendation area.\n';
       }
     }    

     if (window.document.nominations_form.NominationType[0].checked) {
//       window.document.nominations_form.additional.value == "";
       if (window.document.nominations_form.textarea.value == "") {
       errors += '- Please submit your biography file.\n';
       }
     }    

  if (window.document.nominations_form.submit_by.value == "") {
		  errors += '- Nominator e-mail is required.\n';
		  }
//  checkboxErrors = validateCheckBoxes();
//  if (checkboxErrors != null && checkboxErrors != '') {
//    errors += checkboxErrors;
//  }


  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  
  
  
}

