﻿function loadCollection(collectionid) {
    if(collectionid > 0) {
        $.post('../XMLGetSegments.ashx', 
            { collectionId: collectionid },
            completed_loadCollection,
            "xml"
        );
    } else {
        var segmentSelect = $("#segment");
        segmentSelect.html('');
        segmentSelect.append('<option value="-1" disabled="disabled">Segment</option>');
    }
    
    
}

$(function() {
    var cid = $.url.param("CollectionId");
    if(cid != '') {
        $("#collection").val(cid);
        loadCollection(cid);
    }
});

function completed_loadCollection(data, textStatus) {
    
    var segmentSelect = $("#segment");
    segmentSelect.html('<option value="-1">Segment</option>');
    $(data).find("segment").each(function(i) {
        segmentSelect.append('<option value="' + $(this).attr('id') + '">' + $(this).text() + '</option>');
    });
    
    
    var sid = $.url.param("SegmentId");
    if(sid != '') {
        $("#segment").val(sid);
    } 
}

function loadSegment(segmentId) {
    if(segmentId > 0) {
        var file = '';
        location.href = '?CollectionId=' + $("#collection").val() + '&SegmentId=' + segmentId;
    }
}
