/********************************************************************************************************
 *RESOLUTION INTERACTIVE MEDIA INC.																		*
 *560 Wellington Street, London, Ontario, Canada														*
 *Jonathan Kochis (jonathan@resolutionim.com)															*
 *Brendan Farr-Gaynor (brendan@resolutionim.com)														*
 *Owain Johnson (owain@resolutionim.com)																*
 *																										*
 *Version: 1.00 Brendan Farr-Gaynor - 11/17/2006: Added handlers for res2.0 ajax cms 					*
 *Version: 0.90 Brendan Farr-Gaynor - 11/17/2006: Extended master ajax functions to run					*
 *												  multiple connections concurrently						*
 ********************************************************************************************************
 *Date Last Modified: 11/17/06																			*
 *Last Modified By: brendan@resolutionim.com												 			*
 *																										*
 ********************************************************************************************************/
/****************************** GIVE ME A BOX TOGGLE GRAPHICS ***********************************/
/*
These are global variables that need to be included on every page. They are used by the toggle js functions in giveMeABox()
*/
var toggleOpenPic = new Image;
var toggleClosePic = new Image;
toggleOpenPic.src = "/images/arrow1.gif";
toggleClosePic.src = "/images/arrow2.gif";
function toggleMyGiveMeABoxTog(myGID) {
    var str = document.getElementById(myGID).src;
    if (str.indexOf("arrow1.gif") != -1) {
        document.getElementById(myGID).src = toggleClosePic.src;
    } else {
        document.getElementById(myGID).src = toggleOpenPic.src;
    }
    //alert();
    //= closePic.src;
    ///////alert(document.getElementById(myGID).src);
}
/****************************** END GIVE ME A BOX TOGGLE GRAPHICS ***********************************/
/****************************** RESOLUTION MASTER AJAX FUNCTIONS ***********************************/
/*
The following are global functions to be used with all new AJAX activity, some applications require thier
own AJAX functions but these should cover the majority.
*/
//array that stores all ajax request objects
var masterRO = new Array();
function resCreateNewRequestObject() {
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        masterRO[masterRO.length] = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        masterRO[masterRO.length] = new XMLHttpRequest();
    }
    return masterRO.length - 1;
    //masterRO[masterRO.length];
}
function resSndReqPOST(url, params, whatFunctionToRun) {
    //new function to handle POST requests
    reshttp = masterRO[resCreateNewRequestObject()];
    //alert(whatFunctionToRun);
    resAJAXRequestStarted = true;
    var functionToSend = whatFunctionToRun;
    reshttp.open('POST', url, true);
    reshttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reshttp.setRequestHeader("Content-length", params.length);
    reshttp.setRequestHeader("Connection", "close");
    reshttp.onreadystatechange = function () {
        //data is loaded
        if (reshttp.readyState == 4) {
            resAJAXRequestStarted = false;
            var resResponse = reshttp.responseText;
            var arrayToSendBack = new Array();
            if (resResponse.indexOf('|' != -1)) {
                //							alert(resResponse);
                arrayToSendBack = resResponse.split('|');
                if (functionToSend != false) {
                    eval(functionToSend + "(arrayToSendBack);");
                }
            }
        }
        // end of data loaded
    }
    reshttp.send(params);
}
function resSndReq(queryStringToSend, whatFunctionToRun) {
    reshttp = masterRO[resCreateNewRequestObject()];
    resAJAXRequestStarted = true;
    var functionToSend = whatFunctionToRun;
    reshttp.open('get', queryStringToSend, true);
    reshttp.onreadystatechange = function () {
        //data is loaded
        if (reshttp.readyState == 4) {
            resAJAXRequestStarted = false;
            var resResponse = reshttp.responseText;
            var arrayToSendBack = new Array();
            if (resResponse.indexOf('|' != -1)) {
                //							alert(resResponse);
                arrayToSendBack = resResponse.split('|');
                if (functionToSend != false) {
                    eval(functionToSend + "(arrayToSendBack);");
                }
            }
        }
        // end of data loaded
    }
    reshttp.send(null);
}
/************************** END OF RESOLUTION MASTER AJAX FUNCTIONS ***********************************/
/************************** RESOLUTION ADMIN AJAX FUNCTIONS (these depend upon the master ajax functions) ******/
function resTblEditorToggleAdminSlider(editString, listItemString) {
    //HACK to get around bug in mozilla's implementation of designMode
    //designMode = 'On' fails horribly when the target is hidden (hope they fix that soon, till then....)
    Effect.toggle(editString, 'slide');
    //the div is available for init
    tempVar = "global" + listItemString;
    tempVar = eval(tempVar);
    if (document.getElementById(editString).style.display == 'none') {
        for (i = 0; i < tempVar.length; i++) {
            setTimeout("Init('" + tempVar[i] + "')", 500);
        }
    }
    //THE FOLLOWING SNIPPED WAS DUPLICATED HERE FROM ORDER UPDATE BECAUSE WYSIWYG FIELDS WERE GETTING BLANKED 
    /////////////////////////
    //first figure out if there are any editors here (all WYSIWYG editors are stored in an array with a similar name)
    wyName = "global" + listItemString;
    wysForThisRow = eval(wyName);
    for (i = 0; i < wysForThisRow.length; i++) {
        //and chaos ensues
        if (navigator.appName == "Netscape") {
            eval("dragStore" + wyName + "[" + i + "] = document.getElementById(wysForThisRow[" + i + "]).contentDocument.body.innerHTML;");
        } else { //damn IE why can't you be standards compliant
            eval("dragStore" + wyName + "[" + i + "] = wysForThisRow[" + i + "].document.body.innerHTML;");
        }
    }
    ////////////////////////
}
function resTblEditorInsertANewBlankRecord(table, tblKeyString) {
    //this will insert a new blank record with 'active' set to 2 so that it's not displayed on the front end
    //when the user updates/saves, the record's 'active' will be set to the tradional default of 1.
    //alert("You are creating a new record in: " + table + " with the string: " + tblKeyString);
    //alert('resQuery.php?a=nbl&tbl=' + table + '&tblKeyString=' + tblKeyString);
    resSndReq('resQuery.php?a=nbl&tbl=' + table + '&tblKeyString=' + tblKeyString, 'resTblEditorInsertANewBlankRecordComplete');
}
function resTblEditorInsertANewBlankRecordComplete(respArray) {
    //this will pull back the itemID of the latest insert from respArray as well as the table id
    //it will then look through the template storage array to pull out the proper template
    // a find and replace will then replace the JSSTRING with the new proper ID
    //alert('Inserted Record:' + respArray[1]);
    document.getElementById(respArray[2]).innerHTML = globalResTblEditorNewItemTemplates[respArray[2]].replace(/IMNEWREPLACEME/g, respArray[1]) + document.getElementById(respArray[2]).innerHTML;
    //alert(globalResTblEditorNewItemTemplates[respArray[2]].replace(/IMNEWREPLACEME/g, respArray[1]));
    Effect.toggle('table_' + respArray[3] + '_edit_' + respArray[1], 'slide');
    //re-init 'sortable' as a new item has been dynamically added
    Sortable.create(respArray[2], {
        dropOnEmpty: true,
        containment: [respArray[2]],
        constraint: false,
        onUpdate: resTblEditorUpdateOrder
    });
}
var allowChange = true;
function resTblEditorDragChange(whatElement) {
    if (allowChange) {
        allowChange = false;
        /*
			sortable will blanks any WYSIWYG editors in this item
			so we must save out the HTML in the editor (if it exists)
			to a variable that can later populate the editor
		*/
        //first figure out if there are any editors here (all WYSIWYG editors are stored in an array with a similar name)
        wyName = "global" + whatElement.id;
        wysForThisRow = eval(wyName);
        for (i = 0; i < wysForThisRow.length; i++) {
            //and chaos ensues
            //we only want to run init() if the toggle is open, therefore we must detect the open/close state by determining the parent toggle
            divSet = whatElement.id.split('num');
            idSet = whatElement.id.split('_');
            if (document.getElementById("table_" + divSet[0] + "_edit_" + idSet[1]).style.display != 'none') { // run this *ONLY* if the toogle is open (haven't added that yet)
                if (navigator.appName == "Netscape") {
                    eval("dragStore" + wyName + "[" + i + "] = document.getElementById(wysForThisRow[" + i + "]).contentDocument.body.innerHTML;");
                } else { //damn IE why can't you be standards compliant
                    eval("dragStore" + wyName + "[" + i + "] = wysForThisRow[" + i + "].document.body.innerHTML;");
                }
            }
        }
    }
}
function resTblEditorUpdateOrder(whatElement) {
    //re-write the content to any WYSIWYG editors that may exist in this row
    wyName = "global" + whatElement.id;
    allowChange = true;
    for (var i = 0; i < whatElement.childNodes.length; i++) {
        //textContent += getTextContent(node.childNodes[i]);
        thisNode = whatElement.childNodes[i];
        if (thisNode.nodeName == "LI") { //must be a LI or other html tag
            if (eval("dragStoreglobal" + thisNode.id)) {
                for (j = 0; j < eval("dragStoreglobal" + thisNode.id + ".length"); j++) {
                    if (navigator.appName == "Netscape") {
                        document.getElementById(eval('global' + thisNode.id + '[' + j + ']')).contentDocument.body.innerHTML = eval("dragStoreglobal" + thisNode.id + "[" + j + "]");
                    } else { //damn IE why can't you be standards compliant
                        eval('global' + thisNode.id + '[' + j + ']').document.body.innerHTML = eval("dragStoreglobal" + thisNode.id + "[" + j + "]");
                    }
                    //we only want to run init() if the toggle is open, therefore we must detect the open/close state by determining the parent toggle
                    divSet = thisNode.id.split('num');
                    idSet = thisNode.id.split('_');
                    if (document.getElementById("table_" + divSet[0] + "_edit_" + idSet[1]).style.display != 'none') {
                        Init(eval('global' + thisNode.id + '[' + j + ']'));
                    }
                }
            }
        }
    }
    //send the new order to the db
    for (i = 0; i < tableIDKeeper.length; i++) {
        if (i == 0) {
            newOrderToSend = "&";
        }
        newOrderToSend += Sortable.serialize(tableIDKeeper[i]);
        //alert('resQuery.php?a=upo&ts='+ tableIDKeeper[i] + newOrderToSend);
        // alert('resQuery.php?a=upo&ts='+ tableIDKeeper[i] + newOrderToSend);
        resSndReq('resQuery.php?a=upo&ts=' + tableIDKeeper[i] + newOrderToSend, 'resTblEditorUpdateOrderComplete');
    }
}
function resTblEditorUpdateOrderComplete(respArray) {
    for (var i = 0; i < document.getElementById(respArray[1]).childNodes.length; i++) {
        //textContent += getTextContent(node.childNodes[i]);
        thisNode = document.getElementById(respArray[1]).childNodes[i];
        if (thisNode.nodeName == "LI") { //must be a LI or other html tag
            //highlight the parent li (needs to change to reflect new li name)
            new Effect.Highlight(thisNode);
        }
    }
}
function resTblEditorConfirmDelete(table, itemID, tblkey, message) {
    if (confirm(message)) {
        //show the wait graphic
        document.getElementById('table_' + table + '_waitG_' + itemID).style.display = 'block';
        //table_" .$_REQUEST['tbl'] . "_waitG_" . $_REQUEST['id'];
        resSndReq('resQuery.php?a=del&tbl=' + table + '&id=' + itemID + '&tblkey=' + tblkey, 'resTblEditorCompleteDelete');
    }
}
function resTblEditorCompleteDelete(respArray) {
    //hide the wait graphic
    document.getElementById(respArray[1]).style.display = 'none';
    //this item is now technically deleted so remove it from the list items
    Effect.Fade(respArray[2]);
    //document.getElementById(respArray[2]).style.display = 'none';
}
globalResTblEditorLastVars = "Nothing yet."
function packageThisAndUpdate(table, itemID, tblkey, formID) {
    globalResTblEditorLastVars = new Object();
    //loop through the items in the provided form
    stringToWrite = "";
    fToSecure = "";
    thisForm = document.getElementById(formID).elements;
    for (i = 0; i < thisForm.length; i++) {
        stringToWrite += "&" + thisForm[i].name + "=" + escape(thisForm[i].value);
        //save this so we may update the screen later (after 'save changes') to simulate a page refresh
        globalResTblEditorLastVars[thisForm[i].name] = thisForm[i].value;
        fToSecure += thisForm[i].name;
    }
    //alert("Updating: " + itemID);
    //////////////////////
    //first figure out if there are any editors here (all WYSIWYG editors are stored in an array with a similar name)
    wyName = "global" + table + "num" + tblkey + "_" + itemID;
    wysForThisRow = eval(wyName);
    for (i = 0; i < wysForThisRow.length; i++) {
        //and chaos ensues
        //alert(wysForThisRow[i]);
        if (navigator.appName == "Netscape") {
            stringToWrite += "&" + wysForThisRow[i] + "=" + escape(document.getElementById(wysForThisRow[i]).contentDocument.body.innerHTML);
            globalResTblEditorLastVars[wysForThisRow[i]] = document.getElementById(wysForThisRow[i]).contentDocument.body.innerHTML;
            fToSecure += wysForThisRow[i];
        } else { //damn IE why can't you be standards compliant
            stringToWrite += "&" + wysForThisRow[i] + "=" + escape(wysForThisRow[i].document.body.innerHTML);
            globalResTblEditorLastVars[wysForThisRow[i]] = document.getElementById(wysForThisRow[i]).contentDocument.body.innerHTML;
            fToSecure += wysForThisRow[i];
        }
    }
    //////////////////////
    resSndReq('resQuery.php?fToSecure=' + fToSecure + '&a=upd&tbl=' + table + '&tblkey=' + tblkey + '&id=' + itemID + stringToWrite, 'resTblEditorCompleteUpdate');
    //alert(stringToWrite);
}
function resTblEditorCompleteUpdate(respArray) {
    //hide the wait graphic
    document.getElementById(respArray[1]).style.display = 'none';
    //highlight the parent li (needs to change to reflect new li name)
    new Effect.Highlight(respArray[2]);
    //update the div data in the divs located in the display div (then say it 3 times fast)
    whatToAlert = "";
    for (var i = 0; i < document.getElementById(respArray[3]).childNodes.length; i++) {
        //textContent += getTextContent(node.childNodes[i]);
        thisNode = document.getElementById(respArray[3]).childNodes[i];
        if (thisNode.nodeName == "DIV") { //must be a div or other html tag
            //alert(thisNode.id);
            myFieldNameArray = thisNode.id.split('_');
            //now loop through the labels in globalResTblEditorLastVars to see if we have matches
            for (var currentFieldName in globalResTblEditorLastVars) {
                //whatToAlert = 'getting here' + currentFieldName + " = " + myFieldNameArray[0];
                if (currentFieldName.substr(7) == myFieldNameArray[0]) {
                    thisNode.innerHTML = globalResTblEditorLastVars[currentFieldName];
                }
            }
        }
    }
}
/************************** END OF RESOLUTION ADMIN AJAX FUNCTIONS ************************************/
//Resolution WYSIWYG functions
var storePathToFilePathField = null;
function resCustomFileBrowser(field_name, url, type, win) {
    // Custom browser logic
    //alert('field_name: ' + field_name + '\n url: ' + url + '\n type: ' + type + '\n win: ' + win);
    //use the following to reference the field
    //win.document.forms[0].elements[field_name].value = 'my browser value';
    //loaderPopup(type);
    storePathToFilePathField = win.document.forms[0].elements[field_name];
    loaderPopupWin = window.open("/inc/tinyLoader.php?uploadType=" + type, "loaderPopup", "scrollbars=no,width=330,height=150");
}
function confirmDownloadDelete(loc) {
    if (confirm("You are about to permanently delete this file. Are you sure you want to do this?")) {
        window.location = loc;
    }
}
function confirmDelete(loc) {
    if (confirm("Are you sure you would like to delete this listing?")) {
        window.location = loc;
    }
}
var x = false;
var xSet = false;
var IEFlag = false;
function setActiveName(nameToSet) { //switches X var to the active
    if (navigator.appName == "Netscape") {
        if (x = document.getElementById(nameToSet).contentDocument) {
            return true;
        }
    } else { //damn IE why can't you be standards compliant
        //alert("I must be IE");
        IEFlag = true;
        if (x = eval(nameToSet + ".document")) { //iView.document;
            //if(x = document.getElementById(nameToSet).document) { 
            while (!x) {
                //do nothing	
            }
            if (x != false) {
                return true;
            }
        }
    }
}
function cleanWordHTML() {
    //ugh, well here it is, 
    //this should only be run if the user pastes something in and they are using IE
    //we must run the content off the clipboard through this puppy to deal with the 
    //possibility of Word HTML which will almost always break a layout
    html = window.clipboardData.getData('Text');
    window.clipboardData.setData('Text', html.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/g, ''));
}
function Init(myName) { //turns on designMode and sets the first X
    //alert('calling init');
    if (setActiveName(myName)) {
        if (IEFlag) {
            propName = 'On';
        } else {
            propName = 'on';
        }
        if (setTimeout(function () {
            x.designMode = propName;
            return true;
        },
        100)) {
            xSet = true;
            return true;
        }
    }
    /**************************************************
     x.body.style.fontFamily = "Verdana";
     x.body.style.fontSize = "12px";
     x.body.bgColor = "";	
     x.body.text = '#000000';
     **************************************************/
}
function clearContent(myName) {
    setActiveName(myName);
    x.body.innerHTML = "";
}
function setContent(theContent, myName) {
    setActiveName(myName);
    //alert(x.name);
    x.body.style.fontFamily = "Verdana"
    x.body.style.fontSize = "11px"
    x.body.bgColor = "";
    x.body.text = '#000000';
    //BUGFIX 08/14/06 brendan@resolutionim.com
    //users seem to copy from word *a lot* so a call to clean out word
    //formatting before stuff was copied in is necessary, this will likely only work in IE
    if (IEFlag) {
        x.body.attachEvent("onbeforepaste", cleanWordHTML);
    }
    x.body.innerHTML = theContent;
    //alert('two');
}
function postIt(textareaName, myName) {
    setActiveName(myName);
    document.getElementById(textareaName).value = x.body.innerHTML;
}
/// specific action functions
var glbSetPhotoFloater = null;

