//////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
// Copyright 2007 Media Creative Ltd
// mark@mediacreativeltd.com
// MCL2 Functions
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////

var xmlhttp;

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("displayHere").innerHTML=xmlHttp.responseText;
resetAll();
}
else {
document.getElementById("displayHere").innerHTML="<br/><br/><br/><br/><center><img src=/resource/graphics/loader.gif></center><br/><br/><br/><br/><br/><br/><br/><br/>";

}
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("biblioHere").innerHTML=xmlHttp.responseText;
resetAll();
}
else {
document.getElementById("biblioHere").innerHTML="<br/><br/><br/><br/><center><img src=/resource/graphics/loader.gif></center><br/><br/><br/><br/><br/><br/><br/><br/>";
}
}

function stateChanged3()
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("topicHere").innerHTML=xmlHttp.responseText;
document.forms[0].topic.focus();
}
else {
document.getElementById("topicHere").innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=/resource/graphics/loader.gif><br/><br/><br/><br/><br/><br/><br/><br/>";
}
}

function stateChanged4() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("search1").innerHTML=xmlHttp.responseText;
}
else {
document.getElementById("search1").innerHTML="<br/><br/><br/><br/><center><img src=/resource/graphics/loader.gif></center><br/><br/><br/><br/><br/><br/><br/><br/>";
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function returnBiblio(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/working/returnBiblio.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function populateTopic()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var cType = document.forms[0].topic2.value;
var url="/resource/working/returnTopic.asp";
url=url+"?cType="+cType;
xmlHttp.onreadystatechange=stateChanged3;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



var selectedSearchType;



function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}



function collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
//;
}



function pageLoad() {
//var locate = window.location;
//var str = "" + locate;
//theleft = str.indexOf("=")+1;
//var theright = str.lastIndexOf("$");
str = window.myMen
if(str=="1"){
collapseAll($('div2','div3','div4'));
}
if(str=="2"){
collapseAll($('div1','div3','div4'));
}
if(str=="3"){
collapseAll($('div1','div2','div4'));
}
if(str=="4"){
collapseAll($('div1','div2','div3'));
}
//if(str==""){
//collapseAll($('div1','div2','div3'),'div4');
//}
locate = window.location;
var str = window.mySub
//theleft = str.indexOf("&") + 5;
//var theright = str.lastIndexOf("@");
//str = str.substring(theleft, theright);

if(str=="5"){
collapseAll($('sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
}
if(str=="6"){
collapseAll($('sdiv5','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
}
if(str=="7"){
collapseAll($('sdiv5','sdiv6','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
}
if(str=="8"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
}
if(str=="9"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv10','sdiv11','sdiv12','sdiv13'));
}
if(str=="10"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv11','sdiv12','sdiv13'));
}
if(str=="11"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv12','sdiv13'));
}
if(str=="12"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv13'));
}if(str=="13"){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12'));
}
if(str==""){
collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
}

}

///////////////////////////////////////////////////////////////////////

function switchMenu(obj,obj2) {
var el = document.getElementById(obj);

// COLLAPSES ALL BEFORE CHANGE ///
collapseAll($('div1','div2','div3','div4'));
/////////////////////////////////////////////////////////////////

if ( el.style.display != 'none' ) {
el.style.display = 'none';
document.getElementById(obj2).innerHTML = "<img src='/cgraphics/rightArrow.gif' border='0'>";
}
else {
el.style.display = '';
document.getElementById(obj2).innerHTML = "<img src='/cgraphics/downArrow.gif' border='0'>";
}
}


 function switchMenu2(obj,obj2) {
var el = document.getElementById(obj);

// COLLAPSES ALL BEFORE CHANGE ///
//collapseAll($('sdiv5','sdiv6','sdiv7','sdiv8','sdiv9','sdiv10','sdiv11','sdiv12','sdiv13'));
//collapseAll($('div5','div6','div3','div4'));
/////////////////////////////////////////////////////////////////

if ( el.style.display != 'none' ) {
el.style.display = 'none';
document.getElementById(obj2).innerHTML = "&nbsp;&nbsp;&nbsp;<img src='/cgraphics/rightArrow2.gif' border='0'>";
}
else {
el.style.display = '';
document.getElementById(obj2).innerHTML = "&nbsp;&nbsp;&nbsp;<img src='/cgraphics/downArrow2.gif' border='0'>";
}
}

function resetAll() {
document.getElementById('search1').style.display = 'none'
document.getElementById('search2').style.display = 'none' 
document.getElementById('search3').style.display = 'none'
document.getElementById('search4').style.display = 'none'
document.getElementById('search5').style.display = 'none'
document.getElementById('search6').style.display = 'none'
document.getElementById('search7').style.display = 'none'
document.getElementById('search8').style.display = 'none'
document.getElementById("topicHere").innerHTML="<input type=hidden name=topic>";
document.forms[0].isort.disabled = false;
}

function showMe() {
resetAll();
var thisShow = document.forms[0].searchHow.value ;

if (thisShow == "1"){
document.getElementById('search1').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].keyword.focus();
document.forms[0].isort.disabled = false;
selectedSearchType=1;
}
if (thisShow == "2"){
document.getElementById('search2').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].author.focus();
document.forms[0].isort.disabled = true;
selectedSearchType=2;
}
if (thisShow == "3"){
document.getElementById('search3').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].institute.focus();
document.forms[0].isort.disabled = true;
selectedSearchType=3;
}
if (thisShow == "4"){
document.getElementById('search4').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].isort.disabled = true;
selectedSearchType=4;
}
if (thisShow == "5"){
document.getElementById('search5').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].publicationyear.focus();
document.forms[0].isort.disabled = true;
selectedSearchType=5;
}
if (thisShow == "6"){
document.getElementById('search6').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].cantabreference.focus();
document.forms[0].isort.disabled = true;
selectedSearchType=6;
}
if (thisShow == "7"){
document.getElementById('search7').style.display = '';
document.getElementById('search8').style.display = '';
document.forms[0].journal.focus();
document.forms[0].isort.disabled = true;
selectedSearchType=7;
}
}

