var ns =(uBN=="Netscape")?true:false;
var ns5=(uBN=="Netscape"&&uBV=="5.0")?true:false;
var ie4=(uBN=="MSIE"&&uBV!="5.0")?true:false;
var iepc=(uBN=="MSIE"&&uOS=="Windows")?true:false;
var aol =(uBN=="AOL")?true:false;
var aol5 =(uBN=="AOL"&&uBV!="5")?true:false;
var aol6 =(uBN=="AOL"&&uBV!="6")?true:false;
var ns6 = (navigator.userAgent.toLowerCase().indexOf('gecko') != -1);
var ie = ((navigator.appName=="Microsoft Internet Explorer") && ((parseInt(navigator.appVersion)) >= 4));
var ns4 = ((navigator.appName=="Netscape") && ((parseInt(navigator.appVersion)) >= 4) && ((parseInt(navigator.appVersion)) < 5));
var mac = ((uBN=="MSIE" || uBN=="Netscape") && (navigator.userAgent.toLowerCase().indexOf('mac') != -1))?true:false;

/* Opens the Media Player window */
function openMediaPlayer(winName, genre, channel, source, target) {

	var sourceString = "";
	
	//setup source if exists
	if(source != null && source.length >  0) {
		sourceString = "source=" + source;	
	}
	
	//setup url
	var url = "/servlet/MediaPlayer?activity=expand&streamNumber=" + channel + "&" + sourceString;
	var features = "menubar=no,locationbar=no,status=no,resizable=yes,height=550,width=650,screenX=10,screenY=10,left=10,top=10";
	
	//determine target media player page if requested - default is selection screen
	if(target == "register") {
		url = "/servlet/MediaPlayerRegistration?" + sourceString;
	} else if(target == "guestlogin") {
		url = "/servlet/MediaPlayer?activity=selectLoginType&type=guest&" + sourceString;
	} else if(target == "sublogin") {
		url = "/servlet/MediaPlayer?activity=selectLoginType&type=subscriber&" + sourceString;
	}

	var newWin = window.open(url, "FullMediaPlayer", features);
	return;
}

/* Opens the Email Update window with the input form */
function openEmailSignup(target) {
	var win = window.open(target, "email_updates", "menubar=no,locationbar=no,status=no,resizable=yes,height=200,width=400");
	return;
}

/* Opens the Media Player window */
/** NOT YET IMPLEMENTED **/
/*function launchPlayer(stream) {
	
	var url = "/servlet/MediaPlayer?stream=" + stream;
	var features = "menubar=no,locationbar=no,status=no,resizable=yes,height=550,width=650,screenX=10,screenY=10,left=10,top=10";
	var newWin = window.open(url, "FullMediaPlayer", features);

	return;
}*/

/* Opens new window */
function pop(url,name,h,w,s,t,m,r){
	var wWin = null;
	if(uBN=="MSIE" && uOS=="Macintosh"){r = "no"};
	if(document.location.href.substring(0,5) == "https"){
		name="https";
	}
	if(aol){
		wWin = window.open(url,name,"height="+h+",width="+w+"scrollbars="+s+",toolbar="+t+",menubar="+m+",locationbar=no");

		//wWin.resizeTo(w,h);

		wWin.focus();
	} else {
		x=(screen.availWidth-w);
		y=(screen.availHeight-h);
		if (name.document) {
			name.document.location.href=url;
		} else {
			wWin=window.open(url,name,"height="+h+",width="+w+",scrollbars="+s+",toolbar="+t+",menubar="+m+",resizable="+r+",status=yes,location=no,screenX="+x/2+",screenY="+y/2+",left="+x/2+",top="+y/2);
			//wWin.resizeTo(w,h);
			wWin.focus();
		}
	}
}

/* Opens EmailAFriend Window */
function popEmailWindow(szTitle,szURL,szPageName) {
	var wEmailWin = null;
	var nWidth = 552;
	var nHeight = 400;

	var szFeatures = "menubar=no,resizable=no,scrollbars=no,toolbar=no,height="+nHeight+",width="+nWidth;
	var szBaseURL = "/servlet/ContentServer?pagename=Sirius/EmailToFriend&c=Article&cid=1026142020450";
	var szWinURL = szBaseURL + "&p1=" + escape(szTitle) + "&p2=" + escape(szURL) + "&p3=" + escape(szPageName);
	wEmailWin = window.open(szWinURL,"EmailWin",szFeatures);
	wEmailWin.focus();

	return;

}

/**
 * Pops open a new window for email to a friend.
 * This method adds the additional decrypt flag to indicate whether or not the
 * URL for the email is encrypted or not.
 *
 * decrypt = true for encryption/decryption
 */
function popEmailWindow(szTitle,szURL,szPageName, decrypt) {
	var nWidth = 552;
	var nHeight = 400;
		
	var szFeatures = "menubar=no,resizable=no,scrollbars=no,toolbar=no,height="+nHeight+",width="+nWidth;
	var szBaseURL = "/servlet/ContentServer?pagename=Sirius/EmailToFriend&c=Article&cid=1026142020450";
	var szWinURL = szBaseURL + "&p1=" + escape(szTitle) + "&p2=" + escape(szURL) + "&p3=" + escape(szPageName) + "&decrypt=" + decrypt;
	wEmailWin = window.open(szWinURL,"EmailWin",szFeatures);
	wEmailWin.focus();
	
	return;
		
}

/* Opens a new window for the Single Stream Media Player */
function openSingleStreamPlayer(stream) {

	var width = 552;
	var height = 350;
	
	if (mac) {
		width = 540;
		height = 335;
	}

	var url = "/servlet/SingleMediaPlayer?stream=" + escape(stream);
	var windowName = "SIRIUS_Single_Stream_Player";
	var features="menubar=no,locationbar=no,status=no,resizable=no,height=" + height + ",width=" + width;
	var newWin = window.open(url,windowName,features);
	return;
}

