var r = 0;
var c = 0;
var prevCell = '';
var maxRows = 1;
var maxCols = 5;
var playTime = 200;
var clearTime = 150;

var outSelected, inSelected;
function selectHoveredFlight(flight_id, positionout, position, fare_id, fId, routePositionout, routePosition, provider)
{
 var bFound
 bFound = false
 var i
 i = 0
 oFormElements = document.getElementsByName("tblOutbound")
 
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 bFound = false
 i = 0
 oFormElements = document.getElementsByName("tblInbound")
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 
 oFormElement = document.getElementById('flight'+flight_id)
 oFormElement = document.getElementById('flightbutton'+flight_id)
 
 document.frmResults.txtIsPostBack.value="true";
 document.frmResults.FARE_PK.value=fId;
 document.frmResults.CSI_FAREID.value=fId;
 document.frmResults.fare_id.value=fare_id;
 document.frmResults.Provider_Flight.value=provider;
 
 
 if(inSelected != fId) {
  document.frmResults.route_in.value=position; 
  document.frmResults.CSI_ROUTEIDIN.value=position;
 }
 if(outSelected != fId) {
  document.frmResults.route_out.value=positionout; 
  document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
 }
 document.frmResults.route_out_position.value=routePositionout;
 document.frmResults.route_in_position.value=routePosition;
}


function selectHoveredFlightOneWay(flight_id, positionout, fare_id, fId, routePositionout, provider)
{
 var bFound
 bFound = false
 var i
 i = 0
 oFormElements = document.getElementsByName("tblOutbound")
 
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 
 oFormElement = document.getElementById('flight'+flight_id)
 oFormElement = document.getElementById('flightbutton'+flight_id)
 
 document.frmResults.txtIsPostBack.value="true";
 document.frmResults.FARE_PK.value=fId;
 document.frmResults.CSI_FAREID.value=fId;
 document.frmResults.fare_id.value=fare_id;
 document.frmResults.Provider_Flight.value=provider;
 
 if(outSelected != fId) {
  document.frmResults.route_out.value=positionout; 
  document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
 }
 document.frmResults.route_out_position.value=routePositionout;
}

function newcheckSelectedFlight(flight_pos, numberlegsout, numberlegsin)
{
 var foundOutbound
 var foundInbound
 
 foundOutbound = false;
 foundInbound = false;
 
 // PRE CHECK IF FLIGHT IS ALREADY PRE SELECTED
if(document.getElementById('tblInbound'+flight_pos+',1')) {
	 //Return
	 if(numberlegsin == 1 && numberlegsout == 1)
	 {
	  foundInbound = true;
	  foundOutbound = true;
	 }
	 if(foundOutbound == true && foundInbound == true)
	 {
	  return true;
	 }
}else{
	 //Oneway
	 if(numberlegsout == 1)
	 {
	  foundOutbound = true;
	 }
	 if(foundOutbound == true && foundInbound == true)
	 {
	  return true;
	 }	
}
 // END CHECK IF FLIGHT IS ALREADY PRE SELECTED
 for(i=1;i<=numberlegsout;i++)
 {
  oFormElement = document.getElementById('tblOutbound'+flight_pos+','+i)
  if(oFormElement.checked == true)
  {
   foundOutbound = true;
  }
 }
 for(i=1;i<=numberlegsin;i++)
 {
  oFormElement = document.getElementById('tblInbound'+flight_pos+','+i)
  if(oFormElement.checked == true)
  {
   foundInbound = true;
  }
 }
if(document.getElementById('tblInbound'+flight_pos+',1')) {
	//Return flights
	 if(foundOutbound == true && foundInbound == true)
	 {
	  return true;
	  submitform('','Updating your prices based on your new flight selection'); 
	 }
	 else
	 {
	  alert('Please select your flight options.');
	  return false;
	 }	 
 }else{
	 //Oneway flights
	 if(foundOutbound == true)
	 {
	  return true;
	  submitform('','Updating your prices based on your new flight selection'); 
	 }
	 else
	 {
	  alert('Please select your flight options.');
	  return false;
	 }		 
 }

}