var key="";
var aut="";
var ins="";
var top="";
var pub="";
var can="";
var jou="";
var vie;
var sel;
var iso;

function sortout(obj){
	if(obj=="" || obj=="undefined"){
		obj=""
	}
	return obj;
}

function searchMe() {

var thisLot;
thisLot = "keyword=" + encodeURIComponent(document.forms[0].keyword.value);
thisLot = thisLot + "&author=" + encodeURIComponent(document.forms[0].author.value);
thisLot = thisLot + "&institute=" + encodeURIComponent(document.forms[0].institute.value);
thisLot = thisLot + "&topic=" + encodeURIComponent(document.forms[0].topic.value);
thisLot = thisLot + "&publicationyear=" + encodeURIComponent(document.forms[0].publicationyear.value);
thisLot = thisLot + "&cantabreference=" + encodeURIComponent(document.forms[0].cantabreference.value);
thisLot = thisLot + "&journal=" + encodeURIComponent(document.forms[0].journal.value);
thisLot = thisLot + "&viewresults=" + encodeURIComponent(document.forms[0].viewresults.value);
thisLot = thisLot + "&selectedSearchType="  + encodeURIComponent(document.forms[0].searchHow.value);
thisLot = thisLot + "&isort="  + encodeURIComponent(document.forms[0].isort.value);

key=  encodeURIComponent(document.forms[0].keyword.value);
aut= encodeURIComponent(document.forms[0].author.value);
ins =  encodeURIComponent(document.forms[0].institute.value);
top = encodeURIComponent(document.forms[0].topic.value);
pub =  encodeURIComponent(document.forms[0].publicationyear.value);
can = encodeURIComponent(document.forms[0].cantabreference.value);
jou = encodeURIComponent(document.forms[0].journal.value);
vie = encodeURIComponent(document.forms[0].viewresults.value);
sel = encodeURIComponent(document.forms[0].searchHow.value);
iso = encodeURIComponent(document.forms[0].isort.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/working/searchMe.asp";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);

}


function searchMeAgain() {

var thisLot;
thisLot = "keyword=" + encodeURIComponent(sortout(key));
thisLot = thisLot + "&author=" + encodeURIComponent(sortout(aut));
thisLot = thisLot + "&institute=" + encodeURIComponent(sortout(ins));
thisLot = thisLot + "&topic=" + encodeURIComponent(sortout(top));
thisLot = thisLot + "&publicationyear=" + encodeURIComponent(sortout(pub));
thisLot = thisLot + "&cantabreference=" + encodeURIComponent(sortout(can));
thisLot = thisLot + "&journal=" + encodeURIComponent(sortout(jou));
thisLot = thisLot + "&viewresults=" + encodeURIComponent(sortout(vie));
thisLot = thisLot + "&selectedSearchType="  + encodeURIComponent(sortout(sel));
thisLot = thisLot + "&isort="  + encodeURIComponent(sortout(iso));

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/working/searchMe.asp";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);

}

function getBiblio(obj) {

var thisLot;
thisLot = "id=" + obj;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/working/returnBiblio.asp";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);

}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
searchMe();
return false 
}
else{
return true 
}

}

function checkReturn(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
siteSearch();
return false 
}
else{
return true 
}

}

function checkClick(f){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(f && f.which){ //if which property of event object is supported (NN4)
f = f
characterCode = f.which //character code is contained in NN4's which property
}
else{
f = event
characterCode = f.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
//alert("enter");
siteSearch2();
return false 
}
else{
//alert("not enter");
return true 
}

}

function searchMeQuick(obj) {

var thisLot;
thisLot = "keyword="; 
thisLot = thisLot + "&author=" ; 
thisLot = thisLot + "&institute="; 
thisLot = thisLot + "&topic=" + obj;
thisLot = thisLot + "&publicationyear=";
thisLot = thisLot + "&cantabreference=";
thisLot = thisLot + "&journal=" ;
thisLot = thisLot + "&viewresults=1" ;
thisLot = thisLot + "&selectedSearchType=4"; 
thisLot = thisLot + "&isort=1" 

key= "";
aut= "";
ins =  "";
top = obj;
pub =  "";
can = "";
jou = "";
vie = "1";
sel = "4";
iso = "1";

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/working/searchMe.asp";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);

}

function getBibItem(obj) {

var thisLot;
thisLot = "keyword=" + obj; 
thisLot = thisLot + "&author=" ; 
thisLot = thisLot + "&institute="; 
thisLot = thisLot + "&topic=";
thisLot = thisLot + "&publicationyear=";
thisLot = thisLot + "&cantabreference=";
thisLot = thisLot + "&journal=";
thisLot = thisLot + "&viewresults=1" ;
thisLot = thisLot + "&selectedSearchType=1"; 
thisLot = thisLot + "&isort=1" 

key= obj;
aut= "";
ins =  "";
top = "";
pub =  "";
can = "";
jou = "";
vie = "1";
sel = "1";
iso = "1";

var url="/biblioQuickJump.asp";
document.location.href=url + "?" + thisLot;
}