function floatMe(myName, direction) {
    setActiveName(myName);
    alert(glbSetPhotoFloater);
    ///* try ONE */var sel = x.getSelection(); var range = x.createRange(sel); alert(range);
    ///* try TWO */
    /*	if(direction =='L') {
		str = ''; for (i = 0; i != x.getElementsByTagName('img').length; i++) { x.getElementsByTagName('img')[i].className = "floatLeft"; }
	} else {
		str = ''; for (i = 0; i != x.getElementsByTagName('img').length; i++) { x.getElementsByTagName('img')[i].className = "floatRight"; }
	}
/*****************/
    if (direction == 'L') {
        x.getElementsById(glbSetPhotoFloater).className = "floatLeft";
    } else {
        x.getElementsById(glbSetPhotoFloater).className = "floatRight";
    }
    /*****************/
    if (navigator.appName == "Netscape") {
        //			x.execCommand('inserthtml', '', 'ME ME ME Netscape');
    } else { //damn IE why can't you be standards compliant
        //			var sel = x.selection;
        //			var range = sel.createRange();
        //			range.pasteHTML('ME ME ME Not Netscape');
    }
    alert(x.getSelectedNode.type);
    /*****************/
}
function boldIt(myName) {
    setActiveName(myName);
    x.execCommand('bold', false, null);
}
function italIt(myName) {
    setActiveName(myName);
    x.execCommand('italic', false, null);
}
function ordListIt(myName) {
    setActiveName(myName);
    x.execCommand('insertorderedlist', false, null);
}
function supIt(myName) {
    setActiveName(myName);
    x.execCommand('superscript', false, null);
}
function subIt(myName) {
    setActiveName(myName);
    x.execCommand('subscript', false, null);
}
function bulListIt(myName) {
    setActiveName(myName);
    x.execCommand('insertunorderedlist', false, null);
}
function supIt(myName) {
    setActiveName(myName);
    x.execCommand('superscript', false, null);
}
function subIt(myName) {
    setActiveName(myName);
    x.execCommand('subscript', false, null);
}
function blockChange(myName, selectname) {
    setActiveName(myName);
    var cursel = document.getElementById(selectname).selectedIndex;
    /* First one is always a label */
    if (cursel != 0) {
        var selected = document.getElementById(selectname).options[cursel].value;
        document.getElementById(myName).contentWindow.document.execCommand('formatblock', false, selected);
        document.getElementById(selectname).selectedIndex = 0;
    }
    document.getElementById(myName).contentWindow.focus();
}
function linkIt(myName) {
    setActiveName(myName);
    //BUG FIX, IE had issues putting the content in the proper location if a prelim focus was not set, this works in both IE and Mozilla
    document.getElementById(myName).contentWindow.focus();
    if (navigator.appName == "Netscape") {
        var szURL = prompt("URL (ex. http://www.google.com)", ""); //Mozilla doensn't support new interface rendering and does not work with safari yet (as of 1.3)
        x.execCommand('createlink', false, szURL);
    } else {
        x.execCommand('CreateLink');
    }
}
function unlinkIt(myName) {
    setActiveName(myName);
    x.execCommand('unlink', false, null);
}
function alignIt(myName, myAction) {
    setActiveName(myName);
    var whatActionToCall = 'justify' + myAction;
    x.execCommand(whatActionToCall, false, null);
}
function indentIt(myName, myAction) {
    setActiveName(myName);
    x.execCommand(myAction, false, null);
}
function selOn(ctrl) {
    ctrl.style.borderColor = '#CDDAD7';
    ctrl.style.backgroundColor = '#FFFFFF';
    ctrl.style.cursor = 'hand';
}
function selOff(ctrl) {
    ctrl.style.borderColor = '#E7EEEC';
    ctrl.style.backgroundColor = '#E7EEEC';
}
function selDown(ctrl) {
    ctrl.style.backgroundColor = '#D3E4DF';
}
function selUp(ctrl) {
    ctrl.style.backgroundColor = '#E7EEEC';
}
//END OF WY FUNCTIONS
/* Resolution Interactive Media */
/* Developed By: Jonathan Kochis And Brendan Farr-Gaynor */
/* jonathan@teamresolution.com / brendan@teamresolution.com */
//Resolution Multi-Selector functions

