window.onerror = handleError; // Trap all errors on page
function handleError(message, URI, line) {
	return true; // this will stop the default message
}
if (self.parent.frames.length!=0) { // Get rid of framing pages
	self.parent.location.replace(document.location.href);
}

/** Drop down menu in header nav **/
var topnavTimerID;
var cssclass_off = "dropmenu";
var cssclass_over = "dropmenu on";
var disappeardelay=200;
function swapMenu(name, mouse_is_on) {
	if (mouse_is_on) {
		clearTimeout(topnavTimerID);
		changeClass(name, cssclass_over);
	} else {
		clearTimeout(topnavTimerID);
		topnavTimerID = setTimeout( function() {changeClass(name, cssclass_off)}, disappeardelay);
	}
}
function changeClass(item, newclass) {
	var cell = document.getElementById(item);
	cell.className = newclass;
}
/** SwapTabs for old-style tabs (most popular and most commented inited) **/
function swapTabs(tab) {
	var tabs = new Array('most_popular', 'most_commented');
	var tab_bar = 'most_popular_tabs';
	var off_class = 'off';
	var list_suffix = '_list';
	
	for (i=0; i<tabs.length; i++) {
		if (tab == tabs[i]) {
			// first change tab class
			changeClass(tab_bar, tabs[i]);
			
			// now show new tab list
			changeClass(tabs[i]+list_suffix, '');
		} else {
			// hide old tab list
			changeClass(tabs[i]+list_suffix, off_class);
		}
	}
}
/** window openers **/
var win = null;
function NewWindow(mypage,myname,w,h,scroll,resize) {
	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=+resize+';
	win = window.open(mypage,myname,settings);
}

var popUpWin=0;
function popUpWindow(URLStr, width, left, top) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = window.open(URLStr, 'popUpWin', 'width='+width+', scrollbars=yes, left='+left+', top='+top+',screenX='+left+',screenY='+top);
}

/** Background color changer **/
function bgchange(obj,clr) {
	obj.style.backgroundColor=clr;
}

/** Ad placement **/
function adPlace(src, tgt) {
	if (navigator.userAgent.indexOf('Netscape') > -1 && navigator.userAgent.indexOf('Netscape/8') == -1 && navigator.userAgent.indexOf('OS X') == -1) {
		if ((document.getElementById) && navigator.userAgent.indexOf('Netscape6') == -1) {
			var dgTgt = document.getElementById(tgt);
			if (dgTgt!=null) {
				var dgSrc = document.getElementById(src);
				dgTgt.innerHTML = dgSrc.innerHTML;
			}
		}
	} else {
		if (document.getElementById && document.createElement) {
			if (navigator.userAgent.indexOf('Mac_PowerPC') == -1) {
				var dgTgt = document.getElementById(tgt);
				if (dgTgt!=null) {
					var tgtCh = document.createElement("div");
					var dgSrc = document.getElementById(src);
					var temp = dgTgt.appendChild(tgtCh);
					var moveIt = dgTgt.replaceChild(dgSrc, temp);
					dgSrc.style.display="block";
				}
			}
		}
	}
}

/** Ad placement -- document.write an iframe (with innerhtml) ie only! **/
function renderAd(divName, aambTag) {
	var invObj = 'INV' + divName;
	try {
		var code = eval(aambTag);
	} catch(aamErr){ }
	if (typeof(code) != 'undefined') {
		if(navigator.userAgent.indexOf('MSIE') > -1) {
			document.getElementById(divName).innerHTML +=
			'<div id="TMP' + divName + '" style="display:none">' +
			escape('<body><div id="adDiv">' + code + '</div>') +
			'</div><iframe name="' + invObj + '" width="0" height="0" frameborder="0" ' +
			'onload="javascript:try { document.getElementById(\'' + divName + '\').' +
            'insertAdjacentElement(\'beforeEnd\', window.frames[\'' + invObj + '\'].' +
            'document.getElementById(\'adDiv\')) } catch(aamErr) { }"></iframe>';
			window.frames[invObj].document.location =
            'javascript:unescape(parent.document.getElementById(\'TMP' + divName + '\').innerHTML)';
		} else {
			document.writeln('<div id="' + invObj + '" style="display:none">' +
                code + '<script type="text/javascript" defer="true">' +
                'document.getElementById(\'' + divName + '\').innerHTML = ' +
                'document.getElementById(\'' + invObj + '\').innerHTML;' +
                'document.getElementById(\'' + invObj +
                '\').innerHTML = \'\';</scr' + 'ipt></div>');
		}
	}
}
/** ToggleDiv -- show/hide id element **/
function toggleDiv(id){
    if (document.getElementById(id).style.display != "block"){
        document.getElementById(id).style.display = "block";
    }else{
        document.getElementById(id).style.display = "none";
    }
}

/** Sets a dn cookie with / path **/
function setDNCookie(name,value,expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = name + '=' + escape(value) + ((expiredays==null) ? '' : ';expires='+exdate.toGMTString());
}

/** Gets a dn cookie **/
function getDNCookie(name) {
    if (document.cookie.length>0) {
        cookieStart = document.cookie.indexOf(name + "=");
        if (cookieStart != -1) {
            cookieStart = cookieStart + name.length + 1;
            cookieEnd = document.cookie.indexOf(";",cookieStart);
            if (cookieEnd == -1) cookieEnd=document.cookie.length;
            return unescape(document.cookie.substring(cookieStart,cookieEnd));
        }
    }
    return '';
}

/** Check if a user allows cookies **/
function allowsCookies() {
    setDNCookie('cookieTest', '1');
    return (getDNCookie('cookieTest') == 1) ? true : false;
}

/** Check if an ad should be shown this view **/
function showSessionAd(name) {
    if (allowsCookies()) {
        if (getDNCookie(name) != 1) {
            setDNCookie(name, '1');
            return true;
        }
    }
    return false;
}
