var SelectedTourTab = 'search_tab3_1';
function SwitchTabs_Tour(id, on) {
	if(SelectedTourTab!=id) {
		if(on==1){
			if(document.getElementById(id).className.indexOf('Over')<0){
				document.getElementById(id).className = document.getElementById(id).className + 'Over';
			}else{
				SelectedTourTab = id;
			}
		}else{
			if(document.getElementById(id).className.indexOf('Over') > -1) {
				document.getElementById(id).className = Left(document.getElementById(id).className,document.getElementById(id).className.length-4);
			}
		}
	}
	return false;
}
var bShowOnly = 0;
function SwitchTourInfo(id, iPos, iDiv, iPackageID, dDate, sAirport, sTransportMethod) {
    if(parseFloat(bShowOnly) !== parseFloat(iPackageID)){
        bShowOnly = 0;
    }

	if(dDate == undefined || dDate == '') {
		oDateDDL = document.getElementById('ddlDate_' + iPackageID);
		if(oDateDDL){
			dDate = oDateDDL.value;
		}
		oAirportDDL = document.getElementById('ddlDeparture_' + iPackageID);
		if(oAirportDDL){
			sAirport = oAirportDDL.value;
		}
	}
	
	for(x=0;x<8;x++) {
		if(document.getElementById('search_tab'+x+'_'+iPos)) {
			document.getElementById('search_tab'+x+'_'+iPos).className = 'searchtab';
		}
		if(document.getElementById('divInfo_'+x+'_'+iPos)) {
			document.getElementById('divInfo_'+x+'_'+iPos).style.display = 'none';
		}
	}
	SelectedTourTab = id;
	if(document.getElementById(id)) {
		document.getElementById(id).className = 'searchtabOver';
	}
	if(document.getElementById('divInfo_'+iDiv+'_'+iPos)) {
		
		document.getElementById('divInfo_'+iDiv+'_'+iPos).style.display = '';

		/*if(!bShowOnly == true) {
			// Get the airport and date from the tab you are going to.
			// We will use this for checking to see if it has changed. If it has then we need to reload the tab
			// If it hasn't then we don't need to. This stops changes (like upgrades) being lost when swtiching tabs.
			var dDate_Temp = '', sAirport_Temp = '';
			oDateDDL = document.getElementById('ddlDate' + sDDLExtra + '_' + iPackageID);
			if(oDateDDL){
				dDate_Temp = oDateDDL.value;
			}
			oAirportDDL = document.getElementById('ddlDeparture' + sDDLExtra + '_' + iPackageID);
			if(oAirportDDL){
				sAirport_Temp = oAirportDDL.value;
			}
			if(((sAirport_Temp === sAirport && dDate_Temp === dDate) || (dDate_Temp !== '' && dDate === '')) && bShowOnly) {
				// If the dates and departure are the same then don't reload the tab
				bShowOnly_Temp = true;
			}else if(sDDLExtra === 'WhatsIncluded') {
				// Reload the tab
				// The iDivFrom check is to make sure it's not reloading after being on the what's included tab
				bShowOnly_Temp = false;
			}
		}*/
		if(bShowOnly === 0 || iDiv !== 2) {
			var sDivID = 'divDateSelect' + iPos;
			document.getElementById(sDivID).innerHTML = '<div align="center"><img src="/images/animations/ajax-loader-white.gif" /></div>';
			var sSessionID = document.getElementById('SessionID').value;
			sURL = '/includes/tours/ToursAJAX_Response.asp?SessionID=' + sSessionID + '&PackageID=' + iPackageID + '&Date=' + dDate + '&AirportCode=' + sAirport + '&Position=' + iPos + '&transportMethod=' + sTransportMethod;
			var oTourInfo1 = new TourAJAX(sDivID, sURL);
			oTourInfo1.update(sDivID);
			
			document.getElementById('divInfo_'+iDiv+'_'+iPos).innerHTML = '<div align="center"><img src="/images/animations/ajax-loader-white.gif" style="margin-top:15px;" /><br /><br /><span class="resultPleaseWait">Loading... Please wait.</span></div>';
			sDivID = 'divInfo_'+iDiv+'_'+iPos;
			var sURL = '/includes/tours/ToursAJAX_Response.asp?Div=' + iDiv + '&SessionID=' + sSessionID + '&PackageID=' + iPackageID + '&Date=' + dDate + '&AirportCode=' + sAirport + '&transportMethod=' + sTransportMethod;
			var oTourInfo = new TourAJAX(sDivID, sURL);
			oTourInfo.update(sDivID);
			//updatePrices(iPackageID, iDiv);	
		}
	}
}

