//                    Opera   FireFox    Netscape     IE
//window.screenX       196      57          57       undef
//window.screenY       170      30          30       undef
//window.scrollX       undef     0           0       undef
//window.scrollY       undef     0           0       undef
//window.screenTop     287      undef      undef     60
//window.screenLeft    205      undef      undef     61
//window.top           undef    undef      undef     undef
//window.height        undef    undef      undef     undef
//window.width         undef    undef      undef     undef
//window.pageXoffset   0        0          0         undef
//window.pageYoffset   0        0          0         undef
//screen.height        1024     1024       1024      1024
//screen.width         1280     1280       1280      1280 
// var bob = "Bob Boynton";
// document.write('<span id="ruler" name="ruler" src="" style="display: none;"></span>');
// var test = true;
var debug_seq = 0;
var debug_marg = 0;
var global_save_rows;
var dom = document;
var win = null;
var win_state = false;
var root = "";
var s = String(location.pathname);	
s = s.toUpperCase();		
var a = s.split("/");	
var MyFlag = false;
var db_seq = 0;
var v, t;
var host;

host = new String(document.location.host);
host = host.toUpperCase();
// Wr("a=" + a + "  host=" + host + " a.length="+a.length);
if (host == "LOCALHOST") {
// if (a[1] == "TONIOLD") {
	root = "/"+a[1]+"/";
  } else {
  	if (a.length < 3) { 
//  		root = "";
		root = "\\"; // "http://www.townofnewipswich.org/";
  	  } else {
//		if (test == false) 		
//			root = "../"
			root = "\\"; // "http://www.townofnewipswich.org/"
//		  else
//			root = "http://townofnewipswich.org/TONIOLD/"
	}
}
var MenuLeft;
var MenuTop;
// *****
function Wr(str) {
//  	Xlert(str);
	document.write(str);
}
// *****
function GetId(idx)
{
return(document.getElementById(idx));
}
// *****	
function GetEventId(e) {
//	Xlert("GetEventId"); // e.type="+e.type);
	e = (e) ? e : ((event) ? event : null);
return(((e.target) ? e.target : ((e.srcElement) ? e.srcElement : null)).id);
}
// *****
function GetIdIx(id, ix) {
return(document.getElementsByName(id)(ix));
}	
// *****
function GetObj(obj, id) {
return(obj.getElementById(id));
}	
// *****
function GetText(idx)
{
return(GetId(idx).innerHTML);		
}
// *****
function GetObjText(obj, idx)
{
return(GetObj(obj, idx).innerHTML);	
}
// *****
function GetListVal(id)
{
var obj = GetId(id);
var ix = obj.selectedIndex;
// Xlert("GetListVal id="+id);
return(obj.options[ix].value);
}
// *****
/*
function SetListIndex(id, val)
{
var ret = 0, ix;
var obj = GetId(id);

for (ix = 0; ix < obj.length; ++ix) {
	if (obj.options[ix].value == val) {
		obj.selectedIndex = ix;		
		return(ret);
	}
}
obj.selectedIndex = 0;		
return(ret);
}
*/
// *****
function GetListText(id)
{
var obj = GetId(id);
var ix = obj.selectedIndex;
return(obj.options[ix].value);
}
// *****
function SetText(id, txt)
{
if (document.all)
	GetId(id).innerText = txt;
  else
	GetId(id).textContent = txt;
// GetId(idx).innerHTML = txt;
return;
}
// *****
function SetObjText(obj, id, txt)
{
if (document.all)
	GetObj(obj, id).innerText = txt;
  else
	GetObj(obj, id).textContent = txt;
// GetObj(obj, idx).innerHTML = txt;
return;
}
// *****
function SetIdText(id)
{
if (document.all)
	GetId(id).innerText = text;
  else
	GetId(id).textContent = text;
return;
}
// *****
function GetVal(id)
{
return(GetId(id).value);
}
// *****
function SetVal(id, val)
{
GetId(id).value = val;
return(val);
}
/*
// *****
function TestThis()
{
// Xlert("TestThis");	
return;
}
*/	
// *****
function QueryURL(sKey) {
// Xlert("skey="+skey);
return(QueryStr(sKey, document.location));
}
// *****
function QueryVal(sKey) {
return(QueryStr(sKey, GetId("qs").value));
}
// *****
function QueryStr(sKey, str) {
	var p1, p2, k = new String(sKey), s = new String(str);

//	Xlert("k="+k+"  s="+s);
	p1 = s.indexOf(k) + k.length + 1;
	p2 = s.indexOf("&", p1);
	if (p2 == -1) 
		p2 = s.length;
//	Xlert(s.substring(p1, p2));
return(s.substring(p1, p2));	
}
// *****
/*
function ToggleObj(hide_id, show_id)
{
document.getElementById(hide_id).style.display = "none";
document.getElementById(show_id).style.display = "block";	
return;
}
*/	
// *****
function ToggleId(id)
{
if (GetId(id).style.display == "none")
	ShowId(id);
  else
	HideId(id);	
return;
}
// *****
function IsDisplay(id)
{
if (GetId(id).style.display == "none")
	return(false)
return(true);
}
// *****
function ToggleObj(hide_id, show_id)
{
HideId(hide_id);
ShowId(show_id);
//document.getElementById(hide_id).style.display = "none";
//document.getElementById(show_id).style.display = "block";	
return;
}	
// *****
function ShowId(id)
{
if (id != null && id != "")
	GetId(id).style.display = "";
// document.getElementById(id).style.display = "";	
return;
}
// *****
function HideId(id)
{
if (id != null && id != "")
	GetId(id).style.display = "none";
//document.getElementById(id).style.display = "none";	
return;
}
// *****
function ChildOnBlur()
{
// win.close();
top.child_win.close();
return;
}
function DoHr(classx)
{
Wr("<table class='" + classx + "' align='center' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>");				
return;
}
// *****
function DoFooter()
{
//Wr("<table cellpadding='0' cellspacing='0' width='100%' style='font-family: Arial;font-size: 12px;padding-top: 8px;'>");
//Wr("<table border='0' cellpadding='0' cellspacing='0' width='780px' align='center' style='color: #666666;font-size: 9px;margin-left: 0px;margin-right: 20px;padding-top: 1px;padding-bottom: 0px;border-top: 0px solid #000000;margin-top: 8px;margin-bottom: 0px;'>");
Wr("<table cellpadding='0' cellspacing='0' align='center' style='color: #666666;font-size: 9px;padding-top: 0px;padding-bottom: 0px;border-top: 1px solid #000000;margin-top: 12px;margin-bottom: 12px;width: 75%;'>");
	Wr("<tr>");
		Wr("<td align='center' style='padding-top: 8px;'>");
/*			if (top.root_exists == true) {
				DoFooterLink("http://www.NewIpswichCC.org", "_top", "Home", "|");			
				DoFooterLink("javascript:scroll(0,0)", "_self", "Top", "|");							
				DoFooterLink("../contact.htm", "rbottom", "Contact Us", "|");											
				DoFooterLink("http://www.GoPCC.com/WebAid.htm", "_blank", "+Web Aid+", "|");																						
				Wr("<br>");
			}				*/
//			Wr("<span style='font-family: Arial;font-size: 7pt;color: #808080;'>");
			Wr("<span align='center' style='font-size: 9px;color: grey;'>Page Last Revised: " + document.lastModified + "</span>");
//			Wr("<br>");
////			Wr("</span>");											
//			Wr("<a href='http://www.gopcc.com' title='Click to contact PC Consultants' target='_blank' style='color: #6565FF;'>");
//				Wr("Web Site by PC Consultants");
//			Wr("</a>");
		Wr("</td>")
	Wr("</tr>");
Wr("</table>"); 
return;
}
// *****
function DoFooter1()
{
var pos; 
var minObj, mnuObj

Wr("<table border='0' cellpadding='0' cellspacing='0' width='100%' align='center' style='padding-top: 8px;'>");
	Wr("<tr>");
		Wr("<td colspan='1' valign='bottom' height='2px'>");
			DoHr("StdHr");
		Wr("</td>");	
	Wr("</tr>");		
	
/*	Wr("<tr>");
		Wr("<td width='100%' align='center'>");
			Wr("<table border='0' cellpadding='0' cellspacing='0' width='100%' align='center'>");
				Wr("<tr>");
					Wr("<td  width='100%' height='16px' valign='bottom' align='center' style='font-size: 12px;'>");
						if (top.is_parent == true)
		 				DoFooterLink("javascript:top.parent.menutop.ExecTab('home.asp')", "_top", "Home Page", "|", "Home", root +"_images/home.png", "18");			
//						DoFooterLink("javascript:DoHome();", "_top", "Home Page", "|", "Home", root +"_images/home.png", "16");			
						DoFooterLink("javascript:scroll(0,0)", "_self", "Top-of-Page", "|", "Top", root + "_images/TopArrow.gif", "17");						
//						DoFooterLink("javascript:history.back(-1);", "_self", "Previous Page", "|", "Back", root + "_images/Back.gif", "17");															
						DoFooterLink("http://www.GoPCC.com/WebAid.htm", "_blank", "Report Web Site Problems", "|", "WebAid", root +"_images/webaid.gif", "16");									
						DoFooterLink("mailto:Webmaster@TownOfNewIpswich.org;Administrator@TownOfNewIpswich.org", "_blank",  "Click this link to offer suggestions and other feedback about our web site","|", "Feedback", root +"_images/email.gif", "0");															
					Wr("</td>");			
				Wr("</tr>");
			Wr("</table>");		
		Wr("</td>");	
	Wr("</tr>"); */
	
	Wr("<tr>");
//		Wr("<td width='100%' align='center'>");	
//			Wr("<table border='0' cellpadding='0' cellspacing='0' width='100%' align='center'>");
//				Wr("<tr>");	
					Wr("<td width='100%' align='center' height='16px' valign='top' style='padding-left: 8px;font-family: Arial;font-size: 9px;color: #808080;'>");							
						if (root != "/TONIOLD/")
							pfx = "http://www.TownOfNewIpswich.org/";
						  else
						  	pfx = "";	
						Wr(pfx + document.location.pathname);						
						Wr(" last modified on " + document.lastModified);
					Wr("</td>");						
//				Wr("</tr>");	
//			Wr("</table>");						
//		Wr("</td>");	
	Wr("</tr>");			
Wr("</table>"); 

//Wr("</td></tr></table>");
//Wr("</div>");
return;
}
// *****
function DoFooterLink(linkx, targetx, titlex, sep, textx, img, size)
{
	
Wr('<a href="' + linkx + '" target="' + targetx + '" title="' + titlex + '">');
//	if (size != "0")
//		Wr('<img src="' + img + '" height="' + size + 'px" width="' + size + 'px" align="absmiddle" hspace="2" style="font-size: 9px;border: 0px;">');	
//	  else	
//		Wr('<img src="' + img + '" align="absmiddle" hspace="2" style="font-size: 9px;border: 0px;">');		  	
////	Wr(titlex);	
	Wr(textx);	
Wr('</a>');	
Wr("<span style='font-size: 12px;color: #800000;font-weight: normal;'>&nbsp;&nbsp;" + sep +"&nbsp;&nbsp;</span>");
return;
}
// *****
function NavBottom()
{
var msg = "Go to BOTTOM of page"; 

Wr('<a href="javascript:scroll(9999,9999)" title="' + msg + '" style="font-size: 10px;">');
//	Wr('<img src="' + root + '_images/BottomArrow.gif" hspace="2" align="middle" title="' + msg + '" style="border: 0px">');
	Wr('Bottom');
Wr('</a>');	

return;
}	
// *****
function NavTop()
{
var msg = "Go to TOP of page"; 

Wr('<a href="javascript:scroll(0,0)" title="' + msg + '" style="font-size: 10px;">');
//	Wr('<img src="' + root + '_images/TopArrow.gif" hspace="2" align="middle" title="' + msg + '" style="border: 0px">');
	Wr('Top');
Wr('</a>');	
return;
}
// *****
function ExecLink(linkx)
{
var ix, urlx, new_win = true, new_site = false;

// Xebugger;
s = new String(linkx);
x = s.toUpperCase();

window.onfocus = ChildOnBlur;
urlx = s;		

if (x.indexOf("HTTP:") == -1) {
	if (x.indexOf(".PDF") == -1) {   	
		new_win = false;		
		urlx = rt + urlx;
	  } else {
		urlx = rt + urlx;		
	}		
  } else {
  	new_site = true;
}  	 	
sw = SetChildWinSize(urlx, 1) 
if (new_win == true) {
	if (new_site == false) {
		OpenWin(urlx, sw, "");		
      } else { 	
		OpenWin(urlx, sw, ",scrollbars=yes");			   	
	}		
  } else {
	document.location = urlx;	    
}  	 		
return;
}
// *****
function DoSound(sound, loop)
{
// Xlert("DoSound sound="+sound+"  "+loop);
GetId("sound").loop = loop;	
GetId("sound").src = root + "_sounds/" + sound;	
return;
}
/*	
// *****
function SetSessionVar(sess_var, val)
{
request = CreateRequest();	
urlx = "SetSessionVar.asp?val=" + val;
// RequestData(urlx, false, ReturnScreenInfo);
RequestData(urlx, false, null);
return;
}
*/
/*
// *****
function SetScreenInfo() 
{
var urlx;

request = CreateRequest();	
urlx = "SetScreenInfo.asp?height=" + screen.height + "&width="+screen.width;
RequestData(urlx, true, ReturnScreenInfo);
return;	 
}
// *****
function ReturnScreenInfo() 
{
var arrData; 
arrData = GetData();
return;	
}
*/
// *****
function ForEach(obj)
{
var x;	

//	Xlert("ForEach");

/*
for (x in obj) {
	Xlert(x+"="+obj[x]);			
}
*/	 
return;
}		
// *****
function db(str) {
    var ROWS = "15";
    var ct = "";
    var view = GetObj(top.debug.document, "View");

    if (top.debug.frameElement.src == "") // no debug frame available!
        return;

    if (str == null) {
        HideDebug();
        return;
    }

    if (debug_seq == 0) {
        view.rows = ROWS;
        ShowDebug();
    }

    ++debug_seq;
    ct = LPad(debug_seq, 5, "0") + ": ";
    view.value = ct + str + "\n" + view.value;
    return;
}
// *****
function HideDebug() {
    var arr = top.FrameSet1.rows.split(",");

    arr[top.frames.length - 1] = "0";
    top.FrameSet1.rows = arr.join(",");
    return;
}
// *****
function ShowDebug() {
    var arr = top.FrameSet1.rows.split(",");

    arr[top.frames.length - 1] = "400";
    top.FrameSet1.rows = arr.join(",");
    return;
}
// *****
function PixelWidth(elem, str, classx)
{
/*
dom = document;
var obj = document.createElement(elem);
*/
var width = 0, p, s;
/*
// document.body.appendChild(obj);
switch (elem) {
	case "IMG":                 // img tag
//		Xebugger;
		obj.src = str;          // set image source to this string
//		dom.body.appendChild(obj);      // add obj to dom 
		width = obj.scrollWidth;
//		dom.body.removeChild(obj);
		width = 160;
//		xlert("5 PixelWidth elem=" + elem + "  width="+obj.width);
		break;
	default:                    // span tag, etc.
		obj = dom.createElement("td");
		dom.body.appendChild(obj);      // add obj to dom 
		obj.className = classx;
		obj.innerText = str;	// set inner text to this string
//		obj.innerHTML = "<div>" + str + "</div>"
//		width = str.length;
		break;
}
*/
return(width);					// return width in pixels
}
function IsHTA() { return document.location.href.toUpperCase().indexOf(".HTA") != -1 ? true : false; }
function CacheThisImage(url) { var img = new Image(); img.src = url; return (img); }
function GetRect(id) { return (new GetObjRect(document, id)); }
// *****
function GetObjRect(doc, id) {
    var r = { top: 0, left: 0, bottom: 0, right: 0 };
    var r1, obj1;
    var obj = doc.getElementById(id);

    var pos = new Array(4), parentNode;

    pos[0] = 0;
    pos[1] = 0;

    var bl = px(obj.style.borderLeftWidth);
    var bt = px(obj.style.borderTopWidth);
    var ml = px(obj.style.marginLeft);
    var mt = px(obj.style.marginTop);
    var pl = px(obj.style.paddingLeft);
    var pr = px(obj.style.paddingRight);
    var pt = px(obj.style.paddingTop);
    var pb = px(obj.style.paddingTop);

    if (top.is_ie == true) {
        r = obj.getBoundingClientRect();
        return (r);
    }

    if (top.is_ff == true) {
        r1 = obj.getBoundingClientRect();
        r.top = r1.top - pt + bt;
        r.left = r1.left; //  - pl + bl;
        r.bottom = parseInt(r1.bottom) - ((pt + pb) - mt);
        r.right = parseInt(r1.right); //  - (pl + pr) - ml;
        return (r);
    }

    r = [obj.offsetLeft, obj.offsetTop];
    pos = [obj.offsetLeft, obj.offsetTop];
    parentNode = obj.offsetParent;
    if (parentNode != obj) {
        while (parentNode) {
            pos[0] += parentNode.offsetLeft;
            pos[1] += parentNode.offsetTop;
            parentNode = parentNode.offsetParent;
        }
    }

    if (obj.parentNode)
        parentNode = obj.parentNode;
    else
        parentNode = null;

    while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML') { // account for any scrolled ancestors
        if (parentNode.parentNode)
            parentNode = parentNode.parentNode;
        else
            parentNode = null;
    }

    r.top = pos[1];
    r.left = pos[0];
    r.bottom = r.top + obj.clientHeight; //  - (pt + pb);
    r.right = r.left + obj.clientWidth; //  - (pl + pr); */

    return (r);
}
// *****
function px(val) {
    var v = val.replace(/px/, "");

    v == "" ? v = 0 : v = parseInt(v);
    //if (v == "")
    //    v = 0
    //  else
    //  v = parseInt(v);
    return (v);
}
// *****
function A(tag, val) {
    var s;
    switch (tag.substr(tag.length - 1, 1)) {
        case "=":
            s = tag + "'" + val + "' "
            break;
        case ":":
            s = tag + " " + val + ";"
        default:
            alert("A: Invalid " + tag + "!");
            break;
    }
    return (s)
}
// *****
function GetToId(evt) {
    var toElem = GetToElem(evt);
    var toId = null;

    if (toElem != null)
        toId = toElem.id;
    return (toId);
}
/*
// *****
function GetToElem(evt) {
    var toElem = null;

    if (IsIE() == true)
        toElem = evt.toElement;
    else
        toElem = evt.relatedTarget;
    return (toElem);
}
*/
// *****
function GetFromId(evt) 
{
if (top.IsIE() == true) {
    if (evt.fromElement != null)
        return (evt.fromElement.id);
  } else {    
    if (evt.relatedTarget != null)
        return(evt.relatedTarget.id);
}   
return(null);
}
// *****
function GetToId(evt) 
{
if (top.IsIE() == true) {
    if (evt.toElement != null)  
        return (evt.toElement.id);
  } else {
    if (evt.target != null)
        return (evt.target.id);
}
return(null);
}
