String.prototype.trim=function(){
	var str = this.replace(/\s+$/,'');
	str = str.replace(/^\s+/,'');
	return str;
}

//bin in Reddot ausser Vorschumodus
function isReddotmodus(){

var nn='';
	if(location.href.indexOf('http://reddot')>-1 ){
			nn=1;
			if(location.href.indexOf('Action=Preview')>-1){
				nn=0;
			}
		}else{
			nn=0;
		}	

	if(nn==0){return false;}else{return true}

}


function getArgs1(query,sep){
	var args = new Object();
	var params = query.split(sep);
	for(var i=0; params.length > i; i++){
		param = params[i].trim()
		aParam=param.split(/=/);
		args[aParam[0]] = aParam[1]; 
  }
  return args;
}



//liest rekursiv die Tabellen/Listenstruktur, und erzeugt daraus den Menuebaum erzeugt wird
function countTags(n,tiefe,breite){ 
  if(!n){return 0;} //alert(n.childNodes[0])
  if(n.childNodes && (n.tagName=='UL'|| n.tagName=='TR')){
    tiefe++; laenge=n.childNodes.length;
  }
  var children = n.childNodes;

  for(var i=0; i < children.length; i++) {	  
    if(children[i].nodeType!=1){continue;}
    if(children[i].childNodes && (children[i].tagName=='LI' || children[i].tagName=='TD')){
      if(children[i].tagName=='TD'){breite++;
		//internes Menü ausblenden ausser in reddot

		if( (breite==9 && location.href.indexOf('/intern/')==-1)  ){
		
			//if(location.href.indexOf('reddot.conova.com')==-1){break;}
		
		}
			
	  }
      if(children[i].parentNode.parentNode.id){
         //pn_temp = children[i].parentNode.parentNode.id;
		 //aPn = pn_temp.split('_');
		 //pn = aPn[0]+''+aPn[1];
		 //pn = children[i].parentNode.parentNode.id;	
		 //pn=aPn[1];
		 pn=reddot_id;
		 //alert(pn)
        parent_name = 'menu' + breite + '_'+ children[i].parentNode.parentNode.id ;
	  }else{
        pn='';
        parent_name = '';
	  }

      name = 'menu' + breite+ '_' + tiefe + pn +  '_' + i; 

      var elem_index=0;

      if(children[i].childNodes[0].href=='javascript:void(0)'){elem_index=1;} //Reddot setzt noch ein element dazwischen
      
      //text,link,target
      text = children[i].childNodes[elem_index].innerHTML;
      link = children[i].childNodes[elem_index].href;
      target =children[i].childNodes[elem_index].target;
	  reddot_id = 	children[i].childNodes[elem_index].id;
      //restliche Attribute 
      width='';
	  height='';
      pic='';
      pic_over='';
	  reg_class=''
	  ov_class='';
	  align='';
	  rows='';
	  nolink='';
	  onclick='';
	  onmouseover='';
	  onmouseout='';



      if(children[i].childNodes[elem_index+1] && children[i].childNodes[elem_index+1].tagName=='DIV'){
        rest_attr=children[i].childNodes[elem_index+1].innerHTML;
		
		
		aRest_attr = rest_attr.split('|'); //Trennzeichen | oder in Reddot |<br> , es dürfen also in den Attributwerten keine | vorkommmen! 

	    width=aRest_attr[0];
	    height=aRest_attr[1];			  
	    if(window.homepage && tiefe==0){height=53;}
		
		
		aPic1 =aRest_attr[2].split('"');
		if(aPic1.length>1){pic=aPic1[1];}


	    //auf der homepage anderes Bild bereitstellen
		/*
 	    if(window.homepage){
	      pic = pic.replace(/1menu/,'menu');
	    }
	    //für reddot fix setzen
	    if(location.href.indexOf('http://reddot')>-1  && window.homepage && pic){
			
		  aPic = pic.split(/\//);
		    if(aPic){
			  pic = 'http://www.conova.com/' + aPic[aPic.length-1]
		  }
	    }
		*/

		if(aRest_attr.length>3){
			aPic1_over=aRest_attr[3].split('"');		  
			if(aPic1_over.length>1){pic_over=aPic1_over[1];}
		}
		//auf der homepage anderes Bild bereitstellen
 	    if(window.homepage){
			pic_over = pic_over.replace(/1menu/,'menu');
	    }
	    //für reddot fix setzen
		/*
		if(location.href.indexOf('http://reddot')>-1  && window.homepage && pic_over){
		  aPic_over = pic_over.split(/\//);
		    if(aPic_over){
			  pic_over = 'http://www.conova.com/' + aPic_over[aPic_over.length-1]
		  }
	    }
		*/

		if(aRest_attr.length>4){
			reg_class=aRest_attr[4];	
		}

		if(aRest_attr.length>5){
			ov_class=aRest_attr[5];	
		}





	  }

      oCMenu.makeMenu(name,parent_name,text,link,target,width,height,pic,pic_over,reg_class,ov_class,align,rows,nolink,onclick,onmouseover,onmouseout,reddot_id);
	  children[i].id=tiefe + pn + '_' + i;
    }

    countTags(children[i],tiefe,breite);      // Recurse on each one

  }

}


