window.addEvent('domready', function() {
  var rollup = '-305px' ;
  var rolldown = '-118px' ;
  
  $('clickarea').addEvent('click',function() {
    var pos = $('contact-pulldown').getStyle('top') ;
    if (pos == rollup) $('contact-pulldown').tween('top',rollup,rolldown) ;
    else $('contact-pulldown').tween('top',rolldown,rollup) ;
  }) ;
}) ;


/*  Functions for contact-us journey planner. */

function SetDateTimeDropDown()
{
            var currentDate = new Date();
            var hour = currentDate.getHours();
            var minute = currentDate.getMinutes();
            
            // round up the minutes to the nearest 15
            var minutes = (Math.round(minute/5))* 5            
            minutes = minutes+15;
            
            if (minutes > 59)
            {
                        minutes = minutes % 60;
                        // increment the hour
                        hour++; 
                        
                        if(hour > 23) 
                        {
                                    // increment the day
                                    day++;
                                    
                                    // set the hour to midnight
                                    hour = 0;
                        } 
            }
                        
            var month = currentDate.getMonth();
            var day = currentDate.getDate();
            var year = currentDate.getFullYear();
            
            var monthList = new Array(12);
            monthList[0]="Jan";
            monthList[1]="Feb";
            monthList[2]="Mar";
            monthList[3]="Apr";
            monthList[4]="May";
            monthList[5]="Jun";
            monthList[6]="Jul";
            monthList[7]="Aug";
            monthList[8]="Sep";
            monthList[9]="Oct";
            monthList[10]="Nov";
            monthList[11]="Dec";
            
            var displayMonthsText = new Array(3);
            var displayMonthsNumber = new Array(3);
            var followingYear = year+1;
            
            switch(month)
            {
                case 10: 
                        displayMonthsText[0] = monthList[month]+" "+year;
                        displayMonthsText[1] = monthList[month+1]+" "+year;
                        displayMonthsText[2] = monthList[0]+" "+followingYear;
                                    
                        var month2 = month+1;
                        var month3 = month+2;
                        
                        displayMonthsNumber[0] = month2+""+year;
                        displayMonthsNumber[1] = month3+""+year;
                        displayMonthsNumber[2] = "01"+followingYear;
                        break;
                                    
                case 11: 
                        displayMonthsText[0] = monthList[month]+" "+year;
                        displayMonthsText[1] = monthList[0]+" "+followingYear;
                        displayMonthsText[2] = monthList[1]+" "+followingYear;
                        
                        var currentMonth = month+1;
                        displayMonthsNumber[0] = currentMonth+""+year;
                        displayMonthsNumber[1] = "01"+followingYear;
                        displayMonthsNumber[2] = "02"+followingYear;
                        break;
                                                
                default:
                        var month2 = month+1;
                        var month3 = month+2;
                        var month4 = month+3;
                                    
                        displayMonthsText[0] = monthList[month]+" "+year;
                        displayMonthsText[1] = monthList[month2]+" "+year;
                        displayMonthsText[2] = monthList[month3]+" "+year;
                        
                        displayMonthsNumber[0] = "0"+month2+year;
                        displayMonthsNumber[1] = "0"+month3+year;
                        displayMonthsNumber[2] = "0"+month4+year;
 
                        break;
            }
 
            // Get a reference to the drop-down
            var hourDropDownList = document.getElementById("timeHours"); 
            var minutesDropDownList = document.getElementById("timeMinutes");
            var daysDropDownList = document.getElementById("dateTimeDay");
            var monthsDropDownList = document.getElementById("dateTimeMonth");
 
            // Loop through hours
            for (i = 0; i< hourDropDownList.options.length; i++)
            {    
            if (hourDropDownList.options[i].value == hour)
                        {
                                    hourDropDownList.options[i].selected = true;
                                    break;
                        }
            }
 
            // Loop through minutes
            for (k = 0; k< minutesDropDownList.options.length; k++)
            {               
            if (minutesDropDownList.options[k].value == minutes)
                        {
                                    minutesDropDownList.options[k].selected = true;
                                    break;
                        }
            }
 
            // Loop through days
            for (m = 0; m< daysDropDownList.options.length; m++)
            {    
                        if (daysDropDownList.options[m].value == day)
                        {
                                    daysDropDownList.options[m].selected = true;
                                    break;
                        }
            }
 
            // Loop through months
            for (n = 0; n< displayMonthsText.length; n++)
            {               
                         //name, value  e.g. ("May 2006", "052006")
                        monthsDropDownList.options[n]=new Option(displayMonthsText[n], displayMonthsNumber[n]);
            }
            // set current month (the first item in the array) as the selected item
            monthsDropDownList.selectedIndex = 0;
}

function AssembleParameters()
{
 
            var fixedType = document.getElementById("originaltype").value;  
            var fixedData = document.getElementById("originaldata").value;  
            var fixedName =  document.getElementById("originalname").value;
 
            var directionList = document.getElementById("fromTo"); 
            var inputText = document.getElementById("txtOrigin").value;  
            var selection = directionList.options[directionList.selectedIndex].value;
 
            //set the date and time
            document.getElementById("departureDate").value = GetDate();  
            document.getElementById("departureTime").value = GetTime();
 
            if( selection == "From") 
            {
                        document.getElementById("originData").value = fixedData;    
                        document.getElementById("originName").value = fixedName;       
                        document.getElementById("originType").value = fixedType;          
                        
                        // destination is the entered postcode
                        document.getElementById("destinationData").value = inputText;  
                document.getElementById("destinationName").value = inputText;  
                document.getElementById("destinationType").value = "p";
            }
            else 
            {           
                        document.getElementById("destinationData").value = fixedData;  
            document.getElementById("destinationName").value = fixedName;  
            document.getElementById("destinationType").value = fixedType;
 
                        // origin is the entered postcode 
                        document.getElementById("originData").value = inputText;        
                        document.getElementById("originType").value = "p";       
                        document.getElementById("originName").value = inputText; 
            }
}
 
function GetTime()
{
            var hour = document.getElementById("timeHours").options[document.getElementById("timeHours").selectedIndex].value; 
            var min = document.getElementById("timeMinutes").options[document.getElementById("timeMinutes").selectedIndex].value; 
            return hour+""+min;
}
 
function GetDate() 
{
   var day = document.getElementById("dateTimeDay").options[document.getElementById("dateTimeDay").selectedIndex].value; 
   var monthYear = document.getElementById("dateTimeMonth").options[document.getElementById("dateTimeMonth").selectedIndex].value; 
   
   return day+""+monthYear;
}
