
// web comments form

function comments (form) {
  var i;
  if (form) {
    // set the form action
    form.action = "/cgi-bin/mail.cgi";
    // add commentor's name to email subject
    if (form.Name_of_commentor && form.Subject && (form.Subject.value.indexOf(" from ")==-1)) form.Subject.value += " from "+form.Name_of_commentor.value;
		// store referring URL in a form field
		if (form.Previous_page) {
			var prevpage = readCookie("comment_referrer");
			if (prevpage.length == 0) prevpage = document.referrer;
			form.Previous_page.value = prevpage;
		}
    // adjust for staging environment
    if (form.tssms && document.URL.indexOf("staging.epa")>-1) {
      i = form.tssms.value.indexOf("m");
      if (i > -1) form.tssms.value = form.tssms.value.substr(0,i)+"d";
			i = form.Next.value.indexOf("http");
			if (i == -1) form.Next.value = "http://staging.epa.gov"+form.Next.value;
    }
    return true;
  }
  else return false;
} 
// web comments link 
// (onclick event handler, smt="send mail to" the comments address)
// 'thelink' parameter is not used
// split up the address in case spam bots are reading this...
function smt (thelink) {
	var a = "to:OAR_COMMENTS";
	var b = "@epa";
	window.location.href = "mail" + a + b + ".gov";
	return false;  // don't follow the clicked link
}
//
// write a cookie: writeCookie("fruit","apple"[,2])
// if parameter 'hours' is omitted, write a session cookie.
// otherwise, write a permanent cookie that expires in 'hours' hours.
function writeCookie(name, value, hours) {
	if ((name != null) && (name.length > 0)) {
		var expire = "";
		if (hours != null) {
			expire = new Date((new Date()).getTime() + hours * 3600000);
			expire = "; expires=" + expire.toGMTString();
		}
		document.cookie = name + "=" + escape(value) + expire;
	}
}
//
// return the value of a cookie: readCookie("fruit")
function readCookie(name) {
	var value = "";
	if ((name != null) && (name.length > 0) && (document.cookie.length > 0)) {
		var srch = name + "=";
		var cbegin = document.cookie.indexOf(srch);
		if (cbegin != -1) {
			cbegin += srch.length;
			var cend = document.cookie.indexOf(";", cbegin);
			if (cend == -1) cend = document.cookie.length;
			value = unescape(document.cookie.substring(cbegin, cend))
		}
	}
	return value;
}

