var	navTimer;
var debugging=false;
if(window.location.search.indexOf("jsdebug")==1){
	debugging=true;
}

function showPortalDebug(){
	$('.portletDebug').animate({opacity:'show'});
}
function spd(){
	showPortalDebug();
}
if( typeof console !="object" || typeof console.debug !="function" || typeof console.error !="function" || typeof console.warn !="function" || typeof console.log!="function" || typeof console.info!="function"){
	var console={info:function(){},warn:function(){},log:function(){},debug:function(){},error:function(){}};
}
if(!debugging){
	console.info=function(){};
	console.warn=function(){};
	console.debug=function(){};
	console.error=function(){};
	console.log=function(){};
}
if(debugging)showPortalDebug();

//aus der alten Parameters-Datei 
//(wird wg. Netscape-Probs nicht mehr includiert)
var scriptsPath = '/scripts/';
var bUmfrageExist = false;
var sNflRand = '';
var sImpressum = true;
sNflRand = String(Math.random());
sNflRand = sNflRand.substr(2, 12);
saveUsersettings("editcontent", "FontSize", 75);

// Global variables
var fertig = false
var nn4 = false;	// Netscape Navigator or Communicator
var ie4 = false;
var ie5 = false;
var ie6 = false;
var ie = false;		//IE 5 und IE6
var ns6 = false;    	// Netscape 6
var ns7 = false;   	 // Netscape 7
var moz = false;		// Mozilla Engine
var dom1 = false;	// fully supports DOM1
var dom2 = false;	// fully supports (important bits of) DOM2
var op = false;  		//all opera
var op7 = false;  	//opera 7
var mac = false;		//mac
var safari = false;	//mac Safari
var ff = false;		//Firefox

var old = false;		// very old browser

var browserWarn = false;
var strAgent = window.navigator.userAgent;

function browser_detect()
{
	op = (strAgent.indexOf("Opera") > -1);
	op7 = (strAgent.indexOf("Opera/7") > -1) || (strAgent.indexOf("Opera 7") > -1);	

    // do it the official W3C way
    if ( window.document.implementation != null)
    {
         dom1 = window.document.implementation.hasFeature("HTML","1.0");
         dom2 = window.document.implementation.hasFeature("HTML","2.0") &&
         	window.document.implementation.hasFeature("Events","2.0") &&
         	window.document.implementation.hasFeature("Core","2.0") &&
         	window.document.implementation.hasFeature("CSS2","2.0");
    }
    // Mozilla based browsers contain the Gecko rendering engine
    moz = (window.navigator != null )
		? (strAgent.indexOf("ecko") != -1 )
		: false;
    ff = (strAgent.indexOf("Firefox") != -1);
    nn4 = (window.document.layers != null && !moz);
	ns6 = (moz && !dom2);
	ns7 = (moz && (strAgent.indexOf("Netscape/7") > 0));
	
    // IE has incremental support for the Document Object Model
    ie6 = (window.document.all && dom1);
    ie5 = (window.document.all && (strAgent.indexOf('MSIE 5')>0));		//&& window.document.getElementsByTagName()
	ie  = (ie5 || ie6 && !op);
    ie4 = (window.document.all && !ie6 && !ie5); 
	mac = (strAgent.indexOf('Mac')>0);
	safari = (strAgent.indexOf('Safari')>0)
    // something horrible and old
    old = (!ie && !dom1 && !moz);
	
	// set flag browserWarn true if IE<5 or Netscape < 6
	if (ie == true || moz== true){
		browserWarn = false;
	} 
	else {
		browserWarn = true;
	}
	//alert (browserWarn);
}

browser_detect();	
if (ns6 || ns7) document.write('<link rel="stylesheet" type="text/css" href="/styles/net6.css" />');
if (safari) document.write('<link rel="stylesheet" type="text/css" href="/styles/safari.css" />');
if (mac && moz) document.write('<link rel="stylesheet" type="text/css" href="/styles/macmozilla.css" />');

