﻿var getguid_url = 'AJAX/getGUID.aspx?PartialGUID=';

function guid_request(ctl) {

    var sPartialGUID = getRef(BaseID() + 'txtAccessCode').value;

    sPartialGUID = sPartialGUID.replace(' ', '');
    sPartialGUID = sPartialGUID.replace('i', '1');
    sPartialGUID = sPartialGUID.replace('I', '1');
    sPartialGUID = sPartialGUID.replace('l', '1');
    sPartialGUID = sPartialGUID.replace('L', '1');
    sPartialGUID = sPartialGUID.replace('o', '0');
    sPartialGUID = sPartialGUID.replace('O', '0');
    
    if (sPartialGUID.length == 0) {
        guid_response('No Search Text');
    }
    else if (sPartialGUID.length < 8) {
        guid_response('Multiple');
        return;
    }
            
    var xhr = new XHR();
    if (xhr == null) return;

    var sUrl = getguid_url + sPartialGUID
    
    xhr.getRequest(sUrl, 'text', function(str) { guid_response(str); });
}

function guid_response(str) {
    // If we get a response, we enable the submit button
    var btn = getRef(BaseID() + 'btnAccessCode');
    btn.disabled = (str.length != 36);

    var error = getRef(BaseBodyID()+'ucPageHeader_lblErrorMsg');
    if (str == 'Multiple') {
        error.innerHTML = 'Please enter more of the access code.';
    }
    else if (str == 'No GUID') {
        error.innerHTML = '';
    }
    else if (str == '') {
        error.innerHTML = 'You have entered an invalid access code.';
    }
    else {
        error.innerHTML = '';
    }

}
