﻿/*
// JScript File
////////////////////////////
// Emerald Air javascript //
////////////////////////////
*/

//reSizeFrame:
//By Gary Davies 
//Created: 05 09 08
//Version 1.1a
//
//Used to resize the index.htm iframes to match the size of the document loaded.
//In    :The ID of the iFrame to be resized and a minimum height.
function reSizeFrame(frameName,minHeight) {
    	    var iframe = document.getElementById(frameName);
    	        
    	        if (iframe.contentDocument &&!(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))) {
    	           // This code is run by safari and chrome
    	           iframe.style.height="1px";
    	           iframe.style.height=iframe.contentWindow.document.height+40+"px";
    	           iframe.style.width="950px"; 
    	        }
    	        
    	        if (iframe.contentDocument &&(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))){
    	            //FF Browsers
    	            var ffversion=new Number(RegExp.$1);
    	                if (frameName !='main') {
    	                        iframe.style.width="950px";
    	                        iframe.style.height = "85px"
    	                }else{
    	                    if (ffversion>=3) {
    	                        iframe.style.height="1px";
    	                        iframe.style.height=iframe.contentDocument.documentElement.scrollHeight+10+"px";
    	                        //iframe.style.height=iframe.contentWindow.document.scrollHeight+10+"px";
    	                        iframe.style.width="950px"; 
    	                    }else{
        	                    //FF2 code
        	                    iframe.style.height="1px";
        	                    iframe.style.height = iframe.contentDocument.documentElement.scrollHeight+10+"px";
    	                        iframe.style.width="950px";
    	                    }    	                
    	                }
    	                    	                
    	        }
    	        
    	        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
    	                if (iframe.contentWindow.document.body) {
    	                // IE7 - This code is run when IE7 is running (website forces IE8 to run in IE7 mode)
    	                //var element;
    	                var d = document.getElementById(frameName);
    	                var f = d.contentWindow.document.documentElement.scrollHeight;
    	                    if (f < minHeight) {
    	                        iframe.style.height=minHeight+"px";
    	                        iframe.style.width="950px";
    	                    }else{
        	                    f=(f+20);
        	                    iframe.style.height=f+"px";
    	                        iframe.style.width="950px";
    	                    }
    	                }
                }
                
}   	        

//reSizeAllFrames():
//By Gary Davies 
//Created: 29 05 09
//Version 1.0
//This function is called to resize a named iframes (with a mininum height, just in case its a small one!)
function reSizeAllFrames() {
    	    reSizeFrame('main',500);
    	    //reSizeFrame('footer',85);
}


//ShowFrame:
//By Gary Davies 
//Created: 29 05 09
//Version 1.0
//
//Used to load a webpage into the 'main' iframe, when the "prefetch facility is used".
  function showFrame(inPage) {
                var iframe=document.getElementById('main');
                iframe.src=inPage;    	           
}   

//Used to return a value to indicate what browser the client is using
//Browser Check:
//By Gary Davies 
//Created: 05 09 08
//Version 1.0
//
//Used to return a value to indicate what browser the client is using
function testBrowser()
        {
        var userBrowser;
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
            { //test for MSIE x.x;
            var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
            if (ieversion>=8)
                userBrowser="Optimized for IE8";
            else if (ieversion>=7)
                userBrowser="Optimized for IE7";
            else if (ieversion>=6)
                userBrowser="Optimized for IE6";
            else if (ieversion>=5)
                userBrowser="Optimized for IE5";
        }
        else
            {
            if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
                var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
                if (ffversion>=3)
                    userBrowser="Optimized for FF3";
                else if (ffversion>=2)
                    userBrowser="Optimized for FF2";
                else if (ffversion>=1)
                    userBrowser="Optimized for FF1";
                }
                else {
                    userBrowser="Optimized for Chrome/Safari";
                }
        }
    return userBrowser;
    }
    
//Used to return a value to indicate what version of the js/ccs using
//Browser Check:
//By Gary Davies 
//Created: 27 05 09
//Version 1.0
//
//Used to return a value to indicate what version of the js/ccs using
function jsVersion() {
    var jsVer='.5b.2';
    return jsVer;
    }
    
        
