function preinit()
 {
 	x=document.location.href;
  if (document.location.search.indexOf("MIT") >0 || document.location.href.indexOf("mit.de") > 0) 
       return true;
 	if (x.indexOf("/marine/") >0 || x.indexOf("/garden/") >0 || x.indexOf("/garten/") >0  || x.indexOf("/industrie/") >0  || x.indexOf("/industry/") >0) 
 	 return false;
 	return true;
}

function init() {
	if (!(self.isLoaded))
	 {
	  if (preinit()==false)
	   {
		for (var i=0; i<document.images.length; i++) {
   		document.images[i].oncontextmenu = function() {return false;};
		  document.images[i].galleryimg = 'no';
	}
}
	self.isLoaded = true;
}
}

function AddFavorite(alt) {
	if (webclient.ie) {
		window.external.AddFavorite(document.location.href, document.title);
	} else {
		alert(alt);
	}
}

// --------------------------------------------------------------------------------------------------
// Get Querystring Parameters

function getQueryStringParams() {
    GetParams = new Array();
    if (document.location.search) {
        QueryString = unescape(document.location.search.substring(1,document.location.search.length));
        KeyValuePairs = QueryString.split("&");
        for (i=0; i< KeyValuePairs.length; i++) {
            Param = KeyValuePairs[i].split("=");
            GetParams[Param[0]] = Param[1];
        }
    }
    return GetParams;
}


// --------------------------------------------------------------------
// Select randomly an Image out of an Array
// and change source of image tag

var currImageArrayIdx = 0;
var MainImageLoaded = false;

function showRandomImage(imageArray, imageId) {
    if (imageArray.length > 1) {
        if (document.getElementById) {
            var idx = Math.ceil(Math.random()*imageArray.length) - 1;
            while (idx == currImageArrayIdx) {
                idx = Math.ceil(Math.random()*imageArray.length) - 1;
            }
            currImageArrayIdx = idx;
        }
     	sn=imageArray[currImageArrayIdx];
    	if(sn.length>0 && sn.indexOf(".swf")<0) {
    		if(document.getElementById(imageId))
         document.getElementById(imageId).src = imageArray[idx];
      }
      else
      	{
      		 showRandomImage(imageArray, imageId);
      	}
    }
}


// --------------------------------------------------------------------
// Set Loading Status of MainImage
var random=1;
function setMainImageLoadState() {
	fname=(random==1) ? "Random":"Next";
    window.setTimeout("show"+fname+"Image(homeImages, 'MainImage')", 4500);
}

// --------------------------------------------------------------------
// Select next Image not Randomized 
function showNextImage(imageArray, imageId) {
    if (imageArray.length > 1) {
    	currImageArrayIdx =(currImageArrayIdx < (imageArray.length-1)) ? currImageArrayIdx+1:0;
    	sn=imageArray[currImageArrayIdx];
    	if(sn.length>0 && sn.indexOf(".swf")<0 ) {
        document.getElementById(imageId).src = imageArray[currImageArrayIdx];
      }
      else {
      	 showNextImage(imageArray, imageId);
      }
    }
}



// --------------------------------------------------------------------
// Set/Unset Colorcubes / Accessories Icons

var currentCubeContent = "&nbsp;"

function setCube(id, text) {
    if (document.getElementById) {
        if (document.getElementById("Cube"+id)) {
            currentCubeContent =  document.getElementById("Caption").innerHTML;
            document.getElementById("Caption").innerHTML = text;
        }
    }
}

function unsetCube(id, text) {
    if (document.getElementById) {
        if (document.getElementById("Cube"+id)) {
            document.getElementById("Caption").innerHTML = currentCubeContent;
        }
    }
}

function setThumb() {
    if (document.getElementById) {
        if (document.getElementById("Caption")) {
            document.getElementById("Caption").innerHTML = "";
        }
    }
}

function unsetThumb() {
    if (document.getElementById) {
        if (document.getElementById("Caption")) {
            document.getElementById("Caption").innerHTML = "";
        }
    }
}

// --------------------------------------------------------------------
// Show/Hide Tooltip

function showTooltip(evt, id) {

	var x, y;
	e = evt || window.event;
	if (!e) return null;

	if (webclient.ns4) {
		x = e.pageX;
		y = e.pageY;
	} else if (webclient.op) {
		x = e.clientX;
		y = e.clientY;
	} else if (webclient.ie) {
		x = e.x + document.body.scrollLeft;
		y = e.y + document.body.scrollTop;
	} else if (webclient.moz5) {
		x = e.pageX;
		y = e.pageY;
	}

	obj = MM_findObj(id);
	//status = obj + " at position " + x + "/" + y;
	if (obj) {
		if (webclient.ns4) {
			obj.left = x - obj.document.width - 5;
			obj.top  = y - obj.document.height - 5;
			//obj.style.top = (obj.style.top < 380) ? 380 : obj.style.top;
			obj.visibility = 'visible';
		}  else if (webclient.ie || webclient.moz5) {
			x = x - obj.offsetWidth - 5;
			y = y - obj.offsetHeight - 5;
			//y = (y < 380) ? 380 : y;
			if (webclient.ie && webclient.mac) {
				x = x + 'px';
				y = y + 'px';
			}
			//obj.style.left = x;
			obj.style.top  = y;
			obj.style.visibility = 'visible';
		} else if (webclient.op){
        	//obj.style.left = x - obj.style.pixelWidth - 5;
			obj.style.top  = y - obj.style.pixelHeight - 5;
			//obj.style.top = (obj.style.top < 380) ? 380 : obj.style.top;
			obj.style.visibility = 'visible';
		} else {
			//obj.style.left = x - 220;
			obj.style.top  = 380;
			obj.style.visibility = 'visible';
    	}
	}
}

