﻿// JScript File

function ChangeTabs(value) 
{
	value = value;
	document.getElementById('TabControl1_txtThePage').value = value;
	eval(document.getElementById('TabControl1_lnkChangePage').href);
}

function SwapAndChange()
{
	var value = sChannel;
	
	if (value == "Home")
	{
		document.getElementById("tblTabs").style.display = "none";
		document.getElementById("tblHome").style.display = "";
	}
	else
	{	
		var img = document.getElementById("imgTabsBottom");
		switch (value)
		{
			case "Sports":
				img.src = "Images/SportsRotarBottom.jpg";
				break;
				
			case "Family":
				img.src = "Images/Week_familyBottom.gif";
				break;
				
			case "Movie":
				img.src = "Images/Week_movieBottom.gif";
				break;
				
			case "News":
				img.src = "Images/Week_newsTop.gif";
				break;
				
			case "Prime":
				img.src = "Images/Week_primeBottom.gif";
				break;
				
			case "Xtra":
				img.src = "Images/Week_xtraTop.gif";
				break;
				
			case "Spectrum":
				img.src = "Images/RotatorSpecBotm.jpg";
				break;
		}
		
		document.getElementById("tblHome").style.display = "none";
		document.getElementById("tblTabs").style.display = "";
		
		ChangeTabs(value);
	}
}

var sChannel = "";
function jsChangeChannel(channelId)
{
	var channel = "Home";
	
	switch (channelId)
	{
		case 1:
			channel = "Sports";
			break;
		case 2:
			channel = "Prime";
			break;
		case 3:
			channel = "Spectrum";
			break;
		case 5:
			channel = "News"
			break;
		case 6:
			channel = "Xtra"
			break;
		case 9:
			channel = "Family";
			break;
		case 10:
			channel = "Movie";
			break;
	}
	
	sChannel = channel;
	
	SwapAndChange();
	//LoadPromo(sChannel);
}

function GetChannelId(value)
{
	var channelId = 0;
	
	switch (value)
	{
		case "Home":
			channelId = 0;
			break;
			
		case "Sports":
			channelId = 1;
			break;
			
		case "Prime":
			channelId = 2;
			break;
			
		case "Spectrum":
			channelId = 3;
			break;
			
		case "News":
			channelId = 5;
			break;
			
		case "Xtra":
			channelId = 6;
			break;
			
		case "Family":
			channelId = 9;
			break;
			
		case "Movie":
			channelId = 10;
			break;
	}
	
	return channelId;
}

function LoadPromo(value)
{
	var channelId = GetChannelId(value);

	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", "PromoA.ashx", true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) 
		{
			EndLoadPromo(oXmlHttp.responseText);
		}            
	};
    
	var sBody = 
		encodeURIComponent("ChannelId") + "=" + 
		encodeURIComponent(channelId);
	oXmlHttp.send(sBody); 
}

var currentPromo = "";
function EndLoadPromo(value)
{
	value = value.replace("v=", "");
	var promoPath = "";
	if (value.substring(0, 6) == "Promo_")
		promoPath = "Swfs/" + value;
	else
		promoPath = "http://media.myafn.dodmedia.osd.mil/Promo/" + value;
	promoPath = promoPath;
	
	if (currentPromo != promoPath)
	{
		currentPromo = promoPath;
		
		if (document.all)
			CreateIEFlashControl("FlashDiv_Promo1_flaPromo", "Cab/swflash.cab", "400", "375", promoPath, "high", "", "", "", "", "", "", "", "", "", "");
		else
			document.getElementById("FlashDiv_Promo1_flaPromo").src = promoPath;
	}
		
	SwapAndChange();
}

var channelButtons;

function initialize()
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	channelButtons = (isIE) ? window["FlashDiv_flaChannelButtons"] : document["FlashDiv_flaChannelButtons"];
}

function ChangeChannel(channel)
{
	initialize();
	channelButtons.flaChangeChannel(channel);
}

