﻿
function JumpToPage(intPage) {
    var strOldLocation;
    strOldLocation = new String(top.location);
    strOldLocation = strOldLocation.replace(/&page=\d*/, '&page=' + intPage);
    strOldLocation = strOldLocation.replace(/\?page=\d*/, '?page=' + intPage);
    if (strOldLocation.indexOf('page=') == -1) {
        if (strOldLocation.indexOf('?') == -1) {
            strOldLocation += '?page=' + intPage;
        } else {
            strOldLocation += '&page=' + intPage;
        }
    }
    top.location = strOldLocation;
}

var c_lnkSave;
var c_intSaveID;

/*
function saveMustRegister(link) {
    c_lnkSave = link;

    var box = document.getElementById('saveJobNotes');
    box.className = 'saveJobConfirmShow';
    box.style.top = (getOffset(c_lnkSave).top + 20) + 'px';
    box.style.left = (getOffset(c_lnkSave).left - 250) + 'px';
}
*/

function saveJob(link, id) {
    c_lnkSave = link;
    c_intSaveID = id;

    $("#txtNotes").val("");
    $("#selTag").val("");
        
    var box = document.getElementById('saveJobNotes');

    box.className = 'saveJobConfirmShow';
    box.style.top = (getOffset(c_lnkSave).top + 20) + 'px';
    box.style.left = (getOffset(c_lnkSave).left - 250) + 'px';

    if ($.browser.mozilla) {
        $("#txtNotes").attr("rows", "9");
    }

    $("#txtNotes").focus();

    //c_xhrSave = CreateXmlHttp();
    //MakeAjaxCall(c_xhrSave, '/AjaxSaveToMyJobs.aspx?jobid=' + id, saveJobFeedback);
}

function saveJobOKButtonClicked(link, id) {

    //Get the job id, notes and tag and send them off to be saved.

    jQuery.post('/AjaxSaveToMyJobs.aspx?jobid=' + c_intSaveID,
                { notes: $("#txtNotes").val(), tag: $("#selTag").val() },
                saveJobFeedback);
}

function saveJobFeedback(data, textStatus, xhrSave) {

    if (data.indexOf('OK') > -1) {
        if (Get_Cookie("atb-savejobs") != "1") {
            //showConfirm("The job has been saved to your \"My Jobs\" page. To access your \"My Jobs\" list, please click on the \"My Jobs\" tab at the top of the page.<div id=\"MyJobsPreview\"></div>");
            showSaveConfirm();
            Set_Cookie("atb-savejobs", "1", 1, "/");
        }
        c_lnkSave.innerHTML = "Saved";
        c_lnkSave.removeAttribute("href");
        c_lnkSave.removeAttribute("onclick");

    } else {
        //showConfirm("Failed to save the job. This could happen if your browser does not accept cookies or after a long period of inactivity.");
        showSaveFail();
    }

    closeNotes();

}

function showSaveConfirm() {
    document.getElementById('saveConfirm').style.display = 'block';
    showConfirm();
}

function showSaveFail() {
    document.getElementById('saveFail').style.display = 'block';
    showConfirm();
}

function showConfirm(msg) {

//    var box_msg = document.getElementById('saveConfirmMsg');
//    var text = document.createTextNode(msg);
//    box_msg.innerHTML = '';
//    box_msg.appendChild(text);

    var box = document.getElementById('saveJobConfirm');
    box.className = 'saveJobConfirmShow';
    box.style.top = (getOffset(c_lnkSave).top + 20) + 'px';
    box.style.left = (getOffset(c_lnkSave).left - 250) + 'px';

}

function closeNotes() {
    var box = document.getElementById('saveJobNotes');
    box.className = 'saveJobConfirmHidden';
}

function closeConfirm() {
    var box = document.getElementById('saveJobConfirm');
    box.className = 'saveJobConfirmHidden';
}

function getOffset( el ) {
    var _x = 0;
    var _y = 0;
    
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft;
        _y += el.offsetTop;
        el = el.offsetParent;
    }

    return { top: _y, left: _x };
}

function listView() {
    toggleSummary();
    document.getElementById('listViewLink').className = 'jsLink viewLinkOn';
    document.getElementById('detailsViewLink').className = 'jsLink viewLinkOff';
}

function detailsView() {
    toggleSummary();
    document.getElementById('listViewLink').className = 'jsLink viewLinkOff';
    document.getElementById('detailsViewLink').className = 'jsLink viewLinkOn';
}

function toggleSummary()
{
    var abstracts = getElementsByClassName('jobdescription jobdescfull');
    var abstracts2 = getElementsByClassName('jobdescription jobdesclist');
    for (var i = 0, j = abstracts.length; i < j; i++) {
        abstracts[i].className = 'jobdescription jobdesclist';
    }
    for (var i = 0, j = abstracts2.length; i < j; i++) {
        abstracts2[i].className = 'jobdescription jobdescfull';
    }
}

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if (re.test(els[i].className)) a.push(els[i]);
    return a;
}