function check_data(oButton) {

	var oForm = document.getElementById('form1');

	if (oPrice = document.getElementById('price_from')) {
		if (oPrice.value != "" && (isNaN(oPrice.value) || oPrice.value < 1)) {
			alert(messages[2]);
			oPrice.focus();
			oPrice.style.background = error_color;
			return 0;
		} else {
			oPrice.style.background = '#FFFFFF';
		}

		oPrice = document.getElementById('price_to');
		if (oPrice.value != "" && (isNaN(oPrice.value) || oPrice.value < 1)) {
			alert(messages[2]);
			oPrice.focus();
			oPrice.style.background = error_color;
			return 0;
		} else {
			oPrice.style.background = '#FFFFFF';
		}
	}


	if (oPlaces = document.getElementById('places_from')) {
		if (oPlaces.value != "" && (isNaN(oPlaces.value) || oPlaces.value < 1)) {
			alert(messages[3]);
			oPlaces.focus();
			oPlaces.style.background = error_color;
			return 0;
		} else {
			oPlaces.style.background = '#FFFFFF';
		}

		oPlaces = document.getElementById('places_to');
		if (oPlaces.value != "" && (isNaN(oPlaces.value) || oPlaces.value < 1)) {
			alert(messages[3]);
			oPlaces.focus();
			oPlaces.style.background = error_color;
			return 0;
		} else {
			oPlaces.style.background = '#FFFFFF';
		}
	}

	if (oLoad = document.getElementById('max_load_from')) {
		if (oLoad.value != "" && (isNaN(oLoad.value) || oLoad.value < 1)) {
			alert(messages[4]);
			oLoad.focus();
			oLoad.style.background = error_color;
			return 0;
		} else {
			oLoad.style.background = '#FFFFFF';
		}

		oLoad = document.getElementById('max_load_to');
		if (oLoad.value != "" && (isNaN(oLoad.value) || oLoad.value < 1)) {
			alert(messages[4]);
			oLoad.focus();
			oLoad.style.background = error_color;
			return 0;
		} else {
			oLoad.style.background = '#FFFFFF';
		}
	}

	if (oVolume = document.getElementById('volume_from')) {
		if (oVolume.value != "" && (isNaN(oVolume.value) || oVolume.value < 1)) {
			alert(messages[5]);
			oVolume.focus();
			oVolume.style.background = error_color;
			return 0;
		} else {
			oVolume.style.background = '#FFFFFF';
		}

		oVolume = document.getElementById('volume_to');
		if (oVolume.value != "" && (isNaN(oVolume.value) || oVolume.value < 1)) {
			alert(messages[5]);
			oVolume.focus();
			oVolume.style.background = error_color;
			return 0;
		} else {
			oVolume.style.background = '#FFFFFF';
		}
	}

	if (oHeight = document.getElementById('height_from')) {
		if (oHeight.value != "" && (isNaN(oHeight.value) || oHeight.value < 1)) {
			alert(messages[8]);
			oHeight.focus();
			oHeight.style.background = error_color;
			return 0;
		} else {
			oHeight.style.background = '#FFFFFF';
		}

		oHeight = document.getElementById('height_to');
		if (oHeight.value != "" && (isNaN(oHeight.value) || oHeight.value < 1)) {
			alert(messages[8]);
			oHeight.focus();
			oHeight.style.background = error_color;
			return 0;
		} else {
			oHeight.style.background = '#FFFFFF';
		}
	}

	if (oHours = document.getElementById('hours_from')) {
		if (oHours.value != "" && (isNaN(oHours.value) || oHours.value < 1)) {
			alert(messages[7]);
			oHours.focus();
			oHours.style.background = error_color;
			return 0;
		} else {
			oHours.style.background = '#FFFFFF';
		}

		oHours = document.getElementById('hours_to');
		if (oHours.value != "" && (isNaN(oHours.value) || oHours.value < 1)) {
			alert(messages[7]);
			oHours.focus();
			oHours.style.background = error_color;
			return 0;
		} else {
			oHours.style.background = '#FFFFFF';
		}
	}

	if (oDepth = document.getElementById('depth_from')) {
		if (oDepth.value != "" && (isNaN(oDepth.value) || oDepth.value < 1)) {
			alert(messages[9]);
			oDepth.focus();
			oDepth.style.background = error_color;
			return 0;
		} else {
			oDepth.style.background = '#FFFFFF';
		}

		oDepth = document.getElementById('depth_to');
		if (oDepth.value != "" && (isNaN(oDepth.value) || oDepth.value < 1)) {
			alert(messages[9]);
			oDepth.focus();
			oDepth.style.background = error_color;
			return 0;
		} else {
			oDepth.style.background = '#FFFFFF';
		}
	}

	if (oWidth = document.getElementById('width_from')) {
		if (oWidth.value != "" && (isNaN(oWidth.value) || oWidth.value < 1)) {
			alert(messages[10]);
			oWidth.focus();
			oWidth.style.background = error_color;
			return 0;
		} else {
			oWidth.style.background = '#FFFFFF';
		}

		oWidth = document.getElementById('width_to');
		if (oWidth.value != "" && (isNaN(oWidth.value) || oWidth.value < 1)) {
			alert(messages[10]);
			oWidth.focus();
			oWidth.style.background = error_color;
			return 0;
		} else {
			oWidth.style.background = '#FFFFFF';
		}
	}

	if (oLength = document.getElementById('length_from')) {
		if (oLength.value != "" && (isNaN(oLength.value) || oLength.value < 1)) {
			alert(messages[11]);
			oLength.focus();
			oLength.style.background = error_color;
			return 0;
		} else {
			oLength.style.background = '#FFFFFF';
		}

		oLength = document.getElementById('length_to');
		if (oLength.value != "" && (isNaN(oLength.value) || oLength.value < 1)) {
			alert(messages[11]);
			oLength.focus();
			oLength.style.background = error_color;
			return 0;
		} else {
			oLength.style.background = '#FFFFFF';
		}
	}

	if (oMass = document.getElementById('mass_from')) {
		if (oMass.value != "" && (isNaN(oMass.value) || oMass.value < 1)) {
			alert(messages[12]);
			oMass.focus();
			oMass.style.background = error_color;
			return 0;
		} else {
			oMass.style.background = '#FFFFFF';
		}

		oMass = document.getElementById('mass_to');
		if (oMass.value != "" && (isNaN(oMass.value) || oMass.value < 1)) {
			alert(messages[12]);
			oMass.focus();
			oMass.style.background = error_color;
			return 0;
		} else {
			oMass.style.background = '#FFFFFF';
		}
	}

	if (oBeds = document.getElementById('beds_from')) {
		if (oBeds.value != "" && (isNaN(oBeds.value) || oBeds.value < 1)) {
			alert(messages[13]);
			oBeds.focus();
			oBeds.style.background = error_color;
			return 0;
		} else {
			oBeds.style.background = '#FFFFFF';
		}

		oBeds = document.getElementById('beds_to');
		if (oBeds.value != "" && (isNaN(oBeds.value) || oBeds.value < 1)) {
			alert(messages[13]);
			oBeds.focus();
			oBeds.style.background = error_color;
			return 0;
		} else {
			oBeds.style.background = '#FFFFFF';
		}
	}

	oForm.submit();

}

