var galleryImage = 1;
var isAltFlightsShown=false;
var isPageLoaded = false;
function onloadEvent(funcToLoad) {

  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = funcToLoad;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      funcToLoad();
    }
  }
}

function getDimensions() 
{
	var w = 0;
	var h = 0;
//IE
	if(!window.innerWidth)
	{
//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return [h, w];
}

onloadEvent(function() {
	isPageLoaded = true;
})

function checkPageLoaded() {
	return isPageLoaded;
}


function changeImage(imageId){
	if(slideShowEnabled == 1) disableSlideShow();
	if(document.getElementById('mainImage') && document.getElementById('img'+imageId)){
		document.getElementById('mainImage').src = document.getElementById('img'+imageId).src;
		imgNumber = imageId;
	}
}
var lastClickedValue =1;
function changeGalleryPagination(value,maxPages,index){
	if(document.getElementById('galPag'+value)){
		document.getElementById('galPag'+value).style.display = 'block';
	}
	if(value != galleryImage ){
	if(document.getElementById('galPag'+galleryImage)) {
		document.getElementById('galPag'+galleryImage).style.display = 'none';
			var href = document.getElementById('galpos'+value).getAttribute("href");
			    this.document.getElementById('galpos'+value).setAttribute('href_bak', href);
				this.document.getElementById('galpos'+value).style.color="gray";
				this.document.getElementById('galpos'+value).removeAttribute('href'); 
	}

		for(var k=0;k<maxPages;k++){
		if(k==index ){
		var href_bak= document.getElementById('galpos'+lastClickedValue).getAttribute("href_bak");
		if(href_bak == null){
		href_bak = document.getElementById('galpos'+lastClickedValue).getAttribute("href");
		}
		this.document.getElementById('galpos'+lastClickedValue).setAttribute('href', href_bak);
		this.document.getElementById('galpos'+lastClickedValue).style.color="#2EB135";
		}
	}


	}
	
	
	galleryImage = value;
	lastClickedValue = value;
}

function changerDisplay(id){
	if(document.getElementById(id)){
		if(document.getElementById(id).style.position == 'absolute'){
			document.getElementById(id).style.position = 'static';
			document.getElementById(id).style.left = '0px';
		} else if(document.getElementById(id).style.position == 'static'){
			document.getElementById(id).style.position = 'absolute';
			document.getElementById(id).style.left = '-500000px';
		}
	}
	
}
function playSlideShow(){
	if(slideShowEnabled == 1){
		if(document.getElementById('img'+slideShowImage)){
			if(document.getElementById('mainImage') && document.getElementById('img'+slideShowImage)){
				document.getElementById('mainImage').src = document.getElementById('img'+slideShowImage).src;
				imgNumber = slideShowImage;
				if(slideShowImage < maxNumber){
					++slideShowImage;
				} else {
					slideShowImage = 1;
				}
			}
			t=setTimeout("playSlideShow()",4000);
		}
	}
}

function enableSlideShow(){
	slideShowEnabled = 1;
	if(document.getElementById('playSlide')) document.getElementById('playSlide').style.display = 'none';
	if(document.getElementById('stopSlide')) document.getElementById('stopSlide').style.display = 'inline';
}

function disableSlideShow(){
	slideShowEnabled = 0;
	clearTimeout(t);
	if(document.getElementById('playSlide')) document.getElementById('playSlide').style.display = 'inline';
	if(document.getElementById('stopSlide')) document.getElementById('stopSlide').style.display = 'none';
}

function getSiMigrationId(){
	var c_name = "SIVISITOR";
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
	    		c_start=c_start + c_name.length+1;
	    		c_end=document.cookie.indexOf(";",c_start);
	   		if (c_end==-1) c_end=document.cookie.length;
	   		return unescape(document.cookie.substring(c_start,c_end));
	    	}
	  }
	return "";
}

function doCost(){
	 document.packageCost.submit();
}


