﻿
if (typeof (Cufon) != "undefined") {
    Cufon.replace('h1');
    Cufon.replace('h2');
    Cufon.replace('h3');
    Cufon.replace('h4');
    Cufon.replace('h5');
    Cufon.replace('h6');
    Cufon.replace('h7');
}




$(document).ready(function () {
    roundedCorners();
    if ($('.focus').length > 0) if (!$($('.focus')[0]).attr('disabled')) $('.focus')[0].focus();
    $('.onclick').each(function (i) {
        $(this).keypress(function (e) { if (e.which == 13) { $('#' + $(this).attr('clicker')).click(); return false; } });
    });


    $('.hoverAuto').each(function (i) {
        $(this).hover(function () { $(this).attr('src', $(this).attr('hover')); }, function () { $(this).attr('src', $(this).attr('orig')); });
    });

    $('.watermark').each(function (i) {
        $(this).watermark($(this).attr('watermark'));
    });

    $('.staticNut').customFadeIn(250);

    $('.nut').draggable({ axis: 'x', opacity: 0.4, cursor: 'e-resize', containment: 'parent', stop: function (e, i) { handleStop(e, i); }, drag: function (e, i) { handleDrag(e, i); } });

    if ($('.profileMenu').length > 0) {
        $('.profileMenu').contextMenu({
            menu: 'myMenu'
        },
					function (action, el, pos) {

					    if (action == 'viewProfile') {
					        document.location.href = '/profile.aspx?UID=' + $(el).attr('userid');
					        return;
					    }


					    if (action.split('_')[0] == 'shortList') {
					        addToShortList(action.split('_')[1], $(el).attr('userid'), $('#jobid').val());

					        return;
					    }


					    alert(
						'Action: ' + action + '\n\n' +
						'Element ID: ' + $(el).attr('userid') + '\n\n' +
						'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
						'X: ' + pos.docX + '  Y: ' + pos.docY + ' (relative to document)'
						);
					});

    }
});




showPopAlert=  function ( text )
{
    $('#popAlert').html ( text );
    $('#popAlert').customFadeIn('fast');
    setTimeout ( "$('#popAlert').customFadeOut('fast')",2000);
}

sendMail = function (toPerson, jobID) {
    if ($('#message').val() != '' && $('#subject').val() != '') {
        $.post('/genericAuth.asmx?T=EMAIL&JOB=' + jobID, { subject: $('#subject').val(), message: $('#message').val(), to: toPerson },
                function (data) {

                    if (jobID == '00000000-0000-0000-0000-000000000000' || document.location.href.indexOf('mail.aspx') != -1) {
                        

                document.location.href = '/mail.aspx'; 
                } else {
                document.location.href = '/Recruiter/contactApplicants.aspx?JOB=' + jobID; 
                }});
    } else {
        $('.error').remove();
        if ($('#subject').val() == '') $('<label/>').addClass('error').html('This field is required.').insertAfter($('#subject'));
        if ($('#message').val() == '') $('<label/>').addClass('error').html('This field is required.').insertAfter($('#message'));
    }
}

importEmail = function () {

    $('#emailResults').css('display', 'none');
    $('#loading').css('display', 'block');
    $('#emailResultsTable').css('display', 'none');
    $('#inviteSelected').css('display', 'none');
    $('#emailResults').customFadeIn('slow');
    $.get('/generic.asmx?T=IMPORTEMAIL&provider=' + $('#provider').val() + '&username=' + $('#username').val() + '&password=' + $('#password').val(),

        function (data) {
            $('#loading').customFadeOut('fast');
            $('#emailResultsTable').customFadeIn('fast');
            $('#inviteSelected').customFadeIn('slow');
            $('#emailImportResults').html(data);

        });

}



inviteSelected = function () {
    var emails = '';
    for (x = 0; x < $("input[name='contact']").length; x++) {
        if ($("input[name='contact']")[x].checked) {
            emails += $("input[name='contact']")[x].value + ',';
        }
    }
    if (emails != '') {
        Boxy.load('/Popup/Invite.aspx?EMAILS=' + emails, { modal: true });
    } else { alert('No emails selected'); }
}

sendInviteAction = function () {

    $('#sendInvite').val("Sending Invite(s)");
    $('#sendInvite').attr('disabled', 'true');
    $.get("/genericAuth.asmx?T=QUICKINVITE&EMAILS=" + $('#emails').val() + "&MESSAGE=" + $('#message').val().replace(/\n/gi, '~'), function (data) { alert("Invite(s) sent"); document.location.href = '/home.aspx'; });
}

sendInviteActionRecruiter = function (t) {

    $('#sendInvite').val("Sending Invite(s)");
    $('#sendInvite').attr('disabled', 'true');
    $.get("/genericAuth.asmx?T=QUICKINVITE&EMAILS=" + $('#emails').val() + "&MESSAGE=" + $('#message').val().replace(/\n/gi, '~'), function (data) { alert("Invite(s) sent"); Boxy.get(t).hideAndUnload(); return false; });
}

