
function showhide_extrameal() {
	if(jQuery("#noFlightMeals").is(":checked")){
		jQuery("#meals").show();
	} else {
		jQuery("#meals").hide();
	}
} 

var state = 'none';
	function showhide(layer_ref) { 
		if (state == 'block') { 
			state = 'none'; 
		} else { 
			state = 'block'; 
		} 
	
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref + ".style.display = state"); 
		} 
	
		if (document.getElementById && !document.all) { 
			maxwell_smart = document.getElementById(layer_ref); 
			maxwell_smart.style.display = state; 
		} 
	} 

	function showhide_onload(layer_ref, isTrue) { 
	
		if(isTrue){
			if (state == 'block') { 
				state = 'none'; 
			} else { 
				state = 'block'; 
			} 
		
			if (document.all) { //IS IE 4 or 5 (or 6 beta) 
				eval( "document.all." + layer_ref + ".style.display = state"); 
			} 
		
			if (document.getElementById && !document.all) { 
				maxwell_smart = document.getElementById(layer_ref); 
				maxwell_smart.style.display = state; 
			} 
		}
	} 

var changedPercentBy = 200;

//returns the element.
function getElement(pElementId){
	return document.all? document.all[pElementId] : document.getElementById(pElementId);
}

//function to show errata information to the user. 
function showErrata(url){
	
	window.open(url,null,"height=520, width=550, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no");
   

}

//method to check the array contains an element.
function inArray(pArray, pValue){
	for(var i = 0; i<pArray.length; i++){
		if(pArray[i] == pValue){
			return i;
		}
	}
	return null;
}


//function for update or continue depending upon if the user
//has changed any default values in the costing page or not.

function updateOrContinue(){
	var continueBut = getElement("continue_2");
	if(continueBut!=null)
		continueBut.style.display = 'none';

	var updateBut = getElement("update_2");
	if(updateBut!=null)
		updateBut.style.display = 'block';

	var continueBut = getElement("continue_1");
	if(continueBut!=null)
		continueBut.style.display = 'none';

	var updateBut = getElement("update_1");
	if(updateBut!=null)
		updateBut.style.display = 'block';
	
	var continueBut = getElement("continue_3");
	if(continueBut!=null)
		continueBut.style.display = 'none';
}

/* function to update holiday extra price */
function updateHolidayExtraCost() {
	var total = 0;
	var carParkVal = new Array();
	var loungeVal = new Array();
	var airportObj = document.getElementsByName('airportParking');
	var loungeObj = document.getElementsByName('airportLounge');
   	var parkingLength = airportObj.length;
	var loungeLength = loungeObj.length;
	
		
	if(parkingLength != undefined){
		for(var i = 0; i < parkingLength; i++) {
			if(airportObj[i].checked) {
				carParkVal = airportObj[i].value.split("|");
				total = parseFloat(total)+ parseFloat(carParkVal[1]);
			}
		}
	}
	if(loungeLength != undefined){
		for(var i = 0; i < loungeLength; i++) {
			if(loungeObj[i].checked) {
				loungeVal = loungeObj[i].value.split("|");
				total = parseFloat(total)+ parseFloat(loungeVal[1]);
			}
		}
	}
}

//function to update prices
function updateAccommPrices(adultPrice, childPrice, numAdults, numChildren, lateCheckPrice){
	
	//call to change the continue or update buttons
	updateOrContinue();

	var lateCheckElem = null;
	var isLateCheckOptionAvailable = false;
	if(getElement("lCheck") != null){
		lateCheckElem = getElement("lCheck");
		isLateCheckOptionAvailable = lateCheckElem.checked;
		//alert("isLateCheckOptionAvailable - " + isLateCheckOptionAvailable);
	}

}

//function to update accommodation total when latecheckout option is available
function updateLatecheckPrice(checkoutPrice, pElem){	
	//alert("inside latecheckPrice method");

	//call to change the continue or update buttons
	updateOrContinue();

	//this is the current price of the accommodation total.
	var currentPrice = getElement("accomTotal").innerHTML;

	if(pElem.checked == true){
		//alert("late checkout selected, adding price");
		AjaxCostTools.addLateCheckoutPrice(currentPrice, checkoutPrice, "true", updateLatecheck);
	}

	if(pElem.checked == false){
		//alert("latecheckout de selected, updating totals");
		AjaxCostTools.addLateCheckoutPrice(currentPrice, checkoutPrice, "false", updateLatecheck);
	}
}

