 
/* ============================= *header ========================================= */



/* ---- /redirects to localized startpages ---- */

function faqActivate()
{
	var faqCount = document.getElementsByTagName('div');
	for (var i=0; i < faqCount.length; i++) 
	{
		if (faqCount[i].className == 'question')
			{
			document.getElementById(faqCount[i].getAttribute('id')).style.display = 'none';
			}
		if (faqCount[i].className == 'faq' || faqCount[i].className == 'faqSub') 
			{
			document.getElementById(faqCount[i].getAttribute('id')).onclick = function()
				{
				document.getElementById(this.getAttribute('id')+'Questions').style.display = 'block';
				closeFaq(this.getAttribute('id'));
				}
			}
	}
}

function closeFaq(test)
{
/*alert (test+"closeFaq");*/
	document.getElementById(test).onclick = function()
		{
		document.getElementById(test+'Questions').style.display = 'none';
		openFaq(test)
		}
}

function openFaq(test)
{
	/*alert (test+"openFaq");*/
	document.getElementById(test).onclick = function()
		{
		document.getElementById(test+'Questions').style.display = 'block';
		closeFaq(test)
		}
}

/* ---- /open sitemap link into the parent window ---- */
function openParentWindow(url)
{
	window.opener.location.href = url;
	window.opener.focus();
}

/*=============================================*/

function makeAnswerBox () {	
	/* MBL:9339: IE6 Hack for Info Icons */
	var parent = document.getElementsByTagName('div')[0];
	if (parent) {
		var firstDiv = document.createElement('div');
		document.getElementsByTagName('div')[0].appendChild(firstDiv);
		var secondDiv = document.createElement('div');
		firstDiv.appendChild(secondDiv);
		firstDiv.setAttribute('id', 'answer');
		secondDiv.setAttribute('id', 'answerBox');
	}
}

/*=============================================*/




function retrieveAnswers(whichAnswer, whichRequest, rightOfMagelan) {
	
	whichAnswer = whichAnswer + '&lang=' + language + '&javascript=true';
	

    if (window.XMLHttpRequest) { // Non-IE browsers
      request = new XMLHttpRequest();

      try {
        request.open("GET", whichAnswer, false);
        request.send(null);
        requestReceived(request, '', whichRequest, rightOfMagelan);
      } catch (e) {
      }

    } else if (window.ActiveXObject) { // IE

      request = new ActiveXObject("Microsoft.XMLHTTP");

      if (request) {
        request.open("GET", whichAnswer, false);
        request.send();
        requestReceived(request, question, whichRequest, rightOfMagelan);
		return false;
      }
    }
  }



  function requestReceived(request, question, whichRequest, rightOfMagelan) {
	
	
	
    if (request.readyState == 4) { // Complete
      if (request.status == 200) { // OK response
	
    	if (document.getElementById("helpAnswer")) {
          	document.getElementById("helpAnswerBox").innerHTML = request.responseText;
  			document.getElementById("helpAnswer").style.visibility = "visible";
  			document.getElementById("helpAnswerBox").style.visibility = "visible";
  			if (document.getElementById("csFaqHeadline")) {
  				document.getElementById("csFaqHeadline").style.color = "#888888";
  			}
  		}else if (document.getElementById("answer")) {
			document.getElementById('answer').style.visibility = 'hidden';
        	document.getElementById("answerBox").innerHTML = request.responseText;
			document.getElementById('answer').style.visibility = 'visible';
		}
		
		
		if (whichRequest != "helpRequest")
		{
			function findPos(obj, rightOfMagelan) 
			{
				var curleft = curtop = 0;
				if (obj.offsetParent) 
				{
					curleft = obj.offsetLeft;
					curtop = obj.offsetTop;
					while (obj = obj.offsetParent) 
					{
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
					}
				}
				if (rightOfMagelan == 1){
					curtop += 30;
				}
				return [curtop];
			}
			
	
			/* MBL:9339: IE6 Hack for Info Icons */
			var ieversion=new Number(RegExp.$1);
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) && ieversion<7)
			{
				document.getElementsByTagName('div')[0].style.position = 'relative';
				document.getElementById("answer").style.top = findPos(document.getElementById('question'), rightOfMagelan) + 'px';
				if (rightOfMagelan != 1){
					document.getElementById("answer").style.left = '0px';
				}
			}
			else 
			{
				document.getElementById("answer").style.top = findPos(document.getElementById('question'), rightOfMagelan) + 'px';
			}
			document.getElementById('question').setAttribute('id', '');
		}
		
		else if (whichRequest == "helpRequest")
		{

			document.getElementById("helpAnswerBox").style.top = document.documentElement.scrollTop + 20 + 'px';
			document.getElementById("helpAnswer").style.height =  document.documentElement.clientHeight + document.documentElement.scrollTop + 20 + 'px';
			document.getElementById('question').setAttribute('id', '');

		}


		document.getElementById('answerClose').onclick = function()
		{
			if (document.getElementById("answer")) {
				var stopTheShow = setTimeout("document.getElementById('answer').style.visibility = 'hidden';", 0);
			}
			if (document.getElementById("helpAnswer")) {
				document.getElementById("helpAnswer").style.visibility = "hidden";
				document.getElementById("helpAnswerBox").style.visibility = "hidden";
				if (document.getElementById("csFaqHeadline")) {
	  				document.getElementById("csFaqHeadline").style.color = "#FFFFFF";
	  			}
			}
			return false;
		}

		if (document.getElementById('submitClose')) {
			document.getElementById('submitClose').onclick = function() {
				if (document.getElementById("answer")) {
					var stopTheShow = setTimeout("document.getElementById('answer').style.visibility = 'hidden';", 0);
				}
				if (document.getElementById("helpAnswer")) {
					document.getElementById("helpAnswer").style.visibility = "hidden";
					document.getElementById("helpAnswerBox").style.visibility = "hidden";
				}
				return false;
			}
		}
		
      } 
    }
  }


