// Copyright (c) 2006 Tennyson Maxwell Information Systems, Inc.  All Rights Reserved.  Unauthorized copying, reverse engineering, or use of the contents of this file is strictly prohibited.

var tppSortQuery = false;
var tppPassForms = true;
var tppAnalyze = true;
function tppnotrand() { return 0.5; }
Math.random = tppnotrand;
var tppDate = Date;
// Date = function() { return new tppDate(2007,1,1); }
var tppWO = window.open;
window.open = function(u,n,f,r)
	{
	if( !u.Contains('tppmsg(') ) 
		return tppWO(u,n,f,r);
	window.navigate(u);
	return window;
	}


String.prototype.Contains = function(x) { return this.indexOf(x.toString()) != -1; }
String.prototype.BeginsWith = function(x) { return this.indexOf(x.toString()) === 0; }
String.prototype.EndsWith = function(x) { var xs = x.toString(); var s = this.length-xs.length; return s < 0 ? false : (this.lastIndexOf(xs, s) == s); }
String.prototype.ContainsI = function(x) { return this.toLowerCase().indexOf(x.toString().toLowerCase()) != -1; }
String.prototype.BeginsWithI = function(x) { return this.toLowerCase().indexOf(x.toString().toLowerCase()) === 0; }
String.prototype.EndsWithI = function(x) { var xs = x.toString(); var s = this.length-xs.length; return s < 0 ? false : (this.toLowerCase().lastIndexOf(xs.toLowerCase(), s) == s); }

function Contains(a,x,s,e) { for( var i = s ? s : 0; i < (e == undefined ? a.length : Math.min(e,a.length)); i++ ) if( a[i] == x ) return true; return false; }
function Dedupe(a) { for( var i = 1; i < a.length; i++ ) if( Contains(a,a[i],0,i) ) a.splice(i--,1); return a; }

function debug(x) { alert(x); }
function tppsetcookie(x) { return x; }