function tourMoreInfo(iTourID, iAccommID, sSessionID, sDivID){
	sURL = '/includes/info/moreinfo.asp?provider=PackageEngineV2&id=' + iTourID + '&session=' + sSessionID + '&type=Tour&AccommID=' + iAccommID + '&sDivID=' + sDivID;
	var oTourInfo = new TourAJAX(sDivID, sURL);
	oTourInfo.update(sDivID);
}

function TourAJAX(layer, url) {
	var sAdditionalParams = '';
	if(url.indexOf('?') > -1){
		sAdditionalParams = '&' + url.split('?')[1];
		url = url.split('?')[0];
	}
	var that=this;                                                    // A workaround for some javascript idiosyncrocies   
	var updating = false;                                             // Set to true if this object is already working on a request   
	this.callback = function() {}                                     // A post-processing call -- a stub you overwrite.   
	this.update = function(passData) {                                // Initiates the server call.      
		if (updating==true) { return false; }                          // Abort if we're already processing a call.      
		updating=true;                                                 // Set the updating flag.      
		var AJAX = null;                                               // Initialize the AJAX variable.      
		if (window.XMLHttpRequest) {                                   // Are we working with mozilla?         
			AJAX=new XMLHttpRequest();                                  //  Yes -- this is mozilla.      
		} else {                                                       // Not Mozilla, must be IE         
			AJAX=new ActiveXObject("Microsoft.XMLHTTP");                //  Wheee, ActiveX, how do we format c: again?      
		}                                                              // End setup Ajax.      
		if (AJAX==null) {                                              // If we couldn't initialize Ajax...         
			alert("Your browser doesn't support AJAX.");                // Sorry msg.                                                       
			return false;                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)      
		} else {        
			AJAX.onreadystatechange = function() {                      // When the browser has the request info..       
			if(LayerID){
				if (AJAX.readyState==4 || AJAX.readyState=="complete") { //   see if the complete flag is set.   
					var sText = AJAX.responseText;
					if(sText.indexOf("|") > -1){
						sText = sText.split("|")[1];
					}
					document.getElementById(LayerID.id).innerHTML=sText;                 	 //   It is, so put the new data in the object's layer               
					decoGreyboxLinks(1); // This is a function for greybox which initialises the script for the loaded images
					
				    if(document.getElementById(passData+'GoogleMapContainer')) {
				        oGoogleMapLat = document.getElementById(passData+'GoogleMapLat');
				        oGoogleMapLng = document.getElementById(passData+'GoogleMapLng');
				        if(oGoogleMapLat && oGoogleMapLng)
				        {
				            var iGoogleLat;
				            var iGoogleLng;
				            iGoogleLat = oGoogleMapLat.value;
				            iGoogleLng = oGoogleMapLng.value;
					        if(iGoogleLat!=0 && iGoogleLng!=0) {
						        document.getElementById(passData+'GoogleMapContainer').style.display='';
						        LoadGoogleMap(passData+'GoogleMap',iGoogleLat,iGoogleLng);
					        }
				        }
				    }
				    
					delete AJAX;                                          //   delete the AJAX object since it's done.               
					updating=false;                                       //   Set the updating flag to false so we can do a new request               
					that.callback();                                      //   Call the post-processing function.            
				}                                                       // End Ajax readystate check.   
			}
		}                                                           // End create post-process fucntion block.         
		var timestamp = new Date();                                 // Get a new date (this will make the url unique)        
		var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1) + sAdditionalParams;   // Append date to url (so the browser doesn't cache the call)         
		
		AJAX.open("GET", uri, true);                                // Open the url this object was set-up with.         
		AJAX.send(null);                                            // Send the request.         
		return true;                                                // Everything went a-ok.     
		}                                                              // End Ajax setup aok if/else block                    
	}         // This area set up on constructor calls.   
	var LayerID = document.getElementById(layer);                     // Remember the layer associated with this object.   
	var urlCall = url;  
	// Remember the url associated with this object.
}  
function toggleUpgrades(iPackageID, iStay, iAccommID, bCloseOnly) {
	var bAccommInfo = false;
	if(iAccommID > 0){
		bAccommInfo = true;
		var oChanger = document.getElementById('divHotelInfo' + iStay + '_' + iAccommID + '_' + iPackageID);
		var oText = document.getElementById('a_Info_' + iAccommID + '_' + iPackageID + '_' + iStay);
		if(oChanger) {
			if(oChanger.style.display === 'none' && bCloseOnly !== true){
				//oChanger.style.display = '';
				oText.innerHTML = oText.innerHTML.replace('View', 'Hide');
			}else{
				//oChanger.style.display = 'none';
				oText.innerHTML = oText.innerHTML.replace('Hide', 'View');
			}
		}
	}else{
		for(var i=0; i<100; i++) {
			var oChanger = document.getElementById('tb' + iPackageID + '_' + iStay + '_' + i);
			var oText = document.getElementById('a' + iPackageID + '_' + iStay);
			if(oChanger){
				if(oChanger.style.display === 'none' && bCloseOnly !== true){
					oChanger.style.display = '';
					if(oText) {oText.innerHTML = oText.innerHTML.replace('View', 'Hide')};
				}else{
					if(oChanger.getElementsByTagName('tr')[0].className === 'Upgrade') {
						oChanger.style.display = 'none';
						if(oText) {oText.innerHTML = oText.innerHTML.replace('Hide', 'View')};
					}
				}
			}else{
				break;	
			}
		}
	}
	bShowOnly = iPackageID;
}

