
document.domain = "willow.tv";

// a_GMTDate should contain GMT string.
// For example: Thu, 21 Nov 2002 21:00 GMT
function CXFormatDateTime(a_GMTDate)
{
	var LocalDate = new Date();
	if("" != a_GMTDate)
		LocalDate = new Date(a_GMTDate);

	var DateStr = LocalDate.toString();
	// We don't want the seconds, strip them off
	DateStr = DateStr.replace(/ ([0-9]+):([0-9]+):[0-9]+ /, " $1:$2 ");
	return DateStr;
}

// a_GMTDate should contain GMT string.
// For example: Thu, 21 Nov 2002 21:00 GMT
function CXFormatDate(a_GMTDate)
{
	var LocalDate = new Date();	
	if("" != a_GMTDate)
		LocalDate = new Date(a_GMTDate);	
		
	var MonthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var DateStr = "";
	DateStr = LocalDate.getDate() + " ";
	DateStr += MonthArray[LocalDate.getMonth()] + " ";
	DateStr += LocalDate.getYear();
		
	return DateStr;
}

function CXWriteLocalDateTime(a_GMTDate)
{
	document.write(CXFormatDateTime(a_GMTDate));
}

function CXWriteLocalDate(a_GMTDate)
{
	document.write(CXFormatDate(a_GMTDate));
}

function CXGetHostName(URLStr)
{
	var HostStr = new String(URLStr);
		
	HostStr = HostStr.replace(/^[^:]+:\/\/([^\/]*)\/.*$/g, "$1");
	return HostStr;
}

function UpdateStartCountDown(a_StartTime, a_ClientErrorTime, a_DisplayObj)
{
	var CurrDate = new Date();

	var TimeRemaining = (a_StartTime - (CurrDate.getTime() - a_ClientErrorTime));
	if(TimeRemaining > 2000)
	{
		var MinsRemaining = parseInt(TimeRemaining/(1000*60));
		var HrsRemaining = 0;
		if(MinsRemaining > 60)
		{
			HrsRemaining = parseInt(MinsRemaining/60);
			MinsRemaining = MinsRemaining % 60;
		}
		
		var SecsRemaining = parseInt((TimeRemaining/1000) % 60);
		var TempStr = SecsRemaining;
		if(SecsRemaining <= 9)
			TempStr = "0" + SecsRemaining;
		
		var DisplayStr = "Broadcast starts in: <FONT color=Crimson>";
		if(0 != HrsRemaining)
			DisplayStr += HrsRemaining + " hrs ";
		DisplayStr += MinsRemaining + " mins  " + TempStr + " secs</FONT>";
		
		document.all(a_DisplayObj, 0).innerHTML = DisplayStr;
		
		window.setTimeout("UpdateStartCountDown(" + a_StartTime + "," + 
															a_ClientErrorTime + ",'" + a_DisplayObj + "')", 1000);
	}
	else if((TimeRemaining < 2000) && (TimeRemaining > 1000))
	{
		var DisplayStr = "<FONT color=Crimson>Press Ctrl + F5 to start the broadcast.</FONT>";
		document.all(a_DisplayObj, 0).innerHTML = DisplayStr;
		
		//window.setTimeout("top.location=top.location", 2000);
	}
	else
		document.all(a_DisplayObj, 0).style.display = "none";
}

function CXDisplayStartCountDown(a_StartTime, a_ServerCurrentTime, a_DisplayObj)
{
	var StartTime = parseInt(a_StartTime);
	if(isNaN(StartTime))
		return;
	
	if("" == a_DisplayObj)
		return;
		
	var ErrorTime = 0;
		
	var ServerCurrentTime = parseInt(a_ServerCurrentTime);
	if(!isNaN(ServerCurrentTime))
	{
		var ClientCurrentTime = new Date();
	
		// Add 2 seconds to ServerCurrentTime to account for delay between server
		// to client connection.
		ErrorTime = ClientCurrentTime.getTime() - (ServerCurrentTime + 2000);
	}
	
	UpdateStartCountDown(StartTime, ErrorTime, a_DisplayObj);
}

function CXHttpPostClass(a_URL, a_Args)
{
	this.URL = a_URL;
	this.Args = a_Args;
	this.Success = false;
	this.Status = 0;
	this.ResponseText = new String();
		
	if("" == this.URL)
		return;
			
	var HTTPPostObjs = new Array("Msxml2.ServerXMLHTTP", "Microsoft.XMLHTTP");
	for(var i = 0; i < HTTPPostObjs.length; i++)
	{
		try
		{
			objHTTP = new ActiveXObject(HTTPPostObjs[i]);
		}
		catch(e)
		{
			objHTTP = null;
			continue;
		}
		break;
	}
	if(null == objHTTP)
		return;
				
	var szHttpMethod = "POST";
	objHTTP.Open(szHttpMethod, this.URL, false);
	objHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	objHTTP.Send(this.Args);
		
	//window.alert("Coming Here - " + objHTTP.status); // + ":" + objHTTP.responseText);
	this.Status = objHTTP.status;
	if(200 == objHTTP.status)
	{
		this.Success = true;
		this.ResponseText = objHTTP.responseText;
	}
	objHTTP = null;
}

var g_HelpStr = new String();
function CXMessageWnd(a_WebRoot, a_MsgStr, a_Title, a_Width, a_Height, a_ScrollBars)
{
	g_HelpStr = a_MsgStr;
	
	var MsgWndPage = a_WebRoot + "/Misc/MessageWnd.asp?title=" + a_Title;
	var Params = "status=yes,toolbar=no,menubar=no,location=no,resizable=yes,width=" +
								a_Width + ",height=" + a_Height;
	if(true == a_ScrollBars)
		Params += ",scrollbars=yes";

	window.open(MsgWndPage, "CXMessageWnd", Params);
}

function CXShowHelpWithVideoOptions(a_WebRoot)
{
	var HelpStr = "In case you experience difficulties viewing the video, please try the following options:<BR>" +
							"<OL><LI>If you see no video, please try the options in the first dropdown box, which allows"+
							" to you to choose different protocols to watch the video.<BR>" +
							"<LI>If you see constant video buffering, please use the second dropdown box to" +
							" choose our alternate streaming servers.<BR>" +
							"</OL>Once you change any option, hit the 'Refresh' button to view the video. " +
							"If none of these options help, please proceed to the 'Advanced' troubleshooting options.<BR>";

	CXMessageWnd(a_WebRoot, HelpStr, "Video Link Help", 400, 300, false);
}

function CXGetXMLObj()
{
	var XMLObj = null;
	try
	{
		// msxml2 object is supported with IE 5.5 or later
		XMLObj = new ActiveXObject("msxml2.DOMDocument");
	}
	catch(e)
	{
		XMLObj = null;
	}

	if(null == XMLObj)
	{
		try
		{
			XMLObj = new ActiveXObject("msxml.DOMDocument");
		}
		catch(e)
		{
			XMLObj = null;
		}
	}
	
	return XMLObj;
}

