//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
function openWin(href){
	 window.open (href,"HDPopup","location=0,status=0,scrollbars=1,width=600,height=500"); 
}

//All Coding below added for Download capture user details
function initDownloads()
{
	var links = document.getElementsByTagName("A");
	
	for (i=0; i<links.length; i++) 
	{
		var linkHref = links[i].getAttribute("href");  
		var linkHref = linkHref.substr(linkHref.length - 3);
		var linkHref = linkHref.toLowerCase(linkHref);

		var downloadList = new Array()
		//List of suffixes that are to be considered as downloads
		//Update as you wish...
		downloadList['jpg'] = 1;
		downloadList['gif'] = 1;
		downloadList['pdf'] = 1;
		downloadList['mp3'] = 1;
		downloadList['mov'] = 1;
		downloadList['avi'] = 1;
		downloadList['ppt'] = 1;
		downloadList['wma'] = 1;
		downloadList['wav'] = 1;
		downloadList['flv'] = 1;
		
		if (downloadList[linkHref])
		{
			thisHref = String(links[i].getAttribute("href"));
			
			if (String(links[i].getAttribute("target")) !=null){
			thisTarget = String(links[i].getAttribute("target"));
			}else{
			thisTarget = '';
			}
			
			//links[i].onclick=function(e) {
			//	askUser(e,thisHref,thisTarget)
			//	}
			
			if (window.attachEvent) {
        		b=1;
    		} else if (window.addEventListener) {
      			b=2;
    		}
			
			switch (b) {
                case 1:
                    links[i].attachEvent("onclick",askUser);
                    break;
                case 2:
                    links[i].setAttribute("onclick","return askUser('" + thisHref + "','" + thisTarget + "')")
                    break;
                default:
                    //do nothing
            }
			
			//	askUser(e,thisHref,thisTarget)
			//	}

			//links[i].onclick=Function("askUser(window.event,'" + thisHref + "','" + thisTarget + "');return false;");
			//Function("showExample('"+x+"','"+y+"')");
			//links[i].onclick=askUser;
		}
		
	}
	
}


function askUser(url,target)
{
	
try {
	
url = window.event.srcElement.href;
thisTarget = window.event.srcElement.target;

if (String(links[i].getAttribute("target")) !=null){
			thisTarget = String(links[i].getAttribute("target"));
			}else{
			thisTarget = '';
			}
}catch(error){
	
}
	 

	loadPage('/siteINC/askUser.php?returnURL=' + url + "&target=" + target,'lightbox');
	
	//e.returnValue = false;
	//e.preventDefault();
	return false;
}
function temp(){
return true;	
}

function removeAsk(){
	
	var links = document.getElementsByTagName("A");
	
	for (i=0; i<links.length; i++) 
	{
		var linkHref = links[i].getAttribute("href");  
		var linkHref = linkHref.substr(linkHref.length - 3);
		var linkHref = linkHref.toLowerCase(linkHref);

		var downloadList = new Array()
		//List of suffixes that are to be considered as downloads
		//Update as you wish...
		downloadList['jpg'] = 1;
		downloadList['gif'] = 1;
		downloadList['pdf'] = 1;
		downloadList['mp3'] = 1;
		downloadList['mov'] = 1;
		downloadList['avi'] = 1;
		downloadList['ppt'] = 1;
		downloadList['wma'] = 1;
		downloadList['wav'] = 1;
		downloadList['flv'] = 1;
		
if (downloadList[linkHref])
		{
			thisHref = String(links[i].getAttribute("href"));
			
			if (String(links[i].getAttribute("target")) !=null){
			thisTarget = String(links[i].getAttribute("target"));
			}else{
			thisTarget = '';
			}
			
			//links[i].onclick=function(e) {
			//	askUser(e,thisHref,thisTarget)
			//	}
			
			if (window.attachEvent) {
        		b=1;
    		} else if (window.addEventListener) {
      			b=2;
    		}
			
			switch (b) {
                case 1:
                    links[i].detachEvent("onclick",askUser);
					location.reload(true);
                    break;
                case 2:
                    links[i].setAttribute("onclick","")
                    break;
                default:
                    //do nothing
            }
		}
		
	}
	
}

//	*********************************************************
//	Program: 	Lightbox
//	Author:		Nick Power 2009
//	Summary		Displays Lightboxes and center positions.
//	*********************************************************

//	Functions Include:
//	-----------------
//
//	pageDimensions() - 2009
//	scrollDetect() - 2009
//	updatePos() - 2009
//	initLightbox() - 2009
//	hideLightbox() - 2009
//	
//	Stuff used with lightbox functions but can be used with other stuff
//	opacity - originaly-5th Jan 2009 - fades the opacity of a HTML object in the DOM
//	fadeID - originaly-5th Jan 2009 - Fades a HTML Element by its ID 
//	initAjax - 2009 - Initiates the Ajax object
// 	loadpage - 2009 - loads a page into a HTML element using AJAX and the innerHTML method.
// 




