﻿ieMenu = function(list) {
	if (document.all && document.getElementById) {
		var navRoot = document.getElementById(list);
		if(navRoot) {
			navRoot.onmouseover = function() {
				ieSelectBug(true);
			}
			navRoot.onmouseout = function() {
				ieSelectBug(false);
			}
		}
	}
}

ieSelectBug = function(active) {
	var selectBugOuterDiv = document.getElementById("selectBugOuterDiv");
	var selectBugInnerDiv = document.getElementById("selectBugInnerDiv");

	if (!selectBugOuterDiv || !selectBugInnerDiv)
		return;

	if (active) {
		selectBugOuterDiv.style.height = selectBugOuterDiv.offsetHeight;
		selectBugOuterDiv.filters["revealTrans"].apply();
		selectBugInnerDiv.style.display = "none";
	}
	else {
		selectBugInnerDiv.style.display = "block";
		selectBugOuterDiv.filters["revealTrans"].play();
	}
}

function PrintPage(page){
	var printWindow = window.open(page).print();
}


function show_object(strObjectId) {
	var objDiv = document.getElementById(strObjectId);
	if (objDiv.style.visibility == "hidden") {
		objDiv.style.visibility = "visible";
	} else {
		objDiv.style.visibility = "hidden";
	}
}

function delay(prmSec) { 
   var eDate = null; 
   var eMsec = 0; 
   var sDate = new Date(); 
   var sMsec = sDate.getTime(); 
  
   do { 
       eDate = new Date(); 
       eMsec = eDate.getTime(); 
   } while ((eMsec-sMsec)<prmSec); 
 }
 
/*
* redirects to the given url with a delay to avoid problems with the thickbox
*/
function RedirectToUrl(url) {
	window.setTimeout("this.location.href = '" + url + "';", 500);
}

var times = "";
var derivativeValues = "";
var csvValues = "";
var count = 0;
var pushChartActive = false;

function writePushChartData(bid, quotetime) {
	flashChart = document.getElementById("FlashChart");
	if (flashChart) {
		try {
			count++;
			times += "<value xid=\"" + count + "\">" +  quotetime+ "</value>";
			derivativeValues += "<value xid=\"" + count + "\">" + bid + "</value>";
			chartData = "<?xml version=\"1.0\" encoding=\"utf-8\"?><chart><series>" +times+ "</series><graphs><graph gid=\"derivative\" title=\"Produkt\">" + derivativeValues + "</graph><graph gid=\"underlying\" title=\"Basiswert\" /></graphs></chart>";
			if(pushChartActive) {
				if(count >= 2) {
					flashChart.setData(chartData);
				}
			}
		} catch(e) {
			alert(e);
		} finally {
		}
	}
}

function setPushChartActive() {
	return;
	setPushChartActiveWithValue(!pushChartActive);
}

function setPushChartActiveWithValue(value) {
	return;
	oldValue = pushChartActive;
	pushChartActive = value;
	flashChart = document.getElementById("FlashChart");
	if (flashChart) {
		if(pushChartActive) {
			flashChart.setParam('indicator.zoomable', false);
			chartData = "<?xml version=\"1.0\" encoding=\"utf-8\"?><chart><series>" +times+ "</series><graphs><graph gid=\"derivative\" title=\"Produkt\">" + derivativeValues + "</graph><graph gid=\"underlying\" title=\"Basiswert\" /></graphs></chart>";
			if(count >= 2) {
				flashChart.setData(chartData);
			}
			element = document.getElementById("PushChartLink");
			if(element) {
				element.firstChild.nodeValue = "Zum Intraday-Chart wechseln";
			}
		} else if (oldValue) {
			flashChart.setParam('indicator.zoomable', true);
			changeChart = true;
			flashChart_graphVisibilityChanged = true;
			flashChart_newPeriodStart = "09:00";
			now = new Date();
			hours = now.getHours()
			minutes = now.getMinutes();
			flashChart_newPeriodEnd = ((hours < 10) ? "0" + hours : hours) + ":" + ((minutes < 10) ? "0" + minutes : minutes)
			ReloadFlashChart();
			element = document.getElementById("PushChartLink");
			if(element) {
				element.firstChild.nodeValue = "Zum Push-Chart wechseln";
			}
			
			_flashChart = flashChart;
			amChartShowAll();
		}
	}
}

var _flashChart = null;
var _x = 0;
function setPushChartAvailable(value) {
	return;
	var element = document.getElementById("PushChartLinkHolder");
	if (element) {
		if(value == "True") {
			element.style.visibility = "visible";
		} else {
			element.style.visibility = "hidden";
		}
	}
}

