﻿// javascript

function select_process(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 240;
var val3 = 255;
var func = sourceObject.id;
var anow;
var sb;

    switch(func)
    {
    case "refresh":
      break;
    case "newimage": case "newimage2":
        func = "newimage";
        val1 = document.getElementById("newwidth").value;
        val2 = document.getElementById("newlength").value;
        val3 = document.getElementById("newbpp").value;
      break;    
    case "addgrid": case "addgrid2":
        func = "addgrid";
        val1 = document.getElementById("gridsize").value;
      break;
    case "expandcontrast": case "expandcontrast2":
        func = "expandcontrast";
        val1 = document.getElementById("min").value;
        val2 = document.getElementById("max").value;
      break;
    case "reducecontrast": case "reducecontrast2":
        func = "reducecontrast";
        val1 = document.getElementById("rmin").value;
        val2 = document.getElementById("rmax").value;
      break;
    case "changebright": case "changebright2":
        func = "changebright";
        val1 = document.getElementById("change").value;
      break;
    case "multiply": case "multiply2":
        func = "multiply";
        val1 = document.getElementById("multiplier").value;
      break;
    case "divide": case "divide2":
        func = "divide";
        val1 = document.getElementById("divisor").value;
      break;
    case "exchangelevel": case "exchangelevel2":
        func = "exchangelevel";
        val1 = document.getElementById("exmin").value;
        val2 = document.getElementById("exmax").value;
        val3 = document.getElementById("exnew").value;
      break;
    case "adjustrgb": case "adjustrgb2":
        func = "adjustrgb";
        val1 = document.getElementById("ared").value;
        val2 = document.getElementById("agrn").value;
        val3 = document.getElementById("ablu").value;
      break;
    case "adjusthsv": case "adjusthsv2":
        func = "adjusthsv";
        val1 = document.getElementById("ahue").value;
        val2 = document.getElementById("asat").value;
        val3 = document.getElementById("aval").value;
      break;
    case "kodalith": case "kodalith2":
        func = "kodalith";
        val1 = document.getElementById("thresh").value;
      break;
    case "gammabrighten": case "gammabrighten2":
        func = "gammabrighten";
        val1 = document.getElementById("gamma").value;
      break;
    case "addnoise": case "addnoise2":
        func = "addnoise";
        val1 = document.getElementById("noiselevel").value;
      break;
    case "medianfilter": case "medianfilter2":
        func = "medianfilter";
        val1 = document.getElementById("kernelsize").value;
      break;      
    case "gaussianblur": case "gaussianblur2":
        func = "gaussianblur";
        val1 = document.getElementById("blurwidth").value;
      break;
    case "erode": case "erode2":
        func = "erode";
        val1 = document.getElementById("erodeamount").value;
      break;
    case "dilate": case "dilate2":
        func = "dilate";
        val1 = document.getElementById("dilateamount").value;
      break;
    case "dropbits": case "dropbits2":
        func = "dropbits";
        val1 = document.getElementById("bitstodrop").value;
      break;
    case "posterize": case "posterize2":
        func = "posterize";
        val1 = document.getElementById("posterizelevels").value;
      break;
    case "pixellize": case "pixellize2":
        func = "pixellize";
        val1 = document.getElementById("pixelsize").value;
      break;
    case "fountain": case "fountain2":
        func = "fountain";
        sb = document.getElementById("fountaindirection");
        if(sb.checked == true)
            val1 = sb.value;
        else {
            sb = document.getElementById("fountaindirection1");
            if(sb.checked == true)
                val1 = sb.value;
            else {
                sb = document.getElementById("fountaindirection2");
                if(sb.checked == true)
                    val1 = sb.value;
            }
        }    
        val2 = document.getElementById("fountaincycles").value;
      break;

    default:
        ;
    }
    
    anow = new Date();   // to tack on a random number so to the browser it is a new url

    // Determine which image is to be processed       
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
        
        
        nimage.src = "process.aspx?category=process1"
        + "&func=" + func + "&id=img_" + ax
        + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
        + "&xtr=" + anow;
//    }
}

