
var locationId=null;var currentPage=0;function destroySelectServicesView(){killGoogleMap();}
function initializeSelectServicesView(){retrieveLicenseeAttributes();}
function retrieveLicenseeAttributes(){var parameters="language="+language;$.ajax({type:"GET",url:"js/httpRequests/retrieveLicenseeAttributes.php",data:parameters,dataType:"json",cache:"false",success:function(data){processLicenseeAttributesResponse(data);},error:function(XMLHttpRequest,textStatus,errorThrown){alert(textStatus+' '+errorThrown);}});}
function processLicenseeAttributesResponse(data){response=data;initializeGoogleMap();showAddress(urlDecode(response.location.googleSearchString));retrieveServices(null,'0');}
function retrieveServices(aSpan,aPageRequested){var parameters="";var aCategoryId='';var pageRequested=0;if(aSpan!=null&&aSpan!='undefined'&&aSpan!=''){$(".selectCategoryButton").removeClass('selectCategoryButton').addClass('unselectedCategoryButton');$("#"+aSpan.id).removeClass('unselectedCategoryButton').addClass('selectCategoryButton');aCategoryId=aSpan.id;}
else{aCategoryId=$(".selectCategoryButton:first").attr("id");}
$("#selectedCategory").html($(".selectCategoryButton:first").html());if(aPageRequested==undefined||aPageRequested==null||aPageRequested<0){pageRequested=0;}
else{pageRequested=aPageRequested;}
parameters+="licenseeId="+licenseeId
+"&locationId="+locationId
+"&categoryId="+aCategoryId
+"&language="+language
+"&pageRequested="+pageRequested;$.ajax({type:"GET",url:"js/httpRequests/retrieveLocationServices.php",data:parameters,dataType:"json",cache:"false",success:function(data){processLocationServicesResponse(data);},error:function(XMLHttpRequest,textStatus,errorThrown){alert(textStatus+' '+errorThrown);}});}
function getCurrency(aCurrency){if(aCurrency=="1"){return"&#36;";}
else if(aCurrency=="2"){return"&#128;";}
else if(aCurrency=="3"){return"&#163;";}}
function rgb2Hex(rgbValue){rgbValue=rgbValue.replace('rgb(','');rgbValue=rgbValue.replace(')','');var temp=rgbValue.split(',');var currentColor=temp[0];var green=temp[1];var blue=temp[2];var decColor=currentColor+256*green+65536*blue;return decColor.toString(16);}
function processLocationServicesResponse(data){var response=data;var table=buildServiceTable(response);$("#services").empty();$("#services").append(table);$("#topPagination").empty();$("#bottomPagination").empty();if(parseInt(response.count)>parseInt(response.limit)){buildPagination(response.next,response.previous,response.index,response.pageRequested,response.count,response.limit);}}
function buildServiceTable(response){var table='<table id="servicesMainTable" cellpadding="10" cellspacing="0">';if(response.services.length>0){for(var i=0;i<response.services.length;i++){if(response.services[i].id!=""&&response.services[i].durations.length>0){var rowColor='<tr>';table+=rowColor;table+='<td colspan="2">';table+='<div style="width:100%; font-size: 22px;"><b>';table+=urlDecode(response.services[i].name)+'</b>';table+='</div>';if(response.services[i].paymentType!=""){table+='<div style="width:100%; font-size: 10px; color: black; margin-top: 5px;">'
+urlDecode(response.services[i].paymentType)
+'</div>';}
if(response.services[i].description!=""){table+='<div style="width:100%; font-size: 14px; color: gray; margin-top: 5px;">'
+urlDecode(response.services[i].description)
+'</div>';}
table+='</td></tr>';table+=rowColor;table+='<td colspan="2" style="font-size: 12px;">';table+='<table class="serviceTable" width="100%" cellpadding="0" cellspacing="3">';for(var j=0;j<response.services[i].durations.length;j++){var durationText=duration2String(response.services[i].durations[j].duration_time);table+='<tr style="color: black;">';table+='<td width="40%">'+durationText+'</td>';table+='<td width="30%">';if(response.displayPrices=='1'&&response.services[i].durations[j].duration_price!=""&&response.services[i].durations[j].duration_price!="0.00"){if(language=='english'){table+=getCurrency(response.currency)+' '+response.services[i].durations[j].duration_price;}
else{table+=response.services[i].durations[j].duration_price+' '+getCurrency(response.currency);}}
table+='</td>';if(response.services[i].durations[j].duration_price!=""){var parameters="'"+response.services[i].id+"','";parameters+=response.services[i].durations[j].id+"','";parameters+=response.services[i].durations[j].duration_time+"','";parameters+=response.services[i].durations[j].duration_price+"','";parameters+=locationId+"'";if(response.services[i].displayWithoutBooking=='1'){table+='<td width="30%" style=" text-align: right;">';table+='<span>'+getElement('callLabel').innerHTML+'</span>';}
else{table+='<td width="30%" style=" text-align: right; cursor: pointer;" onClick="javascript:selectService('+parameters+');">';table+='<span class="blackLink">'+getElement('bookItLabel').innerHTML+'</span>';}
table+='</td>';}
else{table+='<td width="30%">&nbsp</td>';}
table+='</tr>';}
table+='</table>';table+='</td>';table+='</tr>';table+='<tr><td colspan="2"><div style="width:100%;height: 1px; border-bottom: 1px solid #d7d7d7;"></div></td></tr>';}}}
else{table+='<tr><td style="text-align: left; padding-left: 10px; color: gray;">'
+getElement('noServicesLabel').innerHTML+'</td></tr>';}
table+='</table>';return table;}
function buildPagination(aNext,aPrevious,anIndex,aPageRequested,aCount,aLimit){var next=aNext;var previous=aPrevious;var index=anIndex;var pageRequested=parseInt(aPageRequested);var count=parseInt(aCount);var limit=parseInt(aLimit);var totalPages=count/limit;var navigationHTML="";if(totalPages>1){navigationHTML='PAGES < ';for(var i=0;i<totalPages;i++){if(i==pageRequested){navigationHTML+='<span style="color: #7B797D;"><b>'
+(i+1)+'</b></span>&nbsp;';}
else{navigationHTML+='<span style="cursor: pointer;" '
+'onclick="retrieveServices(\'\','+i+')" >'
+'<u>'+(i+1)+'</u></span>&nbsp;';}}
navigationHTML+='>';}
else{navigationHTML="";}
$("#topPagination").append(navigationHTML);$("#bottomPagination").append(navigationHTML);}
function setLocation(aLocationId){locationId=aLocationId;}
function selectService(aServiceId,aDurationId,aDuration,aPrice,aLocationId){if(isCalendarViewModeEnabled){selectServiceForWeek(aServiceId,aDurationId,aDuration,aPrice,aLocationId);}
else{selectServiceForDay(aServiceId,aDurationId,aDuration,aPrice,aLocationId)}}
function selectServiceForDay(aServiceId,aDurationId,aDuration,aPrice,aLocationId){setFormValue('locationId',aLocationId);setFormValue('serviceId',aServiceId);setFormValue('durationId',aDurationId);setFormValue('durationValue',aDuration);setFormValue('price',aPrice);var form=getElement('schedulerForm');form.action='selectDateTime.php?c='+Math.floor(Math.random()*89430754389794750453);form.submit();}
function selectServiceForWeek(aServiceId,aDurationId,aDuration,aPrice,aLocationId){setFormValue('locationId',aLocationId);setFormValue('serviceId',aServiceId);setFormValue('durationId',aDurationId);setFormValue('durationValue',aDuration);setFormValue('price',aPrice);var form=getElement('schedulerForm');form.action='selectDateTimeForWeek.php?c='
+Math.floor(Math.random()*89430754389794750453);form.submit();}
function showWarning(myText)
{if(language=='french')
{$("#warning").dialog({dialogClass:'reddialog',autoOpen:false,modal:true,overlay:{opacity:0.5,background:"black"},resizable:false,width:'450',height:'450',bgiframe:true,buttons:{"Fermez la fenêtre":function(){closeWarningWindow();}}});}else{$("#warning").dialog({dialogClass:'reddialog',autoOpen:false,modal:true,overlay:{opacity:0.5,background:"black"},resizable:false,width:'450',height:'450',bgiframe:true,buttons:{"Close Window":function(){closeWarningWindow();}}});}
displayWarningWindow(myText,450,250);}
$(document).ready(function(){initializeSelectServicesView();});
