﻿var translationTemp = "";
var translationTemp2 = "";
var state = StateHandler.getInstance();
$(document).ready(function() {
    state.readUrl();
    $("#appDetail-infobox #image").corner("10px");    
    $("#browsable").scrollable({
                    size: 1,
                    hoverClass: 'hover',
                    disabledClass: '',
                    item: 'img'
                }).navigator();
    $("#videoScroll").scrollable({
                    size: 3,
                    hoverClass: 'hover',                    
                    item: 'img'
    });        
    $(".videoItems img").click(function(e){
        playVideo($(this).attr("rel"));
        trackEvent("AppDetail", "PlayVideo", $(this).attr("rel"));
        $("#videoInfoUser").text($(this).attr("rel2"));
        $("#videoInfoDate").text($(this).attr("rel3"));
    });
    $(".videoItems img:first").addClass("active");
    
    $("ul.gallery-tabs").tabs("div.gallery-panes > div",{  
        onBeforeClick: function(event, tabIndex) { 
            if(tabIndex != 0 || state.getParam("gallery", "0") != "0")
                state.fireEvent("gallery", tabIndex);
            if(tabIndex == 1)
                trackEvent("AppDetail","VideoTab",appID);
        },
        initialIndex : parseInt(state.getParam("gallery", "0"))           
    });
    if($(".activity").length > 10){
        $(".activities").after('<a href="#" id="activitiesAll" style="display:block;margin-bottom:20px;margin-top:3px;">' + getLocal('alle einblenden') + '</a>');
        $("#activitiesAll").click(showAllActivities);
    }else{
        $(".activities").css("margin-bottom",20);
    }
    
    var hoverIntentConfig = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 250, // number = milliseconds for onMouseOver polling interval    
         over: function(){$("#partnerLogoHover").show()}, // function = onMouseOver callback (REQUIRED)    
         timeout: 800, // number = milliseconds delay before onMouseOut    
         out: function(){$("#partnerLogoHover").hide();} // function = onMouseOut callback (REQUIRED)    
    };


    
    $(".partnerLogo").hoverIntent(hoverIntentConfig);
    
        
    $("ul.css-tabs").tabs("div.css-panes > div",{         
        // add a class "current" to the active pane 
        onBeforeClick: function(event, tabIndex) { 
            if(tabIndex != 0 || state.getParam("Tab", "0") != "0")
                state.fireEvent("Tab", tabIndex);
            if(tabIndex == 1){
                trackEvent("AppDetail","AppReviewTab",appID);
                loadReviews();
            }else if(tabIndex == 2){
                //trackEvent("AppDetail","AppCommentTab",appID);
                loadComments();
            }
        },
        initialIndex : parseInt(state.getParam("Tab", "0"))            
    });
    $(".appVideoHelpDirect").click(function(e){
        e.preventDefault();
        playVideo("WIzUN64-OI0");
    });
    $(".appVideoHelp").overlay({effect: 'apple'});
    $("#postComment").click(function(e){
        e.preventDefault();
        var text = $("#commentBox").val();
        var type = $("#postType").val();        
        if(text.length > 10 && text.length <= 500){
            if(type != "0"){
                $.ajax({
                    type: "POST",
                    url: "/Service/Details.asmx/InsertComment",
                    data: "{'appID':'" + iTunesAppID + "','type':'"+ type+"','text':'" + text + "','threadID':'0'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        var json = eval('(' + msg.d + ')');
                        if(json.result == "success"){                    
                            window.location.reload();
                        }              
                    }
                });
            }else{
                $("#commentMessage").addClass("red");
                $("#commentMessage").text(getLocal("Bitte einen Kommentartyp auswählen"));
            }
        }else{
            $("#commentMessage").addClass("red");
            $("#commentMessage").text(getLocal("Der Kommentar muss mindestens 10 und maximal 500 Zeichen lang sein"));
        }
    });  
    $(".actionSpam").click(function(e){
        e.preventDefault();
        if (isAuth == "True") {
            var commentID = $(this).attr("rel");
            $.ajax({
                type: "POST",
                url: "/Service/Details.asmx/FlagCommentAsSpam",
                data: "{'appID':'" + iTunesAppID + "','commentID':'"+commentID+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    var json = eval('(' + msg.d + ')');
                    if(json.result == "success"){                    
                        window.location.reload();
                    }              
                }
            });   
        }
    })
    $(".actionReplyDelete").click(function(e){
        e.preventDefault();
        if (isAuth == "True") {
            var commentID = $(this).attr("rel");
            $.ajax({
                type: "POST",
                url: "/Service/Details.asmx/DeleteComment",
                data: "{'appID':'" + iTunesAppID + "','commentID':'"+commentID+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    var json = eval('(' + msg.d + ')');
                    if(json.result == "success"){                    
                        window.location.reload();
                    }              
                }
            });   
        }
    });
    $(".actionReply").click(function(e){
        e.preventDefault();
        if (isAuth == "True") {
            var commentID = $(this).attr("rel");
            var form = $(".replyForm[rel='"+commentID+"']");
            form.html($("#replyDefaultForm").html());
            form.find("#replyCommentCancel").click(function(e){
                e.preventDefault();
                form.empty();
            });
            form.find("#replyCommentPost").click(function(e){
                e.preventDefault();              
                var text = form.find("#replyCommentBox").val();
                if(text.length > 10 && text.length <= 500){
                    form.find("#replyCommentMessage").text("");
                    $.ajax({
                        type: "POST",
                        url: "/Service/Details.asmx/InsertComment",
                        data: "{'appID':'" + iTunesAppID + "','type':'Reply','text':'" + text + "','threadID':'"+commentID+"'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {
                            var json = eval('(' + msg.d + ')');
                            if(json.result == "success"){                    
                                window.location.reload();
                            }              
                        }
                    });                    
                }else{
                    form.find("#replyCommentMessage").addClass("red");
                    form.find("#replyCommentMessage").text(getLocal("Der Kommentar muss mindestens 10 und maximal 500 Zeichen lang sein"));
                }
            });            
        }
    });
     
    $("#videoActionAdd, #videoActionAddCancelButton").click(function(e){
        e.preventDefault();
        if(isAuth == "True")
        { 
            $("#videoActionAddPanel").slideToggle();
        }else{
            $("#videoActionNotAuthPanel").slideToggle();
        }
        
    });   
    
    $("#videoActionAddButton").click(function(e){
        e.preventDefault();
        var url = $("#videoActionAddTextBox").val();
        if(url.length > 5){
            $("#videoActionText").removeClass();
            $("#videoActionText").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif"/>');
            $.ajax({
                type: "POST",
                url: "/Service/Details.asmx/InsertVideo",
                data: "{'appID':'" + iTunesAppID + "','url':'" + url + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    var json = eval('(' + msg.d + ')');
                    if(json.result == "success"){
                        $("#videoActionText").addClass("green");
                        $("#videoActionText").text(getLocal("erfolgreich hinzugefügt"));
                        $("#videoActionAddTextBox").val("");
                        window.location.reload();
                    }else if(json.result == "exists"){
                        $("#videoActionText").addClass("red");
                        $("#videoActionText").text(getLocal("Video schon vorhanden"));
                    }else{
                        $("#videoActionText").addClass("red");
                        $("#videoActionText").text(getLocal("Diese Url ist ungültig"));
                    }                    
                }
            });
            
        }else{
            $("#videoActionText").addClass("red");
            $("#videoActionText").text(getLocal("Diese Url ist ungültig"));
        }
    });   
    
    setMyAppsFunctions();   
    $("#action_priceAlarm").click(function() {
        if (isAuth == "True") {
            $("#ActionBlockPriceAlarmInner").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif" style="margin:5px auto 5px 20px;"/>');
            loadMyApp("PriceAlarm");
        }
        toggleActionButton(this);
        $("#ActionBlockPriceAlarm").toggle();
    });
    $("#action_ihave").click(function() {
        if (isAuth == "True") {
            $("#ActionBlockMyAppInner").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif" style="margin:5px auto 5px 20px;"/>');
            loadMyApp("MyApps");
        }
        toggleActionButton(this);
        $("#ActionBlockMyApp").toggle();
    });
    $("#action_iwant").click(function() {
        if (isAuth == "True") {
            $("#ActionBlockWishlistInner").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif" style="margin:5px auto 5px 20px;"/>');
            loadMyApp("Wishlist");
        }
        toggleActionButton(this);
        $("#ActionBlockWishlist").toggle();
    });
    $("#action_like").click(function() {
        if (isAuth == "True") {
            $("#ActionBlockLike").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif" style="margin:5px auto 5px 20px;"/>');
            loadLikes();
        }
        toggleActionButton(this);
        $("#ActionBlockLike").toggle();
    });
    $("#action_addlist").click(function() {
        if (isAuth == "True") {
            $("#ActionBlockAddList").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif" style="margin:5px auto 5px 20px;"/>');
            loadCustomLists();
        }
        toggleActionButton(this);
        $("#ActionBlockAddList").toggle();
    });
    $("#action_share").click(function() {      
        toggleActionButton(this);
        $("#ActionBlockShare").toggle();
    });
    // default View
    $("#action_share").click();
    $(".action").hover(function() { $(this).children(".action_button").addClass("hover"); }, function() { $(this).children(".action_button").removeClass("hover"); }); 
    $.ajax({
        type: "POST",
        url: "/Service/Listings.asmx/GetRecommendationAppIDs",
        data: "{'appID':'" + appID + "','limit':'20'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var json = eval('(' + msg.d + ')');
            if (json.ResultSet.length == 0) {
                $("#recommendApps").prev().remove();
                $("#recommendApps").remove();
                return;
            }
            $("#recommendApps").setTemplate($("#AppDetailArtistTemplate").html());
            $("#recommendApps").processTemplate(json);
            jQuery.each(json.ResultSet, function(index) {
                var parentDiv = $("#recommendApps div[rel='" + json.ResultSet[index] + "']");
                loadAppDetails(parentDiv, json.ResultSet[index]);
            });
        }
    });
    $.ajax({
        type: "POST",
        url: "/Service/Listings.asmx/GetArtistAppIDs",
        data: "{'appID':'" + appID + "','artistID':'" + artistID + "','limit':'20'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var json = eval('(' + msg.d + ')');
            if (json.ResultSet.length == 0) {
                $("#artistApps").prev().prev().remove();
                $("#artistApps").prev().remove();
                $("#artistApps").remove();
                return;
            }
            $("#artistApps").setTemplate($("#AppDetailArtistTemplate").html());
            $("#artistApps").processTemplate(json);
            jQuery.each(json.ResultSet, function(index) {
                var parentDiv = $("#artistApps div[rel='" + json.ResultSet[index] + "']");
                loadAppDetails(parentDiv, json.ResultSet[index]);
            });
        }
    });
    $.ajax({
        type: "POST",
        url: "/Service/Tracking.asmx/TrackDetailClick",
        data: "{'appID':'" + appID + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
                    $("#browsable img").each(function(){
                        var height = $(this).height();
                        if(height > 0){
                            var max_height = parseInt($(this).css("max-height"));
                            $(this).css("top", ((max_height - height) / 2) + "px");
                        }
                    }); 
        }
    });
    if (curListID > 0) {
        $.ajax({
            type: "POST",
            url: "/Service/listings.asmx/GetCustomList",
            data: "{'listID':'" + curListID + "','priceFilter':'All','sorting':'NoSort','page':'1','appsPerPage':'100'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var json = eval('(' + msg.d + ')');
                if (json.ResultSet.length == 0) {
                    $("#collection").prev().remove();
                    $("#collection").remove();
                    return;
                }
                $("#collection").setTemplate($("#AppDetailArtistTemplate").html());
                $("#collection").processTemplate(json);
                jQuery.each(json.ResultSet, function(index) {
                    var parentDiv = $("#collection div[rel='" + json.ResultSet[index] + "']");
                    loadCollectionAppDetails(parentDiv, json.ResultSet[index], (json.ResultSet[index] == appID), index);
                });

            }
        });
    } else {
        $("#collection").prev().remove();
        $("#collection").remove();
    }
    if (Top100GenreID >= 0) {
        
        $.ajax({
            type: "POST",
            url: "/Service/Charts.asmx/GetItunesTop100",
            data: "{'genreID':'" + Top100GenreID + "','type':'" + Top100Type + "','sort':'Position','langID':'"+currentLang+"'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var json = eval('(' + msg.d + ')');
                if (json.ResultSet.length == 0) {
                    $("#top100").prev().prev().remove();
                    $("#top100").prev().remove();
                    $("#top100").remove();
                    return;
                }
                $("#top100").setTemplate($("#Top100ListTemplate").html());
                $("#top100").processTemplate(json);

                var activeElement = $("#artistAppsDetail[rel='" + appID + "']");
                $(activeElement).addClass("active");
                $(activeElement).parent().scrollTop(60 * (parseInt($(activeElement).find("#index").text()) - 1));
            }
        });
    } else {
        $("#top100").prev().prev().remove();
        $("#top100").prev().remove();
        $("#top100").remove();
    }
    
    $("#translate").click(function(e) {
        e.preventDefault();
        if (!$(this).hasClass("trans")) {            
            $(this).addClass("trans");
            translationTemp = $("#innerDesc").html();
            $("#innerDesc").html('<img src="http://static.appzapp.de/Images/ajax-loader.gif"/>');
            var text = (translationTemp);
            var text2 = "";
            var dosecondTrans = false;
            text = text.substring(0, 1200);
            if (translationTemp.length > 1200) {
                var text2 = translationTemp.substring(1200, 2400);
                dosecondTrans = true;
            }
            translate(text, function(result) {
                $("#innerDesc").html(result);
                $("#translate").text(getLocal("Übersetzung rückgängig machen"));
                if (dosecondTrans) {
                    translate(text2, function(result) {
                        $("#innerDesc").append(result);
                        translateWhatsNew();
                    });
                } else
                    translateWhatsNew();
            });
            trackEvent("UserEvents","TranslationRequested",appID);
        } else {
            $("#innerDesc").html(translationTemp);
            $("#translate").text(getLocal("Nochmals übersetzen."));
            $(this).removeClass("trans");
        }
    });
    $("#videoReport").click(function(e){
        e.preventDefault();
        
    });
});
function showAllActivities(e){
    e.preventDefault();
    $(".activities").css("max-height",800);
    $("#activitiesAll").text(getLocal("ausblenden"));
    $("#activitiesAll").unbind("click",showAllActivities);
    $("#activitiesAll").click(hideAllActivities);
}
function hideAllActivities(e){
    e.preventDefault();
    $(".activities").css("max-height",250);
    $("#activitiesAll").text(getLocal("alle einblenden"));
    $("#activitiesAll").unbind("click",hideAllActivities);
    $("#activitiesAll").click(showAllActivities);
}
function onYouTubePlayerReady(playerid){
    if(state.getParam("videoID", "false") != "false"){        
        playVideo(state.getParam("videoID", "false"));
        trackEvent("AppDetail", "PlayVideo", state.getParam("videoID", "false"));
        $(".videoItems img").removeClass("active");
        $(".videoItems img[rel='"+state.getParam("videoID", "false")+"']").addClass("active");
                       
    }
}
function playVideo(playerId) {
     $("#videoReport").attr("rel",playerId);     
      ytplayer = document.getElementById("myytplayer");
       if (ytplayer) {
            ytplayer.loadVideoById(playerId,0);            
       }

}


