﻿var swf = new Array();



var dailySwf = new Array();

var swfGroup1 = new Array();

//var swfGroup2 = new Array();

//var swfGroup3 = new Array();



swfGroup1[0] = "worldwide_campaign.swf";

swfGroup1[1] = "trenitalia.swf";

//swfGroup1[0] = "aniBanner1_new.swf";

//swfGroup1[1] = "aniBanner2_new.swf";

//swfGroup1[2] = "aniBanner3_new.swf";

//swfGroup1[3] = "aniBanner4_new.swf";

//swfGroup1[4] = "aniBanner5_new.swf";



//swfGroup2[0] = "fiat.swf";

//swfGroup2[1] = "intercontinental_campaign.swf";

//swfGroup2[2] = "healthcare.swf";



//swfGroup3[0] = "superga.swf";

//swfGroup3[1] = "intercontinental_campaign.swf";

//swfGroup3[2] = "automotive.swf";



dailySwf[0] = swfGroup1;

//dailySwf[1] = swfGroup2;

//dailySwf[2] = swfGroup3;



function getDailySwfGroup()

{

    var now = new Date();

    var today = now.getDate();

    var grpLength = dailySwf.length;

    grpOfToday = today % grpLength;

    return dailySwf[grpOfToday];

}



function hpsetup()

