﻿
var c_xhrQuickRegister;
var c_ResponseLabel;
var c_QuickRegInput;
var c_strQuickRegButtonAction = 'ok';

function QuickRegister(qrbox, strPage) {
    var strEmail;

    //if 'ok', continue on to the rest of the function
    switch(c_strQuickRegButtonAction)
    {
        case 'cont':
            window.location.href = '/RegistrationCVUpload.aspx';
            return;
        case 'login':
            window.location.href = '/login.aspx';
            return;
        case 'close':
            closeEmailBox('emailform');
            return;
    }
    
    //Find the text-box containing the e-mail address
    var items = qrbox.getElementsByTagName('input');

    for (i = 0; i < items.length; i++) {
        if (items[i].type == "text") {
            c_QuickRegInput = items[i];
        }
    }

    //Find the message div
    items = qrbox.getElementsByTagName('div');

    for (i = 0; i < items.length; i++) {
        if (items[i].id) {
            if (items[i].id.indexOf('msg') > -1) {
                c_ResponseLabel = items[i];
            }
        }
    }
    
    strEmail = encodeURI(c_QuickRegInput.value);
    c_xhrQuickRegister = CreateXmlHttp();

    if (strEmail.length == 0) {
        c_ResponseLabel.innerHTML = 'Please enter an email address';
    }
    else {
        MakeAjaxCall(c_xhrQuickRegister, '/AjaxQuickRegister.aspx?email=' + strEmail + '&page=' + strPage, GotQuickRegisterFeedback);
    }
}

function GotQuickRegisterFeedback() {
    if (c_xhrQuickRegister.readyState == 4) {
        var strItems = c_xhrQuickRegister.responseText.split('|');

        c_strQuickRegButtonAction = strItems[0];

        if (strItems[0] == 'ok') {
            c_QuickRegInput.style.display = 'block';
        }
        else {
            c_QuickRegInput.style.display = 'none';
        }

        if (c_strQuickRegButtonAction == 'cont') {
            c_ResponseLabel.innerHTML = strItems[1].replace("$url", '/RegistrationCVUpload.aspx');
        } else {
            c_ResponseLabel.innerHTML = strItems[1].replace("$url", location.href);
        }
    }
}

function popupdidyoumean() {
    popupemail(null, 'didyoumeanform', 0, -180);
}

function popuptip0() {
    //This is the location one...
    //popupemail(null, 'tippopup', 0, -100);

    var loc = $("input[id$='_txtLocation']").val();

    if (!loc || loc.length == 0) {
        popupLocationPrompt();
    }
}

function LocationPromptCancel() {
    $('#LocationPromptScreen').css('display', 'none');

    document.cookie = 'tippopup0closed=true';

}

function LocationPromptOK() {

    var loc = $('#ctl00_cphMainColumn_LocationPromptInput').val();

    if (loc) {
        searchJobs(strClientID, null, loc, null);
    }
}

function popuptip1() {
    popupemail(null, 'tippopup', 0, -180);
}

function popuptip2() {
    popupemail(null, 'tippopup', 0, -180);
}

function popupLocationPrompt() {
    $('#LocationPromptScreen').css('display', 'block');
    $('#ctl00_cphMainColumn_LocationPromptInput').focus();
}

function popupemail(event, strID, intX, intY) {

    var form = document.getElementById(strID);

    if (form.className == 'emailformon') {
        form.className = 'emailformoff';
    }
    else {
        form.className = 'emailformon';

        if (event == null) {
            form.style.top = intY + 'px';
            form.style.left = intX + 'px';
        } else {

            if (event.pageX) {
                form.style.top = event.pageY + 20 + "px";
                form.style.left = event.pageX + "px";
            }
            else {
                if (document.documentElement) {
                    form.style.top = document.documentElement.scrollTop + event.clientY + 20 + "px";
                    form.style.left = document.documentElement.scrollLeft + event.clientX + "px";
                }
                else {
                    form.style.top = document.body.scrollTop + event.clientY + 20 + "px";
                    form.style.left = document.body.scrollLeft + event.clientX + "px";
                }
            }

        }
    }

    if (event != null) {
        event.returnValue = false;
    }
}

function closeEmailBox(id, blnSaveCookie, strRef) {

    var form = document.getElementById(id);

    if (form != undefined) {
        form.className = 'emailformoff';
    }

    if (blnSaveCookie) {
        document.cookie = id + strRef + 'closed=true';
    }

}
