// JavaScript Document
	var classAtt;
	if(window.ActiveXObject){
		classAtt='className';
	}else{
		classAtt='class';	
	}
	
function addClass(eleObj,classVal,toggle){
  //alert ('OK');
		if(toggle==true){//if class is to be added
			if(!eleObj.className){//if the 'class' attribute does not exist
				eleObj.className = classVal;
			}else if(eleObj.className && eleObj.className.indexOf(classVal)== -1){//if the 'class' attribute does exist then add value to existing value
				eleObj.className+=' ' + classVal;
			}
		}else if(toggle==false){//if class is to be removed
			var newClassVal=eleObj.className.replace(classVal,'');//replace classVal with empty string and return the remaining class value
			eleObj.className=newClassVal;
		}
}
function togDisplay(id,st) {
  /*  var style = document.getElementById(id).style; */
  if (st == 'on') {
        document.getElementById(id).style.display = 'block';
        document.getElementById("carBrief").style.display = 'none';
        document.getElementById("carPics").style.display = 'none';
        if (document.getElementById("carSpec") != null) {
          document.getElementById("carSpec").style.display = 'none';
        }
        document.getElementById("bkTestDrive").style.display = 'none';
        document.getElementById("co2box").style.display = 'none';
        if (document.getElementById("roadTax") != null) {
          document.getElementById("roadTax").style.display = 'none';
        }
        if (document.getElementById("manComms") != null) {
          document.getElementById("manComms").style.display = 'none';
        }
  } else {
        document.getElementById(id).style.display = 'none';
        document.getElementById("carBrief").style.display = 'block';
        document.getElementById("carPics").style.display = 'block';
        if (document.getElementById("carSpec") != null) {
          document.getElementById("carSpec").style.display = 'block';
        }
        document.getElementById("bkTestDrive").style.display = 'block';
        document.getElementById("co2box").style.display = 'block';
        if (document.getElementById("roadTax") != null) {
          document.getElementById("roadTax").style.display = 'block';
        }
        if (document.getElementById("manComms") != null) {
          document.getElementById("manComms").style.display = 'block';
        }
  }
}
function testObjId(objId){
	if(!document.getElementById(objId)){
		return false;
	}	
}
function setOpenMapLink(){
	if(!document.getElementById('mapDirct')){
		return;
	}
	var imgArr= document.getElementById('mainCol').getElementsByTagName('img');
	for(var i=0;i<imgArr.length;++i){
		if(imgArr[i].getAttribute('alt')=='View Map'){
			imgArr[i].onclick=function(){
				addClass(document.getElementById('mapDirct'),'showMap',true);
			}
		}
	}

}	
function srchForm(form_id, adv_name){
	if(!document.getElementById(form_id)){
		return;
	}
	var eleArr=document.getElementById(form_id).getElementsByTagName('a');
	for(i=0;i<eleArr.length;++i){
		var linkTitle=eleArr[i].getAttribute('title');
		if(linkTitle=="Advanced Search"){
			eleArr[i].onclick=function(){
				if(document.getElementById(adv_name).style.display=="block"){
					document.getElementById(adv_name).style.display="none";
					this.innerHTML='Advanced Search';					
				}else{
					document.getElementById(adv_name).style.display="block";
					this.innerHTML='Close Advanced Search';
				}
			}	
		}
	}
}	
function getEleObj(attVal,eleTag,eleAtt,eleParent){// returns an array of objects based on paramaters
	//var eleArr;
	if(typeof(eleParent)=='string' && document.getElementById(eleParent)){ 
		var eleArr = document.getElementById(eleParent).getElementsByTagName(eleTag);
	}else if(typeof eleParent=='object' && eleParent){
		var eleArr=eleParent.getElementsByTagName(eleTag);
	}else{
    return false;
	}

	var eleObj = new Array();
	for(var i=0;i<eleArr.length;++i){
		if(eleArr[i].getAttribute(eleAtt)==attVal){
			eleObj.push(eleArr[i]);
		}
	}
	return eleObj;
}
function setPanelLinks(){
	var panelEle=getEleObj('panels3','div',classAtt,'mainCol');
	var panelLinks = getEleObj('btnMore','a',classAtt,panelEle[0]);
	
	for(var i=0;i<panelLinks.length;++i){
		panelLinks[i].onclick=function(){
			//this.childNodes[0].src="images/btns/btn_close.gif";
			if(this.childNodes[0].src.indexOf("images/btns/btn_moreinfo.gif") != -1){
			this.childNodes[0].src="images/btns/btn_close.gif";
				//alert(this.childNodes[0].tagName);
				addClass(this.parentNode.parentNode,'panelOpen',true);
			}else{
				this.childNodes[0].src="images/btns/btn_moreinfo.gif";
				addClass(this.parentNode.parentNode,'panelOpen',false);
			}
		}
	}
}
function setOpenImgLink(){
  //alert ('setOpenImgLink');
//  if (current == min_image) {
//    document.getElementById('previous').style.display = 'none';
//  } else if (current == max_image) {
//    document.getElementById('next').style.display = 'none';
//  }
	if (document.getElementById('mainPic')) {
		var linkArr= document.getElementById('mainPic').getElementsByTagName('a');
		for(var i=0;i<linkArr.length;++i){
			if(linkArr[i].getAttribute(classAtt)=='viewLrg'){
				linkArr[i].onclick=function(){
					addClass(document.getElementById('lrgPic'),'showLrg',true);
				}
			}
		}
	}
}
function setCloseImgLink(){
  //alert ('setCloseImgLink');
	if (document.getElementById('picBarL')) {
		var linkArr= document.getElementById('picBarL').getElementsByTagName('a');
		for(var i=0;i<linkArr.length;++i){
			if(linkArr[i].getAttribute(classAtt)=='btnPrev'){
				linkArr[i].onclick=function(){
					addClass(document.getElementById('lrgPic'),'showLrg',false);
				}
			}
		}
	}
}	
function toggleImgLinks(){
	if(!document.getElementById('lrgPic')){
		return false;
	}
		setCloseImgLink();
		setOpenImgLink();
}
function iniFncs(){
  //alert ('iniFncs');
	srchForm('searchForm_used', 'advSearch');
	srchForm('searchForm_new', 'advSearch_new');
	srchForm('searchForm_commercial', 'advSearch_commercial');
	setOpenMapLink();
	setPanelLinks();
	toggleImgLinks();
}
window.onload = function(){
	iniFncs();
	//alert ('onload');
}