function getAllAlternativeFlights(path){

 
   if(!isAltFlightsShown){
	document.getElementById("alternateFlightOptions").innerHTML = "<img src='/images/siteElements/loading.gif' alt='Loading' />";
	document.getElementById('alternateFlightOptions').style.display = "block";
	document.packageCost.selectHolidayIndex.value = document.getElementsByName("altflightoption")[0].value;
	 
	
	if(navigator.appName=='Microsoft Internet Explorer'){	
		document.accommodationForm[0].checkAlternativeFlights.value = document.getElementsByName("altflightoption")[0].value
	      }
   else{
	   document.accommodationForm.checkAlternativeFlights.value = document.getElementsByName("altflightoption")[0].value;
	   }
	//document.packageCost.bookNowHolidayIndex.value =  document.getElementsByName("altflightoption")[0].value;

	id = document.getElementsByName("altflightoption")[0].value;
	if(path && id){
		AjaxSearchResultTools.getAlternateFlightContent(path, id, function(data) {
		//alert(data.replace(/^\s*|\s*$/g,''));
			document.getElementById("alternateFlightOptions").innerHTML = data;	
			document.getElementById("alternateFlightOptions").style.display = 'block';
		});
	}
	
	
	 document.getElementById("altFlightsSpan").innerHTML="Hide alternative flights";
	 isAltFlightsShown=true;
	 altflightTracking('content/altflight/show');
	 


	}else{
		  var oldHtml= document.getElementById("flightfirst").innerHTML;
	      if(document.getElementsByName("altflightoption")[0].checked)
	    	{
			 document.getElementById("alternateFlightOptions").style.display = 'none';
            }
			else
	     	{
	          for(i=0;i<document.getElementsByName("altflightoption").length;i++){
				  if (document.getElementsByName("altflightoption")[i].checked==true){
                            var packageID = document.getElementsByName("altflightoption")[i].value;
						     if(document.getElementById(packageID+"_altFlight")!=null)
							 {
							  document.getElementById("flightfirst").innerHTML = "";
							  document.getElementById(packageID+"_accomflightprice").innerHTML ="";
							  document.getElementById("flightfirst").innerHTML = document.getElementById(id+"_altFlight").innerHTML;
							  document.getElementsByName("altflightoption")[0].checked= true;
							 document.getElementById("alternateFlightOptions").style.display = 'none';
						 	 }
				       }
			   }
		}
	

	// document.getElementById("alternateFlightOptions").style.display = 'none';
	 document.getElementById("altFlightsSpan").innerHTML="Search alternative flights";
       isAltFlightsShown=false;
	   altflightTracking('content/altflight/hide');
	
     }

}

function changePackagePrice(totalPrice, avgPrice, currency,radFlag, packageId){

	window.location.href="#dummyAnchrForLink";
	if(avgPrice){
		document.getElementById("pricepp").innerHTML = currency +""+ roundNumber(avgPrice,0);// + "<span class='pp'>pp</span>";
	}
	if(totalPrice){
		document.getElementById("totalprice").innerHTML = currency +""+ roundNumber(totalPrice,0);	
	}
	var oldHtml= document.getElementById("flightfirst").innerHTML;
	//document.getElementById("flightfirst").innerHTML = "";
	
   

	var selected = 0;
	var isfound =false;
	var altid= packageId;
if(document.getElementsByName("altflightoption")!= undefined){
	for (i=0;i<document.getElementsByName("altflightoption").length;i++){
		if (document.getElementsByName("altflightoption")[i].checked==true && document.getElementsByName("altflightoption")[i].value==packageId ){
				id = document.getElementsByName("altflightoption")[i].value;
				document.getElementById("flightfirst").checked=false;
				document.getElementById("altFlightsSpan").innerHTML="Hide alternative flights";
				if(id){
					document.packageCost.selectHolidayIndex.value = id;
                    if(navigator.appName=='Microsoft Internet Explorer'){		   
	                        document.accommodationForm[0].checkAlternativeFlights.value = id;
					}
                    else{
	                    document.accommodationForm.checkAlternativeFlights.value = id;
	                   }
					AjaxSearchResultTools.setSelectedPackage(id, function(data) {
					});
				   }

				isfound = true;
			  }
        else {
                  document.getElementsByName("altflightoption")[i].checked=false;
			  }

		   }
	
	}

	if(!isfound){   
		        if(navigator.appName=='Microsoft Internet Explorer')
		         {
		         var newdiv = document.createElement("div");
                 newdiv.innerHTML = oldHtml;
		         var oDiv=document.getElementById("flightfirst");
		         var i=0;
                  while(oDiv.hasChildNodes())
                           {  
					          oDiv.removeChild(oDiv.childNodes[0]);	
                           }
                       oDiv.appendChild(newdiv);
		           }
        else
		{
		document.getElementById("flightfirst").innerHTML = oldHtml;
		}

		if(radFlag!='1')
		{      
     	for (i=0;i<document.getElementsByName("altflightoption").length;i++){
			if(document.getElementsByName("altflightoption")[i] != undefined){
			if(document.getElementsByName("altflightoption")[i].value==altid ){
		      document.getElementsByName("altflightoption")[i].checked = true;
			  }
			else
			{	
			document.getElementsByName("altflightoption")[i].checked = false;
            }
		 }
	   }
		
	  }
   	}
	document.getElementById("priceupdate").style.display = 'block';
	document.getElementById("updated").style.backgroundColor ="#F99010";
	var t = setTimeout("bgColor('updated')",2000)
}


