var newwin;

function launchwin(winurl,winname,winfeatures,site,section_color,section)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
    var url = '';
    if (winurl != '') url = winurl + ((winurl.indexOf('?')!=-1)? "&": "?") + "site="+site+"&color="+section_color+"&section="+section;
	newwin = window.open(url,winname,winfeatures);
 	setTimeout('newwin.focus();',250);
}
function openSettings()
{
var pop = window.open('/common/mynick/autologin/editMyNick.jhtml?editMyNick=true&Destination=/index.jhtml',"Settings","width=180,height=250,scrollbars=yes");
}

function openBumper(wBumper, advertiser, onair, customBumper, customHeight, newWindow) {
	var bumperUrl = "/common/bumpers/bumperFrameset.jhtml?";
	var fullPageBumperUrl = "/common/bumpers/fullpage/index.jhtml?";
	var bumperParam = "wBumper";
	var targetUrlParameter = "advertiser";
	onair = onair != null && onair;
	
	switch(wBumper) {
		case "external" : {
			bumperUrl = "/common/bumpers/go.jhtml?";
			bumperUrl += customBumper == null ? "" : ("bumper=" + escape(customBumper) + "&");
			bumperUrl += customHeight == null ? "" : ("bumperHeight=" + customHeight + "&");
			bumperUrl += "isInHouse=false" + "&";
			targetUrlParameter = "destination";
			break;
		} case "fullPage" : {
			bumperUrl = fullPageBumperUrl;
			targetUrlParameter = "destination";
			break;
		} case "paysite" : {
			break;
		} case "grown-ups" : {
			break;
		} case "launchpad" : {
			break;
		} case "sponsor" : {
			break;
		} default : {
			wBumper = "sponsor";
			break;
		}
	}

	var bumperHref = bumperUrl +
					 bumperParam +"="+ wBumper +"&"+
					 targetUrlParameter +"="+ escape(advertiser);

	if(onair) bumperHref += "&onair_landing=true";
	if(onair && wBumper == "external") {
		bumperHref = fullPageBumperUrl + targetUrlParameter +"="+ escape(bumperHref);
	}

	if(newWindow) {
		window.open(bumperHref);
	} else {
		window.location.href = bumperHref;
	}
}

function openNewBumper(wBumper, advertiser, onair, customBumper, customHeight) {
	openBumper(wBumper, advertiser, onair, customBumper, customHeight, true);
}


function pageUrl() {
	return location.href;
}

//start nickVision functions
var nickVision = new Object();
nickVision.start = nickVision_start;
nickVision.stop = nickVision_stop;

function nickVision_start() {  
 
}

function nickVision_stop() {  
	 
} 
//end nickVision functions

function popBumper(bumper,advertiser){
	//alert( bumper + "?advertiser=" + escape(advertiser));
	window.location.href=bumper + "?advertiser=" + escape(advertiser);
}

function makehomepage() {
	var title = "Nick.com";
	var url = "http://www.nick.com/";
	if(window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	} else if(document.all) {
		// add fav in IE
		if(document.body.style && document.body.style.behavior) {
			document.body.style.behavior = 'url(#default#homepage)';
			document.body.setHomePage(url);
		} else if(window.external) {
			window.external.AddFavorite(url , title);
		}
	}
}

//used from the toolbar to update users registration with secrect question.
function gothere() {
	var destination = "<valueof bean=\"/OriginatingRequest.RequestURI\"/>";
	var queryString = "?" + "<valueof bean=\"/OriginatingRequest.queryString\"/>";
	location.href = "/registration/updateAccount.jhtml?destination=" + destination + escape(queryString);
}

function getSessionId() {
	return getCookie("JSESSIONID");
}

function getUsername() {
	return getCookie("loggedInScreenName");
}

function getCookie(name) {
	if(name == null || name == "") return null;

	var cook = document.cookie.toString();
	if(cook.length > 0) {
		var begin = cook.indexOf(name+"=");
		if(begin != -1) {
			begin += name.length+1;
			var end = cook.indexOf(";", begin);
			if(end == -1){
			   end = cook.length;
			}
			return unescape(cook.substring(begin, end));
		}
	}
	return null;
}

function doBumper(whatLink, bumpered) {
	if(bumpered == "true") {
		openBumper("fullPage", whatLink);
	} else {
		document.location.href = whatLink;
	}
}
