/**************************************************
 * Utilities
 **************************************************/
 
var userAgent = window.navigator.userAgent;
var browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
var paidAds = [ 
//	{ "which":"home", "title":"Silverlight Hosting", "markup":"<span style=\"margin-left: 45px;\"><a href=\"http://www.discountasp.net/go/go.aspx?i=3897\"><img src=\"http://silverlight.net/themes/silverlight/images/ads/logo_silverlight_orKE.gif\" border=\"0\" width=\"200\" height=\"50\" /></a></span><br/><br/>DiscountASP.NET - Voted \"Best Web Host\" by asp.netPRO Magazine 3 Years Running ('05,'06,'07) and by Visual Studio for 2007<ul><li><a href=\"http://www.discountasp.net/go/go.aspx?i=3803\">Silverlight Compatible ASP.NET 2.0</a><li>ASP.NET AJAX, VB, & C#<li>.NET Framework 3.0 <li>Visual Studio 2005 & Expression Web Compatible<li><a href=\"http://www.discountasp.net/go/go.aspx?i=3804\">MS SQL 2005 w/ Real Time Backup Tool</a><li>3 Months FREE & FREE Setup</ul><a href=\"http://www.discountasp.net/go/go.aspx?i=3805\">Click Here to Learn More...</a>" }	,
//	{ "which":"getstarted", "title":"Silverlight Hosting", "markup":"<span style=\"margin-left: 45px;\"><a href=\"http://www.discountasp.net/go/go.aspx?i=3898\"><img src=\"http://silverlight.net/themes/silverlight/images/ads/logo_silverlight_orKE.gif\" border=\"0\" width=\"200\" height=\"50\" /></a></span><br/><br/>DiscountASP.NET - Voted \"Best Web Host\" by asp.netPRO Magazine 3 Years Running ('05,'06,'07) and by Visual Studio for 2007<ul><li><a href=\"http://www.discountasp.net/go/go.aspx?i=3807\">Silverlight Compatible ASP.NET 2.0</a><li>ASP.NET AJAX, VB, & C#<li>.NET Framework 3.0 <li>Visual Studio 2005 & Expression Web Compatible<li><a href=\"http://www.discountasp.net/go/go.aspx?i=3808\">MS SQL 2005 w/ Real Time Backup Tool</a><li>3 Months FREE & FREE Setup</ul><a href=\"http://www.discountasp.net/go/go.aspx?i=3809\">Click Here to Learn More...</a>" },
	{ "which":"showcase", "title":"ComponentOne \"Sapphire\" for Silverlight", "markup":"Experience the next generation toolset for Microsoft Silverlight Development,<br>ComponentOne \"Sapphire\" for Silverlight.<br><br>ComponentOne \"Sapphire\" is about delivering the broadest toolset for rich, interactive user interfaces and stunning data visualizations.  Just like the toolsets offered in ComponentOne Studio Enterprise, ComponentOne \"Sapphire\" introduces the Silverlight toolset that you will love to use to create Rich Internet Applications.<br>Visit <a href=\"http://www.componentone.com/redirector/webredirector.aspx?redirectcode=SilverlightShowcaseFeature\">labs.componentone.com/sapphire</a> to get into the action!" },
//	{ "which":"video", "title":"ComponentOne \"Sapphire\" for Silverlight", "markup":"Experience the next generation toolset for Microsoft Silverlight Development,<br>ComponentOne \"Sapphire\" for Silverlight.<br><br>ComponentOne \"Sapphire\" is about delivering the broadest toolset for rich, interactive user interfaces and stunning data visualizations.  Just like the toolsets offered in ComponentOne Studio Enterprise, ComponentOne \"Sapphire\" introduces the Silverlight toolset that you will love to use to create Rich Internet Applications.<br>Visit <a href=\"http://labs.componentone.com/sapphire/\">labs.componentone.com/sapphire</a> to get into the action!" },
//	{ "which":"learn", "title":"Silverlight Hosting", "markup":"<span style=\"margin-left: 45px;\"><a href=\"http://www.discountasp.net/go/go.aspx?i=3899\"><img src=\"http://silverlight.net/themes/silverlight/images/ads/logo_silverlight_orKE.gif\" border=\"0\" width=\"200\" height=\"50\" /></a></span><br/><br/>DiscountASP.NET - Voted \"Best Web Host\" by asp.netPRO Magazine 3 Years Running ('05,'06,'07) and by Visual Studio for 2007<ul><li><a href=\"http://www.discountasp.net/go/go.aspx?i=3811\">Silverlight Compatible ASP.NET 2.0</a><li>ASP.NET AJAX, VB, & C#<li>.NET Framework 3.0 <li>Visual Studio 2005 & Expression Web Compatible<li><a href=\"http://www.discountasp.net/go/go.aspx?i=3812\">MS SQL 2005 w/ Real Time Backup Tool</a><li>3 Months FREE & FREE Setup</ul><a href=\"http://www.discountasp.net/go/go.aspx?i=3813\">Click Here to Learn More...</a>" },	
//	{ "which":"videos", "title":"Silverlight Hosting", "markup":"<span style=\"margin-left: 45px;\"><a href=\"http://www.discountasp.net/go/go.aspx?i=3900\"><img src=\"http://silverlight.net/themes/silverlight/images/ads/logo_silverlight_orKE.gif\" border=\"0\" width=\"200\" height=\"50\" /></a></span><br/><br/>DiscountASP.NET - Voted \"Best Web Host\" by asp.netPRO Magazine 3 Years Running ('05,'06,'07) and by Visual Studio for 2007<ul><li><a href=\"http://www.discountasp.net/go/go.aspx?i=3815\">Silverlight Compatible ASP.NET 2.0</a><li>ASP.NET AJAX, VB, & C#<li>.NET Framework 3.0 <li>Visual Studio 2005 & Expression Web Compatible<li><a href=\"http://www.discountasp.net/go/go.aspx?i=3816\">MS SQL 2005 w/ Real Time Backup Tool</a><li>3 Months FREE & FREE Setup</ul><a href=\"http://www.discountasp.net/go/go.aspx?i=3817\">Click Here to Learn More...</a>" },
//	{ "which":"whitepapers", "title":"Silverlight Hosting", "markup":"<span style=\"margin-left: 45px;\"><a href=\"http://www.discountasp.net/go/go.aspx?i=3901\"><img src=\"http://silverlight.net/themes/silverlight/images/ads/logo_silverlight_orKE.gif\" border=\"0\" width=\"200\" height=\"50\" /></a></span><br/><br/>DiscountASP.NET - Voted \"Best Web Host\" by asp.netPRO Magazine 3 Years Running ('05,'06,'07) and by Visual Studio for 2007<ul><li><a href=\"http://www.discountasp.net/go/go.aspx?i=3819\">Silverlight Compatible ASP.NET 2.0</a><li>ASP.NET AJAX, VB, & C#<li>.NET Framework 3.0 <li>Visual Studio 2005 & Expression Web Compatible<li><a href=\"http://www.discountasp.net/go/go.aspx?i=3820\">MS SQL 2005 w/ Real Time Backup Tool</a><li>3 Months FREE & FREE Setup</ul><a href=\"http://www.discountasp.net/go/go.aspx?i=3821\">Click Here to Learn More...</a>" },
	{ "which":"community", "title":"Clustered Windows / .NET Hosting", "markup":"<a href =\"http://www.mosso.com/?utm_source=silverlight.netFeaturedItem&utm_medium=Banner&utm_content=LogoLink\"><center><img src=\"/themes/silverlight/images/ads/mosso.gif\" border=\"0\"></center></a><br/><br/>Perfect for web developers: host unlimited sites using ASP, .NET 3.0, and MS SQL 2005. Includes business-class email, webmail, SAN storage, load-balancing, and firewalls. $100/mo. <a href =\"http://www.mosso.com/?utm_source=silverlight.netFeaturedItem&utm_medium=Banner&utm_content=TextLink\">Click here</a>." },
	{ "which":"forum:14", "title":"Clustered Windows / .NET Hosting", "markup":"<a href =\"http://www.mosso.com/?utm_source=silverlight.netFeaturedItem&utm_medium=Banner&utm_content=LogoLink\"><center><img src=\"/themes/silverlight/images/ads/mosso.gif\" border=\"0\"></center></a><br/><br/>Perfect for web developers: host unlimited sites using ASP, .NET 3.0, and MS SQL 2005. Includes business-class email, webmail, SAN storage, load-balancing, and firewalls. $100/mo. <a href =\"http://www.mosso.com/?utm_source=silverlight.netFeaturedItem&utm_medium=Banner&utm_content=TextLink\">Click here</a>." }
];
var myjsAdsSmall = [ 
	{ "url":"http://go.microsoft.com/fwlink/?LinkID=89241&clcid=0x409", "image":"get_silverlight_316x127.jpg", "xaml":"na" }	
];
var myjsAdsBig = [ 
	{ "url":"http://go.microsoft.com/fwlink/?LinkID=89241&clcid=0x409", "image":"get_silverlight_300x250.jpg", "xaml":"na" }	
];
var myslAdsSmall = [ 
	{ "url":"/learn", "image":"tout_ads_1.jpg", "xaml":"learnSM" },
	{ "url":"/blogs/MainFeed.aspx", "image":"tout_ads_2.jpg", "xaml":"subscribeSM" },	
	{ "url":"/forums", "image":"tout_ads_3.jpg", "xaml":"forumsSM" }	
];
var myslAdsBig = [ 
	{ "url":"/learn", "image":"tout_ads_1.jpg", "xaml":"learn" },
	{ "url":"/blogs/MainFeed.aspx", "image":"tout_ads_2.jpg", "xaml":"subscribe" },	
	{ "url":"/forums", "image":"tout_ads_3.jpg", "xaml":"forums" }	
];

