// JavaScript Document
function loaddiv(ie8affiliateid,clickid){
	window.newpopdiv = document.createElement('div');
	var currentUrl=window.location.href;
	var html="";
	html='<div id=\"tmn_faderbox\" onclick=\"tmn_popgbox(2);\" style=\"background-color:#000000; display:none; position:fixed; .position:absolute;  z-index:500; left:0; top:0; height:100%; .height:1500px; width:120%; _width:3000px;\">';
	html+='</div><div id=\"tmn_popcontent2\"  style=\"display:none;background-color:none;border:0 none;position:absolute;z-index:501; \"border=\"0\" usemap=\"#close\" alt=\"IE 8 download\">';
	html+='<div style=\"cursor:arrow; height:385px; width:560px;\">';
	html+='<div style=\"background-image:url(\'http://www.toptenreviews.com/i/rev/misc/IE8-Popup.jpg\'); background-repeat:no-repeat;margin-top:15px; height:375px; width:543px;\">';
	html+='<div style=\"float:right;padding-top:297px;padding-right:25px;\"><a href=\"http://www.anrdoezrs.net/click-'+clickid+'-10760544\"><img src=\"http://www.toptenreviews.com/i/rev/misc/ie8download.gif\" border=\"0\"/></a></div></div>';
	html+='<div style=\"cursor:ponter; float:right; background:transparent; margin:-390px 0px 0px 0px;\" onclick=\"tmn_popgbox(2);\">';
	html+='<span style=\"width:35px; height:35px;display:inline-block;;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://www.toptenreviews.com/i/rev/site/popup-close-button.png\', sizingMethod=\'scale\');\"><img style=\"_display:none;\" src=\"http://www.toptenreviews.com/i/rev/site/popup-close-button.png\" /></span>';
	html+='<div id=\"tmn_ie8widgetcall\" style=\"display:none;\">';
	html+="<img src='http://api.toptenreviews.com/widgets/keyword-density-checker/af_widget.php?url=" + currentUrl + "&a_aid=" + ie8affiliateid + "&keywords=&stop=&sub_id=&width=1&height=1&cat=&ad_number=' style='display:none;'/>";
	html+='</div></div>';
	newpopdiv.innerHTML=html
	setTimeout('document.body.appendChild(window.newpopdiv)',2000);
}

function detectBrowser(ie8affiliateid,clickid){
	if(ie8affiliateid!=null && clickid!=null){
		if(!(readCookie('ie8popper'))){
			if(!userexpiredate) {
				var userexpiredate=1;
			}
			createCookie('ie8popper','read',userexpiredate);
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
				var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
				if (ieversion<8){
					loaddiv(ie8affiliateid,clickid);
					setTimeout("tmn_popgbox(3, 'tmn_popcontent2', 543,375,-1, true)", 5000);
				}
			}
		}
	}
}

//graybox stuff
function fadeBox(divName, endOpac){
	var grayBox = document.getElementById(divName);
    if(!grayBox) {
        window.gbinterval = clearInterval(window.gbinterval);
        return false;
    }
	var i = parseFloat(grayBox.style.opacity);
	var step = 0.1;
	if(endOpac){
		if(i < endOpac){
			i += step;
			document.getElementById(divName).style.filter = "alpha(opacity=" + i*100 + ")";
			document.getElementById(divName).style.opacity = i;
		}else{
            window.gbinterval = clearInterval(window.gbinterval);
        }
	}else{
		if(i > endOpac){
			i -= step;
			document.getElementById(divName).style.filter = "alpha(opacity=" + (i*100) + ")";
			document.getElementById(divName).style.opacity = i;
		}else {
			window.gbinterval = clearInterval(window.gbinterval);
			showhidediv(divName,2);
		}
	}
}

function showhidediv(divname,type){
	box=document.getElementById(divname);
	box.style.display=(type==1) ? "block":"none";
}

