﻿// JScript File

function GetWeekday(dayID)
{
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	return weekday[dayID];
}

function GetMonth(monthID)
{
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	return month[monthID];
}

function GetDate(dateID)
{
	var date = dateID;
	if (date < 10)
	{
		date = "0" + date;
	}
	return date;
}

// ******* Page Height functions ******* //
// myMasterLoad will be executed from the body onLoad event in the TopMaster
//	page. myMasterLoad will change the height of the page to fit the open browser.
//	It expects that the very top tag (usually in the TopMaster page) will
//	have an id of "TopTag".  This will determine the bottom edge of the 
//	page in IE.  It also expects the very top tag in the content area/page
//	will have an id of "PageTag".  This will determine the bottom edge of
//	the content area in IE, FF, & Safari.  It will also determine the bottom
//	edge of the page in FF & Safaru.
function myMasterLoad()
{
	//alert("In myMasterLoad");
	var theTable = document.getElementById('TopTag');
	var thePage = document.getElementById('PageTag');
	if (window.innerHeight == null)
	{
		// IE
		if ((theTable != null) && (thePage != null))
		{
			theTable.style.height = document.documentElement.offsetHeight;
			thePage.style.height = theTable.style.height.split('px')[0] - 314 + "px";
		}
	}
	else
	{
		// FF & Safari
		if (thePage!= null)
		{
			thePage.style.height = window.innerHeight - 240 + "px";
		}
	}
}

// ******* Common Cookie functions ******* //
function setCookie(name, value, expires, path, domain, secure) 
{
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}
	
function getCookie(cookieName)
{
	var results = document.cookie.match ( cookieName + '=(.*?)(;|$)' );
	if ( results )
		return ( unescape ( results[1] ) );
	else
		return null;
}

function deleteCookie(cookieName)
{
	var cookieDate = new Date();
	cookieDate.setTime (cookieDate.getTime() - 1);
	document.cookie = cookieName += "=; expires=" + cookieDate.toGMTString();
}
// ******* End of Common Cookie functions ******* //