function ShowSmallInsiteAd(notThisAd, cssclass, styleSL, styleJS)
{
	ShowInsiteAd(myjsAdsSmall, myslAdsSmall, 107, 127, false, "adsmall", notThisAd, cssclass, styleSL, styleJS);
}

// for backwards compatibility
function ShowAd(notThisAd, cssclass, style)
{
	ShowBigInsiteAd(notThisAd, cssclass, style);
}

function ShowBigInsiteAd(notThisAd, cssclass, style)
{
	ShowInsiteAd(myjsAdsBig, myslAdsBig, 250, 250, true, "ad", notThisAd, cssclass, style, "");
}

function ShowInsiteAd(jsAds, slAds, heightSL, heightJS, whitebox, adID, notThisAd, cssclass, styleSL, styleJS)
{
//**************
	var xamlAds = isSL;
//**************
	
	if (notThisAd == "")
		notThisAd = "showall";

	do {
		if (isSL)
			picked = PickAd(slAds);
		else
			picked = PickAd(jsAds);
	} while (picked.url.indexOf(notThisAd) != -1);
	
	if (xamlAds && picked.xaml != "na")
	{
		document.write("<div id=\"" + adID + "\" " + cssclass + " " + styleSL + ">");
		
			document.write("<div class=\"whiteboxtop316\"></div><div class=\"whiteboxmid316\">");

			document.write("<div id=\"xamlHost\">");

				document.writeln("<script type=\"text/javascript\">");
				document.write("createSilverlight({source: \"");
				document.write(themeDir + "../../xaml/stream.aspx?name=" + picked.xaml);
				document.write("\", parentElement: document.getElementById(\"xamlHost\"), id: \"");
				document.write(picked.xaml);
				document.write("\", properties: {width: \"289\", height: \"" + heightSL + "\", version: \"0.90\", enableHtmlAccess: true }, events: {}});");
				document.writeln("</script>");
	        
			document.write("</div>"); // xamlHost
			
			document.write("</div><div class=\"whiteboxbottom316\"></div>");
		
		document.write("</div>"); // ad
	}
	else
	{
		var width = (whitebox? 300 : 316);
		document.write("<div id=\"" + adID + "JS\" " + cssclass + " " + styleJS + ">");

			if (whitebox)
				document.write("<div class=\"whiteboxtop316\"></div><div class=\"whiteboxmid316\">");
			
			document.write("<a href=\"" + picked.url);
			document.write("\"><img src=\"" + themeDir + "images/ads/" + picked.image + "\" width=\"" + width + "\" height=\"" + heightJS + "\">");
			document.write("</a>");

			if (whitebox)			
				document.write("</div><div class=\"whiteboxbottom316\"></div>");
				
		document.write("</div>"); // ad			
	}	
}