function popup_content(fenstername,fensterlink,breite,hoehe,scrolling,resizablevar){
	if(fenstername=='window') fenstername = 'tmpWind'; 
        eval("var "+fenstername+" = window.open('"+fensterlink+"','"+fenstername+"','scrollbars="+scrolling+",width="+breite+",height="+hoehe+",resizable="+resizablevar+",top="+getCoordinateY(25)+",left="+getCoordinateX(165)+",status=yes')");
        if (!ie4) eval(fenstername+".focus()");
}

function popup_fenster(fenstername,fensterlink,breite,hoehe,scrolling,toolbarvar,locationvar,directoriesvar,statusvar,menubarvar,resizablevar,xpos,ypos){
	if(fenstername=='window') fenstername = 'tmpWind'; 
	eval("var "+fenstername+" = window.open('"+fensterlink+"','"+fenstername+"','width="+breite+",height="+hoehe+",scrollbars="+scrolling+",toolbar="+toolbarvar+",location="+locationvar+",directories="+directoriesvar+",status="+statusvar+",menubar="+menubarvar+",resizable="+resizablevar+",top="+getCoordinateY(ypos)+",left="+getCoordinateX(xpos)+"')");
	if (!ie4) eval(fenstername+".focus()");
}
 
function getCoordinateX(nGivenXpos){
 	var xPos=0;
	var xPlus=0;
	if (ie){xPos = window.screenLeft;}
	else{xPos = window.screenX;}
	if(ie) {xPlus=4;}
	if(moz) {xPlus=4;}
	if(op){xPlus=6;}
	if(ff) {xPlus=4;}
	xPos += (nGivenXpos + xPlus);
	return xPos;
}
 
function getCoordinateY(nGivenYpos,bFix){
 	var yPos=0;
	var yPlus=0;
	if (ie){yPos = window.screenTop;}
	else{yPos = window.screenY;}
	if(ie) {yPlus=2;}
	if(moz) {yPlus=142;}
	if(op){yPlus=64;}
	if(ff) {yPlus=134;}
	yPos += (nGivenYpos + yPlus);
	return yPos;
}
		
function popup_navigator(fenstername,fensterlink,breite,hoehe){
        if (ie){
                if (navigator.platform.indexOf("Win") == -1){
                        var xPos = 482;
                        var yPos = 34;}
                else{
                        var xPos = window.screenLeft +  482;
                        var yPos = window.screenTop - 104;}}
        else{
                var xPos = window.screenX + 482;
                var yPos = window.screenY + 34;}
        //alert("X-Pos:" + xPos + "\nY-Pos:" + yPos)
        eval("var "+fenstername+" = window.open('"+fensterlink+"','"+fenstername+"','width="+breite+",height="+hoehe+",scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,top="+yPos+",left="+xPos+"')");
        eval(fenstername+".focus()");}

function surfto1(formid,selectid,bOpener) {
	var sSelectedIndex = "";
	var sSelectedOption = "";
	var oForm;
	var oSelect;
	if(formid.id!=null)
		oForm = eval(formid);
	else
		oForm = document.getElementById(formid);
	
	if(selectid!=null)
	{
		if(selectid.id!=null)
			oSelect = eval(selectid);
		else
			oSelect = document.getElementById(selectid);
			
		sSelectedIndex = oSelect.selectedIndex;
		sSelectedOption = oSelect.options[sSelectedIndex];
	}
	else
	{
		sSelectedIndex = oForm.firstChild.selectedIndex;
		sSelectedOption = oForm.firstChild.options[sSelectedIndex];
	}
		
	if ((sSelectedOption.value !="0")&&(sSelectedOption.value!="")){
		if(bOpener=='true' && opener){
			opener.location.href = sSelectedOption.value
			self.close();
		}
		else if(
			sSelectedOption.value.indexOf("http://")==0 || 
			sSelectedOption.value.indexOf("https://")==0 || 
			sSelectedOption.value.lastIndexOf(".pdf")==sSelectedOption.value.length-4)
			window.open(sSelectedOption.value);
		else
			window.location.href = sSelectedOption.value;
	}
}