function tppexfm(x)
	{
	if( typeof(x) == "string" )
		{
		x = x.replace(/(\. *href|src|location) *= *(('([^\']|\\')*')|("([^\"]|\\")*"))/, "$1=tppxfm($2)");
		x = x.replace(/(\. *replace|assign|navigate|open) *\( *(('([^\']|\\')*')|("([^\"]|\\")*"))/, "$1(tppxfm($2)");
		}
	return x;
	}

function tppdu(x)
  {
  return tppsrc;
  }

function tppexplain(x)
  {
  if( !x )
    x = location.search.substr(1);
  x = x.split('&');
  var url;
  var code;
  for(var i in x)
    {
    if( x[i].substr(0,2) == 'u=' )
      url = x[i].substr(2);
    else if( x[i].substr(0,2) == 'c=' )
      code = 1*(x[i].substr(2));
    }
  document.write(url == undefined ? 
    'This file is not on the WebDisc CD.<p>' : tppAnalyze ? 
    'The link to <a href='+unescape(url)+'>'+unescape(url)+'</a> was not copied because '+tppcodestr(code)+'<p>' :
    'The file <a href='+unescape(url)+'>'+unescape(url)+'</a> is not on this WebDisc CD.<p>');
  }
function tppcodestr(x)
	{
	switch(x) {
		case 302: return "it was redirected outside the project boundary.";
		case 900: return "it is located too far from the project's starting point.";
		case 901: return "it is located too far outside the project boundary.";
		case 902: return "it is not within the project boundary.";
		case 903: return "it was excluded by the project properties.";
		case 904: return "it was excluded by the site's Robot Exclusion properties.";
		case 905: return "it was not needed for the project.";
		case 906: return "the project was stopped due to a project limit property.";
		case 908: return "it was deleted from the project.";
		case 0: 	return "the project hasn't finished running yet.";
		}
	return "the server returned status code "+x+".";
	}
function tppmsg(x,a)
	{
  if( confirm(tppAnalyze ?
    a+"\n\nThis file was not retrieved because "+tppcodestr(x)+"\n\nDo you want to open it from the server?" :
    a+"\n\nThis file is not on the WebDisc CD.  Do you want to open it from the server?") )
		window.location = a;
	}
function tppnul(a,b,c,d,e,f,g)
	{
	return '';
	}
function tppget(f,x)
	{
	var s = tppval(f,x);
	var r = tppxfm(s);
	if( r != s )
		{
		window.location=r;
		return false;
		}
  if( !tppPassForms )
    return false;
	return confirm("Using this form requires an active Internet connection.  Press OK to submit your request, or Cancel to return to browsing.");
	}
function tppformval(x)
	{
	return (""+x).replace(/ /g, '+');
	}
function tppval(f,x)
	{
	var r = (f.action+"").split('#')[0];
	// if form has no action, use current page url minus query parts
	if( !r )
		r = tppsrc.split('?')[0].split('\xbf')[0];
	r += (f.method+"").toLowerCase()=='post' ? '\xbf' : (!r.Contains('?') ? '?' : (r.EndsWith('&') ? '' : '&'));
	for( var i = 0; i < f.elements.length; i++)
		{
		var e = f.elements[i];
		if( !e.name )
			continue;
		var t = e.type.toLowerCase();
		if( t == 'submit' && !e.value )
			e.value = 'Submit Query';
		if( t == 'select-one' )
			r += e.name+'='+tppformval(e[e.selectedIndex].value)+'&';
		else if( ((t=='radio' || t=='checkbox') && e.checked) || t=='hidden' || t=='text' || t=='password' || t=='textarea' || t=='submit' || t=='button' )
			r+=e.name+'='+tppformval(e.value)+'&';
		}
	if( x )
		r += x;
	if( r.substr(r.length-1) != '?' )
		r = r.substr(0,r.length-1);
	if( tppSortQuery )
		{
		var hasq = r.Contains('?');
		var a = r.split(/[?\xbf]/);
		r = a[0];
		if( a[1] )
			r += (hasq ? '?' : '\xbf')+Dedupe(a[1].split('&').sort()).join('&');
		if( a[2] )
			r += '\xbf'+Dedupe(a[2].split('&').sort()).join('&');
		}
	if( (f.method+"").toLowerCase()=='post' )
		r += '_TPPPOST';
	return r;
	}
function switchcd(x)
	{
	alert('The file you clicked on ('+x+') is located on Disk 2 of this WebDisc set.	Please insert Disk 2 now, and press Ok.  After the file has loaded, you must replace Disk 2 with the previously inserted disk, to continue browsing.');
	window.location = x;
	}
function tppprewxfm(x)
	{
	return x;
	}
function tpppostwxfm(x)
	{
	return x;
	}
function tppprexfm(a)
	{
	/*
	var b = ""+a;
	if(b.substr(0,8)=='file:///')
		return b.substr(b.indexOf('/',8));
	*/
	return a;
	}
function xfmpatch(a)
	{
	return a;
	}
function tpppostload()
  {
  }
function tppload()
  {
	for( var i = 0; i < document.forms.length; i++ )
		{
		var f = document.forms[i];
		if( f.onsubmit )
			{
			f.xonsubmit = f.onsubmit;
			f.onsubmit = new Function("if( this.xonsubmit() == false ) return false; return tppget(this);");
			}
		else
			f.onsubmit = new Function("return tppget(this);");
		if( (""+f.submit).indexOf('function submit(') >= 0 )
			{
			f.xsubmit = f.submit;
			f.submit = new Function("if( this.onsubmit() != false ) this.xsubmit();");
			}
		}
  for( var i = 0; i < document.links.length; i++ )
    {
    var e = document.links[i];
    if( e.href == "javascript:void(1)" )
      {
      e.disabled = true;
      e.style.textDecoration = "none";
      e.style.cursor = "default";
      e.target = "";
      }
    else if( e.href == "javascript:void(2)" )
      {
      e.disabled = true;
      e.style.textDecoration = "none";
      e.style.cursor = "default";
      e.style.display = "none";
      e.target = "";
      }
    else if( e.href.indexOf("javascript:tppmsg(") == 0 )
      {
      e.target = "";
      }
    }
  tpppostload();
  }
function tppwxfm(a,b,c,d,e,f,g)
  {
  return a;
  }
function tppixfm(a,b,c,d,e,f,g)
  {
  return tppwxfm(a,b,c,d,e,f,g);
  }

var tppxActiveXObject = ActiveXObject;
ActiveXObject = function(x)
	{
	if( x == 'Msxml2.XMLHTTP' || x == 'Microsoft.XMLHTTP' )
		{
		var r = new Object();
		r.orig = new tppxActiveXObject(x);
		r.orig.onreadystatechange = function()
			{
			r.readyState = r.orig.readyState;
			if( r.readyState >= 4 )
				{
				r.responseBody = r.orig.responseBody; 
				r.responseStream = r.orig.responseStream; 
				r.responseText = r.orig.responseText; 
				r.responseXML = r.orig.responseXML;
				r.status = r.orig.status;
				r.statusText = r.orig.statusText;
				}
			}
		r.abort = function() { r.orig.abort(); }
		r.getAllResponseHeaders = function() { return r.orig.getAllResponseHeaders(); }
		r.getResponseHeader = function(x) { return r.orig.getResponseHeader(x); }
		r.open = function(a,b,c,d,e) { r.orig.open(a,tppxfm(b),c==undefined?1:c,d,e);	}
		r.send = function(a) { r.orig.send(a); }
		r.setRequestHeader = function(h,v) { r.orig.setRequestHeader(h,v); }
		return r;
		}
	return new tppxActiveXObject(x);
	}