//callback function to update totals via ajax calls when boardbasis option is changed.
function updateBoard(data){
	var accomElem = getElement("accomTotal");
	accomElem.innerHTML = formatNumber(data);
}

//callback function to update the accom total when latecheckout option is present.
function updateLatecheck(data){
	var accomElem = getElement("accomTotal");
	accomElem.innerHTML = formatNumber(data);
}

//function to calculate dynamic pricing for flight extras
function updateFlightExtrasPrice(xbgElem, xbgPrice, pbsElem, pbsPrice, flmElem, flmPrice){
	//alert("inside orig price method.");
	
	//call to change the continue or update buttons
	updateOrContinue();
	
	var xbg = null;
	if(xbgElem != null && getElement(xbgElem) != null){
		//alert("xbg here");
		xbg = getElement(xbgElem);
	}

	var pbs = null;
	if(pbsElem != null && getElement(pbsElem) != null){
		//alert("pbs here");
		pbs = getElement(pbsElem);
	}

	var flm = null;
	if(flmElem != null && getElement(flmElem) != null){
		//alert("flm here");
		flm = getElement(flmElem);
	}
	
}


//function to calculate the total
function updateFlightPrice(data){
	//alert("inside updateFlightPrice");
	var flightElem = getElement("flightsTotal");
	flightElem.innerHTML = formatNumber(data);
}

//function to update resort price
function updateResortPrices(pElem, resortPrice, priceBasisCode, numAdults, numChildren){

	//alert("inside updateResortPrices ");
	//call to change the continue or update buttons
	updateOrContinue();
		
}

function updateResortTotals(data){
	//alert("inside updateResortTotals");
	//resort element where the price has to be shown.
	var resortElem = null;
	if(getElement("resortTotal") != null){
		resortElem = getElement("resortTotal");
		resortElem.innerHTML = formatNumber(data);
	}
}

//function to update the insurance price
function updateInsurancePrice(price){
	//call to change the continue or update buttons
	updateOrContinue();
}

//function to disable/enable the dropdowns
function updateDropDowns(pCheckBoxElem, pNumAdults, pNumChildren){	
	for(i = 1;i <= parseInt(pNumAdults);i++){
		if(pCheckBoxElem.checked == false){
		var dropDownObj = getElement('sfm_'+i);
		dropDownObj.disabled = true;		
		}
		if(pCheckBoxElem.checked == true){
		var dropDownObj = getElement('sfm_'+i);
			dropDownObj.disabled = false;		
		}
	}
	
	for(i = 1;i <= parseInt(pNumChildren);i++){
		if(pCheckBoxElem.checked == false){
		var dropDownObj = getElement('sfmc_'+i);
		dropDownObj.disabled = true;		
		}
		if(pCheckBoxElem.checked == true){
		var dropDownObj = getElement('sfmc_'+i);
			dropDownObj.disabled = false;		
		}
	}
}



//function to disable drop downs on re costing if the in flight meals was unchecked
function checkInFlightMeals(pNumAdults, pNumChildren){
	var inFlightElem = null;
	
	if(getElement("noFlightMeals") != null){
		inFlightElem = getElement("noFlightMeals");

		for(i = 1;i <= parseInt(pNumAdults);i++){
			if(inFlightElem.checked == false){
				var dropDownObj = getElement('sfm_'+i);
				dropDownObj.disabled = true;		
			}
			if(inFlightElem.checked == true){
				var dropDownObj = getElement('sfm_'+i);
				dropDownObj.disabled = false;		
			}
		}
	
		for(i = 1;i <= parseInt(pNumChildren);i++){
			if(inFlightElem.checked == false){
				var dropDownObj = getElement('sfmc_'+i);
				dropDownObj.disabled = true;		
			}
			if(inFlightElem.checked == true){
				var dropDownObj = getElement('sfmc_'+i);
				dropDownObj.disabled = false;		
			}
		}
	}
}


