function buildForm(type) {
  if (type == "prayer") {
      document.write("<p>Please complete the following form.</p><form name='prayerform' method='post' action='asp/sendmail.asp?type=" + type + "' onsubmit='return doValidation(this);'><table border='0' cellspacing='0' cellpadding='0'><tr><td><p>Name (or Alias):&nbsp;</p></td><td><input type='text' id='Name' name='Name' size='30' maxlength='50'/></td></tr><tr><td><p>Email (optional):&nbsp;</p></td><td><input type='text' id='Email' name='Email' size='30' maxlength='50'/></td></tr><tr><td><p>Telephone (optional):&nbsp;</p></td><td><input type='text' id='Tel' name='Tel' size='30' maxlength='50'/></td></tr></table><p>Prayer request:<br /><textarea name='Comments' id='Comments' cols='70' rows='6'></textarea></p><p><input type='submit' value='Submit'/></p><p id='error'></p></form>");
  } else if (type == "contact") {
      document.write("<p>Please complete the following form.</p><form name='contactform' 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/request:<br /><textarea name='Comments' id='Comments' cols='70' rows='6'></textarea></p><p><input type='submit' value='Submit'/></p><p id='error'></p></form>");
  } else if (type == "evite") {
      document.write("<form name='eviteform' 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>Your Email Address:&nbsp;</p></td><td><input type='text' id='Email' name='Email' size='30' maxlength='50'/></td><tr><td><p>Your Friend's Name:&nbsp;</p></td><td><input type='text' id='OtherName' name='OtherName' size='30' maxlength='50'/></td></tr></tr><tr><td><p>Your Friend's Email Address:&nbsp;</p></td><td><input type='text' id='OtherEmail' name='OtherEmail' size='30' maxlength='50'/></td></tr></table><p><input type='submit' value='Submit'/></p><p id='error'></p></form>");
  }
}
function doValidation(f) {
  if (f.name == "prayerform") {
      document.getElementById("Name").setAttribute("required",1);
      document.getElementById("Email").setAttribute("required",0);
      document.getElementById("Tel").setAttribute("required",0);
      document.getElementById("Comments").setAttribute("required",1);
  } else if (f.name == "contactform") {
      document.getElementById("Name").setAttribute("required",1);
      document.getElementById("Email").setAttribute("required",0);
      document.getElementById("Tel").setAttribute("required",0);
      document.getElementById("Comments").setAttribute("required",1);
  } else if (f.name == "eviteform") {
      document.getElementById("Name").setAttribute("required",1);
      document.getElementById("Email").setAttribute("required",1);
      document.getElementById("OtherName").setAttribute("required",1);
      document.getElementById("OtherEmail").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)) {
	    if (e.name == "OtherName") e.name = "Your friend's name";
            if (e.name == "OtherEmail") e.name = "Your friend's email";
            msg = generateErrorMessage(e, " must have an entry.&nbsp;&nbsp;Enter <b>no comment</b> if you do not wish to provide a response.");
            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();}
}