function setPrice(averagePrice,totalPrice, packageId, departureDate){

	if(averagePrice){
		document.getElementById('pricepp').innerHTML = averagePrice;//+"<span class='pp'>pp</span>";
	}
	if(totalPrice){
		document.getElementById('totalprice').innerHTML = totalPrice;
	}

	{
		document.getElementById('departureDate').value = departureDate;
	}
	if(packageId){
		//alert(packageId);
		document.packageCost.selectHolidayIndex.value = packageId;
		//alert(document.accommodationForm.selectHolidayIndex.value);
		if(document.accommodationForm.checkAlternativeFlights!=null)
		{
		document.accommodationForm.checkAlternativeFlights.value = packageId;
		}
		//document.packageCost.bookNowHolidayIndex.value = packageId;
	}
	//alert(document.accommodationForm.checkAlternativeFlights);
	if(packageId){
		AjaxSearchResultTools.getMainFlightContent("/templates/accommodation/includes/flightDetails.jsp", packageId,'', function(data) {
		//alert(data.replace(/^\s*|\s*$/g,''));
		
         if(navigator.appName=='Microsoft Internet Explorer')
		{
		         var newdiv = document.createElement("div");
                 newdiv.innerHTML = data;
		         var oDiv=document.getElementById("flightfirst");
		         var i=0;
                 while(oDiv.hasChildNodes())
                           {
                             oDiv.removeChild(oDiv.childNodes[0]);	
                           }
                       oDiv.appendChild(newdiv);
		}
		else{

			document.getElementById("flightfirst").innerHTML = data;
		}
		});

		//AjaxSearchResultTools.getSelectedPackageRoomType(packageId, function(data) {
			//var selObj = document.getElementById('accomroom');
			//for (i=0;i<selObj.length;i++){
			//	var temp = data.match(selObj[i].value);
			//	var roomType = selObj[i].value.split("@");
			//	if(data.match(roomType[1]) !=null){	
					//alert("-----------"+selObj[i].value);
			//		selObj[i].selected = true;
			//	}else{
			//		selObj[i].selected = false;
			//	}
			//}
	
		//});
	}
}

function showAccomCalendarWait(){
	var loadingDisplay = "<div class='dealsLoading'><img src='/images/siteElements/loading.gif' alt='Loading' /></div>";
	document.getElementById('extraContent').innerHTML = loadingDisplay;
}


