// javascript functions for the publications form

  function addPI() {
    var piList = document.form1.list_pis.value
    var piName = document.form1.pi_name.value
    var piAffil = document.form1.pi_affiliation.value
    var piEmail = document.form1.pi_email.value
    var piPhone = document.form1.pi_phone.value
    var numPIs = parseInt(document.form1.num_pis.value)
    numPIs++
    piList = piList + numPIs + ". " + piName + " (" + piAffil + ") (" + piEmail + ") (" + piPhone + ")\n"
    document.form1.list_pis.value = piList
    document.form1.num_pis.value = numPIs
    document.form1.pi_name.value = ""
    document.form1.pi_affiliation.value = ""
    document.form1.pi_email.value = ""
    document.form1.pi_phone.value = ""
    document.form1.pi_name.focus()
  }
  
  
  function delPI() {
    var numPIs = parseInt(document.form1.num_pis.value)
    var delPINum = parseInt(document.form1.del_pi_num.value)
    if (delPINum < 0) {
      document.form1.del_pi_num.value = ""
      alert ("Sorry, but negative numbers aren't allowed.")
    }
    else if (delPINum <= numPIs) {
      var piList = document.form1.list_pis.value
      var replacePI = eval("/"+delPINum+"[.].+\\n/")
      piList = piList.replace(replacePI, "")
      for (var i=delPINum+1; i<=numPIs; i++) {
        var j=i-1
        piList = piList.replace(i, j)
      }
      document.form1.list_pis.value = piList
      document.form1.del_pi_num.value = ""
      numPIs--
      document.form1.num_pis.value = numPIs
    }
    else {
      if (numPIs == 0) {
        alert ("Sorry, but there are no names listed yet.")
      }
      else if (numPIs == 1) {
        alert ("Sorry, but there is only one name listed.")
      }
      else {
        alert ("Sorry, but there are only "+numPIs+" names listed.")
      }
      document.form1.del_pi_num.value = ""
    }
  }
  
  
  function clearPIs() {
    document.form1.list_pis.value = ""
    document.form1.num_pis.value = 0
  }
	
	
	
	function limitText(limitField, limitCount, limitNum) {
		with (document.form1) {
			if (limitField.value.length > limitNum) {
				limitField.value = limitField.value.substring(0, limitNum);
			} 
			else {
				limitCount.value = limitNum - limitField.value.length;
			}
		}
	}
	
	function clearField(def_val, caller_id) {
	
		var caller = new Object();
		caller = eval("document.forms[0]."+caller_id);
		
		if (caller.value == def_val) {
			caller.value = "";
		}
		
		return;
	
	}


	function checkSend() {
		
		with (document.form1) {
			
			if (realname.value == "") {
				alert("Please enter your name.");
				realname.focus();
				return;
			}
			
			if (affiliation.value == "") {
				alert("Please enter your affiliation information.");
				affiliation.focus();
				return;
			}
			
			if (email.value == "") {
				alert("Please enter your email address.");
				email.focus();
				return;
			}
			
			if (phone.value == "") {
				alert("Please enter a phone number where you may be reached.");
				phone.focus();
				return;
			}
			
			if (project_name.value == "") {
				alert("Please enter a name for your project.");
				project_name.focus();
				return;
			}
			
			if (collaborators.value == "") {
				alert("Please enter the names of the collaborating entities for your project.");
				collaborators.focus();
				return;
			}
			
			if (sponsors.value == "") {
				alert("Please enter the namesof of your sponsors.");
				sponsors.focus();
				return;
			}
			
			if (justification.value == "") {
				alert("Please describe your research goals and objectives.");
				justification.focus();
				return;
			}
			
			if (start_month.value == ""||start_day.value == ""||start_year.value == "") {
				alert("Please enter the proposed start date for your project.");
				start_month.focus();
				return;
			}
			
			if (isNaN(start_month.value)||isNaN(start_day.value)||isNaN(start_year.value)) {
				alert("Please enter the proposed start date for your project. (numerical values only)");
				start_month.focus();
				return;
			}
			
			if (end_month.value == ""||end_day.value == ""||end_year.value == "") {
				alert("Please enter the proposed end date for your project.");
				end_month.focus();
				return;
			}
			
			if (isNaN(end_month.value)||isNaN(end_day.value)||isNaN(end_year.value)) {
				alert("Please enter the proposed end date for your project. (numerical values only)");
				end_month.focus();
				return;
			}
			
			if (duration.value == "") {
				alert("Please enter the expected duration of each data collection event.");
				duration.focus();
				return;
			}
			
			if (wx_dependent_info.value == "") {
				alert("Please answer the question regarding the weather dependency of your data collection requirements.");
				wx_dependent_info.focus();
				return;
			}
			
			if (after_hours[0].checked && afterhours_info.value == "") {
				alert("Please describe your requirements for after-hours or weekend access to the NWRT.");
				afterhours_info.focus();
				return;
			}
			
			if (participating[0].checked && !(location[0].checked) && !(location[1].checked)) {
				alert("Please indicate whether you plan to be onsite for data location.");
				location[0].focus();
				return;
			}
			
			if (!(data_type[0].checked) && !(data_type[1].checked)) {
				alert("Please select the type(s) of data that you will be collecting.");
				data_type[0].focus();
				return;
			}
			
			if (scan_strategy.value == "") {
				alert("Please describe your planned scanning strategies.");
				scan_strategy.focus();
				return;
			}
			
			if (signal_proc_changes[0].checked && signal_proc_info.value == "") {
				alert("Please describe your requirements for signal processing software changes.");
				signal_proc_info.focus();
				return;
			}
			
			if (special_equip[0].checked && special_equip_info.value == "") {
				alert("Please describe your requirements for special external equipment or data streams.");
				special_equip_info.focus();
				return;
			}
			
			submit();
			
		}
	
	}