$
/**
 * prefix for all ajax-requests (feed-direct)
 */
var prefixDirect = "";

/**
 * overwrite the prefix for local tests
 * default is "/feed-direct"
 *
 * @param prefixToSet prefix
 */
function setPrefix(prefixToSet) {
    prefixDirect = prefixToSet;
}

/**
 * the actual sessionid.
 * add this parameter to all ajax-requests.
 * use the function getAjaxUrl(url).
 */
var sessionId;

/**
 * set the actual session-id.
 * to set the actual session-id include ajaxsettings.jsp in your page
 *
 * @param sessionIdToSet session-id
 */
function setSessionId(sessionIdToSet) {
    sessionId = sessionIdToSet;
}

///**
// * add the actual session-id as parameter to the url.
// *
// * @param url ajax-url
// */
//function getAjaxUrl(url, params) {
//    var ajaxUrl = prefixDirect + url;
//    if (ajaxUrl.indexOf("akb") > 0 && sessionId != null) {
//        ajaxUrl += ";jsessionid=" + sessionId;
//    }
//    if (params)
//        ajaxUrl += "?" + params;
//    return ajaxUrl;
//}

function setCookie(name,value,path) {
    var ablauf = new Date();
    var in360Tagen = ablauf.getTime() + (360 * 24 * 60 * 60 * 1000);
    ablauf.setTime(in360Tagen);
    var cookieString = name + "=" + value + "; expires=" + ablauf.toGMTString();
    if(path) {
        cookieString += ";path=" + path;
    }else {
        cookieString += ";path=/";
    }
    document.cookie = cookieString;
}

/*------ news functions --------*/
function getNews(box){
    //    var group = $("#changegroup").val();
    var path='?changegroup='+ box;
    window.location.href=path;
}


//* SingleQuote-Function*/
function singleQuoteGetChart(period) {
    var typeFrom = "TYPE=0";
    var typeTO = "TYPE=1";
    if(period=="TODAY") {
        typeFrom = "TYPE=1";
        typeTO = "TYPE=0";
    }
    $('#chart').attr("src",$('#chart').attr("src").replace(typeFrom,typeTO).replace(/PERIOD=(TODAY|MONTH|YEAR)/,"PERIOD="+period))
    $('#TODAY').removeClass("selected");
    $('#MONTH').removeClass("selected");
    $('#YEAR').removeClass("selected");
    $('#'+period).addClass("selected");
}


jQuery.validator.addMethod("dateDE", function(value, element) {
    return this.optional(element) || /^\d\d?[\.]\d\d?[\.]\d\d\d?\d?$/.test(value);
}, "Please enter a valid date."
        );

/* portfolio */
function changeMyList(element,actionPath,listtype) {
    var path = "?list=" +  $(element).val();
    window.location.href = path;
}

/* kurslisten.jsp*/
function fillSelectBox(box, response) {
    var options = "";
    var itemList = $(response).find("item").each (function(index,item) {
        options += "<option value='" + $(item).children("value").text() + "'>" + $(item).children("name").text() + "<\/option>";
    });
    $(box).html(options);

//    if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) {
//        $("#market").setStyle({width:'14em'});
//    }
    //todo
    $(box).effect("highlight", {color:'#FFFFCC'}, 1500);
}

function changeInstrumentTypeBox() {
    //showProgressbar();
    $.ajax({
        url:"core/listingList/jspf/dropdownlistingList.jspf",
        data: {list:$('#instrType').val(),owner:'customer'},
        dataType:'xml',
        success: function(response) {
            fillSelectBox("#market", response);
            changeMarketBox();
        }
    });
}

function changeMarketBox() {
    $.ajax({
        url:"core/listingList/jspf/dropdownlistingList.jspf",
        data: {list:$('#market').val().split(";")[0],owner:'customer',outputCustomer:'true'},
        dataType:'xml',
        success: function(response) {

            fillSelectBox('#listcustomer', response);
            changeListingList();
        }
    });

}

function changeListingList() {
    var _instrType = $('#instrType').val();
    var listcustomer= $('#listcustomer').val();
    if(listcustomer!=null){
        listcustomer = listcustomer.replace("&","%26");
    }
    
    var path = "kurslisten.jsp?instrType=" + $('#instrType').val() + "&market=" + $('#market').val();
    if (_instrType == "301A5285E30A32A528825DDB2FF8822A") {    //Typ List = Optionen
        var typeInVal_listOptionen = $('#typeInVal_listOptionen').val();
        if(typeInVal_listOptionen == undefined || typeInVal_listOptionen == ""){
           typeInVal_listOptionen = "*"; 
        }
        var listOptionen = $('#listOptionen').val();
         if(listOptionen == undefined || listOptionen == ""){
           listOptionen = "998089";
        }
        path += "&listOptionen=" + listOptionen + "&typeInVal_listOptionen=" + typeInVal_listOptionen;
    } else {
        if(($('#listcustomer')).size()>0)
            path +="&listcustomer=" + listcustomer;
    }

    var styleProvided = window.location.href.match(/view=(\w*)/);
    if (styleProvided) {
        path += "&view=" + styleProvided[1];
    }
    var typeProvided = window.location.href.match(/typelist=(\w*)/);
    if (typeProvided) {
        path += "&typelist=" + typeProvided[1];
    }

    var periodProvided = window.location.href.match(/period=(\d)/);
    if(periodProvided) {
        path += "&period=" + periodProvided[1];
    }
    window.location.href = path;
}
function login(contextPath,ssl) {
    var position = window.location.href.indexOf(contextPath) + contextPath.length;
    var path = window.location.href.substring(0, position);
    if(ssl) path = path.replace("http","https");
    $.ajax({url:path + '/usercontent/user/loginAjax.jsp',
        type:'post',
        data:{user:$('#loginUser').val(),password:$('#loginPassword').val()},
        complete:function(data){
            if(data.responseText.indexOf("true")>-1) {
                if(location.href.match(/^.*(register|logout|registration|resetPassword|confirm).*$/)) {
                    window.location.href = path + "/index.jsp";
                } else {
                    if(ssl) {
                        window.location.href = window.location.href.replace("http","https");
                    }else {
                        location.reload();
                    }
                }
            }else {
                $('#loginFailed').show();
            }
        }
    });
}

function togglePortlet(element, img,imgMin, path) {
  if($('#'+element).is(':visible')) {
      $('#'+element).hide();
      $('#'+img).attr("src","../stat/images/maximize.png");
      if(path) setCookie("AjaxJspTag.Portlet." + element,2, path);
  } else {
      $('#'+element).show();
      $('#'+img).attr("src",imgMin);
      if(path) setCookie("AjaxJspTag.Portlet." + element,1, path);
  }
}

