function getMyHTML(url, objID)
{
     //alert(url,objID);
     //url = 'http://localhost/www.preservestaffnow.org/swansong/fi_swan.ihtml';
     //alert('in function');
     var http_request = false;
	 var obj = document.getElementById(objID);
     try {
          if (window.XMLHttpRequest) { // Mozilla, Safari,...
               http_request = new XMLHttpRequest();
               if (http_request.overrideMimeType) {
                   http_request.overrideMimeType('text/plain');
                   // See note below about this line
                }
          }
		  else
		  if (window.ActiveXObject) { // IE
              try {
                  http_request = new ActiveXObject("Msxml2.XMLHTTP");
              } catch (e) {
                  try {
                      http_request = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (e) {}
              }
          }

          if (!http_request) {
            //  alert('Giving up :( Cannot create an XMLHTTP instance');
            //  alert('Unable to create necessary object for accessing the swan songs. Most likely, you need to add http://www.preservestaffnow.org to your trusted Internet sites if your browser is MS Internet Explorer.\nAlso you need to allow cookies to be set.');
			//location.href = "htmlswansongview.php";
			PopTart(url);  
            return -1;
          } 
//alert(http_request);
          http_request.onreadystatechange = function() { alertContents(http_request,obj); };
       	  http_request.open('GET', url, true);
          http_request.send(null);
     } catch (e) {
	 	// error can occur if user makes psn trusted site but neglects to refresh
		alert("The page needs to be refreshed.  Please press F5 or else Ctrl-F5");
	 }
}// end function

function alertContents(http_request,obj)
{
     if (http_request.readyState == 4) {
            if (http_request.status == 200) {
//                alert(http_request.responseText);
				obj.innerHTML = http_request.responseText;
            }
			else
			{
                alert('There was a problem with the request.');
            }
     }
}

// OTHER FUNCTIONS HERE:
// ln is a static variable to contain each of the numerical links.
var ln = document.getElementById('1');
function FixPN(maxnum,objLink,minnum)
{
  var page = objLink.search.split(/=/);       // extract page number from query string of numerical link
  var pnum = parseInt(page[1]);
  var nextp = pnum + 1;                       // next page
  var prevp = pnum - 1;                       // previous page

  if ((parseInt(ln) < maxnum) && (prevp > 0)){
  alert('ln is '+ln + ' and maxnum is ' +maxnum);                  
      BlueLine(ln);
  }   
  ln = objLink;             

try {  
  if (nextp > maxnum) 
  	nextp = maxnum;
  
  if (prevp <= minnum) 
        prevp = 1;
        document.getElementById('np').search = '?page=' + nextp;
        document.getElementById('np').onclick= function() {
        document.getElementById(nextp).onclick();
		document.getElementById(nextp).focus();
		if (nextp < maxnum) {
		   nextp++;
		}   
		return false;
  }// end annonymous function
  		
  if (document.getElementById('pp')) {
  	document.getElementById('pp').search = '?page=' + prevp;
	document.getElementById('pp').onclick= function() {
		document.getElementById(prevp).onclick();
		document.getElementById(prevp).focus();
		if (prevp > minnum) {
			prevp--;
		}
		return false;
	}// end annonymous func
  }// end if
  } catch (e) {
  		//alert('in FixPN and error is: '+e.message);
  }
}// end function  

function NoLine(objLink)
{
	try {
		objLink.style.textDecoration='none';
		objLink.style.color='red';
	} catch(e){
	//alert('in NoLine and message is: '+e.message);
	}
 	
}

function BlueLine(objLink)
{
 	try{
		objLink.style.textDecoration='underline';
		objLink.style.color='blue';
	} catch(e) {
     alert('in BlueLine and message is: '+e.message);
	}
}

function PopTart(url) 
{
  var a = '';
  var pt = null;
  try {
  	pt = document.getElementById('poptart');
  	pt.src=url;
  } catch (e) {
    alert("Please refresh the page now. [F5 or Cntrl-F5]");
  } 
}

// Start ....
window.onload = function() {
	try {
//alert('window.onload event occured');          // window onload events occur initially and if you change browser settings and negelect to refresh.
	 document.getElementById('1').focus();       // so 1st link is not underlined.
	 FixPN(17,document.getElementById('1'),0);   // should not hardcode 17 but not sure re solution.set previous and next links; must set ea time user clicks any nav link.
//alert('after fixPN executed but before ajaxing it.');	
	} catch(e) {
     alert(e.message);
	}
}

var counter = 0;  // used as index into array a
var clicked = 1;  // used in onclick of numerical urls.
var saved = 0;    // to remember where you were previously

// Shortcuts with n and p
// need to fix so that works with accesskeys and clicks?
function DoCommand(e)
{
   var key = window.event ? e.keyCode : e.which;
   var keychar = String.fromCharCode(key);
   var page = 0;
    
    if (counter != (clicked -1)) {    // if user doesn't access sequentially ...
         if (keychar == 'n') {
	         page = ++clicked;
		 }
		 else
		 if (keychar == 'p') {
		    page = saved;             // bookmarking previous page. Note: only one bookmark in this version
			counter = page -1;       // reset counter to avoid 'loop';
		 }
	}
	else {
	  page = PrevNext(keychar);
	}  

	document.getElementById(page).focus();
	document.getElementById(page).onclick();
}


function PrevNext(keypressed)
{
// the ids of the swansong numerical urls
var a = new Array( "1", "2","3","4","5","6","7","8","9",
				   "10","11","12","13","14","15","16","17");
var max = a.length;
// synchronizing so user may click or use shortcut letter

switch(keypressed)
{
 case 'N':
 case 'n':
     if (counter != clicked -1 && counter > 0) {
	      counter = clicked - 1;
     }
     counter++;
	 if (counter > (max-1)) {
	      counter = max-1;
	 }
	 break; 
 case 'P':
 case 'p':
      if (counter != clicked -1 && counter > 0) {
	      counter = clicked - 1;
     }
	  counter--;
	  if (counter < 0 ) { 
	      counter = 0;
	  }
	  break;
  default: 
     break;
}// end switch

var page = a[counter].split(/=/);     // get page and url;
page = page[0];
return page;
}// end function


