//window.onload = ED_onDocLoad;
window.onunload = ED_onDocUnload;
window.onresize = ED_onDocResize;

// START: 'ED_preloadImages' function variables

//var ED_preloads = new Array(); // Contains URLs of images to be pre-loaded
// ED_preloads[ED_preloads.length] = "<URL TO IMAGE TO PRELOAD>";

// END: 'ED_preloadImages' function variables


// START: 'ED_positionLayers' function varibales

var ED_tableID = "entirePageTable";   // HTML ID of the table containing the entire page
var ED_layerIDs   = new Array();   // HTML IDs of layers to be positioned on load and window resize

// Arrays to hold X and Y pixel coordinates of layers relative to entire page's table (NOT document)
// positive values indicate position relative to entire page table's left / top
// negative values indicate position relative to entire page table's right / bottom
var ED_layerLefts = new Array();
var ED_layerTops  = new Array();


/*
This function simply calls a number of other functions.
It simply reduces the funtion calls to be made from the HTML doc when the document unloads i.e. window.onload
It simply calls a number of other functions.
This should be called from the window onload event
*/
function ED_onDocLoad()
{
  //hide horizontal scrollbars!
  //document.body.style.overflowX = 'hidden';


  ED_positionLayers(ED_layerIDs, ED_layerLefts, ED_layerTops, ED_tableID);
  //ED_tickerSetup();
  ED_navOnDocLoad(); // defined in 'nav_bar_behaviours.js' file
  ED_preloadImages(ED_preloadImages);
}

/*
This function simply calls a number of other functions.
It simply reduces the funtion calls to be made from the HTML doc when the document loads i.e. window.onunLoad
It simply calls a number of other functions.
This should be called from the window onunload event
*/
function ED_onDocUnload()
{
  ED_navOnDocUnload(); // defined in 'nav_bar_behaviours.js' file
  //if (tickerScrollID){
     //window.clearInterval(tickerScrollID);
  //}
}

/*
This function simply calls a number of other functions.
It simply reduces the funtion calls to be made from the HTML doc when the document loads i.e. window.onResize
It simply calls a number of other functions.
This should be called from the window onresize event
*/
function ED_onDocResize()
{
  //ED_tickerOnDocResize();
  ED_navOnDocResize(); // defined in 'nav_bar_behaviours.js' file
  ED_positionLayers(ED_layerIDs, ED_layerLefts, ED_layerTops, ED_tableID);
}


/*
This function uses the image URLs in the in the passed in array to pre load images
The loaded image objects then replace the URL strings in the same array.
Nothing is pre-loaded if the array is undefined or has no elements

PARAMS:
- imageURLs - An array containing strings of URLs to images to preload.

ASSUMPTIONS:
    An array called 'ED_preloads' has been declared with global scope
*/
function ED_preloadImages(imageURLs)
{
    if (imageURLs && imageURLs.length)
    {
        for (var i = 0; i < imageURLs.length; i++)
        {
            var temp = new Image();
            temp.src = imageURLs[i];
            imageURLs[i] = temp;
        }
    }
}

/*
This function changes the source property for an image object with a specified id.
Nothing is done if an object with the specified id cannot be found.

PARAMS:
- imageID     : The id of the image to change the source of.
- newImageSrc : A string of the URL of the new image.

*/
function ED_changeImageSrc(imageID, newImageSrc)
{
    var imageObj = document.getElementById(imageID);
    if (imageObj) imageObj.src = newImageSrc;
}



/*
This function positions layers relative to the width and height properties of a table.

PARAMS:
- layerIDs - An array of strings, each string is the HTML id of the layer to be positioned.
- layerLefts - An array of integers. Each integer represents the X / left coordinate position of the layer relative to the table
- layerTops - An array of integers. Each integer represents the Y / top coordinate position of the layer relative to the table
- tableID - A string of the HTML id of the table that the layers will be positioned relative to.

ASSUMPTIONS:
- The table is centred in the document window
- The table is at the very top of the document window i.e. Y coordinate = 0
- The tables width property/attribute has been set in pixels OR if not set is assumed to be 0
- The tables height property/attribute has been set in pixels OR if not set is assumed to be 0
*/
function ED_positionLayers(layerIDs, layerLefts, layerTops, tableID)
{
    var table = document.getElementById(tableID);

    if (table)
    {
        var windowWidth    = document.body.clientWidth || window.innerWidth;
        var tableLeft   = Math.round( (windowWidth  - parseInt(table.width) )  / 2 );
        if (tableLeft < 0)
        {
            tableLeft = 0; //default to 6 pixels from the left
        }
        var tableRight  = tableLeft + parseInt(table.width);
        var tableTop    = 0;
        var tableBottom = tableTop + parseInt(table.height);

        for (var i = 0; i < layerIDs.length; i++)
        {
            tempLayer = document.getElementById(layerIDs[i]);
            if (tempLayer && tempLayer.style)
            {
              //alert ( layerTops[i]  >= 0 ? tableTop  + layerTops[i]  : tableBottom + layerTops[i] );
                tempLayer.style.left = ( layerLefts[i] >= 0 ? tableLeft + layerLefts[i] : tableRight  + layerLefts[i] );
                tempLayer.style.top  = ( layerTops[i]  >= 0 ? tableTop  + layerTops[i]  : tableBottom + layerTops[i] );
            }
        }
    }
}





/*
This function changes the 'visibility' property of a specified layer to either 'hidden' or 'visible'

PARAMS:
- layerObjID - The ID of the layer in the HTML document as a string
- showLayer - A boolean; true to show and false to hide.
*/
function ED_showHideLayer(layerObjID, showLayer)
{
    var layerObj = document.getElementById(layerObjID);
    if (layerObj && layerObj.style)
        layerObj.style.visibility = (showLayer ? "visible" : "hidden");
}

/*
This function sets the rectangle for the clip region for a layer
PARAMS:
- layerID - The HTML id of the layer
- clipTop - The top value of the clip rectangle.
- clipRight - The right value of the clip rectangle.
- clipBottom - The bottom value of the clip rectangle.
- clipLeft - The left value of the clip rectange.
*/
function ED_setLayerClipRect(layerID, clipTop, clipRight, clipBottom, clipLeft)
{
    var layerObj = document.getElementById(layerID);

    if (layerObj && layerObj.style)
    {
        layerObj.style.clip = "rect(" + clipTop + ", " + clipRight + ", " + clipBottom + ", " + clipLeft + ")";
    }
}

function isFilled(ele) {
  if (ele.value == "") {
 	  ele.focus();
 		return (false);
 	}
  else{
    return (true);
  }
}
function isEmail(ele) {
  if (ele.value == "" || ele.value.indexOf('@', 0) == -1) {
 			ele.focus();
 			return false;
 	}
  else{
    return true;
  }
}

