/**
* Tiger Airways 
* 
* @author	Kien Wai
* @version	1.0
*/


function getHttpRequest() {
	if (window.XMLHttpRequest) // Gecko
		return new XMLHttpRequest();
	else if (window.ActiveXObject) // IE
		return new ActiveXObject('MsXml2.XmlHttp');
}

// pulls content from external include file
function loadContent(id, url) {
	// add preloader here
	document.getElementById(id).innerHTML = '<img src="../../img/common/loading.gif" width="41" height="41" />';
	
	var xmlHttp = getHttpRequest();
	var output;
	
	xmlHttp.onreadystatechange = function() {
//		alert('loading... ' + xmlHttp.readyState);
		if (xmlHttp.readyState == 4) { 
			if (xmlHttp.status == 200 || xmlHttp.status == 304) {
				// load new content success
				output = xmlHttp.responseText;
			} else {
				// load new content failure
				output = '<span id="nopromo">There are no promotion fares at the moment.</span>';
				
				// for testing
				//alert( 'XML request error: ' + xmlHttp.statusText + ' (' + xmlHttp.status + ')' ) ;
			} 
			
			writeContent(id, url, output);
		}
	}
	
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
} 


// writes in content
function writeContent(pid, filepath, src) {
	// write in content only if src is not empty and element is found
	if ((src!=null) && (document.getElementById(pid)))
		document.getElementById(pid).innerHTML = src;
}


function selecttab(tab,current_path) {
	var tabname = tab.id.slice(3);
	//var filename = '../menuboard_sg/mb_' + tabname.toLowerCase() + '.html';
	// changed 
	var filename = '../../coms/menuboard_reader/sg_mb_reader.php?country=' + tabname.toLowerCase();
	
	if(current_path != ""){
	filename = filename + '&current_path=' + current_path;
	}
	
	loadContent('faretable', filename);
	
	for (i in tabArray) {
		var tabid = 'ld-' + tabArray[i].toLowerCase();
		/*if (tabid == 'ld-australia')
			document.getElementById(tabid).className = 'base';
		else*/
			document.getElementById(tabid).className = 'default';
	}

	document.getElementById(tab.id).className = 'active';
}