function hideTooltip(id) {
	MM_showHideLayers(id, '', 'hide');
}


// --------------------------------------------------------------------------------------------------
// Function to open popup window for used motorcycles

function showUsedMCs(destUrl) {

	dUrl =(showUsedMCs.arguments.length >0) ?  destUrl:"/redirs/used_mcs.html";
	FE = window.open(dUrl,"usedMCs","width=665,height=580,screenX=5,screenY=5,locationbar=no,menubar=no,status=no,resizable=yes,scrollbars=yes,scrolling=auto");
}



// --------------------------------------------------------------------------------------------------
// Common function to open a popup window

var xwin=null;

function closeWindow() {

  if (xwin.closed==false)
     {
      xwin.close();
      xwin=null;
     };

}

// this function is used by imageshuffle.swf
	function openNewWindow(URLtoOpen,windowName, windowFeatures) {
		newWindow=window.open(URLtoOpen, windowName, windowFeatures);
	}
// end of imageshuffle.swf-window

function openWindow(destination, windowname, xsize, ysize, scrolling,res) {

	if (xwin != null) { closeWindow(); }
	if (res==''  || res==null) {
		res="no";
	}
	 

 	if (webclient.moz5) {
 		res="yes";
 		newx = xsize + 0;
  		newy = ysize + 0;
  	} else {
  		newx = xsize;
  		newy = ysize;
  	}

  	scrollflag = scrolling;

  	if (parseInt(navigator.appVersion) >= 4.0) {
  		POSX = (screen.availWidth-newx)/2;
    	POSY = (screen.availHeight-newy)/2;
 	} else {
  		POSX = 0;
  		POSY = 0;
  	}

	fstring ='toolbar=no,locationbar=no,directories=no,status=no,menubar=no,scrollbars=' + scrollflag + ',resizable='+res+',screenX='+POSX+',screenY='+POSY+',width='+newx + ',height='+newy;
	xwin = window.open(destination,windowname,fstring);

	if (navigator.appName != 'Netscape' && xwin != null ) {
   		xwin.focus();
   		xwin.moveTo((screen.availWidth-newx)/2,(screen.availHeight-newy)/2);
   		//xwin.resizeTo(newx,newy);
   	} else {
   		if (xwin)
   		  xwin.focus();
   	}

	if (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) >= 4.0 && parseInt(navigator.appVersion) < 5.0)
   		if (xwin)
   		  xwin.resizeTo(newx,newy);
	if (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) >= 5.0)
   		if (xwin)
   		  xwin.focus();
}

// --------------------------------------------------------------------------------------------------
// Function to open popup window for automatic generated pdf
function openPrintPDF(newurl)
{
  pdfwin = window.open(newurl,'pdfwin','toolbar=no,locationbar=no,directories=no,status=no,menubar=yes,scrollbars=auto,resizable=yes,width=600,height=400');
}


// --------------------------------------------------------------------------------------------------
// Function to open popup window for a enlarged view on an image

var xwin=null;

function showImage(imgName,newx,newy,ScreenX,ScreenY) {

 	picture = imgName.substring(0,imgName.length-6) + '_l.jpg'

	POSX = 400;
	POSY = 0;

	newx += 20;
	newy += 65;

	if (ScreenX == -1) {
  		if (parseInt(navigator.appVersion) >=4.0) {
    		POSX = (screen.availWidth-newx)/2;
    		POSY = (screen.availHeight-newy)/2;
    	} else {
    		POSX = 0;
    		POSY = 0;
    	}
	} else {
		if ((ScreenX != null) && (ScreenY != null)) {
			POSX = ScreenX;
			POSY = ScreenY;
		}
	}


  	if (xwin != null && navigator.appName !='Netscape') {
  		xwin.close();
  		xwin = null;
  	}

	if (xwin != null  && navigator.appName =='Netscape')
  		if (xwin.closed == false) {
      		xwin.location.href=picture;
      		xwin.resizeTo(newx,newy);
      		xwin.focus();
      		return;
     	}

	fstring ='toolbar=no,locationbar=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,screenX='+POSX +',screenY='+POSY +',width='+newx + ',height='+newy;

	xwin=window.open(picture,'projector',fstring);

	if (navigator.appName !='Netscape' && xwin != null ) {
   		xwin.moveTo(POSX,POSY);
   		xwin.resizeTo(newx,newy);
	} else {
		xwin.focus();
	}

	if (navigator.appName =='Netscape')
   		xwin.resizeTo(newx,newy);
    xwin.focus();
	return;
}

