﻿// JScript File
// JScript File

//Function that displays a countdown clock to the specified date.
function Countdown(strMessage,strTargetID,year, month, day, hour, minute){
	
	var target = "";
	
	if(document.getElementById(strTargetID) != null){
	
	    target = document.getElementById(strTargetID);
    	
	    Today = new Date();
	    Target_Date = (new Date(year, month-1, day, hour, minute, 00));

	    //Find their difference, and convert that into seconds.
	    Time_Left = Math.round((Target_Date.getTime() - Today.getTime()) / 1000);

	    if(Time_Left < 0)
		    {
		    Time_Left = 0;
		    //target.innerHTML = "&nbsp;Hope you had a great trip!"
		    target.innerHTML = '<div>' + strMessage + '<br />Now!</div>';
	    }
	    else
		    {
		    days = Math.floor(Time_Left / (60 * 60 * 24));
		    Time_Left %= (60 * 60 * 24);
		    hours = Math.floor(Time_Left / (60 * 60));
		    Time_Left %= (60 * 60);
		    minutes = Math.floor(Time_Left / 60);
		    Time_Left %= 60;
		    seconds = Time_Left;

		    dps = 's'; hps = 's'; mps = 's'; sps = 's';
		    //ps is short for plural suffix.
		    if(days == 1) dps ='';
		    if(hours == 1) hps ='';
		    if(minutes == 1) mps ='';
		    if(seconds == 1) sps ='';
    		
		    target.innerHTML = '<div>';
		    target.innerHTML += '<span class="countHeader">' + strMessage + '</span><br />';
		    target.innerHTML += days + ' Day' + dps + ' ';

		    if(minutes < 10){
		        target.innerHTML += hours + ':0';
		    }else{
		        target.innerHTML += hours + ':';
		    }		    
		    if(seconds < 10){
		        target.innerHTML += minutes + ':0';
		    }else{
		        target.innerHTML += minutes + ':';
		    }
		    target.innerHTML += seconds;
		    target.innerHTML +='</div>';			

		    /*target.innerHTML = '&nbsp;&nbsp;Time To Departure:&nbsp;&nbsp;';
		    target.innerHTML += days + ' day' + dps + ' ';
		    target.innerHTML += hours + ' hour' + hps + '&nbsp;&nbsp;';
		    target.innerHTML += minutes + ' minute' + mps + ' ';
		    target.innerHTML += seconds + ' second' + sps ;
             */
             
		    //Recursive call, keeps the clock ticking.
		    setTimeout('Countdown("' + strMessage + '","' + strTargetID + '",' + year + ',' + month + ',' + day + ',' + hour + ',' + minute  + ');', 1000);
	    }
	}else{
	    alert("There is an error" + strTargetID + "is null");
	}
}
function redirect(strURL){
	if(strURL != ""){
		window.location.replace(strURL);
	}
}


function getWindowHeight() {
   
    var windowHeight=0;
    
    if (typeof(window.innerHeight)=='number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement&&
        document.documentElement.clientHeight) {
        windowHeight=
        document.documentElement.clientHeight;
        }
        else {
            if (document.body&&document.body.clientHeight) {
            windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

function setFooter(strContent, strFooter, strHeader) {
    if (document.getElementById) {
        
        var windowHeight=getWindowHeight();
        
        if (windowHeight > 0) {
        
            var contentElement = document.getElementById(strContent);
            var contentHeight = document.getElementById(strContent).offsetHeight;
            
            var footerElement = document.getElementById(strFooter);
            var footerHeight = footerElement.offsetHeight;
            
            var headerElement = document.getElementById(strHeader);
            var headerHeight = headerElement.offsetHeight;            
            
            if (windowHeight-(contentHeight+footerHeight+headerHeight)>=0) {
                
                
                footerElement.style.position='relative';
                //footerElement.style.top=(windowHeight-(contentHeight+footerHeight+headerHeight))+'px';
               
                contentElement.style.height = (windowHeight-(footerHeight+headerHeight))-10 +'px'; 
            }
            else {
                //footerElement.style.position='static';
            }
        }
    }
}
