﻿$(document).ready(function() {
	OverrideToolsMenu();
	$("#searchField").hint();
	initTicker();
	
})

function OverrideToolsMenu() {
	$("#mainNav ul.last3level").each(function() {
		$(this).css("margin-left", "-" + ($(this).width() + 2) + "px");
	});
}

function redirectToSearch() {
    if (jQuery('#searchField').val() != 'ISIN/WKN/Artikelsuche' && jQuery('#searchField').val() != '' && jQuery('#searchField').val().length > 1)
        window.location = applicationPath + '/d/search.html?searchText=' + encodeURIComponent(jQuery('#searchField').val().replace(new RegExp("\\+", "g"), "%2B")) + '&searchFor=all';
}
function searchKeyPress(e) {
    if(e.which == 13) {
        redirectToSearch();
    }
}

var tickerFirstLineUpdated = false;
var tickerFirstSecondUpdated = false;

function TickerBoxNavigate(url) {
    window.location = url;
}
function getFirstLine(ajaxData) {
    if(ajaxData != null && jQuery.trim(ajaxData) != '' && ajaxData.indexOf("<a") > -1) {
        jQuery("#firstLinePlaceHolder").html(ajaxData);
        tickerFirstLineUpdated = true;
        if(tickerFirstSecondUpdated)
            makeTickerMouseSensitive();
    }
    
    if(parseInt(jQuery("#tickerRefreshFrequency").val()) != 0 && parseInt(jQuery("#tickerRefreshFrequency").val()) != 'NaN')
        t = setTimeout("tickerFirstLineAutoRefresh(false)", 60000);  //checking for ne data each minute                    
    
}
function getSecondLine(ajaxData) {                
    
    if(ajaxData != null && jQuery.trim(ajaxData) != '' && ajaxData.indexOf("<a") > -1) {
        jQuery("#secondLinePlaceHolder").html(ajaxData);
        tickerFirstSecondUpdated = true;
        if(tickerFirstLineUpdated)
            makeTickerMouseSensitive();
    }
    
    if(parseInt(jQuery("#tickerRefreshFrequency").val()) != 0 && parseInt(jQuery("#tickerRefreshFrequency").val()) != 'NaN')
        t = setTimeout("tickerSecondLineAutoRefresh(false)", 60000);  //checking for ne data each minute    
}
function makeTickerMouseSensitive() {
    if (!jQuery.browser.opera) {
         jQuery('div.runningLine marquee').marquee('pointer').mouseover(function() {
             jQuery(this).trigger('stop');
         }).mouseout(function() {
             jQuery(this).trigger('start');
         });
     }
}
                
//renewing for second line
function tickerFirstLineAutoRefresh(init) {
    if(!init) {
        var url = applicationPath + '/ajaxservice/ajaxDataForTicker.html?line=first';
        g_callServerWithCallBackFunction(url, getFirstLine);                    
    }
    
}
        
//renewing for second line
function tickerSecondLineAutoRefresh(init) {
    if(!init) {
        var url = applicationPath + '/ajaxservice/ajaxDataForTicker.html?line=second';
        g_callServerWithCallBackFunction(url, getSecondLine);
    }    
}
function initTicker() {
    if(parseInt(jQuery("#tickerRefreshFrequency").val()) != 'NaN')
        makeTickerMouseSensitive(); 
}

sfHover = function() {
    var sfEls = document.getElementById("mainNav").getElementsByTagName("li");
    
    //debugger;
    for (var i = 0; i < sfEls.length; i++) {
        var frms = sfEls[i].getElementsByTagName("iframe");
        if(frms != null && frms.length > 0) {
            for (var j = 0; j < frms.length; j++) {
                var withoutPadding = frms[j].parentNode.parentNode.clientHeight;
                if(frms[j].parentNode.parentNode.childNodes != null && frms[j].parentNode.parentNode.childNodes.length > 0)
                    withoutPadding = withoutPadding * frms[j].parentNode.parentNode.childNodes.length;
                withoutPadding += 1;
                frms[j].style.cssText = 'height:' + withoutPadding + 'px;';
            }                    
        }
        
        sfEls[i].onmouseover = function() {            
                this.className += " sfhover";
        }
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");            
        }               
    }
}
    
function fixMenuForIE() {    
    if (window.attachEvent && $.browser.msie) window.attachEvent("onload", sfHover);
}
function redrawSelectsForSafari() {
    if (jQuery.browser.safari) {
        var selects = document.getElementsByTagName('select');
        for (var i = 0; i < selects.length; i++) {
            if (selects[i].parentElement != null)
                selects[i].parentElement.innerHTML = selects[i].parentElement.innerHTML;
        }
    }
}
function addExternalAppToBrowsingHistory(name, url) {
    window.location = applicationPath + '/d/ExternalAppWraper.html?name=' + name + '&url=' + url;
}