//get xy from url if available*********

function createRequestObject() {
 FORM_DATA = new Object();
  // The Object ("Array") where our data will be stored.
 separator = ',';
  // The token used to separate data from multi-select inputs
 query = '' + this.location;
 qu = query
  // Get the current URL so we can parse out the data.
  // Adding a null-string '' forces an implicit type cast
  // from property to string, for NS2 compatibility.
 query = query.substring((query.indexOf('?')) + 1);
  // Keep everything after the question mark '?'.
 if (query.length < 1) { return false; } // Perhaps we got some bad data?
 keypairs = new Object();
 numKP = 1;
  // Local vars used to store and keep track of name/value pairs
  // as we parse them back into a usable form.
 while (query.indexOf('&') > -1) {
  keypairs[numKP] = query.substring(0,query.indexOf('&'));
  query = query.substring((query.indexOf('&')) + 1);
  numKP++;
   // Split the query string at each '&', storing the left-hand side
   // of the split in a new keypairs[] holder, and chopping the query
   // so that it gets the value of the right-hand string.
 }
 keypairs[numKP] = query;
  // Store what's left in the query string as the final keypairs[] data.<
 for (i in keypairs) {
  keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
   // Left of '=' is name.
  keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
   // Right of '=' is value.
  while (keyValue.indexOf('+') > -1) {
   keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
    // Replace each '+' in data string with a space.
  }
  keyValue = unescape(keyValue);
   // Unescape non-alphanumerics
  if (FORM_DATA[keyName]) {
   FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
    // Object already exists, it is probably a multi-select input,
    // and we need to generate a separator-delimited string
    // by appending to what we already have stored.
  } else {
   FORM_DATA[keyName] = keyValue;
    // Normal case: name gets value.
  }
 }
 return FORM_DATA;
}

function getScrollThisY() {
  var thisY = 0; 
    thisY = document.getElementById("auto_scrolling_content").scrollTop;
  return [thisY]; 
}

function setScrollY() {
  if (typeof y == 'undefined') {
    var  y=0;
  }
  if (y>0) {
    document.getElementById("auto_scrolling_content").scrollTop = y;
  }
}

//THIS FUNCTION IS CALLED FROM CHAPTER KEY/CONTACT LINKS SENDING BROWSER INTO DIR AND RELEVANT DEF FILE
//set page 'definition file directory', 'scroll position', 'destination' and 'return chapter' info then redirects to definition page
function createTrackString(defType, depart, destination) { 
  
 var str="../keywords";
	//alert(str.search(/destination/));
	if (destination.substring(0,11) == '../keywords' || defType == 'keywords') {
		var createdTrackDestination = "../" + defType + '/' + destination + '?x=' + depart + '&y=' + getScrollThisY();
	}else{
		var createdTrackDestination = "../" + defType + '/' + destination;
	}
  //var createdTrackDestination = "../" + defType + '/' + destination + '?x=' + depart + '&y=' + getScrollThisY();
  //alert(createdTrackDestination);
  window.location = createdTrackDestination ;
}

//THIS FUNCTION IS CALLED FROM WITHIN A DEFINITION KEYWORD FILE TO LINK TO ANOTHER KEYWORD FILE
//set page 'definition file directory', 'scroll position', 'destination' and 'return chapter' info then redirects to definition page
function createTrackStringWithinDefFile(departWIF, destinationWIF) { 

	//collect page and scroll poistion from url if available
	var FORM_DATA = createRequestObject();
	var x=FORM_DATA['x']; //x is for use in the body to id the chapter to return to
	var y=FORM_DATA['y']; //y is for use in the body to id the scroll position to set to
	var a=FORM_DATA['a']; //new
	var b=FORM_DATA['b']; //new
	var d=FORM_DATA['d']; //new
	var e=FORM_DATA['e']; //new
	var xm=FORM_DATA['x']; //new

	//var createdTrackDestinationWithinDefFile = destinationWIF + '?x=' + x + '&y=' + y;
	var createdTrackDestinationWithinDefFile = destinationWIF + '?x=' + x + '&a=' + a + '&b=' + b + '&d=' + d + '&e=' + e + '&xm=' + xm + '&y=' + y; //new
	
	window.location = createdTrackDestinationWithinDefFile ;
}