function retrieveBundleInfo(whichAnswer) {

	whichAnswer = whichAnswer + '&javascript=true';


    if (window.XMLHttpRequest) { // Non-IE browsers

      request = new XMLHttpRequest();

      try {
        request.open("GET", whichAnswer, false);
        request.send(null);
        bundleInfoReceived(request);
      } catch (e) {
      }

    } else if (window.ActiveXObject) { // IE

      request = new ActiveXObject("Microsoft.XMLHTTP");

      if (request) {
        request.open("GET", whichAnswer, false);
        request.send();
        bundleInfoReceived(request, question);
		return false;
      }
    }
  }

  function bundleInfoReceived(request, question) {

    if (request.readyState == 4) { // Complete
      if (request.status == 200) { // OK response

        document.getElementById("bundleInfoBox").innerHTML = request.responseText;
		document.getElementById("overlay").style.visibility = "visible";
	    document.getElementById("overlay").style.height = "2000px";
		document.getElementById("bundleInfoBox").style.visibility = "visible";
		if (document.getElementById("sprache"))
		{
		document.getElementById("sprache").style.visibility = "hidden";
		}
		
		window.scrollTo(0, 0);
		checkLinks();

		document.getElementById('answerClose').onclick = function() {
			document.getElementById("bundleInfoBox").style.visibility = "hidden";
			document.getElementById("overlay").style.visibility = "hidden";
	        document.getElementById("overlay").style.height = "0";
			document.getElementById("sprache").style.visibility = "visible";
		}

		document.getElementById('submitClose').onclick = function() {
			document.getElementById("bundleInfoBox").style.visibility = "hidden";
			document.getElementById("overlay").style.visibility = "hidden";
	        document.getElementById("overlay").style.height = "0";
			document.getElementById("sprache").style.visibility = "visible";
		}
      } 
    }
  }
/*================================================*/

function closeTanRequest() {
    document.getElementById("bundleInfoBox").style.visibility = "hidden";
    document.getElementById("overlay").style.visibility = "hidden";
}

/* PROTOTYPE 1.5+ REQUIRED! */
function showComplainForm(obj) {
	document.domain = location.hostname.replace(/.*\.([^\.]*\.[^\.\d]*)$/, "$1");
    var url = obj.getAttribute('href') + '&javascript=true';

    var complainFrame = $('complainFrame');
    if (complainFrame) {
        complainFrame.setAttribute('src',url);
    }    

    window.scrollTo(0, 0);

    document.getElementById("bundleInfoBox").style.visibility = "visible";
    document.getElementById("overlay").style.visibility = "visible";
    document.getElementById("overlay").style.height = "2000px";

    document.getElementById("answerClose").onclick = function() {
        document.getElementById("bundleInfoBox").style.visibility = "hidden";
        document.getElementById("overlay").style.visibility = "hidden";
        document.getElementById("overlay").style.height = "0";
    }
    
    return false;
}


function closeComplain() {
    document.getElementById("bundleInfoBox").style.visibility = "hidden";
    document.getElementById("overlay").style.visibility = "hidden";

    var complainFrame = document.getElementById("complainFrame");
    if (complainFrame) {
        complainFrame.setAttribute('src','');
    }    
    
}
/*================================================*/