function preload_image(img_name,img_src){
	eval(img_name+' = new Image()');
	eval(img_name+'.src = img_src');
}

function makeNaviToCookie(){
	return aktivText;
}

function showVTS(sSearchKind){
	var sSearchfach = "search_prox";
	if(sSearchKind) sSearchfach = sSearchKind;
	var CommandID = 'D';
	var ServiceID = 'privat';
	var KundenPLZ = '';
	var KundenStr = '';

	if(document.fachmann){
		if(!sSearchKind){
			KundenPLZ = document.fachmann.Plz.value;
			KundenStr = document.fachmann.Strasse.value;
		} else {
			KundenPLZ = document.fachmann.plz.value;
			KundenStr = document.fachmann.strasse.value;
		}
	}
	if(sSearchfach=='search_fach') CommandID = 'S';
	URI="https://fachmann.allianz.de/vts_app/vts";
	URI+='?ServiceID=' + escape(ServiceID);
	URI+='&AppFlag=VTS';
	URI+='&integrated=false';
	URI+='&CommandID=' + escape(CommandID);
	URI+='&search_fach_prox=' + sSearchfach;
	
	if(sSearchfach=='search_fach'){
		URI+='&plz=' + escape(KundenPLZ);
		URI+='&strasse=' + escape(KundenStr);
	} else {
		URI+='&plz_prox=' + escape(KundenPLZ);
		URI+='&str_prox=' + escape(KundenStr);
	}
	popup_fenster('newSatellit',URI,600,600,'yes','no','no','no','yes','no','yes',55,0);
}

function showVTSWithForm(sSearchfach)
{
	if(sSearchfach=='search_fach') {
		document.fachmann.CommandID.value = 'S';
	}
	else{
		document.fachmann.CommandID.value = 'D';
		document.fachmann.plz_prox.value = document.fachmann.plz.value;
		document.fachmann.str_prox.value = escape(document.fachmann.strasseIntern.value);
	}
	document.fachmann.strasse.value = escape(document.fachmann.strasseIntern.value);
	document.fachmann.search_fach_prox.value = sSearchfach;
	popup_fenster('newSatellit','',600,600,'yes','no','no','no','yes','no','yes',55,0);
}

function showprint(){
	var sUrl = window.location.href;
	if(window.location.search != "")
		sUrl = sUrl + "&mode=print";
	else
		sUrl = sUrl + "?mode=print";
	eval("var newWin = window.open('"+ sUrl +"', 'newWin','height=600,width=800,top=0,left=0,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes')");
}

function checkBackBox(){
	var oBack = document.getElementById('zurueck');
	var oBackPoints = document.getElementById('backpoints');
	
	if((takeCookieText('teasertext')=='' || takeCookieText('teasertext')==null || takeCookieText('teasertext')=='undefined') && (takeCookieText('href')=='' || takeCookieText('href')==null) || takeCookieText('href')=='undefined' || takeCookieText('href')==window.location.pathname){
		oBack.className='notvisible';
		oBackPoints.className='notvisible';
	}else{
		oBack.className='visible';
		oBackPoints.className='points';
	}
	if(bUmfrageExist) processInquiry();
}

function takeCookieText(cookieinhalt){
        if (document.cookie.indexOf(cookieinhalt) != -1){
		var aInCookie = document.cookie.split(";");
		for (y=0;y<aInCookie.length;y++){
			if(aInCookie[y].indexOf(cookieinhalt)!=-1){
				if(aInCookie[y].indexOf("=")!=-1){
					aCookie = aInCookie[y].split("=");
					return unescape(aCookie[1]);}
				else	{
					return null;
				}}	
		}
	}else{return '';}
}

function setQPCookie(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;
}

function nurZahlen(feld) {var zahlen = "0123456789_"; for (var i=0; i < feld.length; i++) if (zahlen.indexOf(feld.charAt(i)) == -1){return false;} return true}