function PickAd(ads)
{
	var pick = Math.floor(Math.random() * ads.length);
	return ads[pick];
}

function ShowPayingAd(which, cssclass, style)
{
	var ad = null;
	
	for (i=0; i<paidAds.length; i++)
	{
		if (paidAds[i].which == which)
		{
			ad = paidAds[i];
			break;
		}
	}
		
	if (ad == null)
		return;
	
	document.write("<div id=\"payad\" " + cssclass + " " + style + ">");
		document.write("<div class=\"whiteboxtop316\"></div><div class=\"whiteboxmid316\">");
		document.write("<div class=\"title\" style=\"padding-bottom: 10px;\">" + ad.title + "</div>");
		document.write("<div id=\"payadcontent\">");
			document.write(ad.markup);
		document.write("</div>");
		document.write("</div><div class=\"whiteboxbottom316\"></div>");
	document.write("</div>");
}

function OnXamlLeftButtonUp(sender, Args)
{
	var i = 0;
	do {
		if (myslAdsBig[i].xaml == sender.name)
			window.location.assign(myslAdsBig[i].url);
	} while (++i < myslAdsBig.length);
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function openWindow(sWin,sName,nWidth,nHeight) {
	x = (.5*screen.width) - (nWidth*.5);
	y = (.5*screen.height) - (nHeight*.5);	
	var props = 'width='+nWidth+','+'height='+nHeight+',' + 'screenX=' + x +','+'screenY='+ y + ','+'left='+ x +','+'top='+  y +',toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=0,scrollbars=0';
	oPop = window.open(sWin,sName,props);
}


///////////////////////////////////////////////////////////////////////////////
//
//  simpler code for just detecting silverlight
//
///////////////////////////////////////////////////////////////////////////////
function simpleDetection()
{
	var query = location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) 
	{
		if (parms[i].toLowerCase() == "nosl=1")
			return false;
		if (parms[i].toLowerCase() == "nosl=0")
			return true;
	}
	
//    alert('detected: ' + Sys.Silverlight.isInstalled("0.90.0"));

	return (Silverlight.isInstalled("0.90.0"));
}