var sortForm = document.formSort;
var formPOST = document.formPOST;

function showSql() {
    document.getElementById('sqlOn').style.display = 'block';
    document.getElementById('sqlOff').style.display = 'none'; 
}

function hideSql() {
    document.getElementById('sqlOn').style.display = 'none';
    document.getElementById('sqlOff').style.display = 'block'; 
}

/* ========= Sort Form functions ========= */
function sort() {
    document.sortForm.submit();
}

function page() {
    document.sortForm.submit();
}

/* ========= Result Form functions ========= */
function refineSearch() {
    postback(refinePage, "");
}

function setSortOrder() {
    document.formPOST.pageMap.value = '';
    document.formPOST.page.value = '1';
    postback(resultsPage, "");
}

function setPageSize() {
    document.formPOST.pageMap.value = '';
    document.formPOST.page.value = '1';
    postback(resultsPage, "");
}

function gotoPage(pageno) {
    document.formPOST.page.value = pageno;
//  alert('page no: ' + frm.page.value);
    postback(resultsPage, "");
}

function goCitation(cid, name) {
/*
 note: the name parameter is extraneous for DA.com, but is included in URL gen'd by hierarchy function in DLL
 note: the function name goCitation is also hardcoded into this DLL
*/
    var address = "companyProfile.asp?comp_id=" + cid;
//  navigate(address);
    postback(address, "");
}

// This function is identical to goCitation
function goProfileSingle(cid, name) {
    var address = "companyProfile.asp?comp_id=" + cid;
    postback(address, "");
}

function postback(page, target) {
    var frm = document.formPOST;
    frm.action = page;
    if (target.length > 0)
        frm.target = target;
    else
        frm.target = "";
/* -- debug form submission problem in IE --
    var debugmsg = "Submitting form 'formPOST' ...";
    debugmsg += "\n- action: " + frm.action;
    debugmsg += "\n- target: " + frm.target;
    debugmsg += "\n- method: " + frm.method;
    alert(debugmsg);
*/
    frm.submit();
}

function profileSelections() {
    if (verifySelections() == true) {
        postback("personnelProfile.asp", "");
    }
}

function compareSelections(actionType) {
    var frm = document.formPOST;
    var count = countSelections();
    var url, operationLabel, actionTarget;
    if ((count < 2) || (count > maxPeopleCompare)) {
        if (actionType == 0) {
            operationLabel = "relate";
        }
        else {
            operationLabel = "compare";
        }
        alert("Please select between 2 and " + maxPeopleCompare + " people to " + operationLabel + ".")
        return;
    }
    else {
        if (actionType == 0) {
            frm.action = "child/relatePeople.asp"
            frm.target = "_blank";
        }
        else {
            frm.action = "comparePeople.asp";
        }
        frm.submit();
    }
}

function addToCompareCart() {
    var frm = document.formPOST;
    if (countSelections() == 0) {
        alert("No selections were found - no records were added to your cart.\nPlease make a selection and try again.")
        return; // return false;
    }
    var url = 'child/addToCompareCart.asp?idlist=' + concatenateSelections('P', '.');

    if (frm.comp_id)
        url += '&idtype=C';
    else
        url += '&idtype=P';

    popup(url, 'addToCompareCart', 640, 480)
    // return true;
}


