// $Id: functions.js 3880 2009-02-19 16:43:27Z MI $
function setImagePath(path)
{
ApplicationPath = new String();
ApplicationPath = path;
img = new Array();

img[0] = new Image();
img[0].src = path + '/images/sys/mainMenuOn.gif';
img[1] = new Image();
img[1].src = path + '/images/sys/mainMenuOff.gif';
}

function highlight(id , ParentId)
{
  var browser = new Array();  browser = browserCheck();
  if (typeof(img) != 'undefined'){		
     if(ParentId == id) //Parent = 1 ==> oberste Menüebene
		{
			if(browser[1] <= 5 && browser[2] == "macppc" && browser[0] == 'Microsoft Internet Explorer')
			{
				document.getElementById('td' + id).style.backgroundImage= "url(" + img[0].src + ")";
			}
			else
			{
			document.getElementById('td' + id).style.background= "url('" + img[0].src + "')";
			}
		
			if (browser[0] == 'Microsoft Internet Explorer' && browser[1] >= 4)
		{   
			document.getElementById('td' + id).style.cursor = 'hand';
			document.getElementById('td' + ParentId).style.cursor = 'hand';
		}
	  
		else
		{
			document.getElementById('td' + id).style.cursor = 'pointer';
			document.getElementById('td' + ParentId).style.cursor = 'pointer';
		}
	}
	else
	{
		if ((browser[0] == 'Microsoft Internet Explorer' && browser[1] >= 4) || (browser[0] == 'Safari'))
		{   
			//document.getElementById('td' + id).style.backgroundColor = '#F2F9F1';
			document.getElementById('td' + id).style.backgroundColor = '#D9EDD4';
			document.getElementById('td' + id).style.color = '#000000';
			document.getElementById('td' + id).style.cursor = 'hand';
			document.getElementById('td' + ParentId).style.cursor = 'hand';
		}
	  
		else
		{	
			document.getElementById('td' + id).style.cursor = 'pointer';
			document.getElementById('td' + ParentId).style.cursor = 'pointer';
			document.getElementById('td' + id).style.backgroundColor = '#D9EDD4';
			document.getElementById('td' + id).style.color = '#000000';
		}
	}	
	     
	var el = document.getElementById('t' + ParentId);
	if (el)
	{
	//if (browser[0] != 'Microsoft Internet Explorer' || browser[1] < 4 || (browser[1] <= 5 && browser[2] == "macppc") && ParentId == id)
	//{//sollte auch für MAC IE 5 funktionieren!!!
		var elWidth = document.getElementById('menuTable').width *0.2;
		var elLeft = findPosX(document.getElementById('td' + id));
		var elTop = findPosY(document.getElementById('td' + id));	 
		if(browser[0] == 'Safari')
		{
			elLeft += 15;
			elTop -= 1;
		}
		    
		if(browser[1] <= 5 && browser[2] == "macppc" && browser[0] == 'Microsoft Internet Explorer')
		{
	  
			if (ParentId == id)
			{
				elTop = 0;
			}	
			else 
			{
				elWidth -= 1;
			}
		}
	       
	       
		el.style.width = elWidth + 1;
		el.style.left = elLeft - 1;
		el.style.top = elTop + 20;
	//}
	   
	el.style.display = 'inline';	   
	}  }
}

function highlight2(id , ParentId)
{
  var browser = new Array();
  browser = browserCheck();
  //document.getElementById('td' + id).style.backgroundColor = '#F2F9F1';
  document.getElementById('td' + id).style.backgroundColor = '#D9EDD4';
  //document.getElementById('td' + id).style.backgroundColor = '#40A629';
  document.getElementById('td' + id).style.color = '#000000';
  
  if (browser[0] != 'Microsoft Internet Explorer' || browser[1] < 4)
	document.getElementById('td' + id).style.cursor = 'pointer';
  else
	document.getElementById('td' + id).style.cursor = 'hand';
  
  if (browser[0] != 'Microsoft Internet Explorer' || browser[1] < 4)
  {
   if (document.getElementById('td' + ParentId))
	  document.getElementById('td' + ParentId).style.cursor = 'pointer';
  }
  else
  {
    if (document.getElementById('td' + ParentId))
      document.getElementById('td' + ParentId).style.cursor = 'hand';
  }
}