// ******* Article Font Size functions ******* //
//Enums
    var eCurrentFontSize = { Small:0, Large:1 }; //enumeration for Font Size
    var eRequiredAction = { Increase:0, Decrease:1 }; //enumeration for Font Size increase/decrease
    //Global variables
    var currentFontSize = eCurrentFontSize.Small; //default font size. Permissible values = "small" or "large"
    var arrModifiedClasses;//array to store the names of the css classes that have been modified
    var arrModifiedClassesCount = 0;//array count
    var fontSizeModifier = 4;//The value by which the font size is to be increased/decreased
    var fontSizeUnit = "pt";//The unit of measure for font size
    
    //This function is invoked when the "Smaller Type Size" or "Larger Type Size" links are clicked.
    //controlID => the container control. The font sizes of its child controls will be modified
    //action => the modifications to the font size. Permissible values = "Increase" or "Decrease"
    function ModifyFontSize(controlID, action, section, url)
    {
        var bDoAction = false;//Boolean indicating whether any action is to be taken
        if (action == null)//Implies the function is being invoked on page load of article and not on click of the small/large font links
        {
        	if (getCookie("ArticleFontSize") != null) //Check if the cookie for article font size exists
        	{
        		if (getCookie("ArticleFontSize") == eCurrentFontSize.Small)
        		{
        			//Do nothing as the default size is small
        		}
        		else
        		{
        			//Implies the user had viewed the previous article in large font size. Hence,
        			//increase the font size if the current article also to large
        			currentFontSize = eCurrentFontSize.Small;
					action = eRequiredAction.Increase;
        		}
        	}
        	
        }
        if (action == eRequiredAction.Increase)// 'Increase'
        {
            //If the font size is to be increased, check if the current size is small. Only then proceed further.
            if (currentFontSize == eCurrentFontSize.Small)
            {
               bDoAction = true; 
            }
        }
        else if (action == eRequiredAction.Decrease)//'Decrease'
        {
            //If the font size is to be decreased, check if the current size is large. Only then proceed further.
            if (currentFontSize == eCurrentFontSize.Large)
            {
               bDoAction = true; 
            }
        }
        //Check if the font size does need to be modified.
        if (bDoAction == true)
        {
            var newID = controlID + "__ControlWrapper_RichHtmlField";
            //Get the container control
            var ctl = document.getElementById(newID);
            //Check if the container control has child nodes. If yes, proceed.
            if (ctl.hasChildNodes)
            {
                arrModifiedClasses = new Array();//Initialize
                arrModifiedClassesCount = 0;
                //Invoke the function to modify the font sizes of the child nodes.
                ModifyFontForChildren(ctl, action);   
            }
            //After the modification is complete, set the currentFontSize as per the modification
            var elementToChange;
            if (action == eRequiredAction.Increase)//'Increase'
            {
                //Action = Increase => after modification, currentFontSize = large
                currentFontSize = eCurrentFontSize.Large;
                //Small image should be grayed out
                elementToChange = document.getElementById('fontSmallImage');
                elementToChange.className = "ArticleContentSections--" + section + "--ArticleOptions_ascx--Font_Small_Image_off";
                //Large image should be un-grayed out
                elementToChange = document.getElementById('fontLargeImage');
                elementToChange.className = "ArticleContentSections--" + section + "--ArticleOptions_ascx--Font_Large_Image";
                //Small text should be grayed out
                elementToChange = document.getElementById('fontSmall');
                elementToChange.className = "ArticleContentSections--ArticleOptions_ascx--Font_Small_Text";
                elementToChange.setAttribute("href", url);
                //Large text should be un-grayed out
                elementToChange = document.getElementById('fontLarge');
                elementToChange.className = "ArticleContentSections--ArticleOptions_ascx--Font_Large_Text_Selected";
                elementToChange.removeAttribute("href");
            }
            else if (action == eRequiredAction.Decrease)//'Decrease'
            {
                //Action = Decrease => after modification, currentFontSize = small
                currentFontSize = eCurrentFontSize.Small;
                //Large image should be grayed out
                elementToChange = document.getElementById('fontLargeImage');
                elementToChange.className = "ArticleContentSections--" + section + "--ArticleOptions_ascx--Font_Large_Image_off";
                //Small image should be un-grayed out
                elementToChange = document.getElementById('fontSmallImage');
                elementToChange.className = "ArticleContentSections--" + section + "--ArticleOptions_ascx--Font_Small_Image";
                //Large text should be grayed out
                elementToChange = document.getElementById('fontLarge');
                elementToChange.className = "ArticleContentSections--ArticleOptions_ascx--Font_Large_Text";
                elementToChange.setAttribute("href", url);
                //Small text should be un-grayed out
                elementToChange = document.getElementById('fontSmall');
                elementToChange.className = "ArticleContentSections--ArticleOptions_ascx--Font_Small_Text_Selected";
                elementToChange.removeAttribute("href");
            }
            //After the modification, store the current font size in a cookie for use by the
            //article pages viewed hereafter.
			setCookie("ArticleFontSize", currentFontSize);
        }
   } 
   
   //This function is invoked recursively to reach the leaf nodes of the input node
   //ctl => control, whose hierarchy is to be navigated. Initial value = container control
   //action => the modifications to the font size. Permissible values = "Increase" or "Decrease"
   function ModifyFontForChildren(ctl, action)
   {
        var i=0;
        var childNodes = ctl.childNodes;
        for(var i=0; i<childNodes.length; i++)
        {
            curr = ctl.childNodes[i];
            if (curr.nodeName == '#text')//This is for browsers like FF that treat an "Enter" as a text node
            {
                if (curr.nextSibling != null)
                {
                    curr = curr.nextSibling;
                }
            }
            if (curr.firstChild != null)
            {
                ModifyFontForChildren(curr, action);
            }
            else
            {
                //if the current node is a leaf node, invoke the function to increase its font size.
                GetNextParentWithFont(curr, action);
            }
        }
   }
   
   //This function is invoked to increase/decrease the font size of the input node. It checks if the input node has a 
   //style/css class, retrieves the style/css class and modifies the font size attribute. If the input node doesn't
   //have these values, the function navigates up the hierarchy to find the next parent that has these
   //attributes and then modifies them.
   //node => the node for which the fontsize is to be modified. Initial value = leaf node, which is #text
   //action => the modifications to the font size. Permissible values = "Increase" or "Decrease"
   function GetNextParentWithFont(node, action)
   {
        //the input node is of type #text, which doesn't have any attributes. Hence get the next parent.
        node = node.parentNode;
        var classAttribute = null;
        if (node != null)
        {
            classAttribute = node.getAttributeNode('class');//Retrieve the "class" attribute
            if (classAttribute == null)
            {
                //class is null so get next parent and invoke the same function recursively
                var nextParent = node.parentNode;
                GetNextParentWithFont(nextParent, action);
            }
            else
            {
                //class is not null
                var classNameValue = classAttribute.nodeValue;
                var classNameArray = classNameValue.split(' ');
                for (var classNameArrayCount=0; classNameArrayCount < classNameArray.length; classNameArrayCount++)
                {
                    var className = classNameArray[classNameArrayCount];
                    var styleSheets = document.styleSheets;
                    //Retrieve the css class from the style sheets for the page
                    for (var s = 0; s < document.styleSheets.length; s++)
	                {
	                    //To modify the font size, we need to work only with internal styles (i.e. styles added by the
	                    //document converter to the page itself. Hence, we need to eliminate the external style sheets.)
	                    if ((styleSheets[s].href == null) || (styleSheets[s].href == "") || (styleSheets[s].href == location.href))
	                    {
	                        var rules = styleSheets[s].cssRules? styleSheets[s].cssRules: styleSheets[s].rules;
		                    for (var r = 0; r < rules.length; r++)
		                    {
			                    if (rules[r].selectorText.toLowerCase() == '.' + className.toLowerCase())
			                    {
				                    if ((rules[r].style.fontSize == null) || (rules[r].style.fontSize == ""))
				                    {
				                         //class doesn't have fontSize so get next parent
                                        var nextParent = node.parentNode;
                                        GetNextParentWithFont(nextParent, action);
				                    }
				                    else
				                    {
				                        //class has the font size so it has to be modified
				                        var x;//iterator
				                        //Boolean to indicate whether the css class has been already modified and shouldn't be modified further
				                        var bClassModified = false;
				                        //Check if the css class for the current node has been already modified
				                        for (x in arrModifiedClasses)
				                        {
				                            if (arrModifiedClasses[x] == className)
				                            {
				                                bClassModified = true;
				                            }
				                        }
				                        //if the css class has not been modified already, modify it now
				                        if (bClassModified == false)
				                        {
				                            //Get the existing font size
				                            var oldFontSize = 0;
				                            if (rules[r].style.fontSize != "")
				                            {
				                                oldFontSize = parseInt(rules[r].style.fontSize.replace("pt",""));
				                            }
				                            var newFontSize;//Variable for new font size
				                            //Modify the font size as per the required action
				                            if (action == eRequiredAction.Increase)//'Increase'
				                            {
                                                newFontSize = oldFontSize + fontSizeModifier;
                                            }
                                            else if (action == eRequiredAction.Decrease)//'Decrease'
                                            {
                                                newFontSize = oldFontSize - fontSizeModifier;
                                            }
                                            //Set the new font size
                                            rules[r].style.fontSize = newFontSize + "pt";
                                            //add the class name to the array of already modifed classes
                                            arrModifiedClasses[arrModifiedClassesCount] = className;
                                            arrModifiedClassesCount += 1;
                                        }
                                    }
			                    }
		                    }
		                }
	                }
	            }
	        }
	    }
	    return true;
   }