function tcFindAccomodationDeals(curencyCode, resultId, month, flagged,url) {
	
	//just before deals are searched, the no availability message should disappear 
	//and only wait image should be displayed.
	if(document.getElementById('noAvailabilityDiv') != null){
		document.getElementById('noAvailabilityDiv').style.display = 'none';
	}
	
	url = url+"?flagged="+ flagged +"&result=" + resultId + "&month=" + month;
	 //alert("hello i am here");
	AjaxSearchResultTools.getAccommodationDeals(month, url, function(data) {
		//alert(data.replace(/^\s*|\s*$/g,''));
		dwr.util.setValue("extraContent", data, {
			escapeHtml : false
			
		});
		//alert("tc flight accom hello i am here");
		AjaxSearchResultTools.getPackagePrice(resultId, month, function(data) {
		//alert(data.replace(/^\s*|\s*$/g,''));
			//alert(data);
			var priceArray = data.split("@");
			document.getElementById('pricepp').innerHTML = "&"+curencyCode + priceArray[0];//+"<span class='pp'>pp</span>";
			document.getElementById('totalprice').innerHTML ="&"+curencyCode + priceArray[1];
			document.packageCost.selectHolidayIndex.value = priceArray[2];
			//alert(document.accommodationForm.selectHolidayIndex.value);
			document.accommodationForm.checkAlternativeFlights.value = priceArray[2];
			//document.packageCost.bookNowHolidayIndex.value = priceArray[2];

			AjaxSearchResultTools.getMainFlightContent("/templates/accommodation/includes/flightDetails.jsp", priceArray[2], month, function(data) {
			//alert(data.replace(/^\s*|\s*$/g,''));
				document.getElementById("flightfirst").innerHTML = data;	
			});

		});

		changeDisplayPrice();
		var calendarDealSize = document.getElementById('calendarDealSize').value;
		var selectedDate = document.getElementById('selectedDate').value;
		calviewTracking(calendarDealSize,selectedDate);
	});

}

function getAccomDivContainerID(flagged, resultId){
	var unID = 'extraContent_' + resultId;
	if(flagged == 'true'){
		unID = 'extraContent';
	}
	return unID;
}
function setActiveTab(tabID) {

	
	var currTabElem;
	var i=0;
	for (i=0;i<=42;i++)
	{
		var styleClass="";
		currTabElem = document.getElementById('calendar_'+i);
        
		if(currTabElem!=null){
            if(navigator.appName=='Microsoft Internet Explorer')
			       {
                           styleClass=currTabElem.className;
			       }
           else    {
		          styleClass= currTabElem.getAttribute("class");
		            }
		}
        
		if(currTabElem!=null  && styleClass =='calenderday chosenblue')
		{
           
			currTabElem.setAttribute("class", "calenderday selecteddate");
			currTabElem.setAttribute("className", "calenderday selecteddate");
        }
        if(currTabElem!=null  && styleClass =='calenderday chosenandselected')
		{           
			currTabElem.setAttribute("class", "calenderday selecteddate");
			currTabElem.setAttribute("className", "calenderday selecteddate");
        }

		if(currTabElem!=null  && styleClass!='calenderday selecteddate'&& styleClass!='calenderday chosenblue' && styleClass!='calenderday chosenandselected'){
			currTabElem.setAttribute("class", "calenderday");
			currTabElem.setAttribute("className", "calenderday");
		}
		currTabElem = document.getElementById('span_'+i);
         
		 if(currTabElem!=null && styleClass!='calenderday chosenblue'){
			currTabElem.setAttribute("class", "pricethreechosen");
			currTabElem.setAttribute("className", "pricethreechosen");
		}
		if(currTabElem!=null && styleClass!='calenderday selecteddate' && styleClass!='calenderday chosenblue'&& styleClass!='calenderday chosenandselected'){
			currTabElem.setAttribute("class", "pricethree");
			currTabElem.setAttribute("className", "pricethree");
		}
	}
    
	currTabElem = document.getElementById('calendar_'+tabID);
	//alert(currTabElem);
     if(navigator.appName=='Microsoft Internet Explorer')
			{
            styleClass=currTabElem.className;
			}
         else{
		styleClass= currTabElem.getAttribute("class");
		 }
	if(styleClass!='calenderday selecteddate')
	{
	currTabElem.setAttribute("class", "calenderday chosen");
	currTabElem.setAttribute("className", "calenderday chosen");

	currTabElem = document.getElementById('span_'+tabID);
	currTabElem.setAttribute("class", "pricethreechosen");
	currTabElem.setAttribute("className", "pricethreechosen");

	document.getElementById("priceupdate").style.display = 'block';
	document.getElementById("updated").style.backgroundColor ="#F99010";
	}
	if(styleClass!='calenderday chosenandselected')
	{
	currTabElem.setAttribute("class", "calenderday chosenblue");
	currTabElem.setAttribute("className", "calenderday chosenblue");

	currTabElem = document.getElementById('span_'+tabID);
	currTabElem.setAttribute("class", "pricethreechosen");
	currTabElem.setAttribute("className", "pricethreechosen");

	document.getElementById("priceupdate").style.display = 'block';
	document.getElementById("updated").style.backgroundColor ="#F99010";
	}
    else
	{
     currTabElem.setAttribute("class", "calenderday chosenblue");
	currTabElem.setAttribute("className", "calenderday chosenblue");

	currTabElem = document.getElementById('span_'+tabID);
	currTabElem.setAttribute("class", "pricethreechosen");
	currTabElem.setAttribute("className", "pricethreechosen");

	document.getElementById("priceupdate").style.display = 'block';
	document.getElementById("updated").style.backgroundColor ="#F99010";



    }

	var t = setTimeout("bgColor('updated')",2000)
	return;
} 

