// framebuster
//if (window!= top) {top.location.href=location.href};

window.onload = function loadbehaviours() {
//do some checking so that JavaScript is unobtrusive and degrades gracefully
	if (!document.getElementById) return;
	
// reusable functions
	function get_cookie ( cookie_name )
		{
			var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
			if ( results )
				return ( unescape ( results[1] ) );
			else
				return null;
		}
		
//set some variables for the cookies
	
	var expire = new Date();
	var today = new Date();
	expire.setTime(today.getTime() + 3600000*24*365);
	
// text-sizing options
if(document.getElementsByTagName && !navigator.userAgent.match("MSIE")){
	var textsizepref = get_cookie("textsize");
	if (textsizepref == "large")
		{
		body_list = document.getElementsByTagName('body');
		body = body_list[0];
		body.id="large";
		}
	if (textsizepref == "xlarge")
		{
		body_list = document.getElementsByTagName('body');
		body = body_list[0];
		body.id="xlarge";
		}
	textcontrolspara = document.createElement('p');
	textcontrolspara.setAttribute("class","textsizecontrols");
	textcontrolslink1 = document.createElement('a');
	textcontrolslink1.setAttribute("class","textnormal");
	textcontrolslink1.setAttribute("href","#");
	textcontrolslink1.onclick = function() {
		body_list = document.getElementsByTagName('body');
		body = body_list[0];
		body.id="";
		document.cookie = "textsize=normal" + ";expires="+expire.toGMTString()+ ";path=/";
		}
	textcontrolslink1.appendChild(document.createTextNode('A'));
	textcontrolspara.appendChild(textcontrolslink1);
	textcontrolslink2 = document.createElement('a');
	textcontrolslink2.setAttribute("class","textlarge");
	textcontrolslink2.setAttribute("href","#");
		textcontrolslink2.onclick = function() {
		body_list = document.getElementsByTagName('body');
		body = body_list[0];
		body.id="large";
		document.cookie = "textsize=large" + ";expires="+expire.toGMTString()+ ";path=/";
		}
	textcontrolslink2.appendChild(document.createTextNode('A'));
	textcontrolspara.appendChild(textcontrolslink2);
	textcontrolslink3 = document.createElement('a');
	textcontrolslink3.setAttribute("class","textxlarge");
	textcontrolslink3.setAttribute("href","#");
		textcontrolslink3.onclick = function() {
		body_list = document.getElementsByTagName('body');
		body = body_list[0];
		body.id="xlarge";
		document.cookie = "textsize=xlarge" + ";expires="+expire.toGMTString()+ ";path=/";
		}
	textcontrolslink3.appendChild(document.createTextNode('A'));
	textcontrolspara.appendChild(textcontrolslink3);
//	findthespot = document.getElementById("navigation");
//	findthespot.insertBefore(textcontrolspara,document.getElementById("navmenu"));
}

//behaviours for display/expand links
	
	//create the book display/expand controls and stick them in the right place
	
if (document.getElementById("bookcontrols")){
	mynewlink=document.createElement('a');
	mynewlink.appendChild(document.createTextNode("hide new books"));
	mynewlink.setAttribute("href","#");
	mynewlink.id="bookcontrollink";
	mynewlink.onclick = function() {
		if (document.getElementById("newbooksdetail").style.display != "none")
			{
				document.getElementById("newbooksdetail").style.display = "none";
				document.getElementById("bookcontrollink").firstChild.data='display new books';
				document.cookie = "books=hide" + ";expires="+expire.toGMTString()+ ";path=/";
			}
		else
			{
				document.getElementById("newbooksdetail").style.display = "block";
				document.getElementById("bookcontrollink").firstChild.data='hide new books';
				document.cookie = "books=show" + ";expires="+expire.toGMTString()+ ";path=/";
			}
		}
	existingobject = document.getElementById("bookcontrols");
	existingobject.appendChild(mynewlink);
	}
	//create the journal display/expand controls and stick them in the right place
	
if (document.getElementById("journalcontrols")){
	yournewlink=document.createElement('a');
	yournewlink.appendChild(document.createTextNode("hide journal news"));
	yournewlink.setAttribute("href","#");
	yournewlink.id="journalcontrollink";
	yournewlink.onclick = function() {
		if (document.getElementById("newjournalsdetail").style.display != "none")
			{
				document.getElementById("newjournalsdetail").style.display = "none";
				document.getElementById("journalcontrollink").firstChild.data='display journal news';
				document.cookie = "journals=hide" + ";expires="+expire.toGMTString()+ ";path=/";
			}
		else
			{
				document.getElementById("newjournalsdetail").style.display = "block";
				document.getElementById("journalcontrollink").firstChild.data='hide journal news';
				document.cookie = "journals=show" + ";expires="+expire.toGMTString()+ ";path=/";
			}
		}
	existingobject = document.getElementById("journalcontrols");
	existingobject.appendChild(yournewlink);
}
	//check display/expand cookies for user preferences
	
	var bookpref = get_cookie("books");
	var journalpref = get_cookie("journals");
	
	// implement user's display/expand preferences
	if (document.getElementById("bookcontrols"))
	{
	if (bookpref == "hide")
		{
			document.getElementById("newbooksdetail").style.display = "none";
			document.getElementById("bookcontrollink").firstChild.data='display new books';
		}
	}
	if (document.getElementById("journalcontrols"))
	{
	if (journalpref == "hide")
		{
			document.getElementById("newjournalsdetail").style.display = "none";
			document.getElementById("journalcontrollink").firstChild.data='display journal news';
		}
	}
//navigation menu dropdown behaviour for Internet Explorer only

	if(navigator.userAgent.match("MSIE")){
		menuRoot = document.getElementById("navmenu");
		for (i=0; i<menuRoot.childNodes.length; i++){
			node = menuRoot.childNodes[i];
			if (node.nodeName=="LI"){
				node.onmouseover=function()
					{this.className+=" expand";}
				node.onmouseout=function() 
					{this.className=this.className.replace(" expand", "");}
   			}
  		}
		SubMenuRoot = document.getElementById("booksmenu");
		for (i=0; i<SubMenuRoot.childNodes.length; i++){
			booknode = SubMenuRoot.childNodes[i];
			if (booknode.nodeName=="LI"){
				booknode.onmouseover=function()
					{this.className+=" expand";}
				booknode.onmouseout=function() 
					{this.className=this.className.replace(" expand", "");}
   			}
  		}
		JSubMenuRoot = document.getElementById("journalsmenu");
		for (i=0; i<JSubMenuRoot.childNodes.length; i++){
			journalnode = JSubMenuRoot.childNodes[i];
			if (journalnode.nodeName=="LI"){
				journalnode.onmouseover=function()
					{this.className+=" expand";}
				journalnode.onmouseout=function() 
					{this.className=this.className.replace(" expand", "");}
   			}
  		}
	}
// code for userprefs page
	if (document.getElementById("countryinfo"))
	{
	showwhylinkpara=document.createElement('p');
	showwhylinkpara.setAttribute("class","infocontrol")
	showwhylink=document.createElement('a');
	showwhylink.appendChild(document.createTextNode("why do we want to know your country?"));
	showwhylink.setAttribute("href","#");
	showwhylink.onclick = function() {
		if (document.getElementById("countryinfoexpanded").style.display != "none")
			{
				document.getElementById("countryinfoexpanded").style.display = "none";
			}
		else
			{
				document.getElementById("countryinfoexpanded").style.display = "block";
			}
		}
	showwhylinkpara.appendChild(showwhylink)
	linkplace = document.getElementById("countryinfo");
	linkplace.insertBefore(showwhylinkpara, document.getElementById("countryinfoexpanded"));
	document.getElementById("countryinfoexpanded").style.display = "none";
	}
	
// hide irrelevant newsletter subject codes

	if (document.getElementById("mailform")){
		var subjectcodeprefix = "BE0160"
		var checkboxes = document.getElementsByTagName("input");
		//if(checkboxes.id.substring(0,1)=="BE"){
		//	firstsixchars = checkboxes.id.substring(0,5)
		//}
	}

//START GOOGLE MAPS JAVASCRIPT
if (window.location.pathname=="/resources/conferences.asp"){
    if (GBrowserIsCompatible()) {
	  // USER EDITED SECTION:
	  var ArenaSubject = "BE0515"; // first 5 characters of subject code
	  var ArenasecondSubject = "BE0530";
	  // END USER EDITED SECTION
      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
      // create the map
      var map = new GMap(document.getElementById("map"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
    		map.centerAndZoom(new GPoint(-0.1365,50.8332), 15);
      // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "/common/generic/psypress/xml/Export.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = request.responseXML;
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("Export_XML");
		  for (var i = 0; i < markers.length; i++) {
		  	var ConferenceNode = markers[i];
			// build date checking facility (to check conferences are not in the past)
			var checkdate = GXml.value(ConferenceNode.getElementsByTagName("end_date")[0]);
			checkdate = checkdate.substring(0,10);
			var today = new Date();
			var FormattedCheckDate = new Date(Number(checkdate.substring(0,4)), Number(checkdate.substring(5,7))-1, Number(checkdate.substring(8,10)));
		  	if ((GXml.value(ConferenceNode.getElementsByTagName("Latitude")[0])) && (GXml.value(ConferenceNode.getElementsByTagName("Longitude")[0])) && (GXml.value(ConferenceNode.getElementsByTagName("id")[0])) && (FormattedCheckDate>=today)){
				var subject1 = GXml.value(ConferenceNode.getElementsByTagName("lookup_sub_code_1")[0]);
				var subject2 = GXml.value(ConferenceNode.getElementsByTagName("lookup_sub_code_2")[0]);
				var subject3 = GXml.value(ConferenceNode.getElementsByTagName("lookup_sub_code_3")[0]);
				// extract records with relevant subject codes:
				if ((subject1.substring(0,6) == ArenaSubject) || (subject2.substring(0,6) == ArenaSubject) || (subject3.substring(0,6) == ArenaSubject) || (subject1.substring(0,6) == ArenasecondSubject) || (subject2.substring(0,6) == ArenasecondSubject) || (subject3.substring(0,6) == ArenasecondSubject)){
					var lat = parseFloat(GXml.value(ConferenceNode.getElementsByTagName("Latitude")[0]));
    	      		var lng = parseFloat(GXml.value(ConferenceNode.getElementsByTagName("Longitude")[0]));
					var point = new GPoint(lng,lat);
					var label = GXml.value(ConferenceNode.getElementsByTagName("id")[0]);
					// create and format date line
					var ConfStartDate = GXml.value(ConferenceNode.getElementsByTagName("start_date")[0]);
					var ConfEndDate = GXml.value(ConferenceNode.getElementsByTagName("end_date")[0]);
					ConfStartDate = ConfStartDate.substring(0,10);
					ConfEndDate = ConfEndDate.substring(0,10);
					if (ConfStartDate && ConfEndDate){
						var FormattedStartDate = new Date(Number(ConfStartDate.substring(0,4)), Number(ConfStartDate.substring(5,7))-1, Number(ConfStartDate.substring(8,10)));
						var FormattedEndDate = new Date(Number(ConfEndDate.substring(0,4)), Number(ConfEndDate.substring(5,7))-1, Number(ConfEndDate.substring(8,10)));
						// for a 1 day conference:
						if (ConfStartDate == ConfEndDate){
							var FormattedDateLine = '<p>'+ FormattedStartDate.toLocaleDateString() +'</p>';
						}
						// for a multi-day conference:
						else{
							var FormattedDateLine = '<p>'+FormattedStartDate.toLocaleDateString() +' to '+FormattedEndDate.toLocaleDateString() +'.</p>';
						}
					}
					else{
						var FormattedDateLine = "";
					}
					// create and format venue line
					var confVenue = GXml.value(ConferenceNode.getElementsByTagName("venue")[0]);
					var confCity = GXml.value(ConferenceNode.getElementsByTagName("city")[0]);
					var confCountry = GXml.value(ConferenceNode.getElementsByTagName("country")[0]);
					var FormattedVenue = "";
					if (!confVenue && !confCity && !confCountry){
						var FormattedVenueLine = "";
					}
					else{
						if (confVenue){FormattedVenue = confVenue + ', ';}
						if (confCity){FormattedVenue = FormattedVenue + confCity + ', ';}
						if (confCountry){FormattedVenue = FormattedVenue + confCountry + '.';}
						var FormattedVenueLine = '<p>' + FormattedVenue + '</p>';
					}
					// create and format title and web link line
					var ConfTitle = GXml.value(ConferenceNode.getElementsByTagName("title")[0]);
					var ConfURL = GXml.value(ConferenceNode.getElementsByTagName("url")[0]);
					if (!ConfURL){
						var FormattedTitle = '<p><strong>' + ConfTitle + '</strong></p>';
					}
					else{
						var FormattedTitle = '<p><strong><a href="' + ConfURL + '" title="' + ConfURL + ' website">' + ConfTitle + '</a></strong></p>';
					}
					// create and format blurb
					var ConfBlurb = "";
					ConfBlurb = GXml.value(ConferenceNode.getElementsByTagName("website_blurb")[0]);
					ConfBlurb = '<p>' + ConfBlurb + '</p>';
					// write infoWindow 
					var html = '<div class="mapwindow">'+ FormattedTitle + FormattedVenueLine + FormattedDateLine + ConfBlurb + '</div>';
        		    // create the marker
           		 	map.addOverlay(createMarker(point,label,html));
				}
			 }
          }
        }
      }
      request.send(null);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
  }	
//END GOOGLE MAPS JAVASCRIPT	
// close the function
}