function addToList(listField, newText, newValue) {
    if ((newValue == "") || (newText == "")) {
        alert("You cannot add blank values!");
    } else {
        var len = listField.length++; // Increase the size of list and return the size
        listField.options[len].value = newValue;
        listField.options[len].text = newText;
        listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered) //BUG FIX
    } // Ends the check to see if the value entered on the form is empty
}
function removeFromList(listField) {
    if (listField.length == -1) { // If the list is empty
        alert("There are no values which can be removed!");
    } else if (listField.options[listField.selectedIndex].text == "") { //If no value is selected
        alert("You cannot remove blank values!");
    } else {
        var selected = listField.selectedIndex;
        if (selected == -1) {
            alert("You must select an entry to be removed!");
        } else { // Build arrays with the text and values to remain
            var replaceTextArray = new Array(listField.length - 1);
            var replaceValueArray = new Array(listField.length - 1);
            for (var i = 0; i < listField.length; i++) {
                // Put everything except the selected one into the array
                if (i < selected) {
                    replaceTextArray[i] = listField.options[i].text;
                }
                if (i > selected) {
                    replaceTextArray[i - 1] = listField.options[i].text;
                }
                if (i < selected) {
                    replaceValueArray[i] = listField.options[i].value;
                }
                if (i > selected) {
                    replaceValueArray[i - 1] = listField.options[i].value;
                }
            }
            listField.length = replaceTextArray.length; // Shorten the input list
            for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
                listField.options[i].value = replaceValueArray[i];
                listField.options[i].text = replaceTextArray[i];
            }
        } // Ends the check to make sure something was selected
    } // Ends the check for there being none in the list
}
function moveUpList(listField) {
    if (listField.length == -1) { // If the list is empty
        alert("There are no values which can be moved!");
    } else {
        var selected = listField.selectedIndex;
        if (selected == -1) {
            alert("You must select an entry to be moved!");
        } else { // Something is selected 
            if (listField.length == 0) { // If there's only one in the list
                alert("There is only one entry!\nThe one entry will remain in place.");
            } else { // There's more than one in the list, rearrange the list order
                if (selected == 0) {
                    alert("The first entry in the list cannot be moved up.");
                } else {
                    // Get the text/value of the one directly above the hightlighted entry as
                    // well as the highlighted entry; then flip them
                    var moveText1 = listField[selected - 1].text;
                    var moveText2 = listField[selected].text;
                    var moveValue1 = listField[selected - 1].value;
                    var moveValue2 = listField[selected].value;
                    listField[selected].text = moveText1;
                    listField[selected].value = moveValue1;
                    listField[selected - 1].text = moveText2;
                    listField[selected - 1].value = moveValue2;
                    listField.selectedIndex = selected - 1; // Select the one that was selected before  //BUG FIX
                } // Ends the check for selecting one which can be moved
            } // Ends the check for there only being one in the list to begin with
        } // Ends the check for there being something selected
    } // Ends the check for there being none in the list
}
function moveDownList(listField) {
    if (listField.length == -1) { // If the list is empty
        alert("There are no values which can be moved!");
    } else {
        var selected = listField.selectedIndex;
        if (selected == -1) {
            alert("You must select an entry to be moved!");
        } else { // Something is selected 
            if (listField.length == 0) { // If there's only one in the list
                alert("There is only one entry!\nThe one entry will remain in place.");
            } else { // There's more than one in the list, rearrange the list order
                if (selected == listField.length - 1) {
                    alert("The last entry in the list cannot be moved down.");
                } else {
                    // Get the text/value of the one directly below the hightlighted entry as
                    // well as the highlighted entry; then flip them
                    var moveText1 = listField[selected + 1].text;
                    var moveText2 = listField[selected].text;
                    var moveValue1 = listField[selected + 1].value;
                    var moveValue2 = listField[selected].value;
                    listField[selected].text = moveText1;
                    listField[selected].value = moveValue1;
                    listField[selected + 1].text = moveText2;
                    listField[selected + 1].value = moveValue2;
                    listField.selectedIndex = selected + 1; // Select the one that was selected before //BUG FIX
                } // Ends the check for selecting one which can be moved
            } // Ends the check for there only being one in the list to begin with
        } // Ends the check for there being something selected
    } // Ends the check for there being none in the list
}
function submitBuckets(textfieldName, listField1) {
    var len1 = listField1.length;
    var buck1 = "";
    for (i = 0; i < len1; i++) {
        buck1 += listField1.options[i].value;
    }
    document.getElementById(textfieldName).value = buck1.substring(1);
    //alert(buck1);
}
//End Of Multi-Selector functions
function submitDateItem(textfieldName, prefix) {
    //submitDateItem('itemDateTimeEnd', 'ed');
    day = document.getElementById(prefix + "Day").value;
    month = document.getElementById(prefix + "Month").value;
    year = document.getElementById(prefix + "Year").value;
    hour = document.getElementById(prefix + "Hour").value;
    minute = document.getElementById(prefix + "Minute").value;
    AMPM = document.getElementById(prefix + "AMPM").value;
    //vvvvvvvvvvvv was setting 08/20 and 09/21 to 12/00	
    //	hour = parseInt(hour);
    //^^^^^^^^^^^^ was setting 08/20 and 09/21 to 12/00	
    hour = Number(hour);
    needsExtraZero = true;
    if (AMPM == "PM") {
        if (hour != 12) {
            hour = hour + 12;
        }
    } else {
        if (hour == 12) {
            hour = '00';
            needsExtraZero = false;
        }
    }
    if (needsExtraZero) {
        if (hour < 10) {
            hour = "0" + hour;
        }
    }
    document.getElementById(textfieldName).value = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":00";
}
/******************************In Out Board Functions ***********************************/

