if (typeof(prependDomain) == "undefined") {
	prependDomain = "";
}

function nullit() {
	return true;
}
//window.onerror = nullit;


function MakeArray(n){
   this.length = n
   for (var i = 1; i<=n; i++) {
      this[i] = new Image()
   }
   return this;
}

function omOver(name,number){
	if (document.images){
      name.src = over[number].src;
   }
}

function omOut(name,number){
	if (document.images){
    	name.src = out[number].src;
   }
}

if (document.images) {
	braille_out = new MakeArray(12);
	braille_over = new MakeArray(12);
	imgLoc = new Array ("","lyl_1","lyl_2","lyl_3","lyl_4","dyl_1","dyl_2","dyl_3","dyl_4","dyl_1","dyl_2","dyl_3","dyl_4")
	imgLoc2 = new Array ("","lyl_a1","lyl_a1","lyl_a1","lyl_a1","dyl_a1","dyl_a1","dyl_a1","dyl_a1","dyl_a1","dyl_a1","dyl_a1","dyl_a1")
	for (imgX=1;imgX<13;imgX++){
	braille_out[imgX].src = "/sitewide/images/icn_braille_" + imgLoc[imgX] + ".gif";
	braille_over[imgX].src = "/sitewide/images/icn_braille_" +imgLoc2[imgX] + ".gif";
	}
}

function brailleOver(name,number){
	if (document.images){
    	name.src = braille_over[number].src;
	}
}
function brailleOut(name,number){
	if (document.images){
    	name.src = braille_out[number].src;
	}
}


function launchRSN(varStationID){
	var tuner = false;
	tuner = window.open(prependDomain + '/mtvradio/radiolaunch.jhtml?oparam=radio&serviceSubjectID='+ varStationID + '&A='+ varStationID ,'TUNERLogin','width=700,height=312,toolbar=no,resizable=no,scrollbars=no');
	tuner.focus();
	// popCheck(tuner);
}


function launchRSNu(url){
	var tuner = false;
	tuner = window.open(url,'TUNERLogin','width=700,height=312,toolbar=no,resizable=no,scrollbars=no');
	tuner.focus();
	//popCheck(tuner);
}

function popCheck(obj){
	if (!obj) {
		alert("Some content on MTV.com is displayed using pop-ups.  \n\nIf you're using a Pop-up Blocker, you'll need to permit pop-ups \nfrom MTV.com in order to view Videos, photos and other content on our site.");
	}
}

/*
 * @description	Opens the sitewide flipbook player.
 * @param fbKey Flipbook ID or URL.
 * @param obj, Object, used to customize the flipbook skin and values.
 */
function popFlip(fbKey, obj){
	var fbArgs = "";
	for (var p in obj){
		fbArgs += "&" + p + "=" + obj[p];
	}

		var lfArg;

		// for fbml urls
			fullLoc = window.location.toString();
			if ((typeof browserManager != "undefined") && (fullLoc.indexOf('#') > 0)) {
				lfArg = "&launchedFrom=" + fullLoc.substr(fullLoc.indexOf('#') +1, fullLoc.length).split("?")[0];
			} else {
				lfArg = "&launchedFrom=" + window.location.pathname;
			}

	      
	var pWin = false;
	if (fbKey.indexOf("fid=")>=0) {
		pWin = window.open('/sitewide/flipbook/?'+fbKey+fbArgs+lfArg,'flipbook','width=747,height=505,scrollbars=no');

	}
	else {
		var flipLoc  = fbKey.split("?");
		flipLocPath  = flipLoc[0].split("index.jhtml");
		var flipLocFull  =  flipLocPath[0];
		if (flipLoc[1] != "" && flipLoc[1] != null) flipLocFull += "&" + flipLoc[1];
		pWin = window.open('/sitewide/flipbook/?pf='+flipLocFull+fbArgs+lfArg+'','flipbook','width=747,height=505,scrollbars=no');

	}
	// popCheck(pWin);

}

function popFlipMedia(fid, mid){
	pWin = window.open('/sitewide/flipbook/?fid=' + fid + '&mid=' + mid,'flipbook' + fid,'width=747,height=505,scrollbars=no');
}

function popFlipU(url){
	pWin = window.open(url,'flipbook','width=747,height=505,scrollbars=no');
}

function popFlipById(fid){
	popFlip('fid=' + fid);
}

function dropIt(layername,layerstatus){
	return true;
}

