/**
 * Adds application specific properties to the base properties from the ExternalMarcolelinker
 * class.  B/c javascript does not hava a notion of inheritance, composition is used instead.
 * The end result is pass-through methods to the methods in the ExternalMarcolelinker class. 
 * The method, toURLString(), forms up a complete URL using all available properties.
 */
function GenericOnlineLinker( bDebugOn )
{
	this.eml = new ExternalMarcoleLinker( bDebugOn );
	this.applId = null;
	this.retailerId = null;
	this.storeId = null;
	
	// Application specific properties.
	this.setApplId = GenericOnlineLinkerSetApplId;
	this.setRetailerId = GenericOnlineLinkerSetRetailerId;
	this.setStoreId = GenericOnlineLinkerSetStoreId;
	this.setRegistryId = GenericOnlineLinkerSetRegistryId;
	this.setExternalSessionId = GenericOnlineLinkerSetExternalSessionId;
	this.addExternalSessionId = GenericOnlineLinkerAddExternalSessionId;
		
	// Pass through methods to ExternalMarcoleLinker methods
	this.setNavKey = GenericOnlineLinkerSetNavKey;
	this.setTransaction = GenericOnlineLinkerSetTransaction;
	this.setLastTransaction = GenericOnlineLinkerSetLastTransaction;
	this.setViewId = GenericOnlineLinkerSetViewId;
	this.setSessionId = GenericOnlineLinkerSetSessionId;
	this.setServerURL = GenericOnlineLinkerSetServerURL;
	this.setStyleId = GenericOnlineLinkerSetStyleId;	
	
	this.getNavKey = GenericOnlineLinkerGetNavKey;
	this.getTransaction = GenericOnlineLinkerGetTransaction;
	this.getLastTransaction = GenericOnlineLinkerGetLastTransaction;
	this.getViewId = GenericOnlineLinkerGetViewId;
	this.getSessionId = GenericOnlineLinkerGetSessionId;
	this.getServerURL = GenericOnlineLinkerGetServerURL;
	this.getStyleId = GenericOnlineLinkerGetStyleId;
	
	this.addSessionVar = GenericOnlineLinkerAddSessionVar;
	this.addStateVar = GenericOnlineLinkerAddStateVar;
	this.addRequestVar = GenericOnlineLinkerAddRequestVar;

	this.toURLString = GenericOnlineLinkerToURLString;	
	
	this.writeForm = GenericOnlineLinkerWriteForm;	
	this.writeStartForm = GenericOnlineLinkerWriteStartForm;
	this.writeFormBody = GenericOnlineLinkerWriteFormBody;
	this.writeEndForm = GenericOnlineLinkerWriteEndForm;
	this.writeHtml = GenericOnlineLinkerWriteHtml;
}

function GenericOnlineLinkerWriteForm()
{
	this.writeStartForm();
	this.writeFormBody();
	this.writeEndForm();
}

function GenericOnlineLinkerWriteHtml( str )
{
	this.eml.writeHtml( str );
}

function GenericOnlineLinkerWriteStartForm()
{
	this.eml.writeStartForm();
}

function GenericOnlineLinkerWriteFormBody()
{
	this.eml.writeFormBody();
/*
	if ( this.applId != null ) 
		this.writeHtml('<input type="hidden" name="applId" value="' + this.applId + '">');
	if ( this.retailerId != null ) 
		this.writeHtml('<input type="hidden" name="retailerId" value="' + this.retailerId + '">');
	if ( this.storeId != null ) 
		this.writeHtml('<input type="hidden" name="storeId" value="' + this.storeId + '">');
*/
}

