﻿var X_Click = 0;
var Y_Click = 0;

var type = 0;
var prevPoint = 0;

function initialize(newType) {
    type = newType;
}
function loadImage(imageName) {
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
        theform = document.forms["Form1"];
    }
    else {
        theform = document.Form1;
    }

    theform.PBCommand.value = "LoadImage";
    theform.PBParams.value = imageName;

    theform.submit();
}

function calcDistance() {
    type = 1;
    prevPoint = 0;
}
function calcHeight() {
    type = 2;
    prevPoint = 0;
}
function calcElevation() {
    type = 3;
    prevPoint = 0;
}
function calcBearing() {
    type = 4;
    prevPoint = 0;
}


function imagemousedown(e) {
    curEvent = (typeof event == 'undefined' ? e : event)

    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
        theform = document.forms["Form1"];
    }
    else {
        theform = document.Form1;
    }

    if (type == 1) {
        if (prevPoint == 0) {
            prevPoint = curEvent.clientX + " " + curEvent.clientY;
        }
        else {
            theform.PBCommand.value = "Distance";
            theform.PBParams.value = prevPoint + " " + curEvent.clientX + " " + curEvent.clientY;

            prevPoint = 0;

            theform.submit();
        }
    }
    else if (type == 2) {
        if (prevPoint == 0) {
            prevPoint = curEvent.clientX + " " + curEvent.clientY;
        }
        else {
            theform.PBCommand.value = "Height";
            theform.PBParams.value = prevPoint + " " + curEvent.clientX + " " + curEvent.clientY;

            prevPoint = 0;

            theform.submit();
        }
    }
    else if (type == 3) {
        prevPoint = 0;

        theform.PBCommand.value = "Elevation";
        theform.PBParams.value = curEvent.clientX + " " + curEvent.clientY;
        theform.submit();
    }
    else if (type == 4) {
        if (prevPoint == 0) {
            prevPoint = curEvent.clientX + " " + curEvent.clientY;
        }
        else {
            theform.PBCommand.value = "Bearing";
            theform.PBParams.value = prevPoint + " " + curEvent.clientX + " " + curEvent.clientY;

            prevPoint = 0;

            theform.submit();
        }
    }
}

function displayLocation(isShowLocation) {
    if (isShowLocation == true) {
        var message = "Location";
        var context = "Location";
        WebForm_DoCallback('__Page', message, getCallbackResult, context, postBackError, true);
    } else {
        hideLayer1("LocationIcon");
    }

}
function getCallbackResult(rStr, Opt) {
//    alert(Opt + " == " + rStr);
//    return true;
    if (Opt == "Identify") {
        if(rStr!=""){
            var str = rStr.split(":");
            DisplayInfoWin(str[0], str[1]);
        }
        else {
            hideInfoWinDiv();
        }
    } else if (Opt == "Location") {
        var xy = rStr.split(",");
        showLocation(xy[0], xy[1]);    
    }


}
function postBackError() {
    alert("error");
}

//glow function
function showLocation(x, y) {
//    alert(x + " " + y);
    if ((x !=-1) || (y != -1) ) {
        var xcor = parseInt(x) + 31;
        var ycor = parseInt(y) + 30 + 61;

        moveLayer1("LocationIcon", xcor, ycor);
        showLayer1("LocationIcon");
    } else {
        hideLayer1("LocationIcon");
    }
}
// toggle layer to invisible
function hideLayer1(name) {
    var layer = getLayer1(name);
    if (layer != null) layer.visibility = "hidden";
    return false;
}

// toggle layer to visible
function showLayer1(name) {
    var layer = getLayer1(name);
    if (layer != null) layer.visibility = "visible";
    return false;
}

// move layer to x,y
function moveLayer1(name, x, y) {
    var layer = getLayer1(name);
    if (layer != null) {
        layer.left = x + "px";
        layer.top = y + "px";
    }
    return false;
}
// get the layer object called "name"
function getLayer1(name) {
    var theObj = document.getElementById(name);
    if (theObj != null) return theObj.style;
    else return (null);
}


//function btnRight_Click() {
//    var message = "btnRight_Click";
//    var context = "btnRight_Click";
//    WebForm_DoCallback('__Page', message, processCallbackResult, context, postBackError, true);
//}
function onload() {
    toggleLocation();
}

function toggleLocation() { 
    var isLocationChecked = document.getElementById("CkLocation");
    var isShowLocation = false;
    if (isLocationChecked.checked == true) {
        isShowLocation = true;
    } else {
        isShowLocation = false;
    }
    displayLocation(isShowLocation);
}

function CenterAt(e) {
//    curEvent = (typeof event == 'undefined' ? e : event)
//    X_Click = curEvent.clientX;
//    Y_Click = curEvent.clientY;
//    var xcor = parseInt(curEvent.clientX) - 30;
//    var ycor = parseInt(curEvent.clientY) - 30 - 61;
//    
//    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
//        theform = document.forms["form1"];
//    }
//    else {
//        theform = document.forms[0];
//    }
//    theform.cmd.value = "CenterAt";
//    theform.x_coor.value = xcor;
//    theform.y_coor.value = ycor;

//    //            alert(curEvent.clientX + " " + curEvent.clientY);
    //    theform.submit();
    return true;
    
    
    curEvent = (typeof event == 'undefined' ? e : event)
    X_Click = curEvent.clientX;
    Y_Click = curEvent.clientY;
    var xcor = parseInt(curEvent.clientX) - 30;
    var ycor = parseInt(curEvent.clientY) - 30 - 61;
    var message = "CenterAt:" + xcor + ":" + ycor;
    var context = "CenterAt";
    WebForm_DoCallback('__Page', message, getCallbackResult, context, postBackError, true);
}

function Identify(e) {
    curEvent = (typeof event == 'undefined' ? e : event)
    X_Click = curEvent.clientX;
    Y_Click = curEvent.clientY;
    var xcor = parseInt(curEvent.clientX) - 30;
    var ycor = parseInt(curEvent.clientY) - 30 - 61;
    var message = "Identify:" + xcor + ":" + ycor; 
    var context = "Identify";
    WebForm_DoCallback('__Page', message, getCallbackResult, context, postBackError, true);
}

function DisplayInfoWin(pid, address) {
    var content=''; 
    content += '<div id="InfoWinTitle" ><table ><tr><td width="100%" align="center" ><b>Parcel Info</B></td><td width="15" valign="top"><img onclick="hideInfoWinDiv();" style="float: right; CURSOR: pointer" onmouseover="this.src =\'images/close_o.gif\'" onmouseout="this.src = \'images/close.gif\'" height="13" alt="Close" src="images/close.gif" /></td><tr></table></div>';
    content += '<div><table border="0" cellpadding="0" cellspacing="2" >';
    content += '<tr><td colspan="3" nowrap>PID: <a href="http://www2.ocpafl.org/searches/ParcelSearch.aspx?pid=' + pid + '" target="_detail">' + pid + '</a></td></tr>';
    content += '<tr><td colspan="3" >ADDRESS: ' + address + '</td></tr>';
    content += '</table></div>';
    document.getElementById('InfoWinDiv').innerHTML = content;
//    var InfoWinDiv = getLayer("InfoWinDiv");
//    InfoWinDiv.innerHTML = content;
    var x = parseInt(X_Click) + 5;
    var y = parseInt(Y_Click) + 5;
    moveLayer1("InfoWinDiv", x, y);
    showLayer1("InfoWinDiv");
}

function hideInfoWinDiv() {
    var InfoWinDiv = getLayer1("InfoWinDiv");
    InfoWinDiv.visibility = "hidden";
}