function highlightout(id, stay)
{
  var browser = new Array();
  browser = browserCheck();
  
  if (stay != '0')
  {
      if(browser[1] <= 5 && browser[2] == "macppc" && browser[0] == 'Microsoft Internet Explorer')
        {
	  document.getElementById('td' + id).style.backgroundImage= "url(" + img[1].src + ")";
        }
        else
        {	
          document.getElementById('td' + id).style.background = "url('" + img[1].src+ "')";
        }
  }
  document.getElementById('td' + id).style.color = '#000000';
  var el = document.getElementById('t' + id);
  if (el)
  {    el.style.display = 'none';
  }
}

function highlightout2(id)
{
  document.getElementById('td' + id).style.backgroundColor = '#FFFFFF';
  document.getElementById('td' + id).style.color = '#000000';
  var el = document.getElementById('t' + id);
  if (el)
  {   el.style.display = 'none';
  }
  
 }	
 
function checkBrowserString(string)
{  
    
	detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	thestring = string;    
	return place;
}	

function browserCheck()
{
	var browser = "";
	var version = "";
	var bInfo = new Array();
    if (checkBrowserString('opera')) 
    {
		browser = "Opera";
	}
	else if (checkBrowserString('msie')) 
	{
		browser = "Microsoft Internet Explorer";
	}    else if (checkBrowserString('safari'))
	{
		browser = "Safari";
		version = detect.charAt(8);
	}
	else if (!checkBrowserString('compatible'))
	{
		browser = "Netscape Navigator";
		version = detect.charAt(8);
	}	else browser = "";
	if (!version)
	{
		version = detect.charAt(place + thestring.length);
	}
	
	bInfo[0] = browser;
	bInfo[1] = version;
	bInfo[2] = navigator.platform.toLowerCase();

	return bInfo;
}

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 movr(k) {
 if (document.images) 
  eval('document.img'+k+'.src=img'+k+'_on.src');
}

function mout(k) {
 if (document.images) 
  eval('document.img'+k+'.src=img'+k+'_off.src');
}

function agbtext(id, mobile)
{
    if (mobile == "J") {
    window.location =  ApplicationPath + '/Texts.aspx?content=5';
    }
    else {
        window.open(ApplicationPath + '/Texts.aspx?content=5', 'editPerson', 'scrollbars,resizable,width=620,height=410,left=0,top=0');
    }
}

function impressumtext(id,mobile)
{

    if (mobile == "J") {
        window.location = ApplicationPath + '/Texts.aspx?content=6';
    }
    else {
        window.open(ApplicationPath + '/Texts.aspx?content=6', 'editPerson', 'scrollbars,resizable,width=620,height=410,left=0,top=0');
    }


}
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
}

function SetSuchfeldFocus(site)
{
	var textfields = document.getElementsByTagName('input');
	var cbAnrede = document.getElementById(GetClientId("anrede"));
    var fieldCounter = 0;
	var focusFeld = document.getElementById(GetClientId("txtSuchtext"));
	var suchFeld = document.getElementById(GetClientId("txtSuchtext"));
			
	//Anrede Fokus
	if (cbAnrede != null)
	{
	   cbAnrede.focus();
	   return;
	}
	
	
	/*if (!focusFeld)
	   focusFeld = document.getElementById('_ctl0_wifiheader_txtSuchtext');*/
	   
	   
	if (site.toUpperCase().indexOf('BBDETAILS') <= 0 && site.toUpperCase().indexOf('SSL/GEBUCHTEKURSE') <= 0)
	{
	        if (textfields)
			{
				for (var i = 0;i<textfields.length;i++)
				{
					if (
					    (textfields[i].type == 'text' && 
					        (textfields[i].id.toUpperCase().indexOf('_txtSuchtext'.toUpperCase()) <= 0
					        && textfields[i].id.toUpperCase().indexOf('_txtSuchtext'.toUpperCase()) <= 0))
						|| (textfields[i].type == 'hidden' && textfields[i].id.toUpperCase() == 'CURSORFETCHER'))
					{
					fieldCounter = i;
					break;
					}
				}
			}
		
		if (fieldCounter != 0)
			focusFeld = textfields[fieldCounter];
		    
		//keine fokusierung
		if (typeof(focusFeld) != 'undefined' && focusFeld != null)
		{
			if (focusFeld.id.toUpperCase() == 'CURSORFETCHER')
				return;
		    
			if (focusFeld && !focusFeld.disabled && focusFeld.id != GetClientId("txtFirmenname"))
			    try{
				    focusFeld.focus();
				    } catch(ex){
				        suchFeld.focus();
				    }
		}
	}
}