//use this for a greybox fadeout
function smokeScreen(divId,endOpac){
    var topscroll=(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    if(endOpac>0){
        // hide scroll bars
        windowscroll=document.getElementsByTagName('html')[0];
        windowscroll.style.overflow="hidden";
        document.documentElement.scrollTop=topscroll;
        //initialize opacity
        box=document.getElementById(divId);
        box.style.opacity=0;
        box.style.filter="alpha(opacity=0)";
        //make div visible
        showhidediv(divId,1);
    }
    else{
        // put back the scrolls
        windowscroll=document.getElementsByTagName('html')[0];
        windowscroll.style.overflow="auto";
        // and for safari and chrome
        document.body.scrollTop += 1;
        document.body.scrollTop -= 1;
        document.documentElement.scrollTop=topscroll;
    }
    // fade in/out
    window.gbinterval=setInterval("fadeBox('"+divId+"',"+endOpac+")",25);
}
function spotLight(highlightId,smokeScreenId,highlightElementHeight,endOpacity){
    if(endOpacity>1) endOpacity = 1;
    else if(endOpacity<0) endOpacity = 0;
    var height = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
    var eTop = document.getElementById(highlightId).offsetTop;
    var scrollLoc = eTop + (highlightElementHeight - height)/2.0;
    if(scrollLoc<0) scrollLoc = 0;
    smokeScreen(smokeScreenId,endOpacity);
    document.getElementById(smokeScreenId).style.top = scrollLoc+'px';
    document.body.scrollTop = scrollLoc;
    document.documentElement.scrollTop  = scrollLoc;
}
//greybox popper
window.grayBoxLoading = false;
function tmn_popgbox(type,desc,width,height,popHeadCode,divpop){
    if(typeof(divpop) == "undefined"){
        divpop = false;
    }
    if(type == 2 && typeof(window.popperBox) != 'undefined') {
        boxname=window.popperBox.name;
        divpop=window.popperBox.isdiv;
    }
    else {
        var boxname = (typeof(desc) == 'undefined') ? 'popcontent' : (desc == '') ? 'tmn_popcontent2' : desc;
        boxname = (type == 1) ? 'popcontent' : boxname;
        if(divpop) {
            window.popperBox= {name:boxname, isdiv:divpop};
        }
    }
    if(desc != ''){
        var testUrl = new String(desc);
        if (testUrl.indexOf('be-the-first.html') > 0 && popHeadCode != 'onclick') {
            return false;
        }
    }
    if(window.grayBoxLoading==false) {
		window.grayBoxLoading = true;
		setTimeout('window.grayBoxLoading=false;',1000);

        // default width and height if not set
        width=(typeof(width) == "undefined") ? 500:width;
        height=(typeof(height) == "undefined") ? 500:height;

        leftscroll=(document.documentElement.scrollLeft) ?  document.documentElement.scrollLeft : document.body.scrollLeft;
        topscroll=(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        browseheight=(window.innerHeight) ? window.innerHeight:document.documentElement.clientHeight;
        browsewidth=(window.innerWidth) ? window.innerWidth:document.documentElement.clientWidth;
        // if the browser is smaller than the window will be..
        height=(browseheight < height) ? browseheight:height;
        width=(browsewidth < width) ? browsewidth:width;

        browseheight=(browseheight < height) ? 0:browseheight;
        boxtop=(browseheight/2) + topscroll;
        boxtop=boxtop-(height/2);
        boxtop=(boxtop <=0) ? 0:boxtop;

        browsewidth=(browsewidth < width) ? 0:browsewidth;
        boxleft=(browsewidth/2) + leftscroll;
        boxleft=boxleft-(width/2);
        boxleft=(boxleft <= 0) ? 0:boxleft;

        contbox=document.getElementById(boxname);
        contbox.style.top=boxtop + "px";
        contbox.style.left=boxleft + "px";
        contbox.style.height=height + "px";
		contbox.style.width=width + "px";

        var out=false;
		if(type == 1){
            ifm=document.getElementById('popfrm');
			// show the content area with the iframe
			ifm.src=desc;
			if(popHeadCode==-1)ifm.style.height = height + "px";
            else ifm.style.height = (height - 25) + "px";
			ifm.style.width = width + "px";

            if(typeof(popHeadCode) == 'undefined' || popHeadCode!=-1){
                var pophead=document.getElementById('pophead');
                pophead.contentWindow.document.body.style.padding="0";
                pophead.contentWindow.document.body.style.margin="0";
                pophead.contentWindow.document.body.style.background="#ABABC2";
                pophead.contentWindow.document.body.style.border="0";
                pophead.contentWindow.document.getElementsByTagName('html')[0].style.overflow="hidden";
                pophead.style.width=width + "px";
                pophead.style.height=25 + "px";
                pophead.style.border="0px";
                if(typeof(popHeadCode)=="undefined" || popHeadCode == 'onclick'){
                    pophead.contentWindow.document.body.innerHTML='<div style="width:45px; margin-top:5px; float:right;"><a style="font-size:12px; color:#000000; text-decoration:none;" href="javascript:top.tmn_popgbox(2);"><img src="http://www.toptenreviews.com/i/community/w_close.gif" border="0" alt="close box"/> Close</a></div>';
                } else {
                    pophead.contentWindow.document.body.innerHTML = popHeadCode;
                    pophead.contentWindow.document.body.style.background="#FFFFFF";
                }
            } else {
                document.getElementById('pophead').style.height="0px";
            }
		} else if(type == 3) {
            // don't do anything, we just don't want it to say it is fading out.
        } else {
            if(!divpop){
                ifm=document.getElementById('popfrm');
                ifm.src='http://www.toptenreviews.com/community/greybox/blank.html';
            }
            out=true;
		}
        // fade
        var endopac=(out == true) ? 0:0.6;
        showhidediv(boxname,(out == true) ? 2 : 1);
        smokeScreen('tmn_faderbox',endopac);
	}
}
//end graybox stuff


function createCookie(name,value,days) {
	var docurl=document.URL;
	if(docurl.indexOf(".toptenreviews.com")>0)
		var dmn = "; domain=.toptenreviews.com;";
	else
		var dmn = ";";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/"+dmn;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}