function check_input(oButton) {

	var error = 0;
	var focus_object;

	var oForm = document.getElementById('form1');

	var oBrand = document.getElementById('brand_id');
	var oPrice = document.getElementById('price');
	var oYear = document.getElementById('year');
	var oRegion = document.getElementById('region_id');
	var oPhone = document.getElementById('phone');
	var oPhone2 = document.getElementById('phone2');
	var oMobile = document.getElementById('mobile');
	var oFax = document.getElementById('fax');
	var oEmail = document.getElementById('email');

	if (oEmail.value != "" && !isValidEmail(oEmail.value)) {
		show_error_div(messages[11], 'div_email');
		focus_object = oEmail;
		error = 1;
	} else {
		hide_error_div('div_email');
	}
	
	if ((oFax.value != "" && !isValidPhone(oFax.value))) {
		show_error_div(messages[33], 'div_fax');
		focus_object = oFax;
		error = 1;
	} else {
		hide_error_div('div_fax');
	}
	
	if ((oMobile.value != "" && !isValidPhone(oMobile.value))) {
		show_error_div(messages[32], 'div_mobile');
		focus_object = oMobile;
		error = 1;
	} else {
		hide_error_div('div_mobile');
	}

	if ((oPhone.value == "" || !isValidPhone(oPhone.value))) {
		show_error_div(messages[10], 'div_phone');
		focus_object = oPhone;
		error = 1;
	} else {
		hide_error_div('div_phone');
	}

	if ((oPhone2.value != "" && !isValidPhone(oPhone2.value))) {
		show_error_div(messages[10], 'div_phone2');
		focus_object = oPhone2;
		error = 1;
	} else {
		hide_error_div('div_phone2');
	}

	if (oRegion.value < 1) {
		show_error_div(messages[9], 'div_region');
		focus_object = oRegion;
		error = 1;
	} else {
		hide_error_div('div_region');
	}

	if (oPrice.value == "" || isNaN(oPrice.value) || oPrice.value < 0) {
		show_error_div(messages[6], 'div_price');
		focus_object = oPrice;
		error = 1;
	} else {
		hide_error_div('div_price');
	}

	if (oYear.value < 1) {
		show_error_div(messages[7], 'div_year');
		focus_object = oYear;
		error = 1;
	} else {
		hide_error_div('div_year');
	}

	if (oEngineCount = document.getElementById('engine_count')) {
		if (oEngineCount.value < 1) {
			show_error_div(messages[21],'div_engine_count');
			focus_object = oEngineCount;
			error = 1;
		} else {
			hide_error_div('div_engine_count');
		}
	}

	if (oCategory = document.getElementById('category_id')) {
		if (oCategory.value < 1) {
			show_error_div(messages[5], 'div_category');
			focus_object = oCategory;
			error = 1;
		} else {
			hide_error_div('div_category');
		}
	}

	if (oMaterial = document.getElementById('material_id')) {
		if (oMaterial.value < 1) {
			show_error_div(messages[22], 'div_material');
			focus_object = oMaterial;
			error = 1;
		} else {
			hide_error_div('div_material');
		}
	}

	if (oVolume = document.getElementById('volume')) {
		if (oVolume.value == "" || isNaN(oVolume.value) || oVolume.value < 1) {
			show_error_div(messages[17], 'div_volume');
			focus_object = oVolume;
			error = 1;
		} else {
			hide_error_div('div_volume');
		}
	}

	if (oLength = document.getElementById('length')) {
		if (oLength.value == "" || isNaN(oLength.value) || oLength.value < 1) {
			show_error_div(messages[23], 'div_length');
			focus_object = oLength;
			error = 1;
		} else {
			hide_error_div('div_length');
		}
	}

	if (oWidth = document.getElementById('width')) {
		if (oWidth.value == "" || isNaN(oWidth.value) || oWidth.value < 1) {
			show_error_div(messages[24], 'div_width');
			focus_object = oWidth;
			error = 1;
		} else {
			hide_error_div('div_width');
		}
	}

	if (oDepth = document.getElementById('depth')) {
		if (oDepth.value == "" || isNaN(oDepth.value) || oDepth.value < 1) {
			show_error_div(messages[25], 'div_depth');
			focus_object = oDepth;
			error = 1;
		} else {
			hide_error_div('div_depth');
		}
	}

	if (oCooling = document.getElementById('cooling_id')) {
		if (oCooling.value < 1) {
			show_error_div(messages[16], 'div_cooling');
			focus_object = oCooling;
			error = 1;
		} else {
			hide_error_div('div_cooling');
		}
	}

	if (oEngineType = document.getElementById('engine_type')) {
		if (oEngineType.value < 1) {
			show_error_div(messages[18], 'div_engine_type');
			focus_object = oEngineType;
			error = 1;
		} else {
			hide_error_div('div_engine_type');
		}
	}

	if (oShafts = document.getElementById('shaft')) {
		if (oShafts.value < 1) {
			show_error_div(messages[30], 'div_shaft');
			focus_object = oShafts;
			error = 1;
		} else {
			hide_error_div('div_shaft');
		}
	}

	if (oKilometers = document.getElementById('kilometers')) {
		if (oKilometers.value == "" || isNaN(oKilometers.value) || oKilometers.value < 0) {
			show_error_div(messages[8], 'div_kilometers');
			focus_object = oKilometers;
			error = 1;
		} else {
			hide_error_div('div_kilometers');
		}
	}

	if (oHeight = document.getElementById('height')) {
		if (oHeight.value == "" || isNaN(oHeight.value) || oHeight.value < 1) {
			show_error_div(messages[19], 'div_height');
			focus_object = oHeight;
			error = 1;
		} else {
			hide_error_div('div_height');
		}
	}

	if (oMass = document.getElementById('mass')) {
		if (oMass.value == "" || isNaN(oMass.value) || oMass.value < 1) {
			show_error_div(messages[20], 'div_mass');
			focus_object = oMass;
			error = 1;
		} else {
			hide_error_div('div_mass');
		}
	}

	if (oBeds = document.getElementById('beds_count')) {
		if (oBeds.value == "" || isNaN(oBeds.value) || oBeds.value < 1) {
			show_error_div(messages[26], 'div_beds');
			focus_object = oBeds;
			error = 1;
		} else {
			hide_error_div('div_beds');
		}
	}

	if (oLoad = document.getElementById('max_load')) {
		if (oLoad.value == "" || isNaN(oLoad.value) || oLoad.value < 1) {
			show_error_div(messages[12], 'div_max_load');
			focus_object = oLoad;
			error = 1;
		} else {
			hide_error_div('div_max_load');
		}
	}

	if (oPlaces = document.getElementById('places')) {
		if (oPlaces.value != "" && isNaN(oPlaces.value) || oPlaces.value < 1) {
			show_error_div(messages[13], 'div_places');
			focus_object = oPlaces;
			error = 1;
		} else {
			hide_error_div('div_places');
		}
	}

	if (oHpower = document.getElementById('hpower')) {
		if (oHpower.value != "" && (isNaN(oHpower.value) || oHpower.value > 9999 || oHpower.value < 1)) {
			show_error_div(messages[14], 'div_hpower');
			focus_object = oHpower;
			error = 1;
		} else {
			hide_error_div('div_hpower');
		}
	}

	if (oHours = document.getElementById('hours')) {
		if (oHours.value == "" || isNaN(oHours.value) || oHours.value < 1) {
			show_error_div(messages[15], 'div_hours');
			focus_object = oHours;
			error = 1;
		} else {
			hide_error_div('div_hours');
		}
	}

	if (oGear = document.getElementById('gear_id')) {
		if (oGear.value < 1) {
			show_error_div(messages[4], 'div_gear');
			focus_object = oGear;
			error = 1;
		} else {
			hide_error_div('div_gear');
		}
	}

	if (oEngine = document.getElementById('engine_id')) {
		if (oEngine.value < 1) {
			show_error_div(messages[3], 'div_engine');
			focus_object = oEngine;
			error = 1;
		} else {
			hide_error_div('div_engine');
		}
	}

	if (oModel = document.getElementById('model_id')) {
		if (oModel.value == "-1" || oModel.value == "") {
			show_error_div(messages[2], 'div_model');
			focus_object = oModel;
			error = 1;
		} else {
			hide_error_div('div_model');
		}
	}

	if (oBrand.value == "" || oBrand.value == "-1") {
		show_error_div(messages[1], 'div_brand');
		focus_object = oBrand;
		error = 1;
	} else {
		hide_error_div('div_brand');
	}
	
	if (error) {
		focus_object.focus();
		return 0;
	}


	//no errors, submit form
	oButton.disabled=true;
	if (oButton.getAttribute('id') == "preview") {
		var reCategory = /(publish_)([a-z]+)(_submit)/;
		reCategory.test(oForm.action);
		var old_action = oForm.action;
		oForm.action = "index.php?action=preview_" + RegExp.$2;
		oButton.disabled=false;
	}

	oForm.submit();
	oForm.action = old_action;

}