//-----------------------------------------------------------
// functions for servicelinks in upper left box

function productInquiry(targetURL, model) {
    document.location.href = targetURL + "?model=" + escape(model);
}

function getTestdrive() {
    obj=MM_findObj("testdriveform");
	if (obj) {
	  obj.submit();
	 }
}

function getBrochure() {
	obj=MM_findObj("brochureform");
	if (obj) {
	  obj.submit();
	}
}

function getRequest() {
	obj=MM_findObj("contactform");
	if (obj) {
	  obj.submit();
	}
}

// ----------------------------------------------------------
// Call Search for Rent- and Testdrive-Vehicles

function searchDRVehicles(type, model_id) {
    document.RentDemoForm.model_id.value = model_id;
    document.RentDemoForm.type.value = type;
    document.RentDemoForm.submit();
}

// ----------------------------------------------------------
// Open History PopUp

function openHistory() {
    void(window.open('/specials/company/history/index.html','History','width=790,height=500,left=0,top=0'));
}

// ----------------------------------------------------------
// Open FaqMC

function FaqMC(nr) {
	 openWindow('/service/motorraeder/'+nr+'.php','faqpopup',510,400,'yes');
}

// ----------------------------------------------------------
// Open FaqCAR

function FaqCAR(nr) {
	 openWindow('/service/automobile/'+nr+'.php','faqpopup',510,400,'yes');
}

// ----------------------------------------------------------
// Open Jobs PopUp

function openJobs() {
    void(window.open('/redirs/jobs.html','Jobs','width=810,height=500,left=0,top=0'));
}

// ----------------------------------------------------------
// Replace Location on Quickfinder change
var executedQuickfinder=false;
function execQuickfinder(dest) {
	executedQuickfinder=true;
    if ((dest != "") && (dest.indexOf("@@") == -1)) {
        document.location.href = dest;
    } else {
        UrlTargetPair = dest.split("@@");
        if (UrlTargetPair.length == 2) {
            if (UrlTargetPair[0] != "") {
                if (UrlTargetPair[1] == "_blank") {
                    window.open(UrlTargetPair[0]);
                } else {
                    document.location.href = UrlTargetPair[0];
                }
            }
        }
    }
}

// --------------------------------------------------------------------------------------------------
// Open Car Special "Civic 2004"

function startCivic2004(mypage,myname,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable';
	win = window.open(mypage,myname,settings);
	if (startCivic2004.opener == null) { // for Nav 2.0x
	   startCivic2004.opener = self; // this creates and sets a new property
	}
}

// --------------------------------------------------------------------------------------------------
// Open Window "Kraftstoffverbrauch und CO2-Emissionen"

function showEmissions(targeturl) {
	settings = (language_id!=5) ?'width=750,height=400,top=0,left=0,scrollbars=yes,resizable=yes':"";
	win = window.open(targeturl,'emissions',settings);
}

function autoShowEmissions(targeturl) {
	  s=document.URL.split("?");
	  sh=true;
	  if (s && document.referrer) {
	    d=s[0].split("/");
	    t=d[d.length-1];
	    sh=(!(document.referrer.indexOf(t)>0)) ;
	  }
    if (document.location.host != "honda.mit.de" && sh) { // wird nur gezeigt, wenn nicht innerhalb der seite gewechselt wurde
        showEmissions(targeturl);
    }
}





// ----------------------------------------------------------
// capture context menu and forget

 function contMen(E) { 	init();}

 document.oncontextmenu = contMen;


// --------------------------------------------------------------------------------------------------
// Open allgemeines, zentriertes Popup, z.B. KKonfigurator


function popup(URL,popupname,b,h,scrollbars) {
	var PopUpName = popupname || 'PopUp';
	var breite = b || 410;
	var hoehe = h || 450;
	var ScrollBars = scrollbars || 'auto';
	var xPos = (screen.availWidth - breite) / 2
	var yPos = (screen.availHeight - hoehe ) / 20
	window.open(URL,PopUpName,'width='+breite+',height='+hoehe+',scrollbars='+ScrollBars+',toolbar=no,location=no,menubar=no,screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos);
}

function popupScroll(URL,popupname,b,h,scrollbars) {
	var PopUpName = popupname || 'PopUp';
	var breite = b || 410;
	var hoehe = h || 450;
	var ScrollBars = scrollbars || 'yes';
	var xPos = (screen.availWidth - breite) / 2
	var yPos = (screen.availHeight - hoehe ) / 20
	window.open(URL,PopUpName,'width='+breite+',height='+hoehe+',scrollbars=no,toolbar=no,location=no,menubar=no,screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos);
}