function flightHotelSort(sId, sPageNum) {
	var iId = parseInt(sId);
	switch(iId){
		case 0:
			setSortHotels('default','','','0');
			break;
		case 1:
			setSortHotels('AccommInfo/AccommName','text','ascending','1');
			break;
		case 2:
			setSortHotels('AccommInfo/StarRating','number','descending','2');
			break;
		case 3:
			setSortHotels("translate(PricedRooms/PricedRoom/TotalStdPrice,',','')",'number','ascending','3');
			break;
	}
	ChangePageHotels(sPageNum);
}

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
	{ window.onload = func; }
	else
	{ window.onload = function() { oldonload(); func(); } }
}
function switchBYOSearchForms(fId)
{
	if(fId[fId.selectedIndex].value=='Flight')
	{ self.location.href='/flights/'; }
	else
	{
		if(fId[fId.selectedIndex].value.indexOf('Flight')>=0)
		{ div_switch('searchOptionsF1',true,true); div_switch('searchOptionsF2',true,true); }
		else
		{ div_switch('searchOptionsF1',false,true); div_switch('searchOptionsF2',false,true); }

		if(fId[fId.selectedIndex].value.indexOf('Hotel')>=0)
		{ div_switch('searchOptionsH1',true,true); div_switch('searchOptionsH2',true,true); }
		else
		{ div_switch('searchOptionsH1',false,true); div_switch('searchOptionsH2',false,true); }

		if(fId[fId.selectedIndex].value.indexOf('Flight')>=0 || fId[fId.selectedIndex].value.indexOf('Hotel')>=0)
		{ div_switch('searchOptionsFH1',true,true); }
		else
		{ div_switch('searchOptionsFH1',false,true); }

		if(fId[fId.selectedIndex].value.indexOf('Flight')>=0 || fId[fId.selectedIndex].value.indexOf('Car')>=0)
		{ div_switch('searchOptionsFC1',true,true); }
		else
		{ div_switch('searchOptionsFC1',false,true); }

		if(fId[fId.selectedIndex].value=='Car')
		{ div_switch('searchOptionsC1',true,true); document.frmProfileSearch.seats_adult.selectedIndex = 0; document.frmProfileSearch.seats_child.selectedIndex = 0; document.frmProfileSearch.seats_infant.selectedIndex = 0; }
		else
		{ div_switch('searchOptionsC1',false,true); }
	}
}
function setFilterHotels(sHotelName)
{ document.frmResults.txtIsPostBack.value="true"; if (document.frmResults.FilterHotels) document.frmResults.FilterHotels.value=sHotelName; }
function setLevel(fieldName, fId)
{ document.frmResults.txtLevel.value=fId; }
function setParentID(fId)
{ document.frmResults.ParentID.value=fId; }
function setFareID(fId)
{ document.frmResults.CSI_FAREID.value=fId; }
function setSortFlights(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortFlights.value=fId + ";" + datatype + ";" + order+ ";" + sId; }
function setSortHotels(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortHotels.value=fId + ";" + datatype + ";" + order + ";" + sId; }
function setSortCars(fId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortCars.value=fId; }
function setSearchType(searchId)
{ document.frmResults.search_type.value=searchId; }
function setAccomm(fieldName, fId, pId, sId, parentId, sessionId, expSupplier, expRoomCode, BoardCode)
{
	if(BoardCode==null) BoardCode='';
	document.frmResults.accomm_id.value=fId;
	document.frmResults.Provider_Accomm.value=pId;
	document.frmResults.hrnQuoteKey.value=sId;
	document.frmResults.expRoomCode.value=expRoomCode;
	document.frmResults.ParentID.value=parentId;
	document.frmResults.exp_supplier.value=expSupplier;
	document.frmResults.BoardCode.value=BoardCode;
}
function setProvider(fieldName, fId)
{
	document.frmResults.Provider_Flight.value=fId;
	document.frmResults.txtIsPostBack.value="true";
}
function updatePricingTotals(iPaxQty,sCode,sRate,sSymbol){
	var dDepositPrice = '0';
	fId = document.frmResults;
	//Get base price
	dTotalPrice = parseFloat(fId.basePrice.value);
	//Check for options and extras and add to total price
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type=="checkbox" && oFormElements.item(i).name=="CarExtras")
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).itemValue != undefined)
			{ dTotalPrice += parseFloat(oFormElements.item(i).itemValue); }
		}
		if(oFormElements.item(i).type=="radio" && (oFormElements.item(i).name=="delopt" || oFormElements.item(i).name.indexOf("_RoomID") > 0))
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).itemValue != undefined && oFormElements.item(i).itemValue != 'na'){ 
				dTotalPrice += parseFloat(oFormElements.item(i).itemValue);
			}
			
			if(oFormElements.item(i).checked && oFormElements.item(i).depositValue != undefined && oFormElements.item(i).depositValue != 'na'){ 
				dDepositPrice = parseFloat(oFormElements.item(i).depositValue);
			}
		}
	}
	//Update totals on page
	
	if(sCode && sRate) {
		sTotalPrice = formatCurrency(dTotalPrice/100*parseFloat(sRate),true);
		sPricePerPax = formatCurrency((dTotalPrice / iPaxQty)/100*parseFloat(sRate),true);
		sTotalDeposit = formatCurrency(dDepositPrice/100*parseFloat(sRate),true);
		if(sSymbol) {
			sTotalPrice = sSymbol + sTotalPrice;
			sPricePerPax = sSymbol + sPricePerPax;
			sTotalDeposit = sSymbol + sTotalDeposit;
		}else{
			sTotalPrice += ' ' + sCode;
			sPricePerPax += ' ' + sCode;
			sTotalDeposit += ' ' + sCode;
		}
	}else{
		sTotalPrice = formatCurrency(dTotalPrice);
		sPricePerPax = formatCurrency(dTotalPrice / iPaxQty);
		sTotalDeposit = formatCurrency(dDepositPrice);
	}

	writeInDiv(sTotalPrice,'total_costTop');
	writeInDiv(sPricePerPax,'perpax_costTop');
	if(document.getElementById('id_depositTop')) {
		writeInDiv(sTotalDeposit,'id_depositTop');
	}
}
function setPrices(roomPrice,roomName,iPaxQty,sCode,sRate,sSymbol)
{
	//document.frmResults.expedia_Price.value=roomPrice;
	if(document.getElementById('currentRoomName')) {
		writeInDiv(roomName,'currentRoomName');
		updatePricingTotals(iPaxQty,sCode,sRate,sSymbol);
	}else{
		writeInDiv(formatCurrency(parseFloat(roomPrice)),'total_costTop');
		writeInDiv(formatCurrency(parseFloat(roomPrice) / iPaxQty),'perpax_costTop');
		if(document.getElementById('id_depositTop')) {
			writeInDiv(formatCurrency(getDepositPrice('radio')),'id_depositTop');
		}
	}
	
}

