/******************************/
/* Last updated 12.02.2010 */
/******************************/
/** Allgemeine Funktionen */

var winID = 0;
var popUp = new Array();

function doAdvancedSubmit(fieldId) {
		var button = document.getElementById(fieldId);
		if (button != null) {
			button.click();
		}
	}

// Radio-Button deselektieren
function resetRadio(form, name, id) {
	document.getElementsByName(form + ":" + name)[id].checked=false;
}

function fensterAuf(inhalt, breite, hoehe, winname) {
  var xOff = 10;
  var yOff = 10;
  if (parseInt(navigator.appVersion)>=4) {
  	//Koordinaten fuer zentriertes PopUp Fenster festlegen
    xOff = (screen.width-breite)/2;
    yOff = (screen.height-(hoehe))/2;
    yOff -= 20;//Hoehenjustage, Wert anpassen, wenn Fenster Toolbar/Adresszeile/Statuszeile etc. hat
  }
  popUp[winID] = window.open(inhalt, winname, 'toolbar=no,status=no,location=no,directories=no,resizable=no,scrollbars=no,width='+breite+',height='+hoehe+',left='+xOff+',top='+yOff);
  winID++;
}

function loadSelectLink(formID, selectID, contrQuickname) {
    if ((loadSelectLink.arguments.length > 3) && (loadSelectLink.arguments[3] == true)) {
      formular = (document.layers) ? document.container0.document : document;
    } else {
      formular = document;
    }
    var basisLink = formular.forms[formID][selectID].options[formular.forms[formID][selectID].selectedIndex].value;
    if (basisLink.length>1){
      contrQuickname = escape(contrQuickname);
      // Die nächsten 2 Zeilen löschen wenn statt dem rlp:a das rlp:url verwendet wird !!
      var cutLink = basisLink.replace(/<a href="/, "");
      basisLink = cutLink.replace(/"><\/a>/, "");
      cutLink = basisLink.replace(/" target="_top/, "");
      basisLink = cutLink;
      var contrSelectEintrag = formular.forms[formID][selectID].options[formular.forms[formID][selectID].selectedIndex].text;
      if (basisLink.indexOf("extern.jsp")!=-1){
        contrSelectEintrag = doExternEscape(contrSelectEintrag);
      }
      else{
        contrSelectEintrag = escape(contrSelectEintrag);
      }
      contrSelectEintrag = contrSelectEintrag.replace(/\//, "_");
      contrSelectEintrag = contrSelectEintrag.replace(/&/, "_");
      var nowLink = basisLink;
      if (contrQuickname != '' && contrQuickname != 'seitenname_boxname') {
    	  nowLink = nowLink + "&tr_quickfinder=" + contrQuickname + "&tr_value=" + contrSelectEintrag;
      }
      document.location.href = nowLink;    }
}

function doExternEscape(linkParam) {
  linkParam = linkParam.replace(/ß/g, "ss");
  linkParam = linkParam.replace(/ä/g, "ae");
  linkParam = linkParam.replace(/Ä/g, "Ae");
  linkParam = linkParam.replace(/ö/g, "oe");
  linkParam = linkParam.replace(/Ö/g, "Oe");
  linkParam = linkParam.replace(/ü/g, "ue");
  linkParam = linkParam.replace(/Ü/g, "Ue");
  linkParam = linkParam.replace(/ /g, "_");
  var finalParam = linkParam
  return finalParam
}

function updateView(optionalId, compareValue, radioName) {
	var selectedValue = getRadioValue(radioName);
	showElement(optionalId, selectedValue == compareValue );
}

function getRadioValue(elementName) {
	var radiobuttons = document.getElementsByTagName('input');
	for (i = 0; i < radiobuttons.length; i++) {
		if (radiobuttons[i].type == 'radio' && radiobuttons[i].name == elementName ) {
			if (radiobuttons[i].checked)
				return radiobuttons[i].value;
		}
	}
	return null;
}

function showElement(id, visible) {
	var element = getElement(id);
	if (visible)
		show(element);
	else
		hide(element);
}

function getElement(id) {
	return document.getElementById(id);
}

// Element anzeigen
function show(obj) {
	if (obj) {
		obj.style.display = "block";
	}
}

// Element verstecken
function hide(obj) {
	if (obj) {
		obj.style.display = "none";
	}
}

// Frame neu laden
function refresh(id){
	activeFrame = sFrame + id;
	if(getElement(activeFrame)){
		parent.frames[activeFrame].location.reload();
	}
}
//Image aktualisieren
function updateOptionView( formId, selectId, chartId ) {

	var source = document.forms[formId][selectId].options[document.forms[formId][selectId].selectedIndex].value;
	var chart = getElement(chartId);
	chart.src = source;
}
/**************************************************/
/* functions add-info */
var sIconTitleMaximize = "maximieren";
var sIconTitleMinimize = "minimieren";
var sAddInfoPrefix = "add-info-";
var sFrame = "frame-";

var activeAddInfoElement;
var activeAddInfoNavigation;

function showAddInfo(sId)
{
	var sAddInfoId = sAddInfoPrefix + sId;

	if (activeAddInfoElement == getElement(sAddInfoId)){
		hide(activeAddInfoElement);
		resetAddInfoNavigation(activeAddInfoNavigation);
		activeAddInfoElement = null;
		activeAddInfoNavigation = null;
	} else {
		hide(activeAddInfoElement);
		resetAddInfoNavigation(activeAddInfoNavigation);
		activeAddInfoElement = getElement(sAddInfoId);
		getAddInfoNavigation(sId);
		activateAddInfoNavigation(activeAddInfoNavigation);
		refresh(sId);
		show(activeAddInfoElement);
	}
}

function getAddInfoNavigation(sId)
{
	var elm = getParentElement(getElement(sAddInfoPrefix+sId));
	var elmHeadline = elm.getElementsByTagName('div')[0];
	var elmNaviDiv = elmHeadline.getElementsByTagName('div')[1];
	var elmNaviA = elmNaviDiv.getElementsByTagName('a')[0];
	activeAddInfoNavigation = elmNaviA;
}

function activateAddInfoNavigation(obj)
{
	if (obj) {
		obj.className = "open";
		obj.title = sIconTitleMinimize;
	}
}

function resetAddInfoNavigation(obj)
{
	if (obj) {
		obj.className = "";
		obj.title = sIconTitleMaximize;
	}
}

function getParentElement(obj)
{
	if (obj.parentElement) {
		return obj.parentElement;
	} else if (obj.parentNode) {
		return obj.parentNode;
	}
}

/**************************************************/
/* ShortContact */



var sImagePath = "/img/pics/";
var sShortContactEmailId = "short-contact-email";
var sShortContactPhoneId = "short-contact-phone";
var sShortContactBranchId = "short-contact-branch";
var sTabNavEmailId = "tab-nav-email";
var sTabNavPhoneId = "tab-nav-phone";
var sTabNavBranchId = "tab-nav-branch";

function contactShowTab(sId) {

	if (getElement(sShortContactPhoneId)) {
		hide(getElement(sShortContactPhoneId));
		getElement(sTabNavPhoneId).src = sImagePath+sTabNavPhoneId+".gif";
	}

	if (getElement(sShortContactBranchId)) {
		hide(getElement(sShortContactBranchId));
		getElement(sTabNavBranchId).src = sImagePath+sTabNavBranchId+".gif";
	}

	if (getElement(sShortContactEmailId)) {
		hide(getElement(sShortContactEmailId));
		getElement(sTabNavEmailId).src = sImagePath+sTabNavEmailId+".gif";
	}

	getElement("tab-nav-"+sId).src = sImagePath+"tab-nav-"+sId+"-active.gif";
	contactActiveDiv = getElement("short-contact-"+sId);
	show(contactActiveDiv);
}

function setDefault(that, default_value) {
	if (that.value == default_value) {
		if(that.className.indexOf(' ') != -1) {
			that.className = that.className.replace(" label", "");
		} else {
			that.className = that.className.replace("label", "");
		}
		that.value = '';
	}
}

function resetDefault(that, default_value) {
	if (that.value == '') {
		if(that.className == '') {
			that.className = "label";
		} else {
			that.className += " label";
		}
		that.value = default_value;
	}
}

/**************************************************/
/*START: Fix IE 6 Text Selection Bug */
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat") {
	document.onreadystatechange = function fixIE6AbsPos()
	{
		if( !document.body ) {
			return;
		}
		if( document.readyState == "complete" ) {
			document.body.style.height = document.documentElement.scrollHeight + 'px';
		}
	}
}
/*END: Fix IE 6 Text Selection Bug */
/**************************************************/
/**************************************************/
/*START: Marktuebersichts-portlet */

var sShortDaxId = "short-dax";
var sShortTecdaxId = "short-tecdax";
var sShortDowId = "short-dow";
var sTabNavDaxId = "tab-nav-dax";
var sTabNavTecdaxId = "tab-nav-tecdax";
var sTabNavDowId = "tab-nav-dow";

function ShortMG(sId) {

	if (getElement(sShortDaxId)) {
		hide(getElement(sShortDaxId));
		getElement(sTabNavDaxId).src = sImagePath+sTabNavDaxId+".gif";
	}

	if (getElement(sShortTecdaxId)) {
		hide(getElement(sShortTecdaxId));
		getElement(sTabNavTecdaxId).src = sImagePath+sTabNavTecdaxId+".gif";
	}

	if (getElement(sShortDowId)) {
		hide(getElement(sShortDowId));
		getElement(sTabNavDowId).src = sImagePath+sTabNavDowId+".gif";
	}

	getElement("tab-nav-"+sId).src = sImagePath+"tab-nav-"+sId+"-active.gif";
	contactActiveDiv = getElement("short-"+sId);
	show(contactActiveDiv);
}

/*START: Marktuebersichts-portlet */
/**************************************************/
/* Setzt den Eingabefokus für das angegebene Eingabefeld im angegebenen Formular */
function setFormFocus( formId, fieldId ) {
	if ( formId ) {
		var targetForm = document.forms[ formId ];
		if ( targetForm != null ) {
			var targetField;
			if ( fieldId ) {
				targetField = targetForm.elements[ fieldId ];
			}
			if ( targetField == null || !targetField.focus ) {
				for ( var elementIndex = 0; elementIndex < targetForm.elements.length; elementIndex++ ) {
					var current = targetForm.elements[elementIndex];
					if ( current.focus
								&& false == current.disabled
								&& 'none' != current.style.display ) {
						targetField = current;
						break;
					}
				}
			}
			if ( targetField != null && targetField.focus ) {
				try {
					targetField.focus();
				}
				catch ( ex ) {
				}
			}
		}
	}
}

function displayField(displayFieldId, toHideFieldId) {
    if(displayFieldId != null) {
		document.getElementById(displayFieldId).style.display='block';
	}
	if(toHideFieldId != null) {
		document.getElementById(toHideFieldId).style.display='none';
	}
}
/* Korrigiert tracking Parameter - suchen (alt) und ersetzen (neu) */
/* wird bei opt_e_imagemap_banner_overview verwendet */
function trFix(alt,neu)
{
  var browserVersion = navigator.appVersion;
  var isIE5 = (browserVersion.indexOf("MSIE 5")>-1 && document.getElementById) ? true : false;
  var isIE6 = (browserVersion.indexOf("MSIE 6")>-1 && document.getElementById) ? true : false;
  var isIE7 = (browserVersion.indexOf("MSIE 7")>-1 && document.getElementById) ? true : false;
    
  alt = "tr=" + alt;
  neu = "tr=" + neu;
  var att;
  var li = document.getElementsByTagName("a");
  var ii = document.getElementsByTagName("img");
  var reg = new RegExp( alt, "g");
  for (var i=0, llen=li.length; i<llen; i++)
  {
    if (li[i].href.indexOf(alt) != -1 )
      li[i].href = li[i].href.replace(reg, neu);
  }
  for (var i=0, llen = ii.length; i<llen; i++)
  {
   att = ii[i].getAttributeNode('onmouseover');
   if (att != null && att.nodeValue)
   {
    att = att.nodeValue.replace(reg, neu);
    ii[i].setAttribute('onmouseover', att);
    if (isIE5 || isIE6 || isIE7) eval("ii[i].parentNode.onmouseover = function () {" + att + "};");
   }
  }
}

/* Ermittelt die Tage neu wenn Monatauswahl geändert wurde (z.B. Februar=28 Tg) */
/* wird verwendet in Combobox für Zeitraum-Auswahl im Banking: Umsatzanzeige, Lastschriftanzeige und -rückgabe */
function OnMonatChanged(monatlist, taglist)
{
	var ausgewaehlterTag = taglist.selectedIndex;

	var text = monatlist[monatlist.selectedIndex].text
	var bschaltJahr = false;
	var laenge = text.length;
	var sjahr = text.substring(laenge - 4, laenge);
	var jahr = parseInt(sjahr);
	//Schaltjahr?
	var rest1 = jahr % 4;
	if (rest1 == 0)
	{
		bschaltJahr = true;
		var rest2 = jahr % 100
		if (rest2 == 0)
		{
			bschaltJahr = false;
			var rest3 = jahr % 400;
			if (rest3 == 0)
				bschaltJahr = true;
		}
	}
	var smonatsName = text.substring(0, laenge - 5);
	var imonatsTage = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	switch (smonatsName)
	{
		case "Januar":	tage = imonatsTage[0];
						break;
		case "Februar":	tage = imonatsTage[1];
						if (bschaltJahr) tage++;
						break;
		case "März":	tage = imonatsTage[2];
						break;
		case "April":	tage = imonatsTage[3];
						break;
		case "Mai":	tage = imonatsTage[4];
						break;
		case "Juni":	tage = imonatsTage[5];
						break;
		case "Juli":	tage = imonatsTage[6];
						break;
		case "August":	tage = imonatsTage[7];
						break;
		case "September":	tage = imonatsTage[8];
						break;
		case "Oktober":	tage = imonatsTage[9];
						break;
		case "November":	tage = imonatsTage[10];
						break;
		case "Dezember":	tage = imonatsTage[11];
						break;
	}

	var oldLength = taglist.options.length;

	//Neue Elemente der Tages-Auswahlliste anfügen
	//oder Elemente am Ende entfernen
	if (oldLength < tage)
	{
		for (var i = oldLength; i < tage; i++)
		{
			taglist.options[i]  = new Option(i + 1, i + 1);
		}
	}
	else
	if (oldLength > tage)
	{
			taglist.options.length = tage;
	}
	//(Möglichst) Vorherigen Wert selectieren
	var last = taglist.options.length;
	if ( parseInt(ausgewaehlterTag) <= parseInt(last)-1 )
		taglist.options[parseInt(ausgewaehlterTag)].selected = true;
	else
		taglist.options[parseInt(last)-1].selected = true;
}

/* Korrigiert bei Bedarf Hoehe von iFrames */
function resizeIframe(myiframe)
{
	if (myiframe.contentDocument || myiframe.contentWindow.document)
	{
		var iframe = (myiframe.contentDocument) ? myiframe.contentDocument : myiframe.contentWindow.document;
		hoeheform = iframe.forms[0].offsetHeight + 30;
		if (hoeheform > myiframe.height) myiframe.style.height = hoeheform + "px";
	}
}

/** Logout-Timer */
var counter = 600-1;

var to_win = "";
var timeout = "10:00";
var timeoutmessage = "Ihre Verbindung wurde automatisch beendet.";

function startTimer(){
	to_win = window.setInterval(timeoutCounter, 1000);
}

function timeoutCounter(){
	var empty = "";
	
	if(counter >= 60){
		var min = counter / 60;
		var sek = counter % 60;
		var mintext = Math.floor(min);
		if(sek < 10) empty = "0";
		timeout = "0" + mintext + ":" + empty + sek;
	}
	else{
		if(counter < 10) empty = "0";
		timeout = "00:" + empty + counter;
	}

	counter--;

	if(counter < 0){
		clearInterval(to_win);
		var message = document.getElementById("message");
		if (message != null) message.innerHTML = timeoutmessage;
	}
	
	var sessiontime = document.getElementById("sessiontime");
	if (sessiontime != null) sessiontime.innerHTML = timeout;
}


/* JS Namespace HVB */
var hvb = window.hvb || {};

/* Check Frames */
/* Pfüft, ob die Seite in einem Frame geladen wird. */
hvb.checkFrames = function () {
  var ph, tt;
  if (window != parent) {
    try { ph = parent.location.hostname; tt = top.document.title; } catch(e) { ph = ""; tt = "" }
    if (ph === "" || (ph.search(/\.hypovereinsbank\.de$/) === -1 && tt.search(/^RedDot CMS/) === -1)) {
      alert("Unzul\u00e4ssiger Frame-Aufruf!\n\nDie Seiten der HypoVereinsbank d\u00fcrfen aus Gr\u00fcnden der Sicherheit nur unter "+location.hostname+" erscheinen. Sie werden nun auf "+location.hostname+" umgeleitet.");
      top.location = self.location;
    }
  }
}
hvb.checkFrames();

/* Beginn Cookie */
hvb.cookie = {
	set : function (name, value, expires, path, domain, secure) {
	  var curCookie = name + "=" + escape(value) +
		  ((expires) ? "; expires=" + expires.toGMTString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "") +
		  ((secure) ? "; secure" : "");
	  document.cookie = curCookie;
	},

	get : function (name) {
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);
	  if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	  }
	  else {
		begin += 2;
	  }
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1) {
		end = dc.length;
	  }
		return unescape(dc.substring(begin + prefix.length, end));
	},

	remove : function (name, path, domain) {
	  if (hvb.cookie.get(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	  }
	}
}
/* Ende Cookie */ 

