//init global vars
// prefixes:
//    pufn_  = public function
//    prfn_  = private function

var mblnGlobalLibraryExists	= true;
CoreMetricsTurnOn			= false;
var mbUseScene7             = true;
var jsURL					= location.href;
var jsURLScheme				= '';
var jsURLAuthority   		= '';
var iURLDelimiterLocation	= jsURL.indexOf('://');

if(iURLDelimiterLocation>=0){
	var jsURLScheme			= jsURL.substring(0,iURLDelimiterLocation).toLowerCase();
	var jsURLAuthority		= jsURL.substring(iURLDelimiterLocation + 3);
	if(jsURLAuthority.indexOf('/')>=0){
		jsURLAuthority=jsURLAuthority.substring(0,jsURLAuthority.indexOf('/'));
	}
}

//functions
function LogOff(url) 
{
	var strURL = new String(url);
	if (strURL.slice(0,5)=="https") 
		strURL = "http" + strURL.slice(5);
	strURL = escape(strURL);
	popup = window.open('/popups/SignOut.asp?destin=' + strURL,'SignOut','width=300,height=200');
	if (!popup.opener)
		popup.opener = self;
}

function openHelp( subPath )
{
	var helpURL = "/pom2k.aspx?category=cc/assistance&page=broadcastcenter&title=Broadcast+Center&displaytype=2&ft=0";
	if(subPath)
	{
		helpURL += "#" + subPath;
	}
	location.href = helpURL;
}
function StopReturn(evt)
{	
	if ((evt.which ? evt.which : evt.keyCode) == 13)
		{return false;}
}
function SetToEmpty(Control)
{
	// USAGE:
	// var x = new SetToEmpty(objTextBox);
	// x.Clear();
	//
	this.TextCleared = false;
	this.ClearOnce = Clear; 
	function Clear(){
		if(!this.TextCleared){ 
			Control.value = '';
			this.TextCleared = true; 
		}
	}
}

function TopKiller(){
	var strhref
	for (x=0; x<document.links.length;x++){
		if (document.links[x].name == 'pop'){
			document.links[x].target = '_blank'
			continue;
			}
		if (document.links[x].name != 'ShopNBC' && document.links[x].name != 'reg' && document.links[x].name != 'login'){
			document.links[x].target = '_self'
			}
		else{
			document.links[x].target = '_top'
			continue;
			}

		strhref = document.links[x].href
		if (strhref.indexOf('javascript') == -1){
			if (strhref.indexOf('?') == -1){
				strhref = strhref + '?NBCAffil=' + intAffil
				}
			else{
				if (strhref.indexOf('adredir.asp') == -1){
					strhref = strhref + '&NBCAffil=' + intAffil
					}
				else{
					strhref = strhref + '%26NBCAffil=' + intAffil
					}
				}
			document.links[x].href = strhref
			}
		}
	}

	
// use this when referring to pop-up window
var popWin = null;    
var winCount = 0;
var winName = "popWin";
var newWin = 0;

function destroyWin ()
{
	if (newWin == 0) 
		popWin = null;
	else 
		newWin = 0;
}