function setPricesExp(roomPrice,roomName,iPaxQty, expRoomCode,sCode,sRate,sSymbol)
{
	//document.frmResults.expedia_Price.value=roomPrice;
	document.getElementById('expRoomCode').value = expRoomCode;
	if(document.getElementById('currentRoomName')) {
		writeInDiv(roomName,'currentRoomName');
		updatePricingTotals(iPaxQty,sCode,sRate,sSymbol);
	}else{
		writeInDiv(formatCurrency(parseFloat(roomPrice)),'total_costTop');
		writeInDiv(formatCurrency(parseFloat(roomPrice) / iPaxQty),'perpax_costTop');
		if(document.getElementById('id_depositTop')) {
			writeInDiv(formatCurrency(getDepositPrice('radio')),'id_depositTop');
		}
	}
	
}

function setDeliveryPrices(delOptionPrice,iPaxQty)
{
	if(document.frmResults.medhotels_RoomID == undefined)
	{ var fId = document.frmResults.expedia_RoomID; }
	else
	{ var fId = document.frmResults.medhotels_RoomID; }
	if(fId.length == undefined)
	{ writeInDiv(formatCurrency(parseFloat(fId.totalValue)+delOptionPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(fId.totalValue)+delOptionPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(fId.totalValue)+delOptionPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(fId.totalValue)+delOptionPrice) / paxQty),'perpax_costTop'); }
	else
	{
		for (var i=0; i < fId.length; i++)
		{ if(fId[i].checked) { writeInDiv(formatCurrency(parseFloat(fId[i].totalValue)+delOptionPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(fId[i].totalValue)+delOptionPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(fId[i].totalValue)+delOptionPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(fId[i].totalValue)+delOptionPrice) / paxQty),'perpax_costTop'); } }
	}
}
function setLMPrice(lmPrice)
{
	document.frmResults.flight_cost.value=lmPrice;
	writeInDiv(lmPrice,'total_cost');
	alert (document.frmResults.flight_cost.value)
}
function onClick(td, tablename, position, fare_id, fId, routePosition, provider)
{
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	if (tablename == "tblOutbound")
	{ document.frmResults.route_out.value=position; document.frmResults.CSI_ROUTEIDOUT.value=position; document.frmResults.route_out_position.value=routePosition; }
	else if (tablename == "tblInbound")
	{ document.frmResults.route_in.value=position; document.frmResults.CSI_ROUTEIDIN.value=position; document.frmResults.route_in_position.value=routePosition; }
}
function SetDevLayer(ShowDiv)
{ document.frmResults.ShowDiv.value=ShowDiv; }
function ChangePageFlights(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberflights.value=pagenumber; document.frmResults.ShowDiv.value='flights'; submitform('','Retrieving another page of flight results'); }
function ChangePageHotels(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberhotels.value=pagenumber; document.frmResults.ShowDiv.value='accomm'; submitform('','Retrieving another page of results'); }
function submitform(level,msg)
{
	writeInDiv(msg,'waitMessage');
	//document.getElementsByTagName("body")[0].style.background='none';
	div_switch('divWebsite',false,true);
	div_switch('divPleasewait',true,true);
	window.setInterval('scrollBar()', 40);
	document.frmResults.submit();
	
}
function PassengerInput(NoOfPax)
{ var x = 1; while (x < NoOfPax) { document.write('Pax Test'); x = x+1; } }
function setCarOption(position)
{ document.frmResults.car_position.value=position; }
function setCarOptionEx(position,supplier)
{ document.frmResults.car_position.value=position;document.frmResults.car_provider.value=supplier; }
function fetchMoreHotels(cacheKey, cacheLocation)
{ document.frmResults.fetchMoreHotels.value='true'; document.frmResults.cacheKey.value=cacheKey; document.frmResults.cacheLocation.value=cacheLocation; document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="false"; submitform('','Please wait while we retrieve more hotel results'); }
function checkSelectedFlights()
{
	var bSelOutBound = false;
	var bSelInBound = false;
	var iOutBoundFlightID = '';
	var iInBoundFlightID = '';
	for (var i=0; i<document.frmResults.tblOutbound.length; i++)
	{
		if (document.frmResults.tblOutbound[i].checked)
		{ bSelOutBound = true; iOutBoundFlightID = document.frmResults.tblOutbound[i].id; }
		else
		{ bSelOutBound = false; }
		if (bSelOutBound == true) break;
	}
	//Check if oneway or return
	if(document.getElementById("tblInbound")) {
		for (var i=0; i<document.frmResults.tblInbound.length; i++)
		{
			if (document.frmResults.tblInbound[i].checked)
			{ bSelInBound = true; iInBoundFlightID = document.frmResults.tblInbound[i].id; }
			else
			{ bSelInBound = false; }
			if (bSelInBound == true) break;
		}
	}else{
		bSelInBound = true;	
	}
	if(bSelOutBound==true && bSelInBound==true)
	{
		if(iOutBoundFlightID==iInBoundFlightID || !document.getElementById("tblInbound"))
		{ submitform('','Updating your prices based on your new flight selection'); }
		else
		{ alert('When selecting alternative flights, the outbound and inbound routes must be from the same flight!'); return false; }
	}
	else
	{ alert('Sorry, you must select an outbound and an inbound flight!'); return false; }
}

