/***********************************************
* Created by Usha Krishnamurthy (Symphony)
* Last modified Date - 03/01/2010
***********************************************/

var airlines = new Array();	
var feedURL = "/rss/topdeals-flights.rss.xml"/* Feed URL */
google.load("feeds", "1");

function createAirlineInfo(){
//	var items= createAirlineInfo.arguments.length;	
	/* Moves all the airline names in an array */

	if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent)) || (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)))
		google.setOnLoadCallback(initialize_AirDealsIEFirefox);
	else 
		initialize_AirDealsSafariNetscape();
}

function initialize_AirDealsIEFirefox() {
     if (window.ActiveXObject)
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	 else if (document.implementation && document.implementation.createDocument)
	  xmlDoc=document.implementation.createDocument("","",null);
	 else 
	  alert('Your browser cannot handle this script');
	xmlDoc.async=false;
	xmlDoc.load(feedURL);
	processXML(xmlDoc);	
 }
	
function initialize_AirDealsSafariNetscape()
{
	if (window.ActiveXObject)
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		objXMLHttp = new XMLHttpRequest();
	else alert("not supported");
	
	objXMLHttp.open("GET",feedURL + "?cache="+Math.random(100),true);
	objXMLHttp.setRequestHeader("Cache-Control", "no-cache");		
	objXMLHttp.setRequestHeader("Pragma", "no-cache");		
	objXMLHttp.onreadystatechange = function() {

		if (objXMLHttp.readyState == 4)	{			
			if (objXMLHttp.status == 200){				
				if (objXMLHttp.responseXML != null){
					processXML(objXMLHttp.responseXML);					
				}
				else{
					alert(" file not found.");
					return false;
				}
			}
			else alert("Error code " + objXMLHttp.status + " received: " + objXMLHttp.statusText);
		}		
	}	
	objXMLHttp.send(null);		
}

function processXML(xmlObj)
{		
	var container = document.getElementById('mainCont');
	var firstCol = document.getElementById('firstCol');
	var secCol = document.getElementById('secondCol');
	var strTitle = "";
	var items = xmlObj.getElementsByTagName("item");				
    var htmlString =""; var htmlString1 ="";
	var FaresSort = new Array();
	
			  for (var i = 0; i < items.length; i++) {/* Traversing through the feed items */
			 
					var title = items[i].getElementsByTagName("title")[0].firstChild.nodeValue;						
					var linkTxt = items[i].getElementsByTagName("link")[0].firstChild.nodeValue;	
					strTitle = title.split(":");
					var title1= strTitle[0].toLowerCase();
					
					FaresSort.push([title,title1,linkTxt])
					
					
		}			FaresSort.sort(sortByAirline);
					var itemLen = Math.round(FaresSort.length/2);
					
					for(var k=0; k<FaresSort.length; k++)
					{	
					
					if(k<itemLen)
					htmlString += "<li style='background: url(/public/ANS/Images/bullet_square.gif) no-repeat;padding: 0 4px 5px 8px;'><a href="+FaresSort[k][2]+">"+FaresSort[k][0]+"</a></li></ul></div>";
					else
					htmlString1 += "<li style='background: url(/public/ANS/Images/bullet_square.gif) no-repeat;padding: 0 4px 5px 8px;'><a href="+FaresSort[k][2]+">"+FaresSort[k][0]+"</a></li></ul></div>";
					}
					
					firstCol.innerHTML = htmlString;
					secCol.innerHTML = htmlString1;
					
}
function sortByAirline(a,b) {
a = a[1]
b = b[1]
return a == b ? 0 : (a < b ? -1 : 1)
}

