/***********************************************
* Created by Usha Krishnamurthy (Symphony)
* Last modified Date - 02/20/2009
***********************************************/

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 */
	for(var a = 0; a < items; a++) airlines.push(createAirlineInfo.arguments[a]);		
	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 items = xmlObj.getElementsByTagName("item");				
    var count = 0;		
	var airlineNoInXML = 0;
	var listItems ="";
	 for(var j = 0; j < airlines.length; j++) /* Traversing through the Airlines 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;				

					var htmlString ="";
					
					var titleFlight= title.split(":");
					var title1= titleFlight[0].toLowerCase(); /* Splitting the title to get only the airline name */
					
					var imgText = airlines[j].split(" ");/* Removing the space between airline name*/					
					var imgName ="";
					
					for(var l=0; l<imgText.length; l++)	imgName += imgText[l];  
					
					if(title1.search(airlines[j].toLowerCase())>=0){										
						if(count<4)
							listItems+="<li style='background: url(/public/ANS/Images/bullet_square.gif) no-repeat;padding: 0 4px 5px 8px;list-style-type:none'><a href='"+linkTxt+"' class='familyContentModuleLink'>"+titleFlight[1]+"</a></li>";
						else
							break;
						count += 1;	/* Count of items in xml for each airline */	
					}										
				}
					
					var borderStr = "<div style='clear:both;background-color:#aaddff; margin:5px 0 10px 0'><img src='/public/ANS/Images/spacer.gif' /></div>";
					
					if(count!=0)
					{ 		
						htmlString += "<div style='width:182px;float:left;padding-right:10px;'><img src='/public/ANS/Images/Carrier_"+imgName+".gif' alt='"+airlines[j]+"' title='"+airlines[j]+"'/><ul class='bulletSquare' style='margin-top:5px; padding-left:3px'>"+listItems+"</ul></div>";
			
					if((airlineNoInXML%3 == 0) && (airlineNoInXML>2)) htmlString  = borderStr + htmlString; 
					/* After 3 airline images moving 4th image to next line seperated by border */	
					airlineNoInXML += 1;
					}				
			
							newDiv= document.createElement("div");  					
							newDiv.innerHTML = htmlString;						
							container.appendChild(newDiv);
					
							count = 0;	
							listItems = "";
		}
}