/* ----------- *Use for any Link with JS functionality ------------- */
function checkLinks() 
{
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) 
	{
		return false; 
	} 
	// create an array of objects of each link in the document 
	var links = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < links.length; i++) 
	{	

		//-----------------------------------------------------
		//*copy this section if you need a link with different 'behaviour' modify "helpPopup" to the desired class name and change the attributes to your need
		
		// if the link has a class of "...Popup"
		if (links[i].className == "helpPopup" || links[i].className == "helpPopup openWindow") 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 574, 380, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}
		//copy this section if you need a popup with different 'behaviour'	and paste below
		
		// another popup for preview images
		if (links[i].className.indexOf("previewImagePopup") > -1) 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 766, 820, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}

		// another popup for average price
		if (links[i].className.indexOf("averagePricePopup") > -1) 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 450, 380, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}
		
		// another popup for ad preview
		if (links[i].className.indexOf("previewPopup") > -1) 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 660, 400, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}
		// another popup for ad preview
		if (links[i].className.indexOf("eyeCatcherPopup") > -1) 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 720, 450, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}
		
		// popup for detail.html
		if (links[i].className.indexOf("detailPopup") > -1) 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			links[i].onclick = function() 
			{	
			openPopUp(this.getAttribute("href"), 840, 750, 50, 50, "no", "no", "no", "no", "yes", "yes");	
			return false; 	
			} 	
		}
		
		
		//-----------------------------------------------------
		
		if (links[i].className == "infoRequest") 
		{		
			setupInfoRequestLink(links[i]);
		}
		
		if (links[i].className == "infoRequestOnSES") 
		{		
			setupInfoRequestLink(links[i], 1);
		}
		
		function setupInfoRequestLink(link, rightOfMagelan) {
			link.onmouseover = function() 
			{
				var newId = this.setAttribute('id', 'question');
				retrieveAnswers(this.getAttribute("href"), '', rightOfMagelan);
				return false; 	
			}
			link.onmouseout = function() 
			{
				document.getElementById('answer').style.visibility = 'hidden';
				// MBL-7714
				//setTimeout("document.getElementById('answer').style.visibility = 'hidden'", 3000);
			}
			link.onclick = function() 
			{
				return false; 
			}			
		}
		
		if (links[i].className == "helpRequest") 
		{	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp
				
			links[i].onclick = function() 
			{
				var newId = this.setAttribute('id', 'question');
				retrieveAnswers(this.getAttribute("href"), "helpRequest");
				return false; 	
			}
		}
		
		if (links[i].className.indexOf("bundleInfoRequest") > -1) 
		{	
			links[i].onclick = function() 
			{
				var newId = this.setAttribute('id', 'question');
				retrieveBundleInfo(this.getAttribute("href"));
				return false; 	
			}
		}

        if (links[i].className.indexOf("complainRequest") > -1) 
        {   
            links[i].onclick = function() 
            {
                showComplainForm(this);
                return false;   
            }
        }
        if (links[i].className.indexOf("richMediaTooltip") > -1) 
        {
        	function tooltipPos(obj, which) 
			{
				var curleft = curtop = 0;
				if (obj.offsetParent) 
				{
					curleft = obj.offsetLeft;
					curtop = obj.offsetTop;
					while (obj = obj.offsetParent) 
					{
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
					}
				}
				if (which == "top"){
					return [curtop];
				}else if (which == "left"){
					curleft += 20;
					return [curleft];
				}
			}
        	
            links[i].onmouseover = function() 
            {
            	var newId = this.setAttribute('id', 'tooltip');
            	document.getElementById('rentInfoText').style.top = tooltipPos(document.getElementById('tooltip'), 'top') + 'px';
            	document.getElementById('rentInfoText').style.left = tooltipPos(document.getElementById('tooltip'), 'left') + 'px';
            	document.getElementById('rentInfoText').style.display="block";
            }
            links[i].onmouseout = function() 
            {
            	var newId = this.setAttribute('id', '');
            	document.getElementById('rentInfoText').style.display="none";
            }
        }
        
	}
	if (document.getElementById('closeTanRequest')) {
        document.getElementById('closeTanRequest').onclick = function() {
            document.getElementById("bundleInfoBox").style.visibility = "hidden";
            document.getElementById("overlay").style.visibility = "hidden";
            return false;
	   }
	} 
} 




