///////////////// JavaScript Document///////////////////////////
//Created by: Adriano da Silva
//Date: 09-10-2008
//Description:This javascript file loads an html page into another page element. It receives the element Id and the Url of the page to load.
//It then creates a request object based on the users browser (Window.XMLHttpRequest). It checks if the element if valid and reads the 
//Response of the server (ResponseText and place it on the element.innerHtml
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var objURI = location.href; 
var locationArray = new Array();

function clientSideInclude(id, url) {
  var req = false;
  //Create the XMLHTTP object 
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
  //Determine if the element if a valid element within the page.
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////Created by Adriano da Silva
////Date:10/10/2008////////////////////////////////////////////////////////////////////////////////
///Desc: This function creates the breadcrumb navigation on the pages//////////////////////////////
///if reads the location.ref and gets the container for the navigation div
///It then creates an array by splitting the location.ref and creates the breadcrumb items////////
/////////////////////////////////////////////////////////////////////////////////////////////////
function breadcrumbs()
		 {
			//objURI="http://wmra.ie/about us not you/Them/index.html";
		    if(objURI != null || objURI != "" )
		    {
		     var objElement = document.getElementById("sitenavigation");
		     var nav = objURI.replace("http://",""); //MUST BE HTTP:// CHANGED HERE JUST FOR TESTING
		    
			 locationArray = nav.split("/");
		     if(objElement == null || objElement =="")
		      {
		         return false;
		      }
		      if(locationArray == null || locationArray == "")
		      { return false;
		      }
		    var arrayLen = locationArray.length;
	        if(arrayLen==null || arrayLen == 'undefined'){return false;}
	        
	        var host  = locationArray[0];
	        var pageFolder = locationArray[1];
	        var pageFolderFormatted = pageFolder.replace(/%20/g,' ');
	        var pagetitle = document.title;
	        
	       switch(arrayLen)
	       {
	            //One folder 
	            case 3:
				    var pageLocation = "http://" + locationArray[0] + "/" + locationArray[1] + "/index.shtml";
		            
				    var objNavigation = "<div id='navElements' style='display:inline;padding-rigth:20px'>You are here:&nbsp;&nbsp;&nbsp;&nbsp;<a id='home'" + "style='padding-rigth:20px'" +
				    "href='http://" + locationArray[0] + "'>Home" +
				    "</a><a style='padding:10px'><img src='http://mwra.ie/images/arrow-right.gif' alt='' /></a><a id='pfolder' style='padding-rigth:20px' href='" +  pageLocation + "'>" + pageFolderFormatted +
				    "</a><a style='padding:10px'><img src='http://mwra.ie/images/arrow-right.gif' alt='' /></a><span id='page'>" + pagetitle +
				    "</span></div>" ;
		             
	                break;
	            //Two folders
	            case 4:
	                var pageLocation = "http://" + locationArray[0] + "/" + locationArray[1] + "/index.shtml";
	                var secPageFolder = locationArray[2];
	                var secPageFolderFormatted = secPageFolder.replace(/%20/g,' ');;
		            var secPageLocation = "http://" + locationArray[0] + "/" + locationArray[1] + "/" + locationArray[2] + "/index.shtml"; 
				    var objNavigation = "<div id='navElements' style='display:inline;padding-rigth:20px'>You are here:&nbsp;&nbsp;&nbsp;&nbsp;<a id='home'" + "style='padding-rigth:20px'" +
				    "href='http://" + locationArray[0] + "'>Home" +
				    "</a><a style='padding:10px'><img src='http://mwra.ie/images/arrow-right.gif' alt='' /></a><a id='pfolder' style='padding-rigth:20px' + href='" +  pageLocation + "'>" + pageFolderFormatted +
				    "</a><a style='padding:10px'><img src='http://mwra.ie/images/arrow-right.gif' alt='' /></a><a id='psecfolder' style='padding-rigth:20px' + href='" +  secPageLocation + "'>" + secPageFolderFormatted +
				    "</a><a style='padding:10px'><img src='http://mwra.ie/images/arrow-right.gif' alt='' /></a><span id='page'>" + pagetitle +
				    "</span></div>" ;
	                break;
	       }
	       objElement.innerHTML = objNavigation;
		  
		      
		    }
		 }
		 
//////////////////////////////////////////////////////////////////////////////////////////
//////////Created by Adriano
/////////Date:30/10/2008
////////Desc:Decodes the Html element
//////////////////////////////////////////////////////////////////////////////////////////
    function decodeHtml(ele)
    {
        ele.replace(/%20/g,' ');
        return ele;
    }
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////Created by Adriano da Silva ////////////////////////////////////////////////////////////////////////////////////////////////////////
///////Date:10/10/2008///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////Desc:This function swaps the images on the vertical menu bar based on the contrast set by the user////////////////////////////////////
////// It sets the div background with the image passed as argument. Also it sets the mouse pointer and the status bar of the window
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function swap(mouseAction, hoverImgHighContrast, hoverLowContrast,defImage, ele,hrefUrl)
{
	//Validate objects;
	if(ele == 'undefined' || ele == null){alert("Element is null"); return;}
	if(hoverImgHighContrast == 'undefined' || hoverImgHighContrast == null){return;}
	if(defImage == 'undefined' || defImage == null){return;}
	if(hoverLowContrast == 'undefined' || hoverLowContrast == null) {return;}
		//Get the contrast by reading the cookie object
		 var contrast = readCookie('styleStore');
		//Select the contrast and set the image
	//	alert(contrast);
		
		switch(contrast)
		{
		   
			case 'highcontrast':
				switch(mouseAction)
				{
					case 'mouseActionHover':
					
					ele.style.backgroundImage = "url(" + hoverLowContrast + ")";
					ele.style.cursor='pointer';
					///window.status = location.ref + hrefUrl;
					SwitchLocation(hrefUrl);
            		
						break;
					case 'mouseActionOut':
						ele.style.cursor='default';
						ele.style.backgroundImage = "url(" + hoverImgHighContrast + ")";
					
						break;
				}
				break;
			case 'default':
				switch(mouseAction)
				{
					case 'mouseActionOut':
						ele.style.backgroundImage = "url(" + defImage + ")";
						ele.style.cursor='default';
						break;
					case 'mouseActionHover':
						ele.style.backgroundImage = "url(" +  hoverLowContrast + ")";
						ele.style.cursor='pointer';
						SwitchLocation(hrefUrl);
						//window.status = location.ref + hrefUrl;
						break;
				}
                break;    
		}
	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////Created by Adriano da Silva/////////////////////////////////////////////////////////////////////////////////////////
////////////Date: 17/10/2008/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////Desc: This function changes the images when the user sets the contrast or the page loads./////////////////////////////
////////////It gets the contrast as an argument. If the contrast is null(in the case of the page load) it then/////////////////////
///////////Retrives the contrast from the user's cookie. If the user does not have the cookie or the cookie retuns null/////////////
//////////we set the default contrast to default and proceed to load the images/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetContrastImage(contrast)
{
	
	if(contrast == null || contrast == 'undefined'){
		 contrast = readCookie('styleStore');
	}
	if(contrast == null || contrast == 'undefined'){
		contrast ='default';
	}
	switch(contrast)
		{
			case 'highcontrast':
				document.getElementById("RA").style.backgroundImage = "url(images/RA_UP_HIGH.jpg)";
				document.getElementById("RP").style.backgroundImage = "url(images/RP_UP_HIGH.jpg)";
				document.getElementById("TD").style.backgroundImage = "url(images/Tourism_Up_High.jpg)";
				document.getElementById("ND").style.backgroundImage = "url(images/NDP_Up_High.jpg)";
				document.getElementById("SM").style.backgroundImage = "url(images/Shannon_Up_High.jpg)";
				document.getElementById("EU").style.backgroundImage = "url(images/EU_Up_High.jpg)";
				break;
			case 'default':
				document.getElementById("RA").style.backgroundImage = "url(images/RA_UP.jpg)";
				document.getElementById("RP").style.backgroundImage = "url(images/RP_UP.jpg)";
				document.getElementById("TD").style.backgroundImage = "url(images/Tourism_Up.jpg)";
				document.getElementById("ND").style.backgroundImage = "url(images/NDP_Up.jpg)";
				document.getElementById("SM").style.backgroundImage = "url(images/Shannon_Up.jpg)";
				document.getElementById("EU").style.backgroundImage = "url(images/EU_Up.jpg)";
				break;
		}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////Create by Adriano da Silva 
//////Date:17/10/2008//////////////////////////////////////////////////////////////////////////////////////////
/////Switch the location on the status bar.
//////Works only for internet by default explorer and only for Firefox if its enable
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SwitchLocation(hrefUrl)
{
    if(hrefUrl == null || hrefUrl == 'undefined'){return false;}
    var locationArray = new Array();
    locationArray = location.href.split("/");
	var arrayLen = locationArray.length;
	var newLocation = location.href.replace(locationArray[arrayLen - 1],hrefUrl);
	window.status = newLocation;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////Created by Adriano da Silva//////////////////////////////////////////////////////////////////////////////////////////////////////
///Date:10/10/2008//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///Desc: Reads the user cookie and return the values////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
 {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////