﻿// JScript File. (c) 2006-2008 Scout Media

var url = "mb.aspx?";
function initForums(sScrollToID, bShowScrollLocation) {
    // if there is something to right of hash (#) containing s=, then load that instead
    var hashLocation = removeHash(window.location.hash);
    if (null != hashLocation && (hashLocation.indexOf("s=") > -1 || hashLocation.indexOf("S=") > -1))
    {        
        var queryString = GetQueryString(window.location.search);
        if(queryString != hashLocation)
        {
            var strGet = url + hashLocation;
            setTimeout("navigateTo('" + strGet + "')", 10);
        }
    }
    if (null != sScrollToID && sScrollToID.length > 0) {
      if (bShowScrollLocation == "T") {
        showHideAnyDiv(sScrollToID, true, "");
      }
      scrollTo(sScrollToID);
    }
    checkOnlineUsersSetting()
}

/*****************************************************
 Navigation functions
******************************************************/

function removeHash (hashValue) {
  if (hashValue == null || hashValue == undefined)
     return null;
  else if (hashValue == "")
     return "";
  else if (hashValue.length == 1 && hashValue.charAt(0) == "#")
     return "";
  else if (hashValue.length > 1 && hashValue.charAt(0) == "#")
     return hashValue.substring(1);
  else
     return hashValue;
}

function GetQueryString (searchValue) {
  if (searchValue == null || searchValue == undefined)
     return null;
  else if (searchValue == "")
     return "";
  else if (searchValue.length == 1 && searchValue.charAt(0) == "?")
     return "";
  else if (searchValue.length > 1 && searchValue.charAt(0) == "?")
     return searchValue.substring(1);
  else
     return searchValue;
}

function navigateTo(sLocation) {
	window.location.href = sLocation;
	return false;
}

function link(sNavigateTo) {
	var strGet = url + sNavigateTo;
	window.location.href = strGet;
}

var lastScrollToID = "";
function scrollTo(sScrollToID) {
    var obj = document.getElementById(sScrollToID);
    if (null != obj) {
        obj.scrollIntoView(true);
    }
    lastScrollToID = sScrollToID;
}


/*****************************************************
 User Profile functions
******************************************************/

function showSection(anchorID, objectID)
{
	var theObject = document.getElementById(objectID);
	var theAnchor = document.getElementById(anchorID);
	if (theObject != null & theAnchor != null) {
	    var aSign = theAnchor.innerHTML.substr(0,1);
	    var aText = "";
	    if (theAnchor.innerHTML.length > 1)
	    {
	        aText = theAnchor.innerHTML.substr(1);
	    }

	    if (aSign == '+') {
	        aSign = "-"; 
            $("#"+objectID).show("slow");
	    }
	    else {
	        aSign = "+"; 
            $("#"+objectID).hide("slow");
	    }
	    theAnchor.innerHTML = aSign + aText;
	}
}

function enableShowSection(newText, srcAnchor, href)
{
	var theAnchor = document.getElementById(srcAnchor);
    if (null!= theAnchor)
    {
        theAnchor.innerHTML = newText;
        theAnchor.href = href;
        if (lastScrollToID == "UPerm")
        {
            showSection("permissionsAnchor", "permissions");
            scrollTo(lastScrollToID);
        }
    }
}

function submitForm(sLoc, isIE) {
    var sAction = "mb.aspx?" + sLoc;
    if (true == isIE) {
		document.forms["aspnetForm"].action = sAction;
		document.forms["aspnetForm"].submit();
    }
    else {
		var theForm = document.getElementById("aspnetForm");
		if (null != theForm) {
			theForm.action = sAction;
			theForm.submit();
		}
    }
}

function togglePerm(sPerm, sMediaSrv) {
    var obj = document.getElementById(sPerm);
    if (null != obj) {
        var val = parseInt(obj.value);
        if (val > 0) { val = -1; }
        else { val = val + 1; }
        obj.value = val;
        var imgobj = document.getElementById('IMG' + sPerm);
        if (null != imgobj) {
            if (val > 0) { imgobj.src = sMediaSrv + "/forums/check.gif"; }
            else if (val < 0) { imgobj.src = sMediaSrv + "/forums/remove.gif"; }
            else { imgobj.src = sMediaSrv + "/forums/default.gif"; }
        }
    }
}

