// GetCAGEInfo() - Do a web request to get the rest of a CAGE's data
function GetCAGEInfo()  {

    // Don't bother unless it's 5 chars long
    var oCage = document.getElementById("cCAGE");
    var cValue = oCage.value.toUpperCase().AllTrim();
    var nLen = cValue.length;
    if (nLen == 5) {
        var url = "cps/svc/GetCAGEInfo.wwsoap";
        url = currentDomain() + url;
        var pl = new SOAPClientParameters();
        var oStepL = document.getElementById("cKey1");
        var cStepL = oStepL.value;
        var oStepP = document.getElementById("cKey2");
        var cStepP = oStepP.value;
        pl.add("cLogin", cStepL);
        pl.add("cPassword", cStepP);
        pl.add("cCAGE", cValue.toString());
	    SOAPClient._sendSoapRequest(url, "GetCAGEInfo", pl, true, loadCAGEInfo, null);
    }
    return true;
}

// loadCAGEInfo() - Do a web request to get the rest of a CAGE's data
function loadCAGEInfo(cXML)  {

    // Clean up the XML
    var cClnXML = cXML.StrTran('&lt;','<');
    cClnXML = cClnXML.StrTran('&gt;','>');

    // We may have an error
    if (cClnXML.length > 0 && cClnXML.StrAt("Invalid") == 0 &&
      cClnXML.StrAt("not in ALI's files") == 0)   {

        // Get the rest of the values we need
        var cCompany = SOAPClient.getValuesByTagName(cClnXML, 'Name');
        var cAddr1 = SOAPClient.getValuesByTagName(cClnXML, 'ADDR1');
        var cCity  = SOAPClient.getValuesByTagName(cClnXML, 'CITY');
        var cState = SOAPClient.getValuesByTagName(cClnXML, 'STATE');
        var cZip   = SOAPClient.getValuesByTagName(cClnXML, 'ZIP');
        var cPhone = SOAPClient.getValuesByTagName(cClnXML, 'Phone');
        var cFax = SOAPClient.getValuesByTagName(cClnXML, 'Fax');

        // deCode needs twice on the company because &amp; was twice
        var oOrgName = document.getElementById("cCompany");
        oOrgName.value = cCompany.deCode();
        oOrgName.value = oOrgName.value.deCode();
        var oAddr = document.getElementById("cAddress");
        oAddr.value = cAddr1.deCode();
        var oCity = document.getElementById("cCity");
        oCity.value = cCity.deCode();
        var oState = document.getElementById("cState");
        oState.value = cState.deCode();
        var oZip = document.getElementById("cZip");
        oZip.value = cZip.deCode();
        var oPhone = document.getElementById("cPhone");
        oPhone.value = formatPhone(cPhone);
        var oFax = document.getElementById("cFax");
        oFax.value = formatPhone(cFax);
    }
}

// setupCageField()
function setupCageField()   {
    oFld = document.getElementById('cCAGE');
    oFld.onchange = function()    {
        GetCAGEInfo()
    }
}

// finalValids()
function finalValids(theForm)   {
    var agreeObj, agreeValue, noticeObj
    agreeObj = idObj("cAgree");
    agreeValue = agreeObj.value;
    noticeObj = idObj("agreeNotice");
    if (agreeValue=="Y")   {
        addClass(noticeObj, "hidden");
    } else {
        removeClass(noticeObj, "hidden");
        validErrCount = validErrCount + 1;
    }
}

// Check the fields on the page
function checkReqd() {

    var cCAGE    = idObj('cCAGE');
    var cPCName  = idObj('cPCName');
    var cCompany = idObj('cCompany');
    var cPhone   = idObj('cPhone');
    var cPCExt   = idObj('cPCExt');
    var cFax     = idObj('cFax');
    var cAddress = idObj('cAddress');
    var cCity    = idObj('cCity');
    var cState   = idObj('cState');
    var cZip     = idObj('cZip');
    var cPCEmail = idObj('cPCEmail');
    var cURL     = idObj('cURL');

    if (Empty(cCAGE.value + cPCName.value + cCompany.value + cPhone.value +
      cPCExt.value + cFax.value + cAddress.value + cCity.value + cState.value +
      cZip.value + cPCEmail.value + cURL.value))  {
        alert('All fields are blank. Please fill in a few fields so we have some way to contact you.')
        return false;
    }
    if (Empty(cCAGE.value))  {
        alert('The CAGE field is blank.')
        return false;
    }  else  {
        if (!(cCAGE.value.length == 5))  {
            alert('The CAGE field must be 5 characters.')
            return false;
        }
    }

    // Make sure they entered the cPCEmail
    if (document.frmEntries.bRFQE.checked) {
        if (Empty(cPCEmail.value))  {
            alert("Email address is required");
            return false;
        }
    }

    // Make sure they selected the cHOW
    var cRadioType = getRadioValue(document.frmEntries.cHOW, 6);
    if (Empty(cRadioType))  {
        alert('"2. How did you hear about ALI Corp" is not selected.');
        return false;
    }

    agreeObj = idObj('cAgree');
    noticeObj = idObj("agreeNotice");
    if (agreeObj.value=="Y")   {
        addClass(noticeObj, "hidden");
    } else {
        removeClass(noticeObj, "hidden");
        return false;
    }
    document.frmEntries.submit();
}

// addLoadListener(setupCageField);