function inOutCreateRequestObject() {
    var inOut;
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        inOut = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        inOut = new XMLHttpRequest();
    }
    return inOut;
}
var httpInOut = inOutCreateRequestObject();
var globalInOutWindow = "";
var globalInOutCurUser = "";
var globalInOutStatus = "";
function inOutSndReq(inOutWindow, currentUser, status, message, time) {
    globalInOutWindow = inOutWindow;
    httpInOut.open('get', '/tools/companyDirectory/dirCommon.php?inOutWindow=' + inOutWindow + '&currentUser=' + currentUser + '&status=' + status + '&message=' + message + '&time=' + time);
    httpInOut.onreadystatechange = inOutHandleResponse;
    httpInOut.send(null);
}
function inOutHandleResponse() {
    if (httpInOut.readyState == 4) {
        var inOutResponse = httpInOut.responseText;
        var inOutUpdate = new Array();
        if (inOutResponse.indexOf('|' != -1)) {
            ///*debug*/	alert("Response:"+inOutResponse);
            inOutUpdate = inOutResponse.split('|');
            document.getElementById(inOutUpdate[0]).innerHTML = inOutUpdate[1];
            document.getElementById(inOutUpdate[2]).innerHTML = inOutUpdate[3];
            /*errorfix*/
            //document.getElementById(inOutUpdate[4]).innerHTML = inOutUpdate[5];
        }
    }
}
function inOutToggleMe() {
    if (document.getElementById('itemInList').style.display == 'none') {
        document.getElementById('itemInList').style.display = 'block';
        document.getElementById('itemOutList').style.display = 'none';
        document.getElementById('btnView').value = 'View Out';
    } else {
        document.getElementById('itemInList').style.display = 'none';
        document.getElementById('itemOutList').style.display = 'block';
        document.getElementById('btnView').value = 'View In';
    }
}

