var ajax = createAjaxObject();
var style = checkBrowser();



function is_numeric(expression) {

	var nums = "0123456789";
	
	if (expression.length==0)
		return(false);
	
	for (var n=0; n < expression.length; n++){
	
		if(nums.indexOf(expression.charAt(n))==-1)
			return(false);
	}
	
	return(true);

}


function n_rotateImage(id_img, dir, tempSessionId) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=n_rotateImage&id_img=' +id_img+ '&dir=' +dir+ '&tempSessionId=' +tempSessionId;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			n_displayAllPictures(tempSessionId);
		
		}
	
	}

}

function r_rotateImage(id_img, dir, id_dealer,id_contact,id_listing) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=r_rotateImage&id_img=' +id_img+ '&dir=' +dir+ '&id_dealer=' +id_dealer+'&id_contact='+id_contact+'&id_listing='+id_listing;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			r_displayAllPictures(id_listing,id_dealer,id_contact);
		
		}
	
	}

}


function c_rotateImage(id_img, dir, tempSessionId) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=c_rotateImage&id_img=' +id_img+ '&dir=' +dir+ '&tempSessionId=' +tempSessionId;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			c_displayAllPictures(tempSessionId);
		
		}
	
	}

}



function c_reloadForm(tempSessionId) {

	document.getElementById('imageSelection').src="c_form.php?id_check="+tempSessionId;

}

function n_reloadForm() {

	document.getElementById('imageSelection').src="n_form.php";

}

function r_reloadForm() {


	document.getElementById('imageSelection').src="r_form.php";

}

function setStyle() {

	if (parseInt(navigator.appVersion.charAt(0))>=4) {
		
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;		

	}
	
	if(isIE) {
	
		return 'block';
	
	} else {
	
		return 'table-row';
	
	}

}

function createAjaxObject() {

	var ajax;
	try	{
		// Firefox, Opera 8.0+, Safari
		ajax = new XMLHttpRequest();
		
	}	catch (e) {
			
		// Internet Explorer
		try {
			
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		
		}	catch (e) {
				try {
					
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
					
				} catch (e) {
				
					alert("Your browser does not support AJAX!");
					return false;
				
			}
		
		}
		
	}
	
	return ajax;
	
}

function n_displayAllPictures(tempSessionId) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=n_displayAllPictures&tempSessionId=' +tempSessionId;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			resp = ajax.responseText;
			document.getElementById('imageList').innerHTML = resp;
			
		}
	
	}

}

function c_displayAllPictures(id_check) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=c_displayAllPictures&tempSessionId=' +id_check;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
			
			resp = ajax.responseText;
			document.getElementById('imageList').innerHTML = resp;
			
		}
	
	}

}


function r_displayAllPictures(id_listing, id_dealer, id_contact) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	postVars = 'action=r_displayAllPictures&id_listing=' +id_listing+ '&id_dealer=' +id_dealer+ '&id_contact=' +id_contact;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
			
			resp = ajax.responseText;
			document.getElementById('imageList').innerHTML = resp;
			
		}
	
	}

}

function n_deleteImage(id_img, tempSessionId) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=n_deleteImage&id_img=' +id_img+ '&';

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			n_reloadForm();
		
		}
	
	}

}

function c_deleteImage(id_img, tempSessionId) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=c_deleteImage&id_img=' +id_img+ '&';

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			c_reloadForm(tempSessionId);
		
		}
	
	}

}


function r_deleteImage(id_img, id_dealer, id_contact) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=r_deleteImage&id_img=' +id_img+ '&id_dealer=' +id_dealer+ '&id_contact=' +id_contact;
	
	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			r_reloadForm();
		
		}
	
	}

}


function sequence(id_img, dir) {

		document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=sequence&id_img=' +id_img+ '&direction=' +dir;

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			displayAllPictures();
		
		}
	
	}

}


function n_setFeaturedImage(id_img, tempSessionId) {

		document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=n_setFeaturedImage&id_img=' +id_img+ '&tempSessionId=' +tempSessionId;

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			n_displayAllPictures(tempSessionId);
		
		}
	
	}

}

