/* Java scripts

   Author:  Peter Wright, Saffron Walden Essex Scouts
   Created: 10 April 2005
   Updated: 15 April 2008
*/

//Globals
var DateDiff,Today,PageDate;

function getElementWithId(id){
    var obj;
    if(document.getElementById){
        /* Prefer the widely supported W3C DOM method, if
           available:-
        */
        obj = document.getElementById(id);
    }else if(document.all){
        /* Branch to use document.all on document.all only
           browsers. Requires that IDs are unique to the page
           and do not coincide with NAME attributes on other
           elements:-
        */
        obj = document.all[id];
    }else if(document.layers){
        /* Branch to use document.layers, but that will only work for
           CSS positioned elements and LAYERs that are not nested. A
           recursive method might be used instead to find positioned
           elements within positioned elements but most DOM nodes on
           document.layers browsers cannot be referenced at all.
        */
        obj = document.layers[id];
    }
    /* If no appropriate/functional element retrieval mechanism
       exists on this browser this function returns null:-
    */
    return obj||null;
}

function TimeDiff(date1, date2) {
    return ((date1.getTime() - date2.getTime())/1000);
}

/* This is called from the 'onload' part of the <body statement.
   The case statement selects the 'page_id' tests that are run.
   Typically this is a comparision between original 'updated'
   page generation time and 'now' - if this is exceeded, a call
   may be made to refresh the page.
*/
function initial(page_id){
    var form1 = document.refresh_form;	/* Embeddeded 'refresh' form */
    var updated = document.getElementById('page_updated').innerHTML;
    
    	Today    = new Date(); /* Create current time object */

    	PageDate = new Date(updated); /* Create page 'date'
    	        ( Note that 'PageDate is timed at 00:00:00!) */

        switch (page_id) {
        case 'home_page':
            if ((TimeDiff(Today,PageDate))>86400) { /* 1 day */
                    form1.submit(); 				/* force refresh */
           	}
            break;
            
        default:
        
    	}
}