//function to return number given a string.
function formatNumber(value){
	value += ""; // turn into string
    if (value.indexOf(".") == -1){
		// if there is no decimal point, add .0
	        value += ".00";
	} else if (value.lastIndexOf(".") == value.length - 2) {
		// if there is one decimal place, add a 0
	    value += "0";
	}
    return value;
}
      /**
      * This method gets called from customize page when user makes a selection on the pax-type radio buttons under insurance section.
      * This makes an AJAX calls to update the state object.
      */
      function updatePaxInfo(paxType){
         if(paxType!='onload'){
			updateOrContinue();
		 }
         AjaxCostTools.updatePaxInfo(paxType,checkStatus);	
      }
      

      function checkStatus(data){
		  /**
		   * data is a string of following format.
		   * "type-noOfAdult-noOfSeniors". 'type' denotes either onclick / onload.
		   */
		if(data != null && data.indexOf("-") > 0){
			var arr = data.split("-");
			if(arr.length > 0 && arr[0] != 'onload'){             
				if(document.getElementById("adultCountHolder")){
					document.getElementById("adultCountHolder").innerHTML = arr[1];
				}else{
					//document.getElementById("adultBlock").innerHTML = '<div class="col2d margintop25px floatleft">Adult</div><div class="col3d qu4 margintop25px floatleft">'+arr[1]+'</div>';
				}
				//document.getElementById("seniorsBlock").innerHTML = "<div  class='col2c margintop5px floatleft'><div class='floatleft'>Senior</div></div><div class='col3a qu4  margintop5px floatright'>"+arr[2]+"</div>";
				//document.getElementById("insuranceTotal").style.display = "none";				
		    }
		 }
      }


     /**
     * Gets called on onClick event of insurance type radio buttons
     */
     function enableInsuranceQuote(insId,insFieldId){
       
         var insObj = document.getElementById(insFieldId);
         if(insId==null || insId == ''){
	         //var insurType = insObj.value;
			 //var 
	         var insValue = insObj.value;
	         if(insValue.indexOf('00000000-') >= 0){
	         	getElement("insQuoteWarning").style.display = 'block';
				getElement("insuranceQuote").style.display = 'none';
	         }else{
	         	getElement("insuranceQuote").style.display = 'block';
	         }
         }else{
            if(insId.indexOf('00000000-') < 0){
                if(document.getElementById("insuranceQuote"))
                	getElement("insuranceQuote").style.display = 'block';
            }else{
            	if(document.getElementById("insQuoteWarning") && document.getElementById("insuranceQuote") ){
	         		getElement("insQuoteWarning").style.display = 'none';   
					getElement("insuranceQuote").style.display = 'none';
				}
            }
         }
      }

     /**
     * Gets called on onClick event of senior radio buttons under insurance section.
     */      
      function enableWarning(){
		if(document.getElementById("insQuoteWarning")){
            document.getElementById("insQuoteWarning").style.display = 'block';
        }
            
      }
	function switchLayer(layer) {
		var elem, vis;
		elem = document.getElementById(layer);
		vis = elem.style; // if the style.display value is blank we try to figure
		// it out here
	
		if (vis.display == '' && elem.offsetWidth != undefined
				&& elem.offsetHeight != undefined) {
			vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block'
					: 'none';
	
		} else {
			vis.display = (vis.display == '' || vis.display == 'block') ? 'none'
					: 'block';
		}
	
	}

