// Funzione per il debug, visualizza le proprietà di un oggetto
function dumpProps(obj, parent) {
    // Go through all the properties of the passed-in object   
    for (var i in obj) {
        // if a parent (2nd parameter) was passed in, then use that to      
        // build the message. Message includes i (the object's property name)      
        // then the object's property value on a new line      
        if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
        // Display the message. If the user clicks "OK", then continue. If they      
        // click "CANCEL" then quit this level of recursion      
        if (!confirm(msg)) { return; }
        // If this property (i) is an object, then recursively process the object      
        if (typeof obj[i] == "object") {
            if (parent) { dumpProps(obj[i], parent + "." + i); }
            else { dumpProps(obj[i], i); }
        }
    }
}


$(document).ready(function () {
    try {
        $.ajax({
            type: "GET",
            url: "/_layouts/Avvenire/listdata.aspx",
            dataType: "xml",
            success: function (xml) {
                $('#tabberContainer').text("");
                $(xml).find('feed').each(function () {
                    $(this).find('entry').each(function () {
                        $(this).find('content').each(function () {
                            $(this).find('[nodeName="m:properties"]').each(function () {
                                var title = $(this).find('[nodeName="d:ID"]').text();
                                var urlImg = "";
                                var vURL = $(this).find('[nodeName="d:URL"]').text();
                                var link = $.trim(vURL.substring(0, vURL.indexOf(",")));
                                var linkDesc = $.trim(vURL.substring(vURL.indexOf(",") + 1));
                                //var strillo = $(this).find('[nodeName="d:StrilloContenuto"]').text();
                                var defaultTab = $(this).find('[nodeName="d:Default"]').text();
                                var vImg = $(this).find('[nodeName="d:Immagine"]').text();
                                var titolo = $(this).find('[nodeName="d:Titolo"]').text();
                                var vRichText = $(this).find('[nodeName="d:ComponenteRichText"]').text();
                                var viframe = htmlDecode($(this).find('[nodeName="d:iframe"]').text());

                                if (vImg != null) {
                                    urlImg = vImg.substring(0, vImg.indexOf(","));
                                }
                                if (defaultTab == 1) // imposto il tab attivo
                                {
                                    html = '<div class="tabbertab tabbertabdefault" title="' + titolo + '">';
                                }
                                else {
                                    html = '<div class="tabbertab" title="' + titolo + '">';
                                }
                                if (urlImg != null && urlImg.length > 0) {
                                    html += '<a href="' + link + '"><img style="float: right; margin-left: 5px" alt="" src="' + urlImg + '" /></a>';
                                }

                                html += viframe;


                                html += '<h3 style="margin-top: 0px; font-size: 1.2em; margin-bottom: 0px; color: #505050"><a href="' + link + '">' + linkDesc + '</a></h3>';

                                html += vRichText;

                                html += '</div>';

                                $('#tabberContainer').append($(html));
                            });
                        });
                    });
                });
                tabberAutomatic(tabberOptions);

                //  ajaxJsonPost("GetICLast", "{}", AjaxFailed);


                //ajaxJsonPost("GetData", "{}", AjaxFailed);
              //  ajaxJsonPostOld("GetICLast", "{}", AjaxFailed);


               // ajaxJsonPost("GetElavoro", "{}", AjaxFailed);
            }
        });
    } catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
});

function htmlEncode(value) { return $('<div/>').text(value).html(); }
function htmlDecode(value) { return $('<div/>').html(value).text(); }

//Italia che cresce e lavoro

//Elavoro
function ajaxJsonPost(method, data, error) {



    url = "/_vti_bin/ElavoroWcf/eLavoroService.svc/" + method;

    $.ajax

                 ({

                     url: url,

                     data: data,

                     type: "POST",
                     processData: false,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",

                     success: function (result, status) {


                         // alert(result.d);

                         if (status == "success") {
                             //alert(result.Xml);
                             $('div#colonnaDxLavoro').html(result.d)


                         }

                     },

                     error: error



                 });

}

//ItaiaCheCresce
function ajaxJsonPostOld(method, data, error) {
    //var url = "/_vti_bin/MCMSConnector/MCMSConnector.svc/" + method;
    var url = "/_vti_bin/ElavoroWcf/eLavoroService.svc/" + method;
    $.ajax

                 ({

                     url: url,

                     data: data,

                     type: "POST",
                     processData: false,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",

                     success: function (result, status) {


                         if (status == "success") {
                             var s = result.d.split('#;');

                             if (s.length < 4) {
                                 var a = '<span class="titoloRubricaItalia">L\'ITALIA CHE CRESCE</span><span class="autoreRubricaItalia"> a cura di <b><i>Michele C&egrave;nnamo</i></b></span> ' +
	                              '<span class="abstractRubricaItalia">' + s[1].toString() + '</span>' +
	                            '<span class="titoloArticoloRubricaItalia"><a href="/italiachecresce/Pagine/default.aspx?IdArticolo=' + s[2].toString() + ' ">' + s[0].toString() + '</a></span>' +
                                '<span class="footerRubricaItalia"><a href="/italiachecresce/Pagine/default.aspx">LE ALTRE NOTIZIE</a></span>';
                                 $('div#colonnaDxItalia').html(a);

                             }

                         }

                     },

                     error: error



                 });

}



function AjaxFailed(result) {
    // alert(result.status + ' ' + result.statusText);

}







$(document).ready(function () {
  
        $.ajax({
            type: "GET",
            url: "/_layouts/Avvenire/ItCData.aspx",
            dataType: "xml",
            success: function (xml) {
                var result = '<center><ul id="marquee1" class="marquee" >';
                $(xml).find('feed').each(function () {
                    $(this).find('entry').each(function () {
                        $(this).find('content').each(function () {
                            $(this).find('[nodeName="m:properties"]').each(function () {
                                result += '<li>' + $(this).find('[nodeName="d:Titolo"]').text() + '</li>';

                            });
                        });
                    });
                });
                result += '</ul></center>'

                $('div#colonnaDxItaliaSub').html(result);
                $("#marquee1").marquee();

            }
        });
   
});