var loadedReviews = false;
var reviewSorting = "Created";
var reviewPage = 1;
var reviewTotalPages = 1;
var reviewsPerPage = 10;
/*
*
*       FUNKTIONEN
*
**/
function loadReviews(){
    if(!loadedReviews){
        $("#reviews").html('<div style="text-align:center"><img src="http://static.appzapp.de/Images/ajax-loader-big.gif"/></div>');
        $.ajax({
            type: "POST",
            url: "/Service/Details.asmx/GetReviews",
            data: "{'appid':'" + appID + "','sorting':'" + reviewSorting + "','page':'" + reviewPage + "','appsPerPage':'" + reviewsPerPage + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var json = eval('(' + msg.d + ')');
                if (json.ResultSet.length == 0) {
                    $("#reviews").html('<div style="text-align:center">' + getLocal("Es sind keine Rezensionen verfügbar") + '</div>');
                    return;
                }
                $("#reviews").setTemplate($("#ReviewTemplate").html());
                $("#reviews").processTemplate(json);
                $("#ReviewSort").AppZappDrowDown({
                    clickEvent: function(relation) {
                        reviewSorting = relation;
                        reviewPage = 1;
                        loadedReviews = false;
                        loadReviews();
                    },
                    topImage : "",
                    cssPrefix: "ReviewSort_",
                    activeRelation: reviewSorting
                });
                reviewTotalPages = json.TotalPages;
                if (json.TotalPages > 1) {
                    $(".pagerTop").pager({ pagenumber: reviewPage, pagecount: reviewTotalPages, buttonClickCallback: handleReviewPageEvent, isTop: true });
                    $(".pagerBottom").pager({ pagenumber: reviewPage, pagecount: reviewTotalPages, buttonClickCallback: handleReviewPageEvent, isTop: false });
                }

            }
        });
           
        loadedReviews = true;
    }
}
function loadComments(){

}
function handleReviewPageEvent(event, page, isTop) {                
        switch (event) {
            case 'next':
                if (reviewPage + 1 > reviewTotalPages)
                    return;
                reviewPage++;
                break;
            case 'prev':
                if (reviewPage - 1 <= 0)
                    return;
                reviewPage--;
                break;
            case 'first':
                if (reviewPage == 1)
                    return;
                reviewPage = 1;
                break;
            case 'last':
                if (reviewPage == reviewTotalPages)
                    return;
                reviewPage = reviewTotalPages;
                break;
            case 'page':
                if(reviewPage == page)
                    return;
                reviewPage = page;
                break;
        }
        loadedReviews = false;
        if(!isTop){
            $('html, body').animate({scrollTop:700}, 400);
            
            $("#reviews").wait(500, function(){loadReviews();});
        }else
            loadReviews();
    };