function genPop(loc,wName,attr){
	var pWin = false;
	pWin = window.open(loc,wName,attr);
	popCheck(pWin);
}

function touppPop(pp){
	var pWin = false;
	if (arguments.length == 1) {
		pWin = window.open(prependDomain + '/sitewide/mtvinfo/privacy.jhtml','Privacy','width=605,height=400,resizable,scrollbars');
	}
	else {
		pWin = window.open(prependDomain + '/sitewide/mtvinfo/terms.jhtml','TOS','width=605,height=400,resizable,scrollbars');
	}
	popCheck(pWin);
}

function adspecsPop(pp){
	var pWin = false;
	pWin = window.open('/asm/adspecs/contact.jhtml','AdSpecs','width=605,height=400,resizable,scrollbars');
	popCheck(pWin);
}

function popQT(url){
	url = "/sitewide/videoplayer/qtplayer.jhtml?" + url;

	var pWin = false;
	window.open(url,"qtplayer","width=320, height=240");
	popCheck(pWin);
}

function openSendFriend(loc,title,template) {
	var template = template;
	var loc = loc;
	var title = title;
	var popped_page = "/sitewide/droplets/emailfriend.jhtml?page="+loc+"&title="+title+"&mode=form&template=" + 	template;
	
	window.open(popped_page, "mailer", "width=420,height=350,resizable,scrollbars");
}

function MakeArray(n){
   this.length = n
   for (var i = 1; i<=n; i++) {
	  this[i] = new Image()
   }
   return this;
}


function imgFlip(imageName,imageSrc) {
  if (document.images)
    document.images[imageName].src = eval(imageSrc + ".src");
}


function toggleFlash(show) {
	if (IE4){
		document.all.flashLayer.style.visibility = show;
	}
	if (NS4){
		document.flashLayer.visibility=show;
	}
	if (NS4 && (show=="visible")){
		document.flashLayer.top = "0";
	}
	if (NS6 && (show=="hidden")){
		document.getElementById("flashLayer").style.top = "-1000px";
	}
	if (NS6 && (show=="visible")){
		document.getElementById("flashLayer").style.top = "0px";
	}
}

function launchEssentials()
{
    var url;
    var win;
    var winWidth = 952;
    var winHeight = 600;
    var msg = "A PopUp blocker has blocked the Essentials window from launching.\nPlease add MTV.com to your safe list.";

    if (screen.width <= 800) {
        winWidth = 780;
        winHeight = 500;
    }

    url = "/partners/essentials/popflash.jhtml?width=" + winWidth + "&height=" + winHeight;

    win = window.open(url, "essentials", "width=" + winWidth + ",height=" + winHeight);
    if (win) {
        win.focus();
    } else {
        alert(msg);
    }

    self.location.href = "/partners/essentials/?autolaunch=false";
}




/**
  * Set, Get, and Delete Cookie utils
  *
  */
function GetCookieUtil (name) {
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if (startOfCookie != -1) {
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}
	return result;
}

function SetCookieUtil (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "; path=/") +
	((domain) ? "; domain=" + domain : "; domain="+document.location.hostname) +
	((secure) ? "; secure" : "");
}

function DeleteCookieUtil (name,path,domain) {
	if (GetCookieUtil(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function popAutoG(url){
	window.open(url,"autoWin","width=750,height=610,scrollbars=no");
}

function popVerizonG(url){
	window.open(url,"autoWin","width=550,height=460,scrollbars=no");
}
function popVerizonGAddHeader(url){
        url = 'http://' + url;
        popVerizonG(url);
}

// Generic Pop Window //
var win = null;
function genPopWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

// CheetahMail Newsletter Signup //
function popCheetah() {
	genPopWindow("http://ebm.cheetahmail.com/r/regf2?aid=409502673&n=102&a=0", "cheetah", 690, 600, "yes");
}

//url param util
ParseUrlEncodedString = function (str,param){
	if (!str)
		return null;
	re = new RegExp("(^|[?&])" + param + "=([^&=]*)(&|$)?","i")
	if (str.match(re))
		return RegExp.$2
	return null;
}

// returns a url param value from the querystring 
getUrlParam = function (param, sDefValue){
	var queryStr = document.location.search;
	if (!queryStr) return sDefValue; // if query string is empty return 
	sRet=ParseUrlEncodedString(queryStr,param);
	return (sRet==null ? sDefValue : sRet);
}

function legacyPopup(URL){
	window.open(URL,'legacyPop','width=764,height=600,scrollbars');
}