function openPopUp(linkURL, width, height, left, top, toolbar, directories, status, menubar, scrollbars, resizable) 
{
	Window = window.open(linkURL,'popup','width='+width+',height='+height+',left='+left+',top='+top+',toolbar='+toolbar+',location='+location+',directories='+directories+',status='+status+',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable+'');
	Window.focus();
}
function openRecomendation(URL, width) {
kontakt = window.open (URL, "recomendation", "width="+ width +" ,height=700,top=0,left=0,resizable=yes,locationbar=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes");
}
/* ----------- /Use for any popup ------------- */

/* ----------- * check radio button for corresponding fieldset------------- */
function setRadioButton(layerIdentifier)
{
	document.getElementById(layerIdentifier).checked=true;
}
/* ----------- / check radio button for corresponding fieldset------------- */

/* ============================= /header ========================================= */

/* ========================== *unobtrusives ======================================= */


// moved into languageSwitch.js because of new prototype depended functionality
/*	function toggleLanguage()
	{
		if (document.getElementById('sprache')) {
			document.getElementById('sprache').onchange = function()
			{
				if (document.getElementById('sprache').value != '') {
					document.getElementById('toggleLanguageForm').submit();
				}
			}
		}
	}*/

function watchFieldsets()
{
	var radioControlLayer = document.getElementsByTagName('fieldset');
	for (var i=0; i < radioControlLayer.length; i++) 
	{
		if (radioControlLayer[i].className == 'controlLayer') 
			{
			document.getElementById(radioControlLayer[i].getAttribute('id')).onclick = function()
			{
			setRadioButton(this.getAttribute('id')+'Radio');
			}
		}
	}
}


// changes highlight for selected package in bundle selection

function bundleSelection() {
	var radios = document.getElementsByName('adPackageName');
	for (var i=0; i < radios.length; i++) {
		if (radios[i].checked) {
			var theBox = radios[i].parentNode.parentNode.parentNode.getElementsByTagName('div');
			for (var i=0; i < theBox.length; i++) {
				if (theBox[i].className.indexOf('teaserBoxContent') > 0) {
					theBox[i].style.border = 'solid #f60';
					theBox[i].style.borderWidth = '0 1px';
				} else if (theBox[i].className.indexOf('teaserBoxFooter') == 0) {
					theBox[i].className = 'teaserBoxFooterHighlight';
				}
			}
		} else {
			var theBox = radios[i].parentNode.parentNode.parentNode.getElementsByTagName('div');
			for (var i=0; i < theBox.length; i++) {
				if (theBox[i].className.indexOf('teaserBoxFooterHighlight') == 0) {
					theBox[i].className = 'teaserBoxFooter';
				}
			}
		}
	}
	

	
	for (var i=0; i < radios.length; i++) {
		radios[i].onclick = function() {
			var allRadios = document.getElementsByName('adPackageName');
			for (var i=0; i < allRadios.length; i++) {
				allRadios[i].parentNode.parentNode.style.border = 'solid #ccc';
				allRadios[i].parentNode.parentNode.style.borderWidth = '0 1px'
				allRadios[i].parentNode.parentNode.style.borderTop = '0';
				
				
			}
			var radios = document.getElementsByName('adPackageName');
			for (var i=0; i < radios.length; i++) {
				if (radios[i].checked) {
					var theBox = radios[i].parentNode.parentNode.parentNode.getElementsByTagName('div');
					for (var j=0; j < theBox.length; j++) {
						if (theBox[j].className.indexOf('teaserBoxContent') > 0) {
							theBox[j].style.border = 'solid #f60';
							theBox[j].style.borderWidth = '0 1px';
						} else if (theBox[j].className.indexOf('teaserBoxFooter') == 0) {
							theBox[j].className = 'teaserBoxFooterHighlight';
						}
					}
				} else {
					var theBox = radios[i].parentNode.parentNode.parentNode.getElementsByTagName('div');
					for (var j=0; j < theBox.length; j++) {
						if (theBox[j].className.indexOf('teaserBoxFooterHighlight') == 0) {
							theBox[j].className = 'teaserBoxFooter';
						}
					}
				}
			}	
			if ((this.value == 'PREMIUM') || (this.value == 'STANDARD') || (this.value='COMMERCIAL_STANDARD') || (this.value='COMMERCIAL_PREMIUM')) {
				var progress = document.getElementsByTagName('li');
				for (var i=0; i < progress.length; i++) {
					if (progress[i].id == 'pay') {
						progress[i].style.display = 'block';
					}
				}
				var progressLast = document.getElementsByTagName('li');
				for (var i=0; i < progressLast.length; i++) {
					if (progress[i].id == 'online') {
						progress[i].firstChild.innerHTML = '7';
					}
				}
			} else {
				var progress = document.getElementsByTagName('li');
				for (var i=0; i < progress.length; i++) {
					if (progress[i].id == 'pay') {
						progress[i].style.display = 'none';
					}
				}
				var progressLast = document.getElementsByTagName('li');
				for (var i=0; i < progressLast.length; i++) {
					if (progress[i].id == 'online') {
						progress[i].firstChild.innerHTML = '6';
					}
				}
			}
		}
	}
}


// count chars for the textarea on initial page load

function prepareCountWords() {
	var this_field = document.getElementById('vehicleDescr');
	
	if (this_field) {
		this_field.onkeyup = function() {
			CountWords();
			
		}
	}
}

// count chars for the textarea on key down

function CountWords () {
	
	var this_field = document.getElementById('vehicleDescr');
	
	if (this_field) {
		var char_count = document.getElementById('vehicleDescr').value.length;
		var fullStr = this_field.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");

		var displayCount = document.getElementById('wordCounter');
		
		if((2000 - char_count) <= 0) {
			char_count = 2000;
			var shortText = document.getElementById('vehicleDescr').value.substr(0, 2000);
			document.getElementById('vehicleDescr').value = shortText;
		}

		if(displayCount) {
			displayCount.firstChild.data = (2000 - char_count);
		}
 	}
}


// Opens the Online Assistent of Altplatform and jumps to Offer section

function OnlineAssistentOeffnen(bereich) {
 openOA(bereich);
 onlineAssistent.focus();
}

function openOA(pageUrl) {
 onlineAssistent = window.open(
 pageUrl, 'onlineAssistent',
 'width=574,height=380,left=50,top=50,toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes'
 );
 onlineAssistent.focus();
}

// Toggle for display< of old/new registration Documents

function regDoc() {
	var regDocNew = document.getElementById('regDocNew');
	var regDocOld = document.getElementById('regDocOld');
	var regDocNewLabel = document.getElementById('regDocNewLabel');
	var regDocOldLabel = document.getElementById('regDocOldLabel');
	if(regDocNew) {
		regDocNew.style.display = 'none';
		regDocNewLabel.style.display = 'block';
	}
	if (regDocNewLabel) {
		regDocNewLabel.onclick = function () {
			regDocNew.style.display = 'block';
			regDocOld.style.display = 'none';
			regDocOldLabel.style.display = 'block';
			regDocNewLabel.style.display = 'none';
		}
	}
	if (regDocOldLabel) {
		regDocOldLabel.onclick = function () {
			regDocNew.style.display = 'none';
			regDocOld.style.display = 'block';
			regDocOldLabel.style.display = 'none';
			regDocNewLabel.style.display = 'block';
		}
	}
}


/*	change country code when country is changed	*/
function countrySelection() {
	var countrySelector = document.getElementById('countrySelect');
	var codeSelector = document.getElementById('primaryNumberCountryId');
	if (countrySelector) {
		countrySelector.onchange = function() {
			codeSelector.selectedIndex = countrySelector.selectedIndex + 1;
		}
	}
}

/*	change country code when country is changed	*/
function countrySelectionByIds(countrySelector, phone, phone2, fax, mobile) {
	
	var phoneSelection = document.getElementById(phone);
	var phone2Selection = document.getElementById(phone2);
	var faxSelection = document.getElementById(fax);
	var mobileSelection = document.getElementById(mobile);
	if (countrySelector) {
		if(phoneSelection){
			phoneSelection.selectedIndex = countrySelector.selectedIndex;
		}
		if(phone2Selection){
			phone2Selection.selectedIndex = countrySelector.selectedIndex;
		}
		if(faxSelection){
			faxSelection.selectedIndex = countrySelector.selectedIndex;
		}
		if(mobileSelection){
			mobileSelection.selectedIndex = countrySelector.selectedIndex;
		}
	}
}

/*	add functions to call onload	*/
function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener)
	{
		obj.addEventListener(evType, fn, false); 
		return true; 
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else
	{
		return false; 
	} 
}

