var BWflag = false;

var Initialized = false;

function popUp(URL)
{
	day = new  Date();
	id = " "+day.getTime();
	page[id] = window.open(URL,"","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=558,left=376,top=153");
}

function popUpWnd(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=558,left = 376,top = 153');");
}
function popUpWndows(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=338,left = 335,top = 200');");
}
function InitFilters()
{
        if(Initialized) return;
        Initialized = true;
        document.all.mainpic.style.filter = "Gray";
        document.all.mainpic.filters["Gray"].enabled = BWflag;
}

function flipBW()
{
        InitFilters();
        BWflag = !BWflag;

        document.all.mainpic.filters["Gray"].enabled = BWflag;

        if(BWflag) document.all.bw.src = "templates/4dark/images/tool_bw_on.gif";
        else document.all.bw.src = "templates/4dark/images/tool_bw.gif";
}

var Cropflag = false;
var Gridflag = false;

var CurrentSide = null;
var x0 = 0;
var y0 = 0;

function MouseDown(side)
{
        CurrentSide = side;
        ev = window.event;
        x0 = ev.x;
        y0 = ev.y;
}

function MouseUp()
{
        CurrentSide = null;
}

function MouseMove()
{
        ev = window.event;
        if((CurrentSide == null) || (ev.button != 1)) return;
        dx = ev.x - x0;
        dy = ev.y - y0;

        style = document.all[CurrentSide].style;
        switch (CurrentSide)
        {
                case "top":
                        if(style.pixelHeight >= 8) style.pixelHeight += dy;
                        if(style.pixelHeight < 8) style.pixelHeight = 8;
                        else {x0 = ev.x; y0 = ev.y;}
                break;
                case "bottom":
                        if(style.pixelHeight >= 8) style.pixelHeight -= dy;
                        if(style.pixelHeight < 8) style.pixelHeight = 8;
                        else {x0 = ev.x; y0 = ev.y;}
                break;
                case "left":
                        if(style.pixelWidth >= 8) style.pixelWidth += dx;
                        if(style.pixelWidth < 8) style.pixelWidth = 8;
                        else {x0 = ev.x; y0 = ev.y;}
                break;
                case "right":
                        if(style.pixelWidth >= 8) style.pixelWidth -= dx;
                        if(style.pixelWidth < 8) style.pixelWidth = 8;
                        else {x0 = ev.x; y0 = ev.y;}
                break;
        }
}

function SetCrop(left, top, right, bottom)
{
        if(!Cropflag) flipCrop();

        document.all.left.style.pixelWidth = left + 8;
        document.all.right.style.pixelWidth = right + 8;
        document.all.top.style.pixelHeight = top + 8;
        document.all.bottom.style.pixelHeight = bottom + 8;

        window.scrollTo(0,0);
}

function AddClipping()
{
        x1 = document.all.left.style.pixelWidth - 8; if(x1 < 0) x1 = 0;
        y1 = document.all.top.style.pixelHeight - 8; if(y1 < 0) y1 = 0;
        x2 = document.all.right.style.pixelWidth - 8; if(x2 < 0) x2 = 0;
        y2 = document.all.bottom.style.pixelHeight - 8; if(y2 < 0) y2 = 0;

        s = '[CROP]'+x1+','+y1+','+x2+','+y2+'[/CROP]';

        document.commentform.comment_text.value += s;
        document.commentform.comment_text.focus();
}

function flipCrop()
{
        Cropflag = !Cropflag;
        if(Cropflag)
        {
                document.all.cropperimg.src = "templates/4dark/images/tool_crop_on.gif";
                document.all.cropper.style.display = "";
        }
        else
        {
                document.all.cropperimg.src = "templates/4dark/images/tool_crop.gif";
                document.all.cropper.style.display = "none";
        }
}

function flipGrid()
{
        Gridflag = !Gridflag;

        if(Gridflag)
        {
                if(!Cropflag) flipCrop();
                document.all.gridimg.src = "templates/4dark/images/tool_grid_on.gif";
                document.all.grid.style.visibility = "visible";
        }
        else
        {
                document.all.gridimg.src = "templates/4dark/images/tool_grid.gif";
                document.all.grid.style.visibility = "hidden";
        }
}