function ort(url, ortnr, mobile)
{
    if (mobile == "J") {
        window.location.href = url + '/eShop/location.aspx?ortnr=' + ortnr;
    }
    else {

        window.open(url + '/eShop/location.aspx?ortnr=' + ortnr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600');
    }
}

function ShowBUBest(url, mobile)
{

    if (mobile == "J") {

        window.location.href = url;
    }

    else {
        window.open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600');
    }
}

  
	
function goUp(site)
{
	/*if (site == 'bbDetails')
	{
		if (window.location.href.toLowerCase().indexOf("#") == -1)
		{
			window.location.href = window.location.href + "#top";
		}
		
	}*/
	return;
}

function showImage(id, filepath){
	//alert(filepath);
	var span = document.getElementById(id);
	
	span.innerHTML = '<img src="' + filepath + '" border="0" width="120" height="120" alt="" />';
}

function showLinkList(evt){
	var oTarget = evt.target || evt.srcElement;
	var div = document.getElementById('divLinkList');
	if (oTarget != null && oTarget != 'undefined')
	{
	
		if (div.style.display == 'inline'){
		   div.style.display = 'none';
	  	   oTarget.innerHTML = 'Linkliste anzeigen';
	  	   return;
	  	} 
	  	
	  	 div.style.display = 'inline';
	  	 oTarget.innerHTML = 'Linkliste ausblenden';
	  	
	}
}


function displayInhalt(id){
	var div = document.getElementById('dvInhalt_' + id);
	if (div != null && div != 'undefined')
	{
	
		if (div.style.display == 'inline'){
		   div.style.display = 'none';
	  	   return;
	  	} 
	  	 div.style.display = 'inline';
	  	 
	}
}

function setMobileDisplay(path)
{
var subitem;
subitem = document.getElementById('vertSubNavigation');
if (subitem != null) {
    var parent;
    parent = document.getElementById('contentContainer');
    var newdiv = document.createElement('div');
    newdiv.style.clear = 'both';
    newdiv.style.paddingTop = '10px';
    
    newdiv.appendChild(document.getElementById('vertsubmenuheader'));

    subitem.innerHTML = subitem.innerHTML.replace('<br>', '&nbsp;')
    subitem.style.marginBottom = '0';
    newdiv.appendChild(subitem);

    parent.appendChild(newdiv);

}
var subitem2;
subitem2 = document.getElementById('vertSubNavigation2');
if (subitem2 != null) {
    var parent;
    parent = document.getElementById('contentContainer');
    var newdiv = document.createElement('div');
    newdiv.style.clear = 'both';
    newdiv.style.paddingTop = '10px';
    document.getElementById('vertsubmenuheader2').style.cssFloat = "none";
    newdiv.appendChild(document.getElementById('vertsubmenuheader2'));

    subitem2.innerHTML = subitem2.innerHTML.replace('<br>', '&nbsp;')
    newdiv.appendChild(subitem2);

    parent.appendChild(newdiv);

}



}

function showKursbuchMobileSubItems(id) {
    var subitem;
    var options = {};
    subitem = document.getElementById(id + '_subitems');
    if (subitem.style.display == 'table') {
       
        document.getElementById(id + '_subitemsarrow').src = document.getElementById(id + '_subitemsarrow').src.replace('arrow2.png', 'arrow1.png');
      
        document.getElementById(id + '_subitemsarrow').style.paddingRight = '10px';
    }
    
    else {


        document.getElementById(id + '_subitemsarrow').src = document.getElementById(id + '_subitemsarrow').src.replace('arrow1.png', 'arrow2.png');
       
        document.getElementById(id + '_subitemsarrow').style.paddingRight = '11px';

    }

    $("#" + id + '_subitems').toggle("blind", options, 1000);

}





function changeMobileMenu(id,arrow) {
    var item;
    item = document.getElementById(id);
   
    if (item.style.display == 'block') {
        item.style.display = 'none';
        document.getElementById(arrow).src = document.getElementById(arrow).src.replace('menu2.png', 'menu1.png');
    }
    else {
        item.style.display = 'block';
        document.getElementById(arrow).src = document.getElementById(arrow).src.replace('menu1.png', 'menu2.png');
    }
}

function goToPageMobile(url) {

    window.location.href = url;
}


