﻿$(document).ready(function() {
$("input[name='upload_type']").click(function() {
if ($("input[name='upload_type']:checked").val() == 'UPL') {
        $('#importPhotoAlbum').hide();
        $('#uploadPhotoAlbum').show();
    }
    else {
        $('#uploadPhotoAlbum').hide();
        $('#importPhotoAlbum').show();
    }
});
});
function onCreateAlbum() {
    $('#pAddPhoto').show();
    $('#pAddNewAlbum').hide();
}
function onSelectAlbum() { $('#selectAlbum a').attr('class', ''); $('#allalbum').addClass('selectedAlbum'); $('#selectMemberPhoto').hide(); }
function onSelectMember() { $('#selectAlbum a').attr('class', ''); $('#bymember').addClass('selectedAlbum'); $('#selectMemberPhoto').show(); }
function onSelectMyAlbum() { $('#selectAlbum a').attr('class', ''); $('#myalbum').addClass('selectedAlbum'); $('#selectMemberPhoto').hide(); }
function gotoAddAlbum() { /*$('#profilePhotoTab').triggerTab(3);*/onShowAddGroupPhotosForm(); }

function onShowGroupPhotos() {
    //$('#profilePhotoTab').tabs();
    $("#gPhotosContentLoading").show();
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 24,
            grp_id: ggrp_id
        },
        success: function(responseText) {
            if ($.browser.msie) {
                $("#gPhotosContentLoading").fadeOut(150, function() {
                    $("#gPhotosContentResult").html(responseText).show();
                    $('#profilePhotoTab').tabs();
                });
            }
            else {
                $("#gPhotosContentLoading").fadeOut(200, function() {
                    $("#gPhotosContentResult").html(responseText).show();
                    $('#profilePhotoTab').tabs();
                });
            }
        }
    });
}
var ggmm_rem_id = 0;
function onShowAddGroupPhotosForm() {
    ggmm_rem_id = 0;
    $("#tabCreateAlbumResult").html('');
    $('#profilePhotoTab').triggerTab(3);
    $("#tabCreateAlbumLoading").show();
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 25,
            grp_id: ggrp_id
        },
        success: function(responseText) {
            if ($.browser.msie) {
                $("#tabCreateAlbumLoading").fadeOut(150, function() {
                    $("#tabCreateAlbumResult").html(responseText).show();
                    var num_of_imgUpload = $("#num_of_imgUpload").val();
                    for (var j = 1; j <= num_of_imgUpload; j++) {
                        uploadGroupPhotoAlbumImgFile('btnUpload' + j, 'imgUpload' + j, 'MMA', mbr_id, session_id, j);
                    }
                });
            }
            else {
                $("#tabCreateAlbumLoading").fadeOut(200, function() {
                    $("#tabCreateAlbumResult").html(responseText).show();
                    var num_of_imgUpload = $("#num_of_imgUpload").val();
                    for (var j = 1; j <= num_of_imgUpload; j++) {
                        uploadGroupPhotoAlbumImgFile('btnUpload' + j, 'imgUpload' + j, 'GMM', mbr_id, session_id, j);
                    }
                });
            }
        }
    });
}

function onSaveGroupPhotoAlbum() {
    $("#msgSaveLoading").show();
    var gmm_id = $("#gmm_id").val() == "" ? 0 : $("#gmm_id").val();
    var gmm_name = $("#gmm_name").val();
    var gmm_ability = $("#cmbPhotoAbility").val();
    var gmm_location = $("#gmm_location").val();
    var gmm_desc = $("#gmm_desc").val();
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 26,
            grp_id: ggrp_id,
            gmm_name: gmm_name,
            gmm_ability: gmm_ability,
            gmm_location: gmm_location,
            gmm_desc: gmm_desc,
            gmm_id: gmm_id
        },
        success: function(responseText) {
            if ($.browser.msie) {
                $("#msgSaveLoading").fadeOut(150, function() {
                    if (responseText.indexOf("Photo album has been saved.") == -1)
                        $("#msgSaveGroupPhotoAlbum").html(responseText).show();
                    else {
                        var real_max_id = responseText.split("||");
                        ggmm_rem_id = real_max_id[1];
                        $("#pAddNewAlbum").hide();
                        $("#pAddPhoto").show();
                    }
                });
            }
            else {
                $("#msgSaveLoading").fadeOut(200, function() {
                    if (responseText.indexOf("Photo album has been saved.") == -1)
                        $("#msgSaveGroupPhotoAlbum").html(responseText).show();
                    else {
                        var real_max_id = responseText.split("||");
                        ggmm_rem_id = real_max_id[1];
                        $("#pAddNewAlbum").hide();
                        $("#pAddPhoto").show();
                    }
                });
            }
        }
    });
}

function onUploadGroupPhotoAlbum() {
    $("#msgSaveLoading").show();
    var file_list = "", intCheck = 0;
    var num_of_imgUpload = $("#num_of_imgUpload").val();
    for (i = 1; i <= num_of_imgUpload; i++) {
        if ($('#imgUpload' + i).val() != '') {
            file_list += $('#imgUpload' + i).val() + ','; 
            intCheck++;
        }
    }
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 32,
            grp_id: ggrp_id,
            gmm_id: ggmm_rem_id,
            gmm_type_cd: 'IMG',
            file_list: file_list
        },
        success: function(responseText) {
            
        }
    });
}

function onEditAlbum(gmm_id, tt_pho, alb_name) {
    $("#tabEditAlbumResult").html('');
    $("#tabEditAlbumLoading").show();
    $('#profilePhotoTab').triggerTab(4);
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 42,
            grp_id: ggrp_id,
            gmm_id: gmm_id,
            tt_pho: tt_pho
        },
        success: function(responseText) {
            $("#tabEditAlbumLoading").fadeOut(200, function() {
                $("#tabEditAlbumResult").html(responseText).show();
                $("#rem_gmm_name").val(alb_name);
                if (parseInt(tt_pho) > 0)
                    $("#albTitle").html("Album " + alb_name);
                else
                    $("#albTitle").html(noPhotoInAlbum);
            });
        }
    });
}

function onSaveCaption(grm_id, gmm_id) {
    var caption = $("#txtCaption" + grm_id).val();
    var url = server_root + "/Processor/GeneralProcessPart8.aspx";
    $.ajax({
        url: url,
        async: true,
        cache: false,
        type: "POST",
        dataType: "html",
        data: {
            proc_id: 43,
            grp_id: ggrp_id,
            grm_id: grm_id,
            gmm_id: gmm_id,
            caption: caption
        },
        success: function(responseText) {
            $("#cptSaveMsg").html(responseText);
        }
    });
}