/***********************************************
* Basic Ajax Routine- Copyright Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'

function createAjaxObj(){
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
		httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject){ // if IE
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
	var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange=callbackfunc
		this.ajaxobj.open('GET', url+"?"+parameters, true)
		this.ajaxobj.send(null)
	}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}


var http = createAjaxObj();
var httpdet = createAjaxObj();

var addtoshorturl  = "http://"+window.location.hostname+"/addtoshorturl.php?carid=";
var remtoshorturl  = "http://"+window.location.hostname+"/remshortlist.php?carid=";

function addshortlist(carID,override) {
	http.open("GET",addtoshorturl + escape(carID) + '&override=' + escape(override) + '&addrem=A&rand=' + Math.random().toString(),true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.responseText.indexOf('invalid') == -1) {
				document.getElementById("myFav").parentNode.innerHTML = http.responseText;
				if (override == 'Y') {
					document.getElementById("short_"+carID).innerHTML = '<a href="javascript:remshortlist(&#39;'+carID+'&#39;,&#39;'+'Y'+'&#39;);" class="greySlab" title="Remove From Shortlist"><img src="/images/btns/btn_remshrtlstl.gif" border="1" alt="Remove From Shortlist"></a>';
				}
			}
		}
	}
	http.send(null);

}

function remshortlist(carID,override) {
	http.open("GET",remtoshorturl + escape(carID) + '&override=' + escape(override) + '&addrem=R&rand=' + Math.random().toString(),true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.responseText.indexOf('invalid') == -1) {
				document.getElementById("myFav").parentNode.innerHTML = http.responseText;
				if (override == 'Y') {
					document.getElementById("short_"+carID).innerHTML = '<a href="javascript:addshortlist(&#39;'+carID+'&#39;,&#39;'+'Y'+'&#39;);" class="greySlab" title="Add to Shortlist"><img src="/images/btns/btn_resshrtlstl.gif" border="1" alt="Add to Shortlist"></a>';
				}
			}
		}
	}
	http.send(null);

}
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function change_tabs(id,last_id) {
	var IDS = Array (
					'General',
          			'Exterior',
					'Interior',
					'Driver',
					'Safety',					
					'Tech'
					 );
	var IDSA = Array (
					'GeneralA',
          			'ExteriorA',
					'InteriorA',
					'DriverA',
					'SafetyA',					
					'TechA'
					 );
	
	for (i=0;i<IDS.length;i++) {
		if(document.getElementById(IDSA[i])){
			if (IDS[i] == id) {
				document.getElementById(id).style.display = 'block';
				document.getElementById(IDSA[i]).className = 'current';
				document.getElementById(last_id).className = 'end current';
			} else {
					document.getElementById(IDS[i]).style.display = 'none';
					document.getElementById(IDSA[i]).className = '';
					document.getElementById(last_id).className = 'end';
			}
		}
	}
	if (id+'A' == last_id) {
		document.getElementById('Spec').style.background = '#fff';
	} else {
		document.getElementById('Spec').style.background = '#dfdfdf';
	}
}

function showMap()
{
  var option=['map'];
  for(var i=0; i<option.length; i++)
  { obj=document.getElementById(option[i]);
  obj.style.display=(obj.style.display=="none")? "block" : "none"; }
}

function validate_email(field) {
	field=trim(field); 
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\!\"\£\$\%\^\&\*\+\=\{\}\~\#\?\(\)\<\>\,\;\:\\\/\"\[\]\ ]/;
	
	if ((!(emailFilter.test(field))) || (field.match(illegalChars))) {
		return 0;
	} else {
		return 1;
	}
}
function trim (str) {
	str = this != window? this : str;
	return str.replace(/^\s+|\s+$/g,"");
}


function validateForm(form_name, more) {
	var valid = true;
	var msg = "";
	
	switch (form_name) {
		case 'searchForm_used':
			/*
		  if (document.searchForm_used.maker_F.value == '-Any-') {
				msg = msg + "Please, choose the maker used\n";
				valid = false;
			}
			if (document.searchForm_used.email_F.value != 'YOUR EMAIL') {
				if(!validate_email(document.searchForm_used.email_F.value)){
				msg = msg + "Please, enter valid email\n";
				valid = false;
			}}*/
			break;
		case 'searchForm_new':
			if (document.searchForm_new.maker_F.value == '-Any-') {
				msg = msg + "Please, choose the maker new\n";
				valid = false;
			}