/* Beginn Schriftgroessen */
hvb.fontsize = {
	init : function () {
		var fontsize = hvb.cookie.get("fontsize");
		if (fontsize) document.documentElement.className = fontsize;
	},
	change : function () {
		var fontsize = "";
		switch (document.documentElement.className) {
			case "fontsize1":
				fontsize = "fontsize2";
				break;
			case "fontsize2":
				fontsize = "";
				break;
			default :
				fontsize = "fontsize1";
				break;
		}
		hvb.cookie.set("fontsize",fontsize);
		document.documentElement.className = fontsize;
	}
}
/* Setze Fontsize direkt beim Laden */
hvb.fontsize.init();
/* Ende Schriftgroessen */


/* Homepage Reiter Cookie  */
/* In dem Cookie "reiter" wird der Fachbereich für die Besucher Startseite gespeichert. */
/* Mögliche Werte: pk|gk|fk|wem */
hvb.extendTabContentLinks = function(reiter) {
	var tc, expires, links;
	tc = document.getElementById("tab-content");
	if (tc) {
		expires = new Date();
		expires.setTime(expires.getTime() + 1000 * 60 * 60 * 24 * 30); // Cookie 30 Tage gültig
		links = tc.getElementsByTagName("a");
		for (var i=0; i<links.length; i++) {
			if (links[i].href.indexOf("kurse.hypovereinsbank.de") === -1) {
				addEvent( links[i], "click", function(){
					hvb.cookie.set("reiter", reiter, expires);
				});
			}
		}
	}
}

/* Start Omniture SpecialLinkTracking */
function addEvent( obj, type, fn )
{
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
/* Ende Omniture SpecialLinkTracking */