function checkPaxForm(sBookLevel, sParentID, sStartDate, sNoPax, bIsHotelOnly){
	var bContinue = true;
	//alert(bIsHotelOnly);
	if(checkFormValidateAttrib('input') == false){ 
		bContinue = false;
	}else if(checkFormFieldValue("firstname", "- First name -", "Please enter a first name for all passengers!", 2) == false){ 
		bContinue = false;
	}else if(checkFormFieldValue("surname", "- Surname -", "Please enter a surname for all passengers!") == false){
		bContinue = false;
	}else if (checkFormFieldValue("pricingEmail", "- Email -", "Please provide an e-mail address!") == false){
		bContinue = false;
	}else if (checkFormFieldValue("pricingTelephone", "- Telephone -", "Please provide a telephone number!") == false){
		bContinue = false;
	}else if(checkAgeDOBMatch(parseInt(sNoPax), sStartDate) == false){
			//alert('Ola');
			bContinue = false;
	}else if(bIsHotelOnly == 1 || bIsHotelOnly == '1'){
		//if(checkFormFieldAges("Please check the following date of births!") == false){
		//	bContinue = false;
		//}else if(checkAgeDOBMatch(parseInt(sNoPax), sStartDate) == false){
			//alert('Ola');
		//	bContinue = false;
		//}
		//if(checkAgeDOBMatch(parseInt(sNoPax), sStartDate) == false){
			//alert('Ola');
		//	bContinue = false;
		//}
	}else if(document.frmResults.CarFlightNo != undefined && (document.frmResults.CarFlightNo.value == "" || document.frmResults.CarFlightNo.value == "Flight No.")){ 
		alert('Please enter your flight number!'); document.frmResults.CarFlightNo.focus(); bContinue = false;
	}else if(document.frmResults.CarFlightTime != undefined && (document.frmResults.CarFlightTime.value.length != 5 || document.frmResults.CarFlightTime.value == "hh:mm")){
		alert('Please enter your flight arrival time!\neg. 09:00'); document.frmResults.CarFlightTime.focus(); bContinue = false;
	}else if(!document.frmResults.acceptterms.checked){
		alert('Please confirm that you have read and understood any\nimportant information and\/or terms and conditions!'); document.frmResults.acceptterms.focus(); 
		bContinue = false;
	}
	
	if(bContinue) {
		div_switch('data',false,true);
		div_switch('divPleasewait',true,true);
		setLevel('txtLevel',sBookLevel);
		if(sParentID!=''){
			setParentID(sParentID);
		}
		//alert('submit');
		submitform('booking','Processing your booking');
	}
}