sendInviteEmbedAction = function () {

    if ($('#emailsEmbed').val() == '') {
        if ($('#emailsEmbed').val() == '') $('<label/>').addClass('error').html('This field is required.').insertAfter($('#emailsEmbed'));
    } else {
        $('.error').remove();


        $('#sendInviteEmbed').val("Sending Invite(s)");
        $('#sendInviteEmbed').attr('disabled', 'true');
        $.get("/genericAuth.asmx?T=QUICKINVITE&EMAILS=" + $('#emailsEmbed').val() + "&MESSAGE=" + $('#messageEmbed').val().replace(/\n/gi, '~'), function (data) {
            alert("Invites sent"); $('#sendInviteEmbed').removeAttr('disabled'); $('#sendInviteEmbed').val('Send Invite(s)'); $('#emailsEmbed').val('');
        });
    }
}


addToShortList = function (selectID, userid, jobid) {

    if ($('#' + selectID).length > 0) {
        if ($('#' + selectID).val() == 'new') {
            Boxy.load('/Popup/Shortlist.aspx?USERS=' + userid + '&JOB=' + jobid + '&RURL=' + escape(document.location.href), { modal: true });
        } else {

            $.get('/genericAuth.asmx?T=ADDSHORTLIST&ADDUSER=' + userid + '&SHORTLIST=' + $('#' + selectID).val(), function (data) {
                showPopAlert('Added to short list');
            });


        }
    } else {
        if (selectID == 'new') {
            Boxy.load('/Popup/Shortlist.aspx?USERS=' + userid + '&JOB=' + jobid + '&RURL=' + escape(document.location.href), { modal: true });
        } else {

            $.get('/genericAuth.asmx?T=ADDSHORTLIST&ADDUSER=' + userid + '&SHORTLIST=' + selectID, function (data) {
                showPopAlert('Added to short list');
            });

        }
    }
}



createShortlist = function (addUserId, jobId, url) {

    // do some sort of asmx lookup

    if ($('#shortListName').val() == '') {
        if ($('#shortListName').val() == '') $('<label/>').addClass('error').html('This field is required.').insertAfter($('#shortListName'));
    } else {
        $('.error').remove();

        $.get('/genericAuth.asmx?T=CREATESHORTLIST&ADDUSER=' + addUserId + '&SHORTLISTNAME=' + escape($('#shortListName').val()) + '&JOBID=' + jobId,
            function (data) { document.location.href = url; });
    }
}


newShortListMulti = function (users, jobid) {

    $('select').css('display', 'none');
    Boxy.load('/Popup/Shortlist.aspx?USERS=' + users + '&JOB=' + jobid + '&RURL=' + escape(document.location.href), { modal: true });
}


removeFromShortList = function (delUser, shortList) {
    $.get('/genericAuth.asmx?T=REMOVESHORTLIST&USER=' + delUser + '&SHORTLIST=' + shortList, function (data) { document.location.reload(); });
}


quickAccept = function (rel, t) {
    $.get('/genericAuth.asmx?T=ACCEPTREVIEW&REL=' + rel, function (data) { $('#' + rel).html('Accepted'); });
    $(t).customFadeOut('fast');
}


sendBreakNotification = function (bid, b) {
    $.get('/genericAuth.asmx?T=BREAKTHROUGHEMAIL&BREAK=' + bid, function (data) { alert('Notification Sent'); Boxy.get(b).hideAndUnload(function () { document.location.reload(); }); });

}


updateBreakthrough = function () {
    $.get('/genericAuth.asmx?T=BREAKTHROUGH&C=' + escape($('#breakthroughText').val()), function (data) { $('#breakthroughText').val(''); Boxy.load('/Popup/BreakthroughAlert.aspx?BREAK=' + data, { modal: false }); });
}

updateBreakthroughComment = function (breakthrough,t) {
    $.get('/genericAuth.asmx?T=BREAKTHROUGHCOMMENT&C=' + escape($('#'+t).val()) + '&BREAKTHROUGH=' + breakthrough, function (data) { $('#'+t).val(''); document.location.reload(); });
}


removeComment = function (comment) {
    $.get('/genericAuth.asmx?T=REMOVECOMMENT&COMMENT=' + comment, function (data) { document.location.reload(); });
}


showExtendedNetworkActivity = function (a) {
    if ($('#networkExtended').css('display') == '' || $('#networkExtended').css('display') == 'none') {
        $('#networkExtended').customFadeIn('fast'); $(a).html('Hide More');
    } else { $('#networkExtended').customFadeOut('fast'); $(a).html('Show More'); }
}


removeRequest = function (inviteRequestId) {
    if (confirm('Are you sure you want to hide this request?')) {
        $.get('/genericAuth.asmx?T=REMOVEREQUEST&ID=' + inviteRequestId, function (data) { $('#' + inviteRequestId).css('display', 'none'); });
    }
}

