// Just in case any debugging is left in somewhere
function trace( msg ){ if( typeof( jsTrace ) != 'undefined' ){ jsTrace.send( msg ); } }

// ########################################
// For future faretable enhancements
// ########################################
var lastMore = 0; 
var newMore = 0;

function showHide ( id, newID_no )
{	
	newMore = newID_no;
	
	var moreID = document.getElementById(id);
	var lastID = document.getElementById("more"+lastMore);

	// Check to see if we should:
	// show or hide
	if (moreID.style.display != "none")
	{
		moreID.style.display = "none";
	} else
	{
		moreID.style.display = "block";
		if (lastMore != 0 && newID_no != lastMore)
			lastID.style.display = "none";
			
		lastMore = newID_no;
	}
}

function id_show ( id )
{	
	var moreID = document.getElementById(id);

	// Check to see if we should:
	// show or hide
	moreID.style.display = "";
}

function id_hide ( id )
{	
	var moreID = document.getElementById(id);

	// Check to see if we should:
	// show or hide
	moreID.style.display = "none";
}


// ########################################
// Generic Popup Window Activator
// ########################################

function popUp( URL, pop_h )
{
	pop_w = 625;
	pop_h = pop_h ? pop_h : 485;
	
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=" + pop_w + ",height="+ pop_h +"');");
}




/* navigation */
function nav(modl, page, mode)
{
	document.navForm.module.value	= modl  || 'SB';
	document.navForm.page.value	= page  || '';
	document.navForm.mode.value	= mode  || '';
	document.navForm.submit();
}


/* Popups */