function bgColor(id){
	document.getElementById(id).style.backgroundColor ="#ffffff";
}

function OnChange(dropdown)
{
	var myindex  = dropdown.selectedIndex
	var selectedDepartureGroupId = dropdown.options[myindex].value;
	var selectedPackageId = document.packageCost.selectHolidayIndex.value;
	var url = "/templates/accommodation/includes/accomCalender.jsp";
	//alert(document.getElementById('accomOverViewDepDate').value);
}

function getMatrixDeals(pBeanElem, pKeyword, url){
	showAccomCalendarWait();
	var index = pBeanElem.indexOf("@");
	var roomType = pBeanElem.split("_");
	if(roomType[1] != null){
		//alert('accomroom_'+roomType[0]);
		document.getElementById('accomroom_'+roomType[0]).value=roomType[1];
	}
	if(index>=0){
		var pBeanElemArray = pBeanElem.split("@");
		pBeanElem = pBeanElemArray[0];
	}
	//if(pKeyword.match('childAges')){
	//	alert(pKeyword);
	//	if(document.getElementById('accomchild_'+url) != null){
	//		pBeanElem1 = document.getElementById('accomchild_'+url).value
	//	}else{
	//		pBeanElem1 = document.getElementById('newAccomchild_'+url).value
	//	}
	//	pBeanElem = pBeanElem + "_" + pBeanElem1 + "_" + url;
	//}

	//if(pKeyword == 'addRoom'){
	//	roomCount = document.getElementById('roomCountValue').value;
	//	alert(roomCount);
	//	if(document.getElementById('accomroom_'+roomCount) != null){
	//		value = document.getElementById('accomroom_'+roomCount).value;
	//	}else{
	//		value = document.getElementById('newAccomroom_'+roomCount).value;
	//	}
	//}
	document.getElementById('noAvailabilityDiv').style.display='none';
	url = "/templates/accommodation/includes/accomCalender.jsp";
	AjaxSearchResultTools.getMatrixDealsForAccom(pBeanElem, pKeyword, url, function(data) {
		dwr.util.setValue("extraContent", data, {
			escapeHtml : false
		});		
		changeDisplayPrice();
		var calendarDealSize = document.getElementById('calendarDealSize').value;
		var selectedDate = document.getElementById('selectedDate').value;
		calviewTracking(calendarDealSize,selectedDate);
	});
}


function populateRoomType(accommItemForRoomType,pKeyword,roomCount){
	if(pKeyword == 'addRoom'){
	var roomCounter= document.getElementById('roomCountValue').value;
	document.getElementById('roomCountValue').value= roomCounter;
	}
	//var idOfRoomAdded = document.getElementById('newAccomroom_2');
	//AjaxSearchResultTools.getMapForAddedRooms(accommItemForRoomType, pKeyword,roomCounter,addRoomMap);
}
function addRoomMap(data) {
	var newRoomCount = document.getElementById('roomCountValue').value;
	dwr.util.removeAllOptions('newAccomroom_'+newRoomCount);
	dwr.util.addOptions('newAccomroom_'+newRoomCount, data);
}