onHelp = function (type) {
    Boxy.load('/Popup/Message.aspx?MSG=' + type, { modal: true })
}


previewInvite = function (val) {

    window.open('/mailTemplates/invitePreview.aspx?BODY=' + escape(val), "popup", "width=650,height=600,status=0,scrollbars=1");

}

replySent = function (id) {

    if ($('#s_' + id).css('display') == 'block' || $('#s_' + id).css('display') == 'table-row') {
        $('#s_' + id).css('display', 'none');
    } else {


        if (!$.browser.msie) $('#s_' + id).css('display', 'table-row');
        else $('#s_' + id).css('display', 'block');
    }
}
reply = function (id) {

    if ($('#' + id).css('display') == 'block' || $('#' + id).css('display') == 'table-row') {
        $('#' + id).css('display', 'none');
    } else {

        $('#' + id).css('display', 'block');
        if (!$.browser.msie) $('#' + id).css('display', 'table-row');
        $.get('/generic.asmx?T=MARKREAD&EMAILID=' + id, function (data) { $('#b_' + id).css('font-weight', 'normal'); });
    }
}



unread = function (id) {
    $.get('/generic.asmx?T=MARKUNREAD&EMAILID=' + id, function (data) { $('#b_' + id).css('font-weight', 'bold'); });
    reply(id);
}



canSubmitReview = function () {


    var selector = 'img[src="/IMG/Review/top_s.png"]';
    if ($.browser.msie && $.browser.version <= 7) {
        selector = 'img[src="http://www.viewsonyou.com/IMG/Review/top_s.png"]';
    }


    if ($(selector).length == 5) {
        return true;
    } else {
        alert('You need to select five questions that you consider are your review top 5. Click on the "Top 5" image next to the questions until you have five selected.');
        return false;
    }
}

setFilterAndRefresh = function (rtype, stype) {

    var rtypeA = [];
    var stypeA = [];


    $('#' + rtype + ' :selected').each(function (i, selected) {
        rtypeA[i] = $(selected).val();
    });

    $('#' + stype + ' :selected').each(function (i, selected) {
        stypeA[i] = $(selected).val();
    });


    $.get('/genericAuth.asmx?T=REVIEWFILTERS&RTYPE=' + rtypeA.join(',') + '&STYPE=' + stypeA.join(','), function (data) { document.location.reload(); });

}


showMoreInfoRecruiter = function () {
    Boxy.load('/Popup/RecruiterMore.aspx', { modal: true });
}


onReuse = function (profileUser) {
    if ($('#reuseID').val() != '') {
        $.get('/genericauth.asmx?T=REUSE&UID=' + profileUser + '&USEON=' + $('#reuseID').val(), function (data) {
            showMessage('You have succesfully reused this review on ' + $('#reuseName').val() + '. <a href="/reviewManagement.aspx?TABSELECT=1">Manage this Review</a>');
        });
    }
}

canDoNextStep = function (jobid) {
    if ($('#top5ProgressText').html() != 'Top 5 Progress 100%' ||
        $('#reviewProgressText').html() != 'Questions Progress 100%') {
        alert('You need to answer all questions and select your top 5 before continuing.');


        if ($('#reviewProgressText').html() != 'Questions Progress 100%') {
            nextUnanswered();
        }

    } else {
        if (document.location.href.indexOf('qReview') == -1) {
            document.location.href = 'jobListingAttachments.aspx?JOB=' + jobid;
        } else {
            document.location.href = 'qReviewSocial.aspx?JOB=' + jobid;
        }
    }

}

weHaveFacebook = function () {
    $('.facebook').css('display', 'block');
}


getReviewsHowWorks = function () {
    Boxy.load('/Popup/ReviewWorksMore.aspx', { modal: true });
}

highlightLogin = function () {
    $.scrollTo(0, 50);
    $('#topLogin1_txtEmail').focus();
    $('#topLogin').highlightFade('yellow');
    
    
}


update_state = function () {
    if ($('#country').val() == 'US') { $('#state').css('display', 'block'); $('#state').highlightFade('yellow'); }
    else { $('#state').css('display', 'none'); $('#state').val(''); }
}


accountOptions = function () {
    if ($('#menu').css('display') == 'block') {
        $('#menu').customFadeOut('fast', function () { $('#menuBlock').customFadeIn('fast', function () { $('#menuUpDown').attr('src', '/IMG/Buttons/menuDown.png'); }); });


    } else {
        $('#menuBlock').customFadeOut('fast', function () { $('#menu').customFadeIn('fast', function () {$('#menuUpDown').attr('src', '/IMG/Buttons/menuUp.png'); }); });
        
    }
}

seeProfileUrl = function (addr) {
    Boxy.load('/Popup/ViewProfileUrl.aspx?ADDR=' + addr, { modal: true });
}

pleaseWait = function (t) { $(t).css('display', 'none'); Boxy.load('/Popup/PleaseWait.aspx', { modal: true }); }