function init(){




//Bereich intern linke/bilder richtigstellen


allImg = document.getElementsByTagName('IMG');

if(location.href.match(/intern/)){
	for(i=0;i<allImg.length;i++){
		if(allImg[i].src.match(/images/)){	
			allImg[i].src =  allImg[i].src.replace('/intern','');
		}
	}	

}

allHref = document.getElementsByTagName('A');

if(location.href.match(/intern/)){
	for(i=0;i<allHref.length;i++){
		if( allHref[i].href.match(/intern/)){
		//	if(allHref[i].href.match(/intern\/index/)){continue;}
			allHref[i].href =  allHref[i].href.replace('intern/','');
			allHref[i].href =  allHref[i].href.replace('intern/intern','/intern/');
			allHref[i].href =  allHref[i].href.replace('at/download','at/intern/download');

		}
	}	

}





/*** 
This is the menu creation code - place it right after you body tag
Feel free to add this to a stand-alone js file and link it to your page.
Wird am Ende des HTML-Dokuments aufgerufen
**/

//Menu object creation
oCMenu=new makeCM("oCMenu") //Making the menu object. Argument: menuname

oCMenu.frames = 0

//es wird nur das angegeben Einzelmenue ausgegeben 
einzelmenu=0;


//Menu properties   
oCMenu.pxBetween=1
oCMenu.fromLeft= xPageX(document.getElementById('headermenu'))+20; 
oCMenu.fromTop=  xPageY(document.getElementById('headermenu'));  

oCMenu.rows=1
oCMenu.menuPlacement=""
                                                             
oCMenu.offlineRoot="" 
oCMenu.onlineRoot="" 
//oCMenu.resizeCheck=0 
oCMenu.wait=200 
oCMenu.fillImg=""
oCMenu.zIndex=1000

//Background bar properties


oCMenu.useBar=0
oCMenu.barWidth="100%"
oCMenu.barHeight="menu" 
oCMenu.barClass="clBar"
oCMenu.barX=0 
oCMenu.barY=0
oCMenu.barBorderX=0
oCMenu.barBorderY=0
oCMenu.barBorderClass=""



//Level properties - ALL properties have to be spesified in level 0
oCMenu.level[0]=new cm_makeLevel() //Add this for each new level
oCMenu.level[0].width=120
oCMenu.level[0].height=24 
oCMenu.level[0].regClass="clLevel0"
oCMenu.level[0].overClass="clLevel0over"
oCMenu.level[0].borderX=0
oCMenu.level[0].borderY=0
oCMenu.level[0].borderClass="clLevel0border"
oCMenu.level[0].offsetX=0
oCMenu.level[0].offsetY=0
oCMenu.level[0].rows=0
oCMenu.level[0].arrow=0
oCMenu.level[0].arrowWidth=0
oCMenu.level[0].arrowHeight=0
oCMenu.level[0].align="bottom"
//oCMenu.level[0].slidepx=10
//oCMenu.level[0].slidetim=20

//oCMenu.level[0].filter="progid:DXImageTransform.Microsoft.Fade(duration=0,8)" 
//oCMenu.level[0].scrollstop =1;
//oCMenu.level[0].clippx=5
//oCMenu.level[0].cliptim=20



//EXAMPLE SUB LEVEL[1] PROPERTIES - You have to specify the properties you want different from LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[1]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[1].width=oCMenu.level[0].width-2
oCMenu.level[1].height=20
oCMenu.level[1].regClass="clLevel1"
oCMenu.level[1].overClass="clLevel1over"
oCMenu.level[1].borderX=1
oCMenu.level[1].borderY=1
oCMenu.level[1].align="right" 
oCMenu.level[1].offsetX=-(oCMenu.level[0].width-2)/2+45
oCMenu.level[1].offsetY=4
oCMenu.level[1].borderClass="clLevel1border"
oCMenu.level[1].zIndex=0


//EXAMPLE SUB LEVEL[2] PROPERTIES - You have to specify the properties you want different from LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[2]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[2].width=oCMenu.level[0].width+25
oCMenu.level[2].height=20
oCMenu.level[2].regClass="clLevel1"
oCMenu.level[2].overClass="clLevel1over"
oCMenu.level[2].borderX=1
oCMenu.level[2].borderY=1
oCMenu.level[2].align="right" 
oCMenu.level[2].offsetX=-(oCMenu.level[0].width-2)/2+45
oCMenu.level[2].offsetY=4
oCMenu.level[2].borderClass="clLevel1border"
oCMenu.level[2].zIndex=0


//HAUPTPROGRAMM
//einlesen der tabelleb menu1

countTags(document.getElementById('menu1'),-1,0);
oCMenu.construct();


if(document.getElementById('menuid')){
	menu_id=document.getElementById('menuid').innerHTML;
}else{
	menu_id='';
}


//	alert(menu_id)
//alert(menuid)
//alert(menuid)
aMenue=baueMenu(oCMenu.m,menu_id);

submenue = aMenue[0];
subsubmenue= aMenue[1];
//alert(aMenue[0]);
//submenue='Submenu in bearbeitung';
//subsubmenue='Subsubmenu in bearbeitung';





if(document.getElementById('sidemenu')){
	document.getElementById('sidemenu').innerHTML=submenue;
}



if(document.getElementById('bluemenu')){
	document.getElementById('bluemenu').innerHTML=subsubmenue;
}





//<![CDATA[
if(typeof sIFR == "function"){
 sIFR.replaceElement(".rubrik", "http://www.daihatsu.at/styles/tom_helv.swf","#E2001A", "#E2001A", null, null, 0, 0, 0, 0, "", "", "transparent");
 sIFR.replaceElement(".td_name", "http://www.daihatsu.at/styles/tom_helv.swf","#999999", "#999999", null, null, 0, 0, 0, 0, "", "", "transparent");
 sIFR.replaceElement(".slogan", "http://www.daihatsu.at/styles/tom_helv.swf","#CCCCCC", "#CCCCCC", null, null, 0, 0, 0, 0, "", "", "transparent");
};
//]]>






function baueMenu(menu,id){



  var templ_hauptmenu_start=
'<table border="0" cellspacing="0" cellpadding="0" class="menublock">'+
'       <tr>'+
'         <td class="menumainblock"><table border="0" cellspacing="0" cellpadding="0" class="menumainbg">'+
'             <tr>'+
'               <td class="menumainbull"><img src="images/navigation/1.gif" width="1" height="1"></td>'+
'               <td class="menumaintxt"><a  href="tmpl_url">tmpl_txt</a></td>'+
'             </tr>'+
'           </table>'+
'         </td>'+
'       </tr>'+
'       <tr class="menusubblock_tr">'+
'         <td class="menusubblock">'+"\n\n\n";

//templ_hauptmenu_start= '<a href="tmpl_url" >tmpl_txt</a><br>';



  var templ_hauptmenu_end=
'         </td>'+
'       </tr>'+
'     </table>'+"\n\n\n";;

 //  templ_hauptmenu_end='';


  var templ_submenu=
'	<table border="0" cellspacing="0" cellpadding="0" class="menusubbg">'+
'             <tr>'+
'               <td class="menusubbull"><img src="images/navigation/1.gif" width="1" height="1"></td>'+
'               <td class="menusubtxt"><a href="tmpl_url" >tmpl_txt</a></td>'+
'             </tr>'+
'        </table>'+"\n\n\n";

//templ_submenu= '<a href="tmpl_url" >tmpl_txt</a><br>';

  var templ_subsubmenu=
'	<table border="0" cellspacing="0" cellpadding="0" class="menusubsubbg">'+
'             <tr>'+
'               <td class="menusubsubbull"><img src="images/navigation/1.gif" width="1" height="1"></td>'+
'               <td class="menusubsubtxt"><a href="tmpl_url" >tmpl_txt</a></td>'+
'             </tr>'+
'        </table>'+"\n\n\n";





  var templ_header=
'     <table border="0" cellspacing="0" cellpadding="0" class="menublock">'+
'       <tr>'+
'         <td class="menutrennerblock">'+
'           <table class="menutrennerbg" border="0" cellspacing="0" cellpadding="0">'+
'             <tr>'+
'               <td class="menutrennerbull"><img src="images/navigation/1.gif" width="1" height="1"></td>'+
'               <td class="rubrik">templ_menutitle</td>'+
'             </tr>'+
'           </table>';
//'         </td>'+
//'       </tr>'+
//'     </table>'+"\n\n\n";

templ_header='';
  var templ_hauptmenu_start_active= templ_hauptmenu_start;
  templ_hauptmenu_start_active=templ_hauptmenu_start_active.replace(/class="(\w+)"/gi, "class='$1_active'");

  var templ_submenu_active= templ_submenu;
  templ_submenu_active=templ_submenu_active.replace(/class="(\w+)"/gi, "class='$1_active'");


  var templ_subsubmenu_active= templ_subsubmenu;
  templ_subsubmenu_active=templ_subsubmenu_active.replace(/class="(\w+)"/gi, "class='$1_active'");



  if(!id){id=-1;}

  var menuepunkt='';

 

  div_subsub=0;	  
  for(var i in menu){ //alert(i); zuerst nach reddotId suchen    	
	

    if(id == menu[i].mid){
	  menuepunkt=i; 
	 // alert(id);
    }
  }



if(!menuepunkt){
  for(var i in menu){ //dann url vergleichen    	
    //url ohne hash bzw, querystring
    loc = location.protocol + '//' + location.host + location.pathname	;
    loc = location.href;
    //if(loc == menu[i].lnk){
     if(loc.indexOf(menu[i].lnk)>-1){
	  menuepunkt=i;
    }
	


  }

}


   //Spezialeinstellung für shop order
/*
  if(location.href.indexOf('http://shop.conova.com/order.php')>-1){
	menuepunkt='menu3_1480_2';
  }	
*/


//alert(menuepunkt)
//menuepunkt='menu1_10_0';
//alert(menu[i].lnk)
//alert(loc)


//  if(!menuepunkt){return ['defaultausgabe submenu starten','defaultausgabe subsubmenu starten']}


  aMenuId = [];
  getArrayMenuId(menu,menuepunkt);


  //Hilight Hauptmenuepunkt

if(aMenuId.length>0){
  menu[menu[aMenuId[aMenuId.length-1]].parent].active('on');
  menu[menu[aMenuId[aMenuId.length-1]].parent].cl = menu[menu[aMenuId[aMenuId.length-1]].parent].cl2;

}else{
//Haupmenues noch implementieren

 // for(var i in menu)
//alert(i)


//	menu.active('on');
//	menu.c1 = menu.c12; 
//  menu[menu[aMenuId[aMenuId.length]]].active('on');
//  menu[menu[aMenuId[aMenuId.length]]].cl = menu[menu[aMenuId[aMenuId.length]].parent].cl2;
}



  aMenuepunkt = menuepunkt.split('_');
  hauptmenue = aMenuepunkt[0];
  ebene = aMenuepunkt[1];
  menu_id = aMenuepunkt[2];


  menue_html ='';
  menuesub_html ='';

divsubsub=0;
divdiv_flag=false;

	active=false;		
	active1=false;		
	active3=false;		
  for(var i in menu){ 
//alert(i + ': ' + menu[i].txt )	
//alert(i)
//		getMenudepth(i);continue;

	if(i.indexOf(hauptmenue)==0){
//alert(i + ' - ' + hauptmenue)


	  if(i.indexOf(hauptmenue+'_0')==0){ //Baue ueberschrift

		//hilight für hauptmenüpunkte
		menu[i].active('on');
		menu[i].img1.src = menu[i].img2.src;
	
		//wenn hauptmenüs Bilder sind, müssen die Texte aus der Tabelle geholt werden, da in 
		//menu[i].txt nur mehr das Image Tag steht

		if(location.href.indexOf('http://reddot')>-1){
			nn=1;
			if(location.href.indexOf('Action=Preview')>-1){
				nn=0;
			}
		}else{
			nn=0;
		}	

		if(menu[i].txt.indexOf('<img')==0){
			var result = menu[i].txt.match(/imgmenu(\d+)/); 	
			result1=result[0].replace(/imgmenu/,'');
			menutable = document.getElementById('menu1');
			menue_tmp = menutable.rows[0].cells[result1-1].childNodes[nn].childNodes[0].nodeValue;
			menue_html += templ_header.replace(/templ_menutitle/i, menue_tmp);  		  		    				
			//alert(menu[i].txt)
		}else{
		    menue_html += templ_header.replace(/templ_menutitle/i, menu[i].txt);  		  		    	
		}
	  }



		  if(i.indexOf(hauptmenue+'_1')==0){ //alert(menu[i].lnk)	 //baue 1. ebene
			menue_html+=templ_hauptmenu_end;


            active1=false;
	    for(m=0;aMenuId.length>m;m++){ if(aMenuId[m]==i){active1=true;} }

	    if(active1){//aktiver Punkt
		
	      templ_hauptmenu_start_active_=templ_hauptmenu_start_active;
	      templ_hauptmenu_start_active_ = templ_hauptmenu_start_active_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_hauptmenu_start_active_.replace(/tmpl_url/i, menu[i].lnk);  

			  menu[menu[i].parent].img1.src = menu[menu[i].parent].img2.src;
			  menu[i].cl = menu[i].cl2;	  
			
	
	    }else{
	      templ_hauptmenu_start_=templ_hauptmenu_start;
	      templ_hauptmenu_start_ = templ_hauptmenu_start_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_hauptmenu_start_.replace(/tmpl_url/i, menu[i].lnk);  	    
	    }	
	  }


          if(i.indexOf(hauptmenue+'_2')==0 && active1){  //baue 2. ebene && nur bei aktiver ersten ebene
		    if(divdiv_flag){
			menue_html += "</div>";
			divdiv_flag=false;
			}
							
			active=false;
	    for(m=0;aMenuId.length>m;m++){ if(aMenuId[m]==i){active=true;} }

	    if(active){//aktiver Punkt 
	      templ_submenu_active_=templ_submenu_active;
	      templ_submenu_active_ = templ_submenu_active_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_submenu_active_.replace(/tmpl_url/i, menu[i].lnk);  

           // menu[i].active('on');
              menu[i].cl = menu[i].cl2;


	    }else{
	      templ_submenu_=templ_submenu;
	      templ_submenu_ = templ_submenu_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_submenu_.replace(/tmpl_url/i, menu[i].lnk);  	    
	    }	
	  }


			
          if( (i.indexOf(hauptmenue+'_3')==0)  && (active == true) && active1){  //baue 3. ebene 
			divdiv_flag=true;
			if(divsubsub==0){ //wenn das erstemal ein susu auftritt
			menue_html += "<div id='subsub'  class='menusubsubblock_active'>";
			}
			divsubsub++;
			active3=false;
	    for(m=0;aMenuId.length>m;m++){ if(aMenuId[m]==i){active3=true;} }
	  // alert( menu[menu[menu[i].parent].parent].parent )

	    if(active3){//aktiver Punkt
		
	      templ_subsubmenu_active_=templ_subsubmenu_active;
	      templ_subsubmenu_active_ = templ_subsubmenu_active_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_subsubmenu_active_.replace(/tmpl_url/i, menu[i].lnk);  

              //menu[i].active('on');
              menu[i].cl = menu[i].cl2;


	    }else{
	      templ_subsubmenu_=templ_subsubmenu;
	      templ_subsubmenu_ = templ_subsubmenu_.replace(/tmpl_txt/i, menu[i].txt);  
	      menue_html += templ_subsubmenu_.replace(/tmpl_url/i, menu[i].lnk);  	    
	    }	
	  }








	}		





  }


  menue_html+=templ_hauptmenu_end;

  aMenue_html=[menue_html,menuesub_html];
//alert(aMenue_html)
  return aMenue_html;






}








//erhalte ein array aller parentobejekte des menues in aMenuId
function getArrayMenuId(obj,id){
  if(obj[id]){
    if(obj[id].parent){
      aMenuId.push(id);	
      getArrayMenuId(obj,obj[id].parent)
    }
  }
}




//////////////////drag Mrenu by crossbrowser

function d1Setup(){
  var d1 = document.getElementById('boxmenu1');
  xMoveTo(d1, xPageX('onoff')+xWidth('onoff'), xPageY('onoff'));
  xEnableDrag(d1, d1OnDragStart, d1OnDrag, d1OnDragEnd);
  xShow(d1);
}

function d1OnDragStart(ele, mx, my){
  ele.totalMX = 0;
  ele.totalMY = 0;
}

function d1OnDrag(ele, mdx, mdy){
  xMoveTo(ele, xLeft(ele) + mdx, xTop(ele) + mdy);
  ele.totalMX += mdx;
  ele.totalMY += mdy;
}

function d1OnDragEnd(ele, mx, my){
}

d1Setup();




	window.onresize=function(){
		oCMenu.fromLeft= xPageX(document.getElementById('headermenu')); 
		oCMenu.fromTop=  xPageY(document.getElementById('headermenu'));  
		oCMenu.construct(1);

	}



	window.onscroll=function(){

		oCMenu.fromLeft= xPageX(document.getElementById('headermenu')); 
		oCMenu.fromTop=  xPageY(document.getElementById('headermenu'));  
		oCMenu.construct(1);
	
	}

//alert(window.onscroll)


   //Cookie für die Menütabelle bei verlassen der Seite einlesen
	window.onunload= function(){
		document.cookie='tab_x=' + xPageX('boxmenu1');
		document.cookie='tab_y=' + xPageY('boxmenu1');
		document.cookie='tab_vis=' + xGetElementById('boxmenu1').style.display;
	}











   //Cookie für die Menütabelle nach einlesen der seite auslesen und aktivieren
	if(location.href.indexOf('http://reddot')>-1 ){	
	var params = getArgs1(document.cookie,';')
	if(params.tab_vis == undefined){params.tab_vis='none'}
	xGetElementById('boxmenu1').style.display = params.tab_vis;
	xGetElementById('boxmenu1').style.top = params.tab_y;
	xGetElementById('boxmenu1').style.left = params.tab_x;

	}






	//fuer sidebar Farbabstufungen
//	if(window.verzeichnis_bilder && xGetElementById('si_content') && location.href.indexOf('daihatsu.at')>-1){
	if(window.verzeichnis_bilder && xGetElementById('si_content')){
		pics = xGetElementById('si_content').getElementsByTagName('IMG');
		for(var i=0; pics.length>i; i++){
			pics[i].align='middle';
			pics[i].parentNode.id=i+1;
			pics[i].parentNode.style.cursor='pointer';
			pics[i].parentNode.style.padding=0;
			pics[i].parentNode.style.marginBottom=-10;
			pics[i].parentNode.style.border='1px solid #eeeeee';
			pics[i].parentNode.onclick= function(){
				showNormPic(parseInt(this.id),verzeichnis_bilder)
				}

			pics[i].parentNode.onmouseover= function(){
				this.style.border='1px solid #999999';
				this.style.backgroundColor='#ffffff';
				}

			pics[i].parentNode.onmouseout= function(){
				this.style.border='1px solid #eeeeee';
				this.style.backgroundColor='#eeeeee';
				}
	

		}
	}



}


