function checkFormValidateAttrib(type) {
	sObjects = document.getElementsByTagName(type);
	for(x=0;x<sObjects.length;x++) {
		if(sObjects[x].getAttribute('validateFId')=='true' || sObjects[x].getAttribute('validateFId')=='True') {
			if(!sObjects[x].value) {
				alert('Please fill in the following field: ' + sObjects[x].name);
				sObjects[x].focus();
				return false;
			}
		}
	}
}


function checkAgeDOBMatch(NumPAX, DepDate){
	//alert(NumPAX+','+DepDate)
	var i, today, d, by, bm, bd, bday, age, dif, DOB
	//alert('Checking Ages');
	var sError = '';
	//var ErrTxt = "Please ensure child ages and their date of births match! -\n\n"
	//alert('AgeChecking1');
	for (i = 1; i < NumPAX+1; i++){
		//alert(i);
		if(document.getElementById('type'+i) && document.getElementById('dobd' + i) && document.getElementById('dobm' + i) && document.getElementById('doby' + i)) {
			var sType = document.getElementById('type'+i).value;
			//alert('AgeChecking1' + sType);
			//alert(NumPAX+' : '+ DepDate);
			if(sType =='ADT') {
				if(!sError) {
					DOB = document.getElementById('dobd' + i).value + "/" + document.getElementById('dobm' + i).value + "/" + document.getElementById('doby' + i).value
					if(DOB.length<10) {
						sError = 'Passenger '+i+': Please select this passengers birthdate';
					}
				}
			}else{
				iMinAge = (sType == 'CHD') ? 2 : 0;
				iMaxAge = (sType == 'INF') ? 2 : 12;
				
				//get depdate in correct format
				d = DepDate.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				today = new Date(by,bm,bd);
				
				//get childs DOB in correct format
				DOB = document.getElementById('dobd' + i).value + "/" + document.getElementById('dobm' + i).value + "/" + document.getElementById('doby' + i).value
				d =DOB.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				bday = new Date(by,bm,bd) 
				age=0; dif=bday; 
				
				while(dif<today)
				{ 
					dif = new Date(by+age,bm,parseInt(bd)-1); 
					age++; 
				} 
				
				age +=-2 ; 
				//alert(DOB.length);
				if(!sError) {
					if(DOB.length<10) {
						sError = 'Passenger '+i+': Please select this passengers birthdate';
					}else{
						if(age < iMinAge || age >= iMaxAge) {
							if(age < iMinAge){
								sError = 'Passenger '+i+': This passenger is too young to be classed as a Child passenger';
								//alert('Passenger '+i+': This passenger is too young to be classed as a Child passenger');
							}
							if(age >= iMaxAge && sType == 'CHD'){
								sError = 'Passenger '+i+': This passenger is too old to be classed as a Child passenger';
								//alert('Passenger '+i+': This passenger is too old to be classed as a Child passenger');
							}else{
								sError = 'Passenger '+i+': Infant has to be under 2 on the date of return, please enter correct date of birth.\nIf the infant is over 2 you could be refused from travelling by the airline.';
								//alert('Passenger '+i+': Infant has to be under 2 on the date of return, please enter correct date of birth.\nIf the infant is over 2 you could be refused from travelling by the airline.');
							}
						}
					}
				}
			}
		}
	}
	if(sError) {
		alert('Please ensure passengers ages and their date of births match! -\n\n'+sError);
		sError = '';
		return false;
	}
	//alert('Finished Checking Ages');
//	if (ErrTxt == "Please ensure child ages and their date of births match! -\n\n")
//		{return true;}
//	else
//		{alert(ErrTxt); return false;}
//	return true;
} 


