function addEventsAddVehicle() {
	nav_links = document.getElementById('place_ad_nav').getElementsByTagName('li');
	for(i=0; i<nav_links.length; i++) {
		nav_links[i].onclick = function() { 
			document.getElementById('frmNavBar').action = this.getAttribute('frmAction');
			if(document.getElementById('frmNavBar').action != "") {
				document.getElementById('frmNavBar').submit();
			}
		};
	}
	if(document.getElementById('makes') != undefined) {
		document.getElementById('makes').onchange = function() { doAJAX("model",this.value); };
	}
	if(document.getElementById('btnSubmit') != undefined) {
		document.getElementById('btnSubmit').onclick = function() { 
			if(validateVehicleInfo()) {
				submitForm(this); 
			} else {
				window.scrollTo(0,260);
			}
		};
	}
	if(document.getElementById('btnUpload') != undefined) {
		document.getElementById('btnUpload').onclick = function() { submitForm(this); };
	}
}

//Event.observe(window,'load',init,false);
function initPhotos() {
	if(document.getElementById('listContainer') != null) {
		Sortable.create('listContainer',{tag:'div',onUpdate:updateList});
	}
}
function updateList(container) {
	var url = '/placead/includes/photo_ajax_functions.php';
	var params = Sortable.serialize(container.id);
	var ajax = new Ajax.Request(url,{
		method: 'post',
		parameters: params,
		onLoading: function(){$('workingMsg').show()},
		onLoaded: function(){$('workingMsg').hide()}
	});
}

function validateVehicleInfo() {
	msgError = '';
	if(document.getElementById('frmSubmitVehicleData') != undefined) {
		if(document.getElementById('makes').value == 0) {
			msgError = msgError + '<li>You must select a vehicle make.</li>';
		}
		if(document.getElementById('model').value == 0) {
			msgError = msgError + '<li>You must select a vehicle model.</li>';
		}
		if(document.getElementById('auto_year').value == 0) {
			msgError = msgError + '<li>You must select a vehicle year.</li>';
		}
	}
	
	if(msgError == '') {
		return true;
	} else {
		document.getElementById('divValidation').innerHTML = '<div id="error"><h3>Error</h3><ul>' + msgError + '</ul></div>';
		return false;
	}
}

function handleResponse(req) {
	// this function will fire after the ajax request is complete...but we have nothing to do here
}

addLoadEvent(addEventsAddVehicle);
addLoadEvent(initPhotos);