function translateWhatsNew(){
    translationTemp2 = $("#whatsNew").html();
    if(translationTemp2 == null || translationTemp2.length == 0)
        return;
    var text = (translationTemp2);
    var text2 = "";
    var dosecondTrans = false;
    text = text.substring(0,1200);
    if(translationTemp2.length > 1200){                
        var text2 = translationTemp2.substring(1200,2400);
        dosecondTrans = true;
    } 
    translate(text,function(result){
        $("#innerDesc").append('<br><br><br><br><h4>Was ist neu in dieser Version</h4>');
        $("#innerDesc").append(result);        
        if(dosecondTrans){                        
             translate(text2, function(result) {
                $("#innerDesc").append(result);  
             });
        }
    });
    
}
function translate(text,callback){
    google.language.translate(text, "en", "de", function(result) {
        if (!result.error) {  
            callback(result.translation);                       
        }
    });      
}
function toggleActionButton(element){
    if (!$(element).children(".action_button").hasClass("active")) {
        $(".action_button").removeClass("active");
        $(".actionPanel").hide();
        $(element).children(".action_button").addClass("active");
    } else
        $(element).children(".action_button").removeClass("active");
}
function loadMyApp(type){            
    $.ajax({
        type: "POST",
        url: "/Service/User.asmx/InsertToMyApps",
        data: "{'appID':'" + appID + "','type':'"+type+"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            json = eval('(' + msg.d + ')');
            switch(type){
                case 'MyApps':
                    if(json.result == 'ok'){
                        $("#ActionBlockMyAppInner").html('<div style="float:left"><img src="http://static.appzapp.de/Images/icon_ok.png" width="25"/></Div><div style="float:left">' + getLocal("App wurde erfolgreich in die Liste MyApps gelegt") +'</div></div>');
                        trackEvent("MyApps","MyAppsFromDetail",appID);
                    }else
                        $("#ActionBlockMyAppInner").html(getLocal("Diese App ist bereits in Dieser Liste"));
                       
                break;
                case 'Wishlist':
                    if(json.result == 'ok'){
                        $("#ActionBlockWishlistInner").html('<div style="float:left"><img src="http://static.appzapp.de/Images/icon_ok.png" width="25"/></Div><div style="float:left">' + getLocal("App wurde erfolgreich in deine Merkliste gelegt") +'</div></div>');
                        trackEvent("MyApps","WishlistFromDetail",appID);
                    }else
                        $("#ActionBlockWishlistInner").html(getLocal("Diese App ist bereits in Dieser Liste"));
                break;
                case 'PriceAlarm':
                    if(json.result == 'ok'){
                        $("#ActionBlockPriceAlarmInner").html('<div style="float:left"><img src="http://static.appzapp.de/Images/icon_ok.png" width="25"/></Div><div style="float:left">' + getLocal("PriceAlarmAdded") + '<a href="/User/Preisalarm.html">' + getLocal("zur Liste") + ' >></a></div></div>');
                        trackEvent("MyApps","PriceAlarmFromDetail",appID);
                    }else
                        $("#ActionBlockPriceAlarmInner").html(getLocal("PriceAlarmAlreadyAdded")+ '<a href="/User/Preisalarm.html">' + getLocal("zur Liste") + ' >></a>');
                break;
            }               
        },
        error: function(msg) { parentDiv.hide(); return false; }
    });
}
function loadLikes() {
    $.ajax({
        type: "POST",
        url: '/Service/User.asmx/InsertAppLike',
        data: "{'id':'" + iTunesAppID + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            json = eval('(' + msg.d + ')');
            $("#ActionBlockLike").setTemplate($("#LikeTemplate").html());
            $("#ActionBlockLike").processTemplate(json);
            trackEvent("Likes","InsertFromDetail",appID);
        },
        error: function(msg) { parentDiv.hide(); return false; }
    });
}
function loadCustomLists() {
    $.ajax({
        type: "POST",
        url: "/Service/CustomLists.asmx/GetLists",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var json = eval('(' + msg.d + ')');
            $("#ActionBlockAddList").setTemplate($("#CustomListTemplate").html());
            $("#ActionBlockAddList").processTemplate(json);
            if ($("#addListSelect").val() == "0")
                $("#newListDiv").show();
            $("#addListSelect").change(function() {
                if ($("#addListSelect").val() == "0")
                    $("#newListDiv").show();
                else
                    $("#newListDiv").hide();
            });
            $("#addListButton").click(function(event) {
                event.preventDefault();
                var listid = $("#addListSelect").val();
                if (listid == "0") {
                    // neue Liste
                    var title = $("#addNewListTextBox").val();
                    if (title.length >= 1) {
                        $.ajax({
                            type: "POST",
                            url: "/Service/CustomLists.asmx/InsertCustomList",
                            data: "{'title':'" + title + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function(msg) {
                                var json = eval('(' + msg.d + ')');
                                $("#errorMessages").empty();
                                if (json.result == "ok") {
                                    loadCustomLists();
                                    trackEvent("CustomLists","CreatedFromDetail",title);
                                }
                                else if (json.result == "exists")
                                    $("#errorMessages").wrapInner('<ul></ul>').html(getLocal('Sie haben bereits eine Liste mit dem selben Namen erstellt.')).wrapInner('<li></li>');
                                else
                                    $("#errorMessages").wrapInner('<ul></ul>').html(getLocal('Diese Funktion ist zur Zeit leider nicht verfügbar.')).wrapInner('<li></li>');

                            },
                            error: function(msg) { return false; }
                        });
                    } else {
                        $("#errorMessages").empty();
                        $("#errorMessages").wrapInner('<ul></ul>').html(getLocal('Vergeben Sie bitte einen Titel.')).wrapInner('<li></li>');
                    }
                } else {
                    // element hinzufügen
                    $.ajax({
                        type: "POST",
                        url: "/Service/CustomLists.asmx/InsertAppToList",
                        data: "{'listID':'" + listid + "','appID':'" + appID + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {
                            var json = eval('(' + msg.d + ')');
                            if (json.result == "ok") {
                                trackEvent("CustomList","AppToCustomList",appID);
                                $("#ActionBlockAddList").html('<div id="ActionBlockAddListInner"><div style="float:left"><img src="http://static.appzapp.de/Images/icon_ok.png" width="25"/></Div><div style="float:left">' + getLocal("Die App wurde erfolgreich hinzugefügt.") +'</div></div>');
                            }
                            else
                                $("#errorMessages").wrapInner('<ul></ul>').html(getLocal('Diese App ist bereits in dieser Liste')).wrapInner('<li></li>');

                        },
                        error: function(msg) { return false; }
                    });

                }
            });
        }
    });
}

