﻿function AttachJobsFancyBox() {

    $("a.viewbutton").fancybox({
        'zoomSpeedIn': 200,
        'zoomSpeedOut': 200,
        'hideOnContentClick': false,
        'frameWidth': 900,
        'frameHeight': 500,
        'callbackOnShow': function() { JobsViewFancyBoxCallBack(); }
    });

    $("a.applybutton").fancybox({
        'zoomSpeedIn': 200,
        'zoomSpeedOut': 200,
        'hideOnContentClick': false,
        'frameWidth': 900,
        'frameHeight': 500,
        'callbackOnShow': function() { JobsApplyFancyBoxCallBack(); }
    });

    setTimeout( function() { $("a.jobjumper").click();} )
}

function JobsViewFancyBoxCallBack() {
    $("#fancy_div a.gobutton").fancybox({
        'zoomSpeedIn': 200,
        'zoomSpeedOut': 200,
        'hideOnContentClick': false,
        'frameWidth': 900,
        'frameHeight': 500,
        'callbackOnShow': function() { JobsApplyFancyBoxCallBack(); }
    });
}

function JobsApplyFancyBoxCallBack() {
//    document.getElementById("submitJobId").value = _submitJobId;
//    document.getElementById("ddTalent").selectedIndex = 1;
    
    ddTalent_onchange(document.getElementById("ddTalent"));
    InitValidation();
}

function InitValidation() {
    $("#TalentAgencySubmitTalentForm").validate({
        rules: {
            talentFirstName: "required",
            talentLastName: "required",
            talentCurrentPosition: "required",
            talentAvailabilityDate: {
                required: true,
                dateISO: false
            },
            talentResumeValidator: "required"
        },
        messages: {
            talentFirstName: "First name is required.",
            talentLastName: "Last name is required.",
            talentCurrentPosition: "Required. Enter 'NONE' if not employed.",
            talentAvailabilityDate: {
                required: "Please enter date available.",
                dateISO: "Please enter a date in format mm-dd-yyyy."
            },
            talentResumeValidator: "A Resume is required."
        }
    });
}

function OnSubmit() {
    var r = FCKeditorAPI.GetInstance("talentResume");
    document.getElementById("talentResumeValidator").value = r.GetXHTML(false)
}

function MoveTalentDetails(position) { $('#slide-frame').animate({ left: position }, "slow", "easeOutBack"); }

function StopMovie() { setTimeout(function() { document.mediaplayer.Stop(); }); }

function ddTalent_onchange(dd) {
    //HtmlControlUpdate("Subscribers_TalentAgencySubmitTalent.GetTalent", 'talentdetail-wrapper', dd.value);
    Jobs.GetTalent(dd.value, ProcessResult);
}

function ProcessResult(res) {
    SetControlValue("talentFirstName", "");
    SetControlValue("talentLastName", "");
    SetControlValue("talentCurrentPosition", "");
    SetControlValue("talentAvailabilityDate", "");
    SetControlValue("talentExternalLink", "");
    SetVideoSource("");
    SetResumeContents("");
    
    if (res.value == null) {
        alert("Talent could not be loaded.");
        return;
    }

    if (res.value[1] != "")
        alert(res.value[1]);

    if (res.value[0] == 0) {
        SetControlValue("talentFirstName", "");
        SetControlValue("talentLastName", "");
        SetControlValue("talentCurrentPosition", "");
       SetControlValue("talentAvailabilityDate", "");
        SetControlValue("talentExternalLink", "");
        SetVideoSource("");
        SetResumeContents("");
    }
    else {
        SetControlValue("talentFirstName", res.value[2]);
        SetControlValue("talentLastName", res.value[3]);
        SetControlValue("talentCurrentPosition", res.value[4]);
        SetControlValue("talentAvailabilityDate", res.value[5]);
        SetControlValue("talentExternalLink", res.value[6]);
        SetVideoSource(res.value[8]);
        SetResumeContents(res.value[7]);
    }


}

function SetControlValue(elementId, value) {
    document.getElementById(elementId).value = value;
}

function SetVideoSource(source) {
    if (source == "") {
        document.getElementById("videoContainer").style.display = "none";
        document.getElementById("noVideoContainer").style.display = "block";
    }
    else {
        document.getElementById("videoContainer").style.display = "block";
        document.getElementById("noVideoContainer").style.display = "none";
    }
    document.talentCurrentVideo.src = source;
}

function SetResumeContents(contents) {
    var editor = FCKeditorAPI.GetInstance("talentResume");
    editor.SetHTML(contents);
}



function Find_ddTalent() {
    //alert($('#ddTalentFinder').value);
    //return $($('#ddTalentFinder').value);
}

var _sortColumn = "Modified";

function GetJobs(sortColumn) {

    if (sortColumn == null || sortColumn == "")
        sortColumn = _sortColumn;

    _sortColumn = sortColumn;

    var jobType = document.getElementById("ddJobType").value;
    var station = document.getElementById("txtStationSearch").value;
    var market = document.getElementById("txtMarketSearch").value;
    var contact = document.getElementById("txtContactSearch").value;
    var showClosed = document.getElementById("cbShowClosed").checked;

    HtmlControlUpdate("JobList.Get", 'position-table-wrapper', jobType, station, market, contact, showClosed, _sortColumn);
    AttachJobsFancyBox();
}

function JobListReset() {
    document.getElementById("ddJobType").value = 0;
    document.getElementById("txtStationSearch").value = "";
    document.getElementById("txtMarketSearch").value = "";
    document.getElementById("txtContactSearch").value = "";
    document.getElementById("cbShowClosed").checked = false;
    GetJobs();
}




var _submitJobId = "";

$(document).ready(function() {
    GetJobs();
});