/************ START popup blocker check utility ************/
// USAGE: CheckForPopUpBlocker(window.open('/'), true, 1);
//	Arguements: 
//		pobjPopWindow:		The popup window object.	[object]
//		pblnVerbose:		Show explination why popup didn't show.	[boolean]
//		pintVerboseType:	Index of showing explination -> 1.)Div Notice Box, 2.)Alert Box 3.)Returned Notice Text		[integer]
function CheckForPopUpBlocker(pobjPopWindow, pblnVerbose, pintVerboseType)
{
	// Call this after popup created
	if (!pobjPopWindow) {
		if(pblnVerbose) {
			var sPopUpBlockedAlertText = 'A popup blocker has been detected!<br><br>Please configure your software to allow popups from this site. Then refresh this web page.<br><br>Thank you.';
			if(pintVerboseType && !isNaN(pintVerboseType)) {
				switch( pintVerboseType ) {
					case 1:
						// Inject Popup Blocker Notice Onto Page.
						var sNoticeBoxID		= 'divOuterPopupNotice';
						var objPopUpNoticeBox	= gGetElementById(sNoticeBoxID);
						if(!objPopUpNoticeBox)
							gGetElementById('container').appendChild( CreatePopBlockerNoticeBox(sNoticeBoxID, sPopUpBlockedAlertText) );
						else
							objPopUpNoticeBox.style.visibility = 'visible';
						break;
					case 2:
						alert(sPopUpBlockedAlertText = sPopUpBlockedAlertText.replace(/<br>/g, '\n'));
						break;				
					default:
						return sPopUpBlockedAlertText;
						break;
				}
			}
			return sPopUpBlockedAlertText;
		}
		return '';		
	}
	else
	{ pobjPopWindow.focus(); }
}
function CreatePopBlockerNoticeBox(sNoticeBoxID, sNoticeText)
{
	// Create Outer Container
	var objNewOuterDiv					= null
		objNewOuterDiv					= document.createElement("DIV");
		objNewOuterDiv.id				= sNoticeBoxID;
		objNewOuterDiv.style.width		= '740px';
		objNewOuterDiv.style.position	= 'absolute';
		objNewOuterDiv.style.display	= 'block';
		objNewOuterDiv.style.top		= '2px';
		objNewOuterDiv.style.textAlign  = 'center';
		objNewOuterDiv.appendChild( CreatePopBlockerNoticeBoxContent(sNoticeBoxID, sNoticeText) );
	return objNewOuterDiv;
}
function CreatePopBlockerNoticeBoxContent(sNoticeBoxID, sNoticeText)
{
	// Create Content Container
	var objNewContentDiv					= null;
		objNewContentDiv					= document.createElement("DIV");
		objNewContentDiv.innerHTML			= sNoticeText;
		objNewContentDiv.className			+= ' borderBoxC';
		objNewContentDiv.className			+= ' padding8';
		objNewContentDiv.className			+= ' i0';		
		objNewContentDiv.align				= 'left';
		objNewContentDiv.style.textAlign	= 'left';
		objNewContentDiv.style.marginLeft	= 'auto';
		objNewContentDiv.style.marginRight	= 'auto';
		objNewContentDiv.style.width		= '200px';
		objNewContentDiv.appendChild( CreatePopBlockerNoticeBoxButton(sNoticeBoxID) );
	return objNewContentDiv;
}
function CreatePopBlockerNoticeBoxButton(sNoticeBoxID)
{
	// Create Close Button
	var objNewDivClose					= null;
		objNewDivClose					= document.createElement("DIV");
		objNewDivClose.innerHTML		= '<a title=\"Close\" style=\"cursor:pointer;\" onclick=\"gGetElementById(\'' + sNoticeBoxID + '\').style.visibility=\'hidden\';\"><img src=\"/images/buttons/close_btn.gif\" border=\"0\"/></a>';
		objNewDivClose.style.position	= 'absolute';
		objNewDivClose.style.bottom		= '5px';
		objNewDivClose.style.right		= '267px';
		objNewDivClose.style.width		= '53px';	
	return objNewDivClose;
}
/************ END popup blocker check utility ************/

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop)
{
	var d_winLeft = 20;  // default, pixels from screen left to window left
	var d_winTop = 20;   // default, pixels from screen top to window top
	winName = "popWin" + winCount++; //unique name for each pop-up window
	closePopWin();           // close any previously opened pop-up window
	if ((openPopWin.arguments.length >= 4) && (openPopWin.arguments[3].length > 0))  // any additional features?
		winFeatures = "," + winFeatures;
	else
		winFeatures = "";
	if (openPopWin.arguments.length == 6)  // location specified
		winFeatures += getLocation(winWidth, winHeight, winLeft, winTop);
	else
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop);
	if(winLeft >0 && winTop>0)
		winFeatures += ",left=" + winLeft + ",top=" + winTop;
    else
        winFeatures += ",left=0,top=0";
	popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures);
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 4.5)
		popWin.onunload = destroyWin;
}

function openDialogWin(winURL, dialogWidth, dialogHeight, winFeatures, winLeft, winTop)
{
	var d_winLeft = 20;  // default, pixels from screen left to window left
	var d_winTop = 20;   // default, pixels from screen top to window top
	winName = "popWin" + winCount++; //unique name for each pop-up window
	closePopWin();           // close any previously opened pop-up window
    if ((openDialogWin.arguments.length >= 4) && (openDialogWin.arguments[3].length > 0))  // any additional features?
	    winFeatures = "," + winFeatures;
    else
	    winFeatures = "";
    if (openDialogWin.arguments.length == 6)  // location specified
	    winFeatures += getLocation(dialogWidth, dialogHeight, winLeft, winTop);
    else
	    winFeatures += getLocation(dialogWidth, dialogHeight, d_winLeft, d_winTop);
    if(!winFeatures && winLeft && winTop)
	    winFeatures += ",left=" + winLeft + ",top=" + winTop;
    if(navigator.userAgent.indexOf("Firefox") != -1)
    {
    }
    else if(navigator.userAgent.indexOf("Netscape") != -1)
    {
	    dialogWidth		+= 6;
	    dialogHeight	+= 34;
    }
    else if (navigator.userAgent.indexOf("MSIE 7.0") != -1)
    {
	    dialogWidth		+= 0;
	    dialogHeight	+= 34;
    }
    else if(navigator.userAgent.indexOf("MSIE") != -1)
    {
	    dialogWidth		+= 0;
	    dialogHeight	+= 0;
    }
    popWin = window.open(winURL, winName, "width=" + dialogWidth + ", height=" + dialogHeight + winFeatures);
	if (navigator.userAgent.indexOf("MSIE") && parseInt(navigator.appVersion) < 4.5)
		popWin.onunload = destroyWin;
}

