var env = new env_settings();
var prevList = getCookie('cnet_newsVideo');
var prefs;
var layerRef, styleRef;
var prefPage;

function opener(){
// v.2: Removed RealOne closing of window.
	var ua = window.navigator.userAgent; 
//	if (prefPage=="no") {
		// v.2: no more flash!
		//setnsFlash();
		//flashMe(); 
		//setVolLevel();
//	}
}

function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);  // Get query string.
    var pairs = query.split(",");              // Break at comma.
    for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');       // Look for "name=value".
	if (pos == -1) continue;               // If not found, skip.
	var argname = pairs[i].substring(0,pos);  // Extract the name.
	var value = pairs[i].substring(pos+1); // Extract the value.
	args[argname] = unescape(value);          // Store as a property.
    }
    return args;                               // Return the object.
}

var args = getArgs();
var isPref = args.pref;

// If 'wm' or 'rm' is passed as the player type in the location string, skip preferences, go right to video.
var pCont = false;
var playerType = args.playtype;
if ((playerType == "wm") || (playerType == "rm")) {
	pCont = true;
	isPref = "no";
}

function getHtml() {
	var prevList = getCookie('cnet_newsVideo');

	if ((env.other) && (pCont != true)) {
		prefPage="yes";
		document.write(pref_html());
		Rollup();
	} else {
		if (((prevList == null) || (isPref=="yes")) && (pCont != true)){	
				prefPage="yes";
				document.write(pref_html());
			
  		} else { 
			if (env.good_default || env.good_ns) {
				prefPage="yes";
				document.write(contentscreen());
			} else if (env.ideal_env){
				prefPage="no";
				// Let's just call the standard controls
				//reg_html_setup();
				//setLayer();
				document.write(contentscreen());
			} 
		}
	}
	

}


function contentscreen() {
var vidObj;
var mPlayer = getCookie('cnet_newsVideo');

//////////////////////////////////////////////////
// If 'wm' is passed as the player type in the location string, default to windowsmedia.
// If 'rm' is passed as the player type in the location string, default to realplayer.
var args = getArgs();
playerType = args.playtype;
if (playerType == "wm") {
	mPlayer = "hiasf";
} else if (playerType == "rm") {
	mPlayer = "hiram";
}
///////////////////////////////////////////////////

if ((mPlayer=="hiasf") || (mPlayer=="loasf")) {
		vidObj = (asf_default_embed());
	} else if ((mPlayer=="hiram") || (mPlayer=="loram")) {
		vidObj = (ram_default_embed());
	}

return(vidObj);
}



function env_settings()
{
	// base attributes ...
	this.u_agent = navigator.userAgent.toLowerCase();
	this.b_name = navigator.appName.toLowerCase();
	this.int_ver = parseInt( navigator.appVersion );
	this.float_ver = parseFloat( navigator.appVersion );
	
	// not a base attribute, but I use this in different areas ...
	this.opera = ( this.u_agent.indexOf( "opera" ) != -1 );
	
	// platforms ...
	this.is_win = ( ( this.u_agent.indexOf( "win" ) != -1 ) && ( this.u_agent.indexOf( "3.1" ) == -1 ) );
	this.is_mac = ( this.u_agent.indexOf( "mac" ) != -1 );
	this.is_linux = ( this.u_agent.indexOf( "linux" ) != -1 );
	
	// browser/platform configurations ...
	this.good_ie = ( ( this.b_name.indexOf( "explorer" ) != -1 ) && ( this.int_ver >= 4 ) && ( !this.opera ) );
	this.good_ns = ( ( this.b_name.indexOf( "netscape" ) != -1 ) && ( this.int_ver >= 4 ) && ( this.int_ver <= 6 ) );
	this.ns6 = ( ( this.b_name.indexOf( "netscape" ) != -1 ) && ( this.int_ver >= 5 ) );
	this.good_default = ( ( this.is_linux ) || ( this.is_mac ) || ( !this.good_ie && this.int_ver >= 5 ) );
	this.other = ( this.opera );
	
	this.ideal_env = ( this.is_win && this.good_ie );
}

function setLayer() {
	if (env.good_ns) {
		layerRef = "document.layers";
    	styleRef = "";
	} else if (env.good_ie) {
		layerRef = "document.all";
    	styleRef = ".style";	
	}
}

function getCookie(Name)

	{
	var search = Name + "="
		if (document.cookie.length > 0) { // if there are any cookies//
		offset = document.cookie.indexOf(search)
			if (offset != -1) {
			// if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie val
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function setCookie(name, myPref) {
		settingPrefs="";
		var today = new Date(); 
		today.setFullYear(2020); 
		document.cookie = name + "=" + escape(myPref) + ";expires=" +       today.toGMTString(); 
		if (env.other) {
			launchPlayList();
		} else {
			var myLoc = (location.pathname);
			var trunc = myLoc.replace("\?pref=yes" , "");
			location.replace(trunc);
		}
}	

function pref_help() {
		//stop_video();
		var str = "http://" + (location.hostname) + (location.pathname);
		str += "?pref=yes";
		location.replace(str);
}

var radionum;
var savedPrefs = getCookie("cnet_newsVideo");

function goBack() {
	//savedPrefs = getCookie("cnet_newsVideo");
	if(savedPrefs != null) {
		var myLoc = (location.hostname) + (location.pathname);
		var trunc = myLoc.replace("\?pref=yes" , "");
		location.replace(trunc);
	} else {
		alert("Please select a player and bitrate first.");
		return false;
	}
}


function setVolLevel() {
	var mPlayer = getCookie('cnet_newsVideo');
	if ((mPlayer=="hiasf") || (mPlayer=="loasf")) {
		//set volume wm
		setVolume(7,3);
	} else if ((mPlayer=="hiram") || (mPlayer=="loram")) {
		//set volume rm
		setVolume(4,3);
	}
}

function reg_html_setup() {
	var mPlayer = getCookie('cnet_newsVideo');
	document.write(reg_html());
	if ((mPlayer=="hiasf") || (mPlayer=="loasf")) {
		document.write(wm_imgMap());
	} else if ((mPlayer=="hiram") || (mPlayer=="loram")) {
		document.write(rm_imgMap());
	}
}

function launchPlayList() {
	var mPlayer = getCookie('cnet_newsVideo');

	src = "1604";
	src += "-";
	src += "2";
	src += "-";
	src += maceAssetId;
	src += "-";
	if (mPlayer=="hiasf") {
		src += "2";
		src += ".asx"
	} else if (mPlayer=="loasf") {
		src += "1";
		src += ".asx"
	} else if (mPlayer=="hiram") {
		src += "4";
		src += ".ram"
	} else if (mPlayer=="loram") {
		src += "3";
		src += ".ram"
	}
	window.open(src);
}

function sendThis() {
	var str;
	str = "<a href=\"";
	str += "mailto:?subject=News Video:";
	str +=  maceTitle;
	str += "&body=";
	str += self.location;
	str += "   (The entire URL must be placed in the address line of your browser for this video to play)  ";
	str += "\" class=\"zd\">";
	return (str);
}