function activationToggle() {
	var links = document.getElementsByTagName('a');
	for (var i=0; i < links.length; i++) {
		if(links[i].className.indexOf('activationToggle') > -1) {
			links[i].onclick = function() {
				for (var i=0; i < links.length; i++) {
					if(links[i].className.indexOf('activationToggle') > -1) {
						this.style.color = '#999';
						links[i].onclick = function() {
							for (var i=0; i < links.length; i++) {
								if(links[i].className.indexOf('activationToggle') > -1) {
									links[i].href= '';
								}
							}
							return false;
						}
					}
				}
			}
		}
	}
}



//moved into languageSwitch.js because of new prototype depended functionality
//addEvent(window, 'load', toggleLanguage);

addEvent(window, 'load', regDoc);
addEvent(window, 'load', countrySelection);

addEvent(window, 'load', checkLinks);
addEvent(window, 'load', watchFieldsets);
addEvent(window, 'load', faqActivate);

addEvent(window, 'load', activationToggle);

addEvent(window, 'load', CountWords);
addEvent(window, 'load', prepareCountWords);

addEvent(window, 'load', bundleSelection);
addEvent(window, 'load', makeAnswerBox);

addEvent(window, 'load', makeLinkOnStartInsertion);

// addEvent(window, 'load', DHTML_init);
// addEvent(window, 'load', Event_init);