function c_setFeaturedImage(id_img, id_check) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=c_setFeaturedImage&id_img=' +id_img+ '&tempSessionId=' +id_check;

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			c_displayAllPictures(id_check);
		
		}
	
	}

}


function r_setFeaturedImage(id_img, id_listing, id_dealer, id_contact) {

	document.getElementById('imageList').innerHTML = "<table style='width: 100%; height: 100%; text-align: center'><tr><td><img src='uploader/images/preloader.gif' /></td></tr></table>";

	var postVars = 'action=r_setFeaturedImage&id_img=' +id_img+ '&id_listing=' +id_listing+ '&id_dealer=' +id_dealer+ '&id_contact=' +id_contact;

	ajax.open('POST', 'server.php', true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(postVars);
	
	ajax.onreadystatechange = function() {
	
		if(ajax.readyState == 4) {
		
			r_displayAllPictures(id_listing, id_dealer, id_contact);
		
		}
	
	}

}




function checkBrowser() {

	if (parseInt(navigator.appVersion.charAt(0))>=4) {
		
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;		

	}
	
	if(isIE) {
	
		return 'ie';
	
	} else {
	
		return 'ff';
	
	}

}
	
	
function editPassword() {

	document.getElementById('cp1').style.display = 'none';
	document.getElementById('cp2').style.display = 'none';
	
	var check = checkBrowser();
	
	if(check == 'ie') {
	
		document.getElementById('cp3').style.display = 'block';
		document.getElementById('cp4').style.display = 'block';
		document.getElementById('cp5').style.display = 'block';
		
	} else {
	
		document.getElementById('cp3').style.display = 'table-row';
		document.getElementById('cp4').style.display = 'table-row';
		document.getElementById('cp5').style.display = 'table-row';
	
	}

}


function numeric_digit(field) {

  field.value=field.value.toUpperCase().replace(/([^0-9A-Z])/g,"");
	

}

function numeric_only(field) {

  //validity of a number

  var e1 = new RegExp("^[0-9]+\?$");


  if (!e1.test(field.value)) {

      var newnum = new String();

      var boolean = true;

      for (var i=0 ; i < field.value.length ; i++) {

          if (field.value.charAt(i).match(new RegExp("[0-9]"))) {

              newnum = newnum + field.value.charAt(i);

          }

      }

      field.value = newnum;

  }

}

function numeric(field) {

  //validity of a number

  var e1 = new RegExp("^[0-9]+\\.?$");

  var e2 = new RegExp("^[0-9]*\\.?[0-9]+$");

  if (!e1.test(field.value) && !e2.test(field.value)) {

      var newnum = new String();

      var boolean = true;

      for (var i=0 ; i < field.value.length ; i++) {

          if (field.value.charAt(i).match(new RegExp("[0-9]"))) {

              newnum = newnum + field.value.charAt(i);

          } else if (((field.value.charAt(i)==",") || (field.value.charAt(i)==".")) && boolean) {

              boolean = false;

              newnum = newnum + ".";

          }

      }

      field.value = newnum;

  }

}

function validate_silent() {

	var check = 1;
	
	if(document.fg_form.MakeID.options[document.fg_form.MakeID.selectedIndex].value == "") {
	
		check = 0;
	
	}
	
	if(document.fg_form.ModelID.options[document.fg_form.ModelID.selectedIndex].value == "") {
	
		check = 0;

	}

	if (!OnlyFromJato) {
		
		if(document.fg_form.variant.value == "") {
	
		check = 0;

		}
		
	}
	
	if(document.fg_form.body.value == "") {
	
		check = 0;

	}

	if(document.fg_form.year.value == "") {
	
		check = 0;
	
	}

	if(document.fg_form.price.value == "") {
	
		check = 0;

	}

	if(document.fg_form.doors.options[document.fg_form.doors.selectedIndex].value == "") {
	
		check = 0;

	}
	
	if(document.fg_form.fuel.value == "") {
	
		check = 0;

	}

	if(document.fg_form.mileage.value == "") {
	
		check = 0;

	}
	
	if(document.fg_form.colour.value == "") {
	
		check = 0;

	}
		
	if(document.fg_form.capacity.value == "") {
	
		check = 0;

	}

	if(document.fg_form.transmission.options[document.fg_form.transmission.selectedIndex].value == 0) {
	
		check = 0;

	}

	if(document.fg_form.owners.options[document.fg_form.owners.selectedIndex].value == "") {
	
		check = 0;

	}

	if(check == 0) {
			
		return false;
	
	}
	else {
	
		return true;

	}

}


function validate() {
	
	var mssg = "The following information is missing:";
	var check = 1;
	
	if(document.fg_form.MakeID.options[document.fg_form.MakeID.selectedIndex].value == "") {
	
		mssg = mssg + "\n Make";
		check = 0;
	
	}
	
	if(document.fg_form.ModelID.options[document.fg_form.ModelID.selectedIndex].value == "") {
	
		mssg = mssg + "\n Model";
		check = 0;

	}

	if (!OnlyFromJato) {
		
		if(document.fg_form.variant.value == "") {
	
		mssg = mssg + "\n Variant";
		check = 0;

		}
		
	}
	
	if(document.fg_form.body.value == "") {
	
		mssg = mssg + "\n Body";
		check = 0;

	}

	if(document.fg_form.year.value == "") {
	
		mssg = mssg + "\n Year";
		check = 0;
	
	}

	if(document.fg_form.price.value == "") {
	
		mssg = mssg + "\n Price";
		check = 0;

	}

	if(document.fg_form.doors.options[document.fg_form.doors.selectedIndex].value == "") {
	
		mssg = mssg + "\n Doors";
		check = 0;

	}
	
	if(document.fg_form.fuel.value == "") {
	
		mssg = mssg + "\n Fuel";
		check = 0;

	}

	if(document.fg_form.mileage.value == "") {
	
		mssg = mssg + "\n Mileage";
		check = 0;

	}
	
	if(document.fg_form.colour.value == "") {
	
		mssg = mssg + "\n Colour";
		check = 0;

	}
		
	if(document.fg_form.capacity.value == "") {
	
		mssg = mssg + "\n Capacity";
		check = 0;

	}

	if(document.fg_form.transmission.options[document.fg_form.transmission.selectedIndex].value == 0) {
	
		mssg = mssg + "\n Transmission";
		check = 0;

	}

	if(document.fg_form.owners.options[document.fg_form.owners.selectedIndex].value == "") {
	
		mssg = mssg + "\n Owners";
		check = 0;

	}

	if(check == 0) {
	
		//l = mssg.length;
		//l = l - 2;
		
		//mssg = mssg.substr(0, l);
		mssg = mssg + ".";
		mssg = mssg + "\n\nAre you sure you want to continue?";
			
		if (confirm(mssg))
      return true;
    else
      return false;
	
	}
	else {
	
		return true;

	}

}


function changeType(type) {

	alert(type);
	document.fg_form.typeOfSubmission.value = type;
	alert(document.fg_form.typeOfSubmission.value);

}


// Peter Crowley, WebZone Limited 17/01/2002

// MacroMedia stuff
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// WebZone select fill stuff

function WZ_fillChild(theArray,thisField, selectedParentIndex, selectedChildValue, bValues, bHasChildren) {
	if (selectedParentIndex == 0) return; 
	if (bValues) jump=bHasChildren?3:2; else jump=bHasChildren?2:1;
    WZ_showField(theArray[(bValues?3:2)*selectedParentIndex-1], jump, thisField,selectedChildValue, bValues);
}

function WZ_fillParent(theArray,thisField, selectedValue, bValues) {
    WZ_showField(theArray, bValues?3:2, thisField, selectedValue, bValues);
}

function WZ_fillGrandChild(theArray,thisField, selectedGrandParentIndex, GrandParentWidth, selectedParentIndex, ParentWidth, selectedChildValue, thisWidth) {
	if (selectedParentIndex == 0) return; 
    WZ_showField(theArray[GrandParentWidth*selectedGrandParentIndex-1][ParentWidth*selectedParentIndex-1], thisWidth, thisField,selectedChildValue, false);
}

function WZ_showField(Obj, jump, thisField, selectedValue, bValues) {
	var bSelect, sValue;
	var iOption = 1;

	if (thisField.tagName != 'SELECT')
		return;
    thisField.options.length = 1;
    for (var iArray = 0; iArray < Obj.length-1;iArray+=jump) {
		if (selectedValue && (Obj[iArray] == selectedValue)) bSelect=true; else bSelect=false;
		if (bValues)
			sValue= Obj[iArray+1]; // value is different to text
		else
			sValue= Obj[iArray]; // value is the same as text
    	thisField.options[iOption] = new Option(sValue, Obj[iArray], false, bSelect);
    	iOption++;
    }

	thisField.disabled = false;
}

function WZ_fillMappedGrandChild(theArray,thisField, selectedGrandParentIndex, GrandParentWidth, selectedParentIndex, ParentWidth, selectedChildValue, thisWidth, oText, textWidth) {
	if (selectedParentIndex == 0) return; 
    WZ_showMappedField(theArray[GrandParentWidth*selectedGrandParentIndex-1][ParentWidth*selectedParentIndex-1], thisWidth, thisField,selectedChildValue, oText, textWidth);
}

function WZ_showMappedField(Obj, jump, thisField, selectedValue, oText, textJump) {
	var bSelect;
	var iOption = 1;
	var sText;

	if (thisField.tagName != 'SELECT')
		return;
	thisField.options.length = 1;
	oSelectOption = 0;
	
    for (var iArray = 0; iArray < Obj.length-1;iArray+=jump) {
		if (selectedValue && Obj[iArray] == selectedValue) bSelect=true; else bSelect=false;
		sText=Obj[iArray];
		for (var iText = 0; iText < oText.length-1;iText+=textJump) {
		  if (oText[iText] == sText) {
			oSelectOption = new Option(oText[iText+1],Obj[iArray],bSelect,bSelect);
			break;
		  }
		}
		if (oSelectOption) {
	    	thisField.options[iOption] = oSelectOption;
			iOption++;
		}
    }
	thisField.disabled = false;
}

function WZ_storefield(SelectField,HiddenField) {
	HiddenField.value = SelectField.options[SelectField.selectedIndex].value;
}

function WZ_openWin( windowURL, windowName, windowFeatures ) { 
	return window.open( windowURL, windowName, windowFeatures ) ; 
} 
function openWin( windowURL, windowName, windowFeatures ) { 
	return window.open( windowURL, windowName, windowFeatures ) ; 
} 


// Javascript for used car forms

// Fill a select triplet MakeID, ModelID, ColourID
// Need a matching xMakeID, xModeID and xColour to enable remeber on back feature.
// Note: Colours are mapped from a separate array

function init_makemodelcolour(currentForm) {
  if (window.Option) {
  with (currentForm) {
	if (MakeID.tagName != 'SELECT')
	  WZ_fillChild(MakeModelColourList, ModelID, 1, xModelID.value, true, true);
	else {
	  WZ_fillParent(MakeModelColourList, MakeID, xMakeID.value, true);
	  if (xMakeID.value > 0) {
		WZ_fillChild(MakeModelColourList, ModelID, MakeID.selectedIndex, xModelID.value, true, true);
	  }
	}
    colour_makemodelcolour(currentForm,xColourID.value);
  }
  }
}

function submit_makemodelcolour(currentForm) {
  with (currentForm) {
	if (MakeID.tagName == 'SELECT') WZ_storefield(MakeID, xMakeID);
	WZ_storefield(ModelID, xModelID);
	WZ_storefield(ColourID, xColourID);
  }
}

function colour_makemodelcolour(currentForm,colourValue) {
  with(currentForm) { 
  	if (MakeID.value > 0 && ModelID.value > 0) {
	  WZ_fillMappedGrandChild(MakeModelColourList, ColourID, (MakeID.tagName != 'SELECT')?1:MakeID.selectedIndex, 3, ModelID.selectedIndex, 3, colourValue, 1, BaseColourList, 2);
	} else
	  WZ_showField(BaseColourList, 2, ColourID, colourValue, true);
  }
}

// Fill a select triplet MakeID, ModelID, YearID
// Need a matching xMakeID, xModeID and xYear to enable remeber on back feature.

function init_makemodelyear(currentForm) {
  if (window.Option) {
  with (currentForm) {
	if (MakeID.tagName != 'SELECT')
	  WZ_fillChild(MakeModelYearList, ModelID, 1, xModelID.value, true, true);
	else {
	  WZ_fillParent(MakeModelYearList, MakeID, xMakeID.value, true); 
	  if (xMakeID.value > 0) {
		WZ_fillChild(MakeModelYearList, ModelID, MakeID.selectedIndex, xModelID.value, true, true);
		if (xModelID.value > 0) {
		  WZ_fillGrandChild(MakeModelYearList, Year, MakeID.selectedIndex, 3, ModelID.selectedIndex, 3, xYear.value, 1);
		}
	  }
	}
  }
  }
}

function submit_makemodelyear(currentForm) {
  with (currentForm) {
	if (MakeID.tagName == 'SELECT') WZ_storefield(MakeID, xMakeID);
	WZ_storefield(ModelID, xModelID);
	WZ_storefield(Year, xYear);
  }
}

// Fill a select couple MakeID and ModelID
// Need a matching xMakeID and xModeID to enable remeber on back feature.

function init_makemodel(currentForm) {
  if (window.Option) {
  with (currentForm) {


	if (MakeID.tagName != 'SELECT')
	  WZ_fillChild(MakeModelList, ModelID, 1, xModelID.value, true, false);
	else {
	  WZ_fillParent(MakeModelList, MakeID, xMakeID.value, true); 
	  if (xMakeID.value > 0) {
		WZ_fillChild(MakeModelList, ModelID, MakeID.selectedIndex, xModelID.value, true, false);
	  }
	}
  }
  }
}

function submit_makemodel(currentForm) {
  with (currentForm) {
	if (MakeID.tagName == 'SELECT') WZ_storefield(MakeID, xMakeID);
	WZ_storefield(ModelID, xModelID);
  }
}

// Javascript for dealer forms

// Fill a select pair CountyID, BusinessID
// Need a matching xCountyID and xBusinessID to enable remeber on back feature.

function init_countygarage(currentForm,showGarage) {
  if (window.Option) {
  with (currentForm) {
	WZ_fillParent(CountyGarageList, CountyID, xCountyID.value, true);
	if (xCountyID.value > 0) {
		WZ_fillChild(CountyGarageList, BusinessID, CountyID.selectedIndex, xBusinessID.value, true, false);
	} else {
	    if (showGarage)
			WZ_showField(GarageList, 2, BusinessID, xBusinessID.value, true);
	}
  }
  }
}

function business_countygarage(currentForm,showGarage) {
  if (window.Option) {
  with (currentForm) {
    if (CountyID.selectedIndex == 0 && showGarage)
		WZ_showField(GarageList, 2, BusinessID, xBusinessID.value, true);
	else
		WZ_fillChild(CountyGarageList, BusinessID, CountyID.selectedIndex, 1, true, false);
  }
  }
}

function submit_countygarage(currentForm) {
  with (currentForm) {
	WZ_storefield(CountyID, xCountyID);
	WZ_storefield(BusinessID, xBusinessID);
  }
}

// Javascript for new car forms

// Fill a select triplet make, Model, Body
// Need a matching xMake, xMode and xBody to enable remeber on back feature.
// Note: BodyType is mapped from a separate array

function init_makemodelbody(currentForm, MakeModelBodyList) {
  if (window.Option) {
	with (currentForm) {
	  WZ_fillParent(MakeModelBodyList, make, xMake.value, false);
	  if (xMake.value != "")
		WZ_fillChild(MakeModelBodyList, model, make.selectedIndex, xModel.value, false, true);
	  body_makemodelbody(currentForm, MakeModelBodyList, xBody.value);
	}
  }
}

function submit_makemodelbody(currentForm) {
  with (currentForm) {
	if (make.selectedIndex==0 && Body.selectedIndex==0) {
		alert('You are searching for a new car. Please make at least one selection in tbe new car table.');
		return false;
	} else {
		// Remember dynamic options for 'back'
		WZ_storefield(make, xMake);
		WZ_storefield(model, xModel);
		WZ_storefield(Body, xBody);
		return true;
	}
  }
  return false;
}

function body_makemodelbody(currentForm, MakeModelBodyList, bodyValue) {
  with(currentForm) {
	if (make.value != "" && model.value != "")
	  WZ_fillMappedGrandChild(MakeModelBodyList, Body, make.selectedIndex, 2, model.selectedIndex, 2, bodyValue, 1, BodyTypeList, 3);
	else
	  WZ_showField(BodyTypeList, 3, Body, bodyValue, true);
  }
}

function in_array (obj,this2) {

  var len = this2.length;
  var x = 0;
  var wordslol = new Array();
  var wordlol = '';

  // Whole text
  //alert(x + '/' + len + ' : ' + this2[x].text.toUpperCase() + ' = ' + obj.toUpperCase() + ' ?');

  for (x=0;x<len;x++) {
    
    if (this2[x].text.toUpperCase() == obj.toUpperCase()) {
      //alert("match full");
      return x;
    }

  }
  
  for (x=0;x<len;x++) {
        
    wordslol = obj.split(' ');
    wordlol = wordslol[0];
    
    if (this2[x].text.toUpperCase() == wordlol.toUpperCase()) {
      //alert("match 1st word");
      return x;
    }
    
  }
  
  for (x=0;x<len;x++) {

    if (this2[x].text.toUpperCase().substr(0,4) == obj.toUpperCase().substr(0,4)) {
      //alert("match 4th first");
      return x;
    }
    
  }

  return false;
}
  

  


function in_array_first_four (obj,this2) {

  var len = this2.length;
  var x;

  for (x=0;x<=len;x++) {
    
    if (this2[x].text.toUpperCase().substr(0,4) == obj.toUpperCase().substr(0,4))
      return x;
  }
  
  return false;
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function select_make(make_name)
{	
	if(in_array_first_four(make_name,document.fg_form.MakeID.options)>=0) document.fg_form.MakeID.options[in_array_first_four(make_name,document.fg_form.MakeID.options)].selected=true;
	
}

function select_model(model_name)
{	

	try {

		if(in_array(model_name,document.fg_form.ModelID.options)>=0) document.fg_form.ModelID.options[in_array(model_name,document.fg_form.ModelID.options)].selected=true;
	
	} catch(e) {}
	
}


function checkForm(thisform) {


	var mssg = "Required fields:";
	var check = 1;
	
	if(document.fg_form.MakeID.options[document.fg_form.MakeID.selectedIndex].value == "") {
	
		mssg = mssg + "\n Make";
		check = 0;
	
	}
	
	if(document.fg_form.ModelID.options[document.fg_form.ModelID.selectedIndex].value == "") {
	
		mssg = mssg + "\n Model";
		check = 0;

	}

	
	if (document.fg_form.variant.value == "") {
	
		mssg = mssg + "\n Variant";
		check = 0;
	
	}


	if(document.fg_form.mileage.value == "") {
	
		mssg = mssg + "\n Mileage";
		check = 0;

	}
	
	if(document.fg_form.price.value == "") {
	
		mssg = mssg + "\n Price";
		check = 0;

	}
	
	if(document.fg_form.body.options[document.fg_form.body.selectedIndex].value == "") {	
		mssg = mssg + "\n Body";
		check = 0;

	}

	if(document.fg_form.year.value == "") {
	
		mssg = mssg + "\n Year";
		check = 0;
	
	}

	if(document.fg_form.doors.value == "") {
	
		mssg = mssg + "\n Doors";
		check = 0;

	}
	
	if(document.fg_form.fuel.options[document.fg_form.fuel.selectedIndex].value == "") {	
	
		mssg = mssg + "\n Fuel";
		check = 0;

	}

	
	if(document.fg_form.colour.value == "") {
	
		mssg = mssg + "\n Colour";
		check = 0;

	}
		
	if(document.fg_form.capacity.value == "") {
	
		mssg = mssg + "\n Capacity";
		check = 0;

	}

	if(document.fg_form.transmission.options[document.fg_form.transmission.selectedIndex].value == "") {	
	
		mssg = mssg + "\n Transmission";
		check = 0;

	}

	if(document.fg_form.owners.options[document.fg_form.owners.selectedIndex].value == "") {	
	
		mssg = mssg + "\n Owners";
		check = 0;

	}

	
	if (check == 1) mssg = '';
	else (mssg = mssg + '\n\n');
	
	if(confirm(mssg + "Sure?")) {
	
		return true
	
	} else {
	
		return false;
	
	}

}


function valbutton(thisform) {	
// place any other field validations that you require here
if (thisform.per_forename.value.length==0)
		{
			window.alert("Please enter your Name!");
			thisform.per_forename.focus();
		    thisform.per_forename.select();
			return false;
		}
if (thisform.per_email.value.length==0)
		{
			window.alert("Please enter your Email!");
			thisform.per_email.focus();
		    thisform.per_email.select();
			return false;
		}
if (thisform.per_email.value.indexOf(".")==-1 || thisform.per_email.value.indexOf("@")==-1 )
		{
			window.alert("Please enter a valid email address!");
			thisform.per_email.focus();
		    thisform.per_email.select();
			return false;
		}
if (thisform.odometer_reading.value.length==0 || thisform.odometer_reading.value!=parseInt(thisform.odometer_reading.value))
{
			window.alert("Please enter an odometer reading (numbers only please)!");
			thisform.odometer_reading.focus();
		    thisform.odometer_reading.select();
			return false;
}
if(thisform.odometer_reading.value!='' && thisform.odometer_reading.value<2000)
	{
		if(confirm('Are you sure that the odometer reading is so low ('+thisform.odometer_reading.value+' '+thisform.odometer_type.value+' only).'));
		else return false;	
	}		
if (thisform.price.value.length==0)
		{
			window.alert("Please enter a Reserve Price!");
			thisform.price.focus();
		    thisform.price.select();
			return false;
		}
// validate myradiobuttons
myOption = -1;
for (i=0; i<thisform.garda.length; i++) {
if (thisform.garda[i].checked) {
myOption = i;
}
}
if (myOption == -1) {
alert("Declarations : Has the vehicle been owned by the Gardai");
return false;
}
myOption2 = -1;
for (i=0; i<thisform.write_off.length; i++) {
if (thisform.write_off[i].checked) {
myOption2 = i;
}
}
if (myOption2 == -1) {
alert("Declarations : Has the vehicle been in a Serious Accident");
return false;
}
myOption3 = -1;
for (i=0; i<thisform.damaged.length; i++) {
if (thisform.damaged[i].checked) {
myOption3 = i;
}
}
if (myOption3 == -1) {
alert("Declarations : Any Structural Damage or Major Body Repair");
return false;
}
myOption4 = -1;
for (i=0; i<thisform.taxi.length; i++) {
if (thisform.taxi[i].checked) {
myOption4 = i;
}
}
if (myOption4 == -1) {
alert("Declarations : Been used as a taxi, hackney or private hire");
return false;
}
myOption5 = -1;
for (i=0; i<thisform.finance.length; i++) {
if (thisform.finance[i].checked) {
myOption5 = i;
}
}
if (myOption5 == -1) {
alert("Declarations : Any outstanding hire purchase, lease, encumbrance");
return false;
}
myOption6 = -1;
for (i=0; i<thisform.imported.length; i++) {
if (thisform.imported[i].checked) {
myOption6 = i;
}
}
if (myOption6 == -1) {
alert("Declarations : Re-registered or imported");
return false;
}
myOption7 = -1;
for (i=0; i<thisform.water_damaged.length; i++) {
if (thisform.water_damaged[i].checked) {
myOption7 = i;
}
}
if (myOption7 == -1) {
alert("Declarations : Water Damaged");
return false;
}
myOption8 = -1;
for (i=0; i<thisform.engine.length; i++) {
if (thisform.engine[i].checked) {
myOption8 = i;
}
}
if (myOption8 == -1) {
alert("Mechanical Condition : Is the Engine ok?");
return false;
}
if(thisform.engine_det.value.length==0 && thisform.engine_not_ok.checked) 
{
	alert('Please describe the problem with the Engine.');
	return false;
}


myOption9 = -1;
for (i=0; i<thisform.gearbox.length; i++) {
if (thisform.gearbox[i].checked) {
myOption9 = i;
}
}
if (myOption9 == -1) {
alert("Mechanical Condition : Is the Gearbox ok?");
return false;
}
if(thisform.gearbox_det.value.length==0 && thisform.gearbox_not_ok.checked) 
{
	alert('Please describe the problem with the Gearbox.');
	return false;
}


myOption10 = -1;
for (i=0; i<thisform.back_axle.length; i++) {
if (thisform.back_axle[i].checked) {
myOption10 = i;
}
}
if (myOption10 == -1) {
alert("Mechanical Condition : Is the Back Axle ok?");
return false;
}
if(thisform.back_axle_det.value.length==0 && thisform.back_axle_not_ok.checked) 
{
	alert('Please describe the problem with the Back Axle.');
	return false;
}

if (
	thisform.ts_cs.checked == false) 
	{
		alert ('You must confirm that you have read the terms and conditions!');
		return false;
}

}

function MM_showHideLayers() 
{ 
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
	if ((obj=MM_findObj(args[i]))!=null) 
	{ 
		v=args[i+2];
		if (obj.style) 
		{ 
			obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
		obj.visibility=v; 
	}
}
var displayduration=0 //duration in seconds image should remain visible. 0 for always.
if (document.getElementById || document.all)
{
	document.write('<div id="trailimageid">');
	document.write('</div>');
}
function gettrailobj()
{
	if (document.getElementById)
	return document.getElementById("trailimageid").style
	else if (document.all)
	return document.all.trailimagid.style
}
function gettrailobjnostyle()
{
	if (document.getElementById)
	return document.getElementById("trailimageid")
	else if (document.all)
	return document.all.trailimagid
}
function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function hidetrail()
{
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-800px"
}
function followmouse_right(e)
{
	var div_width=document.getElementsByTagName("div")["orans_div"].offsetWidth;
	var div_height=document.getElementsByTagName("div")["orans_div"].offsetHeight;
	var width_offset = div_width/2;
	width_offset = -width_offset;
	var height_offset = div_height+50;
	height_offset = -height_offset;
	
	var xcoord=width_offset
	var ycoord=height_offset
	
	if (typeof e != "undefined")
	{
		xcoord+=e.pageX
		ycoord+=e.pageY
	}
	else if (typeof window.event !="undefined")
	{
		xcoord+=truebody().scrollLeft+event.clientX
		ycoord+=truebody().scrollTop+event.clientY
	}
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
function showtrail_right(imagename,title,img_width,img_height)
{

  document.onclick=followmouse_right;
	document.onmousemove=followmouse_right;
	newHTML = '<div style="padding: 0px 5px 5px 5px; background-color: #FFF; border: 1px solid #888; font-family: Arial" id="orans_div">';
	newHTML = newHTML + '<h2>' + title + '</h2>';
	newHTML = newHTML + '<div align="center" style="padding: 2px;">';
	newHTML = newHTML + '<img src="' + imagename + '" border="0"  width="'+img_width+'" height="'+img_height+'"></div>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";

}
