$(document).ready(function() {
// Enquiry Form Validation
$("form#enquiry-frm").submit(function () {
var msg = '';
if ($("#salutation-frm").val()=='') {
msg += "Please select a salutation \n";
}
if ($("#firstname-frm").val()=='' || $("#firstname-frm").val()===$("#firstname").attr('title')) {
msg += "Please enter a first name \n";
}
if ($("#surname-frm").val()=='' || $("#surname-frm").val()===$("#surname-frm").attr('title')) {
msg += "Please enter a surname \n";
}
if ($("#contact_no-frm").val()=='' || $("#contact_no-frm").val()===$("#contact_no-frm").attr('title')) {
msg += "Please enter an contact number \n";
}
if ($("#email-frm").val()=='' || $("#email-frm").val()===$("#email-frm").attr('title')) {
msg += "Please enter an email address \n";
}
if ($("#postcode-frm").val()=='' || $("#postcode-frm").val()===$("#postcode-frm").attr('title')) {
msg += "Please enter a postcode \n";
}
if ($("#contact_type-frm").val()=='') {
msg += "Please select a contact type \n";
}
if (msg.length>0) {
alert("Error: \n"+msg);
return false;
} else {
$("#enquiry textarea[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
$("#enquiry input[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
return true;
}
})
// Enquiry Form Validation
$("form#stock-updates-frm").submit(function () {
var msg = '';
if ($("#salutation-frm").val()=='') {
msg += "Please select a salutation \n";
}
if ($("#firstname-frm").val()=='' || $("#firstname-frm").val()===$("#firstname").attr('title')) {
msg += "Please enter a first name \n";
}
if ($("#surname-frm").val()=='' || $("#surname-frm").val()===$("#surname-frm").attr('title')) {
msg += "Please enter a surname \n";
}
if ($("#contact_no-frm").val()=='' || $("#contact_no-frm").val()===$("#contact_no-frm").attr('title')) {
msg += "Please enter an contact number \n";
}
if ($("#email-frm").val()=='' || $("#email-frm").val()===$("#email-frm").attr('title')) {
msg += "Please enter an email address \n";
}
if ($("#postcode-frm").val()=='' || $("#postcode-frm").val()===$("#postcode-frm").attr('title')) {
msg += "Please enter a postcode \n";
}
if (msg.length>0) {
alert("Error: \n"+msg);
return false;
} else {
$("#enquiry textarea[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
$("#enquiry input[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
return true;
}
})
$("form#stf-frm").submit(function () {
var msg = '';
if ($("#sender_name-frm").val()=='' || $("#sender_name-frm").val()===$("#sender_name-frm").attr('title')) {
msg += "Please enter a your name \n";
}
if ($("#sender_email-frm").val()=='' || $("#sender_email-frm").val()===$("#sender_email-frm").attr('title')) {
msg += "Please enter your email address \n";
}
if ($("#friend_name-frm").val()=='' || $("#friend_name-frm").val()===$("#friend_name-frm").attr('title')) {
msg += "Please enter a your friend's name \n";
}
if ($("#friend_email-frm").val()=='' || $("#friend_email-frm").val()===$("#friend_email-frm").attr('title')) {
msg += "Please enter your friend's email address \n";
}
if (msg.length>0) {
alert("Error: \n"+msg);
return false;
} else {
$("#stf-frm textarea[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
$("#stf-frm input[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
return true;
}
})
$("form#compare-form").submit(function () {
var noChecked = parseInt($("#compare-form input[type=checkbox]:checked").length);
if (noChecked < 2 || noChecked>6) {
var $dialog = $('
')
.html('Please select between 2 and 6 cars to compare')
.dialog({
title: 'My Forecourt',
bgiframe: true,
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
}
});
return false;
}
});
if ($("#home-offers div.slide").length>0) {
$("#home-offers div.slide:first").show().siblings().hide();
var offChange = function () {
$("#home-offers div.slide:visible").fadeOut('slow', function() {
$(this).hide();
nextSlide = $(this).next();
if (nextSlide.length>0) {
$(nextSlide).fadeIn('slow');
} else {
$("#home-offers div.slide:first").fadeIn('slow');
}
})
offTimer = setTimeout(offChange, 5000);
}
offTimer = setTimeout(offChange, 5000);
}
// My Forecourt
$("#my-forecourt-right").click(function() {
var cpos = $("#my-forecourt-basket").offset();
var pos = $("#my-forecourt-basket div").offset();
if ((cpos.left-pos.left)<(($("#my-forecourt-basket div img").size()-5)*50)) {
$("#my-forecourt-basket div").animate({left: "-=50px"},'fast');
return false;
}
})
$("#my-forecourt-left").click(function() {
var cpos = $("#my-forecourt-basket").offset();
var pos = $("#my-forecourt-basket div").offset();
if (cpos.left>pos.left) {
$("#my-forecourt-basket div").animate({left: "+=50px"},'fast');
return false;
}
})
// Offers Filter
$("#off-location-id").change(function() {
if ($(this).val() !=='') {
$("#off-branch-id").attr("selectedIndex",0)
}
})
$("#off-brand-id").change(function() {
if ($(this).val() !=='') {
$("#off-branch-id").attr("selectedIndex",0)
}
})
$("#off-branch-id").change(function() {
if ($(this).val() !=='') {
$("#off-brand-id").attr("selectedIndex",0)
$("#off-location-id").attr("selectedIndex",0)
}
})
// Form titles
$("input[title]").each(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title'));
}
$(this).focus(function() {
if($(this).val() === $(this).attr('title')) {
$(this).val('').addClass('focused');
}
});
$(this).blur(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title')).removeClass('focused');
}
});
});
$("textarea[title]").each(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title'));
}
$(this).focus(function() {
if($(this).val() === $(this).attr('title')) {
$(this).val('').addClass('focused');
}
});
$(this).blur(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title')).removeClass('focused');
}
});
});
//Used Search
$("a.expand-collapse").click(function() {
if ($("#plus-minus").hasClass('minus')) {
$("#plus-minus").removeClass('minus');
$("#plus-minus").addClass('plus');
$("#car-search").hide('fast');
} else {
$("#car-search").show('fast');
$("#plus-minus").removeClass('plus');
$("#plus-minus").addClass('minus');
}
return false;
})
// New Cars Click
$("#new-cars-manufactuer div.model a.summary").each(function() {
$(this).click(function() {
var url = '/ajax/new-cars-summary/'+$(this).attr('rel');
$("#new-cars-manufactuer div.model a.summary").removeClass("curr");
$(this).addClass("curr");
$("#new-car-summary").fadeOut('fast',function() {
$("#new-car-summary").load(url, function() {
$("#new-car-summary").fadeIn('fast');
});
});
return false;
})
})
$("#content a.my-forecourt-add").each(function() {
$(this).click(function() {
$("#my-forecourt-basket div").load($(this).attr('href'), function() {
var msg = '';
if ($("#my-forecourt-basket div a").length>$("#my-no-cars").html()) {
msg = 'The car has been added to your forecourt';
$("#my-no-cars").html($("#my-forecourt-basket div a").length);
} else {
msg = 'You have already added this car'
}
var $dialog = $('')
.html(msg)
.dialog({
title: 'My Forecourt',
bgiframe: true,
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
}
});
});
return false;
})
})
$("#content a.my-forecourt-del").each(function() {
$(this).click(function() {
var lnk = $(this);
var $dialog = $('')
.html('Are you sure you want to remove this car?')
.dialog({
title: 'My Forecourt',
bgiframe: true,
modal: true,
buttons: {
No: function() {
$(this).dialog('close');
},
Yes: function() {
$(this).dialog('close');
$("#my-forecourt-basket div").load($(lnk).attr('href'), function() {
$("#id"+$(lnk).attr('rel')).slideUp('Slow', function() { $(this).remove(); } );
if ($("#my-forecourt-basket div a").length!=$("#my-no-cars").html()) {
$("#my-no-cars").html($("#my-forecourt-basket div a").length);
$("#my-no-cars-tab").html($("#my-forecourt-basket div a").length);
if ($("#my-forecourt-basket div a").length==0) {
$("iframe.finance-apr-frame").slideUp('Slow', function() { $(this).remove(); } );
$("div.right-tab").remove();
}
}
});
}
}
});
return false;
})
})
//Used Car Search models
$("#manufacturer_id").change(function() {
var options = '';
var man_id = $(this).val();
if (car_models[man_id] !== undefined) {
$("#model_id").html(options);
for(i=1;i' + car_models[man_id][i][1] + ' (' + car_models[man_id][i][2] + ')';
}
}
$("#model_id").html(options);
})
$("#com-qs-manufacturer_id").change(function() {
var options = '';
var man_id = $(this).val();
if (com_car_models[man_id] !== undefined) {
$("#com-qs-model_id").html(options);
for(i=1;i' + com_car_models[man_id][i][1] + ' (' + com_car_models[man_id][i][2] + ')';
}
}
$("#com-qs-model_id").html(options);
$("#com-qs-location").load('/ajax/used-car-locations/?commercial=1&branch_id=&manufacturer_id='+man_id);
})
$("#com-manufacturer_id").change(function() {
var options = '';
var man_id = $(this).val();
if (com_car_models[man_id] !== undefined) {
$("#com-model_id").html(options);
for(i=1;i' + com_car_models[man_id][i][1] + ' (' + com_car_models[man_id][i][2] + ')';
}
}
$("#com-model_id").html(options);
})
$("#uc-qs-manufacturer_id").change(function() {
var options = '';
var man_id = $(this).val();
if (car_models[man_id] !== undefined) {
$("#uc-qs-model_id").html(options);
for(i=1;i' + car_models[man_id][i][1] + ' (' + car_models[man_id][i][2] + ')';
}
}
$("#uc-qs-model_id").html(options);
$("#uc-qs-location").load('/ajax/used-car-locations/?branch_id=&manufacturer_id='+man_id);
})
$("#uc-qs-model_id").change(function() {
$("#uc-qs-location").load('/ajax/used-car-locations/?model_id='+$(this).val()+'&branch_id=&manufacturer_id=');
})
$("#com-qs-model_id").change(function() {
$("#com-qs-location").load('/ajax/used-car-locations/?model_id='+$(this).val()+'&branch_id=&manufacturer_id=');
})
// Book a service
$("#bs-manufacturer_id").change(function() {
$("#bs-model_id").load('/ajax/service-models/?manufacturer_id='+$(this).val());
})
$("#bs-location_id").change(function() {
$("#bs-branch_id").load('/ajax/service-branches/?location_id='+$(this).val());
})
$("#bs-preferred_date").datepicker({dateFormat: 'dd/mm/yy'});
$("form#book-a-service-frm").submit(function () {
var msg = '';
if ($("#bs-salutation").val()=='') {
msg += "Please select a salutation \n";
}
if ($("#bs-firstname").val()=='' || $("#bs-firstname").val()===$("#bs-firstname").attr('title')) {
msg += "Please enter a first name \n";
}
if ($("#bs-surname").val()=='' || $("#bs-surname").val()===$("#bs-surname").attr('title')) {
msg += "Please enter a surname \n";
}
if ($("#bs-contact_no").val()=='' || $("#bs-contact_no").val()===$("#bs-contact_no").attr('title')) {
msg += "Please enter an contact number \n";
}
if ($("#bs-email").val()=='' || $("#bs-email").val()===$("#bs-email").attr('title')) {
msg += "Please enter an email address \n";
}
if ($("#bs-postcode").val()=='' || $("#bs-postcode").val()===$("#bs-postcode").attr('title')) {
msg += "Please enter a postcode \n";
}
if ($("#bs-contact_type").val()=='') {
msg += "Please select a contact type \n";
}
if ($("#bs-manufacturer_id").val()=='') {
msg += "Please select a make \n";
}
if ($("#bs-engine_size").val()=='') {
msg += "Please select an engine size \n";
}
if ($("#bs-transmission").val()=='') {
msg += "Please select a transmission \n";
}
if ($("#bs-fuel").val()=='') {
msg += "Please select a fuel type \n";
}
if ($("#bs-registration").val()=='' || $("#bs-registration").val()===$("#bs-registration").attr('title')) {
msg += "Please enter a registration \n";
}
if ($("#bs-service_type").val()=='') {
msg += "Please select a service type \n";
}
if ($("#bs-location_id").val()=='') {
msg += "Please select a location \n";
}
if ($("#bs-branch_id").val()=='') {
msg += "Please select a branch \n";
}
if ($("#bs-preferred_date").val()=='' || $("#bs-preferred_date").val()===$("#bs-preferred_date").attr('title')) {
msg += "Please enter a date \n";
}
if ($("#bs-preferred_time").val()=='' || $("#bs-preferred_time").val()===$("#bs-preferred_time").attr('title')) {
msg += "Please enter a time \n";
}
if (msg.length>0) {
alert("Error: \n\n"+msg);
return false;
} else {
$("#enquiry textarea[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
$("#enquiry input[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
return true;
}
})
// Book a Test Drive
$("#bt-preferred_date").datepicker({dateFormat: 'dd/mm/yy'});
$("form#book-a-test-drive-frm").submit(function () {
var msg = '';
if ($("#bt-salutation").val()=='') {
msg += "Please select a salutation \n";
}
if ($("#bt-firstname").val()=='' || $("#bt-firstname").val()===$("#bt-firstname").attr('title')) {
msg += "Please enter a first name \n";
}
if ($("#bt-surname").val()=='' || $("#bt-surname").val()===$("#bt-surname").attr('title')) {
msg += "Please enter a surname \n";
}
if ($("#bt-contact_no").val()=='' || $("#bt-contact_no").val()===$("#bt-contact_no").attr('title')) {
msg += "Please enter an contact number \n";
}
if ($("#bt-email").val()=='' || $("#bt-email").val()===$("#bt-email").attr('title')) {
msg += "Please enter an email address \n";
}
if ($("#bt-postcode").val()=='' || $("#bt-postcode").val()===$("#bt-postcode").attr('title')) {
msg += "Please enter a postcode \n";
}
if ($("#bt-contact_type").val()=='') {
msg += "Please select a contact type \n";
}
if ($("#bt-branch_id").val()=='') {
msg += "Please select a branch \n";
}
if ($("#bt-preferred_date").val()=='' || $("#bt-preferred_date").val()===$("#bt-preferred_date").attr('title')) {
msg += "Please enter a date \n";
}
if ($("#bt-preferred_time").val()=='' || $("#bt-preferred_time").val()===$("#bt-preferred_time").attr('title')) {
msg += "Please enter a time \n";
}
if (msg.length>0) {
alert("Error: \n\n"+msg);
return false;
} else {
$("#enquiry textarea[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
$("#enquiry input[title]").each(function() {
if ($(this).val() === $(this).attr('title'))
$(this).val('');
})
return true;
}
})
// Maps
if ($("#map").length>0) {
initMap('map',10,'');
}
if ($("#map-small").length>0) {
initMap('map-small',11,'/find-a-dealer/by-map/');
}
// Car Tabs Images
if ($("#car-details").length>0) {
$("#car-spec div.tab").hide();
$("#car-spec div.on").show();
if ($("#thumbnails a.change").length>0) {
var current = 1;
var last = 0;
var timer = '';
var pauseState = 0;
images = [];
$("#car-details a.change").each(function(index, element){
images[index] = $(element).attr("href", $(element).attr("href"));
});
var change = function () {
if ( pauseState == 0 ) {
$("#gallery img")
.fadeOut('slow', function() {
$(this).attr('src',($(images[last]).attr("href"))).fadeIn('slow');
})
$(images[current]).addClass("curr");
$(images[last]).removeClass("curr");
if ( ( current + 1 ) < images.length ) {
current = current + 1;
last = current - 1;
}
else {
current = 0;
last = images.length - 1;
}
timer = setTimeout(change, 5000);
}
}
timer = setTimeout(change, 5000);
}
$("#thumbnails a.change").click(function() {
pauseState = 1;
var imgSrc = this.href
$("#gallery img")
.fadeOut('slow', function() {
$(this).attr('src',imgSrc).fadeIn('slow');
})
$(this).addClass("curr").siblings().removeClass("curr");
return false;
})
$("#car-spec ul.tabs a").click(function() {
$("#car-spec ul.tabs a").parent().removeClass("on");
$(this).parent().addClass("on");
$("#car-spec .tab").hide();
$($(this).attr('href')).show();
return false;
})
}
// Home Locator
if ($("#home-locator").length>0) {
$("#home-locator div.tab").hide();
$("#home-locator div.on").show();
$("#home-locator ul.tabs a").click(function() {
$("#home-locator ul.tabs a").parent().removeClass("on");
$(this).parent().addClass("on");
$("#home-locator div.tab").hide();
$($(this).attr('href')).show();
return false;
})
}
// Home Offers
if ($("#home-offers").length>0) {
$("#home-offers div.tab").hide();
$("#home-offers div.on").show();
$("#home-offers ul.tabs a").click(function() {
$("#home-offers ul.tabs a").parent().removeClass("on");
$(this).parent().addClass("on");
$("#home-offers div.tab").hide();
$($(this).attr('href')).show();
return false;
})
}
// Service Test Drive SB
if ($("#sb-service-test-drive").length>0) {
$("#sb-service-test-drive div.tab").hide();
$("#sb-service-test-drive div.on").show();
$("#sb-service-test-drive ul.tabs a").click(function() {
$("#sb-service-test-drive ul.tabs a").parent().removeClass("on");
$(this).parent().addClass("on");
$("#sb-service-test-drive div.tab").hide();
$($(this).attr('href')).show();
return false;
})
}
// Quick Search
if ($("#sb-quick-search-cont").length>0) {
$("#sb-quick-search-cont div.tab").hide();
$("#sb-quick-search-cont div.on").show();
$("#sb-quick-search-cont ul.tabs a").click(function() {
$("#sb-quick-search-cont ul.tabs a").parent().removeClass("on");
$(this).parent().addClass("on");
$("#sb-quick-search-cont div.tab").hide();
$($(this).attr('href')).show();
return false;
})
}
})
function initMap(elId,zoom,urlPrefix) {
pointCenter = new GLatLng(56.72259433299854, -3.88916015625);
var pointGlasgow = new GLatLng(55.84861416406609, -4.2762136459);
var markerGlasgow = new GMarker(pointGlasgow,{title:"Glasgow"});
var pointFraserburgh = new GLatLng(57.690182,-2.00532);
var markerFraserburgh = new GMarker(pointFraserburgh,{title:"Fraserburgh"});
var pointSelkirk = new GLatLng(55.557894, -2.835142);
var markerSelkirk = new GMarker(pointSelkirk,{title:"Selkirk"});
var pointWallyford = new GLatLng(55.93900997848786, -3.0092239379);
var markerWallyford = new GMarker(pointWallyford,{title:"Wallyford"});
var pointEdinburgh = new GLatLng(55.927408, -3.300666);
var markerEdinburgh = new GMarker(pointEdinburgh,{title:"Edinburgh"});
var pointKemnay = new GLatLng(57.242987,-2.442044);
var markerKemnay = new GMarker(pointKemnay,{title:"Kemnay"});
var map = new GMap(document.getElementById(elId));
map.centerAndZoom(pointCenter,zoom);
map.addOverlay(markerGlasgow);
GEvent.addListener(markerGlasgow, "click", function() {
window.location=urlPrefix+'glasgow/';
});
map.addOverlay(markerFraserburgh);
GEvent.addListener(markerFraserburgh, "click", function() {
window.location=urlPrefix+'fraserburgh/';
});
map.addOverlay(markerSelkirk);
GEvent.addListener(markerSelkirk, "click", function() {
window.location=urlPrefix+'selkirk/';
});
map.addOverlay(markerWallyford);
GEvent.addListener(markerWallyford, "click", function() {
window.location=urlPrefix+'wallyford/';
});
map.addOverlay(markerEdinburgh);
GEvent.addListener(markerEdinburgh, "click", function() {
window.location=urlPrefix+'edinburgh/';
});
map.addOverlay(markerKemnay);
GEvent.addListener(markerKemnay, "click", function() {
window.location=urlPrefix+'kemnay/';
});
}
function initListingMap(elId,zoom,longPoint,latPoint) {
var point = new GLatLng(longPoint, latPoint);
var marker = new GMarker(point);
var map = new GMap(document.getElementById(elId));
map.centerAndZoom(point,zoom);
map.addOverlay(marker);
var mapControl = new GMapTypeControl();
map.addControl(mapControl);
map.addControl(new GSmallMapControl());
}
function finance_dialog(type) {
var url = '/ajax/finance-popup/'+type+'/'
var $dialog = $('')
.load(url)
.dialog({
title: 'Finance Information',
modal: true,
position: 'center'
});
return false;
}
function filter_qs_location_sel(element,query) {
var options = '';
$(element).html(options);
$.getJSON("/ajax/used-car-locations/"+query, function(j){
$(element).html('');
for (var i = 0; i < j.length; i++) {
options += '';
}
$(element).html(options);
})
}