﻿
var InitialLoad=true;var CurrentCar='';var JustHiddenRATDLightBox=false;var RadioButtonsUsed=false;$(document).ready(function(){BuildMOIControl();$('div.RATDnotAvailablePopup').hide();$('ul.ul_main').bind('clickoutside',function(event){HideDropdownIfVisible();});$('div.ManualUnselectionLightBox').hide();$('div.ManualUnselectionLightBox div.lightBoxInner a.button').click(function(){HideFormManualUnselectionLightBoxClick();});$('div.DisabledRATDLightBox').hide();$('div.DisabledRATDLightBox div.lightBoxInner a.button').click(function(){HideFormDisabledRATDLightBoxClick();});$('select.MOIDDL').hide();$('a.arrow_down').click(ExpandDropdown);$('a.arrow_up').click(HideDropdown);SetupCheckboxesEventHandler();$('span.chkBrochure').click(function(){chkClick()});$('span.chkSignUp').click(function(){chkClick()});$('span.chkTestDrive').click(function(){chkClick()});$('div.btnNext input').click(function(){ButtonNextEventHandler();return false;});$('span.chkBrochure').mouseenter(function(){chkRolloverAdd($(this));});$('span.chkBrochure').mouseleave(function(){chkRolloverRemove($(this));});$('span.chkSignUp').mouseenter(function(){chkRolloverAdd($(this));});$('span.chkSignUp').mouseleave(function(){chkRolloverRemove($(this));});$('span.chkTestDrive').mouseenter(function(){chkRolloverAdd($(this));});$('span.chkTestDrive').mouseleave(function(){chkRolloverRemove($(this));});CurrentCar=PreselectedMOI;if(IsNullOrEmpty(PreselectedMOI)){LoadCarLabels('fx');HideFormManual();DisplayHideNextBtn();}
else{var carText=$('select.MOIDDL option[value='+PreselectedMOI+']').html();$('a.currentCar').html(carText);LoadCarLabels(PreselectedMOI);$('.mainArea').show();$('.formBox').show();SetupCheckboxesEventHandler();}
InitialLoad=false;if(IsPNGFixLoaded()){DD_belatedPNG.fix('div.innerMOI, div.topDiv, div.mainAreaTop, div.btnNext, div.btnNext input, div.mainArea, div.mainAreaInner, div.bottomSlice, ul.ul_main, li.li_top, div.lightBox, div.lightBoxInner, div.lightBoxBottom');}
MoveChkEmailErrorIcon();CrushBoxes();});function chkClick(){ToggleDisclaimer();DisplayHideNextBtn();SetupCheckboxesEventHandler()}
function MoveChkEmailErrorIcon(){var div=$('div.EmailOptIn');if(div.length==1){var img=div.parent().siblings('img.error_img');if(img.length==1){img.appendTo(div);}}}
function chkRolloverAdd(span){var div=span.parent();div.addClass('tickRequest');if(IsPNGFixLoaded()){div.css('background-image','');div.css('background-repeat','');var e=div.get(0);DD_belatedPNG.fixPng(e);}}
function chkRolloverRemove(span){var div=span.parent();div.removeClass('tickRequest');if(IsPNGFixLoaded()){div.css('background-image','none');div.css('background-repeat','no-repeat');var e=div.get(0);DD_belatedPNG.fixPng(e);}}
function DisplayHideNextBtn(){if(!IsNullOrEmpty(CurrentCar)&&($('span.chkTestDrive input[type=checkbox]').attr('checked')==true||$('span.chkBrochure input[type=checkbox]').attr('checked')==true||$('span.chkSignUp input[type=checkbox]').attr('checked')==true)){if($('div.mainArea').is(':hidden'))
$('.btnNext').fadeIn('fast');}
else
$('.btnNext').fadeOut('fast');}
function IsChkBruchureTicked(){return $('span.chkBrochure > input').is(':checked');}
function IsChkSignUpTicked(){return $('span.chkSignUp > input').is(':checked');}
function IsChkTestDriveTicked(){return $('span.chkTestDrive > input').is(':checked');}
function GetMandatoryCSSClasses(){var mandatoryCSS=new Array();if(IsChkBruchureTicked()){mandatoryCSS.push('MandatoryForBrochure');}
if(IsChkSignUpTicked()){mandatoryCSS.push('MandatoryForNewsletter');}
if(IsChkTestDriveTicked()){mandatoryCSS.push('MandatoryForTestDrive');}
return mandatoryCSS;}
function GetVisibleCSSClasses(){var visibleCSS=new Array();if(IsChkBruchureTicked()){visibleCSS.push('VisibleForBrochure');}
if(IsChkSignUpTicked()){visibleCSS.push('VisibleForNewsletter');}
if(IsChkTestDriveTicked()){visibleCSS.push('VisibleForTestDrive');}
return visibleCSS;}
function DisplayForm(){if(InitialLoad){$('div.btnNext:visible').hide();}
else{$('div.btnNext:visible').fadeOut('fast',function(){$('div.mainArea:hidden').slideDown('fast');$('div.formBox').animate({'margin-top':divFormBoxMarginTop_TopPosition},'fast');});}
Set_Mandatory_Fields(GetMandatoryCSSClasses());Set_Form_Fields_Visibility(GetVisibleCSSClasses());ApplyTipsInfo();}
function HideForm(){var chkBruchureTicked=$('span.chkBrochure > input').is(':checked');var chkSignUpTicked=$('span.chkSignUp > input').is(':checked');var chkTestDriveTicked=$('span.chkTestDrive > input').is(':checked');if($('div.mainArea').is(':visible')){if(InitialLoad){$('div.mainArea:visible').hide();}
else{if(!JustHiddenRATDLightBox){$('div.ManualUnselectionLightBox').fadeIn();}
else{$('div.mainArea:visible').slideUp('fast');$('div.formBox').animate({'margin-top':divFormBoxMarginTop_BottomPosition},'slow');JustHiddenRATDLightBox=false;}}}}
function HideFormDisabledRATDLightBoxClick(){$('div.DisabledRATDLightBox').hide();if(JustHiddenRATDLightBox){$("span.chkTestDrive input").trigger('click');JustHiddenRATDLightBox=false;}}
function HideFormManualUnselectionLightBoxClick(){$('div.ManualUnselectionLightBox').hide();$('div.mainArea:visible').slideUp('fast');$('div.formBox').animate({'margin-top':divFormBoxMarginTop_BottomPosition},'slow');}
function HideFormManual(){$('div.mainArea:visible').slideUp('fast');if(IsNullOrEmpty(PreselectedMOI)){$('div.formBox').css('margin-top',divFormBoxMarginTop_BottomPosition);$('div.formBox').fadeIn('slow');}
else{$('div.formBox').animate({'margin-top':divFormBoxMarginTop_BottomPosition},'slow');}}
function SetupCheckboxesEventHandler(){if($('div.mainArea').is(':hidden')){return;}
SetupCheckboxes();}
function ButtonNextEventHandler(){SetupCheckboxes();}
function SetupCheckboxes(){var chkBruchureTicked=$('span.chkBrochure > input').is(':checked');var chkSignUpTicked=$('span.chkSignUp > input').is(':checked');var chkTestDriveTicked=$('span.chkTestDrive > input').is(':checked');if(!chkBruchureTicked&&!chkSignUpTicked&&!chkTestDriveTicked){HideForm();}
else
{DisplayForm();}}
function Set_Form_Fields_Visibility(visibleCSS){var fieldRows=$('div.blockDiv');for(var i=0;i<fieldRows.length;i++){var fieldRow=$(fieldRows[i]);var rowShouldBeVisible=FieldContainsAnyOfStyles(fieldRow,visibleCSS);if(rowShouldBeVisible){fieldRow.addClass('RowVisible');}
else{fieldRow.removeClass('RowVisible');}}
var FormIsVisible=$('div.mainArea').is(':visible');if(InitialLoad||!FormIsVisible){$('div.blockDiv:not(div.RowVisible)').hide();$('div.blockDiv.RowVisible:hidden').show();}
else{$('div.blockDiv.RowVisible:hidden').slideDown('fast');$('div.blockDiv:not(div.RowVisible)').slideUp('fast');}}
function ExpandDropdown(){$("a.arrow_hide").hide();$("ul.menu").show();}
function HideDropdown(){$("ul.menu").hide();$("a.arrow_hide").show();}
function HideDropdownIfVisible(){if($("ul.menu").is(':visible')){HideDropdown();}}
function BuildMOIControl(){var div=$('select.MOIDDL').parent();var ulMain=$('<ul class="ul_main"/>');var liTop=$('<li class="li_top"/>');ulMain.append(liTop);var aArrow=$('<a class="arrow_down arrow_hide currentCar" href="javascript:void(0);" title="'+MOIDDLDefaultLabel+'">'+MOIDDLDefaultLabel+'</a>');liTop.append(aArrow);var ulMenu=$('<ul class="menu">');liTop.append(ulMenu);for(var i=0;i<MOICars.length;i++){var li=$('<li>');var carValue=MOICars[i].CarModelValue;var carText=$('select.MOIDDL option[value='+carValue+']').html();var a=$('<a href="javascript:void(0);" class="'+carValue+'"/>');a.html(carText);li.append(a);li.click(CarClicked);ulMenu.append(li);}
ulMenu.append($('<li class="last"><a class="arrow_up" href="javascript:void(0);" title="Close"/></li>'));div.append(ulMain);}
function CarClicked(){var carText=$(this).find("a").html();$('a.currentCar').html(carText);ToggleDisclaimer();CurrentCar=carText;if(typeof(lpSendData)!='undefined'){lpSendData('page','VehicleModel',carText);}
var carValue=$(this).find("a").attr('class');LoadCarLabels(carValue);$('.engineTypeDLL').show();DisplayHideNextBtn();}
function ToggleDisclaimer(){DisplayRadioButtonsIfNeeded();var chkBruchureTicked=$('span.chkBrochure > input').is(':checked');var chkSignUpTicked=$('span.chkSignUp > input').is(':checked');var chkTestDriveTicked=$('span.chkTestDrive > input').is(':checked');var engineTypeDLLVal=$('span.engineTypeDLL input:checked').val();var ShortDisclaimer=$('div.shortDisclaimer');ShortDisclaimer.html('');for(var i=0;i<MOICars.length;i++){var car=MOICars[i];if(car.CarModelValue==CurrentCar.toLowerCase()){ShortDisclaimer.html('');switch(engineTypeDLLVal){case"p":if(chkTestDriveTicked==true){if(car.IsPetrolDisclaimerAvailableForTestDrive==true){ShortDisclaimer.html(car.PetrolDisclaimer);}}
if(chkSignUpTicked==true){if(car.IsPetrolDisclaimerAvailableForNewsletter==true){ShortDisclaimer.html(car.PetrolDisclaimer);}}
if(chkBruchureTicked==true){if(car.IsPetrolDisclaimerAvailableForBrochure==true){ShortDisclaimer.html(car.PetrolDisclaimer);}}
if(chkSignUpTicked==false&&chkBruchureTicked==false&&chkTestDriveTicked==false){ShortDisclaimer.html('');}
break;case"d":if(chkTestDriveTicked==true){if(car.IsDieselDisclaimerAvailableForTestDrive==true){ShortDisclaimer.html(car.DieselDisclaimer);}}
if(chkSignUpTicked==true){if(car.IsDieselDisclaimerAvailableForNewsletter==true){ShortDisclaimer.html(car.DieselDisclaimer);}}
if(chkBruchureTicked==true){if(car.IsDieselDisclaimerAvailableForBrochure==true){ShortDisclaimer.html(car.DieselDisclaimer);}}
if(chkSignUpTicked==false&&chkBruchureTicked==false&&chkTestDriveTicked==false){ShortDisclaimer.html('');}
break;case"h":if(chkTestDriveTicked==true){if(car.IsHybridDisclaimerAvailableForTestDrive==true){ShortDisclaimer.html(car.HybridDisclaimer);}}
if(chkSignUpTicked==true){if(car.IsHybridDisclaimerAvailableForNewsletter==true){ShortDisclaimer.html(car.HybridDisclaimer);}}
if(chkBruchureTicked==true){if(car.IsHybridDisclaimerAvailableForBrochure==true){ShortDisclaimer.html(car.HybridDisclaimer);}}
if(chkSignUpTicked==false&&chkBruchureTicked==false&&chkTestDriveTicked==false){ShortDisclaimer.html('');}
break;}}}}
function EngineTypeSelected(radioButtonValue){ToggleDisclaimer();var CarModelValue=$('select.MOIDDL').val();for(var i=0;i<MOICars.length;i++){var car=MOICars[i];if(car.CarModelValue==CarModelValue){switch(radioButtonValue){case"p":ToggleRequestATestDrive(car.PetrolIsAvailableForTestDrive);break;case"d":ToggleRequestATestDrive(car.DieselIsAvailableForTestDrive);break;case"h":ToggleRequestATestDrive(car.HybridIsAvailableForTestDrive);break;}}}}
function ToggleRequestATestDrive(Enabled){var chk=$("span.chkTestDrive input");if($("span.chkTestDrive").parent().is(':visible')){if(Enabled){$('span.chkTestDrive').mouseenter(function(){$(this).parent().addClass('tickRequest');});$('span.chkTestDrive').mouseleave(function(){$(this).parent().removeClass('tickRequest');});chk.filter(':disabled').removeAttr('disabled');$('img.notAvailable').hide();}
else{$('span.chkTestDrive').unbind('mouseenter');$('span.chkTestDrive').unbind('mouseleave');chk.filter(':not(disabled)').attr('disabled',true);if(chk.is(':checked')){var chkSignUpTicked=$('span.chkSignUp > input').is(':checked');var chkTestDriveTicked=$('span.chkTestDrive > input').is(':checked');if(!InitialLoad&&(chkSignUpTicked||chkTestDriveTicked)){$('div.DisabledRATDLightBox').fadeIn("fast",function(){JustHiddenRATDLightBox=true;chk.removeAttr('checked');});}
else{chk.removeAttr('checked');chk.click();}}
$('img.notAvailable').fadeIn();ApplyRATDTipsInfo();}}
else{$('img.notAvailable').hide();}}
function LoadCarLabels(carModelValue){HideDropdown();var engineTypeDLL=$('span.engineTypeDLL');var PetrolRadio=engineTypeDLL.children(':nth-child(1)');var PetrolLabel=engineTypeDLL.children(':nth-child(2)');var DieselRadio=engineTypeDLL.children(':nth-child(3)');var DieselLabel=engineTypeDLL.children(':nth-child(4)');var HybridRadio=engineTypeDLL.children(':nth-child(5)');var HybridLabel=engineTypeDLL.children(':nth-child(6)');PetrolRadio.removeAttr("checked");DieselRadio.removeAttr("checked");HybridRadio.removeAttr("checked");if(InitialLoad){$('span.engineTypeDLL input').change(function(){EngineTypeSelected($(this).val());});}
var IsFirstRadioButtonSet=false;for(var i=0;i<MOICars.length;i++){var currentCar=MOICars[i];var currentCarModelValue=currentCar.CarModelValue;if(currentCarModelValue.toLowerCase()==carModelValue.toLowerCase()){$('select.MOIDDL').val(carModelValue);PetrolLabel.html(currentCar.PetrolLabel);DieselLabel.html(currentCar.DieselLabel);HybridLabel.html(currentCar.HybridLabel);var VisibleEngineTypes=0;if(currentCar.PetrolIsRadioButtonVisible)
VisibleEngineTypes++;if(currentCar.DieselIsRadioButtonVisible)
VisibleEngineTypes++;if(currentCar.HybridIsRadioButtonVisible)
VisibleEngineTypes++;if(VisibleEngineTypes>=1){RadioButtonsUsed=true;}
else{RadioButtonsUsed=false;}
if(currentCar.PetrolIsRadioButtonVisible&&VisibleEngineTypes!=1){PetrolRadio.show();PetrolLabel.show();if(!IsFirstRadioButtonSet){IsFirstRadioButtonSet=true;PetrolRadio.attr("checked",true);EngineTypeSelected(PetrolRadio.val());}}
else{if(VisibleEngineTypes==1){PetrolRadio.attr("checked",true);EngineTypeSelected(PetrolRadio.val());VisibleEngineTypes--;}
PetrolRadio.hide();PetrolLabel.hide();}
if(currentCar.DieselIsRadioButtonVisible&&VisibleEngineTypes!=1){DieselRadio.show();DieselLabel.show();if(!IsFirstRadioButtonSet){IsFirstRadioButtonSet=true;DieselRadio.attr("checked",true);EngineTypeSelected(DieselRadio.val());}}
else{if(VisibleEngineTypes==1){DieselRadio.attr("checked",true);EngineTypeSelected(DieselRadio.val());VisibleEngineTypes--;}
DieselRadio.hide();DieselLabel.hide();}
if(currentCar.HybridIsRadioButtonVisible&&VisibleEngineTypes!=1){HybridRadio.show();HybridLabel.show();if(!IsFirstRadioButtonSet){IsFirstRadioButtonSet=true;HybridRadio.attr("checked",true);EngineTypeSelected(HybridRadio.val());}}
else{if(VisibleEngineTypes==1){HybridRadio.attr("checked",true);EngineTypeSelected(HybridRadio.val());VisibleEngineTypes--;}
HybridRadio.hide();HybridLabel.hide();}
if(InitialLoad){$('div.pageBackground img').attr('src',currentCar.BackgroundImageURL);$('div.pageBackground img').fadeIn();SetupCarBackground(currentCar.CarImageURL);}
else{$('div.pageBackground img').attr('imageURL',currentCar.BackgroundImageURL);$('div.pageBackground img').fadeOut('1000',function(){var BackgroundImageURL=$(this).attr('imageURL');$('div.pageBackground img').attr('src',BackgroundImageURL);$('div.pageBackground img').fadeIn();});$('div.carArea').attr('imageURL',currentCar.CarImageURL);$('div.carArea').fadeOut('1000',function(){var CarImageURL=$(this).attr('imageURL');SetupCarBackground(CarImageURL);$('div.carArea').fadeIn();});}}}}
function SetupCarBackground(NewImageURL){$('div.carArea').css('background-image','url('+NewImageURL+')');if(IsPNGFixLoaded()){var e=$('div.carArea').get(0);DD_belatedPNG.fixPng(e);}}
function ResetMandatoryFields(){var IsPhoneNumberMandatoryByPhoneOptIn=IsPhoneOptInTicked();var IsPhoneNumberMandatoryByCentreContactOptIn=IsCentreContactOptInTicked();var MakePhoneNumberMandatory=(IsPhoneNumberMandatoryByPhoneOptIn||IsPhoneNumberMandatoryByCentreContactOptIn);var ForceMandatoryFieldCSSClass='ForceMandatoryField';if(MakePhoneNumberMandatory){$('div.phoneNumber input').addClass(ForceMandatoryFieldCSSClass);}
else{$('div.phoneNumber input.'+ForceMandatoryFieldCSSClass).removeClass(ForceMandatoryFieldCSSClass);}
var mandatoryCSS=GetMandatoryCSSClasses();mandatoryCSS.push(ForceMandatoryFieldCSSClass);Set_Mandatory_Fields(mandatoryCSS);}
function DisplayRadioButtonsIfNeeded(){if(RadioButtonsUsed!=true){$(".MOI .radioBox").hide();}else{$(".MOI .radioBox").show();}}
function CrushBoxes(){if(typeof String.prototype.trim!=='function'){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}}
if($(".MOI").length>0){if($(".MOI .testdriveOptionPanel").length>0){var testdriveOptionPanelStatus=true;function testdriveOptionPanelStatusTest(){var anyoneVisible=false;$('.MOI .testdriveOptionPanel').children().each(function(){if($(this).css('display')!="none"){anyoneVisible=true;}});return anyoneVisible;}
testdriveOptionPanelStatus=testdriveOptionPanelStatusTest();if(($(".MOI .testdriveOptionPanel").is(':empty'))||($('.MOI .testdriveOptionPanel').html().trim()=="")||(testdriveOptionPanelStatus==false)){$(".MOI .testdriveOptionPanel").hide();}}
if($(".MOI .brocureOptionPanel").length>0){if(($(".MOI .brocureOptionPanel").is(':empty'))||($('.MOI .brocureOptionPanel').html().trim()=="")){$(".MOI .brocureOptionPanel").hide();}}
if($(".MOI .radioBox").length>0){var radioBoxStatus=true;function radioBoxStatusTest(){var anyoneVisible=false;if($('.MOI .radioBox span').css('display')=="none"){return false;}
$('.MOI .radioBox span').children().each(function(){var displayState=$(this).css('display');if($(this).css('display')!="none"){anyoneVisible=true;}});return anyoneVisible;}
radioBoxStatus=radioBoxStatusTest();if(($(".MOI .radioBox").is(':empty'))||(radioBoxStatus==false)){$(".MOI .radioBox").hide();}}}}
