<!--

var request = null;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = null;
    }
  }
}

if (request == null)
  alert("Error creating request object!");

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function showhide(what,count){
		for(i=0;i<count;i++){
			var obj = findObj("menu"+i+"outline");
			obj.style.display = 'none';
		}	
		var showObj = findObj(what);
		if(showObj.style){
			showObj.style.display = '';
		}
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function addFormatting(tagName,formatString){
  // Get selection
  var selection = document.selection.createRange().text;
  if(selection != ""){   //if selection is not empty...
    var newSelection = document.selection.createRange();
	  newSelection.text = '<'+tagName+'>'+selection+'</'+tagName+'>'; //add opening tag, then text, then closing tag
	  return;
  } else { //otherwise...
	alert("Please select some text to "+formatString); //show an error message
  }
}

function addLink(internal){
var selection = document.selection.createRange().text;
  if(selection != ""){   //if selection is not empty...
	linkTo = prompt("Where do you wish to link to?","","http://");
	internal = confirm("Is this an external link?");
    var newSelection = document.selection.createRange();
	  newSelection.text = '<a href="'+linkTo+'" '+internal+'>'+selection+'</a>'; //add opening tag, then text, then closing tag
	  return;
  } else { //otherwise...
	alert("Please select some text to make into a link"); //show an error message
  }
}

function openWindow(linkURL,windowName,params) {
  window.open(linkURL,windowName,params);
}

function setStyle(size) {
	switch (size){
		case "small":
			document.styleSheets[0].disabled = false;
			document.styleSheets[1].disabled = true;
			document.styleSheets[2].disabled = true;
			document.cookie = "stylesheet=small";
		break;
		
		case "medium":
			document.styleSheets[0].disabled = true;
			document.styleSheets[1].disabled = false;
			document.styleSheets[2].disabled = true;
			document.cookie = "stylesheet=medium";
		break;
		
		case "large":
			document.styleSheets[0].disabled = true;
			document.styleSheets[1].disabled = true;
			document.styleSheets[2].disabled = false;
			document.cookie = "stylesheet=large";
		break;
	}
}

function checkCookie(){
	if(document.cookie){
		
		var ssString = document.cookie.split("; ");
		if(ssString[1]){
			var ssName = ssString[1].split("=");
			setStyle(ssName[1]);
		}
	}
}

function delConfirm(revID)
{
    if(confirm("Do you wish to delete the review with ID: "+revID)){
        window.location = "?act=del&revID="+revID;
    }
}

// Ajax Features

function getSubjects(elem,heading){
	var cell = elem.parentNode;
	var row = cell.parentNode;
	var body = row.parentNode;
	hideAllSubjects(body);
	var url = "../includes/subjectContent.ajax.php?heading="+heading+"&body="+body.id;
	request.open("GET", url, true);
	request.onreadystatechange = showSubjects;
	request.send(null);
	// showSubjects(elem,heading);
	return false;
}

function hideAllSubjects(body){
	var subjects = document.getElementsByTagName('tbody');
	for( var i=0;i<subjects.length;i++){
		if(subjects[i].id.substring(0,5) == "body_"){
			if(subjects[i].childNodes.length > 1 && body.id !== subjects[i].id){
				subjects[i].removeChild(subjects[i].childNodes[1]);
			}
		}
	}
}

function showSubjects(){
	if(request.readyState == 4){
		if(request.status == 200){
			var xmlDoc=request.responseXML;
			var xmlBody = xmlDoc.getElementsByTagName("elemid")[0];
			var bodyID = xmlBody.firstChild.nodeValue;
			var xmlSubjects = xmlDoc.getElementsByTagName("subject");
			var body = document.getElementById(bodyID);
			var row = body.childNodes[0];
			if(body.childNodes.length > 1) {
				body.removeChild(body.childNodes[1]);
			} else {
				var newRow = document.createElement("tr");
				var newCell = document.createElement("td");
				var className = row.getAttribute('class');
				newRow.setAttribute('class',className);
				newCell.setAttribute('colspan','2');
				newCell.setAttribute('align','center');
				var newTable = document.createElement("table");
				newTable.setAttribute('width','100%');
				var newTableHeadBlock = document.createElement("thead");
				var newTableHeadRow = document.createElement("tr");
				var thC1 = document.createElement("th");
				var thC2 = document.createElement("th");
				var thC3 = document.createElement("th");
				var thC1Text = document.createTextNode("Subject");
				var thC2Text = document.createTextNode("Volume / Issue");
				var thC3Text = document.createTextNode("Pages");
				thC1.appendChild(thC1Text);
				newTableHeadRow.appendChild(thC1);
				thC2.appendChild(thC2Text);
				newTableHeadRow.appendChild(thC2);
				thC3.appendChild(thC3Text);
				newTableHeadRow.appendChild(thC3);
				newTableHeadBlock.appendChild(newTableHeadRow);
				newTable.appendChild(newTableHeadBlock);
				newTBody = document.createElement("tbody");
				for(var i=0;i<xmlSubjects.length;i++){
					var newTR = document.createElement("tr");
					newTBody.appendChild(newTR);
					var td1 = document.createElement("td");
					var td2 = document.createElement("td");
					var td3 = document.createElement("td");
					var td1Text = document.createTextNode(xmlSubjects[i].firstChild.firstChild.nodeValue);
					var td2Text = document.createTextNode(xmlSubjects[i].firstChild.nextSibling.firstChild.nodeValue);
					var td3Text = document.createTextNode(xmlSubjects[i].firstChild.nextSibling.nextSibling.firstChild.nodeValue);
					td1.appendChild(td1Text);
					td2.appendChild(td2Text);
					td3.appendChild(td3Text);
					newTR.appendChild(td1);
					newTR.appendChild(td2);
					newTR.appendChild(td3);
				}
				newTable.appendChild(newTBody);
				newCell.appendChild(newTable);
				newRow.appendChild(newCell);
				body.appendChild(newRow);
			}
		}
	}
}
-->