function openPopWinRedirect(winURL, winWidth, winHeight, winFeatures, winLeft,winTop, redirectURL)
{
	location.href = redirectURL;
	openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop);
}
 
function closePopWin(){    // close pop-up window if it is open 
    if(popWin != null)
	{
		if(!popWin.closed) 
		{
			newWin = 1;
			popWin.close();
		}
	}
}

function getLocation(winWidth, winHeight, winLeft, winTop)
{
	return "";
}

function getLocation(winWidth, winHeight, winLeft, winTop)
{
	var winLocation = "";
	if (winLeft < 0)
		winLeft = screen.width - winWidth + winLeft;
	if (winTop < 0)
		winTop = screen.height - winHeight + winTop;
	if (winTop == "cen") 
		winTop = (screen.height - winHeight)/2 - 20;
	if (winLeft == "cen") 
		winLeft = (screen.width - winWidth)/2;
	if (winLeft>0 & winTop>0) 
		winLocation =  ",screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop;
	else
		winLocation = "";
	return winLocation;
}

function mo(added)
{
	window.status='Click to view '+added;
}
window.defaultStatus='';

function getQueryStringValue(strQueryStringName)
{
	//Utility function for getting a specific querystring value from requested name
	var args = null;
	var query = location.search.substring(1);
	var pairs = query.split(",");
	for(var i = 0;i< pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		if(strQueryStringName == argname)
		{
			args = unescape(value);
			continue;
		}
	}
	return args;
}