function changeDeparture(sAirportCode, sSessionID, sDivID, iPackageID) {
	sURL = '/includes/tours/dateddl.asp?AirportCode=' + sAirportCode + '&SessionID='+sSessionID + '&PackageID=' + iPackageID;
	var oTourInfo = new TourAJAX(sDivID, sURL);
	oTourInfo.update(sDivID);
}

function changeContent(iPackageID, sDDLExtra, iPos, bUpdatePrices) {

    if (bUpdatePrices == null)
    {
        bUpdatePrices = true;
    }

	if(document.getElementById('ddlDate_' + iPackageID)) {
		var dDate = document.getElementById('ddlDate_' + iPackageID).value;
		if(document.getElementById('ddlDeparture_' + iPackageID)) {
			var sAirport = document.getElementById('ddlDeparture_' + iPackageID).value;
		}
		var iDiv = parseInt(SelectedTourTab.split('_')[1].replace('tab','')) - 1;
		var iSearchDiv = parseInt(iDiv) + 1;
		var sID = 'search_tab' + iSearchDiv + '_' + iPos;
		bShowOnly = 0;
		SwitchTourInfo(sID, iPos, iDiv, iPackageID, dDate, sAirport);
		updatePrices(iPackageID, iDiv, bUpdatePrices);
	}else{
		setTimeout("changeContent(" + iPackageID + ", '" + sDDLExtra + "', " + iPos + ", " + bUpdatePrices + ")", 100);
	}

}

