var previousId = null ;
var defaultcount = 0;
var prevcolor = null ;
var wrongMonth;
var onRequest;
var partySizeCutoffForFlightMsg;
var restrictionMssg;
var propertyOverFlowMsg;
var infantCutoffForFlightMsg;
var selectParty;
var dateMismatch;
var showControl;
var count = 0 ;
var timer ;	
var adultCount = 0;
var childCount = 0;
var infantCount = 0;
var partyCount = 0;
var countryId;
var accomBrochureId;
var bookingBrochId;
var pageLoaded = null;
var actualBookingFee = '';
var selecteddateStatus;
var propertyTypeCd;
var perPersonValFormat = "";
var sleepCount = 0;

function changeMonth(mode)
{
	document.getElementById("hdnMonthStatus").value=mode;
	return true;
}
function showHideCtrl(ctrlNm,showHide)
{
  var ctrl=document.getElementById(ctrlNm);
  if(ctrl!=null)
  {
	if(showHide)
		document.getElementById(ctrlNm).style.display='block';
	else
		document.getElementById(ctrlNm).style.display='none';
  }
}

function showCtrlTxt(ctrlNm,val)
{
  ctrl=document.getElementById(ctrlNm);
  if(ctrl!=null)
  {
	if(ctrl.firstChild==null)
	{
	   txtNd=document.createTextNode(val);
		ctrl.appendChild(txtNd);
	   ctrl.style.display='block';
	}
	else
	{
		ctrl.style.display='block';
		ctrl.firstChild.nodeValue=val;
	}
		
   }
 }

function displaySplFeatCd(featTxt)
{
	var splFeatList=featTxt.split('~');
	if(splFeatList.length>0)
	{
		for(index=0;index<splFeatList.length;index++)
		{
			if(splFeatList[index].length==0)
			 continue;
			else
			{
				var ctrlTxt=splFeatList[index].split('^');
				var ctrl = document.getElementById(ctrlTxt[0]+"Value");
				var ctrlHdr = document.getElementById(ctrlTxt[0]);
				if(ctrlTxt.length <2)
				{
				if( ctrl != null )
				{
				  ctrl.style.display = 'block';
				  ctrl.innerHTML =  trim(ctrlTxt[1],'');
				}
				    if( ctrlHdr != null )
				    {
				      ctrlHdr.style.display = 'block';
				    }
				}
				else
				{
				    if( ctrl != null )
				    {
				      ctrl.style.display = 'block';
				      ctrl.innerHTML =  trim(ctrlTxt[2],'');
				    }
				    if( ctrlHdr != null )
				    {
				      ctrlHdr.style.display = 'block';
				      if (ctrlTxt[1].length > 0)
				      {
				        ctrlHdr.innerHTML =  trim(ctrlTxt[1],'');
				      }
				    }
				}    
			}
		}
	}
}
function displayGrade(gradeTxt,gradeCtrl)
{
	var ctrl=document.getElementById(gradeCtrl);
	if(ctrl!=null)
	{
	  ctrl.innerHTML=gradeTxt;
	  ctrl.style.display="block";
	}
}
// Function for Availability calendar handling
function ShowRestrictMsg(lblBookingRestrictionMssg,bookingRestriction,dayDiff, bookingFeeControl)
{
    var objrestriction  = document.getElementById('hdnRestriction');
    
    if(objrestriction != null)
    {
	    var cacheRestriction = parseInt(document.getElementById('hdnRestriction').value,10);	
	    var showMsg;
	    var showTime
	    if(parseInt(dayDiff,10) <= parseInt(cacheRestriction,10))
	    {
		    showMsg=true;
		    showTime=true;
	    }
	    if((parseInt(bookingRestriction,10)>0) && (parseInt(dayDiff,10) > parseInt(bookingRestriction,10)))
	    {
	      showMsg=true;
	    }
	    if(showMsg)
	    {
	      restrictionMssg=lblBookingRestrictionMssg!=null?lblBookingRestrictionMssg.firstChild.nodeValue:"";
	      restrictionMssg=showTime?cacheRestriction>0?restrictionMssg.replace(/%RSD/,cacheRestriction):restrictionMssg.replace(/%RSD/,""):restrictionMssg;
	      showCtrlTxt('lblBookingRestrictionMssg',restrictionMssg);
	      //showHideCtrl( bookingFeeControl,false );//CR107 Comment
	      return false;
	    }
	}
	return true;
}
function ShowPriceInfo(actualPrice,duration,calDate,dayVal)
{
var showPriceInfo =  actualPrice.replace(/&lt;/g,"<");
showPriceInfo = showPriceInfo.replace(/&gt;/g,">");
showPriceInfo = showPriceInfo.replace(/%NoDays/,duration);
showPriceInfo = showPriceInfo.replace(/%StDate/,calDate);
showPriceInfo = showPriceInfo.replace(/%StDay/,dayVal);
var lblPrice=document.getElementById('lblPrice') ;
if(lblPrice !=null)	
	{
		lblPrice.style.display= "block";
		lblPrice.innerHTML = showPriceInfo;
	}
}
function CaclculatePriceWithFlight(flightPrice,originalPrice,currencySymbol,seperator)
{
originalPrice=flightPrice!=""?originalPrice+parseFloat(flightPrice):originalPrice;
originalPrice=currencySymbol+originalPrice.toFixed(2);
originalPrice=originalPrice.replace( ".",seperator);
return originalPrice;
}