function getDepositPrice(type) {
	// For use with MultipleRoom types; calculates the price of selected rooms
	var depositPrice = 0;
	if (document.getElementById('RoomCount')) {
		//alert('RoomCount');
		var iRooms = parseInt(document.getElementById('RoomCount').value);
		switch (type) {
			case 'radio': // Room options are in check boxes
				for (var iRoom=0; iRoom<iRooms; iRoom ++) {
					var iOption=1;
					while (document.getElementById('barceloRoomID'+(iRoom+1)+iOption)) {
						if (document.getElementById('barceloRoomID'+(iRoom+1)+iOption).checked) {
							depositPrice += parseFloat(document.getElementById('barceloRoomID'+(iRoom+1)+iOption).getAttribute('depositValue'));
						}
						iOption ++;
					}
					var iOption=1;
					var iOptionLoop=1;
					var bFound=false;
				}
				break;
		}		
	}
	return depositPrice;
}
function getTotalPrice(sCode, sRate, sSymbol, bIsPerPerson) {

iTotalPrice = 0
	iDepositPrice = 0
	/*var qs = new Querystring()
	var sDebug = qs.get("Debug")
	if(sDebug == 'true'){
		bDebug = true;
	}else{
		bDebug = false;
	}*/
	bDebug = false;
	radio = document.getElementsByTagName('input')
	var numPax = 1;
	if(document.getElementById('numPax')) { 
		numPax = parseFloat(document.getElementById('numPax').value)
	}
	for(x=0;x<radio.length;x++) {
		
		if(radio[x].getAttribute('itemValue')!=null && radio[x].getAttribute('itemValue')!='NaN') {
			if(bDebug){alert(radio[x].getAttribute('itemValue'))};
			if((radio[x].type=='radio' || radio[x].type=='checkbox') && radio[x].checked == true){
				iTotalPrice += parseFloat(radio[x].getAttribute('itemValue'))
				if(bDebug){alert('Added')};
			}
		}
		if(radio[x].getAttribute('depositValue')!=null && radio[x].getAttribute('depositValue')!='NaN') {
			if((radio[x].type=='radio' || radio[x].type=='checkbox') && radio[x].checked == true){
				iDepositPrice += parseFloat(radio[x].getAttribute('depositValue'))
				//break;
			}
		}
	}
	
	objSelect = document.getElementsByTagName('select')
	for(x=0;x<objSelect.length;x++) 
	{
		if(objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue')!=null && objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue')!='NaN')
		{
			iTotalPrice += parseFloat(objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue'))
		}
	}
	
	if(sCode && sRate) {
		sTotalPrice = formatCurrency(iTotalPrice/100*parseFloat(sRate),true);
		sPricePerPax = formatCurrency((iTotalPrice / numPax)/100*parseFloat(sRate),true);
		sTotalDeposit = formatCurrency(iDepositPrice/100*parseFloat(sRate),true);
		if(sSymbol) {
			sTotalPrice = sSymbol + sTotalPrice;
			sPricePerPax = sSymbol + sPricePerPax;
			sTotalDeposit = sSymbol + sTotalDeposit;
		}else{
			sTotalPrice += ' ' + sCode;
			sPricePerPax += ' ' + sCode;
			sTotalDeposit += ' ' + sCode;
		}
	}else{
		sTotalPrice = formatCurrency(iTotalPrice);
		sPricePerPax = formatCurrency(iTotalPrice / numPax);
		if(bIsPerPerson) {
			sTotalDeposit = formatCurrency(iDepositPrice / numPax);
		}else{
			sTotalDeposit = formatCurrency(iDepositPrice);
		}
	}
	if(document.getElementById('TotalPrice_Top')) {
		document.getElementById('TotalPrice_Top').innerHTML = sTotalPrice;
	}
	if(document.getElementById('TotalDeposit_Top')) {
		document.getElementById('TotalDeposit_Top').innerHTML = sTotalDeposit;
	}
	if(document.getElementById('PricePerPax_Top')) {
		document.getElementById('PricePerPax_Top').innerHTML = sPricePerPax;
	}
}