function setMyAppsFunctions() {
    if (isAuth == "False") {
        $("a[rel='userAreaMyApp'], a[rel='userAreaWishlist']").click(
                    function(event) {
                        event.preventDefault();
                        $("#appDetail-infobox").animate({ height: "150px" }, 500);
                    });
    }
}

function loadAppDetails(element, id) {
    $.ajax({
        type: "POST",
        url: "/Service/listings.asmx/GetAppDetail",
        data: "{'id':'" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            javascript: try {
                var json = eval('(' + msg.d + ')');
                $(element).setTemplate($("#AppDetailArtistDetailTemplate").html());
                $(element).processTemplate(json);
                $("#act_" + id + " #image").corner("10px");
            } catch (e) { alert(e); }
        },
        error: function(msg) { element.hide(); }
    });
}
function loadCollectionAppDetails(element, id, active,index) {
    $.ajax({
        type: "POST",
        url: "/Service/listings.asmx/GetAppDetail",
        data: "{'id':'" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            javascript: try {
                var json = eval('(' + msg.d + ')');
                $(element).setTemplate($("#AppDetailCollectionDetailTemplate").html());
                $(element).setParam("Temp",curListID);
                $(element).setParam("Index",index);
                $(element).processTemplate(json);
                $("#act_" + id + " #image").corner("10px");
                if(active){
                    $(element).addClass("active");
                    $(element).parent().scrollTop(index*60);
                }
            } catch (e) { alert(e); }
        },
        error: function(msg) { element.hide(); }
    });
}