function showHideSimple(id) {

	if (document.getElementById) {
		if (document.getElementById(id).style.display=="none"){
			document.getElementById(id).style.display="block";
		}
		else{
			document.getElementById(id).style.display="none";
		}
	} 
	else {
		if (document.all) {
			if (document.all[id].style.display=="none"){
				document.all[id].style.display="block";
				}
			else {
			document.all[id].style.display="none";
			}  
		}
		if (document.layers) {
			if (document.layers[id].display=="none"){
				document.layers[id].display="block";
			}
			else{
			document.layers[id].display="none";
			}
		}
	}
} 





//toggles display attribute of block level elements

function showSimple(id) {
	var visible=false;

	if (document.getElementById) {
		document.getElementById(id).style.display="block";
		visible=true;
	} 
	else {
		if (document.all) {
			document.all[id].style.display="block";
			visible=true;
		}
		if (document.layers) {
			document.layers[id].display="block";
			visible=true;
		}
	}
	return visible;
} 

function showLayer (value, layer) {
	document.getElementById(layer).style.visibility = value;
}

function hideSimple(id) {

	if (document.getElementById) {
		document.getElementById(id).style.display="none";
	} 
	else {  
		if (document.all) {
			document.all[id].style.display="none";
		}
		if (document.layers) {
			document.layers[id].display="none";
		}
	}
	
} 

function checkVisible(id) {
		if (visible=false) {
		document.write("<div id='"+id+"' class='hiddenBox'>");
		}

	}


//synchronisizes formfields
function getInput(formName,fieldFrom,fieldTo1,fieldTo2){
	input  = document.forms[formName].elements[fieldFrom].value;
	if (document.registration.elements[fieldTo1].value < 1){
		document.registration.elements[fieldTo1].value = input;
	}
	if (document.registration.elements[fieldTo2].value < 1){
		document.registration.elements[fieldTo2].value = input;
	}

}

//--------------------------------------------
// envKV for fsbo on oeb/gb
function fuelEnvKV (value, disabled, ca) {
	document.getElementById("specifics.envkv.consumptionInner").className = value;
	document.getElementById("specifics.envkv.consumptionOuter").className = value;
	document.getElementById("specifics.envkv.consumptionCombined").className = value;
	document.getElementById("specifics.envkv.carbonDioxydEmission").className = value;

	document.getElementsByName("specifics.envkv.consumptionInner")[0].disabled = disabled;
	document.getElementsByName("specifics.envkv.consumptionOuter")[0].disabled = disabled;
	document.getElementsByName("specifics.envkv.consumptionCombined")[0].disabled = disabled;
	document.getElementsByName("specifics.envkv.carbonDioxydEmission")[0].disabled = disabled;
	
	if (disabled == true){
		  document.getElementsByName("specifics.envkv.consumptionInner")[0].value = '';
		  document.getElementsByName("specifics.envkv.consumptionOuter")[0].value = '';
		  document.getElementsByName("specifics.envkv.consumptionCombined")[0].value = '';
		  document.getElementsByName("specifics.envkv.carbonDioxydEmission")[0].value = '';
	}
}