{



  // Fix the IE active state on buttons (missing pseudo classes for IE cause this bug)

  if (jQuery.browser.msie)

  {

    $('.hpBody').find('button').mousedown(function() {

            $(this).addClass('active');

          });

    $('.hpBody').find('button').mouseup(function() {

            $(this).removeClass('active');

          });

  }

/*

  // Fix the buttons for firefox so it isn't jagged.

  if (jQuery.browser.mozilla == true)

  {

    $('button').addClass('FireFoxButton');

  }

*/

  // Add the flash banner to the homepage - Automatically checks to see if the user has flash or not.



  swf = getDailySwfGroup();



var rand = Math.round(Math.random()*(swf.length-1));



/*

if (true){

*/

if(!FlashDetect.installed || !FlashDetect.majorAtLeast(9)){

/*

	$('img#immHome').attr("src","/images/intercontinental_campaign.gif");

    $('#immHomeLink').attr("href","/intercontinental/index.shtml");



*/



	$('img#immHome').attr("src","/images/worldwide_campaign.jpg");

    $('#immHomeLink').attr("href","/worldwide_campaign/index.shtml");


	//$('#immHomeLink').attr("target","_blank");



/*

    $('img#immHome').attr("src","/images/banners/m_illumino_di_meno_2010.jpg");

    $('#immHomeLink').attr("href","/it/about/amb_illumino_meno.shtml");

*/

}

    else

    {

    var so = new SWFObject("swf/"+swf[rand], "HPBanner", "451", "207", "8", "#ffffff");

    so.addParam("wmode", "transparent");

    so.write("HPBanner");

}

/*

  // Cycle through each element with the class of "tabs"

  $.each($('.tabs'), function() {



        var thisObj = $(this);



        // Replace the list with just the links.

        thisObj.find('ul').replaceWith(thisObj.find('li:first').html() + thisObj.find('li:last').html());



        // Wrap the links with the table information.

        thisObj.find('a:first').wrap('<td class="tdLeft tdLeftActive"></td>');

        thisObj.find('a:last').wrap('<td class="tdRight"></td>');

        thisObj.find('td').wrapAll('<table ><tr></tr></table>');



        //alert(thisObj.html());



        // Setup the click events for showing and hiding the correct tab.

        thisObj.find('a').click(function() {

            // Check that the user hasn't clicked on an already active tab by the td's class.

            if (!$(this).parent().hasClass('tdLeftActive') && !$(this).parent().hasClass('tdRightActive'))

            {

              // Get the div parent

              var divGroupHolder = $(this).parent().parent().parent().parent().parent();

              // Toggle its siblings to show or hide

              $(divGroupHolder).siblings().toggle();

              // Toggle the active class for these links.

              divGroupHolder.find('td:eq(0)').toggleClass('tdLeftActive');

              divGroupHolder.find('td:eq(1)').toggleClass('tdRightActive');

                    checkboxFix();

            }

            return false;

          });



      });

*/

    // Set the current Date on pickup box

    $('[name=collectionDate]').val(formatOutputDate(new Date()));



    $('[name=companyName]').each( function() {

            var cookie = unescape(readCookie("TNTBooking"));

            if(cookie)

            {

                var values = cookie.split("|");

                for(i = 0; i < values.length; i++)

                {

                    var field = values[i].split("=");

                    if(field[0] == 'companyName')

                    {

                        this.value = field[1].replace(/\+/g, " ");

                        break;

                    }

                }

            }

            else

                this.value="";

        });



    $( function() {

            var cookie = unescape(readCookie("IWPLogin"));

            if(cookie)

            {

                var values = cookie.split(":");

                for(i = 0; i < values.length; i++)

                {

                    var field = values[i].split("=");

                    if(field[0] == 'cust')

                        $('[name=customer]').val(field[1]);

                    if(field[0] == 'user')

                        $('[name=user]').val(field[1]);

                    if(field[0] == 'remember' && field[1] == 'Y')

                        $('[name=remember]').attr('checked', 'checked');

                }

            }

        });



  $('#remember').click(function() {

        if(this.checked == true)

            createCookie("IWPLogin",("cust=" + $('[name=customer]').val() + ":user=" + $('[name=user]').val() + ":lng=it:cty=it:remember=Y"),365);



        else

            eraseCookie("IWPLogin");

      });



  $('#btnPickup').click(function(){

                                 if($.trim($('#collectionDate').val()) == '')

                                 {

                                    alert('Indicare la data del ritiro della merce');

                                    return false;

                                 }

                                 if($.trim($('#companyName').val()) == '')

                                 {

                                    alert('Indicare dove deve essere effettuato il ritiro');

                                    return false;

                                 }

                                 $('#bookingForm').submit();



                                 });









  $('#btnTrack').click(function(){

                        if($.trim($('#consigNos').val()) == '')

                        {

                            alert('inserire una lettera di vettura o un riferimento mittente');

                            return false;

                        }

                         $('#trackingForm').submit();

                                  });





    $('#btnLocator').click(function(){



            $('#postcode').val($.trim($('#postcode').val()));

            $('#town').val($.trim($('#town').val()));

            $('#province').val($.trim($('#province').val()));

            if($('#town').val() =="")

            {

                alert("inserire il nome della località");

                return false;

            }

            $('#locatorForm').submit();

        });



    $('#btnTransitTimes').click(function(){



            $('#origintown').val($.trim($('#origintown').val()));

            $('#destinationtown').val($.trim($('#destinationtown').val()));

            if($('#origintown').val() =="" || $('#destinationtown').val() =="")

            {

                alert("inserire il nome di entrambe località");

                return false;

            }

            $('#transitTimesForm').submit();

        });



    $('#btnPricing').click(function(){



            $('#origintown').val($.trim($('#originTown').val()));

            $('#destinationTown').val($.trim($('#destinationTown').val()));

            if($('#originTown').val() =="" || $('#destinationTown').val() =="")

            {

                alert("inserire il nome di entrambe località");

                return false;

            }

            $('#pricingForm').submit();

        });





    $('#btnMyTNT').click(function(){



            $('#customer').val($.trim($('#customer').val()));

            $('#user').val($.trim($('#user').val()));

            $('#password').val($.trim($('#password').val()));

            if($('#customer').val() =="" || $('#user').val() =="" || $('#password').val() =="")

            {

                alert("I dati di connessione sono obbligatori");

                return false;

            }

            $('#myTNTForm').submit();

        });





}



// Prep the setup routine

$(document).ready(hpsetup);