// JavaScript file used to display pictures full size
//
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.
//
// Amended by Ian Billingham Jan 2006 to integrate with ...a3crg website
// Comments added to make code more readable / understandable!
//
// Amended by Ian Billingham may 2007 to add functions for Setting / Getting Cookie information
// Cookie code provided by www.webreference.com

function popImage(imageURL,imageTitle){

// SETUPS:
// ===============================

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 400;
defaultHeight = 400;

// Set the horizontal and vertical position for the popup
//PositionX = 100;
//PositionY = 100;
// Amended by IFB to reflect actual screen width
PositionX = ((screen.availWidth -defaultWidth)/ 2);
PositionY = ((screen.availHeight-defaultHeight)/2);

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = false;

// Determine the type of browser being used
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}

// Set up the pop-up window
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

// Correct the URL of the image to point to the fullsize image, rather than the thumbnail
imageURL = imageURL.replace("thumbs","fullsize");

// Open the pop-up window
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}

// Write HTML to the pop-up window to resize to image size & display Image & Title
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
// include reference to ...a3crg stylesheet
writeln('<link rel=stylesheet type="text/css" href="css/a3crg.css" title="Style"></link>');
writeln('<script>');
writeln('var isNN,isIE;');
writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');
// Regardless of browser, add 70 pixels to window height to display title at bottom
writeln('if (isIE){');
writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height)+70;');
writeln('window.resizeTo(width,height);}');
writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');
writeln('window.innerHeight=document.images["George"].height+70;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');
writeln('</script>');
if (!AutoClose) writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block">');
// Display Image tile at bottom of pop-up window
writeln('<h2 align=center>'+imageTitle+'</h2></body></html>');
close();		
}
return false
}

// -----------------------------------------------------------------------------------------------
function popNews(newsDate, newsTitle, newsText)
{
// Set these values to be the actual window size required
// no resizing will be done of the News pop-up window, but it will be scrollable
defaultWidth  = 700;
defaultHeight = 500;

// Set the horizontal and vertical position for the popup based on users screen
PositionX = ((screen.availWidth -defaultWidth)/ 2);
PositionY = ((screen.availHeight-defaultHeight)/2);

// Open the pop-up window
var optWin='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
imgWin=window.open('about:blank','',optWin);

// Write 'news' into the newly opened pop-up window
with (imgWin.document){
writeln('<html><head><title>'+newsTitle+'</title>');
// include reference to ...a3crg stylesheet
writeln('<link rel=stylesheet type="text/css" href="css/a3crg.css" title="Style"></link>');
writeln('<script type="text/javascript">');
writeln('<!--');
writeln('window.focus();');
writeln('//-->');
writeln('</script>');
writeln('</head>');
writeln('<body>');
writeln('<h1><div align=center><img src="images/icons/a3crg_logo.gif" alt="...a3crg logo" border="0" width="250" height="75"/></div></h1>');
writeln('<hr>');
writeln('<h2 align=center>'+newsTitle+'</h2>');
writeln('<h3 align=center>Release Date: '+newsDate+'</h3>');
writeln('<p>'+newsText+'<p>');
writeln('<hr>');
writeln('For more information, contact <a href=\"mailto:paddy@a3crg.co.uk?subject=RE: '+newsTitle+'\">paddy@a3crg.co.uk</a>');
writeln('</body></html>');
close();
}
return false;
}

// -----------------------------------------------------------------------------------------------
function orig_big_picture(parFileName, parComment) 
{
// alert("Parameter filename = " + parFileName);
//
// Remove 'thumbs' directory from the image location
//
fullFileName = parFileName.replace("thumbs","fullsize");
//alert("Amended Filename = " + fullFileName);
//
selfclose = "<SCRIPT LANGUAGE='JavaScript'>setTimeout('self.close()',5000);</SCRIPT>";
caption = "<CENTER><B>" + parComment + "</B></CENTER>";
// Calculate size of user's screen
w = screen.availWidth;
h = screen.availHeight;
// Set 'onload' script to resize window & move to center of screen
onload = "window.resizeTo(document.image.width+40,document.image.height+75);";
onload = onload + "window.moveTo(("+w+"-document.image.width)/2,("+h+"-document.image.height)/2);";
//
// Set HTML code for the new window
html = "<HTML><HEAD><TITLE>Big Picture</TITLE>" + selfclose + 
       "</HEAD><BODY LEFTMARGIN=10 " +
       "MARGINWIDTH=10 TOPMARGIN=10 MARGINHEIGHT=10><CENTER>" +
       "<IMG SRC='" + fullFileName + "' BORDER=0 NAME=image onload=" + onload + ">" +
       "</CENTER>" + caption + "</BODY></HTML>";
//alert(html);
//
// open new window, write HTML to load picture, etc
popup=window.open("","image","toolbar=0,directories=0,menuBar=0,scrollbars=0,resizable=1");
popup.document.open();
popup.document.write(html);
popup.document.focus();
popup.document.close();
}

// -----------------------------------------------------------------------------------------------
/*
   Added by Ian Billingham May 2007
   Code provided by www.webreference.com

   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
   Added by Ian Billingham May 2007
   Code provided by www.webreference.com

  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


// -----------------------------------------------------------------------------------------------
/*
   Added by Ian Billingham May 2007
   Code provided by www.webreference.com

   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// -----------------------------------------------------------------------------------------------
/* Added by Ian Billingham May 2007
   Code based on that found at www.somecoders.com/2006/04/retrieving-database-information-with-ajax-php-and-mysql/ 
   
   Function used to dynamically replace code within an existing HTML page
   with the output from a PHP script.
   
   [filename] - Name of the PHP script used to retrieve the replacement code.  Also name 
                of the DIV containing the code to be replaced.
   [param'n'] - Parameter(s) to be passed to PHP script
*/   
function replacecode(filename, param1, param2){
  // set up default values for optional parameters
  if (typeof param1 == "undefined") {
    param1 = '<null>';
  }
  if (typeof param2 == "undefined") {
    param2 = '<null>';
  }
  var xmlhttp=false; //Clear our fetching variable
  // alert("Called function replacecode(" + filename + "," + param1 + "," + param2 + ")" );
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
                // alert('First Kind of ActiveX Object used');
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
                        // alert('Second Kind of ActiveX Object used');
            } catch (E) {
                xmlhttp = false;
                // alert('Couldnt get an ActiveX Object');
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
                // alert('using XMLHttpRequest instead - Probably not a Microsoft browser');
        }
        var calledurl = filename + '.php'; //This is the path to the file we just finished making *
        if (!(param1=='<null>')) {
          calledurl += '?param1=' + param1;
        }
        if (!(param2 == '<null>')) {
           calledurl += '&param2=' + param2;
        }
        //alert(calledurl);
        xmlhttp.open('GET', calledurl, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
        xmlhttp.onreadystatechange=function() {
           if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                // alert(content);
                if( content ){ //Make sure there is something in the content variable
                      document.getElementById(filename).innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
                }
           }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

// -----------------------------------------------------------------------------------------------
/* Added by Ian Billingham June 2007
   creates a pop-up window for viewing PDF files (i.e. Points results)
*/

function createWindow(cUrl,cName,cFeatures) {
   var xWin = window.open(cUrl,cName,cFeatures);
}
