//////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
// Copyright 2007 Media Creative Ltd
// mark@mediacreativeltd.com
// MCL2 Functions
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// Ajax Call -----------------------------------------------------------

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=/cgraphics/loader.gif></center>";

}
}

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=/cgraphics/loader.gif></center>";
}
}

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=/cgraphics/loader.gif>";
}
}

function stateChanged4() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("search1").innerHTML=xmlHttp.responseText;
}
else {
document.getElementById("search1").innerHTML="<br/><br/><br/><br/><center><img src=/cgraphics/loader.gif></center>";
}
}

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;
}

// Return Page...............................
function returnPage(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/" + str ;
//url=url+"?id="+selectedSearchType;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
//

// NEWS RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function returnNews(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxPages/returnNews.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END NEWS RETURN

// BIBLIO RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function returnBiblio(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxPages/returnBiblio.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END BIBLIO RETURN

// BIBLIO RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function returnAnswer(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxPages/returnAnswer.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END BIBLIO RETURN

// Month RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function returnCal(mon)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxPages/returnMonth.asp";
url=url+"?mon="+mon;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END Monty RETURN

// Event RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function returnEvent(id)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxPages/returnEvent.asp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END Event RETURN

// Topic RETURN //////////////////////////////////////////////////////////////////////////////////////////////////
function populateTopic()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var cType = document.form1.topic2.value;
var url="/ajaxPages/returnTopic.asp";
url=url+"?cType="+cType;
xmlHttp.onreadystatechange=stateChanged3;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// END Topic RETURN

//Global Variables

var isClickedID=1;
var myClass=1;
var selectedID;
var selectedSearchType;
// This is here purely for image deletion
var selectedFile;
/////////////////////////////////////////////////////////////

// End variables

// Main Menu Rollovers 
function menuOver(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "menuItemOver";
}

function menuOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "menuItem";
}

function calOver(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "calItemOn";
}

function calOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "calItem";
}

function menuOverSub(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "menuItemOverSub";
}

function menuOutSub(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "menuItemSub";
}

function menuClick(thisURL,men,submen) {

var thisLot
thisLot = "?smen=" + men;
thisLot = thisLot + "&ssub=" + submen;
thisLot = thisLot + "&url=" + thisURL;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
 // alert(thisLot);
var url="/cinc/setSession.asp";
document.location.href=url+thisLot;
//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);

//document.location.href=thisURL;
}
// End Function

// mmenu Rollovers 
function mmenuOver(thisId) {
var selected 
selected = document.getElementById(thisId);

selected.className = "menuHeadingOn";
}

function mmenuOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "menuHeading";
}

function mmenuLink(thisURL) {
// document.location.href=thisURL;
switchMenu('div'+thisURL,'change'+thisURL)
}

function mmenuLink2(thisURL,Chg) {
// document.location.href=thisURL;
switchMenu2('sdiv'+thisURL,'schange'+Chg)
//alert(Chg);
}

// End Function  

function qOver(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "qOn";
}

function qOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "qOff";
}

function tOver(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "tOn";
}

function tOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "tOff";
}



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 dirtyCollapse(){
alert("hello");



}
// END MENU FUNCTIONS ///////////////////////////////////////////////////////////////////////////////////////

function swapTo(thisIM){
var oversrc = "/cgraphics/moreon.jpg";
document.getElementById(thisIM).src=oversrc;

}
function swapBack(thisIM){
var oversrc = "/cgraphics/more.jpg";
document.getElementById(thisIM).src=oversrc;
}

function swapToButton(thisIM,thisSRC){
var oversrc = "/cgraphics/" + thisSRC + "on.jpg";
document.getElementById(thisIM).src=oversrc;

}
function swapBackButton(thisIM,thisSRC){
var oversrc = "/cgraphics/" + thisSRC + "off.jpg";
document.getElementById(thisIM).src=oversrc;
}


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.form1.isort.disabled = false;
}