// ******* End of Article Font Size functions ******* //

// ******* Email Validation functions for Article Comments and Survey Subscription ******* //
	var eValidationPageSource = { Survey:0, ArticleComment:1 }; //enumeration for the page from which the validation was invoked

    //This function validates the user input - checks to see if at least one checkbox is checked and the
    //email id is in the valid format.
	function validateForm(pageSource, txtEmailID, txtHiddenID)
		{
			//var oForm = document.forms(0);
			var oForm = document.aspnetForm;
			var oStatus = new ValidationStatus("The following error conditions must be corrected to submit:\n\n", true);
			oStatus.IsValid = true;
			var txtEmail;
			//check if the page source is the SurveySubscription page. If it is, validate the site section check boxes.
			if (pageSource == eValidationPageSource.Survey)
		    {
		        checkRequiredCheckbox(oForm, oStatus);
       			//Get the email text field
				txtEmail = document.getElementById(txtEmailID);
			    //Validate the email since the email is mandatory for the survey
				validateControl(txtEmail, "Email", oStatus, DATATYPE_EMAIL, true);
			}
		    else if (pageSource == eValidationPageSource.ArticleComment)
			{
				//Get the email text field
				txtEmail = document.getElementById(txtEmailID);
			    //Validate the email only if it is not empty since the email is not mandatory for article comments
			 	if ((txtEmail != null) && (Trim(txtEmail.value) != ''))
				{
					validateControl(txtEmail, "Email", oStatus, DATATYPE_EMAIL, true);
				}
			}
			if(!oStatus.IsValid)
			{
				alert(oStatus.Message);
				txtEmail.focus();
			}
			else
			{
			    //check if the page source is the SurveySubscription page. If it is, continue to fetch the selected
			    //site section checkboxes. If not, skip the fetching.
			    if (pageSource == eValidationPageSource.Survey)
			    {
			        //If the user input is valid, retrieve the selected checkboxes and store their siteSections as a
			        //comma-separated string in a hidden field (to be accessed from the server).
			        var selectedSections = "";
			        var delimiter = "";
			        var iTotal = oForm.elements.length;
	                for (var i = 0; i<iTotal; i++) 
	                {
		                var element = oForm.elements[i];
		                if (getControlType(element) == "checkbox") 
		                {
			                if (element.checked) 
			                {
			                    //The parent of the checkbox control needs to be fetched because in the html rendered by
			                    //the framework, the checkbox is encapsulated in a span and the SiteSection attribute is
			                    //added to the span and not to the checkbox.
				                var parent = element.parentNode;
				                var siteSection = parent.getAttributeNode('SiteSection');
				                if (siteSection != null)
                                {
                                    delimiter = ",";
                                    selectedSections += siteSection.nodeValue + delimiter;
                                }
			                }
		                }
	                }
	                //Remove the trailing ",".
	                selectedSections = selectedSections.substring(0, selectedSections.length - 1);
	                var txtHidden = document.getElementById(txtHiddenID);
	                txtHidden.value = selectedSections;
	            }
			}
			return oStatus.IsValid;
		}