//functions to see the block in customise page.
function openParking(){
	document.getElementById("carParkingDetails").style.display='block' ;
}
function closeParking(){
	document.getElementById("carParkingDetails").style.display='none';
}
function openLounge(){
	document.getElementById("airportLoungeDetails").style.display='block';
}
function closeLounge(){
	document.getElementById("airportLoungeDetails").style.display='none';
}
		function addBaggageAllowance() {
			if(document.getElementById('extLug')) document.getElementById('extLug').checked = true;
		}
		
		
		function displayInsuranceOptionInfo(insurancePrice) {
			if(document.getElementById('insuranceOptions')) document.getElementById('insuranceOptions').style.display = "block";
			if(document.getElementById('insurReasons')) document.getElementById('insurReasons').style.display = "none";	
			//added during tc_ui_facet insuranceDefaultPriceDiv
			if(document.getElementById('insurancePriceDiv')) document.getElementById('insurancePriceDiv').style.display = "block";
			if(document.getElementById('insuranceDefaultPriceDiv')) document.getElementById('insuranceDefaultPriceDiv').style.display = "none";
		}
		function removeInsuranceOptionInfo() {
			if(document.getElementById('insuranceOptions')) document.getElementById('insuranceOptions').style.display = "none";
			if(document.getElementById('insurReasons')) document.getElementById('insurReasons').style.display = "block";
		}
		
		
	function validateForm(){
		var submit = false;
		if(document.getElementById('costPackage')){
			var insuranceForm = document.getElementById('costPackage');
			var inputFields = insuranceForm.getElementsByTagName('input');
			for(var i = 0; i < inputFields.length; i++){
				if(inputFields[i].className == 'radioButton'){
					if(inputFields[i].checked == true){
						submit = true;
						break;
					}
				}
			}
			if(submit == false){
				alert('Please select an insurance option');
				
				return false;
			} else {
				document.getElementById('continue').click();
			}
		}
	}
	function hideBaggageAllowance(){
		if(document.getElementById('baggageAllow')) {
			if(document.getElementById('baggageAllow').style.display == 'block'){
				document.getElementById('baggageAllow').style.display = "none";
			} else if(document.getElementById('baggageAllow').style.display == 'none') {
				document.getElementById('baggageAllow').style.display = "block";
			}
			
		}
	}
	
function validateTermsAndCondition(){
		document.getElementById('termsAndCondErrorMsg').style.display="none";
		if(document.getElementById('tandcs') && !document.getElementById('tandcs').checked){
			document.getElementById('termsAndCondErrorMsg').style.display="inline";
			return false;
		}
}

function updateAccommBoardBasis(currentCode, currentDesc, adultPrice, childPrice) {
	//alert("hi.............");
	AjaxCostTools.updateSelPackageBoardBasis(currentCode, currentDesc, adultPrice, childPrice);
}
function displayImpInfo(){
	//if(document.getElementById('impInfoId'))document.getElementById('impInfoId').style.display="block";
	jQuery("#impInfoId").css({
		"position" : "absolute",
		"display":"block"
	});
	jQuery("#bgImpInfoId").css({
		"opacity": "0.3",
		"display":"block"
	});
	jQuery("#bgImpInfoId").fadeIn("medium");
	jQuery("#impInfoId").fadeIn("medium");
	jQuery("#bgImpInfoId").data("state",1);
}
function displayPolicyInfo(){
	jQuery("#policyInfoId").css({
		"position" : "absolute",
		"display":"block"
	});
	jQuery("#bgpolicyInfoId").css({
		"opacity": "0.3",
		"display":"block"
	});
	jQuery("#bgpolicyInfoId").fadeIn("medium");
	jQuery("#policyInfoId").fadeIn("medium");
	jQuery("#bgpolicyInfoId").data("state",1);
}
function closeImpInfo(){
	if(document.getElementById('impInfoId'))document.getElementById('impInfoId').style.display="none";
	if (jQuery("#bgImpInfoId").data("state")==1){
		jQuery("#bgImpInfoId").fadeOut("medium");
		jQuery("#impInfoId").fadeOut("medium");
		jQuery("#bgImpInfoId").data("state",0);
	}
}
function closePolicyInfo(){
	if(document.getElementById('policyInfoId'))document.getElementById('policyInfoId').style.display="none";
	if (jQuery("#bgpolicyInfoId").data("state")==1){
		jQuery("#bgpolicyInfoId").fadeOut("medium");
		jQuery("#policyInfoId").fadeOut("medium");
		jQuery("#bgpolicyInfoId").data("state",0);
	}
}

function setExtrasForLowDeposit(insuranceId, insurancePrice){
	//alert (insuranceId + ":::::::::::::" + insurancePrice);
	document.getElementById('extrasInsuranceLowDeposit').value = insurancePrice;
}