function getTotalPrice_old(type) {
	// For use with MultipleRoom types; calculates the price of selected rooms
	var totalPrice = 0;
	if (document.getElementById('RoomCount')) {
		//alert('RoomCount');
		var iRooms = parseInt(document.getElementById('RoomCount').value);
		switch (type) {
			case 'radio': // Room options are in check boxes
				for (var iRoom=0; iRoom<iRooms; iRoom ++) {
					var iOption=1;
					while (document.getElementById('barceloRoomID'+(iRoom+1)+iOption)) {
						if (document.getElementById('barceloRoomID'+(iRoom+1)+iOption).checked) {
							var sValue = document.getElementById('barceloRoomID'+(iRoom+1)+iOption).value;
							var sValues = sValue.split('|');
							totalPrice += parseFloat(sValues[1]);
						}
						iOption ++;
					}
					var iOption=1;
					var iOptionLoop=1;
					var bFound=false;
					while ( bFound==false)
					{
						if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption))
						{
							if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).checked) {
								
								var sValue = document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).value;
								var sValues = sValue.split('|');
								totalPrice += parseFloat(sValues[1]);
								bFound = true;
							}
						}
						iOption ++;
						if ( iOption==10) {bFound=true;}
					}
				}
				break;
		}		
	}
	return totalPrice;
}

function checkBYOForm(fId)
{
	if(fId.airportfrom.selectedIndex == 0)
	{ alert("Please select a departure airport!"); fId.airportfrom.focus(); return false; }
	else if(fId.airportto == undefined && fId.locationto == undefined && fId.pickup == undefined && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please enter a destination (min. 3 characters)!"); fId.lookup.focus(); return false; }
	else if(fId.airportto != undefined && fId.airportto[fId.airportto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.airportto.focus(); return false; }
	else if(fId.locationto != undefined && fId.locationto[fId.locationto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.locationto.focus(); return false; }
	else if(checkValidDate(fId) == false)
	{ alert("Please select an alternative departure date!\nThe date you have selected is unavailable."); fId.startdate_d.focus(); return false; }
	else if(checkTimeTravel(fId) == false)
	{ alert("Please select an alternative return date!\nYour departure date is after your return date."); fId.enddate_d.focus(); return false; }
	else
	{ return true; }
}

function changeBoardtype(sBoardtype) {
	var sTBody = document.getElementsByTagName('tbody');
	var iRoom = 1
	for(x=0;x<sTBody.length;x++) {
		if(sTBody[x].id.indexOf('_RoomOption') >= 0) {
			if(sTBody[x].id.indexOf('_'+sBoardtype+'_') >= 0) {
				sTBody[x].style.display = '';
				if(Right(sTBody[x].id,1)==iRoom) {
					sTBody[x].getElementsByTagName('input')[0].checked = true;
					sTBody[x].getElementsByTagName('span')[0].innerHTML = 'Room ' + Right(sTBody[x].id,1)
					iRoom++;
				}
			}else{
				sTBody[x].style.display = 'none';
			}
		}
	}
	//setPrices(getTotalPrice('radio')+parseFloat(document.getElementById('autoFlightCarPrice').value),'',parseFloat(document.getElementById('autoNumPax').value));
}