function open_mobility() {
	window.open("http://www.virginblue.com.au/Info/WheelchairsAirport/index.htm",'Mobility',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_med() {
	window.open("http://www.virginblue.com.au/Info/MedicalConditions/index.htm",'Medical',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_meet() {
	window.open("http://www.virginblue.com.au/Info/MeetandAssist/index.htm",'surcharge',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_vision() {
	window.open("http://www.virginblue.com.au/Info/Vision/index.htm",'Vision',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_service() {
	window.open("http://www.virginblue.com.au/Info/ServiceDogs/index.htm",'Service',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_indtrvl() {
	window.open("http://www.virginblue.com.au/Info/Independenttravel/index.htm",'IndependantTravel',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_schedules() {
	window.open("http://www.virginblue.com.au/Info/Schedules/index.htm",'Schedules',"width=800,height=700,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_cxlfee() {
	window.open("http://www.virginblue.com.au/Info/ChangeandCancelFee/index.htm",'CancelFees',"width=740,height=640,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_minors() {
	page = window.open("http://www.virginblue.com.au/Info/Minors/index.htm","Minors","width=640,height=460,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_ccfee() {
	page = window.open("http://www.virginblue.com.au/Info/CreditCardFees/index.htm","CreditCardFees","width=640,height=460,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_help() {
	window.open("http://www.virginblue.com.au/Info/24Hour/index.htm","help","width=640,height=460,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function show_secure() {
	window.open("https://bookings.virginblue.com.au/Info/Thawte/index.htm","thawte","width=640,height=460,toolbar=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function open_specials(){
	window.open("http://www.virginblue.com.au/Personal/Specialsoffers/Specials/index.htm","Specials","width=800,height=600,toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1");
}

function open_kit(){
	window.open("http://www.virginblue.com.au/Info/SalesKit/index.htm","Kit","width=620,height=530,toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1");
}			

function open_hotdeals(){
	var sid = document.navForm.sid.value;
	page = window.open("/agents/skylights/agenthd.php?sid="+ sid,"hotdeals","width=770,height=520,toolbar=1,status=1,menubar=1,scrollbars=1,resizable=1");		
}

function open_passport(){
	window.open("http://www.virginblue.com.au/Info/Passports/index.htm","Specials","width=800,height=600,toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1");
}

function show_cvv(){
	window.open("http://www.virginblue.com.au/Info/CVV/index.htm","CVV","width=800,height=600,toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1");
}				

/* Itinerary Services */
Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
};

function apollo(dest)
{
	var content = ['Campervans and Motorhomes', 'http://virginblue.apollocamper.com/', 'Book Campervans, Motorhomes or off-airport rental cars here'];
	var iata = new Array("SYD","MEL","BNE","ADL","CNS","DRW","PER","BME","AKL","CHC");
						
	if (iata.contains(dest))  {	    
	    insert_travel_extra('travel-extras', content);	  
	} 
}  

function parking()
{
	var market_array = document.itinerary_info.info_mkt1_seg1.value.split('|');
	var origin = market_array[5].toUpperCase();
	var dest = market_array[6].toUpperCase();
	var City = '';
	var Price = '';
					
	switch (origin)
	{
		case "ADL":
		City = 'Adelaide';
		Price = '6';
		break;
		case "BNE":
		City = 'Brisbane';
		Price = '4';
		break;
		case "SYD":
		City = 'Sydney';
		Price = '12';
		break;
		case "MEL":
		City = 'Melbourne';
		Price = '4';
		break;
		case "PER":
		City = 'Perth';
		Price = '8.80';
		break;
		case "HBA":
		City = 'Hobart';
		Price = '5';
		break;
		case "BNK":
		City = 'Ballina';
		Price = '9';
		break;
	}
		                
	var description = City+' Airport Parking - As low as $'+Price;
	var content = ['Airport Parking', 'http://www.airportparking.net.au/virginblue/', description];
	insert_travel_extra('travel-extras', content);
}

function airtrain() {
	var frmone = document.itinerary_info.info_mkt1_seg1.value;
	var myarrayone = new Array();
	var myarraytwo = new Array();
	myarrayone = frmone.split('|');
	//var content = "<div class=servicesbg><img src=/_images/partners/services_transfers.gif alt='Book Airport Transfers' border=0 width=161 height=26 />";
	var content = "";
	var orig = myarrayone[5].toUpperCase();
	var dest = myarrayone[6].toUpperCase();
	var iata = new Array("MEL","BNE");
	var flag = 0;

	if (iata.contains(orig) || (iata.contains(dest) && !document.itinerary_info.info_mkt1_seg2))  {
		if (orig.match('BNE') || dest.match('BNE')) {
				content = ['Brisbane Airport Transfers', 'http://www.airtrain.com.au/virgin/', '10% off for Virgin Blue Guests'];
		}
		flag = 1;
	} 

	if (document.itinerary_info.info_mkt1_seg2){
		var frmtwo = document.itinerary_info.info_mkt1_seg2.value;
		myarraytwo = frmtwo.split('|');
		var dest = myarraytwo[6].toUpperCase();
		
		if (iata.contains(dest))  {
			if (orig.match('BNE') || dest.match('BNE')) {
				content = ['Brisbane Airport Transfers', 'http://www.airtrain.com.au/virgin/', '10% off for Virgin Blue Guests'];
			}                            
			flag = 1;
		}
	} 
						
	if (iata.contains(orig) && (iata.contains(dest) && !document.itinerary_info.info_mkt1_seg2))  {
		if (orig.match('BNE') || dest.match('BNE')) {
				content = ['Brisbane Airport Transfers', 'http://www.airtrain.com.au/virgin/', '10% off for Virgin Blue Guests'];
		}
		
		flag = 1;
	} 
						
	if (flag == '1') {
		insert_travel_extra('travel-extras', content);
	}
}
				
function octopus_redir()
{

	document.itinerary_info.action = "/octopustravel/redir.php";
	document.itinerary_info.target = "_blank";
	document.itinerary_info.submit();
}
/* End Itinerary Services */
    
function insert_travel_extra (id, content) {
	
	dt = 		document.createElement('dt');
	dd = 		document.createElement('dd');
	a = 		document.createElement('a');
	a.target = 	'_blank';
	a.href =	content[1];
	dt_text = 	document.createTextNode(content[0]);
	dd_text = 	document.createTextNode(content[2]);
	
	a.appendChild(dt_text);
	dt.appendChild(a);
	dd.appendChild(dd_text);
	
	var lastTravelExtra = document.getElementById('travel-extras-last');
		
	$(id).insertBefore(dt, lastTravelExtra);
	$(id).insertBefore(dd, lastTravelExtra);
	
}