//	Function pageDimensions
//	=======================
//
//	Original Author:	Nick Power, 2009
//
//	Summary: 			Returns dimensions of the viewport, page and scrolling. This function is used by the 
//						Lightbox features throughout the university college website.
//
//	Parameters (In):	itemWidth - The width (in pixels) of the element which is to be positioned absolutely 
//						centred.

function updatePos(){
	
	//We'll need to declare some variables to store the dimensions.
	var viewPortWidth;
	var viewPortHeight;
	
	var scrollX;
	var scrollY;
	
	var windowWidth;
	var windowHeight;
	
	//var boxWidth = 760;
	//var boxHeight = 500;

	if (document.getElementById('setLightBoxDimensions')){
		var boxWidth = parseInt(document.getElementById('setLightBoxDimensions').style.width);
		var boxHeight = parseInt(document.getElementById('setLightBoxDimensions').style.height);
	}else{
		var boxWidth = 500;
		var boxHeight = 430;
	}
	
	//var newDiv = document.createElement('DIV');
	//newDiv.innerHTML = 'boxWidth=' + boxWidth + ';boxHeight=' + boxHeight + ' ;';
	//document.getElementById('lightbox').appendChild(newDiv);
	
	//Depending on the browser, populate our variables with the dimensions.
	
	//Scrolling Dimensions
	if (window.pageYOffset||window.pageXOffset)
	{
		scrollX = window.pageXOffset;
		scrollY = window.pageYOffset;
	}
    else 
	{
		scrollX = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
		scrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
		
	//alert(scrollX);
	// View Port Dimensions
	if (self.innerHeight) {	// all except Explorer
		viewPortWidth = self.innerWidth;
		viewPortHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		viewPortWidth = document.documentElement.clientWidth;
		viewPortHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		viewPortWidth = document.body.clientWidth;
		viewPortHeight = document.body.clientHeight;
	}	
		
	// Window Dimensions
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
	
	scrollHeight = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	
	
	
	// Finallly-Work out the Box positioning
	
	//If there is a div with ID setLightBoxDimensions then use the top and left parameters of that div for out positioning. 
	
	//		> Grab Top, Left style property values
	
	//else
	
	// We wish to directly centre, so ...
	
	// 		> find middle point of the page (x and y)
	// 		> Now devide box width, height into 2
	// 		> Subtract this from our middle point
	

	boxX = Math.floor(viewPortWidth * 0.5) - (boxWidth / 2) + scrollX;
	boxY =  Math.floor(viewPortHeight * 0.5) - (boxHeight / 2) + scrollY;
	
	//Make sure values are at least zero
	if (boxX < 0){boxX=0;}
	if (boxY < 0){boxY=0;}

	//if the user resises the window smaller than the lightbox:
	
	//	Width - Do not move with scrolling or it will be infinite,  Keep to 0
	//	height - Move to the scroller position so that it is always visible.
	
	if (viewPortWidth < boxWidth){boxX = 0;}
	if (viewPortHeight < boxHeight){boxY = scrollY;}
	
	//Now position the Box and setup update the overlay
	if (document.getElementById('lightbox'))
	{
		objOverlay = document.getElementById('overlay');
		objLightbox = document.getElementById('lightbox');
	}
	
	objOverlay.style.width = '100%';
	objOverlay.style.height = viewPortHeight + 'px';
	objOverlay.style.top =  scrollHeight + 'px';

	if (boxY>=0 && boxX>=0){
	objLightbox.style.top = boxY + 'px';
	objLightbox.style.left =  boxX + 'px';
	}
	
	//objLightbox.innerHTML = boxX + 'px';

}


//	Function scrollDetect
//	=======================
//
//	Original Author:	Nick Power, 2008
//
//	Summary: 			Keeps the pageDimensions function operating at a certain interval.  This is so that 
//						position is 			
//						updated straight away if the user resizes the browser window, maximises, etc

function scrollDetect(){
	//Make an initial call to populate the variables.
	updatePos();
	
	//Set an interval to repeat the operation of our function
	lightboxPos = setInterval("updatePos()", 250);
	
}


//	Function initAJAX
//	=======================
//
//	Original Author:	Nick Power, 2008
//
//	Summary: 			Creates a Http Request ready for any AJAX, Makes a request and returns it into a element.

//	Parameters:			target - ID of the target element. innerHTML of this element will be set.

var xmlHttp;
function initAJAX(target){
//Setup Ajax Object
//Npower 
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      }
    }
  }