function checkIfImpressum(){
	var sQuery = location.search.substring(1);
	if (sQuery.indexOf("Impressum=false") != -1) 
		sImpressum = false;
	if (!sImpressum)
		document.getElementById('navPointImpressum').style.display = "none";
}

function impFalse(where){
	if(sImpressum)
		window.location.href=where;
	else{
		if(where.indexOf('?email=')!=-1)
			window.location.href=where+"&Impressum=false";
		else
			window.location.href=where+"?Impressum=false";}
}

function goToWithHdlDate(where){
	if(where!=null)
		window.location.href=where+location.search;
}

function setFontSize(nSetSize)
{
	var nPercent = 75;
	var nSize = nSetSize;
	var nCookieSize = loadUsersettings("editcontent", "FontSize");
	if(nCookieSize) 
		nPercent = parseInt(nCookieSize);
	if(nSize) {
		nPercent+=parseInt(nSize);
		saveUsersettings("editcontent", "FontSize", nPercent);
		document.body.style.fontSize = nPercent + "%";
	}
}
function loadUsersettings(sGroup, sName)
{
	return loadSaveUsersettings("load", sGroup, sName);
}

//save the user setting
function saveUsersettings(sGroup, sName, sValue)
{
	return loadSaveUsersettings("save", sGroup, sName, sValue);
}

//save/load user setting (cookie)
function loadSaveUsersettings(sType, sGroup, sName, sValue)
{
	var sCookieName = sGroup + sName;
	if (sType == "save") {
		var dDate = new Date(2099, 12, 31);
		var sSetCookie = sCookieName + "=" + escape(sValue) + "; path=/";
		document.cookie = sSetCookie;
	}else{
		var aCookies = document.cookie.split("; ");
		for (var i=0; i < aCookies.length; i++)
		{
			var sCookie = aCookies[i].split("=");
			if (sCookieName == sCookie[0]) 
				return unescape(sCookie[1]);
		}
	}
}