function select_process3(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 0;
var val3 = 20;
var cb;
var func = sourceObject.id;
var anow;

    switch(func)
    {
    case "newimage": case "newimage2":
        func = "newimage";
        val1 = document.getElementById("newwidth").value;
        val2 = document.getElementById("newlength").value;
        val3 = document.getElementById("newbpp").value;
      break;
    case "enlargecanvas": case "enlargecanvas2":
        func = "enlargecanvas";
        val1 = document.getElementById("canvasamount").value;
      break;
    case "resize": case "resize2":
        func = "resize";
        val1 = document.getElementById("magnification").value;
      break;
    case "rotate": case "rotate2":
        func = "rotate";
        val1 = document.getElementById("angle").value;
      break;
    case "reducecolors": case "reducecolors2":
        func = "reducecolors";
        val1 = document.getElementById("numcolors").value;
        cb = document.getElementById("diffusionflag")
        if(cb.checked == true)
            val2 = "1";
      break;
    default:
        ;
    }
    
    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be processed
    
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
   
    nimage.src = "process.aspx?category=process3"
    + "&func=" + func + "&id=img_" + ax
    + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
    + "&xtr=" + anow;
}

function select_process8(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 20;
var val3 = 20;
var val4 = 20;
var val5 = 20;
var val6 = 20;
var val7 = 20;
var val8 = 20;
var func = sourceObject.id;
var anow;
    switch(func)
    {
    case "colorramp": case "colorramp2":
        func = "colorramp";
        val1 = document.getElementById("cr0").value;
        val2 = document.getElementById("cr0red").value;
        val3 = document.getElementById("cr0grn").value;
        val4 = document.getElementById("cr0blu").value;
        val5 = document.getElementById("cr1").value;
        val6 = document.getElementById("cr1red").value;
        val7 = document.getElementById("cr1grn").value;
        val8 = document.getElementById("cr1blu").value;
      break;
    default:
        ;
    }
    
    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be processed
    
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
   
    nimage.src = "process.aspx?category=process3"
    + "&func=" + func + "&id=img_" + ax
    + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 + "&val4=" + val4 
    + "&val5=" + val5 + "&val6=" + val6 + "&val7=" + val7 + "&val8=" + val8
    + "&xtr=" + anow;
}

function send_process(sourceObject)
{
var nimage;
var val1 = "";
var val2 = "";
var val3 = "";
var func = sourceObject.id;
var anow;

    switch(func)
    {
    case "send": case "send2":
        func = "send";
        val1 = document.getElementById("sendto").value;
        val2 = document.getElementById("sendfrom").value;
        val3 = document.getElementById("sendsubject").value;
      break;
    default:
        ;
    }
    
    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be processed
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
    
   
    nimage.src = "process.aspx?category=send"
    + "&func=" + func + "&id=img_" + ax
    + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
    + "&xtr=" + anow;
}



function select_copy(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 240;
var val3 = 255;
var copyfrom_id;
var copyto_id;
var func = sourceObject.id;
var anow;
var rb;

    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be copied
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    copyfrom_id = "img_" + ax;
   
    // Determine which image is receive the copy
    switch(func)
    {
    case "tosource":
        copyto_id = "img_source";
      break;
    case "tooperator":
        copyto_id = "img_operator";
      break;
    case "toresult":
        copyto_id = "img_result";
      break;
      
    case "extractplane": case "extractplane2":
        func = "extractplane"; 
        copyto_id = "img_operator";
        
        var j;
        for(j = 0; j < 6; j++){
            rb = document.getElementById("eplane" + j);   
            if (rb.checked == true){
                val1 = j;
                break;
                }
            }
      break;         
    default:
     ;
    }

    if(copyfrom_id != copyto_id) {
        nimage = document.getElementById(copyto_id);
        nimage.src = "process.aspx?category=copy"
        + "&func=" + func + "&id=" + copyto_id
        + "&id2=" + copyfrom_id
        + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
        + "&xtr=" + anow;
    }
}

