  var downStrokeField;
  function autojump(fieldName,nextFieldName,fakeMaxLength)
  {
    var myForm=document.forms[document.forms.length - 1];
    var myField=myForm.elements[fieldName];
    myField.nextField=myForm.elements[nextFieldName];
    if (myField.maxLength == null)
    myField.maxLength=fakeMaxLength;
    myField.onkeydown=autojump_keyDown;
    myField.onkeyup=autojump_keyUp;
  }
  
  function autojump_keyDown()
  {
    this.beforeLength=this.value.length;
    downStrokeField=this;
  }
  
  function autojump_keyUp()
  {
    if (
    (this == downStrokeField) &&
    (this.value.length > this.beforeLength) &&
    (this.value.length >= this.maxLength)
    )
    this.nextField.focus();
    downStrokeField=null;
  }
  
  function openWindow(URL)
  {
    //var availWidth = screen.availWidth + 1;
    //var availHeight = screen.availHeight;
    var availWidth = 400;
    var availHeight = 200;
    var x = 0, y = 0;
    if (document.all) {
      x = window.screenTop;
      y = window.screenLeft;
    }
    else if (document.layers) {
      x = window.screenX;
      y = window.screenY;
      availWidth = availWidth - 11;
      availHeight = availHeight - 155;
    }
    var arguments =
    'resizable=yes,toolbar=no,location=no,directories=no,addressbar=no,scrollbars=no,status=no,menubar=no,top=100,left=100,screenX='+x+',screenY='+y+',width='+availWidth+',height='+availHeight;
    var newWindow = window.open(URL,'_blank',arguments);
  }

  // Returns true if the string only contains alpha characters (empty string = true)
  function isAlpha(txt)
  {
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
  }

  // Returns true if the string only contains numeric characters (empty string = true)
  function isNumeric(txt)
  {
	return ValidString(txt,'0123456789');
  }

  // Returns true if the string only contains alpha numeric characters (empty string = true)
  function isAlphaNumeric(txt)
  {
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
  }

  // Returns true if the CheckString only contains characters passed in ValidString (empty string = true)
  function ValidString(ChkString,ValidString)
  {
	for (i=0; i<ChkString.length; i++)
	{
		if (ValidString.indexOf(ChkString.substring(i,i+1)) == -1) return false;
	}
	return true;
  }
  
  function okPermNotam(elem, helperMsg)
  {
    var ok = true;
      
	if(elem.value.length == 0)
	{
	  ok = false;
	}else
	if (!isNumeric(elem.value))
	{
	  ok = false;
	}else
	{
	  ok = true;
	}  
	if (ok)
	{
	  return true;
	}else
	{
	  alert(helperMsg);
	  elem.focus();
	  return false;
	}  
  }
  
  function validateOnChange(x) 
  {
      //var textfield = document.getElementById(x);           // the textfield
      var value = x.value;                          // the user's input

      // If the value does not match the pattern set the class to "adinput_invalid".
      //if (value.search(pattern) == -1) textfield.className = "adinput";
      if (isAlpha(value)) x.className = "adinput";
      else x.className = "adinput_invalid";
  }
  
  function validateOnChange_numbers(x)
  {
      var value = x.value;                          // the user's input

      if (isNumeric(value)) x.className = "adinput";
      else x.className = "adinput_invalid";
  }  
  
  function testNumber(x)
  {
    var y=document.getElementById(x).value;
    validateOnChange_numbers(document.getElementById(x));
  }
  
  function upperCase(x)
  {
    var y=document.getElementById(x).value;
    document.getElementById(x).value=y.toUpperCase();
    validateOnChange(document.getElementById(x));
  }
  
  function endValidating()
  {
    alert("The form is incompletely or incorrectly filled out.\n" +
          "Please correct the  highlighted fields and try again.");
    return false;
  }          
  
  function test_field(e)
  {
    if (e.type == "text") 
    {
      e.onchange(); // Invoke the handler to re-validate
      // If validation fails for the element, it fails for the form
      if (e.className == "adinput_invalid")
      {
        return false;
      }else
      {
        return true;
      }    
    }else
    {
      return true;
    }  
  }
  
  
  function validateADs_FIRs_onSubmit()
  {
     // Loop through all form elements
     for(var i = 1; i < 7; i++) 
     { 
         if (!test_field(document.getElementById("FIR"+i)))
         {
           return endValidating();
         }
     }
     
     for(var i = 1; i < 19; i++) 
     {
         if (!test_field(document.getElementById("AED"+i)))
         {
           return endValidating();
         }
     }
     
     if (!test_field(document.getElementById("PermNOTAM")))
     {
       return endValidating();
     }
  }    

  function ADs_FIRs_Reset()
  {
    for(var i = 1; i < 7; i++) 
     {
         var e = document.getElementById("FIR"+i);
         e.className = "adinput";
         e.value = "";
     }
     
     for(var i = 1; i < 19; i++) 
     {
         var e = document.getElementById("AED"+i);
         e.className = "adinput";
         e.value = "";
     }
     
     document.getElementById("PermNOTAM").className = "adinput";
  }

  function set_resetform_field()
  {
    var e = document.getElementById("resetform");
    //alert("Hidden field resetform has now value: "+e.value);
    e.value = "true";
    //alert("Hidden field resetform has now value: "+e.value);
  }
  	
  function validate_NRB_onSubmit()
  {
     // Loop through all form elements
     for(var i = 1; i < 5; i++) 
     {
         if (!test_field(document.getElementById("ALTN"+i)))
         {
           return endValidating();
         }
     }
     
     if (!test_field(document.getElementById("DEP")))
     {
       return endValidating();
     }
     if (!test_field(document.getElementById("DEST")))
     {
       return endValidating();
     }
     if (!test_field(document.getElementById("PermNOTAM")))
     {
       return endValidating();
     }
  }

  function NRB_Reset()
  {
    for(var i = 1; i < 5; i++) 
     {
         var e = document.getElementById("ALTN"+i);
         e.className = "adinput";
     }
     
     var e = document.getElementById("DEP");
     e.className = "adinput";
     e = document.getElementById("DEST");
     e.className = "adinput";
     document.getElementById("PermNOTAM").className = "adinput";
  }
  
  
  function validateAD_FIR_onSubmit()
  {
     
     if (!test_field(document.getElementById("FIR1")))
     {
       return endValidating();
     }
     if (!test_field(document.getElementById("AED1")))
     {
       return endValidating();
     }
     if (!test_field(document.getElementById("PermNOTAM")))
     {
       return endValidating();
     }
  }    
  
  
  function AD_FIR_Reset()
  {
     var e = document.getElementById("FIR1");
     e.className = "adinput";
     var e = document.getElementById("AED1");
     e.className = "adinput";
     document.getElementById("PermNOTAM").className = "adinput";
  }

  function switchDIV(divid)
  {
  	 var divstyle = document.getElementById(divid).style;
  	 divstyle.display = divstyle.display? "":"block";
  }
  
  function showhide(linkid, divid) 
  {
     linktext = new String(document.getElementById(linkid).innerText);
     hidevar = "[hide]"; 
     showvar = "[show]"; 
     switchDIV(divid); 
     if (linktext == showvar) 
     {
        document.getElementById(linkid).innerText = hidevar; 
     } else if (linktext == hidevar) 
     {
        document.getElementById(linkid).innerText = showvar;
     }
  }  