ajax_response	= '';		// Global value to store the respose from Ajax so that it can be used in other functions

/**
 * Submits a query via Ajax and runs a success function if required
 *
 * @return					void
 * @author					Nigel Wells
 * @version					1.0.07.11.09
 * @param function_name		The function that will be called in lib_ajaxrequest.php
 * @param criteria			Criteria to be sent to the php function
 * @param success_function	If set then this function will be called after the Ajax request has been successful
							- The response from Ajax will be stored in a global virable "ajax_response" which can then be accessed from function_name()
 * @param boolAlert			If true then it will alert the response returned from Ajax - Can be useful for debuging
 */
function loadAjaxFunction(function_name, criteria, success_function, boolAlert) {
	var strResponse = '';
	var status = false;

	if(criteria != '') criteria = "&" + criteria;
	AjaxRequest.get(
		{
		  'url':'/includes/inc_ajax.php?ajax_function=' + function_name + criteria
		  ,'onSuccess':function(req){ 
			  var status = true;
			  strResponse = req.responseText; 
			  if(boolAlert === true) alert(strResponse);
			  if(success_function != '') {
				  ajax_response = strResponse;
				  success_function += '()';
				  setTimeout(success_function, 1);
			  }
		  }
		  ,'onError':function(req){ alert(req.responseText + function_name); }
		}
	);
}

function addMyRVLg() {
	if(parseInt(ajax_response) > 0) {
		document.getElementById('id_vehicle_' + ajax_response).innerHTML = '<a href="javascript:loadAjaxFunction(\'removeMyRV\', \'vehicleid=' + ajax_response + '\', \'removeMyRVLg\', false);"><img src="images/button_remove.png" alt="" /></a>';
	} else alert("You need to login or signup first before you can add to your My RV account");
}

function removeMyRVLg() {
	if(parseInt(ajax_response) > 0) {
		document.getElementById('id_vehicle_' + ajax_response).innerHTML = '<a href="javascript:loadAjaxFunction(\'addMyRV\', \'vehicleid=' + ajax_response + '\', \'addMyRVLg\', false);"><img src="images/button_add.png" alt="" /></a>';
	} else alert("You need to login or signup first before you can remove from your My RV account");
}

function addMyRV() {
	if(parseInt(ajax_response) > 0) {
		document.getElementById('id_vehicle_' + ajax_response).innerHTML = '<a href="javascript:loadAjaxFunction(\'removeMyRV\', \'vehicleid=' + ajax_response + '\', \'removeMyRV\', false);"><img src="images/button_remove_small.png" alt="" /></a>';
	} else alert("You need to login or signup first before you can add to your My RV account");
}

function removeMyRV() {
	if(parseInt(ajax_response) > 0) {
		document.getElementById('id_vehicle_' + ajax_response).innerHTML = '<a href="javascript:loadAjaxFunction(\'addMyRV\', \'vehicleid=' + ajax_response + '\', \'addMyRV\', false);"><img src="images/button_add_small.png" alt="" /></a>';
	} else alert("You need to login or signup first before you can remove from your My RV account");
}

function checkEnquire(form) {
	var strErrors = '';
	var intErrors = 0;

	if(form.name.value == '' || form.name.value == 'Name') {
		strErrors += "Name\n";
		intErrors++;
	}
	if(form.email.value == '' || form.email.value == 'Email') {
		strErrors += "Email\n";
		intErrors++;
	} 
	if(form.phone.value == '' || form.phone.value == 'Phone') {
		strErrors += "Phone\n";
		intErrors++;
	}
	if(form.comments.value == '' || form.comments.value == 'Comments') {
		strErrors += "Comments\n";
		intErrors++;
	}

	if(intErrors > 0) {
		alert("There are " + intErrors + " fields incomplete:\n\n" + strErrors);
		return false;
	} else {
		return true;
	}
}