/*			if (document.searchForm_new.email_F.value != 'YOUR EMAIL') {
				if(!validate_email(document.searchForm_new.email_F.value)){
				msg = msg + "Please, enter valid email\n";
				valid = false;
			}}*/
			if (more != 'more') {
				if (document.searchForm_new.model_F.value == '-Any-') {
					msg = msg + "Please, choose the model new\n";
					valid = false;
				}
			}
			break;
		case 'searchForm_commercial':
			/*
		  if (document.searchForm_commercial.maker_F.value == '-Any-') {
				msg = msg + "Please, choose the maker commercial\n";
				valid = false;
			}
			if (document.searchForm_commercial.email_F.value != 'YOUR EMAIL') {
				if(!validate_email(document.searchForm_commercial.email_F.value)){
				msg = msg + "Please, enter valid email\n";
				valid = false;
			}}*/
			break;
		case 'bookTestDrive':
			if (document.bookTestDrive.name_F.value == 'NAME *') {
				msg = msg + "Please, enter your Name\n";
				valid = false;
			}
			if (document.bookTestDrive.email_F.value == 'YOUR EMAIL *') {
				msg = msg + "Please, enter your Email Address\n";
				valid = false;
			} else if (!validate_email(document.bookTestDrive.email_F.value)) {
			  msg = msg + "You must enter a valid e-mail\n";
		    valid = false;
			}
			
			break;
                case 'four_plus_contact':
                        if (document.four_plus_contact.firstname_F.value == '') {
                                msg = msg + "Please, enter your first name\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.surname_F.value == '') {
                                msg = msg + "Please, enter your surname\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.email_F.value == '') {
                                msg = msg + "Please, enter your email\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.address_line_1_F.value == '') {
                                msg = msg + "Please, enter your address\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.town_F.value == '') {
                                msg = msg + "Please, enter your town\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.postcode_F.value == '') {
                                msg = msg + "Please, enter your postcode\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.phone_F.value == '') {
                                msg = msg + "Please, enter your phone number\n";
                                valid = false;
                        }
                        if (document.four_plus_contact.car_reg_no_F.value == '') {
                                msg = msg + "Please, enter your car registration number\n";
                                valid = false;
                        }
                        break;
		default: break;
	}
	
	if (!valid) alert(msg);
	return valid;
}

//function popUp(URL) {
//	day = new Date();
//	id = day.getTime();
//	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,status=0,menubar=0,resizable=1,width=400,height=300,left=312,top=134');");
//}
function sumbitContactForm(form_name) {
	if (validateForm(form_name)) {

	  vars = '/email-dealer.php?name_F='+document.bookTestDrive.name_F.value
	  			  +'&phone_F='+document.bookTestDrive.phone_F.value
				  +'&email_F='+document.bookTestDrive.email_F.value
				  +'&comments_F='+document.bookTestDrive.comments_F.value;

	  MM_openBrWindow(vars,'contact','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width=500,height=160,left=312,top=134');
        } else {
          return false;
        }
}
function popWin(url){
	myWin=window.open(url,'win','width=500,height=650')
	myWin.focus();
}


