var eDay			= 3;
	var eMonth		= 3;
	var eYear		= 2012;
	var eHour		= 9;
	var eMinute	= 30;
	var eSecond	= 0;
        var ticketForm  = false;

	function countdown()
	{
			var ed	= new Date( eYear, eMonth, eDay, eHour, eMinute, eSecond );
			var cd 	= new Date();

			var diff	= ed.getTime() - cd.getTime();

			diff = Math.round( diff / 1000 );

			d		= Math.floor( diff / 86400 );
			diff	= diff - ( d * 86400 );

			h		= Math.floor( diff / 3600 );
			diff	= diff - ( h * 3600 );

			m		= Math.floor( diff / 60 );
			diff	= diff - ( m * 60 );

			s		= diff;

			updateCountdown( d, h, m, s );
			setTimeout( 'countdown()', 1000 );
	}

	function updateCountdown( d, h, m, s )
	{
		if( d < 10 )
		{
			dv = '0' + d;
		}
		else
		{
			dv = d;
		}

		if( h < 10 )
		{
			hv = '0' + h;
		}
		else
		{
			hv = h;
		}

		if( m < 10 )
		{
			mv = '0' + m;
		}
		else
		{
			mv = m;
		}

		if( s < 10 )
		{
			sv = '0' + s;
		}
		else
		{
			sv = s;
		}

		$('#cdDays').html( dv );
		$('#cdHours').html( hv );
		$('#cdMinutes').html( mv );
		$('#cdSeconds').html( sv );
	}

function getTicket()
{
    if( ticketForm )
    {
        if( $('#fRegi').valid() )
        {
            $('#cover').show();
            sendReservation( 14, 7 );
        }
    }
    else
    {
        ticketForm  = true;
        $('#cancel-buy').show();
        $('#registration-form').slideDown();
        $('#gettickets').addClass( 'buy-ticket' );
    }
}

function clone(o) {
 return eval(uneval(o));
}

function sendReservation( tripId, firmId )
{
    var transport   = new Array();
    var extras      = new Array();
    var attributes  = new Array();
    var prices      = new Array();

    $('.price-value').each( function( i ) {
        id  = $(this).attr('id');
        id  = id.split('-');
        id  = id[id.length-1];

        prices.push( { price: $(this).val(), currencyId: $('#price-currency-' + id).val() } );
    })
    

//    $('.extra-field').each( function( i ) {
//
//        id   = $(this).attr('id');
//        id   = id.split('-');
//        id   = id[(id.length-1)];
//
//        attributes.push( { id: id, value: $(this).val() } );
//
//    });

    var type            = '';
    var reservations    = new Array();
    var fNames          = new Array();
    var lNames          = new Array();
    var emails          = new Array();
    var phones          = new Array();
    var attrs           = new Array();

    $('.extra-field-12').each( function( i ) {
        if( $(this).attr('checked') )
        {
            type = $(this).val();
        }
        attrs.push( type );
    });

    $('.rFirstName').each( function( i ){
        fNames.push( $(this).val() );
    });

    $('.rLastName').each( function( i ){
        lNames.push( $(this).val() );
    });

    $('.rEmail').each( function( i ){
        emails.push( $(this).val() );
    });

    $('.rPhone').each( function( i ){
        phones.push( $(this).val() );
    });

    

    for( var a = 0; a < fNames.length; a++ )
    {
        attributes  = new Array();
        attributes.push( { id: 12, value: attrs[a] } );

        var data    = {
                    tripId:                 tripId,
                    firmId:                 firmId,
                    prices:                 new Array(),
                    accommodationRoomId:    null,
                    transport:              transport,
                    attributes:             new Array(),
                    extras:                 new Array(),
                    client: {
                                lastName:               lNames[a],
                                firstName:              fNames[a],
                                phone:                  phones[a],
                                email:                  emails[a],
                                street:                 '',
                                street2:                '',
                                province:               '',
                                postCode:               '',
                                city:                   '',
                                country:                ''
                            },
                    state:                  1,
                    attentions:             '',
                    extras:                 extras,
                    prices:                 prices,
                    attributes:             attributes
                }

        reservations.push( data );
    }

    
    

    $.ajax({
        url: 'http://api.minitravelapp.com/reservation/save/?callback=?',
        type: "GET",
        global: false,
        data: ( { multi: 1, reservations: reservations } ),
        cache: false,
        dataType: 'json',
        success: function( msg ) {
            $('#returnOk').val( $('#returnOk').val() )
            $('#returnCancel').val( $('#returnCancel').val() )
            $('#itemNumber').val( msg.reservationNum );
            $('#paypalForm #amount').val( parseInt( $('.price-value-tpl').val() ) * fn );
            $('#paypalForm').submit();
     }
    });
 }
