/*
|-------------------------------------------|
|Title: "Open-In-Frames Javascript Solution"|
|Written By: Adam Eshleman                  |
|Date: 9/2/04                                |
|Copyright: Gannett Fleming                 |
|-------------------------------------------|
This is one of the three necessary files you need to have in place on your website
to have the "Open-In-Frames Javascript Solution" to function. The complete list of files
is as follows:

1. frame-it.js
2. allow-list.js
3. search-links.htm

The configuration of these files is as follows:

1.  Make sure all three files are located in the root of your website.

2.  The page with the links you want to affect should look something like this.
	(*'s represent the lines of code you need to place)

	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>Untitled Document</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
****<script language="JavaScript" src="allow-list.js"></script>****
****<script language="JavaScript" src="frame-it.js"></script>****
	</head>
****<body onLoad=CaptureLinkAlternate()>****
-----------------------------------------------------------------------------

*Comments for this file*
frame-it.js contains 3 functions (FrameIt, GetDomain, CaptureLink) dedicated 
to opening another web document in frames.  The primary function, FrameIt, does
have some editable content.  Just look for the "Begin Editable" and "End Editable"
comments.
*/

var IsFrameIt
var ua = navigator.userAgent.toLowerCase();   
var MyBrowser

if (ua.indexOf('msie') != -1){
	MyBrowser = "Explorer"
}else{
	MyBrowser = "Netscape"
}

if (MyBrowser == "Explorer"){
	document.onmousedown = 
	function () {
	  if(event.button == 2){
		try{
			event.srcElement.href = GetURL(event.srcElement.href)
		}
		catch(e){
			//do nothing
		}
	  }
	  if(event.button == 1){
		try{
			CaptureLinkAlternate()
		}
		catch(e){
			//do nothing
		}
	  }
	}
}
if (MyBrowser == "Netscape"){
  document.onmousedown = function (evt) {
	  if(evt.button == 2){
		try{
			evt.target.href = GetURL(evt.target.href)
		}
		catch(e){
			//do nothing
		}
	  }
	  if(evt.button == 0){
		try{
			CaptureLinkAlternate()
		}
		catch(e){
			//do nothing
		}
	  }
    }
}

function FrameIt(MyURL){
	var i
	
	var SourceDomain = GetDomain(String(document.location))
	var TargetDomain = GetDomain(String(MyURL))
	
	if (SourceDomain == TargetDomain){
		window.location.href = MyURL
		return
	}
			
	for (i = 0; i < MyAllowList.length; i++) {
		
		if (MyAllowList[i] == MyURL) {
			window.location.href = MyURL
			return
		}
	}
		
	document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>")
	document.write("<HTML>")
	document.write("<head>")
//Begin Editable\\
//This can also be adjusted for whatever websites you use this function set in.	
	document.write("<title>PA Greenways</title>")
//End Editable\\
	document.write("</head>")
	document.write("<!-- frames -->")
	document.write("<frameset  rows='75,*'>")
//Begin Editable\\
//You can edit the src(source) of fraTop, if you are using a different page
//to show the links in the top frame.	
	document.write("<frame name='" + MyURL + "' src='search-links.htm' marginwidth='0' marginheight='0' scrolling='no' frameborder='YES' noresize>")
//End Editable\\
	document.write("<frame id='fraContent' name='fraContent' src='" + MyURL + "' marginwidth='0' marginheight='0' scrolling='auto' frameborder='0'>")
	document.write("<noframes>This page uses frames, which your browser doesn't support.</noframes>")
	document.write("</frameset>")
	document.write("</html>")
}

function CaptureLink(){
	var z
		
	for (z = 0; z < document.links.length; z++) {
		if (window.event.srcElement.href == document.links[z] && window.event.srcElement.href.substring(0,7) == "http://"){
			if (window.event.srcElement.href.substring(window.event.srcElement.href.length - 1, window.event.srcElement.href.length) == "#"){
				return
			}
			FrameIt(window.event.srcElement.href)
			return
		}
	}
}

function CaptureLinkAlternate(){
	var a
	var i
	var theFileName = FileName()
	for (i = 0; i < MyDisableList.length; i++) {
		if (String(MyDisableList[i]).toLowerCase(MyDisableList[i]) == String(theFileName).toLowerCase(theFileName)) {
			return false
		}
	}
	
	
	for (a = 0; a < document.links.length; a++) {
		if (document.links[a].target == "_blank" || document.links[a].href.substring(0,7) == "mailto:" || document.links[a].href.substring(document.links[a].href.length - 1, document.links[a].href.length) == "#"){
			//Skip it
		}else{
			if (String(document.links[a].href).indexOf('javascript:OnClick=FrameIt') != -1){
				//do nothing
			}else{
				document.links[a].href = "javascript:OnClick=FrameIt('" + document.links[a] + "')"
			}
		}
	}
	IsFrameIt = "true"
}

function GetDomain(MyLocation){
	var x = 0 
	var TheDomain=""
	var SlashCount = 0
	for (x = 0; x < MyLocation.length; x++) {
		if (MyLocation.charAt(x) == "/"){
			SlashCount = SlashCount + 1
		}
		TheDomain = TheDomain + MyLocation.charAt(x)
		if (SlashCount == 3){
			return TheDomain
		}

	}
}

function FileName(){
	var MyFileName = ""
	for (i = String(document.location).length; i > 0; i = i - 1) {
		if (String(document.location).charAt(i - 1)==String.fromCharCode(47) || String(document.location).charAt(i - 1)==String.fromCharCode(92)){
			return MyFileName
		}
		MyFileName = String(document.location).charAt(i - 1) + MyFileName
	}
}

function GetURL(MyString){
	var theString = String(MyString)
	if (theString.indexOf('javascript:OnClick=FrameIt') != -1){
		theString = theString.substring(28, theString.length - 2)
	}
	return theString
}