function refreshIndexRand() {
    setTimeout('window.location.href = "/index.php"', 5 * (60 * 1000));
}
/**************************END In Out Board Functions ***********************************/
function commentingHandler(update) {
    //alert(update[0]);
    //alert(update[1]);
    //alert(update[2]);
    //alert(update[3]);
    //alert(update[4]);
    //alert(update[5]);
    //alert(update[6]);
    //alert(update[7]);
    //alert(update[8]);
    //alert(update[9]);
    try {
        document.getElementById(update[0]).innerHTML = update[1]; //calLabel
        try {
            Effect.Appear('alertBoxFunction');
        } catch(e) {}
        try {
            if (update[2] == 'Error') {
                window.location.href = '/login.php?t=7&cf=' + update[8] + '&state=' + update[3] + '&tb=' + update[4] + '&a=' + update[5] + '&c=' + update[7];
            }
        } catch(e) {
            alert('Sorry, we could not forward you to login screen.');
        }
    } catch(e) {
        //alert(update[0]);
        alert('Sorry, we could not proccess your comment.  Please try again later');
        //alert('Error: '+e);
        //alert('FirstReturnBlock: ' +update[0]);
    }
    resSndReq('/inc/rating.php?rand=' + Math.random() + '&tb=' + update[4] + '&a=' + update[5], 'ratingHandler');
}
function ratingHandler(update) {
    //alert(':'+update[0]+':');
    //alert(':'+update[1]+':');
    //alert(':'+update[2]+':');
    //alert(':'+update[3]+':');
    //alert(':'+update[4]+':');
    //alert(':'+update[5]+':');
    try {
        document.getElementById(update[0]).innerHTML = update[1]; //calLabel
        //try { Effect.Appear('alertBoxFunction'); } catch(e) { }
    } catch(e) {
        //alert(update[0]);
        alert('Sorry, we could not proccess your rating.  Please try again later');
        //alert('Error: '+e);
        //alert('FirstReturnBlock: ' +update[0]);
    }
}
/************************** RESOLUTION CMS NAV EDITOR AJAX FUNCTIONS ************************************/

