// Validate the form.
function validateForm (form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];
	var foundTRW = false;
	var foundNGC = false;
    if (el.type == 'text' || el.type == 'textarea' ||
        el.type == 'password' || el.type == 'file' ) { 
		
		if (el.value == '' && el.name == 'keyword') {
            alert("Please enter a search string");
            el.focus();
            return false;
          }
        if (el.value == '' && (el.name == 'email' || el.name == 'Email')) {
            alert("Please enter an email address");
            el.focus();
            return false;
        }
		
		if (el.value.toLowerCase().indexOf('@trw.com') >= 0) {
		   foundTRW = true;
		}
		if (el.value.toLowerCase().indexOf('@ngc.com') >= 0) {
		   foundNGC = true;
		}	
		if (el.name == 'email' || el.name == 'Email') {
			if (!foundTRW && !foundNGC){
			    alert("Please enter a valid Northrop Grumman email address");
	            el.focus();
	            return false;
			}
		}	 
        if (el.value == '') {
       	    alert('Please fill out the text field ' + el.name);
		    //if (e1.name == 'ReviewSite.ApprvdWebmasterName') {
			//alert('Please fill out the text field webmaster text field');
		    //} else {
			  //alert('Please fill out the text field ' + el.name);
		    //}
            el.focus();
            return false;
        }
    }
	
    else if (el.type.indexOf('select') != -1) {
      //if (el.selectedIndex == -1) {
 		  if (el.value == '') {
        alert('Please select a value of the select field ' + el.name);
        el.focus();
        return false;
      }
    }
    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked) {
        alert('Please check one of the radio buttons ' + el.name);
        el.focus();
        return false;
      }
    }
    else if (el.type == 'checkbox') {
      var group = form[el.name];
      if (group.length) {
        var checked = false;
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
        if (!checked) {
          alert('Please check one of the checkboxes ' + el.name);
          el.focus();
          return false;
        }
      }
    }
  }
  return true;
}

function daw(url) {
//detect-and-warn, author: Sam Fishman, 12/2002
//sets requirement of IE on Windows. Alerts user if they don't have this browser.
//USAGE: 
//  1- <a href="/my/destination.htm" onClick="daw('/my/destination.htm');return false">link text</a>
//  2 - menu item links in CMT:
//        javascript:daw('/my/destination.htm')
//        set link to type "remote"; relative paths ok, but start at /
  if (!(navigator.platform.indexOf("Win") > -1) || !(navigator.appName.indexOf("Internet Explorer") > -1)) {
    alert("This feature only available on Internet Explorer for Windows");
    return false;
  }
  document.location = url;
}  