function showbigpicture(sBigImage, sPicID) {
	var	sAbzugY = 149;
	if (op7) {
		sAbzugY = 15;
	}
	else if (moz) {
		sAbzugY = 151;
	}
	var sSmallPicture = document.getElementById(sPicID);
	var sSmallPictureYPos = findPosY(sSmallPicture);
	var sPicDiv = document.getElementById("showbigpictureimage");
	sPicDiv.style.left = 0 + "px";
	sPicDiv.style.top = (sSmallPictureYPos - sAbzugY) + "px";
	sPicDiv.style.display = "inline";
	sPicDiv.src = sBigImage;
}	
function closebigpicture(element) {
	var sPicDiv = document.getElementById(element.id);
	sPicDiv.style.display = "none";
	sPicDiv.src = "";
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function pruefen(form,aReqFields) {
	leeresFeld = false;
	var sLang="de";
	if(form.englishversion.value.toLowerCase()=='true') sLang="en";
	Pflichtfelder = new Array();
	var oField;
	var sRatingResult;
	for (a=0; a<aReqFields.length; a++){
		oField = eval('form.'+aReqFields[a]);
		// Abfrage der Check- und Radioboxen
		var oType = oField.type;
		if (oField.type == undefined)
			oType = oField[0].type;
		if (oType =='checkbox' || oType =='radio'){
			var bChecked = false;
			if(!oField.length) {
				if (oField.checked) 
					bChecked = true;
			}else{
				for (i=0; i<oField.length; i++){
					if (oField[i].checked) {
						sRatingResult = oField[i].value;
						bChecked = true;
						break;}}}
			if (bChecked == false) {
				if(aReqFields[a]=='rating' && sLang == 'de')
					Pflichtfelder[Pflichtfelder.length] = "Bitte bewerten Sie die Seite";
				else if(aReqFields[a]=='rating' && sLang == 'en')
					Pflichtfelder[Pflichtfelder.length] = "Please select a rating";
				else
					Pflichtfelder[Pflichtfelder.length] = "- "+aReqFields[a];
			}
		}
		if ((oType == 'select-one' || oType == 'select') && oField.selectedIndex==0){
			Pflichtfelder[Pflichtfelder.length] = "- "+aReqFields[a];}
		if (leeresFeld == false && FeldLeer(oField) == true){
			Pflichtfelder[Pflichtfelder.length] = "- "+aReqFields[a];
		}
	}
	
	if (Pflichtfelder.length > 0){
		var sFehlerQuery = Pflichtfelder.join("<br>");
		if (window.showModalDialog) {
			window.showModalDialog("/global/azgroup/error.html?lang=" +sLang+ "&" +sFehlerQuery, null, 'dialogHeight:230px;dialogWidth:510px;center:yes;help=no;resizeable=yes;status=no');
		} else {
			eval("popup_content('fehlerhinweis','/global/azgroup/error.html?lang=" +sLang+ "&" +sFehlerQuery + "',500,200,'yes','yes');");
		}
		leeresFeld = true;
	}
	if (leeresFeld == false) {
		var ratingPopup = window.open('','pagerating','width=512,height=530,scrollbars=0,toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1');
		form.target = ratingPopup.name;
		form.submit();
	}
}

function checkLengthAndAlarm(CountSigns,oThisField)
{
	if(oThisField.value.length > CountSigns)
	{
		alert("Ihr Text ist zu lang, er besteht aus " + oThisField.value.length + " Zeichen. Bitte k"+ String.fromCharCode(252) +"rzen Sie den Text auf max. " +CountSigns+ " Zeichen.");
		oThisField.focus();
	}
}

function FeldLeer(feld){
	if (feld && feld.value == "") return true; else return false;}

function checkEmail(email)
{
	var filter=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i;
	if (!(filter.test(email)))
	return false;
}
function nurZahlen(feld) {
	if (isNaN(feld.value))
		return false;
	else 
		return true;
}
function resetForm(){
    var bCheck = confirm("Sollen alle Inhalte des Formulars gel" + String.fromCharCode(246) + "scht werden?");
    if(bCheck == true) 
	document.frmForm.reset();
}

/********* Funktion fuer Such-Feld ***********/
function isSearchEnter(e, sActionUrl) {
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (code == 13){
            e.cancelBubble = true;
            e.returnValue = false;
            window.location.href = sActionUrl;
	}
}

/******** Portlets ****************************/

function toggleTeaserVisibility(block) {
	var e,eall,activlink;
	for(var i=0;i<3;i++){
		eall = document.getElementById("reiter"+(i+1)+"Rechner");
		eall.className += " invisible";
		activlink = document.getElementById("reiter"+(i+1));
		activlink.className = activlink.className.replace(" aktiv", "");
	}
	if(block!=null){
		e = document.getElementById("reiter"+block+"Rechner");
		er = document.getElementById("reiter"+block);
	}
	if (e.className.indexOf(" invisible")!=-1 || !e.className){	
		e.className = "rechner";
		er.className += " aktiv";
	} else { 
		e.className += " invisible";
		er.className = er.className.replace(" aktiv", "");
	}
}
function toggleLinkVisibility(elem) {
	var e;
	if(elem!=null)
		e = elem.nextSibling;
	if (e.className == "invisible" || !e.className){	
		e.className = "visible";
		elem.className += " openlink";
		checkContentHeight("open");
	} else {
		e.className = "invisible";
		elem.className = elem.className.replace(" openlink", "");
		checkContentHeight("close");
	}
}

function toggleInfotextVisibility(elem) {
	var e;
	if(elem!=null)
		e = eval(document.getElementById(elem));
	if (e.className.indexOf("visible")==-1 || !e.className){	
		e.className += " visible";
	} else {
		e.className = e.className.replace(" visible", "");
	}
}
function getParams(){
	var params = window.location.search.slice(1);
	
	var params_arr = params.split("&");
	var key_value_pair;
	var key_value_pairs = {};
	for(var i = 0, len = params_arr.length; i<len; i++){
		key_value_pair = params_arr[i].split("=");
		key_value_pairs[key_value_pair[0]] = key_value_pair[1]
	}
	
	return key_value_pairs;
}

var keyvaluepairs = getParams();