function showMe() {
resetAll();
var thisShow = document.form1.searchHow.value ;

if (thisShow == "1"){
document.getElementById('search1').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.keyword.focus();
document.form1.isort.disabled = false;
selectedSearchType=1;
}
if (thisShow == "2"){
document.getElementById('search2').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.author.focus();
document.form1.isort.disabled = true;
selectedSearchType=2;
}
if (thisShow == "3"){
document.getElementById('search3').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.institute.focus();
document.form1.isort.disabled = true;
selectedSearchType=3;
}
if (thisShow == "4"){
document.getElementById('search4').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.isort.disabled = true;
selectedSearchType=4;
}
if (thisShow == "5"){
document.getElementById('search5').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.publicationyear.focus();
document.form1.isort.disabled = true;
selectedSearchType=5;
}
if (thisShow == "6"){
document.getElementById('search6').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.cantabreference.focus();
document.form1.isort.disabled = true;
selectedSearchType=6;
}
if (thisShow == "7"){
document.getElementById('search7').style.display = '';
document.getElementById('search8').style.display = '';
document.form1.journal.focus();
document.form1.isort.disabled = true;
selectedSearchType=7;
}
}

function swapToSearch(thisIM){
var oversrc = "/cgraphics/searchon.jpg";
document.getElementById(thisIM).src=oversrc;

}
function swapBackSearch(thisIM){
var oversrc = "/cgraphics/searchoff.jpg";
document.getElementById(thisIM).src=oversrc;
}

function swapToReset(thisIM){
var oversrc = "/cgraphics/reseton.jpg";
document.getElementById(thisIM).src=oversrc;

}
function swapBackReset(thisIM){
var oversrc = "/cgraphics/resetoff.jpg";
document.getElementById(thisIM).src=oversrc;
}

function searchMe() {
var thisLot;
thisLot = "keyword=" + encodeURIComponent(document.form1.keyword.value);
thisLot = thisLot + "&author=" + encodeURIComponent(document.form1.author.value);
thisLot = thisLot + "&institute=" + encodeURIComponent(document.form1.institute.value);
thisLot = thisLot + "&topic=" + encodeURIComponent(document.form1.topic.value);
thisLot = thisLot + "&publicationyear=" + encodeURIComponent(document.form1.publicationyear.value);
thisLot = thisLot + "&cantabreference=" + encodeURIComponent(document.form1.cantabreference.value);
thisLot = thisLot + "&journal=" + encodeURIComponent(document.form1.journal.value);
thisLot = thisLot + "&viewresults=" + encodeURIComponent(document.form1.viewresults.value);
thisLot = thisLot + "&selectedSearchType="  + encodeURIComponent(document.form1.searchHow.value);
thisLot = thisLot + "&isort="  + encodeURIComponent(document.form1.isort.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxpages/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 siteSearch() {
var thisLot;
thisLot = "searchme=" + encodeURIComponent(document.thisSearch.searchme.value);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/ajaxpages/siteSearchDo.asp";
xmlHttp.onreadystatechange = stateChanged4;
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 siteSearch2() {
var thisLot;
thisLot = document.thisSearch2.searchme2.value;
if (thisLot==""){
alert("Please specify a keyword to search by");
}
else{
var url="/camcog/site-Search2.asp?kw=" + thisLot;
document.location.href=url;
}
}

function lbMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnBiblio(id);
}

function closelbMe(){
document.getElementById('divThis').style.display='none';
document.getElementById('apDiv1').style.display='none';
document.body.scroll="yes";
}

function ansMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnAnswer(id);
}

function newsMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnNews(id);
}

function ebMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnEvent(id);
}

function outlookMe(id){
document.location.href="/ics/" + id + ".ics";
}

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 
}

}

// animate on/off function ////////////////////////////////////////////////////////////
function animateMe(id){
var onsrc = "/science/cantabtests/graphics/" + id + "on.gif";
var offsrc = "/science/cantabtests/graphics/" + id + "off.gif";
var newSrc=document.getElementById(id).src;
var pos=newSrc.indexOf('on.gif');
if(pos=="-1"){
document.getElementById(id).src=onsrc;
}
else {
document.getElementById(id).src=offsrc;
}
}
// End function/////////////////////////////////////////////////////////////////////////

// new function to display abstratcs from tests...

function displayAbstract(obj){
window.open('/ajaxPages/showBiblio.asp?id=' + obj,'mywin',
'left=20,top=20,width=800,height=600,toolbar=0,resizable=1,scrollbars=1');
}