function SetCookie (name,value,expires,path,domain,secure)
{
        document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookieVal (offset)
{
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
                endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        if( (document.cookie == null) || (document.cookie.length == null))
        {
                return null;
        }
        var i = 0;
        while (i < clen)
        {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break; 
        }
        return null;
}

function valueStrip(regSearch,features)
{
	var results =  features.match(regSearch);
	if (results != null) return results[2];
	else return 0;
}

function popper(theURL,winName,features) {
	var posWin = null;
	var gotIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;	
	var gotNS = (navigator.appName == 'Netscape') ? true : false;
	var gotNN6 = (gotNS && (parseInt(navigator.appVersion) >= 5)) ? true : false;
// REGULAR EXPRESSIONS TO STRIP OUT THE WIDTH AND HEIGHT VARS -----------------
	var widthMatch = /(width=)(\d+)/i;
	var heightMatch = /(height=)(\d+)/i;
	var scrollMatch = /(scrollbars=)([a-zA-Z0-9])/i;
	var numMatch = /\d+/;
	
	var width = valueStrip(widthMatch,features);
	var height = valueStrip(heightMatch,features);
	var scrollbars = valueStrip(scrollMatch,features);
	
	if (posWin!=null && !posWin.closed) posWin.close();
	
	if (gotIE) {
	var left = (screen.Width/2) - width/2;
	var top = (screen.Height/2) - height/2;
	posWin = window.open(theURL,winName,"scrollbars=0,left="+left+",top="+top+",width="+width+",height="+height+",scrollbars="+scrollbars);
	posWin.focus();
	}
	else if (gotNS && !gotNN6) {
	var left = (screen.availWidth/2) - width/2;
	var top = (screen.availHeight/2) - height/2;
	posWin = window.open(theURL,winName,"screenX="+left+",screenY="+top+",innerWidth="+width+",innerHeight="+height+",scrollbars="+scrollbars);
	posWin.focus();
	}
	else if (gotNN6) {
	var left = (screen.availWidth/2) - width/2;
	var top = (screen.availHeight/2) - height/2;
	posWin = window.open(theURL,winName,"screenX="+left+",screenY="+top+",width="+width+"px,height="+height+"px,scrollbars="+scrollbars);
	posWin.focus();
	}
	else {
	posWin = window.open(theURL,winName,"scrollbars=0,width="+width+",height="+height+",scrollbars="+scrollbars);
	posWin.focus();
	}
}

function popCheck(obj){
	if (!obj) {
		alert("Some content on CMT.com is displayed using pop-ups.  \n\nIf you're using a Pop-up Blocker, you'll need to permit pop-ups \nfrom CMT.com in order to view Videos, photos and other content on our site.");
	}
}

/* new flipbook js for popping flipbook media from external photo searches */
function popFlipMedia(fid, mid){
	pWin = window.open('/sitewide/apps/flipbook/index.jhtml?fid=' + fid + '&mid=' + mid,'flipbook' + fid,'width=748,height=500,scrollbars=0');
}