//-------------------------------------------------
//  inseration process : fuelfeatures
function fuel_additional_features(selectbox, type) {
	if (type == "car" || type == "") {					
		if (selectbox.value == "PETROL" || selectbox.value == "HYBRID" ) {
			document.getElementById("E10_ENABLED").className = "visibleBox";
		} else {
			document.getElementById("E10_ENABLED").className = "hiddenBox";
			document.getElementById("CHECKBOX_E10_ENABLED").checked = false;
		}
	} 
	
	if (type == "car" || type == "") {
		if (selectbox.value == "DIESEL") {
			document.getElementById("BIODIESEL_SUITABLE").className = "visibleBox";
		} else {
			document.getElementById("BIODIESEL_SUITABLE").className = "hiddenBox";
			document.getElementById("CHECKBOX_BIODIESEL_SUITABLE").checked = false;
		}
	}

	if (type == "car" || type == "") {
		if (selectbox.value == "DIESEL") {
			document.getElementById("VEGETABLEOILFUEL_SUITABLE").className = "visibleBox";
		} else {
			document.getElementById("VEGETABLEOILFUEL_SUITABLE").className = "hiddenBox";
			document.getElementById("CHECKBOX_VEGETABLEOILFUEL_SUITABLE").checked = false;
		}
	}
	
	if (type == "car" || type == "") {
		var hidSpecEnvkvComp= $("specifics.envkv.compliant");
		if (selectbox.value == "ELECTRICITY") {
			fuelEnvKV('',true,1);
			if (hidSpecEnvkvComp != null) {
				hidSpecEnvkvComp.value="false";
		 	}
		 	if ($("notSpecified") != null) {
		 		$("notSpecified").click();
		 	}
		} else {
			if (hidSpecEnvkvComp != null) {
				hidSpecEnvkvComp.value="true";
		 	 	if (hidSpecEnvkvComp.length > 0) {
		 	 		if (hidSpecEnvkvComp[0].type != 'radio') {
		 	 			fuelEnvKV('important', false, 2);
		 	 	    }
		 	 	}
			}
		}
	}

	if (type == "vanUpTo7500" || type == "motorhome") {		
		if (selectbox.value == "PETROL" || selectbox.value == "HYBRID" ) {
			document.getElementById("E10").className = "visibleBox";
		} else {
			document.getElementById("E10").className = "hiddenBox";
			document.getElementById("CHECKBOX_E10").checked = false;
		}
	}

	if (type == "motorhome" || type == "vanUpTo7500" || type == "semiTrailerTruck") {
		if (selectbox.value == "DIESEL") {
			document.getElementById("BIODIESEL_CONVERSION").className = "visibleBox";
		} else {
			document.getElementById("BIODIESEL_CONVERSION").className = "hiddenBox";
			document.getElementById("CHECKBOX_BIODIESEL_CONVERSION").checked = false;
		}
	}

	if (type == "semiTrailerTruck") {
		if (selectbox.value == "DIESEL") {
			document.getElementById("VEGETABLEOILFUEL_CONVERSION").className = "visibleBox";
		} else {
			document.getElementById("VEGETABLEOILFUEL_CONVERSION").className = "hiddenBox";
			document.getElementById("CHECKBOX_VEGETABLEOILFUEL_CONVERSION").checked = false;
		}
	}

	if (type == "semiTrailerTruck") {
		if (selectbox.value == "DIESEL") {
			document.getElementById("UREA_TANK_AD_BLUE").className = "visibleBox";
		} else {
			document.getElementById("UREA_TANK_AD_BLUE").className = "hiddenBox";
			document.getElementById("CHECKBOX_UREA_TANK_AD_BLUE").checked = false;
		}
	}
}


//-------------------------------------------------
//legacy dealer registraition field manipulators

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x && d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

//synchronisizes formfields
function getInput(formName,fieldFrom,fieldTo1,fieldTo2){
	var input  = document.forms[formName].elements[fieldFrom].value;
	document.registration.elements[fieldTo1].value = input;
	document.registration.elements[fieldTo2].value = input;

}

function getInputDropDown(formName,fieldFrom,fieldTo1) {
	var fieldFrom = document.forms[formName].elements[fieldFrom];
    var fieldTo1 = document.forms.registration.elements[fieldTo1];
    var fieldTo2 = document.forms.registration.elements[fieldTo2];
    var fieldTo3 = document.forms.registration.elements[fieldTo3];
	var selIndex = fieldFrom.selectedIndex;
    var selText = fieldFrom.options[selIndex].text
  

	for (i=0;i<fieldTo1.options.length;i++){
			alert (fieldTo1.options[i].text);
		
		/**if (fieldTo1.options[i].text.indexOf(selText)){
			fieldTo1.options[i] = selIndex;
			alert (fieldTo1.options[i].text);
		}	**/	
	}
	
}



// probably obsolete... (legacy)
function europa(){
        var country = getCountry();
        var Bez = new Array('USTID');
        var Bezeichner = new Array();
        for (var i=0;i<Bez.length;i++) {
                        Bezeichner.push(getElem("id",Bez[i],null));
                }
        if (country == "B" || country == "DK" || country == "D" || country == "EST" ||
                        country == "FIN" ||        country == "F" || country == "GR" || country == "GB" ||
                        country == "IRL" || country == "I" ||country == "LV" ||        country == "LT" || 
                        country == "L" || country == "MT" || country == "NL" || country == "A" || 
                        country == "PL" || country == "P" || country == "SE" || country == "SK" ||
                        country == "SI" || country == "E" || country == "CZ" || country == "H" || 
                        country == "CY" ) {
                        bezeichnerFarbe="#ff6600";
                } else {
                        bezeichnerFarbe="#333333";
                }
        for (var i=0;i<Bezeichner.length;i++) {
                        Bezeichner[i].style.color=bezeichnerFarbe;
                }

}
        