function validatePaxCount(pBeanElem,dynamicRoomCount,roomCount){
	if(document.getElementById('accomroom_'+roomCount) != null){
		var value = document.getElementById('accomroom_'+roomCount).value;
	}else{
		var value = document.getElementById('newAccomroom_'+roomCount).value;
	}
	paxDetails = value.split("@");
	if(document.getElementById('accomadult_'+roomCount) != null){
		var adultCount = document.getElementById('accomadult_'+roomCount).value;
	}else{
		var adultCount = document.getElementById('newAccomadult_'+roomCount).value;
	}
	if(document.getElementById('accomchild_'+roomCount) != null){
		var childtCount = document.getElementById('accomchild_'+roomCount).value;
	}else{
		var childtCount = document.getElementById('newAccomchild_'+roomCount).value;
	}
	var totalPaxCount = parseInt(adultCount) + parseInt(childtCount);
	var minPax = paxDetails[1];
	var maxPax = paxDetails[2];
		if(minPax > totalPaxCount ){
			//alert("Increase the number of Passenger to support this room type");
			displayPaxErrorMesg(minPax, maxPax);
			document.getElementById('paxMixErrorSpan').style.display="block";
			return false;
		}
		if(maxPax < totalPaxCount){
			//alert("Decrease the number of Passenger to support this room type");
			displayPaxErrorMesg(minPax, maxPax);
			document.getElementById('paxMixErrorSpan').style.display="block";
			return false;
		}
		else {
			document.getElementById('paxMixErrorSpan').style.display="none";
			if(dynamicRoomCount.match('child')){
				updateChildAgeBlock(roomCount,pBeanElem);
			}//else{
				getMatrixDeals(pBeanElem,dynamicRoomCount,'');
			//}
		}
}


function displayPaxErrorMesg(minPax, maxPax){

	document.getElementById("min").innerHTML = "'" + minPax + "'";
	document.getElementById("max").innerHTML = "'" + maxPax + "'";
}


function updateChildAgeBlock(roomCount,value){
	for(j=1;j<=6;j++){
		if(j<=value){	
			if(document.getElementById('childAge_'+roomCount+"_"+j) != null){
				document.getElementById('childAge_'+roomCount+"_"+j).style.display='block';
			}else{
				document.getElementById('newChildAge_'+roomCount+"_"+j).style.display='block';
			}
		}else{
			if(document.getElementById('childAge_'+roomCount+"_"+j) != null){
				document.getElementById('childAge_'+roomCount+"_"+j).style.display='none';
			}else{
				document.getElementById('newChildAge_'+roomCount+"_"+j).style.display='none';
			}
		}
	}
}

function removeRooms(){
	var count = document.getElementById('roomCountValue').value;
	if(count>1)
	{
		--count;
		++count;
		if(document.getElementById('roomDetails_'+count) != null){
				document.getElementById('roomDetails_'+count).style.display='none';
			}else{
				document.getElementById('newRoomDetails_'+count).style.display='none';
			}
		--count;
		if(count ==1){
				document.getElementById('removeRooms').style.display='none';
			}
		if(count ==2){
				document.getElementById('addRooms').style.display='block';
			}
	}
	document.getElementById('roomCountValue').value = count;
}

function addRooms(){
	var count = document.getElementById('roomCountValue').value;
	if(count <3)
		{
			++count;
			if(document.getElementById('roomDetails_'+count) != null){
				document.getElementById('roomDetails_'+count).style.display='block';
			}else{
				document.getElementById('newRoomDetails_'+count).style.display='block';
			}
			if(count ==2){
				document.getElementById('removeRooms').style.display='block';
			}
			if(count ==3){
				document.getElementById('addRooms').style.display='none';
			}
		}	
		document.getElementById('roomCountValue').value = count;
}

