function buildForm(type) {
  document.write("<p>Please complete the following form.</p><form name='contactus' method='post' action='asp/sendmail.asp?type=" + type + "'  onsubmit='return doValidation(this);'><table border='0' cellspacing='0' cellpadding='0'><tr><td><p>Name:&nbsp;</p></td><td><input type='text' id='Name' name='Name' size='30' maxlength='50'/></td></tr><tr><td><p>Email:&nbsp;</p></td><td><input type='text' id='Email' name='Email' size='30' maxlength='50'/></td></tr><tr><td><p>Telephone:&nbsp;</p></td><td><input type='text' id='Tel' name='Tel' size='30' maxlength='50'/></td></tr></table><p>Questions/comments/requests:<br /><textarea name='Comments' id='Comments' cols='70' rows='6'></textarea></p><p><input type='submit' value='Submit'/></p><p id='error'></p></form>");
}
function doValidation(f) {
  document.getElementById("Name").setAttribute("required",1);
  document.getElementById("Email").setAttribute("required",0);
  document.getElementById("Tel").setAttribute("required",0);
  document.getElementById("Comments").setAttribute("required",1);
  var result = validate(f);
  if (result) return true;
  //document.getElementById("error").innerHTML = result;
  return false;
}
function validate(f) {
  var msg = "";
  for (var i=0; i < f.length; i++) {
    var e = f.elements[i];
    if (e.style.backgroundColor) e.style.backgroundColor = "white";
    // Required field
    var required = e.getAttribute("required");
    // WORKS FOR BOTH IE and MOSAIC BROWSERS
    if (required == 1) {
        if (!isEntry(e)) {
            msg = generateErrorMessage(e, " must have an entry");
            break;
        }
    }
  }
  if (!msg) return true;
  document.getElementById("error").innerHTML = msg;
  return false;
}
function isEntry(e) {
  var entryExp=/./;
  if (entryExp.test(e.value)) return true;
  return false;
}
function getParam(queryString, parameterName) {
	var parameterName = parameterName + '='; 
	if (queryString.length > 0) {
		begin = queryString.indexOf (parameterName);
		if ( begin != -1 ) { 
			begin += parameterName.length; 
			end = queryString.indexOf ('&' , begin); 
			if ( end == -1 ) { end = queryString.length; }
			return unescape ( queryString.substring (begin, end) ); 
		}
		return "null";
	} else {
           	return "null";
	}
}
function generateErrorMessage(e, str) {
  e.style.backgroundColor = "orangered";
  return (e.name + str + "\n");
}
function windowpopup(url, hheight, wwidth) {
  var left = (screen.width - wwidth) / 2;
  var top = (screen.height - (hheight - 50)) /2;
  var newwindow;
  newwindow = window.open(url,'name','height='+hheight+',width='+wwidth+',left='+left+',top='+top+',resizable=no,scrollbars=no,toolbar=no,status=no');
  if (window.focus) {newwindow.focus();}
}
