

function changeChart(id,period,listings,colors,width,height,listingName,sc) {
    new Ajax.Updater(id, "chart.html", {
        method: 'get',
        parameters:{
            width:width,
            height:height,
            vcharth:0,
            period:period,
            listings:listings,
            colors:colors,
            mstyle:'9,1',
            href:'detailChart.html?listing='+encodeURIComponent(listings)+"&period="+encodeURIComponent(period)+"&listingName="+encodeURIComponent(listingName)+"&sc="+encodeURIComponent(sc)+"&volume=true"}
    });
    var elements = ["AVAIL","MONTH1","YEAR1"];
    for(var i = 0; i < elements.length; i++) {
        if($(elements[i]) && elements[i]!=period && $(elements[i]).hasClassName('tabactive')) {
            $(elements[i]).removeClassName('tabactive');
        }
    }
    $(period).addClassName("tabactive");
}

//calendar functions
function setCalendarPosition(i,id){
    var position = Element.cumulativeOffset($(id));
    dpckArr[i].setPosition(position[1],position[0]);
    for (j = 0; j < dpckArr.length; j++) {
        if(i != j){
            dpckArr[j].close();
        }
    }
}
function closeCalendar(i){
    dpckArr[i].close();
}
function createCaleandars(idArr, language) {
    var dpckArr = new Array();
    for (i = 0; i < idArr.length; i++) {
        dpckArr[i] = new DatePicker({
            relative          : idArr[i],
            language          : language,
            enableCloseEffect : true,
            enableShowEffect  : true,
            showEffect        : 'appear',
            keepFieldEmpty    : true,
            relativePosition  : false,
            showDuration      : 0.2,
            enableCloseOnBlur : true
        });
        dpckArr[i].setDateFormat(["dd", "mm","yyyy" ], ".");
    }
    return dpckArr;
}

function changeExchangeBox() {
    new Ajax.Updater(
            'listcustomer',
            'listinglists/ajaxListingOptions.jsp',
            {
                method:'get',
                parameters: {list:$F("exchange"),owner:'customer',outputCustomer:'true'},
                onComplete: function(transport) {
                    changeListingList();
                }
            }
     );

}

function changeCategoryBox() {
    new Ajax.Updater(
            'listcustomer',
            'listinglists/ajaxListingOptions.jsp',
            {
                method:'get',
                parameters: {list:$F("category"),owner:'customer',outputCustomer:'true'},
                onComplete: function(transport) {
                    changeCategoryListingList();
                }
            }
    );
}

function changeWarrantBox() {
    new Ajax.Updater(
            'valora',
            'listinglists/ajaxLoadValoras.jsp',
            {
                method:'get',
                parameters: {category:$F("category")},
                onComplete: function(transport) {
                    $("warrantsFormId").submit();
                }
            }
    );
}

function fillSelectBox(box,response) {
    var parser = new ResponseXmlParser();
    parser.load(response);
    var itemList = parser.itemList;
    var options = "";
    for(var i = 0; i < itemList.length; i++) {
        options += "<option value='" + itemList[i][1] + "'>" + itemList[i][0] + "<\/option>";
    }
    $(box).update(options);
}
function changeListingList() {
    var path = "?listcustomer=" + encodeURIComponent($F('listcustomer')) + "&exchange=" + encodeURIComponent($F('exchange'));
    var style = window.location.href.match(/style=(\w*)/);
    if(style) {
        path += "&style=" + encodeURIComponent(style[1]);
    }
    var periodProvided = window.location.href.match(/period=(\d)/);
    if(periodProvided) {
        path += "&period=" + periodProvided[1];
    }
    window.location.href = path;
}
function changeCategoryListingList() {
    var path = "?listcustomer=" + encodeURIComponent($F('listcustomer')) + "&category=" + encodeURIComponent($F('category'));
    var style = window.location.href.match(/style=(\w*)/);
    if(style) {
        path += "&style=" + encodeURIComponent(style[1]);
    }
    var periodProvided = window.location.href.match(/period=(\d)/);
    if(periodProvided) {
        path += "&period=" + periodProvided[1];
    }
    window.location.href = path;
}
function changeCurrencyListingList() {
    var path = "?listcustomer=" + encodeURIComponent($F('listcustomer'));
    var style = window.location.href.match(/style=(\w*)/);
    if(style) {
        path += "&style=" + encodeURIComponent(style[1]);
    }
    var periodProvided = window.location.href.match(/period=(\d)/);
    if(periodProvided) {
        path += "&period=" + periodProvided[1];
    }
    window.location.href = path;
}
function changeFondsListingList() {
    var path = "?listcustomer=" + encodeURIComponent($F('listcustomer'))  + "&category=" + encodeURIComponent($F('category'));
    var style = window.location.href.match(/style=(\w*)/);
    if(style) {
        path += "&style=" + encodeURIComponent(style[1]);
    }
    var periodProvided = window.location.href.match(/period=(\d)/);
    if(periodProvided) {
        path += "&period=" + periodProvided[1];
    }
    window.location.href = path;
}

function loadHeatMapChart(cellId, listing, period) {
    new Ajax.Updater(
        { success: $(cellId) },
                "chart.html",
        {
            method: 'get',
            parameters:{
                listings: listing,
                color: "608C3E",
                mtype_ls: "1",
                vcharth: "0",
                width: "240",
                height: "125",
                period: period
            }
        }
    );
}

function newList() {
    new Ajax.Updater('listform',
            'createNewList.htm',
            {
                method: 'get',
                parameters: {
                    replaceOnly: true
                }
            }
    );
}

function newPortfolio() {
    new Ajax.Updater('listform',
            'createNewPortfolio.htm',
            {
                method: 'get',
                parameters: {
                    replaceOnly: true
                }
            }
    );    
}

function showAddListingToList(listing)  {
    new Ajax.Updater('listform',
            'addListingToLists.htm',
            {
                method: 'get',
                parameters: {
                    listing: listing,
                    replaceOnly: true
                }
            }
    );    
}
