//get string for relative path
//var pagepath = self.location.pathname.toLowerCase()
//pathstr = ""

//if there is only one slash, this is the root directory
//if (pagepath.indexOf("/", 1) < 0) {
//    var pathstr = ""
//} else {
//    //get number of slashes
//    var parts = pagepath.split("/")
//    for (i = 0; i < parts.length - 2; i++) {
//        pathstr = pathstr + "../"
//    }
//}

//pagepath = self.location.href.toLowerCase()

function getWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth
}

//validate email address
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "This is not a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

//check for handling of innerText
function putText(elem, str) {
	var hasText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
	if (hasText) {
		elem.innerText = str
	} else {
		elem.textContent = str
	}
}

//new window with url
function popSite(url) {
      popWin2=window.open(url,"newwin",'toolbar=1,location=1,menubar=1,scrollbars=1,width=700,height=550,resizable=1 ,top=50left=50')
      popWin2.focus()
      popWin2.close
}

//===========================================get XMLHTTP object ready
//used on every page that calls ajax routines
function GetXmlHttpObject(){
	var xmlHttp;
    try{    
  	    // Firefox, Opera 8.0+, Safari    
        xmlHttp=new XMLHttpRequest();
    } 
    catch(e){    // Internet Explorer    
  	    try{      
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch(e){
		    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
    }
	return xmlHttp;
}

//************************ old scripts below***********************************

//define menu items
//arrays of filenames (from root directory) and menu display text
menulinks = new Array ("index.shtml","news/news.html","gmaps/gmaps.html","membership/membership.html","events/events.asp",
	"album.asp","links.html","membership/signup.html","store/store.html","index.shtml#Contacts")
menutext = new Array ("Home","News","Maps","Help Us","Events","Album","Links","Join","Store","Contact")

//number of columns for formatting page headings
var ncols = menulinks.length
var colwidth = 100/ncols

//highlight menu items on mouseover
function flipSwitch(mode,cell) {
	if (mode == 1) {
		color1 = "#D50000"
		color2 = "lime"
	} else {
		color1 = "#990000"
		color2 = "#3A5137"
	}
	cell.style.backgroundColor = color1
	cell.style.borderColor = color2
}


//display menu
//relpath = path to root from page, thispage = current menu text, ptitle = title to use of not menu text
//tier=1 if this is a lower tier page do the link back to the first tier page should be active
function showMenu(relpath,thispage,ptitle,tier) {
	if (!ptitle) {
		ptitle = thispage
	}
	document.write('<TABLE cellpadding="2" cellspacing="1" border="0" ID="mainmenu">')
	document.write('<TR><TD colspan="'+ncols+'" class="head1"><A href="'+relpath+'index.shtml" TARGET="_top"' 
			+ ' onMouseOver="document.all.mt.style.filter=\'glow(strength=6, color=orange)\'"'
			+ ' onMouseOut="document.all.mt.style.filter=\'none\'">'
			+ '<IMG src="' + relpath + 'images/Logo143.gif" alt="Montour Trail Home" border="0" align="left" ID="mt"></A>'
			+ 'The Montour Trail<BR><DIV class="head2">' + ptitle + '</DIV></TD></TR><TR>')
	for (i=0; i<ncols; i++) {
		if (menutext[i] == thispage) {
			if (!tier) {
				document.write('<TH CLASS="current">'+menutext[i]+"</TH>")
			} else {
				document.write('<TH CLASS="current"><A HREF="'+relpath+menulinks[i]+'" TARGET="_top">'+menutext[i]+"</A></TH>")
			}
		} else {
			document.write('<TH WIDTH="' + colwidth + 
			'%" onMouseOver="flipSwitch(1,this)" onMouseOut="flipSwitch(0,this)"><A HREF="'+relpath+menulinks[i]+'" TARGET="_top">'+menutext[i]+"</A></TH>")
		}
	}
	document.write("</TR>")

}


//popup windo with url
var wsize = window.screen.width
function popFeature(pg, w, h) {
      var top=100
      var left = (wsize-w)/2		//autocentering
      popWin2=window.open(pg,"msgwin",'toolbar=1,location=0,menubar=1,scrollbars=1,width='+w+',height='+h+',resizable=1 ,top='+top+',left='+left)
      popWin2.focus()
      popWin2.close
}

//fully generated popup
function popUp(url) {
	popWin=window.open("","newWin",'toolbar=0,location=0,menubar=0,scrollbars=1,width=800,height=600,resizable=1')
	popWin.document.write("<HTML><HEAD><TITLE></TITLE></HEAD><BODY>")
	popWin.document.write("<CENTER><IMG SRC='"+url+"'></CENTER>")
	popWin.document.write("<BR><A HREF='javascript:self.close()'>Close Window</A>")
	popWin.document.close()
	popWin.focus()
}