function select_copy_worksIE(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 240;
var val3 = 255;
var copyfrom_id;
var copyto_id;
var func = sourceObject.id;
var anow;
var rb;

    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be copied
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    copyfrom_id = "img_" + ax;
   
    // Determine which image is receive the copy
    switch(func)
    {
    case "tosource":
        copyto_id = "img_source";
      break;
    case "tooperator":
        copyto_id = "img_operator";
      break;
    case "toresult":
        copyto_id = "img_result";
      break;
      
    case "extractplane": case "extractplane2":
        func = "extractplane"; 
        copyto_id = "img_operator";
        
        var j;
        if (document.rbe)
            rb = document.rbe;
        else if(rbe)
            rb = rbe;
                
        j = rb.length;                
        for(j = 0; j < rb.length; j++){
            if (rb[j].checked == true){
                val1 = j;
                break;
                }
            }
      break;         
    default:
     ;
    }

    if(copyfrom_id != copyto_id) {
        nimage = document.getElementById(copyto_id);
        nimage.src = "process.aspx?category=copy"
        + "&func=" + func + "&id=" + copyto_id
        + "&id2=" + copyfrom_id
        + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
        + "&xtr=" + anow;
    }
}

      
function select_combination(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 240;
var val3 = 255;
var func = sourceObject.id;
var anow;
var rb;

    anow = new Date();   // to tack on a random number so to the browser it is a new url

    switch(func)
    {
    case "coverclear": case "coverclear2":
        func = "coverclear";
        val1 = document.getElementById("transcolor").value;
      break;
    case "wtaverage": case "wtaverage2":
        func = "wtaverage";
        val1 = document.getElementById("weight").value;
      break;
    case "insertplane": case "insertplane2":
        func = "insertplane";
        
        var j;
        for(j = 0; j < 6; j++){
            rb = document.getElementById("iplane" + j);   
            if (rb.checked == true){
                val1 = j;
                break;
                }
            }
      break;
      
     default:
     ;
     }
     
    nimage = document.getElementById("img_result");
    
    nimage.src = "process.aspx?category=combine"
    + "&func=" + func + "&id=img_result" + "&id2=img_source" + "&id3=img_operator" 
    + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
    + "&xtr=" + anow;

}

function select_analysis(sourceObject)
{
var nimage;
var func = sourceObject.id;
var anow;
var ax;
var ids;
var data;

    anow = new Date();   // to tack on a random number so to the browser it is a new url
    // Select image to analyze
    ax = document.getElementById("activeimage2").innerHTML;
    ids = "&id=img_" + ax;
    nimage = document.getElementById("img_" + ax);
    
    // Unless we're doing correlation
    if(func == "correlation") {
        ids = "&id=img_result" + "&id2=img_source" + "&id3=img_operator" ;
        nimage = document.getElementById("img_result");
        }
    
    nimage.src = "process.aspx?category=analyze"
    + "&func=" + func 
    + ids
    + "&xtr=" + anow;
    
    data = "";
    while( data == "")
        data = checkdata();    
    
}


function checkdata()
{
var vic_cw_cookies;
var cdata;
var subdata;
var data;
var cookiename;
var j;
var k;

    data = "";
    if(document.cookie != "") {
        vic_cw_cookies = document.cookie.split("; ");
        
        for(j = 0; j < vic_cw_cookies.length; j++) {
            cookiename = vic_cw_cookies[j].split("=")[0];
            if(cookiename == "data") {
                cdata = vic_cw_cookies[j].split("=")[1];
                subdata = cdata.split("~");
                for(k = 0; k < subdata.length; k++) {
                    if(subdata[k] != "0")
                        data = data + "<br>" + subdata[k];
                    }
                }
            }
        }
    return (data);    
}


function select_textaddition(sourceObject)
{
var nimage;
var val1 = 20;
var val2 = 240;
var val3 = 255;
var func = sourceObject.id;
var anow;

    anow = new Date();   // to tack on a random number so to the browser it is a new url

    switch(func)
    {
    case "addtext": case "addtext2":
        func = "addtext";
        val1 = document.getElementById("texttoadd").value;
        val2 = document.getElementById("pointsize").value;
        val3 = document.getElementById("textx").value;
        val4 = document.getElementById("texty").value;
        val5 = document.getElementById("textred").value;
        val6 = document.getElementById("textgrn").value;
        val7 = document.getElementById("textblu").value;
      break;
      
     default:
     ;
     }
     
    // Determine which image is to be processed
    
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
    
   
    nimage.src = "process.aspx?category=process2"
    + "&func=" + func + "&id=img_" + ax
    + "&val1=" + val1 + "&val2=" + val2 + "&val3=" + val3 
    + "&val4=" + val4 + "&val5=" + val5 + "&val6=" + val6 
    + "&val7=" + val7 
    + "&xtr=" + anow;
}


