
function enlargeImage(name) {

		newWindow = window.open(name, 'Image', 'width=600,height=750');


}


// 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;
for ( var x = 0 ; x <= len ; x++ ) {
if ( this2[x].text.toUpperCase() == obj.toUpperCase() ) 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)
{	
	document.fg_form.MakeID.options[in_array(make_name,document.fg_form.MakeID.options)].selected=true;
	
}

function select_model(model_name)
{	
	document.fg_form.ModelID.options[in_array(model_name,document.fg_form.ModelID.options)].selected=true;
	
}


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;
}

}

