﻿var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;

var dragobj = null;

function falsefunc() { return false; } // used to block cascading events

function init(btn, tb) {
    document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
    update();
    var textBox = document.getElementById(tb);
    var saveButton = document.getElementById(btn);
    textBox.setAttribute("class", "editShow");
    textBox.style.width = "50px";
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{
    if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

    if (e) {
        if (e.pageX || e.pageY) { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
            mousex = e.pageX;
            mousey = e.pageY;
            algor = '[e.pageX]';
            if (e.clientX || e.clientY) algor += ' [e.clientX] '
        }
        else if (e.clientX || e.clientY) { // works on IE6,FF,Moz,Opera7
            mousex = e.clientX + document.body.scrollLeft;
            mousey = e.clientY + document.body.scrollTop;
            algor = '[e.clientX]';
            if (e.pageX || e.pageY) algor += ' [e.pageX] '
        }
    }
}

function update(e) {
    getMouseXY(e); // NS is passing (event), while IE is passing (null)
    //    document.getElementById('span_browser').innerHTML = navigator.appName;
    //    document.getElementById('span_winevent').innerHTML = window.event ? window.event.type : '(na)';
    //    document.getElementById('span_autevent').innerHTML = e ? e.type : '(na)';
    //    document.getElementById('span_mousex').innerHTML = mousex;
    //    document.getElementById('span_mousey').innerHTML = mousey;
    //    document.getElementById('span_grabx').innerHTML = grabx;
    //    document.getElementById('span_graby').innerHTML = graby;
    //    document.getElementById('span_orix').innerHTML = orix;
    //    document.getElementById('span_oriy').innerHTML = oriy;
    //    document.getElementById('span_elex').innerHTML = elex;
    //    document.getElementById('span_eley').innerHTML = eley;
    //    document.getElementById('span_algor').innerHTML = algor;
    //    document.getElementById('span_dragobj').innerHTML = dragobj ? (dragobj.id ? dragobj.id : 'unnamed object') : '(null)';
}

function grab(context) {
    document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
    dragobj = context;
    dragobj.style.zIndex = 10; // move it to the top
    document.onmousemove = drag;
    document.onmouseup = drop;
    grabx = mousex;
    graby = mousey;
    elex = orix = dragobj.offsetLeft;
    eley = oriy = dragobj.offsetTop;
    update();
}

function drag(e) // parameter passing is important for NS family 
{
    if (dragobj) {
        elex = orix + (mousex - grabx);
        eley = oriy + (mousey - graby);
        dragobj.style.position = "absolute";
        dragobj.style.left = (elex).toString(10) + 'px';
        dragobj.style.top = (eley).toString(10) + 'px';
    }
    update(e);
    return false; // in IE this prevents cascading of events, thus text selection is disabled
}

function drop() {
    if (dragobj) {
        dragobj.style.zIndex = 0;
        dragobj = null;
    }
    update();
    document.onmousemove = update;
    document.onmouseup = null;
    document.onmousedown = null;   // re-enables text selection on NS
}
//line 96
function getPos(el) {
    // yay readability
    for (var lx = 0, ly = 0;
         el != null;
         lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return { x: lx, y: ly };
}



function showTb(tb, btn, setTo, price, id, hidden) {
    var textBox = document.getElementById(tb);
    var saveButton = document.getElementById(btn);
    var hiddenInput = document.getElementById(hidden);
    var location = document.getElementById(setTo);
    var progress = document.getElementById("progress");
    var pos = getPos(location);
    var jsHide = "javascript:hideTb('" + tb + "', '" + btn + "');";
    var locWidth = location.offsetWidth + 6;
    var tbLeft = (pos.x + locWidth);
    var tbTop = pos.y-2;
    var btnLeft = (tbLeft + textBox.offsetWidth);
    var btnTop = pos.y;
    var proLeft = tbLeft;
    var proTop = pos.y-2;

    textBox.setAttribute("class", "editShow");
    saveButton.setAttribute("class", "editShow");
    saveButton.setAttribute("onclick", jsHide);
    textBox.style.left = tbLeft + "px";
    textBox.style.top = tbTop + "px";
    saveButton.value = "Save";
    saveButton.style.left = btnLeft + "px";
    saveButton.style.top = btnTop + "px";
    progress.style.left = proLeft + "px";
    progress.style.top = proTop + "px";
    textBox.value = price;
    hiddenInput.value = id.toString();

}

function moveUploadDiv() {
    var divUpload = document.getElementById("divUploadFile");
    var divDescription = document.getElementById("divDescribe");

}

function hide(tb, btn) {
    var textBox = document.getElementById(tb);
    var saveButton = document.getElementById(btn);
    if (event.keyCode == 13) {
        hideTb(tb, btn);
    }

}

function hideTb(tb, btn) {
    var textBox = document.getElementById(tb);
    var saveButton = document.getElementById(btn);
    textBox.setAttribute("class", "edit");
    saveButton.setAttribute("class", "edit");
}
//line 152
function hideEl(el1,el2) {
    var elem1 = document.getElementById(el1);
    var elem2 = document.getElementById(el2);
    elem1.style.visibility = "hidden";
    elem2.style.visibility = "visible";

}

function literal(title, text, el1, el2) {
    var elem1 = document.getElementById(el1);
    var elem2 = document.getElementById(el2);
    elem1.value = title;
    elem2.value = text;
}

function readSteps(str) {
    var strArray = new Array();
    var splitSteps = new Array();
    splitSteps=str.split("::");
    for (cnt = 0; cnt < splitSteps.length; cnt++) {
        var splitTitle = splitSteps[cnt].split("**");
        if (splitTitle[0] != "") {
            strArray[cnt] = [splitTitle[0], splitTitle[1], splitTitle[2]];
        }
    }
    return strArray;
}

function getText(str, control) {
    var s = "";
    var strArray = new Array();
    strArray = readSteps(str);
    for (cnt = 0; cnt < strArray.length; cnt++) {
        if (strArray[cnt][2] == control) {
            s = strArray[cnt][1];
            
        }
    }
    return s;
}
//202
function getTitle(str, control) {
    var s = "";
    var strArray = new Array();
    strArray = readSteps(str);
    for (cnt = 0; cnt < strArray.length; cnt++) {
        if (strArray[cnt][2] == control) {
            s = strArray[cnt][0];

        }
    }
    return s;
}

function getPW(pwID) {
    var pw = document.getElementById(pwID);
    pwID.value = pwID.Text;

}

function setWidths() {
    var content = document.getElementById("fullRequest");
    var div1 = document.getElementById("demographic");
    var div2 = document.getElementById("request");
    var div3 = document.getElementById("steps");
    var contentWidth = content.offsetWidth;
    var div1Margins = 30;
    var div2Margins = 23;
    var div3Margins = 23;
    var divWidth1 = parseInt((contentWidth / 3) - div1Margins);
    var divWidth2 = parseInt((contentWidth / 3) - div2Margins);
    var divWidth3 = parseInt((contentWidth / 3) - div3Margins);
    div1.style.width = divWidth1 + "px";
    div2.style.width = divWidth2 + "px";
    div3.style.width = divWidth3 + "px";

}


