// JavaScript Document
function detectBrowser(ie8affiliateid){
	if(!(readCookie('ie8popper'))){
		var currentUrl=window.location.href;
		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){
				document.getElementById('ie8widgetcall').innerHTML="<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;'/>";
				setTimeout("popgbox(3, '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 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 == '') ? '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.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('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 "";
}