function GenericOnlineLinkerWriteEndForm()
{
	this.eml.writeEndForm();
}
/*
function GenericOnlineLinkerSetApplId( newValue )
{
	this.applId = newValue;
}
function GenericOnlineLinkerSetRetailerId( newValue )
{
	this.retailerId = newValue;
}
function GenericOnlineLinkerSetStoreId( newValue )
{
	this.storeId = newValue
}
*/
function GenericOnlineLinkerSetRetailerId( newValue )
{
	this.addSessionVar( 'RetailerId', newValue );
}
function GenericOnlineLinkerSetApplId( newValue )
{
	this.addSessionVar( 'ApplId', newValue );
}
function GenericOnlineLinkerSetStoreId( newValue )
{
	this.addSessionVar( 'storeid', newValue );
}
function GenericOnlineLinkerSetRegistryId( newValue )
{
	this.addRequestVar( 'registry_custcode', newValue );
}
function GenericOnlineLinkerSetExternalSessionId( newValue )
{
	this.addRequestVar( 'xsessionid', newValue )
}

function GenericOnlineLinkerAddExternalSessionId( newValue )
{
	if( document.forms.navform.elements.UpdateValues.value.length > 0 )
		document.forms.navform.elements.UpdateValues.value += '~~';
		
	var uv = new UpdateValue( 'xsessionid', newValue, 'RE' );
	document.forms.navform.elements.UpdateValues.value += uv.toURLString();
}

function GenericOnlineLinkerSetNavKey( newValue )
{
	this.eml.setNavKey( newValue );
}
function GenericOnlineLinkerSetTransaction( newValue )
{
	this.eml.setTransaction( newValue );
}
function GenericOnlineLinkerSetLastTransaction( newValue )
{
	this.eml.setLastTransaction( newValue );
}
function GenericOnlineLinkerSetViewId( newValue )
{
	this.eml.setViewId( newValue );
}
function GenericOnlineLinkerSetSessionId( newValue )
{
	this.eml.setSessionId( newValue );
}
function GenericOnlineLinkerSetServerURL( newValue )
{
	this.eml.setServerURL( newValue );
}
function GenericOnlineLinkerSetStyleId( newValue )
{
	this.eml.setStyleId( newValue );
}
function GenericOnlineLinkerGetStyleId( newValue )
{
	this.eml.getStyleId( newValue );
}
function GenericOnlineLinkerGetNavKey()
{
	return this.eml.getNavKey();
}
function GenericOnlineLinkerGetTransaction() 
{
	return this.eml.getTransaction();
}
function GenericOnlineLinkerGetLastTransaction() 
{
	return this.eml.getLastTransaction();
}
function GenericOnlineLinkerGetViewId()
{ 
	return this.eml.getViewId();
}
function GenericOnlineLinkerGetSessionId()
{
	return this.eml.getSessionId();
}
function GenericOnlineLinkerGetServerURL()
{
	return this.eml.getServerURL();
}

function GenericOnlineLinkerAddSessionVar( newName, newValue )
{
	this.eml.addSessionVar( newName, newValue );
}
function GenericOnlineLinkerAddStateVar( newName, newValue )
{
	this.eml.addStateVar( newName, newValue );
}
function GenericOnlineLinkerAddRequestVar( newName, newValue ) 
{
	this.eml.addRequestVar( newName, newValue );
}
function GenericOnlineLinkerToURLString()
{
	var uRLString = this.getServerURL() + '?';

	uRLString += ( this.applId != null ? 'applId=' + this.applId + '&' : '' );
	uRLString += ( this.retailerId != null ? 'retailerId=' + this.retailerId + '&' : '' );		
 	uRLString += ( this.storeId != null ? 'storeId=' + this.storeId + '&' : '' );
	uRLString += ( this.registryCustcode != null ? 'registryCustcode=' + this.registryCustcode + '&' : '' );

	// Need to remove the possible trailing '&'
	if ( uRLString.lastIndexOf( "&", (uRLString.length-1) ) != -1 )
	{
		uRLString = uRLString.substring( 0, uRLString.length-1 );
	}
	
	var emlString = this.eml.toURLString(); 
	if ( (emlString != null) && (emlString != '') ) 
	{
		uRLString += ( uRLString != '' ? '&' : '' );
		uRLString += emlString;
	}
	
	// It's possible there were no request params?...remove the trailing '?'
	if ( uRLString.lastIndexOf( "?", (uRLString.length-1) ) != -1 )
	{
		uRLString = uRLString.substring( 0, uRLString.length-1 );
	}	
	return uRLString;
}