function deutschland(){
        var country = getCountry();
        var Bez1 = new Array('HaReg','HaRegNr','taxNo', 'oder');
        var Bezeichner1 = new Array();
        for (var i=0;i<Bez1.length;i++) {
                        Bezeichner1.push(getElem("id",Bez1[i],null));
                }
        if (country == "D")     {
                        bezeichnerFarbe="#ff6600";
                } else{
                        bezeichnerFarbe="#333333";
                }
        for (var i=0;i<Bezeichner1.length;i++) {
                        Bezeichner1[i].style.color=bezeichnerFarbe;
                }
}

function setCombined(field,wert,a,b){
        var Bez = new Array(a,b);
    var Bezeichner = new Array();
        for (var i=0;i<Bez.length;i++){
        Bezeichner.push(getElem("id",Bez[i],null));
        }
        if(field.checked == wert) { 
                bezeichnerFarbe="#333333";
        } else {
                bezeichnerFarbe="#ff6600";
    }
    for (var i=0;i<Bezeichner.length;i++) {
                Bezeichner[i].style.color=bezeichnerFarbe;
        }
}

function legal(field){
        var Bez1 = new Array('andereFeld');
        var Bezeichner1 = new Array();
        for (var i=0;i<Bez1.length;i++){
                Bezeichner1.push(getElem("id",Bez1[i],null));
                }
        if (field.options[field.options.selectedIndex].value == "7")
                {
                bezeichnerFarbe="#ff6600";
                }
                else{
                bezeichnerFarbe="#333333";
                }
        for (var i=0;i<Bezeichner1.length;i++){
                Bezeichner1[i].style.color=bezeichnerFarbe;
                }

}

//----------------------- common --------------------------
// used by vehiclecomparison and parking list
// REVISTI: this code is dublicated in mobileSearch.js !!!!!
function checkBoxes (form, check) {
	for (var c = 0; c < form.elements.length; c++) {
		if (form.elements[c].type == 'checkbox') {
	    	form.elements[c].checked = check;
	    }
	}
}

//----------------------- parking --------------------------

function sendRating(parkingId, rating) {
	if (typeof ratings[parkingId] !='undefined'  && rating == ratings[parkingId]['rating']) {
	 	if(rating == 'BEST') rating = 'BETTER';
	 	else if(rating == 'BETTER') rating = 'GOOD';
	 	else if(rating == 'GOOD') rating = 'NONE';
	 }
	document.forms['parkingManager'].elements['parkingIdToRate'].value = parkingId;
	document.forms['parkingManager'].elements['rating'].value = rating;
	document.forms['parkingManager'].submit();
}
function turnON(id) {
	button = document.getElementById(id);
	replacement = button.src.replace(/Grey/g, '');
	button.src = replacement;
}
function turnOFF(id) {
	button = document.getElementById(id);
	if(!button.src.match(/Grey\.gif/g)) {
		replacement = button.src.replace(/\.gif/g, 'Grey.gif');
		button.src = replacement;
	}
}
function changeLighting(parkingId, rating, lighting) {
	rating = rating.toLowerCase();
	var ratingMap = new Array();
	var reverseMap = new Array();
	ratingMap['good'] = 0;
	ratingMap['better'] = 1;
	ratingMap['best'] = 2;
	reverseMap['ON']="OFF";
	reverseMap['OFF']="ON";
	
	var code = '';
	for (var key in ratingMap) {
		if (ratingMap[key] <= ratingMap[rating])
			code += 'turn'+lighting.toUpperCase()+'("'+parkingId+'_'+key+'");';
		else
			code += 'turn'+reverseMap[lighting.toUpperCase()]+'("'+parkingId+'_'+key+'");';
	}
	eval(code);
}
function resetToCurrent(parkingId, rating) {
	eval("changeLighting("+parkingId+",'"+rating+"','ON')");
}


function makeLinkOnStartInsertion()
{
	if (document.getElementById("linkListInsertionStart")) 
	{
		var targetUl = document.getElementById("linkListInsertionStart");
		var firstLi = document.createElement('li');
		targetUl.insertBefore(firstLi, (document.getElementById("linkListInsertionStart").firstChild));
		targetUl.firstChild.innerHTML = innerHtml;

	}	
}

			



/* ========================== /unobtrusives ======================================= */

function browserAcceptsCookies(){
	var acceptsCookies = false;
	if ( document.cookie == '' ) {
		document.cookie = 'acceptsCookies=yes'; // Try to set a cookie.
	    if ( document.cookie.indexOf( 'acceptsCookies=yes' ) != -1 ) {
			acceptsCookies = true;
	    }
	} else { // there was already a cookie
	  acceptsCookies = true;
	}
	return ( acceptsCookies );
}