function navUpdateOrder(whatElement) {
    //send the new order to the db
    parentKey = whatElement.id.substring(4, 10); // makes list1 into 1 and list-23 into (-23)
    newOrderToSend = "&";
    newOrderToSend += Sortable.serialize(whatElement.id);
    resSndReq('navQ.php?a=upo&parentKey=' + parentKey + newOrderToSend, 'navUpdateOrderComplete');
}
function navUpdateOrderComplete(resp) {
    //alert('something something ... complete');
}
function navUpdateDelete(whatElement) {
    if (confirm('Are you sure you want to delete this page/link?')) {
        resSndReq('navQ.php?a=del&whatToDelete=' + whatElement, 'navUpdateDeleteComplete');
        //alert('navQ.php?a=del&whatToDelete='+ whatElement);
    }
}
function navUpdateDeleteComplete(resp) {
    //alert('list_' + resp[1]);
    //Effect.Fade('list_' + resp[1]);
    document.getElementById('list_' + resp[1]).style.display = 'none';
}
/************************** END OF RESOLUTION CMS NAV EDITOR AJAX FUNCTIONS ************************************/
var zKeeper = new Array();
var topzKeeper = new Array();
var vTopOff
var vTopOn
var topvTopOff
var topvTopOn
var runningWin
function prepNavBatch() {
    winTest = navigator.platform.indexOf("Win");
    if (winTest > -1) {
        runningWin = true;
    } else {
        runningWin = false
    }
    if ((navigator.appName == "Microsoft Internet Explorer")) {
        vTopOff = 3;
        vTopOn = 3;
        topvTopOff = -10;
        topvTopOn = -10;
    } else {
        vTopOff = -1;
        vTopOn = -1;
        topvTopOff = -11;
        topvTopOn = -11;
    }
    for (i = 0; i < 4; i++) {
        currentEval = 'M' + (i + 1);
        zKeeper[i] = document.getElementById(currentEval).style.zIndex;
    }
}
function pushMeOut(whoAmI, userPress) {
    if (whoAmI < 99) {
        currentEval = 'M' + whoAmI;
        lessMe = whoAmI - 1;
        //move this tab above all others in the array 
        zKeeper[lessMe] = 4;
        for (var i = 0; i < zKeeper.length; i++) {
            if ((zKeeper[i] > document.getElementById(currentEval).style.zIndex) && ((i + 1) != whoAmI)) {
                //if this level is higher then the one being switched (but not this one), move it down one 
                zKeeper[i] = zKeeper[i] - 1;
            }
        }
    }
    //set the tabs
    for (var i = 0; i < zKeeper.length; i++) {
        myEval = 'M' + (i + 1);
        document.getElementById(myEval).style.zIndex = zKeeper[i];
        document.getElementById(myEval).style.top = vTopOff + "px";
        switch (myEval) {
        case "M2":
            whatClass = "normTabGreen";
            break;
        case "M1":
            whatClass = "normTabBlack";
            break;
        default:
            whatClass = "normTab";
            break;
        }
        if ((navigator.appName == "Microsoft Internet Explorer") && runningWin) {
            whatClass = whatClass + "Alpha";
        }
        document.getElementById(myEval).className = whatClass;
    }
    if (whoAmI < 99) {
        document.getElementById(currentEval).style.top = vTopOn + "px";
        if ((navigator.appName == "Microsoft Internet Explorer") && runningWin) {
            document.getElementById(currentEval).className = "overTabAlpha";
        } else {
            document.getElementById(currentEval).className = "overTab";
            //alert("GETTING HERE AND eval is: " + currentEval + " CURRENT CLASS IS: " + document.getElementById(currentEval).className);
        }
    }
}