(function($) {
    $.fn.emptySelect = function() {
        return this.each(function(){
            if (this.tagName=='SELECT') this.options.length = 0;
        });
    }

    $.fn.affiche = function(optionsDataArray) {

        function createElement(element) {
            if (typeof document.createElementNS != 'undefined') {
                return document.createElementNS('http://www.w3.org/1999/xhtml', element);
            }
            if (typeof document.createElement != 'undefined') {
                return document.createElement(element);
            }
            return false;
        }
  
        return this.emptySelect().each(function(){
            //var selectElement = this;
            var table = document.createElement("table");
            table.setAttribute("class","table");
            table.setAttribute("className","table");
            table.style.width = "100%";
            var thead = document.createElement("thead");
            thead.style.height = "0px";
            var tfoot = document.createElement("tfoot");
            tfoot.style.height = "0px";
            var tbody = document.createElement("tbody");
            var tha = document.createElement("tr");
            var thda = document.createElement("th");
            var thdb = document.createElement("th");
            var thde = document.createElement("th");
            thde.style.width = "26%";
            var thdc = document.createElement("th");
            var thdd = document.createElement("th");
            thda.innerHTML = ("Classe");
            thdb.innerHTML = ("");
            thde.innerHTML = ("Excursions");
            thdc.innerHTML = ("Prix/pers");
            thdd.innerHTML = ("");

            table.appendChild(thead);
            table.appendChild(tfoot);
            table.appendChild(tbody);
            tbody.appendChild(tha);
            tha.appendChild(thda);
            tha.appendChild(thdb);
            tha.appendChild(thde);
            tha.appendChild(thdc);
            tha.appendChild(thdd);
            
            $.each(optionsDataArray,function(index,optionData){
                if (optionData.PriceEur != '0') {
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");
                    var td2 = document.createElement("td");
                    var td5 = document.createElement("td");
                    var td3 = document.createElement("td");
                    var td4 = document.createElement("td");
                    td1.innerHTML = (optionData.Class);
                    tr.appendChild(td1);
                    td2.innerHTML = (optionData.Pax + " Pers");
                    tr.appendChild(td2);
                    td5.innerHTML = (optionData.ExtraFr);
                    tr.appendChild(td5);
                    td3.innerHTML = ((optionData.PriceEur) + " \u20ac");
                    td3.style.color = "red";
                    tr.appendChild(td3);
                    var dispo;
                    if (optionData.Site == 'Y') {
                        dispo = 'Disponible';
                        td4.style.color = "green";
                    }
                    else {
                        dispo = 'Complet';
                        td3.style.textDecoration = "line-through";
                        td4.style.color = "red";
                    }
                    td4.innerHTML = (dispo);
                    tr.appendChild(td4);
                    tbody.appendChild(tr);
                    td1.setAttribute("class","head"); //firefox
                    td1.setAttribute("className","head"); //ie6
                    td2.setAttribute("class","even");
                    td2.setAttribute("className","even");
                    td5.setAttribute("class","even");
                    td5.setAttribute("className","even");
                    td3.setAttribute("class","even");
                    td3.setAttribute("className","even");
                    td4.setAttribute("class","even");
                    td4.setAttribute("className","even");
                }
            });

            document.getElementById("resultTable").appendChild(table);                
        });
    }
})(jQuery);