// Provide the user with a Loading message...
document.getElementById(target).innerHTML='<p><small>Loading...</small></p>';
xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)//Ok
      {
      document.getElementById(target).innerHTML=xmlHttp.responseText;
      }
    }

}
function loadPage(pageURL,target){
// Initiate / Create LightBox

// Npower 2009
if (target=='lightbox'){
	showLightbox();
}

initAJAX(target);
xmlHttp.open("GET",pageURL,true);
xmlHttp.send(null);
}

function processForm(script,frm,target){

//Set Defaults
//Npower 2009
var theForm = document.forms[frm];
var frmData = "";
//Detect if the form has File Data
   for(i=0; i<theForm.elements.length; i++){
	   
	frmData += theForm.elements[i].name + '=' + theForm.elements[i].value;
	if (i<theForm.elements.length){frmData+='&';}

}

loadPage('/siteINC/askUser-send.php?' + frmData,'lightbox');
}
//Function Showlightbox - Nick Power 2009
function showLightbox()
{
	
		// Lightbox and Overlay Elements
		objOverlay = document.getElementById('overlay');
		objLightbox = document.getElementById('lightbox');
	
		objLightbox.style.height = "auto";
		objLightbox.style.width = "auto";
		
		// Hide select boxes as they will 'peek' through the image in IE
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

		//Fade the lightbox into display
		
		//set opacity to zero
		changeOpac(0,'overlay');
		
		if (fadeID('overlay',0,80,500)){
			objLightbox.style.display = 'block';
		}
		
		if (fadeID('lightbox',0,100,600)){
			objOverlay.style.display = 'block';
		}

		
		if (document.getElementById('AofR-FlashHeader'))
		{
			document.getElementById('AofR-FlashHeader').style.visibility = 'hidden';
		}
		
		//document.getElementById('lightbox').style.width = '500px';
		
		//Start the function that detects dinmensions and positions the lightbox
		scrollDetect();
		
		//Stop scroll movement on the body (this is reverted in hidelightbox function)
		
		// View Port Dimensions
	if (self.innerHeight) {	// all except Explorer
		viewPortWidth = self.innerWidth;
		viewPortHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		viewPortWidth = document.documentElement.clientWidth;
		viewPortHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		viewPortWidth = document.body.clientWidth;
		viewPortHeight = document.body.clientHeight;
	}	
		
		//if (document.body.style.height = viewPortHeight + 'px'){alert('Body height ok')};
		//if (document.body.style.width = viewPortWidth - 17 + 'px'){alert('Body width ok')};
		//if (document.body.style.overflow = 'hidden'){alert('Body overflow ok')};
		
		document.body.style.height = viewPortHeight + 'px';
		document.body.style.width = viewPortWidth - 17 + 'px';
		document.body.style.overflow = 'hidden';
		
		return false;
	}
	
	
//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	//fade it out of display and then set display:block when fading had completed
		if (fadeID('lightbox',100,0,400)){
			
			objLightbox.style.display = 'none';
			objLightbox.innerHTML = '';
		}
		
		if (fadeID('overlay',80,0,400)){
			
			objOverlay.style.display = 'none';
			objLightbox.innerHTML = '';
			
		}


	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}

	
	if (document.getElementById('AofR-FlashHeader'))
		{
			document.getElementById('AofR-FlashHeader').style.visibility = 'visible';
		}

	//restore the visible and srollable state for body
	document.body.style.height = 'auto';
	document.body.style.overflow = 'visible';
	
	initDownloads();
	
}



function initLightbox()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}

		
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	// create lightbox div, same note about styles as above
	//var objLightbox = document.createElement("div");
	if (document.getElementById("lightbox")){
		var objLightbox = document.getElementById("lightbox");
	}else{
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
	}
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Click to close');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);

}

//2009, Npower

//fadeID - Fades an HTML object by its ID
// Example usage:

// 	fadeID('body',10,100,500);
// 	
//	This would fade the body object from 10% opacity until 100% which a delay of 500 milliseconds in between 
//	each percentage increment.

function fadeID(elementID,opacityStart,opacityEnd,delay) { 
      
   //set some defaults
    var speed = Math.round(delay / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacityStart > opacityEnd) { 
        for(i = opacityStart; i >= opacityEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + elementID + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacityStart < opacityEnd) { 
        for(i = opacityStart; i <= opacityEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + elementID + "')",(timer * speed)); 
            timer++; 
        } 
    } 
	
	//return true to indicate fading has completed - used in some lightboxing functions
	return true;
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
	
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

//End of the Lightbox functions, NP 2008