function amChartShowAll() {
	_x++;
	if(_x < 10) {
		_flashChart.showAll();
		window.setTimeout("amChartShowAll()", 100);
	}
}

var shoppingCardWKN = null;
var shoppingCardISIN = null;
/**
* shows shopping card 
*/
function showShoppingCard(wkn, isin, anchorElement) {
	shoppingCardWKN = wkn;
	shoppingCardISIN = isin;
	$('#ShoppingCard').css("display", "block");
	if(anchorElement) {
	    $('#ShoppingCard').css("position", "absolute");
	    //we have to use fixed positioning to use it right
	    if(anchorElement.className.indexOf('ShoppingCardIconLeaflet') != -1) {
            $('#ShoppingCard').css("position", "fixed");
	    }
		if(anchorElement.offsetParent.className.indexOf('mp-table-icon') != -1){
			$('#ShoppingCard').css("left", $get('table').offsetWidth + "px");
			var top1 = 70  + anchorElement.offsetParent.offsetTop;
			$('#ShoppingCard').css("top", top1+ "px");
		} else {
			position = getPosition(anchorElement);
			$('#ShoppingCard').css("left", position.x + "px");
			$('#ShoppingCard').css("top", position.y - 10 + "px");
		}
	}
	return false;
}

var shoppingCardHide = false;
/**
* hides the shopping card
*/
function hideShoppingCard(event) {
	shoppingCardHide = true;
	window.setTimeout("hideShoppingCardBox()", 500);
}

/**
* function to set a property not to hide the box
*/
function showShoppingCardBox() {
	shoppingCardHide = false;
}

/**
* hides the shopping card box
*/
function hideShoppingCardBox() {
	if(shoppingCardHide) {
		shoppingCardWKN = null;
		shoppingCardISIN = null;
		$('#ShoppingCard').css("display", "none");
	}
}

/**
* Executes the request and opens a new window
*/
function shoppingCardRequest(link, popupsettings) {
	if(shoppingCardWKN || shoppingCardISIN) {
		link = link.replace("##ISIN##", shoppingCardISIN);
		link = link.replace("##WKN##", shoppingCardWKN);
		hideShoppingCardBox();
		if(popupsettings) {
			window.open(link, "TradingPopop", popupsettings);
		} else {
			window.open(link, "TradingPopop", "");
		}
	}
	return false;
}

