



$(document).ready(function() {
	$('.tabContainer .tabList div').click(function() {
		$(this).parent('.tabList').find('div').removeClass('panelButtonOn').addClass('panelButtonOff');
		$(this).parents('.tabContainer').find('.panel .panelBox').hide();
		$(this).removeClass('panelButtonOff').addClass('panelButtonOn');
		$(this).parents('.tabContainer').find('.panel #'+this.id+'Panel.panelBox').show();
		$(this).find('a').blur();
		return false;
	});
});

 


/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}



function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

var ajax = new Array();



function getModelList(sel)
{
//	var countryCode = sel.options[sel.selectedIndex].value;


var countryCode = get_cookie ("vmake")

if (globalholder==0) {
    countryCode = sel.options[sel.selectedIndex].value;

 }

if (countryCode==null || countryCode==''){

countryCode = sel.options[sel.selectedIndex].value;
}


var modelsnew = get_cookie ("vmodel")




	document.getElementById('model').options.length = 0;	// Empty city select box
	
if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

if (globalholder==1){
		ajax[index].requestFile = host +'/vehicles/getmakes1.asp?makes='+countryCode + '&modelsnew=' + modelsnew	// Specifying which file to get
		
}
else
{

ajax[index].requestFile = host +'/vehicles/getmakes1.asp?makes='+countryCode;	// Specifying which file to get

}		


ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function

if (globalholder==1 && modelsnew!='' && modelsnew!=null){

getColour(modelsnew);
}



	}
}



function createCities(index)
{
	var obj = document.getElementById('model');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

//TESTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


function fillmakes(sel)
{



var makesCode = get_cookie ("vdealerid")

if (document.getElementById("DealerLocations").value=="" || makesCode=='Please Select..'){
makesCode='All'

}
else
{

if (globalholder ==0)   {

    makesCode = sel.options[sel.selectedIndex].value;
 }



}

if (makesCode == null || makesCode=='' || makesCode=='Please Select..' || makesCode=='Please+Select..'){
makesCode = sel.options[sel.selectedIndex].value;

}

var makesnew = get_cookie ("vmake")
 


 
	document.getElementById('make').options.length = 0;	// Empty city select box
if(makesCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
	
		
if (globalholder==1 && makesnew!=null && makesnew!=''){


ajax[index].requestFile = host +'/vehicles/getmakes1.asp?location='+makesCode + '&makesnew=' + makesnew // Specifying which file to get

}
else
{
ajax[index].requestFile =host + '/vehicles/getmakes1.asp?location='+makesCode;	// Specifying which file to get
}


		ajax[index].onCompletion = function(){ createmakes(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function


if (globalholder ==1 && makesnew !='Please Select..' && makesnew != 'None'  && makesnew != null  && makesnew != '')  {


getModelList(makesnew);
}

	
}
}


function createmakes(index)
{
	var obj = document.getElementById('make');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}





//TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


function filltransmission(sel)
{
	//var transCode = sel.options[sel.selectedIndex].value;



	
var transCode = get_cookie ("vmodel")

if (globalholder==0) {
    transCode = sel.options[sel.selectedIndex].value;
 }


var transnew = get_cookie ("vtransmission")

document.getElementById('transmission').options.length = 0;	// Empty city select box
	if(transCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

if (globalholder==1){
		
		ajax[index].requestFile =host + '/vehicles/getmakes1.asp?models='+transCode + '&transmissionnew=' + transnew;	// Specifying which file to get

}
else
{
		ajax[index].requestFile = host +'/vehicles/getmakes1.asp?models='+transCode;	// Specifying which file to get

}


		ajax[index].onCompletion = function(){ createtransmissions(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function

if (globalholder==1){

getColour(transnew);
}
	}
}



function createtransmissions(index)
{
	var obj = document.getElementById('transmission');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}



//TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


function fillfuel(sel)
{
	var fuelCode = sel.options[sel.selectedIndex].value;
	document.getElementById('test_fuel').options.length = 0;	// Empty city select box
	if(fuelCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = host +'/vehicles/getmakes1.asp?transmission='+fuelCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createfuel(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}



function createfuel(index)
{
	var obj = document.getElementById('test_fuel');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}



//TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


function getColour(sel)
{
	//var ColourCode = sel.options[sel.selectedIndex].value;



//var ColourCode = get_cookie ("vtransmission")

var ColourCode = get_cookie ("vmodel")

if (globalholder==0) {
    ColourCode = sel.options[sel.selectedIndex].value;
 }
if (ColourCode==null || ColourCode==''){
ColourCode = sel.options[sel.selectedIndex].value;

}

var colournew = get_cookie ("vcolour")



	document.getElementById('test_Colour').options.length = 0;	// Empty city select box
	if(ColourCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
	
if (globalholder==1){
	
		ajax[index].requestFile =host + '/vehicles/getmakes1.asp?transmission='+ColourCode +'&colournew='+colournew;	// Specifying which file to get

}
else
{
	ajax[index].requestFile = host + '/vehicles/getmakes1.asp?transmission='+ColourCode;	// Specifying which file to get

}

		ajax[index].onCompletion = function(){ createColour(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function

globalholder=0
	}
}



function createColour(index)
{
	var obj = document.getElementById('test_Colour');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}



//TESTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


function CheckForm () {

	if (document.frmSiteSearch.search.value==""){
		alert("Please enter at least one keyword to search");
		document.frmSiteSearch.search.focus();
		return false;
	}
	
	return true
}

function CheckNewsletterForm () {

	if (document.frmNewsletter.Name.value==""){
		alert("Please enter your Name");
		document.frmNewsletter.Name.focus();
		return false;
	}
	
	if (document.frmNewsletter.Email.value==""){
		alert("Please enter your Email Address");
		document.frmNewsletter.Email.focus();
		return false;
	}
	
	return true
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


$(function()
{
    $("#imageOptions a").click(function()
        {
        var imageSource = $(this).children("img").attr("src");
       
        $("#loader").addClass("loading");
        $("h6").remove();
          showImage(imageSource);
          return false;
        });
});

function showImage(src)
{
$("#loader img").fadeOut("normal").remove();
var largeImage = new Image();
$(largeImage).load(function()
                        {
                        $(this).hide();
                        $("#loader").append(this).removeClass("loading");
                                             
                        $(this).fadeIn("slow");              
                        });    
$(largeImage).attr("src", src);                                                                               
}

function disp_confirm()
{


var inname
inname = document.tellafriend.EmailAddress.value;

var r=confirm("Are you happy to send this email to " + inname + "?");
if (r==true)
  {
  document.tellafriend.submit();
  }
else
  {
 
  }
}

