﻿/*
#region "History"
'20090309 - RH - Script file added, all scripts relating to the basket page live here.
'20090309 - RH - Pass accommodation name into supplements request
'20090309 - RH - Added email quote function
'20090327 - RH - Added background to table
'20090327 - RH - Fixed "hang" when email fails
#end region
*/

function Basket()
{
    this.Start=function() {
        if($('Basket_Accommodation_0')) this.SupplementSearch();
        if($('Basket_Transfers')) this.TransferSearch();
    }
    
    this.SupplementSearch=function() {
        var i=0;
        
        while($('Basket_Accommodation_' + i))
        {
            Website.Results.EmbedDisplay('&Action=SS&RoomNo=' + (i+1) + '&CID=' + $F('Basket_Accommodation_' + i) + '&AccommodationName=' + $F('Basket_AccommodationName_' + i),'Embed_Supplements_' + $F('Basket_Accommodation_' + i), 'supplementsembed');
            i++;
        }
    }
                
    this.TransferSearch=function() {
        Website.Results.EmbedDisplay('&Action=TS&Occupancy=' + $F('Basket_Adults') + ',' + $F('Basket_Children') + ',' + $F('Basket_Infants') + '&ArrivalLocation=' + $F('Basket_Transfers_ArrivalLocation') + '&DepartureDate=' + $F('Basket_StartDate') + '&DepartureLocation=' + $F('Basket_Transfers_DepartureLocation') + '&ReturnDate=' + $F('Basket_EndDate') ,'Embed_Transfers', 'transfersembed');
    }
    
    this.DisplayEmailQuote=function() {
        Website.SnapTop();
        Website.LightsOff();
        $('emailquote').show();
        $('emailquote').setStyle('position: absolute; top:100px; left: 50%; margin-left: -150px; width: 300px; background: #fff; border: 1px solid #333; z-index: 1; padding: 5px;');
        var s='';
        
        s+='<table width="100%" style="font-size: 12px; background: url(graphics/accommodation_search_bg.gif);">';
        s+='<tr><td class="red_title">Email Request</td><td align="right"><a href="javascript:void(0);" onclick="Website.Basket.HideEmailQuote();"><img alt="Close" border="0" src="graphics/close.png"/></a></td></tr>';
        s+='<tr><td class="text_white">Name:</td><td align="right"><input type="textbox" id="txt_eq_name"/></td></tr>';
        s+='<tr><td class="text_white">Email Address:</td><td align="right"><input type="textbox" id="txt_eq_email"/></td></tr>';
        s+='<tr><td class="text_white">Confirm Address:</td><td align="right"><input type="textbox" id="txt_eq_confirm"/></td></tr>';
        s+='<tr><td colspan="2" align="right"><a href="javascript:void(0);" onclick="Website.Basket.RequestEmailQuote();"><img alt="Close" border="0" src="graphics/bt_send.gif"/></a></td></tr>';
        s+='</table>';
        
        $('emailquote').innerHTML=s;
    }
    
    this.HideEmailQuote=function() {
        Website.LightsOn();
        $('emailquote').hide();
    }
    
    this.RequestEmailQuote=function() {
        if($F('txt_eq_email')=='') {
            $('txt_eq_email').setStyle('border: 2px solid #f00;');
            return;
        } else {
            //$('txt_eq_email').style='';
        }
        
        if($F('txt_eq_email')!=$F('txt_eq_confirm')) {
            $('txt_eq_email').setStyle('border: 2px solid #f00;');
            $('txt_eq_confirm').setStyle('border: 2px solid #f00;');
            return;
        } else {
           // $('txt_eq_email').style='';
           // $('txt_eq_confirm').style='';
        }   
        
        var emailaddress= $F('txt_eq_email')
        
        $('emailquote').innerHTML='Sending Email';
        
        new Ajax.Request('ajax.ashx?_t=' + ticks() + '&action=EQ&to=' + emailaddress, {
            method:'get',
            onSuccess: function(transport) {
                try {
                    if(transport.responseText=='Email Sent') {
                        $('emailquote').hide();
                        Website.LightsOn();
                        Website.Alert('Thank you','Your email has been sent');
                    } else {
                        $('emailquote').hide();
                        Website.LightsOn();
                        Website.Alert('Sorry','There was an error sending your email, please try again later');
                    }          
                } catch(e) {
                    Website.HandleError('Request Error: ' + e);
                }
            },
            onFailure: function() { 
               Website.HandleError('Request Error: ' + q);
            }
        });             
    }
       
}

