var Interface = {
	isFlash: false,
	orderSaveIsOk: false,
	html: [],
	isLoading: false,
	loadingClicked: false,
	flashCache: null,

	loading: function(off) {
		Interface.isLoading = true;
		var v = 'block';
		var v2 = 'hidden';
		var o = $('wall');
		if (off === true) {
			v = 'none';
			v2 = 'visible';
			Interface.isLoading = false;
		} else {
			var sizes = this.getScreenSizes();
			o.style.height = sizes.y +'px';
		}

		o.style.display = v;
		if ($('currencies_list')) $('currencies_list').style.visibility = v2;
		if ($('languages')) $('languages').style.visibility = v2;
		if ($('countries')) $('countries').style.visibility = v2;
	},

	translate: function(key, escape) {
		if (isset(mGLOBALS.translations_cc[key])) {
			if (isset(escape)) return mGLOBALS.translations_cc[key].replace('"', '&quot;');
			return mGLOBALS.translations_cc[key];
		}
		if (isset(mGLOBALS.translations_ot[key])) {
			if (isset(escape)) return mGLOBALS.translations_ot[key].replace('"', '&quot;');
			return mGLOBALS.translations_ot[key];
		}
		return 'no data';
	},

	loadInterface: function(obj) {
		this.html = [];
		if (obj.logo === true) Interface.showLogo();
		if (obj.title === true) Interface.showTitle();
		this.html.push('<td />');
		if (obj.countries === true && Configurator.fromVDI === false || !Configurator.isDealer) Interface.showCountries();
		if (obj.languages === true && Configurator.fromVDI === false) Interface.showLanguages();
		if (obj.alternative_languages === true && Configurator.fromVDI === false) Interface.showAlternativeLanguages();
		this.html.push('</tr>');
		if (obj.showSeparator) this.html.push('<tr><td class="separator" colspan="7"><br></td></tr>');
		this.html.push('</table>');
		if (obj.bigIntro) Interface.showIntro();
		if (obj.middleMenu) Interface.showMiddleMenu();
		if (obj.stepMenu) Interface.showStepMenu();
		$('header').innerHTML = this.html.join('');
		if (this.isFlash && Configurator.standartOptions !== null && Configurator.fromVDI === false) Interface.showFlash();

		if (obj.middleMenu) this.middleMenuOut(Car.modelID);

		this.html = [];
		if (obj.footer) Interface.showFooter();
		$('footer').innerHTML = this.html.join('');

		Configurator.regionID = 1;
		if (Configurator.marketID == '4') Configurator.regionID = 3;
		else if (Configurator.marketID == '5') Configurator.regionID = 2;
	},

	showLogo: function() {
		this.html.push('<table width="100%"><tr><td class="w100"><img src="/_/volvo.gif" alt="Volvo logo" onclick="location.href=\'/'+
			(Configurator.fromVDI === true ? '?p=ot&do=vcctool&lng=en&country=3#models' : '') +'\'" class="pointer" class="logo" /></td>');
	},

	showTitle: function() {
		this.html.push('<td><span class="big_title">'+Interface.translate('car_configurator')+'</span></td>');
	},

	showLanguages: function() {
		this.html.push('<td class="header_item" align="right">'+Interface.translate('language')+':</td>');

		var SO = mGLOBALS.markets.length;
		for (var i = 0; i < SO; ++i) {
			if(mGLOBALS.markets[i].id == Configurator.marketID) {
				var temp = mGLOBALS.markets[i].lng;
				break;
			}
		}

		this.html.push('<td class="header_item">');
		this.html.push('<select onchange="location.href=\'/?lng=\'+this.value+\'&country=\'+Configurator.marketID+\'&nostepchange=1\'" id="languages" style="visibility: hidden;">');
		SO = mGLOBALS['languages'].length;
		for (i = 0; i < SO; ++i) {
			if(mGLOBALS['languages'][i]['id'] == temp || mGLOBALS['languages'][i]['id'] == 'en' || mGLOBALS['languages'][i]['id'] == 'ru') {
				this.html.push('<option value="'+mGLOBALS['languages'][i]['id']+'"');
				if (Configurator.language == mGLOBALS['languages'][i]['id']) this.html.push(' selected="selected"');
				this.html.push('>'+mGLOBALS['languages'][i]['name']+'</option>');
			}
		}
		this.html.push('</select></td>');
	},

	showAlternativeLanguages: function() {
		this.html.push('<td class="header_item" align="right" style="border: 1px solid #e9e6e1;"><table><tr>');

		var SO = mGLOBALS.markets.length;
		for (var i = 0; i < SO; ++i) {
			if(mGLOBALS.markets[i].id == Configurator.marketID) {
				var temp = mGLOBALS.markets[i].lng;
				break;
			}
		}

		SO = mGLOBALS['languages'].length;
		for (i = 0; i < SO; ++i) {
			if(mGLOBALS['languages'][i]['id'] == temp || mGLOBALS['languages'][i]['id'] == 'en' || mGLOBALS['languages'][i]['id'] == 'ru') {
				this.html.push('<td style="padding-left: 20px;"><a href="" class="alt_lang_href" ');
				this.html.push('onclick="location.href=\'/?lng='+ mGLOBALS['languages'][i]['id'] +'&country=\'+Configurator.marketID; return false;">');
				this.html.push(mGLOBALS['languages'][i]['id'].toUpperCase() +'</a></td>');
			}
		}

		this.html.push('</tr></table></td>');
	},

	showCountries: function() {
		this.html.push('<td class="header_item" align="right">'+Interface.translate('country')+':</td>');
		this.html.push('<td class="header_item">');
		this.html.push('<select onchange="Interface.reloadMarket(this.value);" id="countries" style="visibility: hidden;">');

		var find = false;
		var SO = mGLOBALS.markets.length;
		for (var i = 0; i < SO; ++i) {
			if(Configurator.marketID == mGLOBALS.markets[i].id) {
				Configurator.marketName = mGLOBALS.markets[i].name;
				this.html.push('<option value="'+mGLOBALS.markets[i].id+'" selected="selected">'+mGLOBALS.markets[i].name+'</option>');
				find = true;
			} else this.html.push('<option value="'+mGLOBALS.markets[i].id+'">'+mGLOBALS.markets[i].name+'</option>');
		}
		if(!find) {
			Configurator.marketID = mGLOBALS.markets[0].id;
			Configurator.marketName = mGLOBALS.markets[0].name;
		}

		this.html.push('</select></td>');
	},

	showFooter: function() {
		this.html.push('<table class="footer"><tr><td class="separator"/></tr>');
		this.html.push('<tr><td><br><span class="small">'+Interface.translate('disc1_'+Configurator.market)+'</span><br /><br /></td></tr></table>');
	},

	reloadMarket: function(id) {
		var lng = 0;
		for(var i = 0; i < mGLOBALS.markets.length; i++) {
			if(mGLOBALS.markets[i]['id'] == id) {
				lng = mGLOBALS.markets[i]['lng'];
				break;
			}
		}
		if (!Configurator.isDealer) {
			location.href='/?p=ot&do=vcctool&lng=en&country=3&nostepchange=1&country='+id+'#dealers';
		}
		else location.href='/?lng='+lng+'&country='+id +'&nostepchange=1';
	},

	showMiddleMenu: function() {
		this.html.push('<table align="center" class="middle_menu"><tr>');
		var so = mGLOBALS.models.length;
		var width = 882/so;
		for (var i = 0; i < so; i++) {
			this.html.push('<td id="'+mGLOBALS.models[i].car_id+'" class="center" width="'+width+'" onmouseover="this.style.color=\'#000\'; this.style.background=\'url(/_/middle_menu/');
			if(i == 0) this.html.push('first.gif)');
			else if(i == (so-1)) this.html.push('last.gif) top right');
			else this.html.push('middle.gif)');

			this.html.push('\'" onmouseout="Interface.middleMenuOut(\''+mGLOBALS.models[i].car_id+'\')" ');
			this.html.push('onclick="Car.modelID = '+mGLOBALS.models[i].car_id+'; Configurator.currentStep = \'matrix\'; Configurator.ini();">'+mGLOBALS.models[i].text+'</td>');

			if(i < (so-1)) this.html.push('<td class="w1"><img src="/_/middle_menu/separator.gif" alt="" /></td>');
		}
		this.html.push('</tr></table>');
	},

	middleMenuOut: function(id) {
		if(id == Car.modelID) {
			if(id == mGLOBALS.models[0].car_id) $(id).style.background = 'url(/_/middle_menu/firstOn.gif)';
			else if(id == mGLOBALS.models[(mGLOBALS.models.length-1)].car_id) $(id).style.background = 'url(/_/middle_menu/lastOn.gif) top right';
			else $(id).style.background = 'url(/_/middle_menu/middleOn.gif)';
			$(id).style.color = '#fff';
		} else {
			$(id).style.background = '';
			$(id).style.color = '#000';
		}
	},

	showIntro: function() {
		if (this.isFlash && Configurator.standartOptions !== null && Configurator.fromVDI === false) {
			//$('flashCache').style.display = 'block';
			this.html.push('<div id="main_flash"></div>');
			//this.showFlash();
		}
		else {
			this.flashCache = false;
			$('flashCache').style.display = 'none';
			this.html.push('<img id="intro_pic" style="margin-top: 10px;" src="/_/headers/'+ Car.modelID +'.jpg" alt="" />');
		}
	},

	showStepMenu: function() {
		var so = Configurator.steps.length;
		for (var num = 0; num < so; num++) {
			if (Configurator.steps[num] == Configurator.currentStep) break;
		}
		this.html.push('<table class="step_menu w100p"><tr><td>');
		if (Configurator.isDealer && Configurator.fromVDI === true && num == 2) this.html.push('<img src="/_/step_left_inactive.gif" alt="previous" />');
		else this.html.push('<img src="/_/step_left_active.gif" alt="previous" class="pointer"  onclick="Interface.nextStep(true);"/>');
		this.html.push('</td><td><table><tr>');

		var params = color = '';
		var last = false;
		var number = 1;
		for (var i = 0; i < so; i++) {

			// do not show step with pdf download in menu
			if (Configurator.steps[i] == 'pdf') continue;

			params = '';
			color = 'grey';
			if ((Configurator[Configurator.steps[i]] || last == i || i < num) && !(Configurator.isDealer && Configurator.fromVDI === true && i == 1)) {
				params = ' onclick="Configurator.currentStep = \''+Configurator.steps[i]+'\'; Configurator.ini();" class="pointer"';
				color = 'blue';
				if (Configurator[Configurator.steps[i]]) {
					last = i;
					if (num > 3) last = i + 1;
				}
			}

			if (Configurator.currentStep == Configurator.steps[i])  {
				this.html.push('<td'+ params +'><table class="white_bold"><tr><td><img src="/_/submenu_left2.gif" alt="" /></td>');
				this.html.push('<td style="background: url(/_/submenu_middle2.gif) repeat-x">&nbsp;'+ number +'.&nbsp;'+ Interface.translate(Configurator.stepsTitles[i]) +'&nbsp;&nbsp;</td>');
				this.html.push('<td><img src="/_/submenu_right2.gif" alt="" /></td></tr></table></td>');
			} else {
				this.html.push('<td'+ params +'><table class="'+ color +'_bold"><tr><td class="w4">&nbsp;</td>');
				this.html.push('<td '+ (color == 'blue' ? ' onmouseover="this.style.color=\'#000\';" onmouseout="this.style.color=\'#4466ae\';"' : ''));
				this.html.push('>&nbsp;'+ number +'.&nbsp;'+ Interface.translate(Configurator.stepsTitles[i]) +'&nbsp;&nbsp;</td>');
				this.html.push('<td class="w4">&nbsp;</td></tr></table></td>');
			}
			if ((i + 1) < so) this.html.push('<td class="w10 center"><img src="/_/submenu_line2.gif" alt="" /></td>');
			number++;
		}
		this.html.push('</tr></table></td><td>');
		if (num > 6 || num < 4) this.html.push('<img src="/_/step_right_inactive.gif" alt="next" />');
		else this.html.push('<img src="/_/step_right_active.gif" alt="next" class="pointer"  onclick="Interface.nextStep();" />');
		this.html.push('</td></tr></table>');
	},

	showStepButtons: function(noSeparator) {
		var so = Configurator.steps.length;
		for (var i = 0; i < so; i++) {
			if (Configurator.steps[i] == Configurator.currentStep) break;
		}
		var html = [];
		html.push('<table class="w100p"><tr><td colspan="3">&nbsp;</td></tr>');
		if (!isset(noSeparator)) html.push('<tr><td class="separator_top" colspan="3">&nbsp;</td></tr><tr>');

		// so - 1 because 1 step must be invisible
		html.push('<td><div class="big_title2">'+Interface.translate('step')+' '+ (i < 1 ? 1 : i) +'/'+ (so - 1) +' - '+ Interface.translate(Configurator.stepsTitles[i]) +'</div></td>');



		/*
		 * Removed after redesign
		 *
		 *html.push('<td class="b_div" align="center"><div class="b_div">');
			html.push('<table id="previous" class="blue_bold">');
			html.push('<tr class="pointer" onclick="Interface.nextStep(true);">');
			html.push('<td class="w4"><img src="/_/previous_left.gif" alt="" /></td>');
			html.push('<td class="w140 pic_prev" nowrap="nowrap" align="center">'+Interface.translate('prev_step')+'</td>');
			html.push('<td class="w4"><img src="/_/previous_right.gif" alt="" /></td>');
			html.push('</tr></table>');
		html.push('</div></td>');

		html.push('<td class="b_div" align="center"><div class="b_div">');
			html.push('<table id="previous" class="blue_bold'+((i + 1) == so ? ' hidden' : '')+'">');
			html.push('<tr class="pointer" onclick="Interface.nextStep();">');
			html.push('<td class="w4"><img src="/_/previous_left.gif" alt="" /></td>');
			html.push('<td class="w140 pic_prev" nowrap="nowrap" align="center">'+Interface.translate('next_step')+'</td>');
			html.push('<td class="w4"><img src="/_/previous_right.gif" alt="" /></td>');
			html.push('</tr></table>');
		html.push('</div></td>');	*/
		html.push('</tr></table>');

		return html.join('');
	},

	showRightMenu: function() {

		var so = Configurator.steps.length;
		for (var i = 0; i < so; i++) {
			if (Configurator.steps[i] == Configurator.currentStep) break;
		}
		var html = [];
		html.push('<td class="w240 ptop" valign="top"><table class="w240">');

		// flash
		if (Configurator.interior !== null && Configurator.fromVDI === false && Car.modelID != 155) {
			if (Configurator.isDealer) {
				html.push('<tr class="h24"><td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_left.gif" alt="" /></td>');
				html.push('<td style="background-color: #8899ac;" nowrap="nowrap"><span class="white_bold">&nbsp;360Вє</span></td>');
				html.push('<td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_right.gif" alt="" /></td></tr>');

				html.push('<tr style="background-color: #fff" class="h21"><td />');
				html.push('<td>&nbsp;<a href="" class="href2 s11" onclick="Interface.isFlash = '+ (this.isFlash ? 'false' : 'true') +'; Configurator.ini(); return false;">');
				html.push((this.isFlash ? Interface.translate('hide')+'&nbsp;' : '') + Interface.translate('360_view') +'</a></td><td /></tr>');
			}
			html.push('<tr><td class="w4" style="background: url(/_/corner_left_bottom.gif) top left no-repeat">&nbsp;</td>');
			html.push('<td style="background: url(/_/middle_white.gif) top left repeat-x" align="center">&nbsp;</td>');
			html.push('<td class="w4" style="background: url(/_/corner_right_bottom.gif) top left no-repeat">&nbsp;</td></tr>');
			html.push('<tr><td colspan="3"/></tr>');
		}

		// financial information
		html.push('<tr class="h31">');
			html.push('<td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_left.gif" alt="" />');
			html.push('<div class="relative"><div class="message_box" id="message_box"><table><tr><td id="message_text"></td></tr></table></div></div></td>');
			html.push('<td style="background-color: #8899ac;" nowrap="nowrap"><table class="w100p"><tr><td class="white_bold">&nbsp;'+Interface.translate('finance_info')+'</td>');
			html.push('<td align="right">'+ this.currenciesIni() +'&nbsp;</td></tr></table></td>');
			html.push('<td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_right.gif" alt="" /></td>');
		html.push('</tr>');

		html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');
		html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
		html.push('<table class="w100p"><tr><td class="black_bold s11" colspan="2">&nbsp;'+Interface.translate('dealer') +'</td></tr></table>');
		html.push('</td><td style="background-color: #fff;"/></tr>');
		html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
		html.push('<div class="black p10 s11">');


		if (Configurator.outletID === null) html.push(Interface.translate('select_dealer'));
		else {
			html.push(Configurator.dealers.getName());
		}
		html.push('</div></td><td style="background-color: #fff;"/></tr>');

		html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');

		if (Configurator.matrix !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
			html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;Volvo '+ Configurator.models.getModelById() +'</td>');
			html.push('<td align="right" class="black_bold s11">'+ (Configurator.standartOptions !== null ? Price.getModelPrice(true) : '') +'&nbsp;</td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');
			if (Configurator.standartOptions !== null) {
				html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
				html.push('<div class="black p10 s11">');
				//html.push('<img src="/_/q_white.jpg" class="question" onmouseover="Interface.showHint(\'');
				//html.push('CO<sup>2</sup> '+ Configurator.matrix.getCO2()+', '+ Configurator.matrix.getFC() +'\', 5);"');
				//html.push(' onmouseout="Interface.hideHint();"/></td><td class="black s11">');
				html.push('<img src="/_/info_icon.gif" class="question" onmouseover="Interface.show(\'engine_preview\');" ');
				html.push('onmouseout="Interface.hide(\'engine_preview\')"/> <span>');
				html.push(Configurator.matrix.getEngineById());
				html.push('</span></div></td><td style="background-color: #fff;">');
				html.push('<div class="relative"><div class="message_box" id="engine_preview" style="left: -430px; top: -10px; z-index: 100;"><table><tr><td>');
				html.push('CO<sup>2</sup> '+ Configurator.matrix.getCO2()+', '+ Configurator.matrix.getFC() +'</td></tr></table></div></div>');
				html.push('</td></tr>');

				html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
				html.push('<div class="black p10 s11">');
				html.push(Configurator.matrix.getGearboxById());
				html.push('</div></td><td style="background-color: #fff;"/></tr>');

				html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
				html.push('<div class="black p10 s11">');
				html.push(Car.sv);
				html.push('</div></td><td style="background-color: #fff;"/></tr>');
			}
			html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');
		}

		/*if (Configurator.standartOptions !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 30px;">');
				html.push('<table class="w100p"><tr><td class="black">&nbsp;'+Interface.translate('msrp'));
				html.push('<img src="/_/info_icon.gif" class="question" onmouseover="Interface.showHint(\''+ Interface.translate('msrp_desc', 1) +'\', 5);"');
				html.push(' onmouseout="Interface.hideHint();"/></td>');
				html.push('<td class="black_bold" align="right">'+ Price.getPrice(Price.MSRP) +'&nbsp;</td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');
		}*/

		//if (Configurator.interior !== null) html.push('<tr style="background-color: #fff; height: 5px;"><td style="border-top: 1px solid #EAE7E2;" colspan="3"></td></tr>');
		if (Price.color !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
			html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;'+Interface.translate('color') +'</td>');
			html.push('<td class="black_bold s11" align="right"><nobr>'+ Price.getPrice(Price.color) +'&nbsp;</nobr></td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');

			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
			html.push('<div class="black p10 s11">');
			html.push('<img src="/_/info_icon.gif" class="question"');
			html.push(' onmouseover="Interface.show(\'color_preview\');" onmouseout="Interface.hide(\'color_preview\')"/>');
			html.push('<span class="pointer" onmouseover="Interface.show(\'color_preview\');" onmouseout="Interface.hide(\'color_preview\')"> '+ Car.colorData.text +'</span>');
			html.push('</div></td><td style="background-color: #fff;" valign="top"><div class="relative"><div class="box1pic" style="left: -345px;" id="color_preview">');
			html.push('<img src="'+ Car.colorData.pic +'" alt=""/></div></div></td></tr>');
		}
		if (Price.uphols !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
			html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;'+Interface.translate('uphols') +'</td>');
			html.push('<td class="black_bold s11" align="right"><nobr>'+ Price.getPrice(Price.uphols) +'&nbsp;</nobr></td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');

			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
			html.push('<div class="black p10 s11">');
			html.push('<img src="/_/info_icon.gif" class="question"');
			html.push(' onmouseover="Interface.show(\'uphols_preview\');" onmouseout="Interface.hide(\'uphols_preview\')"/>');
			html.push('<span onmouseover="Interface.show(\'uphols_preview\');" onmouseout="Interface.hide(\'uphols_preview\')" class="pointer"> '+ Car.upholsData.text +'</span>');
			html.push('</div></td><td style="background-color: #fff;" valign="top"><div class="relative"><div class="box3pic" style="left: -525px;" id="uphols_preview">');
			html.push('<img src="'+ Car.upholsData.pic +'" alt=""/></div></div></td></tr>');
		}
		if (Price.rims !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
			html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;'+Interface.translate('rims') +'</td>');
			html.push('<td class="black_bold s11" align="right" valign="top"><nobr>'+ Price.getPrice(Price.rims) +'&nbsp;</nobr></td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');

			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 14px;">');
			html.push('<div class="black p10 s11">');
			html.push('<img src="/_/info_icon.gif" class="question"');
			html.push(' onmouseover="Interface.show(\'rims_preview\');" onmouseout="Interface.hide(\'rims_preview\')"/>');
			html.push('<span onmouseover="Interface.show(\'rims_preview\');" onmouseout="Interface.hide(\'rims_preview\')" class="pointer"> '+ Car.rimsData.text +'</span>');
			html.push('</div></td><td style="background-color: #fff;" valign="top"><div class="relative"><div class="box2pic" style="left: -365px;" id="rims_preview">');
			html.push('<img src="'+ Car.rimsData.pic +'" alt=""/></div></div></td></tr>');
		}
		//alert(Car.options);
		if (Price.options !== null) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
			html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;'+Interface.translate('optional_equipment') +'</td>');
			html.push('<td class="black_bold s11" align="right" valign="top"><nobr id="rm_options"><span>'+ Price.getPrice(Price.options) +'</span>&nbsp;</nobr></td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');
		}
		html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');

		if (Configurator.matrix === null) {
			html.push('<tr><td class="w4" style="background: url(/_/corner_left_bottom.gif) top left no-repeat">&nbsp;</td>');
			html.push('<td style="background: url(/_/middle_white.gif) top left repeat-x" align="center">&nbsp;</td>');
			html.push('<td class="w4" style="background: url(/_/corner_right_bottom.gif) top left no-repeat">&nbsp;</td></tr>');
		} else {
			// dealer dropdown list
			if (Configurator.summary !== null && Configurator.fromVDI !== true) {
				html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
				html.push('<table class="w100p"><tr><td class="black_bold s11"><img src="/_/separator.gif" class="h1" style="width: 100%;"></td>');
				html.push('<td align="right" valign="top"></td></tr></table>');
				html.push('</td><td style="background-color: #fff;"/></tr>');
				html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');

				html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">');
				html.push('<table class="w100p"><tr><td class="black_bold s11">&nbsp;'+ Configurator.dealers.genSelect() +'</td>');
				html.push('<td align="right" valign="top"></td></tr></table>');
				html.push('</td><td style="background-color: #fff;"/></tr>');
				html.push('<tr style="height: 5px;"><td style="background-color: #fff;" colspan="3"/></tr>');
			}

			// retail price inc VAT
			html.push('<tr style="background-color: #F5F5F5;" class="h21"><td /><td class="black_bold"><table class="w100p"><tr><td class="black_bold s11">&nbsp;');
			html.push(Interface.translate('dealer_total')+'&nbsp;');
			html.push('<td align="right" class="black_bold s11" id="total_price">'+ (Configurator.standartOptions === null ? '' : Price.getTotalPrice()) +'&nbsp;</td>');
			html.push('</td></tr></table></td><td /></tr>');

			html.push('<tr><td class="w4" style="background: url(/_/corner_left_bottom2.gif) top left no-repeat">&nbsp;</td>');
			html.push('<td style="background: url(/_/middle_grey.gif) top left repeat-x" align="center">&nbsp;</td>');
			html.push('<td class="w4" style="background: url(/_/corner_right_bottom2.gif) top left no-repeat">&nbsp;</td></tr>');
		}

		if (Configurator.summary !== null) {
			//html.push('<tr style="background-color: #fff; height: 5px;"><td colspan="3"></td></tr>');
			//html.push('<tr style="background-color: #fff; height: 5px;"><td style="border-top: 1px solid #EAE7E2;" colspan="3"></td></tr>');

			if (Configurator.fromVDI === false) {
				//html.push('<tr style="background-color: #fff; height: 5px;"><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle;">&nbsp;');
				//html.push(this.genOutletsList() +'&nbsp;</td><td style="background-color: #fff;"/></tr>');

				if (Configurator.outletID !== null) {

					// print
					html.push('<tr style="background-color: #fff;" class="h21"><td /><td class="black_bold">&nbsp;<span class="pointer" ');
					html.push('onclick="Print.ini();">'+ Interface.translate('print')+'</span>&nbsp;');
					html.push('</td><td /></tr>');
					html.push('<tr style="height: 10px;"><td colspan="3"/></tr>');

//					html.push('<tr style="background-color: #fff;" class="h24"><td /><td>');
//					html.push('<table class="w100p"><tr><td>&nbsp;');
//					html.push(Interface.translate('handover_expenses')+'&nbsp;<img src="/_/info_icon.gif" class="question"');
//					html.push(' onmouseover="Interface.showHint(\''+ Interface.translate('handover_desc', 1) +'\', 120);" onmouseout="Interface.hideHint();"/>');
//					html.push('</td><td align="right" class="black_bold">'+ Price.getLocalExpenses() +'&nbsp;</td></tr></table>');
//					html.push('</td><td /></tr>');

//					html.push('<tr style="background-color: #F5F5F5;" class="h31"><td /><td class="black_bold"><table class="w100p"><tr><td class="black_bold">&nbsp;');
//					html.push(Interface.translate('dealer_total')+'&nbsp;<img src="/_/info_icon.gif" class="question"');
//					html.push(' onmouseover="Interface.showHint(\''+ Interface.translate('dealer_total_desc', 1) +'\', 160);" onmouseout="Interface.hideHint();"/>');
//					html.push('<td align="right" class="black_bold">'+ Price.getTotalPrice() +'</td>');
//					html.push('</td></tr></table></td><td /></tr>');
//
//					html.push('<td class="w4" style="background: url(/_/corner_left_bottom2.gif) top left no-repeat">&nbsp;</td>');
//					html.push('<td style="background: url(/_/middle_grey.gif) top left repeat-x" align="center">&nbsp;</td>');
//					html.push('<td class="w4" style="background: url(/_/corner_right_bottom2.gif) top left no-repeat">&nbsp;</td>');

					// personal information
					html.push('<tr class="h24"><td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_left.gif" alt="" /></td>');
					html.push('<td style="background-color: #8899ac;" nowrap="nowrap"><span class="white_bold">&nbsp;'+ Interface.translate('personal_info') +'</span></td>');
					html.push('<td class="w4" valign="top" style="background-color: #8899ac;"><img src="/_/rightmenu_right.gif" alt="" /></td></tr>');

					if (this.orderSaveIsOk === true) {
						html.push('<tr style="background-color: #fff" class="h21" id="order_ok"><td />');
						html.push('<td>&nbsp;<br><b>'+ Interface.translate('send_is_ok') +'</b></td><td /></tr>');
						this.orderSaveIsOk = false;
					}
					// inputs
					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td>&nbsp;<input class="text_input" type="text" value="'+ Interface.translate('name') +'" id="name" style="margin-top: 10px" ');
					html.push('onfocus="if(this.value==\''+ Interface.translate('name') +'\') this.value=\'\'; this.style.color = \'#000\'" ');
					html.push('onblur="if(this.value==\'\') this.value=\''+ Interface.translate('name') +'\';"');
					html.push('/></td><td /></tr>');

					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td>&nbsp;<input class="text_input" type="text" value="'+ Interface.translate('surname') +'" id="surname" ');
					html.push('onfocus="if(this.value==\''+ Interface.translate('surname') +'\') this.value=\'\'; this.style.color = \'#000\'" ');
					html.push('onblur="if(this.value==\'\') this.value=\''+ Interface.translate('surname') +'\';"');
					html.push('/></td><td /></tr>');

					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td>&nbsp;<input class="text_input" type="text" value="'+ Interface.translate('phone') +'" id="phone" ');
					html.push('onfocus="if(this.value==\''+ Interface.translate('phone') +'\') this.value=\'\'; this.style.color = \'#000\'" ');
					html.push('onblur="if(this.value==\'\') this.value=\''+ Interface.translate('phone') +'\';"');
					html.push('/></td><td /></tr>');

					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td>&nbsp;<input class="text_input" type="text" value="'+ Interface.translate('email') +'" id="email" ');
					html.push('onfocus="if(this.value==\''+ Interface.translate('email') +'\') this.value=\'\'; this.style.color = \'#000\'" ');
					html.push('onblur="if(this.value==\'\') this.value=\''+ Interface.translate('email') +'\';"');
					html.push('/></td><td /></tr>');

					// submit button & text
					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td><div style="margin: 10px 5px 10px 5px;">'+ Interface.translate('contact_text') +'</div></td><td /></tr>');
					html.push('<tr style="background-color: #fff" class="h21"><td />');
					html.push('<td><table><tr><td><input type="checkbox" id="personal_data"></td><td>&nbsp;<label for="personal_data" id="personal_data_text" style="cursor: pointer;">');
					html.push(Interface.translate('submit_protection')+'</label></td></tr></table></td><td /></tr>');

					html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 40px; padding-left: 23px;">');
						html.push('<table class="pointer"><tr><td class="w4 send_l h21">&nbsp;</td><td class="white_bold w165 send_m" align="center" onclick="Interface.getOrder();">');
						html.push(Interface.translate('send')+'</td><td class="w4 send_r h21">&nbsp;</td></tr></table>');
					html.push('</td><td style="background-color: #fff;"/></tr>');

					html.push('<tr><td class="w4" style="background: url(/_/corner_left_bottom.gif) top left no-repeat">&nbsp;</td>');
					html.push('<td style="background: url(/_/middle_white.gif) top left repeat-x" align="center">&nbsp;</td>');
					html.push('<td class="w4" style="background: url(/_/corner_right_bottom.gif) top left no-repeat">&nbsp;</td></tr>');
					html.push('<tr><td colspan="3"/></tr>');

					//data protection text
					html.push('<tr><td /><td style="font-size: 10px; padding: 10px;"><b>'+ Interface.translate('data_protection') +'</b><br>');
					html.push(Interface.translate('data_protection_text') +'</td><td /></tr>');
				}
			}
		}

		//if (Configurator.fromVDI === true && (i + 1) == so) {
		if (Configurator.fromVDI === true && i > 5 && (Configurator.completeOrder === true || Configurator.currentStep == 'summary')) {
			html.push('<tr><td style="background-color: #fff;"/><td style="background-color: #fff; vertical-align: middle; height: 40px;" align="center">');
				html.push('<table class="pointer"><tr><td class="w4 send_l h21">&nbsp;</td><td class="white_bold w165 send_m" align="center" onclick="Configurator.putCar();">');
				html.push(Interface.translate('complete')+'</td><td class="w4 send_r h21">&nbsp;</td></tr></table>');
			html.push('</td><td style="background-color: #fff;"/></tr>');
		}

		html.push('<tr class="h24">');
		html.push('</tr></table></td>')
		return html.join('');
	},

	getOrder: function() {
		$('name').style.color = $('surname').style.color = $('phone').style.color = $('email').style.color = $('personal_data_text').style.color = '#000';
		if ($('order_ok')) $('order_ok').style.display = 'none';
		var error = false;

		$('name').value = $('name').value.trim();
		if($('name').value.length < 2 || $('name').value == Interface.translate('name')) {
			$('name').style.color = 'red';
			error = true;
		}

		$('surname').value = $('surname').value.trim();
		if($('surname').value.length < 2 || $('surname').value == Interface.translate('surname')) {
			$('surname').style.color = 'red';
			error = true;
		}

		if($('phone').value.length < 7 || $('phone').value == Interface.translate('phone')) {
			$('phone').style.color = 'red';
			error = true;
		}

		if(!checkData($('email').value, 'email')) {
			$('email').style.color = 'red';
			error = true;
		}

		if (!$('personal_data').checked) {
			$('personal_data_text').style.color = 'red';
			error = true;
		}
		if(!error) {
			var options = [];
			var temp = [];
			var so = Car.options.length;
			var so2 = 0;
			for (var i = 0; i < so; i++) temp.push(Car.options[i].id);

			for (el in Configurator.options.ad_options) {
				so2 = Configurator.options.ad_options[el].length;
				for (i = 0; i < so2; i++) {
					if (in_array(Configurator.options.ad_options[el][i][1], temp)) options.push(Configurator.options.ad_options[el][i][1]);
				}
			}

			var params = [];

			params.push('market='+Configurator.marketID);
			params.push('region='+Configurator.regionID);
			params.push('sv='+Car.svID);
			params.push('gear='+Car.gearboxID);
			params.push('engine='+Car.engineID);
			params.push('car='+Car.modelID);
			params.push('mc='+Car.mc);
			params.push('roof=0');
			params.push('lng='+Configurator.language);
			params.push('DBnum='+ Configurator.DBnum);
			params.push('marketID='+Configurator.marketID);
			params.push('s_currency='+Price.defaultCurrency);
			params.push('color='+Car.colorID);
			params.push('uphols='+Car.upholsID);
			params.push('wheels='+Car.rimsID);
			params.push('dealer='+Configurator.dealerID);
			params.push('outlet='+Configurator.outletID);
			params.push('price='+Price.getTotalPrice(true));
			params.push('options='+options.join(','));
			params.push('name='+$('name').value);
			params.push('surname='+$('surname').value);
			params.push('phone='+$('phone').value);
			params.push('email='+$('email').value);

			this.orderSaveIsOk = true;

			ajax('/en/daction/save/', '', params.join('&'));


//			ajax('/en/daction/save/', 'Configurator.ini()', params.join('&'));
//			ajax('/en/daction/save/', 'Interface.test()', params.join('&'));
		}
	},

	test: function() {
		document.body.innerHTML = '<pre>'+ajaxReq.responseText;
	},

	nextStep: function(prev) {
		var so = Configurator.steps.length;
		for (var i = 0; i < so; i++) {
			if (Configurator.steps[i] == Configurator.currentStep) break;
		}
		Configurator.currentStep = (isset(prev) ? Configurator.steps[(i - 1)] : Configurator.steps[(i + 1)]);
		Configurator.ini();
	},

	genOutletsList: function() {
		var html = [];
		html.push('<select onChange="Interface.setOutlet(this.value); Configurator.ini();" style="width: 200px;">&nbsp;');
		var SO = mGLOBALS['dealers'].length;
		var SO2 = mGLOBALS['outlets'].length;
		var addr = '';

		html.push('<option value="0">'+ Interface.translate('select_dealer') +'</option>');
		for (var i = 0; i < SO; ++i) {
			if(mGLOBALS['dealers'][i]['id'] != 1 && mGLOBALS['dealers'][i]['id'] != 2 && Configurator.marketID == mGLOBALS['dealers'][i]['market_id']) {
				for (var n = 0; n < SO2; n++) {
					if(mGLOBALS['outlets'][n]['dealer_id'] == mGLOBALS['dealers'][i]['id'] && mGLOBALS['outlets'][n]['id'] != '34') {
						html.push('<option value="'+ mGLOBALS['outlets'][n]['id'] +'"');

						if (Configurator.outletID == mGLOBALS['outlets'][n]['id']) {
							html.push(' selected="selected"');
							if(Configurator.language == 'en') var addr_id = mGLOBALS['outlets'][n]['address_id'];
							else var addr_id = mGLOBALS['outlets'][n]['address_id_local'];
							var so = mGLOBALS['addr'].length;
							for (var g = 0; g < so; g++) {
								if (mGLOBALS['addr'][g]['id'] == addr_id) {
									addr = mGLOBALS['addr'][g]['street']+', '+mGLOBALS['addr'][g]['city']+', '+mGLOBALS['addr'][g]['postal_code']+', '+mGLOBALS['addr'][g]['country'];
									break;
								}
							}
						}

						html.push('>'+ mGLOBALS['outlets'][n]['name'] +'</option>');
					}
				}
			}
		}
		html.push('</select>');
		if (Configurator.outletID !== null) {
			html.push('<img id="dealer_info" onmouseover="Interface.showHint(\''+ addr +'\', 110);"');
			html.push(' onmouseout="Interface.hideHint();" src="/_/info_icon.gif" class="question"/>');
		}
		return html.join('');
	},

	setOutlet: function(v) {
		if (v == '0') {
			Configurator.dealerID = Configurator.outletID = null;
			return;
		}
		Configurator.outletID = v;

		var so = mGLOBALS['outlets'].length;
		for (var i = 0; i < so; ++i) {
			if(mGLOBALS['outlets'][i]['id'] == Configurator.outletID) {
				if(mGLOBALS['lang'] == 'en') var addr_id = mGLOBALS['outlets'][i]['address_id'];
				else var addr_id = mGLOBALS['outlets'][i]['address_id_local'];
				Configurator.dealerID = mGLOBALS['outlets'][i]['dealer_id'];
				break;
			}
		}

		// delivery
		Price.local_delivery = 0;
		so = mGLOBALS['dealers'].length;
		for(i = 0; i < so; i++) {
			if(mGLOBALS['dealers'][i]['id'] == Configurator.dealerID) {
				Price.local_delivery = parseInt(mGLOBALS['dealers'][i]['delivery'], 10);
				break;
			}
		}

		// other
		Price.other = 0;
		so = mGLOBALS['price_upgrades'].length;
		for(i = 0; i < so; i++) {
			if(mGLOBALS['price_upgrades'][i]['id'] == Configurator.dealerID) {
				if(mGLOBALS['price_upgrades'][i]['upgrade_id'] == 3) {
					Price.other = parseFloat(mGLOBALS['price_upgrades'][i]['price']);
					break;
				}
			}
		}
	},

	showFlash: function() {

		var o = $('main_flash');
		o.style.width = '900px';
		o.style.height = '373px';
		$('flashCache').style.display = 'block';
		if (this.flashCache === true) return;

		var ob = new SWFObject('/files/flash/host.swf', 'host', '900', '373', '8', '#FFFFFF');
		ob.addVariable('mt', Configurator.models.getModelById().toLowerCase());
		if(Car.colorID !== null) ob.addVariable('ct', Car.colorID);
		if(Car.rimsID !== null) ob.addVariable('rt', Car.rimsID);
		ob.addVariable('path', '/files/flash/cars/');
		ob.addVariable('styling', 'true');
		ob.addParam('wmode', 'transparent');
		ob.useExpressInstall('_js/expressinstall.swf');
		ob.write('flashCache');
		this.flashCache = true;
	},

	currenciesIni: function() {
		var html = [];
		html.push('<select onchange="Interface.changeCurrency(this.value); Configurator.ini();" id="currencies_list" style="visibility: hidden;"><option value="EUR">EUR</option>');
		var so = mGLOBALS.markets.length;
		for (var i = 0; i < so; ++i) {
			if(mGLOBALS.markets[i]['id'] == Configurator.marketID && mGLOBALS.markets[i].currency != '') {
				html.push('<option value="'+ mGLOBALS.markets[i].currency +'"');
				if (mGLOBALS.markets[i].currency == Price.defaultCurrency) html.push(' selected="selected"');
				html.push('>'+ mGLOBALS.markets[i].currency +'</option>');
				break;
			}
		}
		html.push('</select>');
		return html.join('');
	},

	changeCurrency: function(v) {
		if (isset(mGLOBALS.currencies[v])) {
			if (v != 'EUR') alert('Please note, that currency exchange rate is updated daily, according to exchange rate of National Bank, and is subject to change. EUR is the preveiling currency.');
			Price.defaultCurrency = v;
			Price.rate = parseFloat(mGLOBALS.currencies[v]);
		} else {
			Price.defaultCurrency = 'EUR';
			Price.rate = 1;
		}
	},

	showHint: function(v, y) {
		var o = $('message_box');
		o.style.top = y;
		$('message_text').innerHTML = v;
		o.style.display = 'block';
	},

	hideHint: function() {
		$('message_box').style.display = 'none';
	},

	show: function(id) {
		$(id).style.display = 'block';
	},

	hide: function(id) {
		$(id).style.display = 'none';
	},

	getScreenSizes: function() {
		var absolute_y = document.body.scrollHeight;
		var y = window.innerHeight ? window.innerHeight : (document.documentElement ? document.documentElement.clientHeight : document.body.clientHeight);
		var x = document.body.clientWidth;
		var scroll_top = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

		return {"x":x, "y":y, "absolute_y": absolute_y, "scroll_top": scroll_top};
	},

	alignAlertArea: function() {
		var sizes = this.getScreenSizes();
		if (!$('screen')) return;
		var o = $('screen');
		o.style.height = (sizes.y > sizes.absolute_y ? sizes.y : sizes.absolute_y) + 'px';
		o.style.width = sizes.x + 'px';

		if (!$('alert_box')) return;
		o = $('alert_box');
		o.style.top = ((sizes.y - 190)/2 + sizes.scroll_top) + 'px';
		o.style.left = (sizes.x - 480)/2 + 'px';
	},

	showAlertArea: function(hide) {
		var style = ['block', 'hidden'];
		if (isset(hide)) style = ['none', 'visible'];

		var o = $('currencies_list');
		if (o) o.style.visibility = style[1];

		o = $('dealers_list');
		if (o) o.style.visibility = style[1];

		this.alignAlertArea();
		o = $('screen');
		o.style.display = style[0];

		o = $('alert_box');
		o.style.display = style[0];
		if (isset(hide)) {
			o.className = 'screen_box';
			$('screen').removeChild($('is_rules_popup'));

		} else {
			if (!$('is_rules_popup')) {
				var DIV = document.createElement('DIV');
				DIV.id = 'is_rules_popup';
				DIV.style.display = 'none';
				//DIV.style.border = '1px solid red';
				//DIV.style.backgroundColor = 'red';
				//DIV.style.height = '100px';
				//DIV.style.width = '100px';
				$('screen').appendChild(DIV);
			}
			o.className = 'screen_box screen_box_is_visible';
		}
	},


	alert: function (text, confirm, new_id, old_id, rule) {

		this.showAlertArea();
		var o = $('alert_box');
		var html = [];
		html.push('<table width="100%" height="100%"><tr height="1%"><td>'+ text +'</td></tr>');
		html.push('<tr><td><br></td></tr><tr height="1%"><td align="right"><table><tr><td style="padding-right: 8px;">');

		if (confirm === true) {
			html.push('<table class="pointer w85"><tr><td class="w4 send_l h21">&nbsp;</td><td class="white_bold send_m" align="center" ');
			html.push('onclick="Interface.showAlertArea(1); ');
			switch(rule) {
				case 0:
					html.push('Rules.removeFromStack(\''+ new_id +'\');');
					html.push('Rules.addToStack(\''+ new_id +'\', false);');
					html.push('Rules.removeOption(\''+ new_id +'\');');
					break;
				case 1:
					html.push('Rules.removeFromStack(\''+ new_id +'\');');
					html.push('Rules.addToStack(\''+ new_id +'\', false);');
					html.push('Rules.removeOption(\''+ new_id +'\');');
					break;
				case 2:
					html.push('Rules.removeFromStack(\''+ new_id +'\');');
					html.push('Rules.addToStack(\''+ new_id +'\', false);');
					html.push('Rules.removeOption(\''+ new_id +'\');');
					break;
				case 3:
					html.push('Rules.addToStack(\''+ new_id +'\', true);');
					html.push('Rules.addOption(\''+ new_id +'\');');
					break;
			}
			html.push('Rules.followStack(); return false;">');
			html.push('Cancel</td><td class="w4 send_r h21">&nbsp;</td></tr></table></td><td>');
		}

		html.push('<table class="pointer w85"><tr><td class="w4 send_l h21">&nbsp;</td><td class="white_bold send_m" align="center" ');
		html.push('onclick="Interface.showAlertArea(1); ');
		if (confirm === true) {
			switch(rule) {
				case 0:
					html.push('Rules.addToStack(\''+ old_id +'\', false);');
					html.push('Rules.removeOption(\''+ old_id +'\');');
					break;
				case 1:
					html.push('Rules.addToStack(\''+ old_id +'\', true);');
					html.push('Rules.addOption(\''+ old_id +'\');');
					break;
				case 2:
					html.push('Rules.addToStack(\''+ old_id +'\', true);');
					html.push('Rules.addOption(\''+ old_id +'\');');
					break;
				case 3:
					html.push('Rules.addToStack(\''+ old_id +'\', false);');
					html.push('Rules.removeOption(\''+ old_id +'\');');
					break;
			}
		}
		html.push('Rules.followStack(); return true;" id="rules_ok">');
		html.push('Ok</td><td class="w4 send_r h21">&nbsp;</td></tr></table>');

		html.push('</td></tr></table></td></tr></table>');

		o.innerHTML = html.join('');
	},

	turnOffLoading: function() {
		Interface.loading(true);
	}
};