function selectUpgrade(sID, iPackageID, iStay, iStayOption, iRoomPos) {
	var oUpgrade = document.getElementById(sID);
	if(iRoomPos){
	    sSelectedText = 'Selected room'
	}else{
	    sSelectedText = 'Selected hotel'
	}
	if(oUpgrade) {
		var sClass = 'Upgrade'; //changed from '' JF 05-08-2009
		for(var i=0; i<100; i++) {
			if (isNaN(iStay)){
				if(iStay.indexOf('-') > -1) {
					var oChanger = document.getElementById('tb' + iPackageID + '_' + iStay.split('-')[0] + '-' + (i + 1) + iStayOption + iRoomPos +'_'+iStayOption);
					sName = 'divSelect' + iPackageID + '_' + iStay.split('-')[0] + '-' + (i + 1) + iStayOption + iRoomPos + '_'+iStayOption;
				}else{
					//alert('2\ntb' + iPackageID + '_' + iStay + '_' + i);
					var oChanger = document.getElementById('tb' + iPackageID + '_' + iStay + '_' + i);
					sName = 'divSelect' + iPackageID + '_' + iStay + '_' + i;
				}
			}else{
				//alert('3\ntb' + iPackageID + '_' + iStay + '_' + i);
				var oChanger = document.getElementById('tb' + iPackageID + '_' + iStay + '_' + i);
				sName = 'divSelect' + iPackageID + '_' + iStay + '_' + i;
			}
			if(oChanger){
				for(var j=0; j<2; j++){
					var oTR_Temp = oChanger.getElementsByTagName('tr')[j];
					if(oTR_Temp) {
						if(oTR_Temp.className != 'Upgrade') {
							sClass = oTR_Temp.className;
						}
						oTR_Temp.className = 'Upgrade';
					}
				}
				document.getElementById(sName).innerHTML = document.getElementById(sName).innerHTML.replace(sSelectedText, 'Select');
			}
		}
		for(var k=0; k<2; k++) {
			var oTR = oUpgrade.getElementsByTagName('tr')[k];
			if(oTR) {
				oTR.className = 'Light';
			}
		}
		document.getElementById('divSelect' + iPackageID + '_' + iStay + '_' + iStayOption).innerHTML = document.getElementById('divSelect' + iPackageID + '_' + iStay + '_' + iStayOption).innerHTML.replace(sSelectedText, 'Select').replace('Select', sSelectedText);
		if(document.getElementById('rbUpgrades_' + iPackageID + '_' + iStay + '_' + iStayOption)) {
			document.getElementById('rbUpgrades_' + iPackageID + '_' + iStay + '_' + iStayOption).checked = true;
		}
	}
	updatePrices(iPackageID, 2);	
}

function selectAltFlight(sID, iPackageID, iFlightPos){
	var oAltFlight = document.getElementById(sID);
	if (oAltFlight){
		for(var i=1; i<20; i++) {
			var oChanger = document.getElementById('PEV2_F' + i);
			sName = 'divSelect_F' + i;
			if(oChanger){
				document.getElementById(sName).innerHTML = document.getElementById(sName).innerHTML.replace('Selected', 'Select');
			}
		}
		//alert('divSelect_F' + iFlightPos)
		document.getElementById('divSelect_F' + iFlightPos).innerHTML = document.getElementById('divSelect_F' + iFlightPos).innerHTML.replace('Select', 'Selected');
	}
}