function loadimagefromweb(sourceObject)
{
var nimage;
var fname;
var func = "loadfromweb";
var anow;

    fname = document.getElementById("fname").value;
    anow = new Date();   // to tack on a random number so to the browser it is a new url
    
    // Determine which image is to be processed
    var ax;
    ax = document.getElementById("activeimage2").innerHTML;
    
    nimage = document.getElementById("img_" + ax);
    
   // nimage.src = "bass.jpg";
    nimage.src = "process.aspx?category=loadfile&func=" + "loadurlimage" + "&id=img_" + ax
    + "&fname=" + fname
    + "&loadfile=1" 
    + "&xtr=" + anow;
}

function uploader(sourceObject)
{
var anow;

anow = new Date();   // to tack on a random number so to the browser it is a new url

var ax;
ax = document.getElementById("activeimage2").innerHTML;

if(ax == "source")
    document.form2.action = "process.aspx?category=loadfile&func=upload&id=img_source&xtr=" + anow; 
if(ax == "operator")
    document.form2.action = "process.aspx?category=loadfile&func=upload&id=img_operator&xtr=" + anow; 
if(ax == "result")
    document.form2.action = "process.aspx?category=loadfile&func=upload&id=img_result&xtr=" + anow; 
}

function viewer()
{
var anow;

    var ax;
    ax = document.getElementById("activeimage2").innerHTML;

anow = new Date();   // to tack on a random number so to the browser it is a new url
if(ax == "source")
    document.getElementById("img_source").src="process.aspx?category=process1&func=refresh&id=img_source&xtr=" + anow; 
if(ax == "operator")
    document.getElementById("img_operator").src="process.aspx?category=process1&func=refresh&id=img_operator&xtr=" + anow; 
if(ax == "result")
    document.getElementById("img_result").src="process.aspx?category=process1&func=refresh&id=img_result&xtr=" + anow; 
}

function viewall()
{
var anow;


anow = new Date();   // to tack on a random number so to the browser it is a new url
document.getElementById("img_source").src="process.aspx?category=process1&func=refresh&id=img_source&xtr=" + anow; 
document.getElementById("img_operator").src="process.aspx?category=process1&func=refresh&id=img_operator&xtr=" + anow; 
document.getElementById("img_result").src="process.aspx?category=process1&func=refresh&id=img_result&xtr=" + anow; 
}

function set_timer_to_refresh(sourceObject)
{
var timeoutID = setTimeout("viewer()", 200);
}

function hidedatabox(sourceObject){
var databox;

databox = document.getElementById("databox");
databox.style.visibility = "hidden";
}

function view_rcode(sourceObject)
{
var vic_cw_cookies;
var rcode;
var active;
var newimage;
var vinfo;
var cdata;
var subdata;
var data;
var cookiename;
var j;
var k;

var databox;

rcode = "";
active = "";
newimage = "";
vinfo = "";
data = "";


databox = document.getElementById("databox");

if(document.cookie != "") {
    vic_cw_cookies = document.cookie.split("; ");
    
    for(j = 0; j < vic_cw_cookies.length; j++) {
        cookiename = vic_cw_cookies[j].split("=")[0];
        if(cookiename == "rcode")
            rcode = vic_cw_cookies[j].split("=")[1];
        if(cookiename == "active")
            active = vic_cw_cookies[j].split("=")[1];
        if(cookiename == "newimage")
            newimage = vic_cw_cookies[j].split("=")[1];
        if(cookiename == "vinfo")
            vinfo = vic_cw_cookies[j].split("=")[1];
        if(cookiename == "data") {
            cdata = vic_cw_cookies[j].split("=")[1];
            subdata = cdata.split("~");
            for(k = 0; k < subdata.length; k++) {
                if(subdata[k] != "0")
                    data = data + "<br>" + subdata[k];
                }
            }
        }
    }
    
if(active == "")
    active = "source";    
//document.getElementById("returncode").innerHTML = rcode; 

if((data != "0") && (data != "")) {
    document.getElementById("datawindow").innerHTML = data; 
    databox.style.visibility = "visible";
    }
else {
    document.getElementById("activeimage2").innerHTML = active;
    document.getElementById(active + "_dim").innerHTML = vinfo;
    databox.style.visibility = "hidden";        
    }

document.cookie = "data=0";

if(newimage == "1") 
    viewall();
}