//Parameters changed for CR104
function DisplayPriceDiscount( cellId,status,addFee,seperator,actBasePrice,actbookingFee,actdiscount,bookingRestriction,dayVal,discountType,calDate,dayDiff,displaySleep , displayStartDays,displayFeatureCd,displaySplFeatureCd,gradeText,totalFee,classADisplayOption,classADisplayText,bcDisplayText,priceAfterDiscount,accomBrochId,country,bookingBrId, numberOfBeds, bedAttrFormatted, isAP, isHSCal, hsBookingLink )
{	
//debugger;
var isAPBool=(isAP.toLowerCase() == 'False'.toLowerCase() ? false : true);
var lblStartDateValue=document.getElementById('lblStartDateValue') ;
var hdnDefault=document.getElementById('hdnDefault') ;
var hdnSelectedDates=document.getElementById('hdnSelectedDates') ;
var lblSleepValue=document.getElementById('lblSleepValue') ;
//var hdnSleeps=document.getElementById('hdnSleeps') ;
var lblBookingRestrictionMssg=document.getElementById('lblBookingRestrictionMssg') ;
var lblPriceValue=document.getElementById('lblPriceValue') ;
var lblPriceWording= document.getElementById('lblPriceWording') ;
var lblPrice=document.getElementById('lblPrice') ;
var hypDiscounts=document.getElementById('hypDiscounts') ;

var imgBtnBookCottage=document.getElementById('imgBtnBookCottage') ;
var hdnBasePrice=document.getElementById('hdnBasePrice') ;
//var hdnStatus=document.getElementById('hdnStatus') ;
//var hdnPriceMoney=document.getElementById('hdnPriceMoney') ;
var hdnStartDate=document.getElementById('hdnStartDate') ;
var lblDiscount=document.getElementById('lblDiscount') ;
var imgDiscount=document.getElementById('imgDiscount') ;
var lblNowValue=document.getElementById('lblNowValue') ;
var lblWas=document.getElementById('lblWas') ;
var lblWasValue=document.getElementById('lblWasValue') ;
var lblNow=document.getElementById('lblNow') ;
var lblSavingValue=document.getElementById('lblSavingValue') ;
var lblSaving=document.getElementById('lblSaving') ;
var lblReducedValue=document.getElementById('lblReducedValue') ;
var lblReduced= document.getElementById('lblReduced') ;
var lblStartDayValue=document.getElementById('lblStartDayValue' );
var lblGradingValue=document.getElementById('lblGradingValue');
var lblFeatureCode=document.getElementById('lblFeatureCode');
var lblBookingFeeAddedInfo=document.getElementById(isAPBool ? 'lblBookingFeeAddedInfo' : 'lblBookingFee');
var currencySymbol=document.getElementById('hdnCurrencySymbol').value;
var hypBookNow=document.getElementById('hypBookNow');
var hypBookNowBtm=document.getElementById('hypBookNowBtm');
var tdDsc=document.getElementById('tdDsc'); 
var lblBNoV=document.getElementById('lblBNoV');
var lblBNo=document.getElementById('lblBNo');
var divBedAttr=document.getElementById('divBedAttr');
var hdnHSBookingLink=document.getElementById('hdnHSBookingLink');//Added for CR112
var isHSCalBool = (isHSCal.toLowerCase() == 'False'.toLowerCase() ? false : true);
var totalPrice;//Added for CR114

//Added for CR114
totalPrice = parseFloat(priceAfterDiscount).toFixed(2);

if(hdnHSBookingLink != null)
{
    hdnHSBookingLink.value = hsBookingLink
}

if(!isAPBool)
{
    if(lblBNoV != null)
    {
        if(numberOfBeds > 0)
        {
            lblBNoV.innerHTML = numberOfBeds;
            if(lblBNo != null)
            {
               lblBNo.style.display='block';
            }
            lblBNoV.style.display='block';
        }
        else
        {
            if(lblBNo != null)
            {
               lblBNo.style.display='none';
            }
            lblBNoV.style.display='none';
        }
    }
    else
    {
       if(lblBNo != null)
            {
               lblBNo.style.display='none';
            } 
    }
    if (divBedAttr != null)
    {
        divBedAttr.innerHTML = bedAttrFormatted;
        divBedAttr.style.display='block';
    }
}


accomBrochureId=accomBrochId;
countryId=country;
bookingBrochId = bookingBrId;

showCtrlTxt('lblStartDayValue',displayStartDays);
displayGrade(gradeText,'lblGradingValue');
if( lblFeatureCode != null)
{
    lblFeatureCode.innerHTML = displayFeatureCd;
}
showCtrlTxt('lblStartDateValue',calDate);
showCtrlTxt('lblSleepValue',displaySleep);
showHideCtrl('lblPets',false);
showHideCtrl('lblSwimmingPool',false);
showHideCtrl('lblOpenFire',false);
showHideCtrl('lblPubNearBy',false);
showHideCtrl('lblGoldAward',false);
showHideCtrl('lblGarden',false);
showHideCtrl('lblCloseToBeach',false);
showHideCtrl('lblShrtBrk',false);
showHideCtrl('lblPetsValue',false);
showHideCtrl('lblSwimmingPoolValue',false);
showHideCtrl('lblOpenFireValue',false);
showHideCtrl('lblPubNearByValue',false);
showHideCtrl('lblGoldAwardValue',false);
showHideCtrl('lblGardenValue',false);
showHideCtrl('lblCloseToBeachValue',false);
showHideCtrl('lblShrtBrkValue',false);

displaySplFeatCd(displaySplFeatureCd);

hdnStartDate.value = calDate;	

if( actBasePrice > 0 )
{
    actBasePrice=totalFee;
}
	
var newActBKfee = parseFloat(actbookingFee);
newActBKfee=newActBKfee.toFixed(2);

selecteddateStatus = status;

clearInterval( timer );
var ctrlCellOrev ;
if( previousId == null )
	previousId=document.getElementById('hdnDefault').value;

var prevCell = document.getElementById(previousId);
prevCell.style.borderColor="#ffffff";
prevCell.style.borderWidth="1px";
var currCell = document.getElementById(cellId);
currCell.style.borderColor=document.getElementById("hdnDefaultColor").value;
currCell.style.borderWidth="1px";
currCell.style.borderStyle="solid";

previousId = cellId ;
if(hdnSelectedDates!=null)
	hdnSelectedDates.value = calDate + "|" + hdnSelectedDates.value;
	
hideElements();	

if(bcDisplayText.length>0 && tdDsc != null )
{
	tdDsc.style.display='block';
	tdDsc.innerHTML = bcDisplayText;
}
 else
  {
        if( tdDsc != null )
        {
            tdDsc.style.display='none';
        }
   }

// Application of Booking restriction
if(actBasePrice !=0 )
{
/*--CR107 Comment Start --*/
	/*if( !ShowRestrictMsg(lblBookingRestrictionMssg,bookingRestriction,dayDiff, isAPBool ? 'lblBookingFeeAddedInfo' : 'lblBookingFee'))
	 return false;*/
/*--CR107 Comment End --*/	 
	 
	if(addFee == "Y" && parseFloat(newActBKfee,10) > 0)
    {
	    actualBookingFee=actualBookingFee.replace(/%BF/,(currencySymbol+newActBKfee));
	    actualBookingFee=actualBookingFee.replace(".",seperator);
	    showCtrlTxt(isAPBool ? 'lblBookingFeeAddedInfo' : 'lblBookingFee',actualBookingFee);
    }	
    else
	    showHideCtrl(isAPBool ? 'lblBookingFeeAddedInfo' : 'lblBookingFee',false);
	
	var baseRentalPrice = actBasePrice.toString().replace(seperator,".");
	var bookingFee = actbookingFee.replace(seperator,"."); 
	var discount = actdiscount.replace(seperator,".");
	var flightPrice = ""; //changed for CR112
	var actualPrice = document.getElementById('hdnPriceInfo').value;
	var duration = document.getElementById('hdnDuration').value;
	
	//added for CR112
	if(document.getElementById('hdnFlightPrice') != null)
	{
	    flightPrice = document.getElementById('hdnFlightPrice').value.replace(seperator,"."); 
	}
	
	/*--CR107 Comment Start --*/
	/*if(hypBookNow !=null)
		hypBookNow.style.display = "block";*/
    /*-- CR107 Comment End --*/
    
	//if(lblPriceWording !=null)	
	//	lblPriceWording.style.display= "block";
	ShowPriceInfo(actualPrice,duration,calDate,dayVal);
	hdnStartDate.value = calDate;	
	if( classADisplayText.length >0 && lblDiscount!=null )
	{
		lblDiscount.style.display='block'
		lblDiscount.innerHTML = classADisplayText;
	}
    else
    {
        if( lblDiscount != null )
        {
            lblDiscount.style.display='none'
        }
    }
	if(classADisplayOption.length <= 0)
	{
		hdnBasePrice.value = actBasePrice.toString().replace(seperator,".");
		var priceMoney = parseFloat(actBasePrice.toString().replace(seperator,"."))-parseFloat(discount);
		
		var showPrice;
		priceAfterDiscount=flightPrice !=""?parseFloat(priceAfterDiscount)+ parseFloat(flightPrice):parseFloat(priceAfterDiscount);
		priceAfterDiscount = priceAfterDiscount.toFixed(2);
		var basePrice = priceAfterDiscount.toString().replace(".",seperator);
		showPrice = currencySymbol+ basePrice;
		showCtrlTxt('lblPriceValue',showPrice);
		//ShowPriceInfo(actualPrice,duration,calDate,dayVal);
		if(lblPriceWording !=null)	
	    	lblPriceWording.style.display= "block";
	}
	else
	{
		displayOptionType = classADisplayOption.split('~')[0];
		displayvalue = classADisplayOption.split('~')[1];
		    
		switch(displayOptionType)
		{
			case "W":
				if( lblWas !=null )
				 lblWas.style.display = "block";
				if( lblWasValue !=null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[0]);
				   showCtrlTxt('lblWasValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
				if( lblNow!=null)
				 lblNow.style.display = "block";
				if( lblNowValue != null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[1]);
				   showCtrlTxt('lblNowValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
			break; 
			case "S" :
				ShowPriceInfo(actualPrice,duration,calDate,dayVal);
				if( lblPriceValue != null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[0]);
				   showCtrlTxt('lblPriceValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
				if(lblPriceWording !=null)	
	    	        lblPriceWording.style.display= "block";
				if (lblSaving != null)
					lblSaving.style.display = "block";
				if (lblSavingValue != null)
					showCtrlTxt('lblSavingValue',currencySymbol+parseFloat(displayvalue.split('|')[1]).toFixed(2));
			break;
		  case "R" :
				if( lblReduced !=null)
					lblReduced.style.display = "block";
				if(lblReducedValue !=null)
				 showCtrlTxt('lblReducedValue',currencySymbol+parseFloat(displayvalue).toFixed(2) );
		  break;
		}
	}
	
	//Added for CR114
    ShowPerPersonValue(flightPrice,duration,totalPrice,currencySymbol,seperator);
	
    if(!isHSCalBool)
    {
        /*-- CR107 Block Addition Start --*/			
        if( !ShowRestrictMsg(lblBookingRestrictionMssg,bookingRestriction,dayDiff, isAPBool ? 'lblBookingFeeAddedInfo' : 'lblBookingFee'))
         return false;
        else
        {
            if(hypBookNow !=null)
    	        hypBookNow.style.display = "block";          
	    }
    }
    else if(hsBookingLink.toUpperCase() == "CALL TO BOOK")
    {      
        if(hsBookingLink.toUpperCase() == "CALL TO BOOK")
        {
            if(lblBookingRestrictionMssg != null)
            {
                lblBookingRestrictionMssg.style.display = "block";
            }
            
            if(hypBookNowBtm !=null)
	            hypBookNowBtm.style.display = "none";
	            
            return false;
        }
    }
    else if(hsBookingLink = null || hsBookingLink == "")
    {
        if(hypBookNow !=null)
            hypBookNow.style.display = "none";
            		            
        if(hypBookNowBtm !=null)
            hypBookNowBtm.style.display = "none";
    }
    else 
    {
        if(lblBookingRestrictionMssg != null)
        {
            lblBookingRestrictionMssg.style.display = "none";
        }
                
        if(hypBookNow !=null)
            hypBookNow.style.display = "block";
            
        if(hypBookNowBtm !=null)
            hypBookNowBtm.style.display = "block";
    }
    
    /*-- CR107 Block Add End --*/
	        startBlink() ;
	
}	
		
}

//only for sister cottage--Parameters changed for CR104
function DisplayPriceDiscount_SisCot( cellId,status,addFee,seperator,actBasePrice,actbookingFee,actdiscount,bookingRestriction,dayVal,discountType,calDate,dayDiff,displaySleep ,displayStartDays,displayFeatureCd,displaySplFeatureCd,gradeText,totalFee,classADisplayOption,classADisplayText,bcDisplayText,priceAfterDiscount,accomBrochId,country,bookingBrId,propertyCodes,lengthOfStay,propertyIds, displayAccomCodes, sleepValues, count,pdURL,propDate, priceguideText, numberOfBeds, bedAttrFormatted)
{	

//debugger;
var lblStartDateValue=document.getElementById('lblStartDateValue') ;
var hdnDefault=document.getElementById('hdnDefault') ;
var hdnSelectedDates=document.getElementById('hdnSelectedDates') ;
var lblSleepValue=document.getElementById('lblSleepValue') ;
//var hdnSleeps=document.getElementById('hdnSleeps') ;
var lblBookingRestrictionMssg=document.getElementById('lblBookingRestrictionMssg') ;
var lblPriceValue=document.getElementById('lblPriceValue') ;
var lblPriceWording= document.getElementById('lblPriceWording') ;
var lblPrice=document.getElementById('lblPrice') ;
var hypDiscounts=document.getElementById('hypDiscounts') ;

var imgBtnBookCottage=document.getElementById('imgBtnBookCottage') ;
var hdnBasePrice=document.getElementById('hdnBasePrice') ;
//var hdnStatus=document.getElementById('hdnStatus') ;
//var hdnPriceMoney=document.getElementById('hdnPriceMoney') ;
var hdnStartDate=document.getElementById('hdnStartDate') ;
var lblDiscount=document.getElementById('lblDiscount') ;
var imgDiscount=document.getElementById('imgDiscount') ;
var lblNowValue=document.getElementById('lblNowValue') ;
var lblWas=document.getElementById('lblWas') ;
var lblWasValue=document.getElementById('lblWasValue') ;
var lblNow=document.getElementById('lblNow') ;
var lblSavingValue=document.getElementById('lblSavingValue') ;
var lblSaving=document.getElementById('lblSaving') ;
var lblReducedValue=document.getElementById('lblReducedValue') ;
var lblReduced= document.getElementById('lblReduced') ;
var lblStartDayValue=document.getElementById('lblStartDayValue' );
var lblGradingValue=document.getElementById('lblGradingValue');
var lblFeatureCode=document.getElementById('lblFeatureCode');
var tabFeatureCtrl=document.getElementById('tabFeatureCtrl');
var lblBookingFeeAddedInfo=document.getElementById('lblBookingFee');
var currencySymbol=document.getElementById('hdnCurrencySymbol').value;
var hypBookNow=document.getElementById('hypBookNow');
var tdDsc=document.getElementById('tdDsc'); 
var sisCot=document.getElementById('divSisCottage');
var lblPriceGuideValue = document.getElementById('lblPriceGuideValue');
var lblBNoV=document.getElementById('lblBNoV');
var lblBNo=document.getElementById('lblBNo');
var divBedAttr=document.getElementById('divBedAttr');
var totalPrice;

//Added for CR114
totalPrice = parseFloat(priceAfterDiscount).toFixed(2);

accomBrochureId=accomBrochId;
countryId=country;
bookingBrochId = bookingBrId;

//sister cottage
if (count > 0 && sisCot != null)
{
    var sisCotCount = 0;
    var arrPropertyCodes = propertyCodes.split(',');
    var arrPropertyIds = propertyIds.split(',');
    var arrDisplayAccomCodes = displayAccomCodes.split(',');
    var arrSleepValues = sleepValues.split(',');
    
    var noOfColumn = parseInt(sisCot.attributes["noofcol"].value,10);
    if(noOfColumn == null)
        noOfColumn = 3;
        
    var noRows = Math.floor(count % noOfColumn == 0 ? count / 2 : (count / noOfColumn) + 1);

    var tableString = "<table class=\"classSisCot\">";
    
    for(var i = 0; i < noRows; i++)
    {
        tableString += "<tr>";
        
        var sisCotURL = pdURL;
        for(var j=0; j<noOfColumn && sisCotCount < count; j++)
        {
            sisCotURL = sisCotURL.replace("{1}",arrPropertyCodes[sisCotCount]);
            sisCotURL = sisCotURL.replace("{2}",countryId);
            sisCotURL = sisCotURL.replace("{3}",lengthOfStay);
            sisCotURL = sisCotURL.replace("{4}",propDate);
            sisCotURL = sisCotURL.replace("{5}",arrPropertyIds[sisCotCount]);
            tableString += "<td><a href=\"";
            tableString += sisCotURL;
            tableString += "\" target=\"_self\">";
            tableString += arrDisplayAccomCodes[sisCotCount];
            tableString += "</a>&nbsp;&nbsp;Sleeps&nbsp;";
            tableString += arrSleepValues[sisCotCount++];
            tableString += "</td>";
        }
        tableString += "</tr>";
    }
    tableString += "</table>";
    
    sisCot.innerHTML = tableString;
    tableString = null;
    arrPropertyCodes = null;
    arrPropertyIds = null;
    arrDisplayAccomCodes = null;
    arrSleepValues = null;

}
if(lblBNoV != null)
{
    if(numberOfBeds > 0)
    {
        lblBNoV.innerHTML = numberOfBeds;
        if(lblBNo != null)
        {
            lblBNo.style.display = 'block';
        }
        lblBNoV.style.display='block';
    }
    else
    {
        if(lblBNo != null)
        {
            lblBNo.style.display = 'none';
        }
        lblBNoV.style.display='none';
    }
}
else
{
  if(lblBNo != null)
        {
            lblBNo.style.display = 'none';
        }  
}
if (divBedAttr != null)
{
    divBedAttr.innerHTML = bedAttrFormatted;
    divBedAttr.style.display='block';
}

showCtrlTxt('lblStartDayValue',displayStartDays);
displayGrade(gradeText,'lblGradingValue');
if( lblFeatureCode != null)
{
    lblFeatureCode.innerHTML = displayFeatureCd;
}
if( tabFeatureCtrl != null)
{
    tabFeatureCtrl.innerHTML = displayFeatureCd;
}
if( lblPriceGuideValue != null)
{
    lblPriceGuideValue.innerHTML = priceguideText;
}

showCtrlTxt('lblStartDateValue',calDate);
showCtrlTxt('lblSleepValue',displaySleep);
showHideCtrl('lblPets',false);
showHideCtrl('lblSwimmingPool',false);
showHideCtrl('lblOpenFire',false);
showHideCtrl('lblPubNearBy',false);
showHideCtrl('lblGoldAward',false);
showHideCtrl('lblGarden',false);
showHideCtrl('lblCloseToBeach',false);
showHideCtrl('lblShrtBrk',false);
showHideCtrl('lblPetsValue',false);
showHideCtrl('lblSwimmingPoolValue',false);
showHideCtrl('lblOpenFireValue',false);
showHideCtrl('lblPubNearByValue',false);
showHideCtrl('lblGoldAwardValue',false);
showHideCtrl('lblGardenValue',false);
showHideCtrl('lblCloseToBeachValue',false);
showHideCtrl('lblShrtBrkValue',false);

displaySplFeatCd(displaySplFeatureCd);

hdnStartDate.value = calDate;	

if( actBasePrice > 0 )
{
    actBasePrice=totalFee;
}
	
var newActBKfee = parseFloat(actbookingFee);
newActBKfee=newActBKfee.toFixed(2);

selecteddateStatus = status;

clearInterval( timer );
var ctrlCellOrev ;
if( previousId == null )
	previousId=document.getElementById('hdnDefault').value;

//////debugger;
var prevCell = document.getElementById(previousId);
prevCell.style.borderColor="#ffffff";
prevCell.style.borderWidth="1px";
var currCell = document.getElementById(cellId);
currCell.style.borderColor=document.getElementById("hdnDefaultColor").value;
currCell.style.borderWidth="1px";
currCell.style.borderStyle="solid";

previousId = cellId ;
if(hdnSelectedDates!=null)
	hdnSelectedDates.value = calDate + "|" + hdnSelectedDates.value;
	
hideElements();	
if(bcDisplayText.length>0 && tdDsc != null )
{
	tdDsc.style.display='block';
	tdDsc.innerHTML = bcDisplayText;
}
 else
  {
        if( tdDsc != null )
        {
            tdDsc.style.display='none';
        }
   }

// Application of Booking restriction
if(actBasePrice !=0 )
{
/*-- CR107 Code Comment Start --*/
	/*if( !ShowRestrictMsg(lblBookingRestrictionMssg,bookingRestriction,dayDiff, 'lblBookingFee'))
	 return false;*/
/*-- CR107 Code Comment End --*/
	 
	if(addFee == "Y" && parseFloat(newActBKfee,10) > 0)
    {
	    actualBookingFee=actualBookingFee.replace(/%BF/,(currencySymbol+newActBKfee));
	    actualBookingFee=actualBookingFee.replace(".",seperator);
	    showCtrlTxt('lblBookingFee',actualBookingFee);
    }	
    else
	    showHideCtrl('lblBookingFee',false);
	
	var baseRentalPrice = actBasePrice.toString().replace(seperator,".");
	var bookingFee = actbookingFee.replace(seperator,"."); 
	var discount = actdiscount.replace(seperator,".");
	var flightPrice = document.getElementById('hdnFlightPrice').value.replace(seperator,"."); 
	var actualPrice = document.getElementById('hdnPriceInfo').value;
	var duration = document.getElementById('hdnDuration').value;
	
	/*-- CR107 Comment Start --*/
	/*if(hypBookNow !=null)
		hypBookNow.style.display = "block";*/
	/*-- CR107 Comment End --*/	
		
	//if(lblPriceWording !=null)	
	//	lblPriceWording.style.display= "block";
	
	ShowPriceInfo(actualPrice,duration,calDate,dayVal);
	hdnStartDate.value = calDate;	
	if( classADisplayText.length >0 && lblDiscount!=null )
	{
		lblDiscount.style.display='block'
		lblDiscount.innerHTML = classADisplayText;
	}
    else
    {
        if( lblDiscount != null )
        {
            lblDiscount.style.display='none'
        }
    }
	if(classADisplayOption.length <= 0)
	{   
		hdnBasePrice.value = actBasePrice.toString().replace(seperator,".");
		var priceMoney = parseFloat(actBasePrice.toString().replace(seperator,"."))-parseFloat(discount);
		
		var showPrice;
		priceAfterDiscount=flightPrice !=""?parseFloat(priceAfterDiscount)+ parseFloat(flightPrice):parseFloat(priceAfterDiscount);
		priceAfterDiscount = priceAfterDiscount.toFixed(2);
		var basePrice = priceAfterDiscount.toString().replace(".",seperator);
		showPrice = currencySymbol+ basePrice;
		showCtrlTxt('lblPriceValue',showPrice);
		//ShowPriceInfo(actualPrice,duration,calDate,dayVal);
		if(lblPriceWording !=null)	
	    	lblPriceWording.style.display= "block";
	}
	else
	{
		displayOptionType = classADisplayOption.split('~')[0];
		displayvalue = classADisplayOption.split('~')[1];
		
		switch(displayOptionType)
		{
			case "W":
				if( lblWas !=null )
				 lblWas.style.display = "block";
				if( lblWasValue !=null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[0]);
				   showCtrlTxt('lblWasValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
				if( lblNow!=null)
				 lblNow.style.display = "block";
				if( lblNowValue != null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[1]);
				   showCtrlTxt('lblNowValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
			break; 
			case "S" :
				ShowPriceInfo(actualPrice,duration,calDate,dayVal);
				if( lblPriceValue != null )
				{
				   wasvalue = parseFloat(displayvalue.split('|')[0]);
				   showCtrlTxt('lblPriceValue',CaclculatePriceWithFlight(flightPrice,wasvalue,currencySymbol,seperator));
				}
				if(lblPriceWording !=null)	
	    	        lblPriceWording.style.display= "block";
				if (lblSaving != null)
					lblSaving.style.display = "block";
				if (lblSavingValue != null)
					showCtrlTxt('lblSavingValue',currencySymbol+parseFloat(displayvalue.split('|')[1]).toFixed(2));
			break;
		  case "R" :
				if( lblReduced !=null)
					lblReduced.style.display = "block";
				if(lblReducedValue !=null)
				 showCtrlTxt('lblReducedValue',currencySymbol+parseFloat(displayvalue).toFixed(2) );
		  break;
		}
	}
	
	//Added for CR114
    ShowPerPersonValue(flightPrice,duration,totalPrice,currencySymbol,seperator);
	 				
	/*-- CR107 Block Addition Start --*/			
	if( !ShowRestrictMsg(lblBookingRestrictionMssg,bookingRestriction,dayDiff, 'lblBookingFee'))
	    return false;
	if(hypBookNow !=null)
		hypBookNow.style.display = "block";
    /*-- CR107 Block Add End --*/
	startBlink() ;
}	
		
}
// function to hide elements of price
function hideElements()
{
showHideCtrl('lblPriceWording',false);
showHideCtrl('lblPriceValue',false);	
showHideCtrl('lblWas',false);	
showHideCtrl('lblWasValue',false);	
showHideCtrl('lblPriceValue',false);	
showHideCtrl('lblNow',false);	
showHideCtrl('lblNowValue',false);	
showHideCtrl('lblSaving',false);	
showHideCtrl('lblSavingValue',false);	
showHideCtrl('lblReduced',false);	
showHideCtrl('lblReducedValue',false);	
showHideCtrl('lblBookingRestrictionMssg',false);	
showHideCtrl('lblPrice',false);	
showHideCtrl('lblReducedValue',false);
showHideCtrl('hypBookNow',false);	
showHideCtrl('lblDiscount',false);
showHideCtrl('tdDsc',false);
}
// function to check validity for available date search
function dateCheck(index,mode, monthControl)
{			
//////debugger;
var cmbMonth = document.getElementById(monthControl) ;
var cmbYear = document.getElementById('cmbYear') ;
if(cmbMonth ==null)
	return false;
if(cmbYear ==null)
	return false;

var month = cmbMonth.options[ cmbMonth.selectedIndex ].value.substr(5);
month = parseInt( month,10 ) -1 ;
var year = cmbYear.value ;
var nowDate = new Date();
nowDate.setMonth(month);
nowDate.setYear(year);
nowDate.setDate(1);

var userDate = new Date();
userDate.setDate(1);
var checkDate = false;
if(nowDate < userDate && mode == "month")
{
	checkDate = false;
	alert(wrongMonth);
		cmbMonth.selectedIndex = index;
	return false;
}
else
	checkDate = true;
	
if(checkDate)
{
if(mode == "month")
{
	if(parseInt(document.getElementById('hdnPrevMonthVal').value,10)!=cmbMonth.selectedIndex)
		__doPostBack( monthControl , '' );
	else
		return false;	
}
else
if(parseInt(document.getElementById('hdnPrevYearVal').value,10)!=cmbYear.selectedIndex)
__doPostBack( 'cmbYear' , '' );
else
return false;
		
}

}
// Function for opening Grades popup
function openWindow(widthVal,heightVal)
{
var gid = document.getElementById('hdnSiteGuid').value;
window.open( "GradeDetails.aspx?Qs="+gid+"~"+countryId+"~"+accomBrochureId+"~"+propertyTypeCd ,null ,"width="+widthVal+"px"+",height="+heightVal+"px"+",menubar=no,titlebar=no,statusbar=yes,scrollbars=yes" );
}

function openTCWindow( disId,width,height )
{

var url = "TermsCondition.aspx?qs=D~~~#LCD~#SGuid~#ProfId~"+disId;
url = url.replace("#SGuid",document.getElementById("hdnSiteGuid").value);  
url = url.replace("#LCD",languageId);  
url = url.replace("#ProfId",profileId);  
window.open( url ,null ,"width="+width+"px"+",height="+height+"px"+",menubar=no,titlebar=no,statusbar=yes,scrollbars=yes" );
}
// Function for registering Javascript to Travel Option radio buttonlist
function registerTravelOptionEvent()
{

var cmbYear = document.getElementById( "cmbYear" );
var cmbMonth = document.getElementById( "cmbMonth" );
var cmbDuration = document.getElementById( "cmbHolidayDuration" );
var cmbUnit = document.getElementById( "cmbUnitTypes" );

if( cmbYear != null )
{
    cmbYear.selectedIndex = selYear;
}
if( cmbMonth != null )
{
    cmbMonth.selectedIndex = selMonth;
}
if( cmbDuration != null )
{
    cmbDuration.selectedIndex = selDuration;
}
if( cmbUnit != null )
{
    cmbDuration.selectedIndex = selDuration;
}
var tabUnAvailableDateColor = document.getElementById( "tabUnAvailableDateColor" ) ;
var tabAvailableDateColor = document.getElementById( "tabAvailableDateColor" );
var lblBookingRestrictionMssg = document.getElementById( "lblBookingRestrictionMssg" );
var rdTravelop = document.getElementById("rdbTravelOptions") ;


if( tabUnAvailableDateColor != null )
 tabUnAvailableDateColor.style.backgroundColor = tabUnAvailableDateColor.bgColor ;
if( tabAvailableDateColor != null )
 tabAvailableDateColor.style.backgroundColor = tabAvailableDateColor.bgColor ;
 
if( showControl != null && showControl )
{
if(lblBookingRestrictionMssg!=null)
  lblBookingRestrictionMssg.style.display = 'block';
}
else
{
 if(lblBookingRestrictionMssg !=null)
  lblBookingRestrictionMssg.style.display = 'none';
}
	
}
// Function for Book button validation
//Modified for CR112
function checkBooking()
{
if(document.getElementById("rdbTravelOptions") != null)
{		
var travelOptList = document.getElementById("rdbTravelOptions").getElementsByTagName( "INPUT" );
for( count= 0 ; count< travelOptList.length ; count++ )
{
if( travelOptList[ count ].type == "radio" && travelOptList[ count ].checked )
{					
if( travelOptList[ count ].value == "FLIGHTINCLUSIVE" )
{
    var flightdt = document.getElementById("hdnPrevUnitVal").value;
    var year=parseInt(flightdt.substr(6,4),10);
    var month=parseInt(flightdt.substr(3,2),10);
    var dt=parseInt(flightdt.substr(0,2),10);
	
    var flightDate = new Date();
    flightDate.setMonth(month-1);
    flightDate.setYear(year);
    flightDate.setDate(dt);  
	
    var holidaydt = document.getElementById("hdnStartDate").value;
    var year=parseInt(holidaydt.substr(6,4),10);
    var month=parseInt(holidaydt.substr(3,2),10);
    var dt=parseInt(holidaydt.substr(0,2),10);
	
    var holidayDate = new Date();
    holidayDate.setMonth(month-1);
    holidayDate.setYear(year);
    holidayDate.setDate(dt); 
    if(holidayDate < flightDate)
    {
	    var ans = confirm(dateMismatch);	
	    if(ans == 0)
	    {
		    return false;
	    }
		
    }	

}

}
}
}	
var startdate=document.getElementById('hdnStartDate').value;
var day=startdate.split('/')[0];
var month=startdate.split('/')[1];
var year=startdate.split('/')[2];
startdate=month+"-"+day+"-"+year;
redirectionUrl = redirectionUrl.replace("STARTDATE",startdate) ;
redirectionUrl = redirectionUrl.replace("STATUS",selecteddateStatus) ;
redirectionUrl = redirectionUrl.replace("ABID",accomBrochureId) ;
redirectionUrl = redirectionUrl.replace("BBID",bookingBrochId) ;
//alert( redirectionUrl );
location.href = redirectionUrl ;
setTimeout( "CreateProgressTab()" , 500 );
return true;

}

function checkHSBooking(hsRedirectTime, redirectionMsg)
{
    if(document.getElementById('tabError') != null && document.getElementById('lblErrorMessage') != null)
    {
        document.getElementById('tabError').style.display = 'block';
        document.getElementById('lblErrorMessage').innerHTML = redirectionMsg;
    }

    setTimeout( "RedirectToHoseasons()" , hsRedirectTime);
    return true;
}

// Fuction for reseting the travel option radiobuttonlist
function setTravelOption()
{
var rdbTravelOptions = document.getElementById("rdbTravelOptions") ;
for( counter= 0 ; counter< rdbTravelOptions.getElementsByTagName( "INPUT" ).length ; counter++ )
{
if(rdbTravelOptions.getElementsByTagName( "INPUT" )[ counter ].type == "radio" )
{					
if( rdbTravelOptions.getElementsByTagName( "INPUT" )[ counter ].value == document.getElementById("hdnServerPath").value )
{
	rdbTravelOptions.getElementsByTagName( "INPUT" )[ counter ].checked = true;
}
}	
}
}
var blinkPrice ;
var lblNowValue;
var lblWasValue;
var lblSavingValue;
var lblReducedValue;
var isPrice ;
var isNow;
var isWas;
var isSaving;
var isReduced;
function startBlink()
{
    blinkPrice=document.getElementById( 'lblPriceValue' ); 
    lblNowValue = document.getElementById('lblNowValue') ;
    lblWasValue = document.getElementById('lblWasValue') ;
    lblSavingValue = document.getElementById('lblSavingValue') ;
    lblReducedValue = document.getElementById('lblReducedValue') ;

    isPrice= ( blinkPrice && blinkPrice.style.display == "block");
    isNow= ( lblNowValue && lblNowValue.style.display == "block");
    isWas= ( lblWasValue && lblWasValue.style.display == "block");
    isSaving= ( lblSavingValue && lblSavingValue.style.display == "block");
    isReduced= ( lblReducedValue && lblReducedValue.style.display == "block");


    timer = setInterval("doBlink()",500) ;  
}
function doBlink()
{

    if( count== 5 )
    {
        clearInterval( timer );
        if( isPrice )
          blinkPrice.style.visibility = "" ;
        if(isNow)
	        lblNowValue.style.visibility = "" ;
        if(isWas)
           lblWasValue.style.visibility = "" ;
        if(isSaving)
         lblSavingValue.style.visibility = "" ;
        if(isReduced)
         lblReducedValue.style.visibility = "" ;
        count = 0;
        return ;
    }
    if(isPrice)
      blinkPrice.style.visibility = blinkPrice.style.visibility == "" ? "hidden" : "" 
    if(isNow)
      lblNowValue.style.visibility = lblNowValue.style.visibility == "" ? "hidden" : "" 
    if(isWas)
      lblWasValue.style.visibility = lblWasValue.style.visibility == "" ? "hidden" : "" 
    if(isSaving)
      lblSavingValue.style.visibility = lblSavingValue.style.visibility == "" ? "hidden" : "" 
    if(isReduced)
      lblReducedValue.style.visibility = lblReducedValue.style.visibility == "" ? "hidden" : "" 
count++ ; 

}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function openNoVBGradeWindow(width,height,profileId)
{
  window.open( "NonVbGradeDetails.aspx?ProfileId="+profileId ,null ,"width="+width+"px"+",height="+height+"px"+",menubar=no,titlebar=no,statusbar=yes,scrollbars=yes" );
}


function RedirectToHoseasons()
{
    var hdnHSBookingLink=document.getElementById('hdnHSBookingLink');
    var hdnAutoRed=document.getElementById('hdnAutoRed');
    
    if(document.getElementById('tabError') != null && document.getElementById('lblErrorMessage') != null)
    {
        document.getElementById('tabError').style.display = 'none';
        document.getElementById('lblErrorMessage').innerHTML = "";
    }

    if(hdnHSBookingLink != null )
    {
        if(hdnAutoRed != null && hdnAutoRed.value.toUpperCase() == "Y")
        {
            window.open (hdnHSBookingLink.value,""); 
        }
        else
        {
            window.location = hdnHSBookingLink.value;
        }
    }
}

//Function Added for Cr114
//This method calculates perpersonvalue
function ShowPerPersonValue(flightPrice,duration,priceAfterDiscount,currencySymbol,seperator)
{
    showHideCtrl('lblPerPersonValue',true);
    var lblPerPersonValue=document.getElementById('lblPerPersonValue') ;
    var perPersonValue = 0.0;
    
    if(flightPrice == "" && (duration == '7' || duration == '14' || duration == '21') && sleepCount > 0 && lblPerPersonValue != null && priceAfterDiscount > 0.0)
    {
        
        perPersonValue = (priceAfterDiscount/sleepCount).toFixed(2);
		perPersonValue = currencySymbol+ perPersonValue;
		lblPerPersonValue.innerHTML = perPersonValFormat.replace(/%PPVAL/, perPersonValue.toString().replace(".",seperator));
    }
    else
    {
        showHideCtrl('lblPerPersonValue',false);
    }
}
