﻿// AJAX ACCOMMODATION SEARCH RESULTS TEMPLATE
// COPYRIGHT 2007-2009 DIGITAL TRIP LTD. ALL RIGHTS RESERVED.
// NO PORTION OF THIS CODE MAY BE COPIED, STORED OR DISTRIBUTED WITHOUT PRIOR WRITTEN CONSENT BY DIGITAL TRIP LTD.
var ajaxVarGoogleMapsAPI='ABQIAAAAZa-2cVAuTocH2CoT_q3u4RSbshw1CABOq_af4cO9h7xuMHHh-BQqkG0BfmRj7tOUA_3VdpNTfuafxw';
function ajaxAccommLayout(res,fId){
    var a='';
    var f='';
    var sa='';
    var flag=0;
    // Build result html
    var h='<div class="box1 outerBorder">';
    
	if(res.deposit==1 && (res.roomQty*res.roomAllocations[0].rooms[0].priceD)>0)
	{
        h+='<div class="deposit box10"><span class="text4">PAY A DEPOSIT OF JUST <span id="priced_'+fId+'" style="color:#FFF">'+ajaxVarCurrSymbol+(res.supplier!='VILLASTOGO' && res.supplier!='VILLASABROAD'?(res.roomQty*res.roomAllocations[0].rooms[0].priceD):res.roomAllocations[0].rooms[0].priceD)+'</span> PER PERSON</span></div>';
	}
	
    if(res.onRequest==1)
	{//check if property is enquiry only seperate from other if as on request takes priority MV 18/10/2010
        h+='<div class="deposit box10"><span class="text4">AVAILABILITY at this property is currently ON REQUEST</span></div>';
    }
    
    h+='<table class="tableDisplay" cellpadding="0" cellspacing="0" border="0"><tr>';
    //h+='<td valign="top" class="tdAccommImg"><img height="94" src="'+(res.imageUrl==''?'/Assets/Themes/'+themeID+'/Images/noImageAvailable.gif':res.imageUrl)+'" onerror="this.src=\'/Assets/Themes/'+themeID+'/Images/noImageAvailable.gif\'" width="138" alt="'+res.accommName+'" title="'+res.accommName+'" /></td>';
    //h+='<td valign="top" class="tdAccommDetails"><h4>'+res.accommName+'</h4>'
    h+='<td valign="top" class="fixedWidth"><h4>'+res.accommName+'</h4>'
    h+='<div class="AccommStarRating box1">'+(res.classCode==0?'Unrated':ajaxFnDrawImgLoop('/Assets/Images/Icons/'+(res.classType==1?'Star':'key')+'.gif',res.classCode,res.classCode))+'</div> Location: <strong>'+ajaxFnArraySearch(ajaxVarLoc,res.location,0,1)+'</strong><br/>';
    h+=res.description+'...<br/>';
    h+='<span id="spanPlusMinus'+fId+'"><img class="icnPlusMinus" id="imgMoreInfo'+fId+'" src="/Assets/Images/plus.gif" /></span> <a href="javascript:ajaxFnMoreInfo('+fId+',\'Click here to show more property information and images\',\'Click here to hide more property information and images\')" id="linkMoreInfo'+fId+'" class="text2">Click here to show more property information and images</a></td>';
    h+='</td><td valign="top" id="tdAccommPrice" class="box9" style="text-align:center;">PRICES FROM<h2>'+ajaxVarCurrSymbol+'<span id="price_'+fId+'">'+ajaxFnCalcPriceFrom(ajaxVarRes[fId])+'</span></h2><span style="font-size:9px">PER PERSON</span></td></tr>';
    h+='<tr><td style="height:5px;font-size:1px;">&nbsp;</td></tr>';
    if(res.reviewCount>0) h+='<tr><td class="ratings" colspan="3"><div class="fL" style="padding-top:4px;"> &nbsp;&nbsp; Customer Rating <span class="redText">('+res.reviewCount+' Reviews)</span> &nbsp;&nbsp; </div><div class="tick">'+ajaxFnDrawImgLoop('/Assets/Images/Icons/key.gif',res.reviewAvg,res.reviewAvg)+'</div><div class="fL" style="padding-top:4px;"> &nbsp;&nbsp; ('+res.reviewAvg+' out of 5) &nbsp;&nbsp; <a href="javascript:ajaxFnMoreInfo('+fId+');">Click here to read reviews</a></div></td></tr>';
    h+='<tr><td style="height:5px;font-size:1px;">&nbsp;</td></tr></table>';
    h+='<div id="ajaxMoreInfoLdr'+fId+'" style="display:none;text-align:center;padding-bottom:5px;"><strong>Loading more information...</strong><br/><img src="/Assets/Themes/'+themeID+'/Images/Loaders/AjaxLoaderBar.gif"/></div>';
    h+='<div id="ajaxMoreInfo'+fId+'" style="display:none"></div>';
    h+='<table class="tableDisplay tableAccommRow" cellpadding="0" cellspacing="0" border="0" style="width:100%">';
    for(var ra=0;ra<res.roomAllocations.length;ra++){
        h+='<tr><td class="box8 pad5 text4"><strong>Select</strong></td><td class="box8 pad5 text4"><strong>';
        //h+='Room '+(ra+1)+' (';
        if(res.roomAllocations[ra].composite==1){h+='Room Options';}else{h+='Room '+(ra+1);}
        h+=' (';
        if(res.roomAllocations[ra].adts>0 && res.roomAllocations[ra].chd==0){
            h+=res.roomAllocations[ra].adts+' adults sharing';
        }else if(res.roomAllocations[ra].adts>0 && res.roomAllocations[ra].chd>0){
            h+=res.roomAllocations[ra].adts+' adults and '+res.roomAllocations[ra].chd+' child'+(res.roomAllocations[ra].chd>1?'ren':'');
        }else if(res.roomAllocations[ra].chd>0 && res.roomAllocations[ra].adts==0){
            h+=res.roomAllocations[ra].chd+' children sharing';
        }
        //h+=')</strong></td><td class="box8 pad5 text4" align="right"><strong>Room Cost</strong></td></tr>';
        h+=')</strong></td><td class="box8 pad5 text4" align="right"><strong>';
        if(res.roomAllocations[ra].composite==1){h+='Total Cost';}else{h+='Room Cost';}
        h+='</strong></td></tr>';
        
        //build accommodation information for enquiry
        if(ra==0){
            a+='Name:          '+res.accommName+'|';
            a+='Location:      '+ajaxFnArraySearch(ajaxVarLoc,res.location,0,1)+'|';
            a+='Rating:        '+res.classCode+'';
        }
        
        for(var r=0;r<res.roomAllocations[ra].rooms.length;r++){
            //build selected accommodation for onclick
            var onclick='';
            
            if(res.roomAllocations[ra].composite==1 && res.roomAllocations[ra].rooms[r].roomName.indexOf(" {")>0){
                onclick+='Type:          '+res.roomAllocations[ra].rooms[r].roomName.replace(' {',': ').replace('|',', ').replace('}','');
            }else{
                onclick+='Type:          '+res.roomAllocations[ra].rooms[r].roomName;
            }
            onclick+=' - '+ajaxFnBoardBasis(res.roomAllocations[ra].rooms[r].boardBasis)+'|';
            onclick+='Occupancy:     '
            +(res.roomAllocations[ra].rooms[r].occMin==res.roomAllocations[ra].rooms[r].occMax?res.roomAllocations[ra].rooms[r].occMin:(res.roomAllocations[ra].rooms[r].occMin==0?res.roomAllocations[ra].rooms[r].occMax:res.roomAllocations[ra].rooms[r].occMin+' - '+res.roomAllocations[ra].rooms[r].occMax))
            +' guests'+(res.roomAllocations[ra].composite==1?'':' per room')
            +(res.roomAllocations[ra].rooms[r].occExtraChild==0?'':' (+'+res.roomAllocations[ra].rooms[r].occExtraChild+' extra child'+(res.roomAllocations[ra].rooms[r].occExtraChild>1?'ren':''))
            +'|';
            onclick+='Price:         '+res.roomAllocations[ra].rooms[r].price;
            
            
            h+='<tr'+(r%2!=0?'':' class="box2"')+'>';
            h+='<td class="pad5"><input type="radio" onclick="ajaxFnClickRadio('+fId+');objAttach(\'price_'+fId+'\').innerHTML=ajaxFnCalcPriceFrom(ajaxVarRes['+fId+']);" name="room'+res.fid+ra+'" id="room'+res.fid+ra+'-'+r+'" value="'+res.roomAllocations[ra].rooms[r].roomId+';'+res.roomAllocations[ra].rooms[r].roomRateId+'" '+(res.roomAllocations[ra].rooms[r].selected?'checked="checked"':'')+'/></td>';
           
            h+='<td class="pad5"><label for="room'+res.fid+ra+'-'+r+'"><strong>';
            if(res.roomAllocations[ra].composite==1 && res.roomAllocations[ra].rooms[r].roomName.indexOf(" {")>0){
                h+=res.roomAllocations[ra].rooms[r].roomName.replace(' {',': ').replace('|',', ').replace('}','');
            }else{
                h+=res.roomAllocations[ra].rooms[r].roomName;
            }
            h+=' - '+ajaxFnBoardBasis(res.roomAllocations[ra].rooms[r].boardBasis)+'</strong>';
            if(res.roomAllocations[ra].rooms[r].priceO>0){
                h+='<br/>Occupancy: '
                    +(res.roomAllocations[ra].rooms[r].occMin==res.roomAllocations[ra].rooms[r].occMax?res.roomAllocations[ra].rooms[r].occMin:(res.roomAllocations[ra].rooms[r].occMin==0?res.roomAllocations[ra].rooms[r].occMax:res.roomAllocations[ra].rooms[r].occMin+' - '+res.roomAllocations[ra].rooms[r].occMax))
                    +' guests'+(res.roomAllocations[ra].composite==1?'':' per room')
                    +(res.roomAllocations[ra].rooms[r].occExtraChild==0?'':' (+'+res.roomAllocations[ra].rooms[r].occExtraChild+' extra child'+(res.roomAllocations[ra].rooms[r].occExtraChild>1?'ren':'')+')')
            }
            h+='</label></td>';
            h+='<td class="pad5" align="right"><h4 class="text1">'+ajaxVarCurrSymbol+res.roomAllocations[ra].rooms[r].price+'</h4></td>';
            h+='</tr>';
        }
    }
    h+='</table>';
    /*was box8 class*/
    h+='<br style="height:2px;line-height:3px;"/>';
    h+='<div class="pad5 box4" style="width:638px;"><div style="float:right">';
    
    if(res.onRequest==0){
        h+='<input type="button" class="btnSelectContinue" id="ajaxBtn'+res.id+'" onclick="ajaxFnSelect('+fId+');" value="Select &amp; Continue" />';
    }else{
        h+='<input type="button" class="btnEnquiryFlow" id="ajaxBtn'+res.id+'" onclick="return toggleResultsEnquiry('+fId+');" value="" />';
    }
    h+='</div>';
    h+='<div class="box1 text3 fL" style="width:150px;padding:2px 2px 2px 24px;background:#FFFFFF url(/assets/images/icons/calendar_view_day.gif) no-repeat 4px 8px;">Check-In Date:<br/><strong>'+res.checkInDate+'</strong> <span class="text4">'+(res.supplier=='SEHR'?'SS':res.supplier)+'</span></div><div style="clear:both"></div></div>';
    
    //check if property is enquiry only
    if(res.onRequest==1){
    //Build Enquiry Form
    h+='<div id="divResultsEnquiry'+fId+'" style="display:none">';
    h+='<div class="divResultsEnquiry">';
	
	
    h+='<label for="contact_name1_'+fId+'">Name:</label>';
    h+='<select id="contact_name1_'+fId+'" class="boxInput">';
    h+='<option value="Mr">Mr</option>';
    h+='<option value="Mrs">Mrs</option>';
    h+='<option value="Miss">Miss</option>';
    h+='<option value="Ms">Ms</option>';
    h+='</select>';
    h+='<input type="text" class="boxInput" id="contact_name2_'+fId+'" />';
    h+='<input type="text" class="boxInput" id="contact_name3_'+fId+'" />';
    /*h+='<label for="contact_name1_'+fId+'">Agent\'s  Reference:</label>';
    h+='<input type="text" class="boxInput" id="contact_name1_'+fId+'" />';*/

    h+='<br class="cB" />';
    h+='<label for="contact_email_'+fId+'">Email:</label> <input type="text" class="boxInput" id="contact_email_'+fId+'" />';
    h+='<br class="cB" />';
    h+='<label for="contact_telno_'+fId+'">Phone:</label>';
    h+='<input type="text" class="boxInput" id="contact_telno_'+fId+'" />';
    h+='<br class="cB" />';
    h+='<label for="contact_best_'+fId+'">Best time to call:</label>';
    h+='<input type="text" class="boxInput" id="contact_best_'+fId+'" />';
    h+='<br class="cB" />';
    h+='<label for="contact_additional_'+fId+'">Comments:</label>';
    h+='<textarea class="boxInput" id="contact_additional_'+fId+'" rows="3" cols="30"></textarea>';
    h+='<br class="cB" />';
    h+='</div>';
    h+='<div class="box8 divResultsEnquirySubmit">';
    h+='<input type="button" value="" class="fR btnSendEnquiry" onclick="sendResultsEnquiry('+fId+');"/>';
    h+='<br class="cB" />';
    h+='</div>';
    h+='<div id="enquiry_details_'+fId+'"></div>';
    h+='<div id="divErrors_'+fId+'"></div>';
    h+='<div id="divContact_'+fId+'"></div>';
    h+='</div>';
    h+='</div>';
    h+='<input type="hidden" id="accomm_details_'+fId+'" value="'+a+'" />';
    h+='<input type="hidden" id="selected_details_'+fId+'" value="'+sa+'" />';
    h+='<input type="hidden" id="flight_details_'+fId+'" value="" />';//needs to be blank
    }
    h+='</div>';
    return h;
}
function ajaxAccommMoreInfoLayout(res,infos,imgs){
    var h='';
    if(imgs!=null && imgs.length!=0){
        h+='<div class="imgGallery box2">';
        h+='<strong>Image Gallery</strong>';
        h+='<div id="imgGalMain"><img id="imgGal'+res.id+'" src="'+imgs[0].getAttribute('u')+'" width="180" /></div>';
        h+='<div class="imgGalleryThumbnails">';
        h+='<span>Click a thumbnail to enlarge</span>';
        for(var i=0;i<imgs.length;i++){
            h+='<a href="#" onclick="ajaxImageGallery(\'imgGal'+res.id+'\',\''+imgs[i].getAttribute('u')+'\',\''+imgs[i].getAttribute('d')+'\');return false;" rel="enlargeimage::mouseover" rev="imgGalMain"><img src="'+imgs[i].getAttribute('u')+'" alt="'+imgs[i].getAttribute('d')+'" title="'+imgs[i].getAttribute('d')+'"id="imgGalImg'+i+'" /></a> ';
        }
        h+='<br class="cB"/></div>';
        h+='</div>';
    }
    if(infos!=null && infos.length!=0){
        for(var i=0;i<infos.length;i++){
            h+='<strong>'+infos[i].getAttribute('t')+'</strong><br/>'+infos[i].childNodes[0].nodeValue+'<br/><br/>';
        }
    }else{
        h+='<p>Sorry, there is not more information about this accommodation.</p><br/>';
    }
    h+='<br class="cB"/>';
    
    if(!(res.lon==0 && res.lat==0)){
        h+='<div>';
        h+='<div class="fL" style="margin: 0px 4px 4px 0px;;">';
        h+='<strong>Regional Map</strong><br/>';
        h+='<img src="http://maps.google.com/staticmap?center='+res.lat+','+res.lon+'&zoom=9&size=320x200&maptype=mobile\&markers='+res.lat+','+res.lon+',red\&key='+ajaxVarGoogleMapsAPI+'&sensor=false" style="border:1px solid #333;" alt="Region map of '+res.accommName+'" title="Region map of '+res.accommName+'" /> ';
        h+='</div><div class="fL">';
        h+='<strong>Local Map</strong><br/>';
        h+='<img src="http://maps.google.com/staticmap?center='+res.lat+','+res.lon+'&zoom=13&size=320x200&maptype=mobile\&markers='+res.lat+','+res.lon+',red\&key='+ajaxVarGoogleMapsAPI+'&sensor=false" style="border:1px solid #333;" alt="Local map of '+res.accommName+'" title="Local map of '+res.accommName+'" />';
        h+='</div><br class="cB"/></div>'
    }
    return h;
}
function ajaxImageGallery(id,u,t){
    $(id).src=u;
    $(id).title=t;
}
function ajaxAccommLoaderLayout(){
    // ajaxVarSearchCriteria[destination, checkIn, checkOut, duration, rooms, adt1, tng1, chd1, inf1, adt2, tng2, chd2, inf2, adt3, tng3, chd3, inf3]
    var h='<div id="ajaxLoadingBox" class="box3 box4">';
    h+='<div id="ajaxLoadingBoxInner">';
    h+='<div id="ajaxLoadingLeft">';
    h+='<h2>Please Wait...</h2>';
    h+='<img src="/Assets/Themes/'+themeID+'/Images/Loaders/AjaxLoaderBar.gif"/>';
    h+='<span id="ajaxResultCount">We have found <strong><span id="ajaxLoadingCount" class="text1">0</span></strong> results so far</span>';
    h+='<span id="ajaxLoadingSearchType" class="text1">Your <strong>Accommodation</strong> Search</span>';
    h+='<table id="ajaxLoadingSummaryTable">';
    h+='<tr><td id="tdSearchLabel">Destination:</td><td><strong>'+ajaxVarSearchCriteria[0]+'</strong></td></tr>';
    h+='<tr><td>Check In:</td><td><strong>'+ajaxVarSearchCriteria[1]+'</strong></td></tr>';
    h+='<tr><td>Check Out:</td><td><strong>'+ajaxVarSearchCriteria[2]+'</strong></td></tr>';
    h+='<tr><td>Duration:</td><td><strong>'+ajaxVarSearchCriteria[3]+' days</strong></td></tr>';
    h+='<tr><td>Rooms:</td><td><strong>'+ajaxVarSearchCriteria[4]+' rooms</strong></td></tr>';
    for(var r=1;r<=ajaxVarSearchCriteria[4];r++){
        h+='<tr><td>Room '+r+':</td><td><strong>'+(ajaxVarSearchCriteria[(4*r)+1] + ajaxVarSearchCriteria[(4*r)+2] + ajaxVarSearchCriteria[(4*r)+3])+' guests</strong></td></tr>';
    }
    h+='</table>';
    h+='</div>';
    h+='<div id="ajaxLoadingRight">'+ajaxAccommSalesMessage()+'</div>';
    h+='<br class="cB"/>';
    h+='</div>';
    h+='</div>';
    return h;
}
function ajaxAccommAvailLoaderLayout(){
    var h='<div id="ajaxLoadingBox" class="box3 box4">';
    h+='<div id="ajaxLoadingBoxInner">';
    h+='<div id="ajaxLoadingLeft">';
    h+='<h2>Please Wait...</h2>';
    h+='<img src="/Assets/Themes/'+themeID+'/Images/Loaders/AjaxLoaderBar.gif"/>';
    h+='<span id="ajaxResultCount">We are confirming pricing and availability</span>';
    h+='<span id="ajaxLoadingSearchType" class="text1">What\' Next?</span>';
    h+='We are confirming your selected accommodation pricing and availability. Once this has been confirmed, you will be offered a series of optional travel extras.';
    h+='</div>';
    h+='<div id="ajaxLoadingRight">'+ajaxAccommSalesMessage()+'</div>';
    h+='<br class="cB"/>';
    h+='</div>';
    h+='</div>';
    return h;
}
function ajaxAccommSalesMessage(){
    var h='';
    h+='<img height="70" width="118" src="/Assets/Themes/'+themeID+'/Images/AjaxLoading/magnifier.gif" alt="Searching" title="" class=""/>';
    h+='<img height="70" width="70" src="/Assets/Themes/'+themeID+'/Images/Logos/lgoFSA-Approved.gif" alt="FSA Approved" title="FSA Approved" class="fsa"/>';
    h+='<img height="59" width="116" src="/Assets/Themes/'+themeID+'/Images/Logos/lgoAbtaNum.gif" alt="Abta Protected" title="Abta Protected" class="abta"/>';
    h+='<div id="ajaxSearchMsg">';
    h+='<img height="137" width="321" src="/Assets/Themes/'+themeID+'/Images/AjaxLoading/searchMsg.gif" alt="Searching hundreds of suppliers Worldwide" title="" class=""/>';
    h+='</div>';
    return h;
}

function toggleResultsEnquiry(id){
    var el = document.getElementById('divResultsEnquiry'+id);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
    return false;
}

/*var ajaxSelectedRoom1Details = '';
var ajaxSelectedRoom2Details = '';
var ajaxSelectedRoom3Details = '';

function ajaxFnChangeSelected(sel,id,r){
    if(r==1){
        ajaxSelectedRoom1Details = sel;
    }else if(r==2){
        ajaxSelectedRoom2Details = sel;
    }else if(r==3){
        ajaxSelectedRoom3Details = sel;
    }
    objAttach('selected_details_'+id).value=ajaxSelectedRoom1Details+ajaxSelectedRoom2Details+ajaxSelectedRoom3Details;
}*/