// ******* End of Email Validation functions for Article Comments and Survey Subscription ******* //

// ******* Checkbox toggle function for Survey Subscription ******* //
	//This function toggles the checkbox that is passed in as the input. So, clicking on the site section name
    //toggles the checkbox next to it.
	function ToggleCheckTheSection(checkBoxId)
	{
	    checkBoxId.checked = !checkBoxId.checked;
	}
// ******* End of Checkbox toggle function for Survey Subscription ******* //

// ******* VideoSetup user control functions ******* //
	var VideoConnection_MediaSelection_0;
    var VideoConnection_MediaSelection_1;
    var VideoPlayer_MediaSelection_0;
    var VideoPlayer_MediaSelection_1;
    var VideoFormat_MediaSelection_0;
    var VideoFormat_MediaSelection_1;
  	
	function storeSetting() 
	{
		var cookieDate = new Date();
		cookieDate.setTime (cookieDate.getTime() + 3600000*24*365);
		if (document.getElementById(VideoPlayer_MediaSelection_0).disabled)
			setCookie("DisabledConnection", "0", cookieDate);
		if (document.getElementById(VideoPlayer_MediaSelection_1).disabled)
			setCookie("DisabledConnection", "1", cookieDate);	
		if (document.getElementById("WMPVersionInfo").style.visibility == "visible")
			setCookie("WMPVersionInfo", "1", cookieDate);	
		if (document.getElementById("RealVersionInfo").style.visibility == "visible")
			setCookie("RealVersionInfo", "1", cookieDate);	
	}
	
	function storeSettings() 
	{
		var cookieDate = new Date();
		cookieDate.setTime (cookieDate.getTime() + 3600000*24*365);
		setCookie("VideoConnection", (document.getElementById(VideoConnection_MediaSelection_0).checked == true)?"0":"1", cookieDate);
		setCookie("VideoPlayer", (document.getElementById(VideoPlayer_MediaSelection_0).checked==true?"0":"1"), cookieDate);
		setCookie("VideoFormat", (document.getElementById(VideoFormat_MediaSelection_0).checked==true?"0":"1"), cookieDate);
		if (document.getElementById(VideoPlayer_MediaSelection_0).disabled)
			setCookie("DisabledConnection", "0", cookieDate);
		if (document.getElementById(VideoPlayer_MediaSelection_1).disabled)
			setCookie("DisabledConnection", "1", cookieDate);	
		return true;
	}
	
	function retrieveSettings() 
	{
		if (getCookie("VideoConnection")) {
			document.getElementById(VideoConnection_MediaSelection_0).checked = (getCookie("VideoConnection") == "0"?true:false);
			document.getElementById(VideoConnection_MediaSelection_1).checked = !document.getElementById(VideoConnection_MediaSelection_0).checked;
			if (document.getElementById(VideoConnection_MediaSelection_0).checked) {
				MSG += "'High speed connection selected' info retrieved from cookie" + "\n";
			} else {
				MSG += "'Low speed connection selected' info retrieved from cookie" + "\n";
			}
		}
		if (getCookie("VideoPlayer")) {
			document.getElementById(VideoPlayer_MediaSelection_0).checked = (getCookie("VideoPlayer") == "0"?true:false);
			document.getElementById(VideoPlayer_MediaSelection_1).checked = !document.getElementById(VideoPlayer_MediaSelection_0).checked;
			if (document.getElementById(VideoPlayer_MediaSelection_0).checked) {
				MSG += "'Windows Media Player selected' info retrieved from cookie" + "\n";
			} else {
				MSG += "'Real Player selected' info retrieved from cookie" + "\n";
			}
		}
		if (getCookie("VideoFormat")) {
			document.getElementById(VideoFormat_MediaSelection_0).checked = (getCookie("VideoFormat") == "0"?true:false);
			document.getElementById(VideoFormat_MediaSelection_1).checked = !document.getElementById(VideoFormat_MediaSelection_0).checked;
			if (document.getElementById(VideoFormat_MediaSelection_0).checked) {
				MSG += "'View format' is Video retrieved from cookie" + "\n";
			} else {
				MSG += "'View format' is Audio/text retrieved from cookie" + "\n";
			}
		}
		if (getCookie("DisabledConnection")) {
			if (getCookie("DisabledConnection") == "0") {
				document.getElementById(VideoPlayer_MediaSelection_0).disabled = true;
				MSG += "WMP not available/no right version info retrieved from cookie" + "\n";
			}
			if (getCookie("DisabledConnection") == "1")
			{
				document.getElementById(VideoPlayer_MediaSelection_1).disabled = true;
				MSG += "RealPlayer not available/no right version info retrieved from cookie" + "\n";
			}
		}			
		if (getCookie("WMPVersionInfo")){
			if (getCookie("WMPVersionInfo") == "1"){
				document.getElementById("WMPVersionInfo").style.visibility = "visible";
				MSG += "WMP version unkown info retrieved from cookie" + "\n";
			} 
			else {
				document.getElementById("WMPVersionInfo").style.visibility = "hidden";
			}
		}
		if (getCookie("RealVersionInfo")) {
			if (getCookie("RealVersionInfo") == "1") {
				document.getElementById("RealVersionInfo").style.visibility = "visible";
				MSG += "RealPlayer version unkown info retrieved from cookie" + "\n";
			} else {
				document.getElementById("RealVersionInfo").style.visibility = "hidden";
			}
		}
	}
	
	//----------------------- Detect Settings
		var MSG = "";
		var PLAYER_UNAVAILABLE = 0;
		var PLAYER_AVAILABLE = 2;
		var PLAYER_VALID_VERSION_AVAILABLE = 4;
		
		var PLUGIN_WINDOWS_MEDIA = 0;
		var PLUGIN_REAL_PLAYER = 1;
		
		var _plugins = null;

		function calcThroughput(startTime, endTime)
		{
			var datasize = 31468; // in Bytes
			var diffTimeMilliseconds = endTime - startTime;
			var diffTimeSeconds = diffTimeMilliseconds/1000;
			var bits = (datasize*8);   // convert Bytes to bits, 
			var kbits = bits/1024;     // convert bits to kbits
			var throughput = kbits/(diffTimeSeconds);
			throughput = throughput * .93;  // account for IP packet header overhead - averages about 7%
			
			return throughput;
		}
		function initPluginMapping()
		{
			var plugins = new Array();
			plugins[PLUGIN_WINDOWS_MEDIA] = new Array("Windows Media Player", "WMPlayer.OCX.7", "application/x-mplayer2", "9");
			plugins[PLUGIN_REAL_PLAYER] = new Array("RealPlayer", "rmocx.RealPlayer G2 Control", "audio/x-pn-realaudio-plugin", "6.0.12");
			
			/*
					Detect "ShockwaveFlash.ShockwaveFlash", "Macromedia Flash Player"
					Detect "SWCtl.SWCtl", "Macromedia Shockwave Player"
					Detect "Macromedia.ActiveShockwave.1", "Active Shockwave"
					Detect "RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)", "RealPlayer"
					Detect "rmocx.RealPlayer G2 Control", "RealPlayer G2"
					Detect "IERJCtl.IERJCtl.1", "RealJukebox"
					Detect "MediaPlayer.MediaPlayer.1", "MediaPlayer"
					Detect "PDF.PdfCtrl.1", "Adobe Acrobat 1.0 Reader"
					Detect "PDF.PdfCtrl.2", "Adobe Acrobat 2.0 Reader"
					Detect "PDF.PdfCtrl.3", "Adobe Acrobat 3.0 Reader"
					Detect "PDF.PdfCtrl.4", "Adobe Acrobat 4.0 Reader"
					Detect "PDF.PdfCtrl.5", "Adobe Acrobat 5.0 Reader"
					Detect "Agent.Control.1", "MS Agent 1.5"
					Detect "Agent.Control.2", "MS Agent 2.0"
					Detect "MSComCtl2.Animation", "MS Animation"
					Detect "DirectAnimation.DirectAnimationIntegratedMediaControl.1", "MS DirectAnimation"
					Detect "MSVRML2C.VRMLBrowserCtl.1", "MS VRML 2.0 Viewer"
			*/
			return plugins;
		}
		function versionRequired(type)
		{
			var required = false;
			var userAgent = navigator.userAgent;
			MSG += "userAgent: " + userAgent + "\n";
			if(type == PLUGIN_REAL_PLAYER)
			{
				if((userAgent.indexOf("Mac") > 0) && userAgent.indexOf("MSIE"))
					required = false;
				else
					required = true;
			}
			else if(userAgent.indexOf("Windows NT") > 0)
			{
				if(userAgent.indexOf("MSIE 6.0") > 0)
					required = true;
			}
			
			return required;
		}
		function getActiveXPlayer(progID, mimeType)
		{
			var player = null;
			try 
			{
				if (window.ActiveXObject) {//Use ActiveXObject
					player = new ActiveXObject(progID);
					MSG += "ActiveXObject detected for '" + progID + "'!" + "\n";
				} else if (window.GeckoActiveXObject) { //Use GeckoActiveXObject
					player = new GeckoActiveXObject(progID);
					MSG += "GeckoActiveXObject detected for '" + progID + "'!" + "\n";
				} else {// Plugin code using navigator.mimeTypes
					player = navigator.mimeTypes[mimeType].enabledPlugin;
					MSG += "navigator.mimeTypes[mimeType].enabledPlugin detected for '" + progID + "'!" + "\n";
				}
			}
			catch(e)
			{
				player = null;
				MSG += "Got exception when detecting '" + progID + "' using ActiveXObject!" + "\n";
			}
			return player;
		}
		
		function playerAvailable(type)
		{
			var available = PLAYER_UNAVAILABLE;

			if(_plugins == null)
				_plugins = initPluginMapping();
			var progID = _plugins[type][1];
			var mimeType = _plugins[type][2];
			var requiredVersion = _plugins[type][3];
			var player = getActiveXPlayer(progID, mimeType);
			var version = null;
			
			if(player != null)
			{
				available = PLAYER_AVAILABLE;
				switch(type)
				{
					case PLUGIN_WINDOWS_MEDIA:
						MSG += "Media Player detected under ActiveXObject for WMP!" + "\n";
						try {
						if(player.versionInfo)
						{
							MSG += "WMP version: " + player.versionInfo + "\n";
							aVersion = player.versionInfo.split(".");
							version = aVersion[0];
							//for windows media player, any version greater than required version is OK
							if(parseInt(version) >= parseInt(requiredVersion))							
								available += PLAYER_VALID_VERSION_AVAILABLE;						
						}
						} catch (e) {
							MSG += "Got exception when detecting WMP version!!!" + "\n";
						}
						break;
					case PLUGIN_REAL_PLAYER:
						MSG += "Media Player detected under ActiveXObject for RealPlayer!" + "\n";
						try {						
						if(player.GetVersionInfo())
						{
							MSG += "RealPlayer version: " + player.GetVersionInfo() + "\n";
							aVersion = player.GetVersionInfo().split(".");
							version = aVersion[0] + "." + aVersion[1] + "." + aVersion[2];
							
							if(version == requiredVersion)
								available += PLAYER_VALID_VERSION_AVAILABLE;
						}
						} catch (e) {
							MSG += "Got exception when detecting RealPlayer version!!!" + "\n";
						}
						break;	
				}
			}
			else
			{
				MSG += "Media Player NOT detected under ActiveXObject!" + "\n";
				//try to find the plugin using the name and description properties
				for(var i = 0; i < navigator.plugins.length; i++)
				{
					var plugin = navigator.plugins[i];
					if(plugin.name.indexOf(_plugins[type][0]) >= 0)
					{
						available = PLAYER_AVAILABLE;
						MSG += "Media Player detected under navigator.plugins[i].name: '" + plugin.name + "' :::Description: " + plugin.description + "' \n";
						if(plugin.description.indexOf(requiredVersion) >= 0)
						{
							available += PLAYER_VALID_VERSION_AVAILABLE;
							break;
						}
					}
				}
				
			}
			return available;
		}
		function selectMediaOption(settingName, option)
		{
			// document.getElementById("_ctl3_" + settingName + "_MediaSelection_" + option).checked = true;
			document.getElementById(eval(settingName + "_MediaSelection_" + option)).checked = true;
		}
		function disableMediaOption(settingName, option)
		{
		    //alert("In disableMediaOption, settingName = " + settingName);
			document.getElementById(eval(settingName + "_MediaSelection_" + option)).checked = false;
			//document.all("_ctl3_" + settingName + "_MediaSelection_" + option).checked = false;
			document.getElementById(eval(settingName + "_MediaSelection_" + option)).disabled = true;
			//document.all("_ctl3_" + settingName + "_MediaSelection_" + option).disabled = true;
		}
		function setDefaultBandwidth()
		{
  			// high speed threshold 56K
  			var throughput = calcThroughput(_startDate, _endDate);
  			if (throughput >= 560)
  				selectMediaOption("VideoConnection", 0);
  			else
  				selectMediaOption("VideoConnection", 1);

  			if (throughput >= 560)
				MSG += "High speed connection detected!" + "\n";
  			else
				MSG += "Low speed connection detected!" + "\n";
  				
		}
	function setDefaultPlayer()
	{
		MSG += "\nDetect WMP begin ..." + "\n";
		var windowsMediaInfo = playerAvailable(PLUGIN_WINDOWS_MEDIA);
		var windowsMediaVersionRequired = versionRequired(PLUGIN_WINDOWS_MEDIA); 
		if((windowsMediaVersionRequired) && ((windowsMediaInfo & PLAYER_VALID_VERSION_AVAILABLE) == 0))
			windowsMediaInfo = PLAYER_UNAVAILABLE;
		MSG += "Version required? " + windowsMediaVersionRequired + "\n\n";
		MSG += "Detect WMP end ..." + "\n\n";
		
		MSG += "\nDetect RealPlayer begin ..." + "\n";
		var realPlayerInfo = playerAvailable(PLUGIN_REAL_PLAYER);
		var realPlayerVersionRequired = versionRequired(PLUGIN_REAL_PLAYER); 
		if((realPlayerVersionRequired) && ((realPlayerInfo & PLAYER_VALID_VERSION_AVAILABLE) == 0))
			realPlayerInfo = PLAYER_UNAVAILABLE;
		MSG += "Version required? " + realPlayerVersionRequired + "\n\n";
		MSG += "Detect RealPlayer end ..." + "\n\n";

		//if neither player is available, go to the error page
		if(((windowsMediaInfo || realPlayerInfo) & PLAYER_AVAILABLE) == 0)
			gotoErrorPage();
			
		//If WindowsMedia is unavailable, disable the option.
		//If we cannot detect the version of the player, show the version detect message
		if((windowsMediaInfo & PLAYER_AVAILABLE) == 0)
			disableMediaOption("VideoPlayer", 0);
		else if ((windowsMediaInfo & PLAYER_VALID_VERSION_AVAILABLE) == 0)
  			document.getElementById("WMPVersionInfo").style.visibility = "visible";

		//If RealPlayer is unavailable, disable the option.
		//If we cannot detect the version of the player, show the version detect message
		if((realPlayerInfo & PLAYER_AVAILABLE) == 0)
			disableMediaOption("VideoPlayer", 1);
		else if ((realPlayerInfo & PLAYER_VALID_VERSION_AVAILABLE) == 0)
  			document.getElementById("RealVersionInfo").style.visibility = "visible";

		//select the correct player, WindowsMedia first, then RealPlayer
		if((windowsMediaInfo & PLAYER_AVAILABLE) > 0)
			selectMediaOption("VideoPlayer", 0);
		else
			selectMediaOption("VideoPlayer", 1);
			
		storeSetting();	
	}
	function gotoErrorPage()
	{
		// var queryString = window.location.href.split("?");
		// document.location = "/VideoError.aspx?" +  queryString[1];
		document.location = "/VideoError.aspx";
	}
	
    function checkSettings()
	{	
	    //alert("Inside checkSettings");
	    var inputControls = document.getElementsByTagName("input");
	    //alert(inputControls.length);
	    for (i = 0; i < inputControls.length; i++)
        {
            //alert("Inside for");
            if (inputControls[i].id.indexOf('VideoConnection_MediaSelection_0') > 0)
            {
                VideoConnection_MediaSelection_0 = inputControls[i].id;
                //alert(VideoConnection_MediaSelection_0);
            }
            if (inputControls[i].id.indexOf('VideoConnection_MediaSelection_1') > 0)
            {
                VideoConnection_MediaSelection_1 = inputControls[i].id;
                //alert(VideoConnection_MediaSelection_1);
            }
            if (inputControls[i].id.indexOf('VideoPlayer_MediaSelection_0') > 0)
            {
                VideoPlayer_MediaSelection_0 = inputControls[i].id;
                //alert(VideoPlayer_MediaSelection_0);
            }
            if (inputControls[i].id.indexOf('VideoPlayer_MediaSelection_1') > 0)
            {
                VideoPlayer_MediaSelection_1 = inputControls[i].id;
                //alert(VideoPlayer_MediaSelection_1);
            }
            if (inputControls[i].id.indexOf('VideoFormat_MediaSelection_0') > 0)
            {
                VideoFormat_MediaSelection_0 = inputControls[i].id;
                //alert(VideoFormat_MediaSelection_0);
            }
            if (inputControls[i].id.indexOf('VideoFormat_MediaSelection_1') > 0)
            {
                VideoFormat_MediaSelection_1 = inputControls[i].id;
                //alert(VideoFormat_MediaSelection_1);
            }
        }
        //alert("After for");
		if ((getCookie("VideoConnection") != null)) 
		{
		    //alert("Inside if for getCookie VideoConnection");
			MSG += "Cookies available at client!" + "\n";
			retrieveSettings();
			MSG += "Above Info is from Cookie!" + "\n";
			//alert(MSG);
			return;
		}
        //alert("Before SetDefaultBandwidth");
		setDefaultBandwidth();
		//alert("After setDefaultBandwidth");
		setDefaultPlayer();			
		//alert(MSG);
	}
// ******* End of VideoSetup user control functions ******* //

// ******* ArticleOptions user control -> Chinese language function ******* //
/* Commented the fol. function since it is not being used anymore to replace the Chinese image.
function toggleClassForChinese()
{
    var normalClass = "ArticleContentSections--ArticleOptions_ascx--Language_Chinese";
    var mouseoverClass = "ArticleContentSections--ArticleOptions_ascx--Language_Chinese_over";
    var divChinese = document.getElementById("divChinese"); 
    if (divChinese != null)
    {
        if (divChinese.className != null)
        {
            if (divChinese.className == normalClass)
            {
                divChinese.className = mouseoverClass;
            }
            else if (divChinese.className == mouseoverClass)
            {
                divChinese.className = normalClass;
            }
            else
            {
                divChinese.className = normalClass;
            }
        }
    }
}*/
// ******* End of ArticleOptions user control -> Chinese language function ******* //