/* View BackStageAsset window */
function viewBackstageAsset(assetId) {

	var url = "/servlet/ContentServer?pagename=Sirius/Page&c=BackStageAsset&cid=" + assetId;
	var features = "menubar=no,locationbar=no,status=no,resizable=yes,height=400,width=400";
	var newWin = window.open(url,"BackStageAsset",features);

	return;
}

/* View Slideshow window */
function viewSlideShow(collectionId) {

	var url = "/servlet/ContentServer?pagename=Sirius/Page&c=Collection&cid=" + collectionId;
	var features = "menubar=no,locationbar=no,status=no,resizable=yes,height=390,width=390";
	var newWin = window.open(url,"Collection",features);

	return;
}

// Set cookie SIRIUS_CAMPAIGN, if any
var expires = new Date();
expires.setTime(expires.getTime() + (30*24*60*60*1000));
var campaignCookie = getParaValue("source");

if (campaignCookie) {
	setCookie("SIRIUS_CAMPAIGN", campaignCookie, null, "/", expires.toGMTString());
}

function getParaValue(paraName) {
	var searchString = location.search;
	
	if (searchString == null)
		return null;
		
	var fields = searchString.substring(1).split("&");
	for (var i = 0; i < fields.length; i++) {
		tmp = fields[i].split("=");
		if (tmp[0] == "source") {
			if (typeof(tmp[1]) == "undefined")
				return null;
			var sourceVal = unescape(tmp[1]);
			var validChars = "abcdefghijklmnopqrstuvwxyz0123456789";
			var letter = sourceVal.charAt(0).toLowerCase();
			if (validChars.indexOf(letter) == -1)
				return null;
			else
				return sourceVal;
		}		
	}
	return null;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//	setCookie() - Create a cookie with the specified name and value.
//  Args:
//      sName                       - name of the cookie
//      sValue                      - value of the cookie
//      sDomain[OPTIONAL]           - Setting the domain of the cookie allows pages on a domain made up
//                                      of more than one server to share cookie information
//      sPath[OPTIONAL]             - Setting a path for the cookie allows the current document to share cookie
//                                      information with other pages within the same domain
//      sExpires[OPTIONAL]          - Setting no expiration date on a cookie causes it to expire when
//                                      the browser closes. If you set an expiration date in the future, the cookie
//                                      is saved across browser sessions. If you set an expiration date in the past,
//                                      the cookie is deleted. Use GMT format to specify the date.
////////////////////////////////////////////////////////////////////////////////////////////////////////
function setCookie(sName, sValue, sDomain, sPath, sExpires) {
	if(sName) {
		var sCookie = sName + "=";
		if(sValue)
			sCookie += escape(sValue);
		if(sPath)
		   sCookie += "; path=" + sPath;
		if(sDomain)
			sCookie += "; domain=" + sDomain;
		if(sExpires)
			sCookie += "; expires=" + sExpires;
		document.cookie = sCookie;
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//	getCookie() - Retrieve the value of the cookie with the specified name.
//  Args:
//  sName                       - name of the cookie
////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(cookieName) {
	var cookieArray = document.cookie.split("; ");
	for(k in cookieArray)
	{
		var cookie = cookieArray[k].split("=");
		if (cookieName == cookie[0])
			return unescape(cookie[1]);
	}
	return null;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//	deleteCookie() - Deletes the cookie with the specified name.
//  Args:
//  sName                       - name of the cookie
////////////////////////////////////////////////////////////////////////////////////////////////////////
function deleteCookie(cookieName, path, domain)
{
	setCookie(cookieName, null, domain, path, "Thu, 01-Jan-70 00:00:01 GMT")
}

function getSourceUrl(instring) {
	var campaign_code = getCookie("SIRIUS_CAMPAIGN");	
	if (campaign_code != null) {
		if (instring.indexOf("?") == -1)
			instring += "?source=" + campaign_code;
		else
			instring += "&source=" + campaign_code;
	}
	return instring;
}

function getSIDUrl(instring) {
	var sidVal = getCookie("SIRIUS_VISITOR_ID");	
	if (sidVal != null) {
		if (instring.indexOf("?") == -1)
			instring += "?sid=" + sidVal;
		else
			instring += "&sid=" + sidVal;
	}
	return instring;
}

function getSourceAndSIDUrl(instring) {
	var campaign_code = getCookie("SIRIUS_CAMPAIGN");	
	if (campaign_code != null) {
		if (instring.indexOf("?") == -1)
			instring += "?source=" + campaign_code;
		else
			instring += "&source=" + campaign_code;
	}
	var sidVal = getCookie("SIRIUS_VISITOR_ID");	
	if (sidVal != null) {
		if (instring.indexOf("?") == -1)
			instring += "?sid=" + sidVal;
		else
			instring += "&sid=" + sidVal;
	}
	return instring;
}

/**
 * opens the SIRIUS Direct site and passes in the users source code if present
 */
function siriusDirect() {
	var url = getSourceUrl("https://home.sirius.com/webDUWI/HomePage.aspx");
	window.location = url;
}

// Rollovers
function preload(name,dir) {
	eval(
		name + "_on = new Image();" + 
		name + "_on.src = \"" + dir + name + "_on.gif\";" + 
		name + "_off = new Image();" + 
		name + "_off.src = \"" + dir + name + "_off.gif\";"
	);
}
function loadImage(name, img) {
	if (document.images) {
		document.images[name].src = img.src;
	}
}
