﻿function UpdateGallery(galph, ownerid, tipogal, tipoowner, thumb, bigimg, sortable,firstindex) {

    var thumbclickcode = "";
    var prefix = "";
    switch (tipogal) {
        case "I":
            if (tipoowner == "I") {
                thumbclickcode = "SelectImg(\"itemid\")";
            }

            if (tipoowner == "S") {
                thumbclickcode = "SelectSectionImg(\"itemid\")";
            }

            prefix = "galimg[]=";
            break;
        case "D":
            thumbclickcode = "SelectDoc(\"itemid\")";
            if (tipoowner == "S") {
                thumbclickcode = "SelectSectionDoc(\"itemid\")";
            }
            prefix = "galdoc[]=";

            break;
    }

    $.ajax({
        type: "POST",
        url: "/sharedfunctions.asmx/GetAdGalleryCode",
        data: "{'ownerid':'" + ownerid + "','ownertype':'" + tipoowner + "','galtype':'" + tipogal + "','thumbclickcode':'" + thumbclickcode + "','thumbs':'" + thumb + "','bigimg':'" + bigimg + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        indiceini = 0;
       
            if (firstindex != null) {
                
                indiceini = firstindex;
            }



            $(galph).html(msg.d);
            $(".ad-gallery", galph).adGallery({
                width: 400,
                height: 300,
                start_at_index: indiceini
            });
            if (sortable) {
                $(".ad-thumb-list", galph).sortable(
                                     { update: function(event, ui) {
                                         nuovoord = $(".ad-thumb-list", galph).sortable("serialize");
                                         $.ajax({
                                             type: "POST",
                                             url: "/sharedfunctions.asmx/SaveGalOrder",
                                             data: "{'imgids':'" + nuovoord + "','prefix':'" + prefix + "'}",
                                             contentType: "application/json; charset=utf-8",
                                             dataType: "json",
                                             success: function(msg) {
                                             },
                                             error: function(xhr, ajaxOptions, thrownError) {
                                                 alert(xhr.responseText);
                                             }
                                         });
                                     }


                                     });
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError);
        }
    });
}




function Watermark(item) {

    $(item).val($(item).attr("title"));
    $(item).addClass("watermark");

    $(item).focusin(
    function() {
        if ($(item).val() == $(item).attr("title")) {
            $(item).val('');
            $(item).removeClass("watermark");
        }
    });

    $(item).focusout(
    function() {
        if ($(item).val() == '') {
            $(item).val($(item).attr("title"));
            $(item).addClass("watermark");
        }
    });
}

