// FORUM POST SEPARATOR ADS

function DisplayPostSeparatorAd(sectionId,itemIndex)
{
    if (isNaN(sectionId)==true || sectionId <= 0 || isNaN(itemIndex)==true) {return;}

    // Advertising for first post separator
    if(itemIndex==0)
    {
        zoneId = 0;
        switch(sectionId)
        {
        	default:zoneId = 51; // SCA
        }	
        document.writeln("<div class=\"SeparatorAd\"><script type='text/javascript'>DisplayAdsCSForum(" + zoneId + ");</script></div>");
    }
}


// IMAGE VIEW LARGER CODE
function CSViewLargerImage(width, height, location)
{
    
    // Grab the current page height
    var PageHeight = screen.height;
    var PageWidth = screen.width;
    
    
    
    // Determine the top and left positions
    var PageTop = ((PageHeight - height) / 2);
    var PageLeft = ((PageWidth - width) / 2);
    
    
    
    // Set the location of the file being opened
    var PageLoader = "/brdcs/themes/brd/common/viewimage.aspx?img=" + location;
    
    
    
    // Set the window properties
    var Properties = "width=" + width + ", height=" + height + ", top=" + PageTop + ", left=" + PageLeft + ", location=no, menubar=no, resizebale=no, scrollbars=no, titlebar=no, toolbar=no";
    
    
    
    // Open the new window
    window.open(PageLoader, "null", Properties);
    
    
}



// IMAGE AUTO-RESIZE CODE

function resizeImage(thisimage) {
    if (thisimage.src.indexOf('emoticons/') == -1) ImageResizer.createOn(thisimage);
    return;
}

function walkImages(){
    re = /^inlinepostimage/;
    if (document.images){
        for (a=0;a<document.images.length;a++){
          if (re.test(document.images[a].className)) resizeImage(document.images[a]);
        }
    }
}

ImageResizer.ImageIdPrefix = 'ImageResize_Image_';
ImageResizer.WarningIdPrefix = 'ImageResize_Warning_';
ImageResizer.MAXWIDTH = 450;
ImageResizer.MAXHEIGHT = 350;

function ImageResizer(id, img)
{
    this.id = id;
    this.img = img;
    this.originalWidth = 0;
    this.originalHeight = 0;
    this.warning = null;
    this.warningTextNode = null;
    img.id = ImageResizer.ImageIdPrefix+id;
}

ImageResizer.getNextId = function()
{
    id = 1;
    while(document.getElementById(ImageResizer.ImageIdPrefix+id) != null)
        id++;
    return id;
}

ImageResizer.createOn = function(img)
{
    if(!img.tries || typeof img.tries == 'undefined')
        img.tries = 1;
    else
      img.tries++;

    if((img.width == 0 || img.height == 0) && img.tries < 4)
    {
        setTimeout(function() { ImageResizer.createOn(img); }, 500);
        return;
    }

    isRecovery = false;
    if(img.id && img.id.indexOf(ImageResizer.ImageIdPrefix) == 0 && document.getElementById(ImageResizer.WarningIdPrefix+img.id.substr(ImageResizer.ImageIdPrefix.length)) != null)
    {
        newid = img.id.substr(ImageResizer.ImageIdPrefix.length);
        resizer = new ImageResizer(newid, img);
        isRecovery = true;
        resizer.restoreImage();
    } else
    {
        newid = ImageResizer.getNextId();
        resizer = new ImageResizer(id, img);
    }

    if (resizer.originalWidth == 0) resizer.originalWidth = img.width;
    if (resizer.originalHeight == 0) resizer.originalHeight = img.height;

    if((ImageResizer.MAXWIDTH > 0 && resizer.originalWidth > ImageResizer.MAXWIDTH) || (ImageResizer.MAXHEIGHT > 0 && resizer.originalHeight > ImageResizer.MAXHEIGHT))
    {
        if(isRecovery)
            resizer.reclaimWarning(warning);
        else
        {
            resizer.createWarning();
            img.className = 'inlinepostimageresized';
        }
        resizer.scale();
    }
}

ImageResizer.prototype.restoreImage = function()
{
    newimg = document.createElement('IMG');
    newimg.src = this.img.src;
    this.img.width = newimg.width;
    this.img.height = newimg.height;
}

ImageResizer.prototype.reclaimWarning = function()
{
    warning = document.getElementById(ImageResizer.WarningIdPrefix+newid);
    this.warning = warning;
    this.warningTextNode = warning.firstChild.firstChild.childNodes[0].firstChild;
    this.warning.resize = this;
    this.scale();
}

ImageResizer.prototype.createWarning = function()
{
    var warning = document.createElement('div');
    warning.className = 'ImageResizer_Warning';
    warning.id = ImageResizer.WarningIdPrefix + this.id;
    
    var LargerImage = "/brdcs/themes/brd/common/viewimage.aspx?img="  + this.img.src + "&w=" + this.originalWidth + "&h=" + this.originalHeight;

    var warningLink = document.createElement('a');
    warningLink.setAttribute('href', LargerImage);
    warningLink.setAttribute('target', '_blank');
    /*warningLink.setAttribute('rel', 'lytebox');*/
    /*warningLink.setAttribute('href', this.img.src);*/
    /*warningLink.setAttribute('target', '_blank');*/
    /*warningLink.onclick = function () { myLytebox.start(this, false, false); return false; }*/

    var warningMessage = document.createElement('div');
    warningMessage.className = 'ImageResizer_WarningMessage';

    var messageNode = document.createTextNode('');
    warningMessage.appendChild(messageNode);

    warningLink.appendChild(warningMessage);
    warning.appendChild(warningLink);

    this.img.parentNode.insertBefore(warning, this.img);

    this.warning = warning;
    this.warningTextNode = messageNode;
}

ImageResizer.prototype.scale = function()
{
    this.img.height = this.originalHeight;
    this.img.width = this.originalWidth;

    if(ImageResizer.MAXWIDTH > 0 && this.img.width > ImageResizer.MAXWIDTH)
    {
        resized = true;
        this.img.height = (ImageResizer.MAXWIDTH / this.img.width) * this.img.height;
        this.img.width = ImageResizer.MAXWIDTH;
    }

    if(ImageResizer.MAXHEIGHT > 0 && this.img.height > ImageResizer.MAXHEIGHT)
    {
        resized = true;
        this.img.width = (ImageResizer.MAXHEIGHT / this.img.height) * this.img.width;
        this.img.height = ImageResizer.MAXHEIGHT;
    }

    var resizer = this;
    this.warning.style.width = this.img.width + 'px';

   var message = 'This image has been resized. Click this bar to view the full image.  The dimensions of the original image are ' + this.originalWidth + 'x' + this.originalHeight;
   if(this.img.fileSize && this.img.fileSize > 0)
      message += ' with a file size of ' + parseInt(this.img.fileSize/1024) + 'k.';
   else
      message += '.';

    this.warningTextNode.data = message;

    return false;
}
