var $j = jQuery.noConflict();

var serviceSafetyHasVehicle = false;
//-----------------------------------
//Bindings for ymme
//-----------------------------------

//a list of any modal dialog created
var allDialogs = [];
//the currently being used modal always is stored here
var mainDialog;

var doYmmeRefresh = false;

var doRegRefresh = false;

//create a modal overlay for the YMME
function createYMME(options, showbanner, showselect, showregform, callback, showeserve) {
	options = $j.extend({title: "", draggable: false, closable: false, center: true, fixed: false, modal: true, afterHide: function() {
	eval(callback);
	//put stuff to do after ymme close here - use callback somehow
 	 } }, options || {});
	//create a new modal
	var dialog = new Boxy("<div style=\"width: 670px; height: 552px;\"><img src=/images/cat/ajaxlwhite.gif /></div>", options);
	//retrieve the content and fill the modal
	dialog.resize(670,552);

	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

    $j.get("/ymme/ajax/year", "showbanner=" + showbanner + "&showselect=" + showselect + "&showregform=" + showregform + "&showeserve=" + showeserve + "&time=" + tsTimeStamp,  function(data){
    	dialog.setContent("<div style=\"width: 670px; height: 552px;\">"+ data+"</div>");
    	dialog.resize(670,552);
    	dialog.center('x');
        dialog.center('y');
	});

    //add to the dialog list, and set as the current dialog
	allDialogs.push(dialog);
	mainDialog = dialog;
	return false;
}

function ymmeYearClick(makeUrl) {
	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

	$j.get(makeUrl, {time: tsTimeStamp},  function(data){
	  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
	  mainDialog.resize(670,552);
	  mainDialog.center('x');
	  mainDialog.center('y');
    });

	return false;
}

function ymmeMakeClick(modelUrl) {
	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

	$j.get(modelUrl, {time: tsTimeStamp},  function(data){
	  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
	  mainDialog.resize(670,552);
	  mainDialog.center('x');
	  mainDialog.center('y');
    });

	return false;
}

function ymmeModelClick(submodelUrl) {
	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

	$j.get(submodelUrl, {time: tsTimeStamp},  function(data){
	  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
	  mainDialog.resize(670,552);
	  mainDialog.center('x');
	  mainDialog.center('y');
    });

	return false;
}

function ymmeEngineClick(vehicleUrl) {
	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

	$j.get(vehicleUrl, {time: tsTimeStamp},  function(data){
	  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
	  mainDialog.resize(670,552);
	  mainDialog.center('x');
	  mainDialog.center('y');
    });

	return false;
}

function goBack(ymmeBackUrl) {

	mainDialog.setContent("<div style=\"width: 670px; height: 552px;\"><img src=/images/cat/ajaxlwhite.gif /></div>");

	$j.get(ymmeBackUrl, null,  function(data){
		  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
		  mainDialog.resize(670,552);
		  mainDialog.center('x');
		  mainDialog.center('y');
	});

	return false;
}

function submitRegister() {
	$j.post("/ymme/ajax/register", $j("#ymmeRegisterForm").serialize(),
			function(data) {
				$j("#regintYmmeFormbox").html(data);
			});
}

function submitEserve() {
	$j.post("/ymme/ajax/eserve", $j("#ymmeEserveForm").serialize(),
			function(data) {
				$j("#eserveYmmeFormbox").html(data);
			});
}

function ymmeRegisterClick(vehicleUrl) {
	//needed for IE AJAX caching issues
	var tsTimeStamp= new Date().getTime();

	$j.get(vehicleUrl, {time: tsTimeStamp},  function(data){
	  mainDialog.setContent("<div style=\"width: 670px; height: 552px;\">"+data+"</div>");
	  mainDialog.resize(670,552);
	  mainDialog.center('x');
	  mainDialog.center('y');
    });

	return false;
};