function updatePrices(iPackageID, iDiv, bUpdateSubTotal){

    if (bUpdateSubTotal == null)
    {
        bUpdateSubTotal = true;
    }

	var oDateDDL = document.getElementById('ddlDate_' + iPackageID);
	var oDepartingText = document.getElementById('spnDepartingText_' + iPackageID);
	var oSubDiv = document.getElementById('spnPrice_Sub_' + iDiv + '_' + iPackageID);
	var dbTempPrice = 0;
	var dbPrice = 0;
	var iSelectedCount = 0;
	if(oDateDDL && (oSubDiv || iDiv === 0)) {
		var iNumPax = document.getElementById('hidNumPax_' + iPackageID).value;
		var iMaxOcc = document.getElementById('hidMaxOcc_' + iPackageID).value;
		dbPrice = oDateDDL.options[oDateDDL.selectedIndex].attributes['Price'].value;
		for(x=0;x<101;x++) {
			var oRadio = document.getElementsByName('rbUpgrades_' + iPackageID + '_' + x);
			if(oRadio) {
				for(y=0;y<100;y++) {
					if(oRadio[y]) {
						if(oRadio[y].checked === true){
							dbTempPrice += parseFloat(oRadio[y].attributes['Price'].value);
							iSelectedCount += 1;
						}
					}else{
						break;	
					}
				}
			}else{
				break;
			}
		}
		var dbTotalPrice = (parseFloat(dbPrice) + parseFloat(dbTempPrice)) / parseInt(iMaxOcc);
		var sUpdate = formatCurrency(parseFloat(dbTotalPrice) * parseFloat(iNumPax), false);
		document.getElementById('spnPrice_' + iPackageID).innerHTML = '<strong>Total price: ' + sUpdate + '</strong>';
		document.getElementById('spnPrice_Av_' + iPackageID).innerHTML = '(Avg/person: ' + formatCurrency(parseFloat(dbTotalPrice), false) + ')';
		//if(oSubDiv && iSelectedCount > 0) {
		if(oSubDiv && bUpdateSubTotal) {
			document.getElementById('spnPrice_Sub_' + iDiv + '_' + iPackageID).innerHTML = sUpdate;
			document.getElementById('spnPrice_SubSub_' + iDiv + '_' + iPackageID).innerHTML = sUpdate;
		}
		// Set departing text in steps.asp
		var oDepDDL = document.getElementById('ddlDeparture_' + iPackageID);
		sUpdate = '';
		if(oDepDDL){
			sUpdate = '<strong>Current departure point: </strong> ' + oDepDDL.options[oDepDDL.selectedIndex].text.split('-')[0];	
		}
		sUpdate += '<br /><strong>Current departure date: </strong> ' + oDateDDL.options[oDateDDL.selectedIndex].text.split('-')[0];
		if(oDepartingText) {oDepartingText.innerHTML = sUpdate};
	}else{
		setTimeout("updatePrices(" + iPackageID + ", " + iDiv + ", " + bUpdateSubTotal + ")", 100);
	}
}
function updateRBPrice(sTheID, oDDL) {
	var oRB = document.getElementById(sTheID);
	var oDIV = document.getElementById(sTheID.replace('PEV2_S', 'divPrice'));
	if(oRB) {
		if(oDDL) {
			var dbUpdate = parseFloat(oDDL.options[oDDL.selectedIndex].attributes['extracost'].value);
			var upCode = oDDL.options[oDDL.selectedIndex].attributes['upgradecode'].value;
			oRB.attributes['itemvalue'].value = dbUpdate;
			oRB.attributes['value'].value = upCode;
		}else{
			var dbUpdate = oRB.attributes['itemvalue'].value;
		}
	}
}
function showSteps(iDiv, iPackageID) {
	
	var oChanger = document.getElementById('divSteps_' + iDiv + '_' + iPackageID);
	var oText = document.getElementById('aSteps_' + iDiv + '_' + iPackageID);
	if(oChanger){
		if(oChanger.style.display === 'none'){
			oChanger.style.display = '';
			if(oText) {oText.innerHTML = oText.innerHTML.replace('View', 'Hide')};
		}else{
			oChanger.style.display = 'none';
			if(oText) {oText.innerHTML = oText.innerHTML.replace('Hide', 'View')};
		}
	}

}

function showRowExtrasUpsell(iValue, sExtraCode) {
	for(var i=1; i<50; i++) {
		var oRows = document.getElementsByName('tr' + sExtraCode + '_Pax' + i);
		if(oRows.length > 0) {
			for(var j=0; j<oRows.length; j++) {
				var oRow = oRows[j];
				oRow.style.display = 'none';
			}
		}else{
			break;	
		}
	}
	for(var i=0; i<iValue; i++) {
		var oRows = document.getElementsByName('tr' + sExtraCode + '_Pax' + i);
		if(oRows.length > 0) {
			for(var j=0; j<oRows.length; j++) {
				var oRow = oRows[j];
				oRow.style.display = '';
			}
		}else{
			break;	
		}
	}
}