// Use this to get complete QS value, the one above will split on commas
function GetQueryValue( Name )
{
	return FindQueryValue( Name, window.location.href );
}
function FindQueryValue( Name, Url )
{
  var regexS = "[\\?&]"+Name+"=([^&#]*)";
  var regex = new RegExp( regexS , "i");
  var tmpURL = Url;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

// Cross-browser get event target element
function GetEventTarget(evt){
    var e = evt || window.event;
    if(!e) 
		{ return null; }
    if(e.target) 
		{ return e.target; }
    else if(e.srcElement) 
		{ return e.srcElement; }
}
// Cross-browser get html element
function gGetElementById(e)
{
    if(typeof(e)!='string')
		return e;
    if(document.getElementById) 
		e=document.getElementById(e);
    else if(document.all) 
		e=document.all[e];
    else 
		e=null;
    return e;
}

function trimString(value) 
{
	value = value.replace(/^\s+/, '');
	value = value.replace(/\s+$/, '');
	return value;
}

// USAGE: String.format('Hello. My name is {0} {1}.', 'Super', 'Man');
// Note: This doesn't allow for escaping '{' or '}' characters...
//   It will still replace {{0}} instead of skipping it like .NET does.
String.format = function()
{
    if( arguments.length == 0 )
        return null;

    var str = arguments[0];
    for(var i=1;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

/************ START Custom TextBox utilities ************/
function pufn_ClearReg(Control)
{
	if(Control) 
	{
		if(typeof(gClearNewsRegTB) == 'undefined') 
		{
			gClearNewsRegTB = new SetToEmpty(Control);
		}
		
		gClearNewsRegTB.ClearOnce();
	}
}

function NewLetterReg(evt, oBtnReg, oTextBox) 
{
	// For newletter signup (CS Footer) popup
	var filter		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var strEmailValue = trimString(oTextBox.value);
	
	if (oTextBox != null && strEmailValue != "Your E-Mail Address") 
	{
		if(strEmailValue.length > 0) 
		{
			if(filter.test(strEmailValue)) 
			{
				var strPath = 'http://ebm.e.shopnbc.com/r/regf2?aid=342318099&n=1000&a=0&cm_re=Settings-_-Email-_-N&CIID=11315&email=' + strEmailValue + '&pls_login=';
				var newWin	= window.open(strPath, 'Newsletters', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=600');
				
				CheckForPopUpBlocker(newWin, true, 1);
			}
			else 
			{
				oTextBox.value = ' Your E-Mail Address';
			}
		}
	}
	
	return false;
}

function WatchOrbitNewLetterReg(evt, oBtnReg, oTextBox) 
{    
    //Nov-29-2007. ACG
	// For WatchOrbit newletter signup (CS Footer) popup
	var filter		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (oTextBox !== null) 
	{
		    var strEmailValue = trimString(oTextBox.value);		
			
			if(filter.test(strEmailValue)) 
			{
				var strPath = 'http://ebm.e.watchorbit.com/r/regf2?aid=1672852974&n=1&a=0&email1=' + strEmailValue;
				var newWin	= window.open(strPath, 'WatchOrbitNewsletters', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=600');
				
				CheckForPopUpBlocker(newWin, true, 1);
			}
			else 
			{
				oTextBox.value = '';
			}
	}
	
	return false;
}

function pufn_ClearFindChannel(Control)
{
	if(Control) 
	{
		if(typeof(gClearFindChTB) == 'undefined') 
		{
			gClearFindChTB = new SetToEmpty(Control);
		}
		
		gClearFindChTB.ClearOnce();
	}
}

function FindChannel(evt, oBtnSearch, oTextBox) 
{
    var strZipCode = trimString(oTextBox.value);
    
	// For channel finder (OnAir) popup
	if (oTextBox != null && strZipCode != "Enter ZIP Code") 
	{
		if(strZipCode.length > 0) 
		{	
			var newWin = window.open('/popups/channelfinder.aspx?zipcode=' + strZipCode, null,'status=0,scrollbars=0,width=400,height=400,top=0,left=0',true);
			
			CheckForPopUpBlocker(newWin, true, 1);
			
			return true;
		}
		else 
		{
			oTextBox.value = ' Enter ZIP Code';
		}
	}
	
	return false;
}
/************ END Custom TextBox utilities ************/

/************ START Search utilities ************/
function GoogleSearch()
{
	document.googlesearch.submit();
}

function pufn_ClearSearch(Control)
{
	if(Control) {
		if(typeof(gClearSearch) == 'undefined') {
			gClearSearch = new SetToEmpty(Control);
		}
		gClearSearch.ClearOnce();
	}
}

function searchClick(evt, oBtnSearch, oTextBox) 
{ 
	if((oBtnSearch !== null) && (oTextBox !== null)) { 
		var searchValue = trimString(oTextBox.value); 
		if((typeof(gClearSearch) != 'undefined') && (gClearSearch.TextCleared) && (searchValue.length > 0)) { 
			return true;
		} 
	} 
	return false;
} 

//New - This function submits the form
function searchSubmit(evt, oBtnSearch, oTextBox) 
{ 
	if((oBtnSearch !== null) && (oTextBox !== null)) { 
		var searchValue = trimString(oTextBox.value); 
		
		if ((searchValue == 'Search by Item # or Keyword') 
		    || ((typeof(gClearSearch) == 'undefined') 
		            && (!(gClearSearch.TextCleared)) || (searchValue.length == 0)))
		{
		    alert ('Please enter a valid search term or Item #');
		    return false;
		}
	    
	    if((typeof(gClearSearch) != 'undefined') && (gClearSearch.TextCleared) && (searchValue.length > 0)) 
	    {
	        var m = GetQueryValue('Mode'); 
            var ts = GetQueryValue('ForTesting');            
            var l = "/SearchM/Default.aspx";
            var t = "" ; 
            
            if (m!= null && m.toLowerCase() =='cmc')
            {
                t = '&Mode=' + mode ;                
            }
            
            if(ts != null && ts.toLowerCase() == 'true')
            {
                t+= ('&ForTesting=' + ts); 
            }
            
            var targetLocation =  l + '?page=LIST&free_text='+ searchValue + t;
            
            document.forms[0].action = targetLocation;
            document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
            document.forms[0].submit();
	    }		 
	} 
} 

/************ END Search utilities ************/

/************ START Key Trap utilities ************/
function gPreTrap(evt, sButtonClientID, sTextBoxClientID, oFunction)
{
	var objButton=gGetElementById(sButtonClientID);
	var objTextBox=gGetElementById(sTextBoxClientID);
	if (objButton) {
		if ((evt.which ? evt.which : evt.keyCode) == 13) {
			gEnterKeyPressed(evt, objButton, objTextBox, oFunction);
			return true;
		}
	}
	return false;
}
function gEnterKeyPressed(evt, objButton, objTextBox, func)
{ 
	if (typeof(func)=="function") {
		func(evt, objButton, objTextBox); 
	} 
	else if(document.all) { 
		objButton.click(); 
	} 
	else { 
		var evt = objButton.ownerDocument.createEvent('MouseEvents'); 
		evt.initMouseEvent('click', true, true, objButton.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); 
		objButton.dispatchEvent(evt); 
	} 
}
/************ END Key Trap utilities ************/			

var myBrowser 		= null;
var myFlash			= null;
var myJavascript	= null;

// USAGE: RunDetection(true, false, false);
function RunDetection()
{
	var _bCheckBrowser		= ( arguments && arguments.length > 0 ) ? arguments[0] : false;
	var _bCheckFlash		= ( arguments && arguments.length > 1 ) ? arguments[1] : false;
	var _bCheckJavascript	= ( arguments && arguments.length > 2 ) ? arguments[2] : false;

	if(_bCheckBrowser)	
		{ myBrowser 		= new GetBrowserInfo(); }
	if(_bCheckFlash)	
		{ myFlash			= new GetFlashInfo(); }
	if(_bCheckJavascript)
		{ myJavascript		= new GetJSInfo(); }
}

/************ START Browser Detection utility ************/
function GetBrowserInfo() 
{
	// Get basic agent info.
	this.AppName 				= navigator.appName.toLowerCase();
	this.UserAgent 				= navigator.userAgent.toLowerCase();
	this.AppVersion				= isNaN(parseInt(navigator.appVersion)) ? -1 : parseInt(navigator.appVersion);
	this.DomAble				= document.getElementById;
	this.BrowserSupported		= (this.DomAble && document.createElement);
	
	// IE detection
	this.objIE					= new Object();
	this.objIE.IsIE				= ((this.UserAgent.indexOf("msie") != -1) && (this.UserAgent.indexOf("opera") == -1));
	this.objIE.IsIE4 			= (this.objIE.IsIE && (this.AppVersion == 4) && (this.UserAgent.indexOf("msie 4") != -1));
	this.objIE.IsIE5 			= (this.objIE.IsIE && (this.AppVersion == 4) && (this.UserAgent.indexOf("msie 5.0") != -1));
	this.objIE.IsIE5_5 			= (this.objIE.IsIE && (this.AppVersion == 4) && (this.UserAgent.indexOf("msie 5.5") != -1));
	this.objIE.IsIE6 			= (this.objIE.IsIE && (this.AppVersion == 4) && (this.UserAgent.indexOf("msie 6.0") != -1));
	this.objIE.IsIE7 			= (this.objIE.IsIE && (this.AppVersion == 4) && (this.UserAgent.indexOf("msie 7") != -1));
	this.objIE.IsSupported 		= (this.BrowserSupported && this.objIE.IsIE && (this.AppVersion >= 4) && (!this.objIE.IsIE4));
	this.objIE.IsNewest			= (this.objIE.IsIE && this.objIE.IsSupported);
		
	// Mozilla detection
	this.objMoz					= new Object();
	this.objMoz.IsMoz			= ((this.UserAgent.indexOf('mozilla') != -1 ) && (this.UserAgent.indexOf('spoofer') == -1 ) && (this.UserAgent.indexOf('compatible') == -1));
	this.objMoz.IsMoz4 			= (this.objMoz.IsMoz && this.AppVersion == 4);
	this.objMoz.IsMoz6 			= (this.objMoz.IsMoz && this.AppVersion == 5);
	this.objMoz.IsSupported 	= (this.BrowserSupported && this.objMoz.IsMoz && this.AppVersion >= 5);
	this.objMoz.IsNewest		= (this.objMoz.IsMoz && this.objMoz.IsSupported);
	
	// Mozilla FireFox			
	var arrFireFox				= this.UserAgent.match(/(firefox)+.(\d[\.|\d]*)?/i);
	this.objMoz.IsFireFox		= (this.objMoz.IsMoz && arrFireFox && arrFireFox[1] && (arrFireFox[1].length > 0));
	this.objMoz.FireFoxVersion	= (this.objMoz.IsFireFox && arrFireFox[2] && (arrFireFox[2].length > 0)) ? arrFireFox[2] : -1;
	this.objMoz.IsFoxCurrent	= (this.BrowserSupported && this.objMoz.IsFireFox && (parseFloat(this.objMoz.FireFoxVersion) > 1.1))
	
	// Opera detection
	this.objOpera				= new Object();
	this.objOpera.IsOpera		= this.UserAgent.indexOf("opera") != -1;
	this.objOpera.IsOpera2 		= (this.objOpera.IsOpera && (this.UserAgent.indexOf("opera 2") != -1) || (this.UserAgent.indexOf("opera/2") != -1));
	this.objOpera.IsOpera3 		= (this.objOpera.IsOpera && (this.UserAgent.indexOf("opera 3") != -1) || (this.UserAgent.indexOf("opera/3") != -1));
	this.objOpera.IsOpera4 		= (this.objOpera.IsOpera && (this.UserAgent.indexOf("opera 4") != -1) || (this.UserAgent.indexOf("opera/4") != -1));
	this.objOpera.IsOpera5 		= (this.objOpera.IsOpera && (this.UserAgent.indexOf("opera 5") != -1) || (this.UserAgent.indexOf("opera/5") != -1));
	this.objOpera.IsSupported 	= (this.BrowserSupported && !this.objOpera.IsOpera2 && !this.objOpera.IsOpera3);
	this.objOpera.IsNewest		= (this.objOpera.IsSupported && !this.objOpera.IsOpera4);
	
	// Macintoch detection
	this.objMac					= new Object();
	this.objMac.IsMac			= this.UserAgent.indexOf("mac") != -1;
	
	// Safari detection
	this.objSafari				= new Object();
	this.objSafari.IsSafari		= this.UserAgent.indexOf("safari") != -1;

	// Return the browser detection object
	return this;
};

function IsIE6()
{
    return /*@cc_on!@*/false; //isIE
    return (false /*@cc_on || @_jscript_version < 5.7 @*/);// is IE6
}
/************ END Browser Detection utility **************/

/************ START Javascript Version Detection utility ************/
function GetJSInfo()
{
	FindVersion = function() {
		jsVer = 0.0;
		
		for(var i=0; i<=6;i++) {
			document.write('<script type="text/javascript" language="JavaScript1.'+i+'">\n');
			document.write('//<!-- Hide from non JavaScript browsers\n');
			document.write('var jsVer=1.'+i+';\n');
			document.write('//-->\n');
			document.write('</script>\n');
		}

		document.write('<script type="text/javascript" language="JavaScript2.0">');
		document.write('var jsVer=2.0;');
		document.write('</script>');

		return jsVer;	
	};
	
	this.version = FindVersion();

	// JS Support Must Be At Least...
	this.ver10=(this.version >= 1.0) ? true:false;
	this.ver11=(this.version >= 1.1) ? true:false;
	this.ver12=(this.version >= 1.2) ? true:false;
	this.ver13=(this.version >= 1.3) ? true:false;
	this.ver14=(this.version >= 1.4) ? true:false;
	this.ver15=(this.version >= 1.5) ? true:false;
	this.ver20=(this.version >= 2.0) ? true:false;
	
	return this;
}
/************ END Javascript Version Detection utility ************/

/************ START Shockwave Flash Detection utility ************/
function GetFlashInfo() 
{
	this.IsFlashInstalled 	= false;
	this.FlashVersion		= 1; 
	var _objFlash			= null;
	
	if (navigator.plugins && navigator.plugins.length){
		_objFlash = navigator.plugins["Shockwave Flash"];
		if (_objFlash)
		{
			if (_objFlash.description)
			{
				this.FlashVersion 	= parseInt(_objFlash.description.replace( /^[^\d]*/, '' ));
			}
			this.IsFlashInstalled = true;
		}
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			// Plugins 1.0 & 2.0 were titled differently then the rest, hence the extra check.
			// Note: 1.0 is the initial version, if neither checks are valid.
			this.IsFlashInstalled 	= true;
			this.FlashVersion 	= 2;
		}		
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length){
	 	// old browsers such as Opera 5- do not support the plugins collection
		_objFlash = navigator.mimeTypes['application/x-shockwave-flash'];
		if (_objFlash && _objFlash.enabledPlugin){
			this.IsFlashInstalled = true;
		}
	}
	else{
		// all browsers that support ActiveX (Most IE-based and some newer mozilla-based browsers)
		for (var j=7; j>0; j--){
			try{
				_objFlash		= new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + j);
				this.FlashVersion 	= j;
				this.IsFlashInstalled 	= true;
				break;
			}
			catch(e){ /*try again*/ }
		}
	}
	return this;
};
/************ END Shockwave Flash Detection utility **************/

/**************** START Flash Manul Link Tags ******************/
function FlashCMCManul(strURL, intFlash)
{
	//cmCreateManualLinkClickTag(strURL,'flash' + intFlash );
	dcsMultiTrack('DCSext.url', strURL, 'DCSext.flash', intFlash);
	
	var strPath = strURL;
  	strPath=   strPath.replace(/&/g,"%26");
  
	alert(strPath + "\n\r" + strURL); 
	location.href = strPath;
}
/**************** END Flash Manul Link Tags ******************/

/************ START of Object work-around **************/
function CreateFlashObject(DivID, ObjectID, WIDTH, HEIGHT, URL, BGCOLOR, NOFLASHIMG)
{
	var d = document.getElementById(DivID);
	d.innerHTML = '<object name="' + ObjectID + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="' + HEIGHT + '" width="' + WIDTH + '"><param name="movie" value="' + URL + '"/><param name="bgcolor" value="' + BGCOLOR + '" />' + NOFLASHIMG + '</object>';
}

function CreateProductFlashPlayer(url, flashPlayer, bgColor, width, height)
{
    if ((typeof(myBrowser)=='undefined')||(!myBrowser))
        myBrowser = GetBrowserInfo();
    if (myBrowser.objIE.IsIE && !myBrowser.objMac.IsMac){
        document.write(
        '<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n'+
        '  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n'+   
        '  ID=flaMovie WIDTH=' + width + ' HEIGHT=' + height + '>\n'+
        '  <PARAM NAME=movie '+
        '    VALUE="' + flashPlayer + '?movie=' + url + '">\n'+
        '  <PARAM NAME=quality VALUE="high">\n'+
        '  <PARAM NAME=bgcolor VALUE=' + bgColor + '>\n'+
        '  <EMBED src="' + flashPlayer + '?movie=' + url + '">\n'+
        '    bgcolor=' + bgColor + ' WIDTH=' + width + ' HEIGHT=' + height + '\n'+
        '    TYPE="application/x-shockwave-flash">\n'+
        '  </EMBED>\n'+
        '</OBJECT>\n');
    }
    else { 
        document.writeln (
            '<embed src="' + flashPlayer + '?movie=' + url + '" bgcolor="' + bgColor + '"' + 
            ' pluginspage="http://www.macromedia.com/go/getflashplayer"' + 
            ' allowScriptAccess="sameDomain"' +
            ' type="application/x-shockwave-flash" wmode="opaque" width="' + width + '" height="' + height + '">' +
            '</embed>');
    }
}

function GetProductFlashPlayer(url, flashPlayer, bgColor, width, height)
{
    var flashPlayer; 
    if ((typeof(myBrowser)=='undefined')||(!myBrowser))
        myBrowser = GetBrowserInfo();
    if (myBrowser.objIE.IsIE && !myBrowser.objMac.IsMac){
       flashPlayer = 
        '<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n'+
        '  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n'+   
        '  ID=flaMovie WIDTH=' + width + ' HEIGHT=' + height + '>\n'+
        '  <PARAM NAME=movie '+
        '    VALUE="' + flashPlayer + '?movie=' + url + '">\n'+
        '  <PARAM NAME=quality VALUE="high">\n'+
        '  <param name="wmode" value="transparent" />\n' +
        '  <PARAM NAME="bgcolor" VALUE=' + bgColor + '>\n'+
        '  <PARAM NAME="allowScriptAccess" VALUE="always">\n'+
        '  <EMBED src="' + flashPlayer + '?movie=' + url + '">\n'+
        '    bgcolor=' + bgColor + ' WIDTH=' + width + ' HEIGHT=' + height + '\n'+
        '    TYPE="application/x-shockwave-flash">\n'+
        '  </EMBED>\n'+
        '</OBJECT>\n';
    }
    else { 
         flashPlayer = 
            '<embed src="' + flashPlayer + '?movie=' + url + '" bgcolor="' + bgColor + '"' + 
            ' pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"' + 
            ' allowScriptAccess="always"' +
            ' type="application/x-shockwave-flash" wmode="opaque" width="' + width + '" height="' + height + '">' +
            '</embed>';
    }
    return flashPlayer; 
}


/************ END of Object work-around **************/

function flashVideoHelper(strVideoUrl, blnShowDisclaimer, intVideoWidth, intVideoHeight)
{
	var strPopupURL = '/product/launchProductVOD2.aspx?videourl=';
	var intPopUpWidth = 447;
	var intPopUpHeight = 463;
	var strPopupParams = strPopupURL + strVideoUrl + '&showDisclaimer=' + blnShowDisclaimer;
	openDialogWin(strPopupParams, intPopUpWidth, intPopUpHeight, '', 1,1)
}

/************ START event listener utility **************/
// http://dean.edwards.name/weblog/2005/10/add-event/
function gAddEventListener(element, type, handler) {
	if (!((element=gGetElementById(element)) && (type) && (handler))) return;
	type=type.toLowerCase();
	if (!handler.$$guid) {handler.$$guid = gAddEventListener.guid++;}
	if (!element.events) element.events = {};
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	handlers[handler.$$guid]	= handler;
	element["on" + type]		= handleEvent;
}
function gRemoveEventListener(element, type, handler) {
	if (!((element=gGetElementById(element)) && (type) && (handler))) return;
	type=type.toLowerCase();
	if (element.events && element.events[type]) { delete element.events[type][handler.$$guid]; }
};
function handleEvent(evt) {

try{
	var returnValue			= true;
	evt						= fixEvent(evt || window.event);
	var handlers			= this.events[evt.type];
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(evt) === false) {
			returnValue = false;
		}
	}
	if (this.$$handler) { this.$$handler = null; }
	return returnValue;
}catch(e)
{
}
};
function fixEvent(evt) {
	evt.preventDefault 	= fixEvent.preventDefault;
	evt.stopPropagation	= fixEvent.stopPropagation;
	return evt;
};
fixEvent.preventDefault		= function() { this.returnValue		= false; };
fixEvent.stopPropagation	= function() { this.cancelBubble	= true;	};
gAddEventListener.guid		= 1;
/************ END event listener utility **************/

/************ START legacy onload utility ************/
// Call the following with your function as the argument
//   --> SafeAddOnload(your_onload_function_goes_here);
function SafeAddOnload(f){
	if(typeof (f) == 'function'){
		gAddEventListener(window, 'load', f);
	}
}
/************ END legacy onload utility **************/

/************ MISC global javascript functions **************/
function GetDateStringFromJSON(JSONDate)
{
    eval('var GetDateStringFromJSONdate = new ' + JSONDate.replace(/\//g, '') );
    GetDateStringFromJSONdate.setHours(GetDateStringFromJSONdate.getHours()+1)
    GetDateStringFromJSONdate.setMinutes(0);
    GetDateStringFromJSONdate.setSeconds(0);

    return GetDateStringFromJSONdate.toLocaleDateString() + ' at ' +GetDateStringFromJSONdate.toLocaleTimeString().replace(':00:00',':00'); 
}
	   
function SubmitMVCForm(url, validate)
{
    // Run the validation
    if (validate != null && validate != '' && typeof validate != 'function' && eval("typeof " + validate) != 'undefined' && eval(validate) != null)
    {
	    if (!eval(validate+"()"))
	    {
		    return;
	    }
    }
    
    // Submit the form 
    var f  = document.forms[0];
    f.action = url; 
    f.submit(); 
    
    return; 
}

function SubmitMVCClick(url)
{
                //  SubmitMVCClick nothing so if the SubmitMVCForm fails or takes to long, the link wont do anything else. 
                //  SubmitMVCForm must be on the onclick event so we can use the enter event handler on the login page.   
    return;     //  I added the URL so we can see where your going.  
}

function checkRequiredInput(input)
{   
    var regex = new RegExp('[a-zA-Z0-9]');
    
    return regex.test(input);
}

function checkRequiredInputSize(input, size)
{   
    var regex = new RegExp('[a-zA-Z0-9]{' + size + '}');
    
    return regex.test(input);
}

function checkEmailAddressInput(input) 
{    
    var regex = new RegExp('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}');
    
    return regex.test(input);
}

function checkNumericInput(input)
{    
    var regex = new RegExp('[0-9]');
    
    return regex.test(input);
}

function checkNumericInputSize(input, size)
{    
    var regex = new RegExp('[0-9]{' + size + '}');
    
    return regex.test(input);
}



    function OpenNotifyMePopUp(strFamilyID)
    {
        if(mblnGlobalLibraryExists)
        {
            var oWin = window.open('/Product/NotifyMeSignup.aspx?familyid=' + strFamilyID,'','status=yes,scrollbars=0,width=400,height=580,top=0,left=0,resizeable=0');
            CheckForPopUpBlocker(oWin, true, 1);
        }
    }    



function AddLivePersonError(errorName)
{
	if(errorName != null)
		lpErrorName = errorName + lpErrorCount;
		
	lpErrorCount++;
	
	lpSendData('page', 'ErrorName', lpErrorName);
	lpSendData('page', 'ErrorCounter', lpErrorCount);

}

function AlertLivePerson()
{
    alert("Error Name: " + lpErrorName + " --- Error Count: " + lpErrorCount);
}