//loadFrame:
//By Gary Davies 
//Created: 05 09 08
//Version 1.0
//
//Used to load a page in another iFrame, when the link is in a different iFrame
//FF and IE do this differently.
function loadFrame(iframeURL,frameType) {
        var userBrowser;
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
            { //test for MSIE x.x;
            var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
            if (ieversion>=8)
                userBrowser="IE8";
            else if (ieversion>=7)
                userBrowser="IE7";
            else if (ieversion>=6)
                userBrowser="IE6";
            else if (ieversion>=5)
                userBrowser="IE5";
        }
        else
            {
            userBrowser="FF";
        }
            	    
        if (userBrowser!='FF') {
            // IEBrowser
            switch(frameType){
            /* 
            Case B - We want to load the new page in the main iframe
            Case P - We want to load the new page in the _parent
            Case I - We want to load the new page from the interactive site in _parent
            */
            case 'B': parent.parent.main.location.href=iframeURL;
                      break;
            case 'P': parent.parent.location.href=iframeURL;
                      break;
            case 'I': alert('You are being transfered to our other site');
                      parent.parent.location.href=iframeURL;  
                      break;
            case 'T': parent.parent.title.location.href=iframeURL;
                      break;
                }
            }
        else {
            // FFBrowser - so use plain text
            switch(frameType){
            /* 
            Case B - We want to load the new page in the main iframe
            Case P - We want to load the new page in the _parent
            Case I - We want to load the new page from the interactive site in _parent
            */
            case 'B': top.document.getElementById('main').src='web/pages/'+iframeURL;
                      break;
            case 'P': top.document.src=iframeURL;
                      break;
            case 'I': alert('You are being transfered to our interactive site');
                      top.document.src=iframeURL;
                      break;
            case 'T': top.document.getElementById('title').src=iframeURL;
                      break;
                }
            }

   }
        
//setNews
//By Gary Davies 
//Created: 05 09 08
//Version 1.0
//
//Used to load a scrolling news story - or static 'this cannot be displayed' message if using FF
//Needs  : (BrowserType,CSS Class to use, ID of the HTML, The news story in noraml text)
//Returns: (the news story formated correctly for the users browser)
function setNews(pBrowser,pClass,pID,pStory) {
        if (pBrowser!='FF2') {
            // IEBrowser - so use marquee
            var txt="<span class='"+pClass+"' id='"+pID+"'><marquee>"+pStory+"</marquee></span>";
            return txt;
            }
        else {
            // FFBrowser - so use plain text
            var txt="<span class='"+pClass+"' id='"+pID+"'>Firefox is unable to display scrolling news</span>";
            return txt;
            }
    }



//UTC & Local Clock Display

//By Gary Davies 
//Created: 12 09 07
//Version 1.1 - updated 11 09 08
//Used to display a clock with UTC and the users local time
//Needs  : (nothing)
//Returns: HTML code for display in an 'innerHTML' of a web page control
function upclockU()
    {
        var dte=new Date();
        var udy=dte.getUTCDate();
        var umt=dte.getUTCMonth()+1;
        var uyr=dte.getUTCFullYear();
        
        var ldy=dte.getDate();
        var lmt=dte.getMonth()+1;
        var lyr=dte.getFullYear();
        
        var uhrs=dte.getUTCHours();
        var lhrs=dte.getHours();
        var umin=dte.getUTCMinutes();
        var lmin=dte.getMinutes();
        var usec=dte.getUTCSeconds();
               
        if (uhrs<=9) uhrs="0"+uhrs;
        if (lhrs<=9) lhrs="0"+lhrs;
        if (umin<=9) umin="0"+umin;
        if (lmin<=9) lmin="0"+lmin;
        if (usec<=9) usec="0"+usec;
        
        return "<span>UTC Time ► "+udy+"/"+umt+"/"+uyr+" "+uhrs+":"+umin+":"+usec+"</span>";
    }
 
//By Gary Davies 
//Created: 12 09 07
//Version 1.1 - updated 11 09 08
//Used to display a clock with UTC and the users local time
//Needs  : (nothing)
//Returns: HTML code for display in an 'innerHTML' of a web page control
function upclockL()
    {
        
        var dte=new Date();
        var udy=dte.getUTCDate();
        var umt=dte.getUTCMonth()+1;
        var uyr=dte.getUTCFullYear();
        
        var ldy=dte.getDate();
        var lmt=dte.getMonth()+1;
        var lyr=dte.getFullYear();
        
        var uhrs=dte.getUTCHours();
        var lhrs=dte.getHours();
        var umin=dte.getUTCMinutes();
        var lmin=dte.getMinutes();
        var usec=dte.getUTCSeconds();
               
        if (uhrs<=9) uhrs="0"+uhrs;
        if (lhrs<=9) lhrs="0"+lhrs;
        if (umin<=9) umin="0"+umin;
        if (lmin<=9) lmin="0"+lmin;
        if (usec<=9) usec="0"+usec;
        
        return "<span>Your Local Time ► "+ldy+"/"+lmt+"/"+lyr+" "+lhrs+":"+lmin+":"+usec+"  .</span>";
    }

//Countdown:
//By Gary Davies 
//Created: 05 10 08
//Version 1.0
//
//Used to redirect pages after a countdown
//

var cd=10;
function updateCd() {
    cd--;    
    return "<span>"+cd+" seconds</span>";
    
}


//Countdown:
//By Gary Davies 
//Created: 05 10 08
//Version 1.0
//
//Used to redirect pages after a countdown
//
function CharLeft()
        {
            var str=document.getElementById('ct100_LabCharLeft').innerHTML;
            var cl=133-str.length;
            document.getElementById('ct100_LabCharLeft').innerHTML="You Twitter message can have "+cl+" more charactors.";
        }
        
//jSCheckFrame:
//By Gary Davies 
//Created: 04 04 10
//Version 1.0
//
//Used to redirect pages if not accessed through default.aspx
//