/**
* retrieves the position of the element
*/
function getPosition(element) {
	var elem=element,tagname="",x=0,y=0;
	while ((elem != null)&&(typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined")) {
		y += elem.offsetTop;
		x += elem.offsetLeft;
		tagname = elem.tagName.toUpperCase(); 
		if (tagname=="BODY") {
			elem=0;
		}
		if (typeof(elem)=="object") {
			if (typeof(elem.offsetParent)=="object") {
				elem=elem.offsetParent;
			}
		}
	}
	position=new Object();
	position.x=x;
	position.y=y;
	return position;
}


function resetPosition() {
	location.hash = "#"+location.href.split('#')[1];
}

function openBuySell(url) {
    window.open(url,'BuySell','resizable=yes,scrollbars=yes,status=yes,location=yes,width=810,height=700');
}

/**
*   adds the given movie in player to the element with given identifier
**/
function showMovie(contentID, flashUrl, imageUrl) {
	var so = new FlashObject("/Flash/mediaplayer.swf", "Videoplayer", "560", "335", "7", "#FFF");
	so.addParam("wmode", "opaque");
	so.addParam("allowfullscreen", "true");
	so.addVariable("width", "560");
	so.addVariable("height", "308");
	so.addVariable("autostart", "false");
	
	if(flashUrl.indexOf("rtmp") != -1) {
	    flashUrl = flashUrl.replace("rtmp://", "");
	    splittedData = flashUrl.split("/");
	    flashUrl = flashUrl.replace(splittedData[0], "");    
	    so.addVariable("streamer", "rtmp://" + splittedData[0]);
	    so.addVariable("file", flashUrl.substring(1));
	} else {
	    so.addVariable("file", flashUrl);
	}
	
	so.addVariable("image", imageUrl);
	/*so.addVariable("config","/Config/mediaplayer.xml");*/
	so.write(contentID);
}




function calculateChangeForQuoteStream (updateInfo) {
    if (updateInfo.getNewValue('hasreference')) {
	    var reference = updateInfo.getNewValue('reference');
		var newValue = parseFloat(updateInfo.getNewValue('bid'));
		if(isNaN(newValue)) {
		    newValue = parseFloat(updateInfo.getOldValue('price'));
		}
		var changepercent = '-';
		var changeabsolute = '-';
		if(reference != 0) {
		    changepercent = ((newValue / reference) - 1) * 100;
			changeabsolute = newValue - reference;
		}
		if(isNaN(changepercent)) {
		    changepercent = '-';
		}
		if(isNaN(changeabsolute)) {
		    changeabsolute = '-';
		}
		
		updateInfo.addField('changepercent', changepercent, true);
		updateInfo.addField('changeabsolute', changeabsolute, true);
	}
}


/**** Lightstreamer Functions ****/
function LightstreamerUnderlyingFormatNumber(num) {
    if(num.toString() == 'NaN') {
        return "-";
    }
    var numberFormat = Sys.CultureInfo.CurrentCulture.numberFormat;
	var currencyGroupSize = numberFormat.CurrencyGroupSizes[0];
	var dec = numberFormat.CurrencyDecimalDigits;

	if(((Math.round((num*10000)%10)) != 0) && (Math.round((num*10000)%10)) != 10) {
	    dec = 4;
	} else if(((Math.round((num*1000)%10)) != 0) && (Math.round((num*1000)%10)) != 10) {
	    dec = 3;
	} else {
	    dec = 2;
	}
	var decpoint = numberFormat.CurrencyDecimalSeparator;
	var sep = numberFormat.CurrencyGroupSeparator;

	if (num.toFixed) {
	    num = num.toFixed(dec).toString();
	} else {
		num = num.toString();
    }
	splitArray = num.split('.');
	left = splitArray[0];
	right = splitArray[1];
	tmp = '';

	if (typeof(left) != 'undefined') {
	    for (i = left.length; i >= 1; i--) {
		    if ((i < left.length) && (((left.length-i) % currencyGroupSize) == 0)) {
			    tmp = sep + tmp;
			}
			tmp = left.charAt(i-1) + tmp;
		}
		if (typeof(right) != 'undefined' && right.length > 0) {
		    tmp += decpoint + right;
		}
	}
	if(dec > 2) {
	    if(typeof(tmp) != 'undefined') {
    	    for (i = tmp.length; i >= 1; i--) {
	            if(tmp.charAt(i-1) == '0') {
	                tmp = tmp.slice(0, tmp.length);
	                dec--;
	                if(dec == 2) {
	                    break;
	                }
	            } else {
	                break;
	            }
    	    }
	    }
	}
	
	return tmp
}
/****** Datepicker *******/

	
function SetDatePickerVisible(p_minDate, p_maxDate){
var dates = $('#from, #to').datepicker({
			changeMonth: true,
			changeYear:true,
			minDate: new Date(p_minDate),
			maxDate: p_maxDate,
			onSelect: function(selectedDate) {
									 var option = this.id == "from" ? "minDate" : "maxDate";
									 var instance = $(this).data("datepicker");
									 var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
									 dates.not(this).datepicker("option", option, date);
									 
										 if(this.id == "from")
										 {
											$('#DivArrow').css("display", "block");
										 }
										 else
										 {
										  $('#DivArrow').css("display", "none");
											$('#DivDatepicker').css("display", "none");
											var fromdate = $('#from').datepicker("getDate");
											var todate = $('#to').datepicker("getDate");
											var strFromDate =  fromdate.getDate() + '.' + fixMonth(fromdate.getMonth())+ '.' + fixYear(fromdate.getYear());
											var strToDate =  todate.getDate() + '.' + fixMonth(todate.getMonth())+ '.' + fixYear(todate.getYear());
											SearchSliderPostback('MaturityDate',strFromDate, strToDate, 1);
										 }
									 
									 }
		});
		
		position = getPosition(document.getElementById('DatePickerImg'));
		$('#DivDatepicker').css("left", position.x + "px");
		$('#DivDatepicker').css("top", position.y + "px"); 
		
		$('#from').datepicker( "show" );
		$('#to').datepicker( "show" );

		$('#DivDatepicker').css("display", "block");
}

function fixYear(y) {
  return (y < 1999 ? y+1900 : y);
}
function fixMonth(m) {
	var monatHelper = m+1;
	return monatHelper < 9 ? '0'+ monatHelper : monatHelper; 
}

function CloseDatePicker()
{
	$('#DivDatepicker').css("display", "none");
	$('#DivArrow').css("display", "none");
}


/****** Watermark *******/
function activateWatermark(identifier, text) {
    if($('#' + identifier).length > 0) {
        $('#' + identifier).focus(function() {
            if(this.value == text) {
                this.value = '';
                $(this).removeClass('watermark');
            }
        });
        $('#' + identifier).blur(function() {
            if(this.value == '') {
                this.value = text;
                $(this).addClass('watermark');
            }
        });
    }
}