// NE 16/07/2009 Extras Upsell Validation
function euLoadDoc(session) {
	url = '/buildyourown/xml_price/'+session+'.xml';
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = euValidate;
		req.open("GET", url, true);
		req.send(null);
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = euValidate;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function euValidate() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var XMLDoc = req.responseXML;

			try {
				var rootNode = XMLDoc.childNodes[0];
				var pricingNode = findChildNode(rootNode, 'PRICING');
				var toursNode = findChildNode(pricingNode, 'TOURS');
				alert(toursNode);
				if (extrasNodes) {
					for (iextra=0;iextra<extrasNodes.count;iextra++) {
						extraNode = extrasNodes[iextra];
						alert(extraNode);
						if (etxraNode.attributes["PerBooking"] == 'false') {
							/*
								Check if an extra is required; if so, and there are groups, check something from each selected/required group has been selected, and that the value corresponds
								passes any reg ex validation.
								
								A passenger should not be selected to an extra more than once
								
							*/
						}
						else 
						{
							/*
								Check if an extra is required; if so, and there are groups, check something from each selected/required group has been selected, and that the value corresponds
								passes any reg ex validation.
							*/
						}
					}
				}
			}
			catch (err) {
				alert('Error1: '+err);
			}
		} else {
			alert('There was a problem loading the data. Please try again.');
		}
	}

}

function findChildNode(parentNode, childNodeName) {
	var foundNode;
	for (i=0;i<parentNode.childNodes.length;i++) {
		if (parentNode.childNodes[i].nodeName == 'TOURS') { 
			foundNode = parentNode.childNodes[i]; 
			break; 
		}
	}
	return foundNode;
}

function toggleUpsellOptions(id) {
	
	var oChanger = document.getElementById('tb' + id);
	var oText = document.getElementById('a' + id);
	if(oChanger){
		if(oChanger.style.display === 'none'){
			oChanger.style.display = '';
			if(oText) {oText.innerHTML = oText.innerHTML.replace('View', 'Hide')};
		}else{
			oChanger.style.display = 'none';
			if(oText) {oText.innerHTML = oText.innerHTML.replace('Hide', 'View')};
			var oInputs = document.getElementsByTagName('input');
			for(var i=0; i<oInputs.length; i++) {
				if(oInputs[i].id.indexOf(id) > -1) {
					if(oInputs[i].type === 'text') {
						oInputs[i].value = '';
					}
					if(oInputs[i].type === 'checkbox') {
						oInputs[i].checked = false;	
					}
				}
			}
			var oInputs = document.getElementsByTagName('select');
			for(var i=0; i<oInputs.length; i++) {
				if(oInputs[i].id.indexOf(id) > -1) {
					oInputs[i].options[1].selected = true;
				}		
			}
		}
	}
}

