﻿

function changeProdukteAjax(pHerstellerID, pKategorieID)
{   
    $.ajax(
    {
        url: "ajaxhelper.aspx/changeProdukte",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: "{ pHerstellerID:'" + pHerstellerID + "', pKategorieID: '" + pKategorieID + "'}",
        dataType: "json",
        success: function (res) 
        {
            var strHTML = "";
            var iWidth = "334px";
            var iMarginTop = "200px";

            if(iResolution == "1024") { iWidth = "228px"; iMarginTop = "175px"; }

            if(res.d.length == 0)
            { strHTML = "<div style='color:#e7e7d5;font-size:24px;width:"+iWidth+";text-align:center;margin-top:"+iMarginTop+";'>Kein Treffer</div>"; }
            else
            {
                for(var i=0; (Produkt=res.d[i]); i++)
                { 
                    strHTML +=  "<div id='repProdukte_divProdukt_" + i + "' class='divProdukt'>" +
                                    "<a id='repProdukte_hlProdukt_"+ i + "' onclick=\"changeProdukt('" + Produkt.ID + "','repProdukte_divProdukt_" + i + "', 'divText', 'frames/iframe.aspx?src=" + Produkt.Streaming + "&width=658&height=368', '" + Produkt.Beschreibung + "');\" href='javascript:;' >" +
                                        "<div class='divBild'><img id='repProdukte_imgProdukt_" + i + "' src='" + Produkt.Bild + "' /></div>" +
                                        "<div class='divProduktTitel'>" +
                                            "<span id='repProdukte_lblTitel_"+i+"'>" + Produkt.Hersteller + "</span>" +
                                        "</div>" +
                                        "<div class='divProduktModell'>" +
                                            "<span id='repProdukte_lblModell_"+i+"'>" + Produkt.Modell + "</span>" +
                                        "</div>" +
                                    "</a>" +
                                "</div>";
                }
            }
            $("#divProdukte").html(strHTML);
        },
        error: function (err)   { alert(err.responseText); }
    });
}

function changeHerstellerAjax(pHerstellerID, pKategorieID) 
{
    $.ajax(
    {
        url: "ajaxhelper.aspx/changeHersteller",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: "{ pHerstellerID:'" + pHerstellerID + "', pKategorieID: '" + pKategorieID + "'}",
        dataType: "json",
        success: function (res) 
        {
            $("#ddHersteller > option").remove();
            $("#ddHersteller").append("<option value='0'>Marken wählen</option>");
            for (var i = 0; (Hersteller = res.d[i]); i++) 
            {                
                $("#ddHersteller").append("<option value='" + Hersteller.ID + "'>" + Hersteller._Hersteller + "</option>");
            }
            $("#ddHersteller").val(pHerstellerID);
        },
        error: function (err) { alert(err.responseText); }
    });
}

function changeKategorieAjax(pKategorieID, pHerstellerID) 
{
    $.ajax(
    {
        url: "ajaxhelper.aspx/changeKategorie",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: "{ pKategorieID:'" + pKategorieID + "', pHerstellerID: '" + pHerstellerID + "'}",
        dataType: "json",
        success: function (res)
        {
            $("#ddKategorie > option").remove();
            $("#ddKategorie").append("<option value='0'>Kategorie wählen</option>");
            for (var i = 0; (Kategorie = res.d[i]); i++) 
            {
                $("#ddKategorie").append("<option value='" + Kategorie.ID + "'>" + Kategorie._Kategorie + "</option>");
            }
            $("#ddKategorie").val(pKategorieID);
        },
        error: function (err) { alert(err.responseText); }
    });
}


function setMedienByProductId(pID, pView)
{
    $.ajax(
    {
        url: "ajaxhelper.aspx/getMedienByProductId",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: "{ pID:'" + pID + "'}",
        dataType: "json",
        async: false,
        success: function (res) 
        {
            var strHTML = "";
            var strStyle = "";
            var strSize;
            
            if(pView == "full") 
            {
                if(iResolution == "1024")
                     { strSize = "&w=688&h=350"; }
                else { strSize = "&w=991&h=507"; }
            }
            else 
            {
                if(iResolution == "1024")
                     { strSize = "&w=460&h=258"; }
                else { strSize = "&w=650&h=368"; }
            }

            for(var i=0; (Medium=res.d[i]); i++)
            { 
                if(i>0) { strStyle = "style='display:none'"; }
                strHTML +=  "<img id='img"+i+"' border='0' " + strStyle + " src='" + Medium.WebPath + strSize + "' />";
            }
            $("#divFotos").html(strHTML);
            $("#divBlättern").html("1 / "+res.d.length);

            imgCount = res.d.length;
            navIndex = 0;
        },
        error: function (err)   { alert(err.responseText); }
    });
}