function banUser(nSite, profile, banAction, dropDown)
{
    var days = "-1";
    if (dropDown != "")
    {
        var dd = document.getElementById(dropDown);
        if (dd != null)
        {            
            days = dd.value;
        }
    }
	var strSpecial = "s="+nSite+"&up="+profile+"&bu="+banAction+
		"&be="+days;
	link(strSpecial);
}


/*****************************************************
 Online Users functions
******************************************************/

function checkOnlineUsersSetting()
{
    var setting = readCookie('OnlineU');
    if (null != setting)
    {
        var theSpan = document.getElementById('OUSpan');
        if (null != theSpan)
        {
            if (('1' == setting && theSpan.innerHTML == '-') || ('0' == setting && theSpan.innerHTML == '+'))
            {
                onlineusersShowHide('OUSpan','OUH','OUP','');
            }
        }
    }
}

function onlineusersShowHide(spanID, hID, pID, speed)
{
	var theSpan = document.getElementById(spanID);
	var theH = document.getElementById(hID);
	var theP = document.getElementById(pID);
	if (theH != null & theP != null & theSpan != null) {
	    if (theSpan.innerHTML == '+') {
	        theSpan.innerHTML = "-"; 
	        theH.className = 'collapse';
            $("#"+pID).show(speed).removeClass("expand").addClass("collapse");
	        createCookie('OnlineU','0',30);
	    }
	    else {
	        theSpan.innerHTML = "+"; 
	        theH.className = 'expand';
            $("#"+pID).hide(speed).removeClass("collapse").addClass("expand");
	        createCookie('OnlineU','1',30);
	    }
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var start = document.cookie.indexOf(nameEQ);
	if (-1 != start) {
	    var len = start + nameEQ.length;
	    var end = document.cookie.indexOf(';', len);
	    if (-1 == end) { /* last cookie */ end = document.cookie.length; }
	    return document.cookie.substring(len, end);
	}
	return null;
}

function createCookie(name,value,days) {
	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=/";
}


/*****************************************************
 Private messageing functions
******************************************************/

function PM_SelectAll() {
	var vCheckAll = document.getElementById("CB_All");
	var vrgCB = document.getElementsByName("PMCheckBox");
	var vCB;
	for (vCB =0; vCB < vrgCB.length; vCB++) {
		vrgCB[vCB].checked = vCheckAll.checked;
	}		
}

function PM_DeleteMsg(siteid, mailbox, msgid) {
	link("s=" + siteid + "&pmb=" + mailbox + "&pmdm="+msgid);
}

function PM_DeleteMsgs(siteid, mailbox) {
	var vMsgs = "";

	var vrgCB = document.getElementsByName("PMCheckBox");
	var vCB;
	for (vCB =0; vCB < vrgCB.length; vCB++) {
		if (vrgCB[vCB].checked) {
			vMsgs += vrgCB[vCB].id + ",";
		}
	}
	
	if (vMsgs.length == 0) {
		alert("You have not selected any messages.");
	} else if (mailbox == "Trash") {
	    link("s=" + siteid + "&pmb=" + mailbox + "&pmdm="+vMsgs);
	} else {
		if (confirm('Do you want to delete?'))link("s=" + siteid + "&pmb=" + mailbox + "&pmdm="+vMsgs);
	}
}


/*****************************************************
 Help functions
******************************************************/

function ShowHelp(topicid, path) {
    var helpPage;
    helpPage = path + "help.aspx?start=1";
    if (topicid != null) {
        helpPage = path + helpPage + "?t=" + topicid;
    }    
	var wnd = open(helpPage, "wndHelp", "height=400, width=600, status=no, statusbar=no, toolbar=no, menubar=no, location=no, resizable=no, directories=no");
	wnd.focus();
}

function ShowModHelp(topicid, path) {
    var helpPage;
    helpPage = path + "help.aspx?tl=modtopics&start=1";
    if (topicid != null) {
        helpPage = path + helpPage + "&t=" + topicid;
    }
	var wnd = open(helpPage, "wndHelp", "height=400, width=600, status=no, statusbar=no, toolbar=no, menubar=no, location=no, resizable=no, directories=no");
	wnd.focus();
}

function ShowAdminHelp(topicid, path) {
    var helpPage;
    helpPage = path + "help.aspx?tl=admintopics&start=1";
    if (topicid != null) {
        helpPage = path + helpPage + "&t=" + topicid;
    }
	var wnd = open(helpPage, "wndHelp", "height=400, width=600, status=no, statusbar=no, toolbar=no, menubar=no, location=no, resizable=no, directories=no");
	wnd.focus();
}


function ShowMove(siteid, forumid, topicid) {
    var wleft = (screen.width - 500) / 2;
    var wtop = (screen.height - 125) / 2; 
    var url = "admin/MoveTopic.aspx?s=" + siteid + "&f=" + forumid + "&t=" + topicid;
	var wnd = open(url, "wndMove", "height=125,width=500,left=" + wleft + ",top=" + wtop + ",status=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no");
	wnd.focus();
}

function ShowCopy(siteid, forumid, topicid, lockable) {
    var wleft = (screen.width - 600) / 2;
    var wtop = (screen.height - 300) / 2;  
    var url = "admin/CopyTopic.aspx?s=" + siteid + "&f=" + forumid + "&t=" + topicid + "&l=" + lockable;
	var wnd = open(url, "wndCopy", "height=300,width=600,left=" + wleft + ",top=" + wtop + ",scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no");
	wnd.focus();
}

function CheckMaxLength(maxlength, name, textbox) {
	var value = (window.tinyMCE) ? tinyMCE.get(textbox).getContent() : $("#" + textbox).val();
	var length = value.length;
	
	if (length > maxlength) {
		alert("Your " + name + " is " + length + " characters (including HTML), which is larger than we allow. Please make your " + name + " less than " + maxlength + " characters and try again.");
		
		return false;
	}
	
	return true;
}

/*****************************************************
 Pending Users functions
******************************************************/

function UpdatePendingUsers(querystring, accept, browser)
{
    var allCB = document.getElementById("all");
    var inputs = document.getElementsByTagName("input");
    var proceed = true;
    if(allCB.checked & inputs.length > 3)
    {
        var text;
        if(accept)
        {
            text = "Accept";
        }
        else
        {
            text = "Reject";
        }
        proceed = confirm(text + " all users?");
     }
     else
     {
        var atLeastOneChecked = false;
        var i;
	    for (i = 0; i < inputs.length; i++)
	    {
	        if(inputs[i].type == "checkbox")
	        {
		        if(inputs[i].checked)
		        {
		            atLeastOneChecked = true;		            
		            break;
		        }
		    }
	    }
	    if(!atLeastOneChecked)
	    {
	        alert('No users selected');
	    }
	    proceed = atLeastOneChecked;
     }
        
    if(proceed)
    {
		if (browser.indexOf("IE") > -1)
		{
			var sAction = document.forms["aspnetForm"].action;
	        
			sAction = "mb.aspx?" + querystring + "&pu=1";
			if(accept)
			{
				sAction = sAction + "&apu=1";
			}
			else
			{
				sAction = sAction + "&rpu=1";
			}
			document.forms["aspnetForm"].action = sAction;
			document.forms["aspnetForm"].submit();
        }
        else
        {
			var theForm = document.getElementById("aspnetForm");
			if (null != theForm) {
				if(accept)
				{
					theForm.action = "mb.aspx?" + querystring + "&pu=1&apu=1";
				}
				else
				{
					theForm.action = "mb.aspx?" + querystring + "&pu=1&rpu=1";
				}
				theForm.submit();
			}
        }
     }
    
}

function CheckAllCheckboxes()
{
	var allCB = document.getElementById("all");
	var inputs = document.getElementsByTagName("input");
	var i;
	for (i = 0; i < inputs.length; i++)
	{
	    if(inputs[i].type == "checkbox")
	    {
		    inputs[i].checked = allCB.checked;
		}
	}
}

function UpdateAllCheckbox()
{
	var allCB = document.getElementById("all");
	var inputs = document.getElementsByTagName("input");
	var allChecked = true;
	var i;
	for (i = 0; i < inputs.length; i++)
	{
	    if(inputs[i].type == "checkbox")
	    {
		    if(inputs[i] != allCB & !inputs[i].checked)
		    {
		        allChecked = false;
		        break;
		    }
		}
	}
	allCB.checked = allChecked;
}


/*****************************************************
 Post-related functions
******************************************************/

function vote(nSite, nForum, nTopic, nPage, nPoll, nAnswer) {
	if ((nAnswer == null) || (nAnswer == -1)) {
		return;
	}
	var strSpecial = "s="+nSite+"&f="+nForum+"&t="+nTopic+
		"&p="+nPage+"&vp=" + nPoll + "&vr=" + nAnswer;
	link(strSpecial);
}

function showIgnoredPost(postDivID, postIgnoredDivID, tbDivID, authorDivID)
{
	var postDiv = document.getElementById(postDivID);
	var postIgnoredDiv = document.getElementById(postIgnoredDivID);
	var tbDiv = document.getElementById(tbDivID);
	if(authorDivID != null) { var authorDiv = document.getElementById(authorDivID); }
	
	if(postDiv != null) { postDiv.style.display = 'inline'; }
	if(postIgnoredDiv != null) { postIgnoredDiv.style.display = 'none'; }
	if(tbDiv != null) { tbDiv.style.display = 'inline'; }
	if(authorDiv != null) { authorDiv.style.display = 'inline'; }
}

function ratingEnter(divStars, index, mediaurl) {
	if (index >= 1) { document.getElementById("rate_"+divStars+"_1").src = mediaurl + "/forums/scout2/star_hover.gif"; }
	if (index >= 2) { document.getElementById("rate_"+divStars+"_2").src = mediaurl + "/forums/scout2/star_hover.gif"; }
	if (index >= 3) { document.getElementById("rate_"+divStars+"_3").src = mediaurl + "/forums/scout2/star_hover.gif"; }
	if (index >= 4) { document.getElementById("rate_"+divStars+"_4").src = mediaurl + "/forums/scout2/star_hover.gif"; }
	if (index == 5) { document.getElementById("rate_"+divStars+"_5").src = mediaurl + "/forums/scout2/star_hover.gif"; }

	switch (index) {
		case 1:  document.getElementById("rating_" + divStars).innerHTML = " awful"; break;
		case 2:  document.getElementById("rating_" + divStars).innerHTML = " poor"; break;
		case 3:  document.getElementById("rating_" + divStars).innerHTML = " average"; break;
		case 4:  document.getElementById("rating_" + divStars).innerHTML = " good"; break;
		case 5:  document.getElementById("rating_" + divStars).innerHTML = " excellent"; break;
	}
}

function ratingLeave(divStars, mediaurl) {
	document.getElementById("rate_"+divStars+"_1").src = mediaurl + "/forums/scout2/star_outline.gif";
	document.getElementById("rate_"+divStars+"_2").src = mediaurl + "/forums/scout2/star_outline.gif";
	document.getElementById("rate_"+divStars+"_3").src = mediaurl + "/forums/scout2/star_outline.gif";
	document.getElementById("rate_"+divStars+"_4").src = mediaurl + "/forums/scout2/star_outline.gif";
	document.getElementById("rate_"+divStars+"_5").src = mediaurl + "/forums/scout2/star_outline.gif";
	
	document.getElementById("rating_" + divStars).innerHTML = "&nbsp;";
}

function showModHist(spanID, srcAnchor)
{
	var theAnchor = document.getElementById(srcAnchor);
	var theSpan = document.getElementById(spanID);
	var theEntries = theSpan.getElementsByTagName("span");
	
	if(theEntries[0] != null)
	{
	    var open = theAnchor.innerHTML == "+ Moderation History";

        if(open)
        {
            if (null!= theAnchor) { theAnchor.innerHTML = "- Moderation History"; }
        }
        else
        {
            if (null!= theAnchor) { theAnchor.innerHTML = "+ Moderation History"; }
        }
    	
	    for(var i = 0; i < theEntries.length; i++)
	    {
	        var theEntry = theEntries[i];
	        if (null != theEntry)
	        {
	            if (open)
	            {
    	            
	                theEntry.style.display = 'block';
    	            
	            }
	            else
	            {
	                theEntry.style.display = 'none';  
	            }
	        }
        }
    }
}

function showHideAnyDiv(divID, bShow, speed)
{
	if (bShow == true) {
		$("#"+divID).show(speed);
	}
	else {
		$("#"+divID).hide(speed);
	}
}

function toggleAnyDiv(divID, speed)
{
	var theDiv = document.getElementById(divID);
	if (theDiv != null) {
		if (theDiv.style.display == 'inline' || theDiv.style.display == 'block') {
			showHideAnyDiv(divID, false, '');
		}
		else {
			showHideAnyDiv(divID, true, speed);
		}
	}
}

/*****************************************************
 Ad/News Fade functions
******************************************************/

// FADE globals
var fadeStepNow = 0;
var opacityNow = 100;
var fadeOutName = "";
var fadeInName = "";
var fadeTimemout;
var fadeBGColor = "";

function fade( from, to, step )
{	
	var totalSteps = 30;
	return Math.floor( (from * (totalSteps - step)/totalSteps) + (to * (step/totalSteps) ) ); 
}

// Set opacity of object, level 0 - 100
function setOpacity(obj, level) {
	obj.style.opacity = level/100;  // mozilla is 0 to 1
	obj.style.filter = 'alpha(opacity=' + level + ')';	// ie is 0 to 100
}

function fadeTeamNews ( objNameFadeOut, objNameFadeIn, bgColor ) {
    clearTimeout(fadeTimemout);
    fadeOutName = objNameFadeOut;
    fadeInName = objNameFadeIn;
    fadeBGColor = bgColor;
    var objOut = document.getElementById(objNameFadeOut);
    var objIn = document.getElementById(objNameFadeIn);
    if (null != objOut && null != objIn) {
	    objOut.style.opacity = 1;  // mozilla is 0 to 1
	    objOut.style.filter = 'alpha(opacity=' + 100 + ')';	// ie is 0 to 100
        objOut.style.display = '';
        if (fadeBGColor.length > 0) {
            objOut.style.background = fadeBGColor;
        }
	    objIn.style.opacity = 0;
	    objIn.style.filter = 'alpha(opacity=' + 0 + ')';
        objIn.style.display = 'none';
	    fadeStepNow = 0;
	    opacityNow = 100;
        fadeTimemout = setTimeout( "fadeItems(true)", 20000 );
    }
}
function fadeItems( fadeOut ){
	if( fadeOut == true )
	{
        var obj = document.getElementById(fadeOutName);
		if( opacityNow != 0 )
		{
			// not yet fully transparent, so keep fading out
			opacityNow = fade( 100, 0, fadeStepNow );
			fadeStepNow++;
			if (null != obj)
			{
			    setOpacity( obj, opacityNow );
                if (fadeBGColor.length > 0) {
                    obj.style.background = fadeBGColor;
                }
			    fadeTimemout = setTimeout( "fadeItems(true)", 50 );
			    return;
			}
		}
		else 
		{
			// fully transparent.  reset fade increment step.  update with new data.
			fadeStepNow=0; 
			var objNews = document.getElementById(fadeInName);
			if (null != objNews && null != obj)
			{
			    obj.style.display = 'none';
			    objNews.style.display = '';
			    fadeTimemout = setTimeout( "fadeItems(false)", 1 ); 
			    return;
			}
		}
	}
	else 
	{
		// fading in
		if( opacityNow != 100 )  
		{
			// not yet fully opaque, so keep fading in
			opacityNow = fade( 0, 100, fadeStepNow );
			fadeStepNow++;
            var obj = document.getElementById(fadeInName);
			if (null != obj)
			{
			    setOpacity( obj, opacityNow );
                if (fadeBGColor.length > 0) {
                    obj.style.background = fadeBGColor;
                }
			    fadeTimemout = setTimeout( "fadeItems(false)", 50 ); 
			    return;
			}
		}
		else
		{
			// fully opaque.  done...
            var obj = document.getElementById(fadeInName);
			if (null != obj)
			{
                if (fadeBGColor.length > 0) {
                    obj.style.background = fadeBGColor;
                }
			}
			return;
		}
	}
}


/*****************************************************
 Miscellaneous functions
******************************************************/
function calcNoticeHeight(iFrameID)
{
try {
    var ifn = document.getElementById(iFrameID);
    if (null != ifn) {
        var vsHeight = ifn.contentWindow.document.body.scrollHeight;
        var vdHeight = ifn.contentWindow.document.height;
        var vboHeight = ifn.contentWindow.document.body.offsetHeight;
        if (vdHeight != "undefined" && vdHeight < vsHeight && vdHeight > 0) {
			vsHeight = vdHeight;
        }
        if (vboHeight != "undefined" && vboHeight < vsHeight && vboHeight > 0) {
			vsHeight = vboHeight;
        }
        ifn.height = vsHeight;
    }
}
catch (ex) {}
}

function reloadFrame(frameId) {
	var theFrame = document.getElementById(frameId);
	if (null != theFrame) {
		theFrame.contentWindow.document.location.reload();
	}
}

function showMods(divID, srcAnchor)
{
	var theAnchor = document.getElementById(srcAnchor);
	var theDiv = document.getElementById(divID);
	
	if(theAnchor != null && theDiv != null)
	{
	    var open = theAnchor.innerHTML == "+ Moderators";

        if(open)
        {
            if (null!= theAnchor) { theAnchor.innerHTML = "- Moderators:"; }
        }
        else
        {
            if (null!= theAnchor) { theAnchor.innerHTML = "+ Moderators"; }
        }
    	
        if (open)
        {
            
            theDiv.style.display = 'block';
            
        }
        else
        {
            theDiv.style.display = 'none';  
        }
    }
}

function CheckQRMaxPostLength()
{ 
    try
    {
        var maxLen = 64 * 1024;
        var qrArea = document.getElementById('quickreplytext');
        var thePost = qrArea.value;
        var actLen = thePost.length;
        if (actLen > maxLen)
        {
            var actKB = Math.ceil(actLen/1024);
            alert('Your message is ' + actKB + ' KB, which is larger than we allow. Please make your message smaller and try again.');
            return false;
        }
    }
    catch(err)
    {
        return true;
    }
    return true;
}


/*****************************************************
 Bulk Action functions
******************************************************/

function ShowBulkAction(actionName, browser, querystring, requiresMultipleTopics, pageName)
{
    if (pageName == null) { pageName = "Action"; }
    var allCB = document.getElementById("all");
    var inputs = document.getElementsByTagName("input");
    var proceed = true;

    var atLeastOneChecked = false;
    var atLeastTwoChecked = false;
    var i;
    for (i = 0; i < inputs.length; i++)
    {
        if(inputs[i].type == "checkbox")
        {
	        if(inputs[i].id != "all" && inputs[i].checked)
	        {
	            if (!atLeastOneChecked)
	            {
	                atLeastOneChecked = true;
	                if(!requiresMultipleTopics)
	                {
	                    break;
	                }
	            }
	            else
	            {
	                atLeastTwoChecked = true;
	                break;
	            }
	        }
	    }
    }
    
    if(requiresMultipleTopics)
    {
        proceed = atLeastTwoChecked;
        if(!atLeastTwoChecked)
        {
            alert('Please select two or more topics');
        }
    }
    else
    {
        proceed = atLeastOneChecked;
        if(!atLeastOneChecked)
        {
            alert('Please select one or more topics');
        }
    }
    
    if(proceed)
    {
        if(!confirm('Do you want to ' + actionName + ' the selected Topic(s)'))
        {
            proceed = false;
        }
    }
        
    if(proceed)
    {
		if (browser.indexOf("IE") > -1)
		{
			var sAction = document.forms["aspnetForm"].action;
			sAction = "admin/" + pageName + ".aspx?" + querystring;
			document.forms["aspnetForm"].action = sAction;
			document.forms["aspnetForm"].method = "post";
			document.forms["aspnetForm"].target = "wndAction";
			OpenWindow(document.forms["aspnetForm"].target);
			document.forms["aspnetForm"].submit();
        }
        else
        {
			var theForm = document.getElementById("aspnetForm");
			if (null != theForm) {
				theForm.action = "admin/" + pageName + ".aspx?" + querystring;
				theForm.target = "wndAction";
				OpenWindow("wndAction");
				theForm.submit();
			}
        }
     }   
}

function OpenWindow(targ)
{
    var wleft = (screen.width - 500) / 2;
    var wtop = (screen.height - 125) / 2;
    var wnd = window.open('', targ, "height=125,width=500,left=" + wleft + ",top=" + wtop + ",status=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no");
	wnd.focus();
}

/*****************************************************
*   BACKBUTTON IE FIX
******************************************************/

(function() { if (document.all && window.attachEvent) {

var cookie = {
	save: function(name, value) {
		if (value.constructor == Array) {
			for (var i = 0; i < value.length; i++) {
				value[i] = value[i].name + ";" + value[i].value;
			}
			
			if (value.length > 0) {
			    value = "$a::" + value.join("|");
			}
			else {
			    value = "";
			}
		}
		
        var date = new Date();
        date.setTime(date.getTime() + 86400000);

		document.cookie = name + "=" + escape(value) + ";expires=" + date.toGMTString() + "; path=/";
	},
	
	get: function(name) {
		name = new RegExp("^" + name + "=");
		
		var cookies = document.cookie.split(";");
		for (var i = 0; i < cookies.length; i++) {
			var c = cookies[i].replace(/^\s+|\s+$/g, "");
			
			if (name.test(c)) {
				var value = unescape(c.replace(name, ""));
				// Possible array
				if (value.indexOf("$a::") != -1) {
					var values = value.replace(/^\$a::/, "").split("|");
					value = [];
					for (var v = 0; v < values.length; v++) {
						var o = values[v].split(";");
						
						value.push({
							name: o[0],
							value: o[1]
						});
					}
				}

				return value;
			}
		}
	}
};

var getScrollTop = function() {
    if (document.compatMode == "CSS1Compat") {
        return document.documentElement.scrollTop;
    }
    else {
        return document.body.scrollTop;
    }
};

document.attachEvent("onclick", function(event) {
    event = event || window.event;
    
    if (event.srcElement.tagName == "A") {
        cookie.save("clicked", "y");
    }
});

window.attachEvent("onload", function() {
	var scroll = cookie.get("scroll") || [];
	var clicked = cookie.get("clicked") || "n";
	
	cookie.save("clicked", "n");    // Reset.
	
	if (clicked == "y") {
	    return;  // User is navigating.
	}
	
	if (!scroll.length) {
	    return; // No history saved.
	}
	
	if (scroll[scroll.length-1].name == location) {
	    return; // Most likely a refresh.
	}
	
	var match = false;
	var list = [];
	
	for (var i = scroll.length-1; i >= 0; i--) {
	    if (scroll[i].name == location && !match) {
	        match = true;
	        window.scroll(0, scroll[i].value);
	    }
	    else {
	        list.push(scroll[i]);
	    }
	}

	cookie.save("scroll", list);
});

window.attachEvent("onunload", function() {
	var scroll = cookie.get("scroll") || [];
	
    scroll.push({
	    name: location,
	    value: getScrollTop()
    });
	
    if (scroll.length >= 5) {
	    scroll.shift();
    }

    cookie.save("scroll", scroll);
});

} })();