function updateExtraPrice(bCheckAndClear) {
	var iCheckedCount = 0;

	var oInputs = document.getElementsByTagName('input');
	var sPaxID = '|';
	for(var i=0; i<oInputs.length; i++) {
		
		if(oInputs[i].id.indexOf('txtCost') > -1) {
			oInputs[i].value = 0;
		}else{
			if(oInputs[i].attributes['dbPrice']) {
				//alert('oInputs[i].id: ' + oInputs[i].id + '\noInputs[i].type: ' + oInputs[i].type + '\n oInputs[i].checked:' + oInputs[i].checked + '\n oInputs[i].attributes[dbPrice]:' + oInputs[i].attributes['dbPrice'])
				if((oInputs[i].type === 'checkbox' && oInputs[i].checked) || oInputs[i].type !== 'checkbox') {
					bAdd = true;
					if(oInputs[i].id.indexOf('ddlQty') > -1 || (oInputs[i].id.indexOf('cb_') && oInputs[i].attributes['GroupRequired']) > -1) {
						var iPaxID = oInputs[i].id.split('_')[1];
						//alert('here! ' + bAdd + ': ' + iPaxID)
					}else{
						var iPaxID = oInputs[i].id.split('_')[0].replace('txt', '');
						var oCheckForThisUpgrade = document.getElementById('cb_' + oInputs[i].id.replace('txt', ''));
						if(oCheckForThisUpgrade) {
						    //alert('yes ' + iPaxID + ' - 1');
							if(!oCheckForThisUpgrade.checked) {
    						   // alert('yes ' + iPaxID + ' - 2');
								bAdd = false;	
								if(bCheckAndClear === true) {oInputs[i].value = '';}
							}else{
                                iCheckedCount +=1;
							}
						}else{
                           iCheckedCount +=1;
						}
					}
					if(bAdd) {
						if(bCheckAndClear && oInputs[i].value === '') {
							alert('Please enter a value for all selected upgrades');
							return false;
							break;
						}
						//alert("sPaxID.indexOf('|' + iPaxID + '|'): " + sPaxID.indexOf('|' + iPaxID + '|') + '\nsPaxID: ' + sPaxID + '\niPaxID: ' + iPaxID);
						if(sPaxID.indexOf('|' + iPaxID + '|') == -1) {
							sPaxID += '|' + iPaxID + '|';
							eval("var dbUpdate" + iPaxID + " = 0;");
						}
						//eval("alert(iPaxID + '-' + dbUpdate" + iPaxID + ");");
						eval("dbUpdate" + iPaxID + " = parseFloat(dbUpdate" + iPaxID + ") + parseFloat(oInputs[i].attributes['dbPrice'].value);");
						//eval("alert(iPaxID + '-' + dbUpdate" + iPaxID + ");");
					}
				}else if(oInputs[i].type === 'checkbox' && oInputs[i].attributes['GroupRequired']) {
					if(bCheckAndClear && !oInputs[i].checked) {
						bAdd = true;
						var oCheckForThisUpgrade = document.getElementById('ddlQty_' + oInputs[i].id.split('_')[1] + '_' + oInputs[i].id.split('_')[2]);
						if(oCheckForThisUpgrade) {
						    //alert('yes ' + iPaxID + ' - 1');
							if(!oCheckForThisUpgrade.checked) {
    						   // alert('yes ' + iPaxID + ' - 2');
								bAdd = false;	
							}else{
		                        iCheckedCount +=1;
							}
						}
						if(bAdd) {
							alert('Please ensure you have selected all required options');
							return false;
							break;
						}
					}					
				}
			}
		}
	}
	var bAdded = false;
	var oInputs = document.getElementsByTagName('select');
	for(var i=0; i<oInputs.length; i++) {
		var oDDL = oInputs[i];
		var iPaxID = oDDL.id.split('_')[1];
		//alert('1: ' + iPaxID)
		
		if(iPaxID === '') { iPaxID = 0; }
		if(oDDL.options[oDDL.selectedIndex].attributes['dbPrice']) {
		   //alert(sPaxID + '\n|' + iPaxID + '|')
			if(sPaxID.indexOf('|' + iPaxID + '|') == -1) {
			    //alert('Reset: ' + iPaxID + '\n' + sPaxID);
				if(sPaxID !== '') {
					sPaxID += '|';
				}
				sPaxID += iPaxID + '|';
				eval("var dbUpdate" + iPaxID + " = 0;");
			}
			bAdd = true;
			var oCheckForThisUpgrade = document.getElementById('cb' + oInputs[i].id.replace('ddlVar', ''));
			if(oCheckForThisUpgrade) {
			    //alert(oCheckForThisUpgrade.id + '\nChecked: ' + oCheckForThisUpgrade.checked);
				if(!oCheckForThisUpgrade.checked) {
					bAdd = false;
					bUpgradeChecked = false;
					if(bCheckAndClear === true) {oDDL.options[0].selected = true;}
			    }else{ 
			        bUpgradeChecked = true; 
		            iCheckedCount +=1;
			    }
			}
			if(bAdd) {
				if(bCheckAndClear && oDDL.options[0].selected === true && oInputs[i].id.indexOf('ddlVar') > -1) {
					alert('Please enter a value for all selected upgrades');
					return false;
					break;
				}
				if(oInputs[i].selectedIndex === 0 && oInputs[i].attributes['GroupRequired'] && bCheckAndClear) {
					alert('Please ensure you have selected all required options');
					return false;
					break;
				}	
				bFreeUpgrades = true;
				
				
			    var dbUpdateAmount = oDDL.options[oDDL.selectedIndex].attributes['dbPrice'].value;	
			    if(oDDL.id.indexOf('ddlQty') > -1) {
				    dbUpdateAmount = parseFloat(dbUpdateAmount) * oDDL.value;
				}

				eval("dbUpdate" + iPaxID + " = parseFloat(dbUpdate" + iPaxID + ") + parseFloat(dbUpdateAmount);")
			    //eval("alert('1: dbPrice:' + parseFloat(oDDL.options[oDDL.selectedIndex].attributes['dbPrice'].value));");
			    //eval("alert('1: dbUpdate" + iPaxID + ":' + dbUpdate" + iPaxID + ");");
			}else{
			    var oCB = document.getElementById('ddlQty_' + oInputs[i].id.split('_')[1] + '_' + oInputs[i].id.split('_')[2]);
			    var bSelected = false;
			    if(oCB.type === 'checkbox' && oCB.checked) {
			        bSelected = true;
			    }else if(oCB.type === 'select' && oCB.selectedIndex > 0) {
			        bSelected = true;
			    }
			    if(oInputs[i].selectedIndex === 0 && oInputs[i].attributes['GroupRequired'] && bCheckAndClear && bSelected){
				    alert('Please ensure you have selected all required options');
				    return false;
				    break;	
				}		    			    
			}
		}
	}
	var arPaxIDs = sPaxID.split('|');
	var dbPerBooking = 0;
	try {
		dbPerBooking = parseFloat(dbUpdate0);
	}catch(ex){
		
	}
	//dbPerBooking = parseFloat(dbPerBooking / arPaxIDs.length);
	var dbTotalCost = dbPerBooking;
	for(var i=0; i<arPaxIDs.length; i++) {
		if(document.getElementById('txtCost' + arPaxIDs[i]) && parseFloat(arPaxIDs[i]) !== 0) {
		    
			//eval("alert(dbUpdate" + arPaxIDs[i] + ");");
			//eval("alert('2: dbUpdate" + arPaxIDs[i] + ": ' + dbUpdate" + arPaxIDs[i] + ");");
			eval("document.getElementById('txtCost" + arPaxIDs[i] + "').value = dbUpdate" + arPaxIDs[i]);
			eval("dbTotalCost = parseFloat(dbTotalCost) + parseFloat(dbUpdate" + arPaxIDs[i] + ")");
		}else{
			
		}
	}
	//alert(formatCurrency(dbTotalCost));
	document.getElementById('spnPrice').innerHTML = formatCurrency(dbTotalCost);

	if((bCheckAndClear && dbTotalCost === 0) && iCheckedCount === 0) {
		alert('Please add or upgrade at least one extra');
		return false;
	}
}
function SubmitTour(iType, iPackageID, oVar1, oVar2, oVar3, oVar4) {
    var iLastI = 0, iStayCount = 0, iCheckedCount = 0;
    
    for(var i=0; i< 21; i++){
        if(!document.getElementById('rbUpgrades_' + iPackageID + '_' + i + '_1')){
            break;
        }else{
            if(parseInt(i) + 1 !== iLastI) {
                iStayCount += 1;
            }
            for(var j=1; j< 201; j++){
                var oRadio = document.getElementById('rbUpgrades_' + iPackageID + '_' + i + '_' + j);
                if(oRadio){
                    if(oRadio.checked){
                        iCheckedCount += 1;
                    }
                }else{
                    break;
                }
            }
            iLastI = parseInt(i) + 1;
        }
    }
    //alert(iStayCount + ' *** ' + iCheckedCount)
    
    var oDeparture = document.getElementById('ddlDeparture_' + iPackageID);
    if (oDeparture)
    {
        if (oDeparture.value == "")
        {
            alert('Please select a departure point before continuing.');
            return;
        }
    }
    
    if(iStayCount !== iCheckedCount) {
        alert('Please select accommodation for each part of your stay');
    }else{
        if(iType === 0) {
		    redirectTourToFlightHotel(iPackageID, oVar1, oVar2);
        }else{
	        setLevel('PRICING');
	        setTour(oVar1, oVar2, oVar3, oVar4);
	        frmBYOSubmit();
	    }
    }
}