function changeDisplayPrice(){

	
	if(isAltFlightsShown){
		
		document.getElementById("alternateFlightOptions").style.display = 'none';
	 document.getElementById("altFlightsSpan").innerHTML="Search alternative flights";
	 isAltFlightsShown=false;
	

	}


	
    var choosenPriceAvailable = 'False' ;
	var cheapesetPriceAvailable='False'

 

	if(document.getElementById('calenderChossenPrice') != null ){
	
		var selDealAvailable = true;
		var valArray = document.getElementById('calenderChossenPrice').value.split(",");
		var currency = valArray[1].substring(0, 1);
		var totalprice= roundNumber(valArray[1].substring(1),0);
		var packagePrice = currency+""+totalprice;
		choosenPriceAvailable='True'
		 setPrice(valArray[0],packagePrice, valArray[2], valArray[3])
		//document.getElementById('pricepp').innerHTML = document.getElementById('calenderChossenPrice').value+'<span class="pp">pp</span>';
		document.getElementById('accombooknowDiv').style.display='block';
		document.getElementById('accomflightsDiv').style.display='block';
		//document.getElementById('noAvailabilityDiv').style.display='none';
	}
	
	
      	if(document.getElementById('calenderChossenandCheapestPrice') != null ){
			
		
		var selDealAvailable = true;
		var valArray = document.getElementById('calenderChossenandCheapestPrice').value.split(",");
		var currency = valArray[1].substring(0, 1);
		var totalprice= roundNumber(valArray[1].substring(1),0);
		var packagePrice = currency+""+totalprice;
		
		if(choosenPriceAvailable!='True' && cheapesetPriceAvailable!='True'){
			setPrice(valArray[0],packagePrice, valArray[2], valArray[3]);
		 }
		//document.getElementById('pricepp').innerHTML = document.getElementById('calenderChossenPrice').value+'<span class="pp">pp</span>';
		document.getElementById('accombooknowDiv').style.display='block';
		document.getElementById('accomflightsDiv').style.display='block';
		//document.getElementById('noAvailabilityDiv').style.display='none';
	}
    else if(choosenPriceAvailable!='True' && cheapesetPriceAvailable!='True')
	{
        
			document.getElementById('noAvailabilityDiv').style.display='block';
			document.getElementById('accombooknowDiv').style.display='none';
			document.getElementById('accomflightsDiv').style.display='none';

	}
	
	
	if(selDealAvailable != true){
		
		//execute this block only if sel deal not available.
		if(document.getElementById('dealPresent') != null){
			document.getElementById('noAvailabilityDiv').style.display='none';
			document.getElementById('accombooknowDiv').style.display='block';
			document.getElementById('accomflightsDiv').style.display='block';
		}
	}
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}

function ajaxTracking(trackingType,value){
	
	var selectedTrackingType = trackingType.split("_")[0];
	if(trackingType.split("_")[1] != null){
		var	selectedRoomCount = trackingType.split("_")[1];
	}else{
		var	selectedRoomCount = "";
	}

	if(selectedTrackingType == 'alternateFlights'){
		value = value + '_' +document.getElementById('trackDepartureTime_'+selectedRoomCount).innerHTML + '_'+document.getElementById('trackArrivalTime_'+selectedRoomCount).innerHTML;
	}

	if(selectedTrackingType == 'unit'){
		value=document.getElementById('roomCountValue').value;
	}
	if(selectedTrackingType == 'roomType'){
		value=value.split("@")[0];
	}
	if(selectedTrackingType == 'addRoom'){
		value=document.getElementById('roomCountValue').value;
		selectedRoomCount = document.getElementById('roomCountValue').value
		if(document.getElementById('accomroom_'+value) != null){
			code = document.getElementById('accomroom_'+value).value;
		}else{
			code = document.getElementById('newAccomroom_'+value).value;
		}
		code = code.split("@")[0];
		value = value+"_"+code;
	}
	if(selectedTrackingType == 'removeRoom'){
		value=document.getElementById('roomCountValue').value;
		selectedRoomCount = document.getElementById('roomCountValue').value
	}
	AjaxSearchResultTools.siTagAccommodation(selectedTrackingType,value,selectedRoomCount,updateAjaxTracking);
}

function updateAjaxTracking(data) {
	eval(data);
}

function ajaxTrackingPayment(trackingType,value){
	AjaxSearchResultTools.siTagPassenger(trackingType,value,updatePaymentAjaxTracking);
}

function updatePaymentAjaxTracking(data) {
	eval(data);
	//document.getElementById('extraContent123').value = data;
}

function calviewTracking(numberOfDeals,selectedDate){
	sitracker.trackEvent("content/calendar/view/"+selectedDate+"/"+numberOfDeals);
}

function altflightTracking(value){
	sitracker.trackEvent(value);
}

function contentTracking(content,imageURL){
	var imageNameArray = imageURL.split("/");
	var imageName = imageNameArray[imageNameArray.length -1]
	sitracker.trackEvent(content+imageName);
}

