var j$ = jQuery.noConflict();
var inputID = "from";

j$(document).ready( function() {

update_translation_dropdown();

/* RBTT Module */
if (typeof(loadRBTTModuleScripts) != 'undefined') { loadRBTTModuleScripts(); }


j$("table.fareslist > tbody > tr").hover(function(){ 
	j$(this).addClass("farestblhover"); 
},function(){ 
	j$(this).removeClass("farestblhover"); 
});

    //j$("#sortingRow").text("<a href="#">Sort</a>");
    var headers = j$("grdData > th");
	
	//set up the initial form in the tabs which is reservations
	j$("#resbox").attr({ style: "background:#78a1e2;" }).load("/DesktopModules/FlightBox/res.html");
    //if (j$("#sortLink > th")) 
    //{
        
    //}   

	if (j$("span.small > a").length)
	{
		j$("span.small > a").bind("click",function(){
			var s=j$(this).parent().text();
			var clean='';
			if (s.indexOf("Holiday")>=0)
			{
			 clean="Holiday Inn Lansing West";
			}
			else
			{
			 clean="University Quality Inn";
			}
			j$(this).attr("href",j$(this).attr("href")+"?location="+clean);		
		});
	}
//j$("#resbox").load("/nporta/nporta-quicksearch.htm");
	j$("#res").addClass("here");
	
	j$("#restabs > li > a").click(function(){
										  
		j$("#restabs > li > a").removeClass("here");
		
		if(this.id == "res"){
	
			j$(this).addClass("here");

			
			var resboxLoading = document.getElementById('resboxLoading');
		    
		    if (resboxLoading == null)
		    {			
		        var resboxLoading = document.createElement('div');
		        resboxLoading.setAttribute('id', 'resboxLoading_reservations');
		    
		        document.getElementById('resbox').innerHTML = resboxLoading.innerHTML;
		    }
		    else
		    {
		        resboxLoading.setAttribute('id', 'resboxLoading_reservations');
		    }

			
			//j$("#resbox").attr({ style: "background:#78a1e2;" }).load("/nporta/nporta-quicksearch.htm");
			j$("#resbox").attr({ style: "background:#78a1e2;" }).load("/DesktopModules/FlightBox/res.html");
			return false;
			
		} else if(this.id == "arrivals"){
				
			j$(this).addClass("here");

			var resboxLoading = document.getElementById('resboxLoading');
		    
		    if (resboxLoading == null)
		    {			
		        var resboxLoading = document.createElement('div');
		        resboxLoading.setAttribute('id', 'resboxLoading_arrivals');
		    
		        document.getElementById('resbox').innerHTML = resboxLoading.innerHTML;
		    }
		    else
		    {
		        resboxLoading.setAttribute('id', 'resboxLoading_arrivals');
		    }

			j$("#resbox").attr({ style: "background:#7ea75e;" }).load("/DesktopModules/ArrivalDepatureMini/Default.aspx?type=a #ArrivalDepatureMini_arrivalDepartBack");
			return false;
			
		} else if(this.id == "dept"){
				
			j$(this).addClass("here");

			var resboxLoading = document.getElementById('resboxLoading');
		    
		    if (resboxLoading == null)
		    {			
		        var resboxLoading = document.createElement('div');
		        resboxLoading.setAttribute('id', 'resboxLoading_departures');
		    
		        document.getElementById('resbox').innerHTML = resboxLoading.innerHTML;
		    }
		    else
		    {
		        resboxLoading.setAttribute('id', 'resboxLoading_departures');
		    }
	
			j$("#resbox").attr({ style: "background:#e4ad3e;" }).load("/DesktopModules/ArrivalDepatureMini/Default.aspx?type=d #ArrivalDepatureMini_arrivalDepartBack");
			return false;
			
		}
		return false;

	});

	j$("#aircodes > p > a").click(function(){
		j$("#aircodes").hide();
		return false;
	});
/*
	j$("#aircodes > ul > li > a").click(function(){
		if(inputID == "from"){
			j$("#depart").attr("value",j$(this).text());
		} else {
			j$("#arrival").attr("value",j$(this).text());
		}
		j$("#aircodes").hide();
		return false;
	});
*/

	j$("#dnn_ctr446_FormMaster_ctl__20071114T144527").show();
	j$("#dnn_ctr446_FormMaster_ctl__20071114T144743").show();

	j$("#dnn_ctr446_FormMaster_ctl__20071114T144743_0").click( function(){
		if(j$(this).attr("checked") == true){
			j$("td.formTD > span.SubHead").each( function(){
				var topThis = j$(this);
				j$("td.formTD3 > span.SubHead").each( function(){
					if(j$(this).text() == topThis.text()){
						j$(this).next().val(topThis.next().val());
					}
				});
			});
		} else {
			j$("td.formTD3 > input").not("#dnn_ctr446_FormMaster_ctl__20071114T144418").each( function() {
				j$(this).val('');
			});
		}
	});

	

});


function update_translation_dropdown()
{
	if (window.location.hostname != "www.flylansing.com" && window.location.hostname != "flylansing.com")
	{
        var _qs = gup("tl");
        var _len = document.getElementById("translation_dropdown").length;
        
        for (i=0; i<_len; i++)
	    {
		    if (document.getElementById("translation_dropdown")[i].value == _qs)
		    {
			    document.getElementById("translation_dropdown").selectedIndex = i;
			    break;
		    }
	    }
    }
    else
    {
        document.getElementById("translation_dropdown").selectedIndex = 8;
    }
}

function translate(){
    if (window.location.hostname == "flylansing.com" || window.location.hostname == "www.flylansing.com")
		{
		    var _value;
            var _index = document.getElementById("translation_dropdown").selectedIndex;
            
			_value = document.getElementById("translation_dropdown")[_index].value;
			_url = window.location.href;
			window.location.href = "http://translate.google.com/translate?u=" + _url + "&hl=en&ie=UTF8&sl=en&tl=" + _value;
		}
}