
/** YMMOComponent Class
 * USE: Update dependent select boxes based on user selection and
        results from Ajax calls

        This is an updated MMYO Component
 *
 * NOTES:
 * 1. The ajax functionality is not defined as a privileged method in order to keep it loosely
 *  coupled from the rest of the functionality as there is no need for it to be exposed to private
 *  variables
 *
 */
function YMMOComponent(){

	/**
		YMMO Component Static Variables
		for now leave them as MMYO in the pages
	*/
	YEARS_ID = 'MMYO:years';
	MAKES_ID = 'MMYO:makes';
	MODELS_ID = 'MMYO:models';
	OPTIONS_ID = 'MMYO:options';

	this.YMMO_FIELDS = new Array(YEARS_ID, MAKES_ID, MODELS_ID, OPTIONS_ID);

	//maintain the conversation id between remoting calls
	var conId = null;

	//Variables for the preservation of the current state of the dropdown lists and their selections
	//These are used to save the original state of the dropdowns before they are updated by the Seam
	//Remoting calls.  The onChange event handler for the findTires button restores these values
	//into the DOM before firing the search, in order for the DOM to be in the correct state if the
	//user hits the back button.
	var currentMakeList = null;
	var currentMakeIndex = null;
	var currentModelList = null;
	var currentModelIndex = null;
	var currentYearList = null;
	var currentYearIndex = null;
	var currentOptionsList = null;
	var currentOptionIndex = null;

	DEBUG = false ;

	this.debug = function(debugMessage) {
	//Simple debug message function that uses alerts.  Controlled by setting DEBUG variable to
	//either true to activate debug, or false to deactive debug.
		if (DEBUG) {
			alert(debugMessage);
		}
	}

	function ymmoExists(){
		if (document.getElementById(YEARS_ID) == null){
			return false;
		}
		return true;
	}


	this.init = function(){
		//Verify that a valid MMYO exists for the selections - if not reset the
		//dropdown boxes such that the make will be available to be selected.
		//Do this before any additional validation logic.
		this.debug("YMMO.init() called");
		if (!ymmoExists()){
			return
		}
		if (!this.isYMMOValid()){
			this.debug("YMMO.init() - calling resetLists()");
			this.resetLists();
		}

		//Save the current state of the MMYO select lists; will be used to
		//restore the DOM when the findTires button is pressed.  Restoration is
		//necessary so DOM will be in correct state if the back button is pressed.
		this.currentYearList = this.copyOptions(document.getElementById(YEARS_ID).options);
		this.currentYearIndex = document.getElementById(YEARS_ID).selectedIndex;

		this.currentMakeList = this.copyOptions(document.getElementById(MAKES_ID).options);
		this.currentMakeIndex = document.getElementById(MAKES_ID).selectedIndex;

		this.currentModelList = this.copyOptions(document.getElementById(MODELS_ID).options);
		this.currentModelIndex = document.getElementById(MODELS_ID).selectedIndex;

		this.currentOptionsList = this.copyOptions(document.getElementById(OPTIONS_ID).options);
		this.currentOptionsIndex = document.getElementById(OPTIONS_ID).selectedIndex;

		this.debug("YMMO.init() end");
	}

	this.copyOptions = function(sourceList) {
		//build a new array of options from an existing array
		var result = [];
		for (var i = 0; i<sourceList.length; i++)
		{
			result[i] = new Option(sourceList[i].text, sourceList[i].value);
		}
		return result;
	}

	this.restoreSelectList = function(listObj, sourceOptionArray, selectedIndex){
		//Rebuild the "listObj" select list using the options in the "sourceOptionArray".  Set
		//the selected value to the index value contained in "selectedIndex".
		listObj.disabled = true;
		listObj.length = 0;
		for (var i = 0;i<sourceOptionArray.length;i=i+1)
		{
			//listObj.appendChild(new Element('option', {'value' : sourceOptionArray[i].value }).apppendText(sourceOptionArray[i].text) );
			listObj.options[i] = new Option(sourceOptionArray[i].text, sourceOptionArray[i].value);
		}
		listObj.selectedIndex = selectedIndex;
	}

	this.restoreDOM = function(){
		//Restore the DOM to the correct MMYO state to support the back button; selected MMYO
		//state for next search is already stored server-side by the SEAM remoting calls,
		//so we don't have to worry about posting it.
		this.restoreSelectList(document.getElementById(YEARS_ID), this.currentYearList, this.currentYearIndex);
		this.restoreSelectList(document.getElementById(MAKES_ID), this.currentMakeList, this.currentMakeIndex);
		this.restoreSelectList(document.getElementById(MODELS_ID), this.currentModelList, this.currentModelIndex);
		this.restoreSelectList(document.getElementById(OPTIONS_ID), this.currentOptionsList, this.currentOptionsIndex);
		addUnloadEvent(this.enableYMMO);
		this.debug("restoreDOM: end of list restores");
	}

	this.enableYMMO = function() {
		document.getElementById(YEARS_ID).disabled = false;
		document.getElementById(MAKES_ID).disabled = false;
		document.getElementById(MODELS_ID).disabled = false;
		document.getElementById(OPTIONS_ID).disabled = false;
		//this.debug("enableDOM: end of list enables during onunload");
	}

	this.synchronize = function(){

		this.debug("YMMO.synchronize() called");

		if (!ymmoExists()){
			this.debug("YMMO.synchronize(); returning after ymmoExists() check");
			return
		}

		var yearSelection = document.getElementById(YEARS_ID).value;
		var makeSelection = document.getElementById(MAKES_ID).value;
		var modelSelection = document.getElementById(MODELS_ID).value;
		var optionSelection = document.getElementById(OPTIONS_ID).value;



		this.debug( "synchronize:"+ this.isYMMOValid() );
		if( !this.isYMMOValid() ) {



			// were the form fields set?
			var y = document.getElementById('sYear' );
			this.debug( "synchronize:"+ y );
			if( y ) {
				var yr = document.getElementById('sYear').value;
				var mk = document.getElementById('sMake').value;
				var md = document.getElementById('sModel').value;
				var op = document.getElementById('sOption').value;



                this.debug( this.isValidYMMO( yr, mk, md, op ) );
				if( this.isValidYMMO( yr, mk, md, op ) ){


					yearSelection = yr ;
					makeSelection = mk ;
					modelSelection = md ;
					optionSelection = op ;

					//Now check to see that the MMYO matches what exists on
					this.debug("YMMO.synchronize making updateYMMOInPage call" + yearSelection +","+ makeSelection +","+ modelSelection +","+ optionSelection );

					Seam.Component.getInstance("ymmoInformation").updateYMMOInPage(
						yearSelection, makeSelection, modelSelection, optionSelection,
						this.populateYMMO2.bindObj(ymmoComponent));
				}
				else {
					// we want to take the values from the session if any
					Seam.Component.getInstance("ymmoInformation").updateYMMOFromSession( this.populateYMMO.bindObj(ymmoComponent) );
				}
			}
		} else {

			if( this.isValidYMMO( yearSelection, makeSelection, modelSelection, optionSelection ) ){

				//Now check to see that the MMYO matches what exists on
				this.debug("YMMO.synchronize making validateYMMOInPage call" + yearSelection +","+ makeSelection +","+ modelSelection +","+ optionSelection );
				Seam.Component.getInstance("ymmoInformation").
					validateYMMOInPage(yearSelection, makeSelection, modelSelection, optionSelection,
					this.populateYMMO.bindObj(ymmoComponent));
			}
		}
	}

	this.isValidYMMO = function( yr, mk, md, op ){
		if( yr == null
			|| mk == null
			|| md == null
			|| op == null ){
			return false ;
		}

		if( yr.length == 0
		 	|| mk.length == 0
		 	|| md.length == 0
		 	|| op.length == 0 ){
		 	return false ;
	 	}

	 	if( yr == "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue"
	 		|| mk == "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue"
	 		|| md == "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue"
	 		|| op == "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue" ){
	 		return false ;
	 	}

	 	return true ;


	}

	this.populateYMMO = function( ymmoObject){

		this.debug("AJAX Callback (populateYMMO)"+ ymmoObject[0][0]);

		//If valid or if there is nothing in session then do nothing
		if (ymmoObject[0][0] == 'Valid YMMO' ||
			ymmoObject[0][0] == 'Not in Session'){
			this.debug("AJAX Callback (populateYMMO); not updating");
			return;
		}

		// this.debug("updating");

		var selectedYear = ymmoObject[0][0];
		var selectedMake = ymmoObject[1][0];
		var selectedModel = ymmoObject[2][0];
		var selectedOption = ymmoObject[3][0];

		// this.debug( selectedYear +","+ selectedMake +","+ selectedModel +","+ selectedOption );

		var years = assignFrom2DArray(ymmoObject,0);
		var makes = assignFrom2DArray(ymmoObject,1);
		var models = assignFrom2DArray(ymmoObject,2);
		var options = assignFrom2DArray(ymmoObject,3);

		// this.debug( "update drop downs" );

		// need to do something here
		this.updateMake(makes);
		this.updateModel(models);
		this.updateOptions(options);

		// this.debug( "set selected" );

		document.getElementById(YEARS_ID).selectedIndex=selectedYear;
		document.getElementById(MAKES_ID).selectedIndex=selectedMake;
		document.getElementById(MODELS_ID).selectedIndex=selectedModel;
		document.getElementById(OPTIONS_ID).selectedIndex=selectedOption;
		//this.debug("AJAX Callback (populateYMMO); updating - Make = " + selectedMake + " Model = " +
		//	selectedModel + " Year = " + selectedYear + " Options = " + selectedOption);


	}


	this.populateYMMO2 = function( ymmoObject){

		this.debug("AJAX Callback (populateYMMO2)"+ ymmoObject[0][0]);

		//If valid or if there is nothing in session then do nothing
		if (ymmoObject[0][0] == 'Valid YMMO' ||
			ymmoObject[0][0] == 'Not in Session'){
			this.debug("AJAX Callback (populateYMMO); not updating");
			return;
		}

		// this.debug("updating");

		var selectedYear = ymmoObject[0][0];
		var selectedMake = ymmoObject[1][0];
		var selectedModel = ymmoObject[2][0];
		var selectedOption = ymmoObject[3][0];

		this.debug( selectedYear +","+ selectedMake +","+ selectedModel +","+ selectedOption );

		var years = assignFrom2DArray(ymmoObject,0);
		var makes = assignFrom2DArray(ymmoObject,1);
		var models = assignFrom2DArray(ymmoObject,2);
		var options = assignFrom2DArray(ymmoObject,3);

		// this.debug( "update drop downs" );

		// need to do something here
		this.updateMake(makes);
		this.updateModel(models);
		this.updateOptions(options);

		// this.debug( "set selected" );

		document.getElementById(YEARS_ID).selectedIndex=selectedYear;
		document.getElementById(MAKES_ID).selectedIndex=selectedMake;
		document.getElementById(MODELS_ID).selectedIndex=selectedModel;
		document.getElementById(OPTIONS_ID).selectedIndex=selectedOption;
		this.debug("AJAX Callback (populateYMMO); updating - Make = " + selectedMake + " Model = " +
			selectedModel + " Year = " + selectedYear + " Options = " + selectedOption);

		// try it again
		this.updateOptions(options);
		document.getElementById(OPTIONS_ID).selectedIndex=selectedOption;
		this.updateSelectedOption( 'success' );


	}

	function assignFrom2DArray(mmyoObject, fieldIndex){
		//Assign to one because you actually want the second value in the array
		var i=1;
		var returnValue = new Array();

		while (mmyoObject[fieldIndex][i] != null){
			returnValue[(i-1)] = mmyoObject[fieldIndex][i];
			i=i+1;
		}
		return returnValue;
	}


	this.clearSelectBoxes = function(level) {
		if (level == "make"){
			document.getElementById(MAKES_ID).options.length=1;
			document.getElementById(MAKES_ID).selectedIndex=0;
			document.getElementById(MODELS_ID).options.length=1;
			document.getElementById(MODELS_ID).selectedIndex=0;
			document.getElementById(OPTIONS_ID).options.length=1;
			document.getElementById(OPTIONS_ID).selectedIndex=0;
		}

		if (level == "model"){
			document.getElementById(MODELS_ID).options.length=1;
			document.getElementById(MODELS_ID).selectedIndex=0;
			document.getElementById(OPTIONS_ID).options.length=1;
			document.getElementById(OPTIONS_ID).selectedIndex=0;
		}

		if (level == "option"){
			document.getElementById(OPTIONS_ID).options.length=1;
			document.getElementById(OPTIONS_ID).selectedIndex=0;
		}
	}

	this.updateMake = function(makeList) {
		this.debug("Start updateMakes; remote callback, cid = " + Seam.Remoting.getContext().getConversationId());
		//We always start a new conversation prior to this remote call, so grab and save the id for the nested conversation
		//so that we can use it for the rest of the remote calls
		this.conId = Seam.Remoting.getContext().getConversationId();

		//Handle case where only one item has been returned
		//Set to the current value
		if (makeList.length == 1){

			document.getElementById(MAKES_ID).options[1] = new Option(makeList[0],makeList[0]);
			document.getElementById(MAKES_ID).selectedIndex = 1;

			// Update the models list
			document.getElementById( MODELS_ID).focus();
			this.remoteUpdate("model", document.getElementById(YEARS_ID).value,
				document.getElementById(MAKES_ID).value,
				document.getElementById(MODELS_ID).value );
		} else {
			//More than one returned - update as normal
			for (var i = 0;i<makeList.length;i=i+1)
			{
				document.getElementById(MAKES_ID).options[i+1] = new Option(makeList[i],makeList[i]);
			}
		}
	}

	this.updateModel = function(modelList) {
		this.debug("Start updateModel; remote callback, cid = " + Seam.Remoting.getContext().getConversationId());
		if(typeof(this.conId) == "undefined"){
			//we are not currently in a conversation, so grab and save the id for the nested conversation so that we can use it for the
			//rest of the remote calls
			this.conId = Seam.Remoting.getContext().getConversationId();
			this.debug("updateYear: conId is undefined, so this.conId set to " + this.conId);
		}
		//Handle case where only one item has been returned
		//Set to the current value
		if( modelList.length == 1){
			document.getElementById(MODELS_ID).options[1] = new Option(modelList[0],modelList[0]);
			document.getElementById(MODELS_ID).selectedIndex = 1;

			// Update the options list
			document.getElementById(OPTIONS_ID).focus();
			this.remoteUpdate("option", document.getElementById(YEARS_ID).value,
				document.getElementById(MAKES_ID).value,
				document.getElementById(MODELS_ID).value,
				document.getElementById(OPTIONS_ID).value );

		} else {
			//More than one returned - update as normal
			for (var i = 0;i<modelList.length;i=i+1)
			{
				document.getElementById(MODELS_ID).options[i+1] = new Option(modelList[i],modelList[i]);
			}
		}
	}

	this.updateOptions = function(optionList) {
		//Handle case where only one item has been returned
		//Set to the current value
		this.debug("Start updateOptions; remote callback, cid = " + Seam.Remoting.getContext().getConversationId());
		if(typeof(this.conId) == "undefined"){
			//we are not currently in a conversation, so grab and save the id for the nested conversation so that we can use it for the
			//rest of the remote calls
			this.conId = Seam.Remoting.getContext().getConversationId();
			this.debug("updateOptions: conId is undefined, so this.conId set to " + this.conId);
		}
		if (optionList.length == 1){
			document.getElementById(OPTIONS_ID).options[1] = new Option(optionList[0],optionList[0]);
			document.getElementById(OPTIONS_ID).selectedIndex = 1;
			document.getElementById(OPTIONS_ID).focus();
			this.remoteUpdate("setOption",document.getElementById(YEARS_ID).value,
				document.getElementById(MAKES_ID).value,
				document.getElementById(MODELS_ID).value,
				document.getElementById(OPTIONS_ID).value);
		} else {
			//More than one returned - update as normal
			for (var i = 0;i<optionList.length;i=i+1)
			{
			 document.getElementById(OPTIONS_ID).options[i+1] = new Option(optionList[i],optionList[i]);
			}
		}
	}

	this.updateSelectedOption = function(successFlag) {

		//Callback from final remoting call, nothing to do at this point
		this.debug("Start updateSelectedOption; remote callback, cid = " + Seam.Remoting.getContext().getConversationId() + " successFlag = " + successFlag);

		//Important Note:  The following code works around an issue with conversation
		//management in the Seam framework by re-writing the onclick handling function
		//for the findTires button.  It replaces the id for the current conversation with the
		//id used by the Seam remoting framework.
		// now that we have two search buttons - we need to do this twice
		var ele = document.getElementById("MMYO:findTires");
		if( ele ) {
			this.debug("updateSelectedOption; current handler = " + ele.onclick);
			this.cleanHandler( ele );
			this.debug("updateSelectedOption; new handler = " + ele.onclick);
		} else {
			this.debug("updateSelectedOption; button not found in DOM");
		}


		var ele = document.getElementById("MMYO:findTiresMichelin");
		if( ele ) {

			this.debug("updateSelectedOption; current handler = " + ele.onclick);
			this.cleanHandler( ele );
			this.debug("updateSelectedOption; new handler = " + ele.onclick);

		} else {
			this.debug("updateSelectedOption; button not found in DOM");
		}
	}

	this.cleanHandler = function( ele ){

			//get function text and strip off function wrappings and closing brace
			var handlerScript = ele.onclick.toString();



			handlerScript = handlerScript.replace(/[^{]+{/,"");
			handlerScript = handlerScript.substring(0, handlerScript.length-1);

			//find and replace the cid; add a bogus parameter (foo) to contain the old cid
			var cidIndex = handlerScript.indexOf("cid=");
			var newHandlerScript = handlerScript.substring(0, cidIndex+4);
			newHandlerScript += Seam.Remoting.getContext().getConversationId();
			newHandlerScript += "&foo=";
			newHandlerScript += handlerScript.substring(cidIndex+4);

			// remove unwanted params
			newHandlerScript = this.removeParam( newHandlerScript, 'sYear' );
			newHandlerScript = this.removeParam( newHandlerScript, 'sMake' );
			newHandlerScript = this.removeParam( newHandlerScript, 'sModel' );
			newHandlerScript = this.removeParam( newHandlerScript, 'sOption' );
			newHandlerScript = this.removeParam( newHandlerScript, 'foo' );

			// construct a new function ptr with our updated code
			ele.onclick = new Function(newHandlerScript);
	}

	this.removeParam = function( orig, param ){

		// make sure that the string contains the param
		var start = orig.indexOf( param );
		if( start == -1 ){
			return orig ;
		}

		// substring until the next param
		var end = orig.indexOf( '&', start );
		if( end == -1 ){

			// if its the last param - go to the end
			// of the href string
			end = orig.indexOf( '"', start );
			if( end == -1 ){
				// Firefox uses double quote
				// IE uses single quote
				end = orig.indexOf( '\'', start );
				if( end == -1  ){
					// now we have trouble
					return orig ;
				}
			}
		}


		// if the character before is a & remove it too
		var c = orig.charAt( (start - 1 ) );
		if( c == '&' ){
			start = start - 1 ;
		}

		// remove the section
		var s1 = orig.substring( 0, start );
		var s2 = orig.substring( end );
		var s3 = s1 + s2 ;

		return s3 ;
	}


	this.isYMMOValid = function(){
		for (var i=0;i<this.YMMO_FIELDS.length;i=i+1){
			var fieldID = this.YMMO_FIELDS[i];
			if( !(document.getElementById(fieldID).selectedIndex > 0) ){
				return false ;
			}
		}
		return true ;
	}

	/*
	var yr = document.getElementById(YEARS_ID).value;
		var mk = document.getElementById(MAKES_ID).value;
		var md = document.getElementById(MODELS_ID).value;
		var op = document.getElementById(OPTIONS_ID).value;

		// we need to make sure that the remote bean is in sync
		Seam.Component.getInstance("ymmoInformation").setSelectedOptions(
			yr, mk, md, op, null );

		return true;

		var yr = document.getElementById(YEARS_ID).value;
		var mk = document.getElementById(MAKES_ID).value;
		var md = document.getElementById(MODELS_ID).value;
		var op = document.getElementById(OPTIONS_ID).value;

		// we need to make sure that the remote bean is in sync
		// Seam.Component.getInstance("ymmoInformation").setSelectedOptions( yr, mk, md, op, null );

	*/

	this.validateFindTireButton = function(){
		if (!this.isYMMOValid()){
		 	var errorLabel = document.getElementById('label.mmyoErrorMessage' );
			alert(errorLabel.innerHTML) ;
			return false ;
		}

		return true;


	}

	this.resetLists = function(){

		if (!ymmoExists()){
			return
		}

		this.clearSelectBoxes("make");
		document.getElementById(YEARS_ID).selectedIndex=0;
	}

	// this function will detect if a drop down
	// is set to index 0 or 'Select blah...'
	this.isSelectionValid = function( eleId ){
		// this.debug( eleId );
		var ele = document.getElementById( eleId );
		if( ele ){

			// get the selected index
			var idx = ele.selectedIndex ;
			if( idx == 0 ){
				return false ;
			}
			return true ;
		}
		return false ;
	}

}

/** YMMOComponent.remoteUpdate -- AJAX Calling Method
 * Additional AJAX method on the YMMOComponent class - Defined outside of the class constructor as it will never require access
 * to any private variables within the YMMOComponent class.
 *
 * NOTE: The callback function from SEAM is in a different scope than the remoteUpdate call and
 * the bindObj method is used to keep the reference to the ymmoComponent allowing class methods to be called in the
 * callback method.
 */
YMMOComponent.prototype.remoteUpdate = function(level, yearSelection, makeSelection, modelSelection, optionsSelection){

	this.debug( "remoteUpdate:"+ level );

	var yr = document.getElementById('sYear');
	var mk = document.getElementById('sMake');
	var md = document.getElementById('sModel');
	var op = document.getElementById('sOption');

	ymmoComponent.clearSelectBoxes(level);

	if (level == "make") {
		if( !ymmoComponent.isSelectionValid( 'MMYO:years' ) ){
			return false;
		}

		if( yr ){
			yr.value = yearSelection ;
		}

		//Force remoting calls onto a new conversation
		// if we are on the landing page we dont want a new conv
		if( yr == null ){
        	Seam.Remoting.getContext().setConversationId(null);
		}
		Seam.Component.getInstance("ymmoInformation").getYMMOMakes( yearSelection, this.updateMake.bindObj(ymmoComponent));
		this.debug("After getYMMOMakes remote call, cid = " + Seam.Remoting.getContext().getConversationId());

	} else if (level == "model") {

		if( !ymmoComponent.isSelectionValid( 'MMYO:makes' ) ){
			return false;
		}

		if( yr ){
			yr.value = yearSelection ;
			mk.value = makeSelection ;
		}

		//Handle conversation state
		if( yr == null ){
			if(typeof(this.conId) == "undefined"){
				//we are not currently in a new conversation for updating MMYO, so start one
				Seam.Remoting.getContext().setConversationId(null);
				this.debug("remoteUpdate: conId is undefined at model level, so starting new conversation");
			} else {
				this.debug("Before getModels call, setting con id to " + this.conId);
				Seam.Remoting.getContext().setConversationId(this.conId);
			}
		}

		this.debug("Before getYYMOModels call year:"+ yearSelection +" makeSelection:"+ makeSelection ) ;
		Seam.Component.getInstance("ymmoInformation").getYMMOModels( yearSelection, makeSelection, this.updateModel.bindObj(ymmoComponent));

	} else if (level == "option") {

		if( !ymmoComponent.isSelectionValid( 'MMYO:models' ) ){
			return false;
		}

		if( yr ){
			yr.value = yearSelection ;
			mk.value = makeSelection ;
			md.value = modelSelection ;
		}


		//Handle conversation state
		if( yr == null ){
			if(typeof(this.conId) == "undefined"){
				//we are not currently in a new conversation for updating MMYO, so start one
				Seam.Remoting.getContext().setConversationId(null);
				this.debug("remoteUpdate: conId is undefined at option level, so starting new conversation");
			} else {
				this.debug("Before getOptions call, setting con id to " + this.conId);
				Seam.Remoting.getContext().setConversationId(this.conId);
			}
		}

		Seam.Component.getInstance("ymmoInformation").getYMMOOptions( yearSelection, makeSelection, modelSelection, this.updateOptions.bindObj(ymmoComponent));

	} else if (level == "setOption") {
		if( !ymmoComponent.isSelectionValid( 'MMYO:options' ) ){
			return false;
		}

		if( yr ){
			yr.value = yearSelection ;
			mk.value = makeSelection ;
			md.value = modelSelection ;
			op.value = optionsSelection ;
		}

		//Handle conversation state
		if( yr == null ) {
			if(typeof(this.conId) == "undefined"){
				//we are not currently in a new conversation for updating MMYO, so start one
				Seam.Remoting.getContext().setConversationId(null);
				this.debug("remoteUpdate: conId is undefined at setSelectedOption call, so starting new conversation");
			} else {
				this.debug("Before setSelectedOption call, setting con id to " + this.conId);
				Seam.Remoting.getContext().setConversationId(this.conId);
			}
		}
		Seam.Component.getInstance("ymmoInformation").setSelectedOptions( yearSelection, makeSelection, modelSelection, optionsSelection, this.updateSelectedOption.bindObj(ymmoComponent));
	}

}