function imageLoadingError(imageURL){
	var imageNameArray = imageURL.split("/");
	var imageName = imageNameArray[imageNameArray.length -1]
	sitracker.trackEvent("content/image/404error/"+imageName);
}

  function durationSorting(){
				
	var durationsArray = ["less than 7 nights", "7 nights", "8-13 nights", "14 nights", "More than 14 nights" ];
	var optionsArray = new Array();
	var durationSelObj = document.getElementById("inputnights");
	for(var i=0; i< durationSelObj.options.length;i++){
		optionsArray[i] = new Option(durationSelObj.options[i].text, durationSelObj.options[i].value);
		if(durationSelObj.options[i].selected)
			optionsArray[i].selected=true;
	}
	durationSelObj.options.length=0;
	for(var j=0;j<durationsArray.length;j++){
		for(var i=0;i<optionsArray.length;i++){
			if(durationsArray[j] == optionsArray[i].text){
				document.getElementById("inputnights").options[j]=optionsArray[i];	
				break;
			}
		}
	}
}


/*Search Results Page hover*/
function showToolTips1(ID){
			document.getElementById(ID).style.display = 'block';
			
}

function hideToolTips1(ID){
			document.getElementById(ID).style.display = 'none';

}
/*Search Results Page hover*/

function loading(id) {
var elements = document.facetsForm.elements;
for (var i = 0; i < elements.length; i++) {
  if (elements[i].id == id && elements[i].type == 'checkbox') {
   elements[i].parentNode.className = 'pleasewait';
 } else {
   elements[i].disabled = true;
  }
  if (elements[i].id == id && elements[i].type == 'select-one') {
	  elements[i].parentNode.getElementsByTagName('label')[0].className = 'pleasewaitdropdown';
  } else {
   elements[i].disabled = true;
  }
}
jQuery('a', '.facetbody').removeAttr('href');
jQuery('a', '.facetbody').css('color', 'grey');
jQuery('a', '.fpartysize').css('textDecoration', 'underline');
jQuery('a', '.fdepart').css('textDecoration', 'underline');
}

function disableFacetsNoResult()
{
	        jQuery('input:checkbox','.facetbody').attr('disabled', 'disabled');
			jQuery('select','.facetbody').attr('disabled', 'disabled');
			jQuery('a', '.fpartysize').removeAttr('href').removeAttr('onclick').css('color', 'grey').css('textDecoration', 'underline');
			jQuery('#bBookNow').removeAttr('href').removeAttr('onclick').css('color', 'grey').css('textDecoration', 'underline');
}

/*Function to display hidden values and update expanded values var*/

function showHiddenValuesFromFacet(divId, facetId){
	jQuery('.facetvaluehidden', '#' + divId).show();
	jQuery( '#' + divId + 'ShowLink').hide();
	jQuery( '#' + divId + 'HideLink').show();
	if(expandedFacets){
		expandedFacets += ":" + facetId;
	}
	else expandedFacets = facetId;

}

/*Function to disable hidden values and update expanded values var respectively
 taking some risk with using ":" in url*/

function hideHiddenValuesFromFacet(divId, facetId){
	jQuery('.facetvaluehidden', '#' + divId).hide();
	jQuery( '#' + divId + 'ShowLink').show();
	jQuery( '#' + divId + 'HideLink').hide();
	var facetsArray = expandedFacets.split(':');
	expandedFacets = '';
	for(var i=0;i < facetsArray.length;i++) {
		if(facetsArray[i] != facetId){
            if(expandedFacets){
               		 expandedFacets += ":" + facetsArray[i];
                  }
               	 else expandedFacets = facetsArray[i];
		}

	}
}


function initFacetIfExpanded(divId , facetId){
	var facetsArray = expandedFacets.split(':');
	for(var i=0;i < facetsArray.length;i++) {
		if(facetsArray[i] == facetId){
            jQuery('.facetvaluehidden', '#' + divId).show();
            jQuery( '#' + divId + 'ShowLink').hide();
            jQuery( '#' + divId + 'HideLink').show();
		}

	}
}

function getFacetsToExpand(){
	if(expandedFacets){
		return expandedFacets;
	}
	else return '';
}

function addExpandParameter(id){
	id.href += '&expand=' + getFacetsToExpand();
}