// from utils\page.inc
// begin
	function load(glat,glong) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			var point = new GLatLng(glat,glong);
			map.setCenter(point, 13);
			var marker = new GMarker(point);
			map.addOverlay(marker);
		}
	}

	function loadMult(glat,glong,mapid) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById(mapid));
			map.addControl(new GSmallMapControl());
			var point = new GLatLng(glat,glong);
			map.setCenter(point, 13);
			var marker = new GMarker(point);
			map.addOverlay(marker);
		}
	}

	function loadMap(glat, glong) {
		ele = document.getElementById("map");
		ele.style.display = "block";
		
		load(glat, glong);
		if(document.getElementById("hideMap")){
			ele = document.getElementById("hideMap");
			ele.onclick = function () {
				obj = document.getElementById("map");
				if (obj.style.display != "block") {
					obj.style.display = "block";
				} else {
					obj.style.display = "none";
				}
			}
		}
	}

	function loadMapMult(glat, glong, linkid, mapid) {
		ele = document.getElementById(mapid);
		ele.style.display = "block";
		
		loadMult(glat, glong, mapid);
		if(document.getElementById(linkid)){
			ele = document.getElementById(linkid);
			ele.onclick = function () {
				obj = document.getElementById(mapid);
				if (obj.style.display != "block") {
					obj.style.display = "block";
				} else {
					obj.style.display = "none";
				}
			}
		}
	}
// from utils\page.inc
// end

// from utils\block-vehicle-search.inc, utils\block-vehicle-search-hot-offer-details.inc,
// utils\block-more-offers.inc, utils\block-left-col.inc
// begin
function ChangeTab(given_tab_id) {
	var style = document.getElementById(given_tab_id).style;
	Class_Name = Array (
	'leftTab',
	'midTab',
	'rightTab'
	);
	Tabs_Name = Array (
	'used',
	'new',
	'commercial'
	);
	Tabs_ID = Array (
	'searchForm_used',
	'searchForm_new',
	'searchForm_commercial'
	);
	for (x = 0; x < 3; x++) {
		if (Tabs_ID[x] == given_tab_id) {
			style.display = 'block';
			document.getElementById(Tabs_Name[x]).className = Class_Name[x] + ' current';
			if (Tabs_Name[x] == 'commercial') {
				document.getElementById(Tabs_Name[x]).style.width = '82px';
			} else {
				document.getElementById(Tabs_Name[x]).style.width = '68px';
			}
		} else {
			document.getElementById(Tabs_ID[x]).style.display = 'none';
			document.getElementById(Tabs_Name[x]).className = Class_Name[x];
		}
	}
}
// from utils\block-vehicle-search.inc, utils\block-vehicle-search-hot-offer-details.inc,
// utils\block-more-offers.inc, utils\block-left-col.inc
// end

// from block-email-bulletins.inc
// begin
var select_box;
  var current_model;
  var msg="";
  function validateUpdateMe() {
  	
  	var valid = true;

  	if(document.emailBull.maker_F.value == "-Any-") {
  		msg = msg + "You must select make.\n";
  		valid = false;
  	} 

  	if(document.emailBull.model_F.value == '-Any-') {
  		msg = msg + "You must select model.\n";
  		valid = false;
  	}
  	
  	if (document.emailBull.email_F.value=="Your email address*") {
	 	msg = msg + "You must enter your e-mail.\n";
	 	valid = false;
	} else {
		if(!validate_email(document.emailBull.email_F.value)) {
			msg = msg + "You must enter a valid e-mail.";
			valid = false;
		}  			
	}
  	  	  	  		
  	return valid;  	
  }

  
  function sumbitForm() {
		
		if (validateUpdateMe())	{
			vars = '/update-me.php?maker_F='+document.emailBull.maker_F.value+'&model_F='+document.emailBull.model_F.value+'&email_F='+document.emailBull.email_F.value;
			MM_openBrWindow(vars,'Email_Updates','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=160,left=312,top=134');			
		} else {
			alert(msg);
			msg = "";
		}
		
    return false;
	}
		function change(id) {
		  var container = document.getElementById(id);		  		  		 		  	
		    container.style.display='block';
		}    
		function change1(id) {
		  var container = document.getElementById(id);
		    container.style.display='none';
		    container.style.height='0px';
		}
	
// from block-email-bulletins.inc
// end
var current_images = 0;

function first(current) {
  if (current == min_image) {
    current_images = max_image + 1;
  }
}
function last(current) {
  if (current == max_image) {
    current_images = min_image - 1;
  }
}
function previous () {
  first(current_images);
  current_images = current_images - 1;
  document.images.photo_huge.src = image_path_array[current_images];
 // document.images.photo_large.src = image_path_array[current_images].replace('huge', 'large');
  document.getElementById('next').style.display = 'block';
}
function next () {
  last(current_images);
  current_images = current_images + 1;
  document.images.photo_huge.src = image_path_array[current_images];
 // document.images.photo_large.src = image_path_array[current_images].replace('huge', 'large');
  document.getElementById('previous').style.display = 'block';
}
function openCItNow(url) {
  window.open("http://www.citnow.co.uk/citnow/holdcroft/honda/stoke/welcome.html?" + url, "", "width=1024, height=568, resizable=no");
}
