//    Licensed Materials - Property of IBM
//
//    IBM Cognos Products: ps
//
//    (C) Copyright IBM Corp. 2005, 2021
//
//    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
// Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
// Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).

var DUAL_CNX_STR_SEPARATOR = 'IBM_JD_CNX_STR:';

function isDualStackConnectString(connectionString) {
	return (connectionString.indexOf(DUAL_CNX_STR_SEPARATOR) != -1) ? true : false ;
}

function buildConnectString(connectType, connectVariant) {
	// reset the connect string
	var f = document.pform;
	f.m_p_connectionString.value = '';
	var connectTypes = connectType.split(",");
	for (var i = 0; i < connectTypes.length; i++) {
		if (i != 0) {
			// append special separator
			f.m_p_connectionString.value += DUAL_CNX_STR_SEPARATOR;
		}
		// trim off the whitespace
		var type = connectTypes[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		f.m_p_connectionString.value += _buildConnectString(type, connectVariant);
	}
}

function parseConnectString(connectType, credentialNamespaces, connectVariant) {
	var connectTypes = connectType.split(",");
	var connectStrings = document.pform.m_p_connectionString.value.split(DUAL_CNX_STR_SEPARATOR);
	
	for (var i = 0; i < connectTypes.length; i++) {
		if (i < connectStrings.length) {
			// trim off the whitespace
			var type = connectTypes[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			_parseConnectString(type, connectStrings[i], credentialNamespaces, connectVariant);
		}
	}
}

function _buildConnectString(connectType, connectVariant)
{
	var connectString = '';
	var f = document.pform;

	if (connectType == 'redbrick' || connectType == 'sybaseIQ' || connectType == 'openEdge')
	{
		connectString = ';LOCAL';
		var type = '';
		if (connectType == 'redbrick')
		{
			type = 'RB'
		}
		else if (connectType == 'sybaseIQ')
		{
			type = 'IQ';
		}
		else if (connectType == 'openEdge')
		{
			type = 'PG';
		}
		
		connectString += ';' + type;
		connectString += ';DSN=' + f.m_connection_database.value;

		if (f.m_connection_use_userid.checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}

		connectString += ';' + f.m_connection_string.value;
		connectString += '@ASYNC=' + ((isCheckboxChecked(f.m_connection_use_async)) ? '1' : '0');
		connectString += '@' + f.m_connection_connect_time.value;
		connectString += '/' + f.m_connection_reply_time.value;
		if (connectType == 'openEdge' || connectType == 'sybaseIQ')
		{
			if (f.m_connection_odbc_access_mode.checked)
				connectString += '@UNICODE';
		}
		connectString += '@COLSEQ=' + f.m_connection_colseq.value;
	}
	
	else if (connectType == 'odbc' || connectType == 'composite' || connectType == 'virtualviewmanager' || connectType == 'sqlodbc' || connectType == 'teradata' || connectType == 'db2'  || connectType == 'netezza')
	{
		connectString = ';LOCAL';
		var type = '';
		if (connectType == 'odbc')
		{
			type = 'OD';
		}
		else if (connectType == 'sqlodbc')
		{
			type = 'SS';
		}
		else if (connectType == 'db2')
		{
			type = 'D2';
		}
		else if (connectType == 'teradata')
		{
			type = 'TD';
		}
		else if (connectType == 'composite')
		{
			type = 'CS'; //Composite connection.
		}
		else if (connectType == 'netezza')
		{
			type = 'NZ';
		}		
		else
		{
			type = 'VM'; //Virtual View Manager
		}		
		connectString += ';' + type;
		connectString += ';DSN=' + f.m_connection_database.value;

		if (isRadioButtonSelected(f.authentication, 'namespace') || isRadioButtonSelected(f.authentication, 'signon'))
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || isRadioButtonSelected(f.authentication, 'namespace'))
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			// for third party namespace authentication we need to put Trusted_Connection=yes in the connection string
			if (isRadioButtonSelected(f.authentication, 'namespace') && connectType != 'teradata' && connectType != 'db2' && connectType != 'odbc' && connectType != 'netezza')
			{
				connectString += ';Trusted_Connection=yes';
			}
			connectString = prefix + connectString;
		} 
		else if ((connectType == 'sqlodbc') && isRadioButtonSelected(f.authentication, 'windows'))
		{
			connectString += ';Trusted_Connection=yes';
		}

		connectString += ';' + f.m_connection_string.value;
		connectString += '@ASYNC=' + (isCheckboxChecked(f.m_connection_use_async) ? '1' : '0');
		connectString += '@' + f.m_connection_connect_time.value;
		connectString += '/' + f.m_connection_reply_time.value;
		if (connectType == 'odbc' || connectType == 'composite' || connectType == 'virtualviewmanager')
		{
			if (f.m_connection_odbc_access_mode.checked)
				connectString += '@UNICODE';
		}
		if (connectType == 'db2')
		{
			if (isCheckboxChecked(f.m_connection_trusted_context))
			{	connectString += '@TRUSTED_CONTEXT';
				if (f.m_connection_identity_propagation && f.m_connection_identity_propagation.value!='')
				{
					connectString += '@REGISTRY_NAME=' + f.m_connection_identity_propagation.value;
				}	
			}
		}

		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID';
		}
		
		connectString += '@COLSEQ=' + f.m_connection_colseq.value;

	}

	
	else if (connectType == 'consolidation' || connectType == 'contributor' || connectType == 'contributorSeries7')
	{
		
		connectString = ';LOCAL';
		var type = '';
		var padid = '';
		
		if (connectType == 'consolidation')
		{
			type = 'CL';
		}
		else if (connectType == 'contributor')
		{
			type = 'CR';
		}
		else if (connectType == 'contributorSeries7')
		{
			type = 'CR';
			if (f.m_connection_padid && f.m_connection_padid.value != null)
			{
				padid = f.m_connection_padid.value;
			}
		}
		
		connectString += ';' + type;
		if (connectType == 'consolidation') 
		{
			connectString += ';SERVER=' + f.m_connection_servername.value;
			connectString += ';PORT=' + f.m_connection_port.value;
		} else if (connectType == 'contributorSeries7') {
			connectString += ';SERVER=' + f.m_connection_servername.value;
			connectString += ';PORT=' + f.m_connection_port.value;
			if ( padid != '' )
			{
				connectString += ';PADID=' + padid + ';UID=%s;PWD=%s';
			}
		} else if (connectType == 'contributor')
		{
			if (f.m_p_credentialNamespaces && f.m_p_credentialNamespaces.options[f.m_p_credentialNamespaces.selectedIndex].value != '')
			{
				connectString += ';UID=%s;PWD=%s';
			}
		}
		if (connectType == 'consolidation')
		{
			connectString += ';UID=%s;PWD=%s';
		}
	}
	else if (connectType == 'dbtwoolap')
	{
		
		connectString = ';LOCAL';
		
		connectString += ';DO';
		connectString += ';SERVER=' + f.m_connection_servername.value;
		if (f.authentication[1].checked || f.authentication[2].checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}
	}
	
	else if (connectType == 'tm1')
	{
		
		connectString = ';LOCAL';
		
		connectString += ';TM';
		connectString += ';TM1AdminHost=' + f.m_connection_hostname.value;
		connectString += ';TM1ServerName=' + f.m_connection_servername.value;
		if (f.authentication[1].checked || f.authentication[2].checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}
	}
	
	else if (connectType == 'tm1R')
	{
		
		connectString = ';LOCAL';
		
		connectString += ';TMR;LCID=en-us';
		connectString += ';TM1AdminHost=' + f.m_connection_hostname.value;
		if (f.m_connection_use_ssl.checked){
			connectString += ';TM1Protocol=https';
		} else {
			connectString += ';TM1Protocol=http';
		}
		connectString += ';TM1ServerPort=' + f.m_connection_tm1port.value;
		connectString += ';TM1ServerName=TM1ServerName;CATALOG=CATALOG';
		if (f.authentication[1].checked || f.authentication[2].checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString += ";";
			connectString = prefix + connectString;
		}
	}
	
	else if (connectType == 'odata')
	{
		connectString = ';LOCAL';
		connectString += ';ODATA';
		connectString += ';URL=' + f.m_connection_service_root_URI.value;
		if (f.authentication[1].checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}
	}
	
	else if (connectType == 'json')
	{
		connectString = ';LOCAL';
		connectString += ';JSON';
		connectString += ';URL=' + f.m_connection_url.value;
		if(f.m_connection_subType) {
			connectString += ';SUBTYPE=' + f.m_connection_subType;
		}
		if(f.m_connection_assembly.checked) {
			connectString += ';ASSEMBLY=true';
		}
		if(!f.m_connection_schema.disabled && f.m_connection_schema.value) {
			connectString += ';SCHEMA=' + f.m_connection_schema.value;
		}
		if(!f.m_connection_http_method.disabled) {
			connectString += ';METHOD=' + f.m_connection_http_method.value;
		}
		if(f.m_connection_http_mime_type && !f.m_connection_http_mime_type.disabled && f.m_connection_http_mime_type.value) {
			connectString += ';MIME_TYPE=' + f.m_connection_http_mime_type.value;
		}
		if(f.m_connection_http_message_body && !f.m_connection_http_message_body.disabled && f.m_connection_http_message_body.value) {
			connectString += ';DATA=' + f.m_connection_http_message_body.value;
		}
		if(!f.m_connection_json_path.disabled && f.m_connection_json_path.value) {
			connectString += ';PATH=' + f.m_connection_json_path.value;
		}
		if(f.m_connection_authentication_type.value == 'OAuth1.0'){
			connectString += ';TEMPORARY_TOKEN_ENDPOINT=' + f.m_connection_temporary_token_endpoint.value;
			connectString += ';AUTHORIZATION_ENDPOINT=' + f.m_connection_authorization_endpoint.value;
			connectString += ';TOKEN_ENDPOINT=' + f.m_connection_token_endpoint.value;
		}
		if(f.m_connection_authentication_type.value == 'OAuth2.0'){
			connectString += ';AUTHORIZATION_ENDPOINT=' + f.m_connection_authorization_endpoint.value;
			connectString += ';TOKEN_ENDPOINT=' + f.m_connection_token_endpoint.value;
			if (f.m_connection_scope.value)
			{
				connectString += ';SCOPE=' + f.m_connection_scope.value;
			}
		}
		connectString += ';AUTHENTICATION_TYPE=' + f.m_connection_authentication_type.value;
		if (f.m_connection_authentication_type.value != 'None') 
		{
			connectString += ';UID=%s';
			connectString += ';PWD=%s';
		}
		
	}

	else if (connectType == 'cognosnow')
	{
		
		connectString = ';LOCAL';
		
		connectString += ';LA';
		connectString += ';SERVER=' + f.m_connection_servername.value;
		if (f.m_connection_port.value != '')
		{
			connectString += ':' + f.m_connection_port.value;
		}
		connectString += f.m_connection_file.value;

	}	
	else if (connectType == 'msas_xmla')
	{
		connectString = ';LOCAL';
		connectString += ';X8';
		connectString += ';SERVER=' + f.m_connection_servername.value;
		
		if (f.m_connection_locale)
		{
			connectString += ';LCID=' + f.m_connection_locale.value;
		}
		
		if (f.m_connection_use_userid.checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}
	}
	else if (connectType == 'msanalysis2005' || connectType == 'msanalysis2008' || connectType == 'msanalysis2012' || connectType == 'msanalysis2014' || connectType == 'msanalysis2016' || connectType == 'msanalysis2017')
	{
		connectString = ';LOCAL';
		var type = '';
		
		if (connectType == 'msanalysis2005')
		{
			type = 'YK';
		}
		else if (connectType == 'msanalysis2008')
		{
			type = 'M8';
		}
		else if (connectType == 'msanalysis2012')
		{
			type = 'M12';
		}
		else if (connectType == 'msanalysis2014')
		{
			type = 'M14';
		} 
		else if (connectType == 'msanalysis2016')
		{
			type = 'M16';
		}
		else if (connectType == 'msanalysis2017')
		{
			type = 'M17';
		}
		
		connectString += ';' + type;
		connectString += ';SERVER=' + f.m_connection_servername.value;
		if ( trim(f.m_connection_namedinstance.value) != '')
		{
			connectString += '\\' + f.m_connection_namedinstance.value;
		}
		
		if (f.authentication[1].checked || f.authentication[2].checked)
		{
			var prefix = '^User ID:';
			connectString += ';UID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';PWD=%s';
			}
			connectString = prefix + connectString;
		}
		if (f.authentication[0].checked)
		{
			connectString += ';Trusted_Connection=yes';
		}

		if (f.m_connection_locale)
		{
			connectString += ';LCID=' + f.m_connection_locale.value;
		}
	}
	
	else if (connectType == 'powercube')
	{
		
		connectString = ';LOCAL';
		connectString += ';PC';
		connectString += ';WIN_PATH=' + f.m_connection_windows_cube.value;
		connectString += ';UNIX_PATH=' + f.m_connection_unix_cube.value;
		
		if (f.m_connection_cache_size && f.m_connection_cache_size.value != '') 
		{
			connectString += ';readCacheSize=' + f.m_connection_cache_size.value;
		}

		if (f.cube_password_checkbox && f.cube_password_checkbox.checked)
		{
			connectString = '^?Password:' + connectString;
			connectString += ';cubePassword=%s';
		}
	}
	
	else if (connectType == 'sql' || connectType == 'sql2005' || connectType == 'sql2008' || connectType == 'sql2012-2014')
	{
		if (connectType == 'sql') 
		{
			connectString = ';LOCAL;OL;DBInfo_Type=MS;Provider=SQLOLEDB';
		} 
		
		else if (connectType == 'sql2005')
		{
			connectString = ';LOCAL;OL;DBInfo_Type=MS;Provider=SQLNCLI';		
		} 
		
		else if (connectType == 'sql2008')
		{
			connectString = ';LOCAL;OL;DBInfo_Type=MS;Provider=SQLNCLI10';		
		}

		else if (connectType == 'sql2012-2014')
		{
			connectString = ';LOCAL;OL;DBInfo_Type=MS;Provider=SQLNCLI11';	
		}
		if (f.authentication[2].checked || f.authentication[3].checked)
		{
			var prefix = '^User ID:';
			connectString += ';User ID=%s';
			if (f.m_connection_use_pword.checked || f.authentication[2].checked)
			{
				prefix += '\^\?Password:';
				connectString += ';Password=%s';
			}
			connectString = prefix + connectString;
		}

		connectString += ';Data Source=' + f.m_connection_database.value;
		
		if (f.authentication[1].checked || f.authentication[2].checked)
		{
			connectString += ';Integrated Security=SSPI';
		}
		
		var cat = isRadioButtonSelected(f.m_connection_sql_database_choice, 'master') ? 'master' :  f.m_connection_sql_database_name.value;
		connectString += ';Provider_String=Initial Catalog=' + cat;
		
		if (f.m_connection_sql_application.value != '')
		{
			connectString += ';Application=';
			connectString += f.m_connection_sql_application.value;
		}

		if (connectType == 'sql2005' || connectType == 'sql2008' || connectType == 'sql2012-2014')
		{
			if (isListItemSelected(f.m_connection_sql_marsconnection, 'YES')) 
			{
				connectString += ';MarsConn=YES';
			}
		}

		if (f.m_connection_optional_parameters.value && f.m_connection_optional_parameters.value != '') 
		{
			connectString += ';' + f.m_connection_optional_parameters.value;
		}

		connectString += ';';

		if (isCheckboxChecked(f.m_transformUserIdentification))
		{
			connectString += '@TRANSFORMUID';
		}

		connectString += '@COLSEQ=' + f.m_connection_colseq.value;
	}
	else if (connectType == 'oracle')
	{
		connectString = ';LOCAL;OR;ORACLE@';
		var prefix = '';

		
		if (f.m_connection_use_userid.checked || isRadioButtonSelected(f.authentication, 'namespace'))
		{
			prefix = '^User ID:';
			connectString += '%s';
		}

		connectString += '@' + f.m_connection_database.value + '/';

		if ((f.m_connection_use_userid.checked && f.m_connection_use_pword.checked) || isRadioButtonSelected(f.authentication, 'namespace'))
		{
			prefix += '^?Password:';
			connectString += '%s';
		}

		connectString = prefix + connectString;

		if (isCheckboxChecked(f.m_transformUserIdentification))
		{
			connectString += '@TRANSFORMUID';
		}

		connectString += '@COLSEQ=' + f.m_connection_colseq.value;
	}
	else if (connectType == 'sybase' || connectType == 'sybase_ct15')
	{
                connectString = ';LOCAL;';

        if (connectType == 'sybase')
		{
			connectString += 'CT;';
		} else
		{
			connectString += 'CT15;';
		}

        connectString += f.m_connection_database.value;
		connectString += '|';
		var cat;
		if (f.m_connection_sybase_database_choice[0].checked)
		{
			cat = 'master';
		}
		else
		{
			cat = f.m_connection_sybase_database_name.value;
		}
		connectString += cat;
		connectString += '@';

		if (f.m_connection_use_userid.checked)
		{
			var prefix = '^User ID:';
			connectString += '%s/';
			if (f.m_connection_use_pword.checked)
			{
				prefix += '^?Password:';
				connectString += '%s';
			}
			connectString = prefix + connectString;
		}
		connectString += '@';
		connectString += f.m_connection_connect_time.value;
		connectString += '/';
		connectString += f.m_connection_reply_time.value;
		connectString += '@';
		connectString += f.m_connection_packet.value;
		connectString += '@ASYNC=';
		connectString += f.m_connection_sybase_async.options[f.m_connection_sybase_async.selectedIndex].value;
		connectString += '@POLL=';
		connectString += f.m_connection_polling.value;
		connectString += '@APPNAME=';
		connectString += f.m_connection_sybase_application.value;
		connectString += '@COLSEQ=';
		connectString += f.m_connection_colseq.value;
	}
	else if (connectType == 'informix')
	{
		connectString = ';LOCAL;IF;';
		connectString += f.m_connection_database.value;
		connectString += '@';

		connectString += f.m_connection_hostname.value;
		connectString += ':';
		connectString += f.m_connection_servername.value;
		connectString += '|';

		if (f.m_connection_service[0].checked)
		{
			connectString += f.m_connection_service[0].value;
		}
		else if (f.m_connection_service[1].checked)
		{
			connectString += f.m_connection_service[1].value;
		}
		else
		{
			if (f.m_connection_service_name.value != '')
			{
				connectString += f.m_connection_service_name.value;
			}
		}

		if (f.m_connection_use_userid.checked)
		{
			var prefix = '^User ID:';
			connectString += '@%s';
			if (f.m_connection_use_pword.checked)
			{
				prefix += '^?Password:';
				connectString += '/%s';
			}
			connectString = prefix + connectString;
		}
		connectString += '@COLSEQ=';
		connectString += f.m_connection_colseq.value;
	}
	else if (connectType == 'sr3')
	{
		connectString = ';LOCAL;ERP-SAP;URL=sap:';
		
		var prefix = '^User ID:';
		if (f.m_connection_use_pword.checked || f.authentication[0].checked)
		{
			prefix += '\^\?Password:';
		} 
		connectString = prefix + connectString;
		
		if (f.m_connection_use_loadbalancing_hidden.value == "true")
		{
			connectString += 'LB:' + f.m_connection_message_server.value + ':' + f.m_connection_system_id.value + ':' +  f.m_connection_logon_group.value + ':';
			
		}
		else 
		{
			connectString += f.m_connection_application_server.value + ':' + f.m_connection_system_number.value + ':';
			
		}
		
		connectString += 'ROUTER_STRING=' + f.m_connection_router_string.value;
		
		connectString += ':' + f.m_connection_client.value + ':' + f.m_connection_language.value + ';';
		
		connectString += 'MAX_CONN=' + f.m_connection_max_conn_in_pool.value + ';';
		
		connectString += 'ABAP_QUERY_DB_ACCESSES=' + f.m_connection_abap_query_db_access_limit.value + ';';
		
		connectString += 'TABLE_READ_COUNT=' + f.m_connection_table_row_count.value + ';';
		
		connectString += 'READ_TABLE_FUNCTION_NAME=' + f.m_connection_table_read_function.value + ';';
		
		connectString += 'DRIVER_NAME=com.cognos.jdbc.driver.sap.SAPJdbcDriver';
		
	}
	else if (connectType == 'sfdc')
	{
		connectString = ';LOCAL;ERP-SFDC;URL=sfdc:' + f.m_connection_url.value;

		var prefix = '^User ID:';
		if (f.m_connection_use_pword.checked || f.authentication[0].checked)
		{
			prefix += '\^\?Password:';
		}
		connectString = prefix + connectString;
		
		connectString +=  ';CONCURRENT_CALLS_LIMIT=' + f.m_connection_conc_calls_limit.value + ';USER_CONCURRENT_CALLS_LIMIT=';
		
		connectString += f.m_connection_user_conc_calls_limit.value + ';CONNECTION_TIMEOUT=';
		
		connectString += f.m_connection_timeout.value + ';QUERY_BATCH_SIZE=';
		
		connectString += f.m_connection_query_batch_size.value + ';MAX_RETRIES=';
		
		connectString += f.m_connection_max_retries.value + ';WAIT_BETWEEN_RETRIES=';
		
		connectString += f.m_connection_wait_between_retries.value + ';PROXY_ENABLED=';
		
		if (f.m_connection_proxy_enabled.value == "true") 
		{
			connectString += f.m_connection_proxy_enabled.value + ';PROXY_HOST=';
			connectString += f.m_connection_proxy_host.value + ';PROXY_PORT=';
			connectString += f.m_connection_proxy_port.value;
		}
		else
		{
			connectString += 'false';
		}
		connectString += ';USE_REST_API=';
		
		connectString += 'FALSE;CLIENT_ID=';
		
		connectString += ';CLIENT_SECRET=';
		
		connectString += ';';
		
		connectString += 'DRIVER_NAME=com.cognos.jdbc.driver.sfdc.SFDCJdbcDriver';
		
	}
	else if (connectType == 'siebel')
	{
		connectString = ';LOCAL;ERP-SIEBEL;URL=Siebel.';

		var prefix = '^User ID:';
		if (f.m_connection_use_pword.checked || f.authentication[0].checked)
		{
			prefix += '\^\?Password:';
		} 
		connectString = prefix + connectString;

		connectString += f.m_connection_transport.value + '.';
		
		connectString += f.m_connection_encryption.value + '.';
		
		connectString += f.m_connection_compression.value + ':';
		
		connectString += '//' + f.m_connection_gatewayserver.value + ':';
	
		connectString += f.m_connection_gatewayport.value + '/' + f.m_connection_enterprise_name.value + '/';
		
		connectString += f.m_connection_aom.value + '_' + f.m_connection_language.value + ';';
		
		if (f.m_connection_siebel_repo.value != "")
		{
			connectString += 'REPOSITORY_NAME=' + f.m_connection_siebel_repo.value + ';';
		}		
		
		if (f.m_connection_login_retries.value != "")
		{
		 connectString += 'LOGIN_RETRY_COUNT=' + f.m_connection_login_retries.value + ';';
		}
		
		if (f.m_connection_login_retry_delay.value != "")
		{
			connectString += 'LOGIN_RETRY_DELAY=' + f.m_connection_login_retry_delay.value + ';';
		}
		
		if (f.m_connection_local_sort.value != "")
		{
			connectString += 'LOCALSORT=' + f.m_connection_local_sort.value + ';';
		}
		
		if (f.m_connection_level.value != "")
		{
			connectString += 'LEVEL=' + f.m_connection_level.value + ';';
		}
		
		if (f.m_connection_charset.value != "")
		{
			connectString += 'CHARSET=' + f.m_connection_charset.value + ';';
		}
		
		if (f.m_connection_adv_parameters.value != "")
		{
			connectString += 'ADVANCED_PARAMETERS=' + f.m_connection_adv_parameters.value + ';';
		}
		
		connectString += 'DRIVER_NAME=com.cognos.jdbc.driver.siebel.SiebelJdbcDriver';
		
	}
	else if (connectType == 'sap')
	{
		var sapType = f.m_connection_sap_type.options[f.m_connection_sap_type.selectedIndex].value;
		connectString = '^User ID:^?Password:;LOCAL;BW;serverType=';
		connectString += sapType + ';';
		connectString += 'server=';
		connectString += f.m_connection_database.value + ';';
		if (sapType == 'applicationServer')
		{
			connectString += 'sysnr=';
			connectString += f.m_connection_sys_no.value + ';';
		}
		if (sapType == 'messageServer')
		{
			connectString += 'sysid=';
			connectString += f.m_connection_sys_id.value + ';';
		}
		connectString += 'client=';
		connectString += f.m_connection_client_no.value + ';';
		if (sapType == 'messageServer')
		{
				connectString += 'logonGroup=';
				connectString += f.m_connection_logon.value + ';';
		}
		if (f.m_connection_sap_codepage.value != '')
		{
			connectString += 'codePage=';
			connectString += f.m_connection_sap_codepage.value + ';';
		}
		
		connectString += 'UID=%s;PWD=%s;';
		if (f.m_connection_router_string && f.m_connection_router_string.value != '')
		{
			connectString += 'routerString=';
			connectString += f.m_connection_router_string.value + ';';
		}
		
		if (isCheckboxChecked(f.m_transformUserIdentification))
		{
			connectString += '@TRANSFORMUID=TRUE';
		}
	}
	else if (connectType == 'sapR3' || connectType == 'sapECC')
	{
		if (connectType == 'sapR3') 
		{
			connectString = '^User ID:^?Password:;LOCAL;R3;hostname=';
		}
		else if (connectType == 'sapECC')
		{
			connectString = '^User ID:^?Password:;LOCAL;EC;hostname=';
		}
		connectString += f.m_connection_hostname.value + ';';
		connectString += 'sysnr=';
		connectString += f.m_connection_sys_no.value + ';';
		connectString += 'gateway_host=';
		connectString += f.m_connection_gateway_host.value + ';';
		connectString += 'gateway_service=';
		connectString += f.m_connection_gateway_service.value + ';';
		connectString += 'destination=';
		connectString += f.m_connection_destination.value + ';';
		connectString += 'client=';
		connectString += f.m_connection_client.value + ';';
		connectString += 'UID=%s;PWD=%s;';
		connectString += 'language=';
		connectString += f.m_connection_sap_language.value + ';';
		if (f.m_connection_dictionary && f.m_connection_dictionary.value != '')
		{
			connectString += 'dictionary=';
			connectString += f.m_connection_dictionary.value + ';';
		}
		connectString += 'background=';
		if (f.m_connection_background.checked)
		{
			connectString += 'ON;';
		}
		else 
		{
			connectString += 'OFF;';
		}
		if (connectType == 'sapR3') 
		{
			if (f.m_connection_cogudaouterjoin.options[f.m_connection_cogudaouterjoin.selectedIndex].value == 'ON')
			{
				//No need to add it when the value is off.
				connectString += 'cogudaouterjoin=ON;';
			}
		}
		connectString += '@COLSEQ=';
		connectString += f.m_connection_colseq.value;
	}
	else if (connectType == 'xml')
	{
		connectString = ';LOCAL;XML;';
		connectString += f.m_connection_database.value;
	}
	else if (connectType == 'jdbc-db2')
	{
		// [^User ID:][^?Password:];LOCAL;JD-D2;URL=<URLSPEC>;DRIVER_NAME=com.ibm.db2.jcc.DB2Driver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:db2://<SERVERNAME>:<PORT>/<DBNAME>[:[jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		// Authentication:  [0] None, [1] Namespace, [2] Signon (User ID/[Password])
		
		if (f.authentication[1].checked || f.authentication[2].checked) {
			var prefix = '^User ID:';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked){
				prefix += '\^\?Password:';
			}
			connectString = prefix + connectString;
		}

		connectString += ';LOCAL;JD-D2';
		connectString += ';URL=jdbc:db2://' + f.m_connection_servername.value + ':' + f.m_connection_port.value + '/' + f.m_connection_jdbc_database_name.value;
		
		if (f.m_connection_jdbc_parameters.value != '') {
			connectString += ':' + f.m_connection_jdbc_parameters.value;
		}
		
		connectString += ';DRIVER_NAME=com.ibm.db2.jcc.DB2Driver';

		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += ';LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}
	}
	else if (connectType == 'jdbc-oracle') 
	{
		// [^User ID:][^?Password:];LOCAL;JD-OR;URL=<URLSPEC>;DRIVER_NAME=oracle.jdbc.OracleDriver  [;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:oracle:thin:@//<SERVERNAME>:<PORT>/<SERVICE_D>
		// URLSPEC = jdbc:oracle:thin:@(DESCRIPTION=...)
		// URLSPEC = jdbc:oracle:thin:@(DESCRIPTION_LIST=...)
		// URLSPEC = jdbc:oracle:oci:@<TNS_NAME>
		// URLSPEC = jdbc:oracle:oci:@(DESCRIPTION=...)
		// or URLSPEC = jdbc:oracle:oci:@(DESCRIPTION_LIST=...)
		
		// Authentication:  Signon (User ID/[Password])
		
		if (f.m_connection_use_userid.checked || isRadioButtonSelected(f.authentication, 'namespace')) {
			connectString += '^User ID:';
		}
		if ((f.m_connection_use_userid.checked && f.m_connection_use_pword.checked) || isRadioButtonSelected(f.authentication, 'namespace')) {
			connectString += '^?Password:';
		}
		
		connectString += ';LOCAL;JD-OR;URL=jdbc:oracle:';
		if (f.m_connection_jdbc_oracle_style[0].checked) {
			connectString += "thin:@//" + f.m_connection_servername.value + ":" + f.m_connection_port.value + "/" + f.m_connection_oracle_service_id.value;
		} else if (f.m_connection_jdbc_oracle_style[1].checked) {
			connectString += "oci:@" + f.m_connection_oracle_tns_name.value;
		} else {
			if (f.m_connection_jdbc_oracle_driver_type[0].checked) {
				connectString += "thin:@";
			} else {
				connectString += "oci:@";
			}
			connectString += stripSpecialCharsFromOracleNetDesc(f.m_connection_oracle_net_descriptor.value);
		}
		
		connectString += ';DRIVER_NAME=oracle.jdbc.OracleDriver';
		
		if (isCheckboxChecked(f.m_transformUserIdentification))
		{
			connectString += '@TRANSFORMUID=TRUE';
		}
		
		var properties = f.m_connection_jdbc_parameters.value;
		if (properties != '' )
		{
			connectString += ';'
			connectString += properties;
		}
		
		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += ';LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}	
	}
	else if (connectType == 'jdbc-generic' ||  connectType == 'lob-jdbc') 
	{
		// [^User ID:][^?Password:];LOCAL;JDBC-OR;URL=<URLSPEC>;DRIVER_NAME=<DRIVER_NAME>[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = specific to the driver
		var connectString = '';
		if (f.authentication[2].checked) {
			connectString += '^User ID:';
			if (f.m_connection_use_pword.checked) {
				connectString += '^?Password:';
			}
		}
		connectString += ';LOCAL;JDBC;URL=';
		var url = f.m_jdbc_connection_url.value;
		connectString += url;
		connectString += ';DRIVER_NAME=' + f.m_jdbc_driver_class.value + ';';

		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		var properties = f.m_jdbc_connection_properties.value;
		connectString += properties;
		if (properties != '' && properties.charAt(properties.length - 1) != ';')
		{
			connectString += ';';
		}
		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += 'LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}
	}
	else if (connectType == 'filenet') 
	{
		// [^User ID:][^?Password:];LOCAL;RP-CMIS-FILENET;URL=<URLSPEC>;DRIVER_NAME=<DRIVER_NAME>[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = specific to the driver
		
		// Authentication:  Signon (User ID/[Password])
		
		var repositoryPluginClass;
		var provider;
		if (f.m_connection_jdbc_driverclass.value.indexOf('CMIS_') == 0) {
			repositoryPluginClass = 'com.ibm.cognos.cm.CMISRepository.CMISRepositoryPlugin';
			provider = f.m_connection_jdbc_driverclass.value.substring(5);
			if (f.m_connection_use_userid.checked) {
				connectString += '^User ID:';
			}
			if (f.m_connection_use_userid.checked && f.m_connection_use_pword.checked) {
				connectString += '^?Password:';
			}
		}
		connectString += ';LOCAL;RP-CMIS-FILENET;URL=';
		if (f.m_connection_jdbc_driverclass.value == 'FileSystem') {
			repositoryPluginClass = 'com.ibm.cognos.cm.fileSystemPlugin.FileSystemArchivePlugin';
			connectString += "alias:"
		}
		connectString += f.m_connection_jdbc_url.value + ";DRIVER_NAME=" + repositoryPluginClass;
		if (f.m_connection_file.value != '') {
			connectString += ';ROOT=' + f.m_connection_file.value;
		}
		if (f.m_connection_jdbc_parameters.value != '') {
			providerIdx = f.m_connection_jdbc_parameters.value.indexOf('PROVIDER=');
			if (providerIdx < 0 && provider != null) {
				connectString += ';PROVIDER=' + provider;
			}
			connectString += ';' + f.m_connection_jdbc_parameters.value;
		} else {
			if (provider != null) {
				connectString += ';PROVIDER=' + provider;
			}
		}

	}
	else if (connectType == 'jdbc-sql')
	{
		// [^User ID:][^?Password:];LOCAL;JD-SS;URL=<URLSPEC>;DRIVER_NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:sqlserver://<SERVERNAME>[:<PORT>][;INSTANCENAME=<INSTNAME>];DATABASE=<DB>[;LOGINTIMEOUT=<TIMEOUT>][;integratedSecurity=true][;[jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		// Authentication:  [0] None, [1] C8 service creds, [2] Namespace, [3] Signon (User ID/[Password])
		
		if (f.authentication[2].checked || f.authentication[3].checked) {
			connectString = '^User ID:';
			if (f.m_connection_use_pword.checked || f.authentication[2].checked) {
				connectString += '\^\?Password:';
			}
		}
		
		connectString += ';LOCAL;JD-SS';
		connectString += ';URL=jdbc:sqlserver://' + f.m_connection_servername.value;
        if (f.m_connection_port.value != '') {
            connectString += ':' + f.m_connection_port.value;
        }
		connectString += ';DATABASE=' + f.m_connection_jdbc_database_name.value;
		
		if (f.m_connection_sql_instance_name.value != '') {
			connectString += ';INSTANCENAME=' + f.m_connection_sql_instance_name.value;
		}

		if (f.m_connection_jdbc_connect_time.value != '') {
			connectString += ';LOGINTIMEOUT=' + f.m_connection_jdbc_connect_time.value;
		}
		
		if (f.authentication[1].checked || f.authentication[2].checked) {
			connectString += ';integratedSecurity=true';
		}
		
		if (f.m_connection_jdbc_parameters.value != '') {
			connectString += ';' + f.m_connection_jdbc_parameters.value;
		}
		
		connectString += ';DRIVER_NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver';
		
		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += ';LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}
		
	}
	else if (connectType == 'jdbc-teradata')
	{
		// [^User ID:][^?Password:];LOCAL;JD-TD;URL=<URLSPEC>;DRIVER_NAME=com.teradata.jdbc.TeraDriver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:teradata://<SERVERNAME>/DBS_PORT=<PORT>,DATABASE=<DBNAME>[,jdbcproperty1=jdbcvalue1][,jdbcproperty2=jdbcvalue2]...
		
		// Authentication:  [0] None, [1] Namespace, [2] Signon (User ID/[Password])

		if (f.authentication[1].checked || f.authentication[2].checked) {
			var prefix = '^User ID:';
			if (f.m_connection_use_pword.checked || f.authentication[1].checked){
				prefix += '\^\?Password:';
			}
			connectString = prefix + connectString;
		}

		connectString += ';LOCAL;JD-TD';
		connectString += ';URL=jdbc:teradata://' + f.m_connection_servername.value;
		if (f.m_connection_port.value != '') { 
			connectString += '/DBS_PORT=' + f.m_connection_port.value;
		}	
		if (f.m_connection_jdbc_database_name.value != '') {
			connectString += ',DATABASE=' + f.m_connection_jdbc_database_name.value;
		}
		if (f.m_connection_jdbc_parameters.value != '') {
			connectString += ',' + f.m_connection_jdbc_parameters.value;
		}

		connectString += ';DRIVER_NAME=com.teradata.jdbc.TeraDriver';
		
		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += ';LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}
	}	
	else if (connectType == 'jdbc-netezza')
	{
		// [^User ID:][^?Password:];LOCAL;JD-NZ;URL=<URLSPEC>;DRIVER_NAME=org.netezza.Driver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:netezza://<SERVERNAME>[:<PORT>]/<DBNAME>[[;jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		var isNamespaceAuthSelected = f.authentication[1].checked;
		var isSignonsAuthSelected = f.authentication[2].checked;
		if (isNamespaceAuthSelected || isSignonsAuthSelected) {
			var prefix = '^User ID:';
			if (f.m_connection_use_pword.checked || isNamespaceAuthSelected){
				prefix += '\^\?Password:';
			}
			connectString = prefix + connectString;
		}

		connectString += ';LOCAL;JD-NZ';
		
		portString = "";
		if (f.m_connection_port.value != ""){
		   portString = ":" + f.m_connection_port.value; 
		}
		
		connectString += ';URL=jdbc:netezza://' + f.m_connection_servername.value + portString + '/' + f.m_connection_jdbc_database_name.value;
		
		if (f.m_connection_jdbc_parameters.value != '') {
			connectString += ';' + f.m_connection_jdbc_parameters.value;
		}
		
		connectString += ';DRIVER_NAME=org.netezza.Driver';
		
		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		if (f.m_connection_jdbc_sort_colseq.value != '') {
			connectString += ';LOCALSORT=' + f.m_connection_jdbc_sort_colseq.value + ';LEVEL=' + f.m_connection_jdbc_sort_level.value;
		}
	}
	else if (connectType == 'other')
	{
		connectString = f.m_other_connectionString.value;
	}
	return connectString;
}


function _parseConnectString(connectType, cs, credentialNamespaces, connectVariant)
{
	var f = document.pform;
	
	if (connectType == 'composite' || connectType == 'virtualviewmanager' || connectType == 'db2' || connectType == 'odbc' || connectType == 'openEdge' || connectType == 'redbrick' || connectType == 'teradata' || connectType == 'sqlodbc' || connectType == 'sybaseIQ' || connectType == 'netezza')
	{
		var TRUSTED_CONNECTION = "Trusted_Connection=yes";
		var indexOfTrustedConnection = cs.indexOf(TRUSTED_CONNECTION);

		// Determine if a userid and password are required.
		var start;
		var end;
		if (credentialNamespaces == 'true' && (connectType == 'composite' || connectType == 'virtualviewmanager' || connectType == 'sqlodbc' || connectType == 'teradata' || connectType == 'db2' || connectType == 'odbc' || connectType == 'netezza'))
		{
			selectRadioButton(f.authentication, 'namespace');
			
			if (indexOfTrustedConnection != -1) {
				cs = cs.substring(0, indexOfTrustedConnection - 1) + cs.substring(indexOfTrustedConnection + TRUSTED_CONNECTION.length);
			}
			
			if (cs.indexOf("^?Password:") != -1)
			{
				start = cs.indexOf("PWD=");
				end = cs.indexOf(";", start + 5);
				if (start != -1 && end != -1)
				{
					cs = cs.substring(0, start) + cs.substring(end + 1);
				}
			}
			start = cs.indexOf("UID=");
			end = cs.indexOf(";", start + 5);
			if (start != -1 && end != -1)
			{
				cs = cs.substring(0, start) + cs.substring(end + 1);
			}
		}
		else if (indexOfTrustedConnection != -1 && connectType == 'sqlodbc') 
		{
			selectRadioButton(f.authentication, 'windows');
			cs = cs.substring(0, indexOfTrustedConnection - 1) + cs.substring(indexOfTrustedConnection + TRUSTED_CONNECTION.length);
		}
		else if (cs.indexOf("^User ID:") != -1)
		{
			if (connectType == 'sqlodbc' || connectType == 'composite' || connectType == 'virtualviewmanager' || connectType == 'teradata' || connectType == 'db2' || connectType == 'odbc' || connectType == 'netezza')
			{
				selectRadioButton(f.authentication, 'signon');
			}
			else if (connectType == 'oracle') {
				selectRadioButton(f.authentication, 'signon');
				f.m_connection_use_userid.checked = true;
			}				
			else
			{
				f.m_connection_use_userid.checked = true;
			}
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
				start = cs.indexOf("PWD=");
				end = cs.indexOf(";", start + 5);
				if (start != -1 && end != -1)
				{
					cs = cs.substring(0, start) + cs.substring(end + 1);
				}
			}
			start = cs.indexOf("UID=");
			end = cs.indexOf(";", start + 5);
			if (start != -1 && end != -1)
			{
				cs = cs.substring(0, start) + cs.substring(end + 1);
			}
		}
		else if (connectType == 'sqlodbc' || connectType == 'composite' || connectType == 'virtualviewmanager' || connectType == 'teradata' || connectType == 'db2' || connectType == 'odbc' || connectType == 'netezza' || connectType == 'oracle')
		{
			selectRadioButton(f.authentication, 'none');
		}

		// Strip everything up to and including the database code.
		//		The offset is 10 because 7 for ;LOCAL; and 3 for XX; which is the database code.
		cs = cs.substring(cs.indexOf(";LOCAL;") + 10);

		// Determine the datasource name.
		start = cs.indexOf("DSN=");
		if (start != -1)
		{
			var end = cs.indexOf(";", start + 4);
			f.m_connection_database.value = cs.substring(start + 4, end);

			// Strip off the datasource name.
			cs = cs.substring(end + 1);
		}
		// Determine the collation sequence.
		start = cs.indexOf("@COLSEQ=");
		if (start != -1)
		{
			f.m_connection_colseq.value = cs.substring(start + 8);
		}

		// Determine the Async option.
		start = cs.indexOf("@ASYNC=");
		if (start != -1)
		{
			var useAsync = cs.substring(start + 7, start + 8);
			f.m_connection_use_async.checked = (useAsync == "1" ? true : false);
		}
		
		// Determine the connect timeout and reply timeout.
		start = cs.indexOf("@", start + 1);
		mid = cs.indexOf("/", start + 1);
		end = cs.indexOf("@", mid + 1);

		if (start != -1 && mid != -1 && end != -1)
		{
			f.m_connection_connect_time.value = cs.substring(start + 1, mid);
			f.m_connection_reply_time.value = cs.substring(mid + 1, end);
		}
		else
		{
			f.m_connection_connect_time.value = "0";
			f.m_connection_reply_time.value = "0";
		}
		// Determine the datasource Unicode access.
		start = cs.indexOf("@UNICODE");
		if (start != -1 && f.m_connection_odbc_access_mode)
		{
			f.m_connection_odbc_access_mode.checked = true;
		}
		
		start = cs.indexOf("@ASYNC=");
		if (start != -1)
		{
			f.m_connection_string.value = cs.substring(0, start);
		}
		else
		{
			f.m_connection_string.value = cs;
		}

		// Determine the User Identification Transform value.
		start = cs.indexOf("@TRANSFORMUID");
		if (start != -1)
		{
			f.m_transformUserIdentification.checked = true;
		}

		start = cs.indexOf("@TRUSTED_CONTEXT");
		if (start != -1)
		{
			f.m_connection_trusted_context.checked = true;
			start = cs.indexOf("@REGISTRY_NAME");
			if (start != -1)
			{
				end = cs.indexOf("@", start+14)
				f.m_connection_identity_propagation.value=cs.substring(start+15,end);
			}
			
			
		}		
	}
	else if (connectType == 'oracle')
	{
		var start;
		var end;
		var bHasUserID = false;
		var bHasPassword = false;
		if (credentialNamespaces == 'true')
		{
			selectRadioButton(f.authentication, 'namespace');
			var bHasUserID = true;
			var bHasPassword = true;

		} else {
			if (cs.indexOf("^User ID:") != -1)
			{
				bHasUserID = true;
				f.m_connection_use_userid.checked = true;
				f.m_connection_use_pword.disabled = false;
				if (cs.indexOf("^?Password:") != -1)
				{
					bHasPassword = true;
					f.m_connection_use_pword.checked = true;
				}
			}
		}

		// Strip everything up to and including the ORACLE@ token.
		cs = cs.substring(cs.indexOf(";ORACLE@") + 8);

		if (bHasUserID == true)
		{
			// Strip off the user id placeholder.
			cs = cs.substring(cs.indexOf("@") + 1);
		}
		// if we're left with an @ at the start then remove it. This should happen with Bering+ Oracle strings but not with Baltic strings
		else if (cs.indexOf("@") == 0)
		{
			cs = cs.substring(1);
		}

		// Determine the User Identification Transform value.
		start = cs.indexOf("@TRANSFORMUID");
		if (start != -1)
		{
			f.m_transformUserIdentification.checked = true;
		}

		// Determine the collation sequence.
		start = cs.indexOf("@COLSEQ=");
		if (start != -1)
		{
			f.m_connection_colseq.value = cs.substring(start + 8);
			// Strip off the collation sequence.
			cs = cs.substring(0, start);
		}

		// Strip off the password placeholder and everything after it.
		start = cs.indexOf("/");
		if (start != -1)
		{
			cs = cs.substring(0, start);
		}

	
		// What remains of cs should be the SQL*Net connection string.
		f.m_connection_database.value = cs;
	}
	else if (connectType == 'sql' || connectType == 'sql2005' || connectType == 'sql2008' || connectType == 'sql2012-2014')
	{
		// Determine if a userid and password are required.
		var start;
		var end;
		if (credentialNamespaces == 'true')
		{
			f.authentication[2].checked='true';
		}
		else if (cs.indexOf("^User ID:") != -1)
		{									
			f.authentication[3].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else if (cs.indexOf(";Integrated Security=SSPI") != -1)
		{
			f.authentication[1].checked = true;
		}
		else
		{
			f.authentication[0].checked = true;
		}

		// Determine the database name.
		f.m_connection_database.value = getField(cs, "Data Source=");

		// Determine the collation sequence.
		f.m_connection_colseq.value = getField(cs, "COLSEQ=");

		start = cs.indexOf("Initial Catalog=");
		if (-1 != start)
		{
			end = cs.indexOf(";", start + 16);
			var cat = '';
			if (end == -1)
			{
				cat = cs.substring(start + 16);
			}
			else
			{
				cat = cs.substring(start + 16, end);
			}
			if (cat == 'master')
			{
				f.m_connection_sql_database_choice[0].checked = true;
				f.m_connection_sql_database_choice[1].checked = false;
				f.m_connection_sql_database_name.value = '';
			}
			else
			{
				f.m_connection_sql_database_choice[0].checked = false;
				f.m_connection_sql_database_choice[1].checked = true;
				f.m_connection_sql_database_name.value = cat;
			}
		}

		//Determine the MARS connection
		if (connectType == 'sql2005' || connectType == 'sql2008' || connectType == 'sql2012-2014')
		{
			var marsconn = getField(cs, "MarsConn=");
			if (marsconn == 'YES') {
				f.m_connection_sql_marsconnection.value = 'YES' ;
			}
		}
		// Determine the application string.
		// Still waiting for the actual format (within the connect string) for this entry.
		f.m_connection_sql_application.value = getField(cs, "Application=");

		// last valid param can be either "MarsConn=" "Application=" or "Catalog=" 
		startMarsConn = cs.indexOf("MarsConn=");
		startApplication = cs.indexOf("Application=");
		startCatalog = cs.indexOf("Catalog=");

		last_valid_param = Math.max(startMarsConn, startApplication, startCatalog);
		
		// Determine the User Identification Transform value.
		start = cs.indexOf("@TRANSFORMUID");
		if (start != -1)
		{
			f.m_transformUserIdentification.checked = true;
			end = start;
		}
		else
		{
			end = cs.indexOf("@COLSEQ=");
		}
		
		// Determine optional params (if they exist)
		var optional_params ='';
		if (last_valid_param != -1)
		{
			start = cs.indexOf(";", last_valid_param);
			if (start != -1)
			{
				optional_params = cs.substring (start+1,end);
			}
		}
		f.m_connection_optional_parameters.value = optional_params;
	}
	else if (connectType == 'sybase' || connectType == 'sybase_ct15')
	{
		// Treat the prefixes
		if (cs.indexOf("^User ID:") != -1)
		{
			f.m_connection_use_userid.checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}

		if (connectType == 'sybase')
		{ 
			cs = cs.substring(cs.indexOf(";LOCAL;CT;") + 10);
		} else
		{
			cs = cs.substring(cs.indexOf(";LOCAL;CT15;") + 12);
		}

		var tokens = cs.split("@");
		var first = tokens[0];
		var start = first.indexOf("|");
		if (-1 != start)
		{
			var cat = first.substring(start+1);
			f.m_connection_sybase_database_choice[0].checked = (cat == "master");
			f.m_connection_sybase_database_choice[1].checked = (cat != "master");
			if (cat != "master")
			{
				f.m_connection_sybase_database_name.value = cat;
			}
			first = first.substring(0, start);
		}
		f.m_connection_database.value = first;

		var third = tokens[2];
		start = third.indexOf("/");
		if (-1 != start)
		{
			var value = third.substring(0, start);
			value = (value == '') ? '0' : value;
			f.m_connection_connect_time.value = value;
			third = third.substring(start + 1);
		}
		f.m_connection_reply_time.value = (third == '') ? '0' : third;

		var fourth = tokens[3];
		f.m_connection_packet.value = (fourth == '') ? '512' : fourth;

		var fifth = tokens[4];
		start = fifth.indexOf("ASYNC=");
		if (-1 != start)
		{
			var value = fifth.substring(start + 6);
			value = (value == '') ? '0' : value;
			var number = parseInt(value);
			for (var i = 1; i < 4; i++)
			{
				f.m_connection_sybase_async.options[i].selected = (number == i) ? true : false;
			}
		}

		var sixth = tokens[5];
		start = sixth.indexOf("POLL=");
		if (-1 != start)
		{
			var value = sixth.substring(start + 5);
			value = (value == '') ? '100' : value;
			f.m_connection_polling.value = value;
		}

		var seventh = tokens[6];
		f.m_connection_sybase_application.value = getField(seventh , "APPNAME=");

		var eigth = tokens[7];
		f.m_connection_colseq.value = getField(eigth, "COLSEQ=");
	}
	else if (connectType == 'informix')
	{
		// Treat the prefixes
		if (cs.indexOf("^User ID:") != -1)
		{
			f.m_connection_use_userid.checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}

		cs = cs.substring(cs.indexOf(";LOCAL;IF;") + 10);
		var colStart = cs.indexOf("@COLSEQ=");
		if (-1 != colStart)
		{
			f.m_connection_colseq.value = cs.substring(colStart + 8);
			cs = cs.substring(0, colStart);
		}

		var tokens = cs.split("@");
		f.m_connection_database.value = tokens[0];
		if (tokens.length > 1)
		{
			var middle = tokens[1];
			var start = middle.indexOf("|");
			if (-1 != start)
			{
				var service = middle.substring(start + 1);
				
				f.m_connection_service[0].checked = (service == "sqlexec");
				f.m_connection_service[1].checked = (service == "sqlturbo");
				f.m_connection_service[2].checked = (service != "sqlexec" && service != "sqlturbo");
				if (f.m_connection_service[2].checked)
				{
					f.m_connection_service_name.value = service;
				}

				middle = middle.substring(0, start);
			}
			
			start = middle.indexOf(":");
			if (-1 != start)
			{
				f.m_connection_servername.value = middle.substring(start + 1);
				middle = middle.substring(0, start);
			}

			f.m_connection_hostname.value = middle;
		}
	}
	
	
	
	else if (connectType == 'consolidation' || connectType == 'contributorSeries7')
	{
		f.m_connection_servername.value = getField(cs, "SERVER=");
		f.m_connection_port.value = getField(cs, "PORT=");
		if (connectType == 'contributorSeries7') 
		{
			if(f.m_connection_padid)
			{
				f.m_connection_padid.value = getField(cs, "PADID=");
			}
		}
	}
	
	else if (connectType == 'powercube')
	{
		// Determine if a userid and password are required.
		var start;
		var end;
		if (credentialNamespaces == 'true')
		{
			f.authentication[1].checked = true;
		}
		else
		{
			f.authentication[0].checked = true;
		}

		// Determine the cache size.
		if (getField(cs, "readCacheSize=") != '')
		{
			f.m_connection_cache_size.value = getField(cs, "readCacheSize=");
		}
		
		// Determine the Location string.
		if (getField(cs, "WIN_PATH=") != '')
		{
			f.m_connection_windows_cube.value = getField(cs, "WIN_PATH=");
		}
		else
		{
			// upgrade old powercube connections to the new UI (WO 1116)
			f.m_connection_windows_cube.value = getField(cs, "CUBE=");
		}

		f.m_connection_unix_cube.value = getField(cs, "UNIX_PATH=");

		if (cs.indexOf("^?Password:") != -1 && f.cube_password_checkbox)
		{
			f.cube_password_checkbox.checked = true;
		}
	}
	
	else if (connectType == 'msanalysis2005' || connectType == 'msanalysis2008' || connectType == 'msanalysis2012' || connectType == 'msanalysis2014' || connectType == 'msanalysis2016' || connectType == 'msanalysis2017')
	{
		// Determine if a userid and password are required.
		if (credentialNamespaces == 'true')
		{
			f.authentication[1].checked = true;
		}
		else if (cs.indexOf("^User ID:") != -1)
		{									
			f.authentication[2].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else if (cs.indexOf("Trusted_Connection=yes") != -1)
		{
			f.authentication[0].checked = true;
		}
		
		// Determine the server name.
		var serverField = getField(cs, "SERVER=");
		var position = serverField.indexOf("\\");
		if ( position != -1) 
		{
			f.m_connection_servername.value = serverField.slice(0, position);
			f.m_connection_namedinstance.value = serverField.slice(position+1); 
		}
		else {
			f.m_connection_servername.value = serverField;
			f.m_connection_namedinstance.value = ''; 
		}
	}
		
	else if (connectType == 'dbtwoolap')
	{
		// Determine if a userid and password are required.
		if (credentialNamespaces == 'true')
		{
			f.authentication[1].checked='true';
		}
		else if (cs.indexOf("^User ID:") != -1)
		{									
			f.authentication[2].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else
		{
			f.authentication[0].checked = true;
		}
		// Determine the server name.
		f.m_connection_servername.value = getField(cs, "SERVER=");
	}
	
	else if ((connectType == 'tm1'))
	{
		if (credentialNamespaces == 'true')
		{
			f.authentication[1].checked='true';
		}
		else if (cs.indexOf("^User ID:") != -1)
		{			
			f.authentication[2].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else
		{
			f.authentication[0].checked = true;
		}		
		//Determine the TM1 hostname 
		f.m_connection_hostname.value = getField(cs, "TM1AdminHost=");			
		// Determine the TM1 server name.
		f.m_connection_servername.value = getField(cs, "TM1ServerName=");
	}	
	else if ((connectType == 'tm1R'))
	{
		if (credentialNamespaces == 'true')
		{
			f.authentication[1].checked='true';
		}
		else if (cs.indexOf("^User ID:") != -1)
		{			
			f.authentication[2].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else
		{
			f.authentication[0].checked = true;
		}		
		//Determine the TM1 hostname 
		f.m_connection_hostname.value = getField(cs, "TM1AdminHost=");			
		// Determine the TM1 server name.
		f.m_connection_tm1port.value = getField(cs, "TM1ServerPort=");
		//determine the tm1 protocol
		var protocol =  getField(cs, "TM1Protocol=");
		if (protocol === 'https') {
			f.m_connection_use_ssl.checked = true;
		}
	}
	else if (connectType == 'odata')
	{

		if (cs.indexOf("^User ID:") != -1)
		{			
			f.authentication[1].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1)
			{
				f.m_connection_use_pword.checked = true;
			}
		}
		else
		{
			f.authentication[0].checked = true;
		}		
		//Determine the OData Service Root URI
		f.m_connection_service_root_URI.value = getField(cs, ";URL=");			
	}	
	else if (connectType == 'json')
	{
		f.m_connection_subType = getField(cs, ";SUBTYPE=");
		f.m_connection_url.value = getField(cs, ";URL=");
		f.m_connection_assembly.checked = (getField(cs, ";ASSEMBLY=") == 'true');
		if (f.m_connection_assembly.checked) {
			f.m_connection_schema.disabled = true;
			f.m_connection_http_method.disabled = true;
			if (f.m_connection_http_message_body) {
				f.m_connection_http_message_body.disabled = true;
			}
			f.m_connection_json_path.disabled = true;
		} else {
			f.m_connection_schema.value = getField(cs, ";SCHEMA=");
			f.m_connection_http_method.value = getField(cs, ";METHOD=");
			if(f.m_connection_http_method.value == 'POST'){
				f.m_connection_http_mime_type.value = getField(cs, ";MIME_TYPE=");
				f.m_connection_http_message_body.value = getField(cs, ";DATA=");
			}
			f.m_connection_json_path.value = getField(cs, ";PATH=");
		}
		f.m_connection_authentication_type.value = getField(cs,';AUTHENTICATION_TYPE=');
		if(f.m_connection_authentication_type.value == 'OAuth1.0'){
			f.m_connection_temporary_token_endpoint.value = getField(cs,';TEMPORARY_TOKEN_ENDPOINT=');
			f.m_connection_authorization_endpoint.value = getField(cs,';AUTHORIZATION_ENDPOINT=');
			f.m_connection_token_endpoint.value = getField(cs,';TOKEN_ENDPOINT=');
		}
		if(f.m_connection_authentication_type.value == 'OAuth2.0'){
			f.m_connection_authorization_endpoint.value = getField(cs,';AUTHORIZATION_ENDPOINT=');
			f.m_connection_token_endpoint.value = getField(cs,';TOKEN_ENDPOINT=');
			f.m_connection_scope.value = getField(cs,';SCOPE=');
		}
	}	
	else if (connectType == 'cognosnow')
	{
		// Determine if a userid and password are required.
		var start;
		var end;
		// Determine the CognosNow port.
		start = cs.indexOf(":");
		end = cs.indexOf("/", start + 1);
		if (start != -1 && end != -1)
		{
			f.m_connection_port.value = cs.substring(start+1, end);
		}
		//Determine the CognosNow server 
		var startServer = cs.indexOf("SERVER=");
		if (startServer != -1) {
			if (start!=-1) 
			{
				f.m_connection_servername.value = cs.substring(startServer+7, start);
			}
			else if (end!=-1)
			{
				f.m_connection_servername.value = cs.substring(startServer+7, end-1);			
			}
		}

		//Determine the file name and path.
		start = cs.indexOf("/");
		if (start != -1)
		{
			cs = cs.substring(start, cs.length-1);
		}
	}
	else if (connectType == 'sap')
	{

		// Determine the server name.
		f.m_connection_database.value = getField(cs, "server=");

		// Determine the system number.
		if (f.m_connection_sys_no)
		{
			f.m_connection_sys_no.value = getField(cs, "sysnr=");
		}

		// Determine the system id.
		if (f.m_connection_sys_id)
		{
			f.m_connection_sys_id.value = getField(cs, "sysid=");
		}
		
		// Determine the logon group.
		if (f.m_connection_logon)
		{
			f.m_connection_logon.value = getField(cs, "logonGroup=");
		}
		
		// Determine the client number.
		f.m_connection_client_no.value = getField(cs, "client=");

		// Determine the system number.
		if (f.m_connection_sap_codepage)
		{
			var value = getField(cs, "codePage=")
			if (value == '')
			{
				f.m_connection_sap_codepage.value = "4110";
			}			
			else
			{
				f.m_connection_sap_codepage.value = value;
			}
		}

		// default the signon section
		if (f.authentication)
		{
			if (credentialNamespaces == 'true')
			{
				f.authentication[0].checked = true;
			}
			else
			{
				f.authentication[1].checked = true;
			}
		}

		// Determine the router string.
		if (f.m_connection_router_string)
		{
			f.m_connection_router_string.value = getField(cs, "routerString=");
		}

		// Determine the User Identification Transform value.
		if (cs.indexOf("@TRANSFORMUID") != -1)
		{
			f.m_transformUserIdentification.checked = true;
		}
	}
	else if (connectType == 'sapR3' || connectType == 'sapECC')
	{

		// Determine the server name.
		f.m_connection_hostname.value = getField(cs, "hostname=");

		f.m_connection_sys_no.value = getField(cs, "sysnr=");

		f.m_connection_gateway_host.value = getField(cs, "gateway_host=");

		f.m_connection_gateway_service.value = getField(cs, "gateway_service=");

		f.m_connection_client.value = getField(cs, "client=");

		f.m_connection_destination.value = getField(cs, "destination=");
		
		f.m_connection_sap_language.value = getField(cs, "language=");

		// Determine the background.
		var value = getField(cs, "background=")
		if (value == 'ON')
		{
			f.m_connection_background.checked=true;
		}
		else
		{
			f.m_connection_background.checked=false;
		}
		if (connectType == 'sapR3')
		{
			var cogudajoin = getField(cs, "cogudaouterjoin=");
			if (cogudajoin == 'ON')
			{
				f.m_connection_cogudaouterjoin.value = cogudajoin;
			}
		}
		// Determine the collation sequence.
		f.m_connection_colseq.value = getField(cs, "COLSEQ=");
	}
	else if (connectType == 'jdbc-db2')
	{
		// [^User ID:][^?Password:];LOCAL;JD-D2;URL=<URLSPEC>;DRIVER_NAME=com.ibm.db2.jcc.DB2Driver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:db2://<SERVERNAME>:<PORT>/<DBNAME>[:[jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		// Authentication:  [0] None, [1] Namespace, [2] Signon (User ID/[Password])
		
		if (credentialNamespaces == 'true') {
			f.authentication[1].checked = true;
		} else if (cs.indexOf("^User ID:") != -1) {
			f.authentication[2].checked = 'true';
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		} else {
			f.authentication[0].checked = 'true';
		}

		var serverNameEnd;
		var urlProtocol = "jdbc:db2://";
		var urlStart = cs.indexOf(urlProtocol);
		if (urlStart != -1) {
			serverNameEnd = cs.indexOf(":", urlStart + urlProtocol.length);
			if (serverNameEnd != -1) {
				f.m_connection_servername.value = cs.substring(urlStart + urlProtocol.length, serverNameEnd);
			}
		}
		
		var portEnd = cs.indexOf("/", serverNameEnd + 1);
		if (portEnd != -1) {
			f.m_connection_port.value = cs.substring(serverNameEnd + 1, portEnd);
		}
		
		var urlEnd;
		var dbNameEnd = cs.indexOf(":", portEnd + 1);
		if (dbNameEnd != -1) {
			// has JDBC properties
			f.m_connection_jdbc_database_name.value = cs.substring(portEnd + 1, dbNameEnd);
			var urlEnd = cs.indexOf(";DRIVER_NAME", dbNameEnd + 1);
			if (urlEnd != -1) {
				f.m_connection_jdbc_parameters.value = cs.substring(dbNameEnd + 1, urlEnd);
			}
		} else {
			var urlEnd = cs.indexOf(";DRIVER_NAME", portEnd + 1);
			if (urlEnd != -1) {
				f.m_connection_jdbc_database_name.value = cs.substring(portEnd + 1, urlEnd);
			}
		}

		if (isCheckboxChecked(f.m_transformUserIdentification)){
			connectString += '@TRANSFORMUID=TRUE';
		}

		f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, urlEnd + 1, "LOCALSORT=", ";");
		f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, urlEnd + 1, "LEVEL=", ";");

	}	
	else if (connectType == 'jdbc-oracle')
	{
		// [^User ID:][^?Password:];LOCAL;JD-OR;URL=<URLSPEC>;DRIVER_NAME=oracle.jdbc.OracleDriver  [;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:oracle:thin:@//<SERVERNAME>:<PORT>/<SERVICE_D>
		// URLSPEC = jdbc:oracle:thin:@(DESCRIPTION=...) 
		// URLSPEC = jdbc:oracle:thin:@(DESCRIPTION_LIST=...)
		// URLSPEC = jdbc:oracle:oci:@<TNS_NAME>
		// URLSPEC = jdbc:oracle:oci:@(DESCRIPTION=...)
		// or URLSPEC = jdbc:oracle:oci:@(DESCRIPTION_LIST=...)
		
		// Authentication:  Signon (User ID/[Password])
		
		if (cs.indexOf("^User ID:") != -1) {
			f.m_connection_use_userid.checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		}

		var urlEnd;
		if (cs.indexOf('DESCRIPTION') != -1 || cs.indexOf('DESCRIPTION_LIST') != -1) {
			// Oracle Net Descriptor
			f.m_connection_jdbc_oracle_style[2].checked = true;
			
			var thinURLProtocol = "jdbc:oracle:thin:@";
			var thinURLStart = cs.indexOf(thinURLProtocol);
			if (thinURLStart != -1) {
				// Thin
				f.m_connection_jdbc_oracle_driver_type[0].checked = true;
				
				urlEnd = cs.indexOf(";DRIVER_NAME", thinURLStart + thinURLProtocol.length);
				if (urlEnd != -1) {
					f.m_connection_oracle_net_descriptor.value = formatOracleNetDesc(cs.substring(thinURLStart + thinURLProtocol.length, urlEnd));
				}
				
			} else {
				// OCI
				f.m_connection_jdbc_oracle_driver_type[1].checked = true;
				
				var ociProtocol = "jdbc:oracle:oci:@";
				var ociURLStart = cs.indexOf(ociProtocol);
				if (ociURLStart != -1) {
					urlEnd = cs.indexOf(";DRIVER_NAME", ociURLStart + ociProtocol.length);
					if (urlEnd != -1) {
						f.m_connection_oracle_net_descriptor.value = formatOracleNetDesc(cs.substring(ociURLStart + ociProtocol.length, urlEnd));
					}
				}
			}
			
		} else {
			var thinServiceIDProtocol = "jdbc:oracle:thin:@//";
			var thinURLStart = cs.indexOf(thinServiceIDProtocol);
			if (thinURLStart != -1) {
				// Service ID
				f.m_connection_jdbc_oracle_style[0].checked = true;
				
				var serverNameEnd = cs.indexOf(":", thinURLStart + thinServiceIDProtocol.length);
				if (serverNameEnd != -1) {
					f.m_connection_servername.value = cs.substring(thinURLStart + thinServiceIDProtocol.length, serverNameEnd);
				}
				
				var portEnd = cs.indexOf("/", serverNameEnd + 1);
				if (portEnd != -1) {
					f.m_connection_port.value = cs.substring(serverNameEnd + 1, portEnd);
				}
				
				urlEnd = cs.indexOf(";DRIVER_NAME", portEnd + 1);
				if (urlEnd != -1) {
					f.m_connection_oracle_service_id.value = cs.substring(portEnd + 1, urlEnd);
				}
			} else {
				var ociProtocol = "jdbc:oracle:oci:@";
				var ociURLStart = cs.indexOf(ociProtocol);
				if (ociURLStart != -1) {
					// TNS Names Alias
					f.m_connection_jdbc_oracle_style[1].checked = true;
				
					urlEnd = cs.indexOf(";DRIVER_NAME", ociURLStart + ociProtocol.length);
					if (urlEnd != -1) {
						f.m_connection_oracle_tns_name.value = cs.substring(ociURLStart + ociProtocol.length, urlEnd);
					}
				}
			}
		}
		
		// find out if there are driver specific properties
		// urlEnd = cs.indexOf(";DRIVER_NAME");
		var driverEnd = cs.indexOf(";", urlEnd + ";DRIVER_NAME".length);
		if (driverEnd != -1) {
			var localsortstart = cs.indexOf(";LOCALSORT", driverEnd)
			if (localsortstart != -1) { 
				if (localsortstart != driverEnd ) {
				 f.m_connection_jdbc_parameters.value = cs.substring(driverEnd + 1, cs.indexOf(";LOCALSORT", driverEnd));
				}
			} else {
				f.m_connection_jdbc_parameters.value = cs.substring(driverEnd + 1);
			}
			f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, urlEnd + 1, "LOCALSORT=", ";");
			f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, urlEnd + 1, "LEVEL=", ";");
		}			
	}	
	else if (connectType == 'jdbc-generic' || connectType == 'lob-jdbc')
	{
		// [^User ID:][^?Password:];LOCAL;JDBC;URL=jdbc:<subprotocol>:<URL>;DRIVER_NAME=<DRIVER_NAME>[;CognosProperty1=value1[;...]]
		// where 
        // subprotocol is defined in generateDatasourceMetadata.
		// URL is user specified.

		if (credentialNamespaces == 'true' ) {
			selectRadioButton(f.authentication, 'namespace');		
		} else if (cs.indexOf("^User ID:") != -1) {			
			selectRadioButton(f.authentication, 'signon');
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		} else {
			selectRadioButton(f.authentication, 'none');
		}
		
		var urlConstant = "URL=";
		var urlStart = cs.indexOf(urlConstant)
		if (urlStart != -1) {
			var urlEnd;
			var driverConstant = ";DRIVER_NAME=";
			urlEnd = cs.indexOf(driverConstant, urlStart + urlConstant.length);
			if (urlEnd != -1) {
				var jdbcUrl = cs.substring(urlStart + urlConstant.length, urlEnd);
                var protocolStart = "jdbc:".length;
				// Sybase and Greenplum have ':' in the protocol name so searching for the first index doesn't work
				// Have to put in a static check for now. If we get too many exceptions we should look at
				// reading the connections metadata file for a list subprotocols.
                var protocolEnd = jdbcUrl.indexOf(":", protocolStart);
                if (protocolEnd != -1) {
					var subprotocol = jdbcUrl.substring(protocolStart, protocolEnd);
					if (subprotocol.toLowerCase() == "sybase" || subprotocol.toLowerCase() == "pivotal") {
						protocolEnd = jdbcUrl.indexOf(":", protocolEnd + 1);
						subprotocol = jdbcUrl.substring(protocolStart, protocolEnd);
					}
                    f.m_jdbc_connection_code = subprotocol;
					f.m_jdbc_connection_url.value = jdbcUrl;
                }
				var driverEnd = cs.indexOf(";", urlEnd + driverConstant.length);
				if (driverEnd != -1) {
					f.m_jdbc_driver_class.value = cs.substring(urlEnd + driverConstant.length, driverEnd);
					var localSort = "LOCALSORT=";
					var propEnd = cs.indexOf(localSort, driverEnd + 1);
					if (propEnd == -1) {
						f.m_jdbc_connection_properties.value = cs.substring(driverEnd + 1);
					} else if (propEnd == 0) {
						f.m_jdbc_connection_properties.value = '';
					} else {
						f.m_jdbc_connection_properties.value = cs.substring(driverEnd + 1, propEnd);
					}
					f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, driverEnd, "LOCALSORT=", ";");
					f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, driverEnd, "LEVEL=", ";");
				} else {
					f.m_jdbc_driver_class.value = cs.substring(urlEnd + driverConstant.length);
				}
				
				// Determine the User Identification Transform value.
				start = cs.indexOf("@TRANSFORMUID");
				if (start != -1)
				{
					f.m_transformUserIdentification.checked = true;
				}
			}
		}
	}
	else if (connectType == 'filenet')
	{
		// [^User ID:][^?Password:];LOCAL;RP-CMIS-FILENET;URL=<URLSPEC>;DRIVER_NAME=<DRIVER_NAME>;ROOT=GRAPHIC[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = specific to the driver
		
		// Authentication:  Signon (User ID/[Password])
		
		if (cs.indexOf("^User ID:") != -1) {
			f.m_connection_use_userid.checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		}
		
		connectionData = [
			{key: "URL=", field: "m_connection_jdbc_url", end: ";DRIVER_NAME="},
			{key: "DRIVER_NAME=", field: "m_connection_jdbc_driverclass", end: ";"},
			{key: "ROOT=", field: "m_connection_file", end: ";"},
			{key: "PROVIDER=", field: "", end: ";"}
		];
		var startAt = cs.indexOf(connectionData[1].key);
		var repositoryPluginType = getFieldStartingAt(cs, startAt, connectionData[1].key, connectionData[1].end);
		var provider;
		var isFilesystem = false;
		if(repositoryPluginType == 'com.ibm.cognos.cm.fileSystemPlugin.FileSystemArchivePlugin') {
			f[connectionData[1].field].value = "FileSystem";
			isFilesystem = true;
		} else {
			startAt = cs.indexOf(connectionData[3].key);
			if (startAt>=0) {
				provider = getFieldStartingAt(cs, startAt, connectionData[3].key, connectionData[3].end);
				if (isSupportedCmisProvider(provider)) {
					f[connectionData[1].field].value = "CMIS_" + provider;
				} else {
					f[connectionData[1].field].value = "CMIS_FileNet";
				}
			} else {
				f[connectionData[1].field].value = "CMIS_FileNet";
			}
		}
		repoTypeSelectInd=f[connectionData[1].field].selectedIndex;
		
		startAt = cs.indexOf(connectionData[0].key);
		if(isFilesystem) {
			f[connectionData[0].field].value = getFieldStartingAt(cs, startAt, connectionData[0].key+'alias:', connectionData[0].end);
		} else {
			f[connectionData[0].field].value = getFieldStartingAt(cs, startAt, connectionData[0].key, connectionData[0].end);
		}
		var endAt = 0;
		startAt = cs.indexOf(connectionData[2].key);
		if (startAt >= 0) {
			f[connectionData[2].field].value = getFieldStartingAt(cs, startAt, connectionData[2].key, connectionData[2].end);
			if (isSupportedCmisProvider(provider)) {
				endAt = cs.indexOf(connectionData[3].key) + connectionData[3].key.length + provider.length;
			} else {
				endAt = cs.indexOf(connectionData[2].key) + connectionData[2].key.length + f[connectionData[2].field].value.length;
			}
		} else {
			if (isSupportedCmisProvider(provider)) {
				endAt = cs.indexOf(connectionData[3].key) + connectionData[3].key.length + provider.length;
			} else {
				endAt = cs.indexOf(connectionData[1].key) + connectionData[1].key.length + repositoryPluginType.length;
			}
		}
		f.m_connection_jdbc_parameters.value = cs.substring(endAt + 1);
	}
	else if (connectType == 'jdbc-sql')
	{
		// [^User ID:][^?Password:];LOCAL;JD-SS;URL=<URLSPEC>;DRIVER_NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:sqlserver://<SERVERNAME>:<PORT>[;INSTANCENAME=<INSTNAME>];DATABASE=<DB>[;LOGINTIMEOUT=<TIMEOUT>][;integratedSecurity=true][;[jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		// Authentication:  [0] None, [1] C8 service creds, [2] Namespace, [3] Signon (User ID/[Password])

		if (credentialNamespaces == 'true') {
			f.authentication[2].checked = 'true';
		} else if (cs.indexOf("^User ID:") != -1) {									
			f.authentication[3].checked = true;
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		} else if (cs.indexOf(";integratedSecurity=true") != -1) {
			f.authentication[1].checked = true;
		} else {
			f.authentication[0].checked = true;
		}
		
		var serverNameEnd;
		var urlProtocol = "jdbc:sqlserver://";
		var urlStart = cs.indexOf(urlProtocol);
		var portEnd = -1;
		if (urlStart != -1) {
			serverNameEnd = cs.indexOf(":", urlStart + urlProtocol.length);
            portEnd = cs.indexOf(";", urlStart + urlProtocol.length);
            var hasPort = true;
            if (serverNameEnd == -1 || serverNameEnd > portEnd) {
                serverNameEnd = portEnd;
                hasPort = false;
            }
			if (serverNameEnd != -1) {
				f.m_connection_servername.value = cs.substring(urlStart + urlProtocol.length, serverNameEnd);
			}
            if (hasPort) {
                f.m_connection_port.value = cs.substring(serverNameEnd + 1, portEnd);
            }
		}
		
		var startingWith = "INSTANCENAME=";
		var start = cs.indexOf(startingWith, portEnd + 1);
		if (start != -1) {
			var end = cs.indexOf(";", start + startingWith.length);
			if (end != -1) {
				f.m_connection_sql_instance_name.value = cs.substring(start + startingWith.length, end);
			} else {
				f.m_connection_sql_instance_name.value = cs.substring(start + startingWith.length);
			}
			cs = cs.replace(eval("/;" + startingWith + f.m_connection_sql_instance_name.value + "/"), "");
		}
		
		var startingWith = "DATABASE=";
		var start = cs.indexOf(startingWith, portEnd + 1);
		if (start != -1) {
			var end = cs.indexOf(";", start + startingWith.length);
			if (end != -1) {
				f.m_connection_jdbc_database_name.value = cs.substring(start + startingWith.length, end);
			} else {
				f.m_connection_jdbc_database_name.value = cs.substring(start + startingWith.length);
			}
			cs = cs.replace(eval("/;" + startingWith + f.m_connection_jdbc_database_name.value + "/"), "");
		}

		var startingWith = "LOGINTIMEOUT=";
		var start = cs.indexOf(startingWith, portEnd + 1);
		if (start != -1) {
			var end = cs.indexOf(";", start + startingWith.length);
			if (end != -1) {
				f.m_connection_jdbc_connect_time.value = cs.substring(start + startingWith.length, end);
			} else {
				f.m_connection_jdbc_connect_time.value = cs.substring(start + startingWith.length);
			}
			cs = cs.replace(eval("/;" + startingWith + f.m_connection_jdbc_connect_time.value + "/"), "");
		}
		
		cs = cs.replace(/;integratedSecurity=true/, "");
		
		var startingWith = ";DRIVER_NAME=";
		var start = cs.indexOf(startingWith, portEnd);
		if (start != portEnd) {
			f.m_connection_jdbc_parameters.value = cs.substring(portEnd + 1, start);
		}
		 
		f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, portEnd + 1, "LOCALSORT=", ";");
		f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, portEnd + 1, "LEVEL=", ";");

	}	
	else if (connectType == 'jdbc-teradata')
	{
		// [^User ID:][^?Password:];LOCAL;JD-TD;URL=<URLSPEC>;DRIVER_NAME=com.teradata.jdbc.TeraDriver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:teradata://<SERVERNAME>/DBS_PORT=<PORT>,DATABASE=<DBNAME>[,jdbcproperty1=jdbcvalue1][,jdbcproperty2=jdbcvalue2]...
		
		// Authentication:  [0] None, [1] Namespace, [2] Signon (User ID/[Password])
		
		if (credentialNamespaces == 'true') {
			f.authentication[1].checked = true;
		} else if (cs.indexOf("^User ID:") != -1) {
			f.authentication[2].checked = 'true';
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		} else {
			f.authentication[0].checked = 'true';
		}

		var serverNameEnd;
		var urlProtocol = "jdbc:teradata://";
		var urlStart = cs.indexOf(urlProtocol);
		var dbs_port = "DBS_PORT=";
		var dbs_port_start = cs.indexOf(dbs_port, serverNameEnd + 1);
		
		if (urlStart != -1) {
			if (dbs_port_start != -1) {
				serverNameEnd = cs.indexOf("/", urlStart + urlProtocol.length);
			} else {
				serverNameEnd = cs.indexOf(",", urlStart + urlProtocol.length);
				if (serverNameEnd == -1){
					serverNameEnd = cs.indexOf(";", urlStart + urlProtocol.length);
				}	
			}
			
			if (serverNameEnd != -1) {
				f.m_connection_servername.value = cs.substring(urlStart + urlProtocol.length, serverNameEnd);
			}
		}
		
		var startingWith = "DBS_PORT=";
		var start = cs.indexOf(startingWith, serverNameEnd + 1);
		if (start != -1) {
			var end = cs.indexOf(",", start + startingWith.length);
			if (end != -1) {
				f.m_connection_port.value = cs.substring(start + startingWith.length, end);
			} else {
				var end = cs.indexOf(";", start + startingWith.length);
				if (end != -1) {
					f.m_connection_port.value = cs.substring(start + startingWith.length, end);
				}
			}
			var separator = "";
			if (cs.charAt(start-1) == ",") {
				separator = ",";
			}
			cs = cs.replace(eval("/" + separator + startingWith + f.m_connection_port.value + "/"), "");
		}
		
		var startingWith = "DATABASE=";
		var start = cs.indexOf(startingWith, serverNameEnd);
		if (start != -1) {
			var end = cs.indexOf(",", start + startingWith.length);
			if (end != -1) {
				f.m_connection_jdbc_database_name.value = cs.substring(start + startingWith.length, end);
			} else {
				var end = cs.indexOf(";", start + startingWith.length);
				if (end != -1) {
					f.m_connection_jdbc_database_name.value = cs.substring(start + startingWith.length, end);
				}
			}
			var separator = "";
			if (cs.charAt(start-1) == ",") {
				separator = ",";
			}
			cs = cs.replace(eval("/" + separator + startingWith + f.m_connection_jdbc_database_name.value + "/"), "");
		}
		
		var startingWith = ";DRIVER_NAME=";
		var start = cs.indexOf(startingWith, serverNameEnd);
		if (start != serverNameEnd + 1 && start != serverNameEnd) {
			if (cs.charAt(serverNameEnd + 1) == ",") {
				f.m_connection_jdbc_parameters.value = cs.substring(serverNameEnd + 2, start);
			} else {
				f.m_connection_jdbc_parameters.value = cs.substring(serverNameEnd + 1, start);
			}
		}		

		f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, serverNameEnd + 1, "LOCALSORT=", ";");
		f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, serverNameEnd + 1, "LEVEL=", ";");

	}	
	else if (connectType == 'jdbc-netezza')
	{
		// [^User ID:][^?Password:];LOCAL;JD-NZ;URL=<URLSPEC>;DRIVER_NAME=org.netezza.Driver[;CognosProperty1=value1[;...]]
		// where 
		// URLSPEC = jdbc:netezza://<SERVERNAME>[:<PORT>]/<DBNAME>[[;jdbcproperty1=jdbcvalue1][;jdbcproperty2=jdbcvalue2]...]
		
		// Authentication:  [0] None, [1] Namespace, [2] Signon (User ID/[Password])
		
		if (credentialNamespaces == 'true') {
			f.authentication[1].checked = true;
		} else if (cs.indexOf("^User ID:") != -1) {
			f.authentication[2].checked = 'true';
			f.m_connection_use_pword.disabled = false;
			if (cs.indexOf("^?Password:") != -1) {
				f.m_connection_use_pword.checked = true;
			}
		} else {
			f.authentication[0].checked = 'true';
		}


		var serverNameEnd;
		var urlProtocol = "jdbc:netezza://";
		var urlStart = cs.indexOf(urlProtocol);
		
		if (urlStart != -1) {
		    var serverPortEnd = cs.indexOf("/", urlStart + urlProtocol.length);
		    if (serverPortEnd != -1) {
		        var serverAndPort = cs.substring(urlStart + urlProtocol.length, serverPortEnd);
		        var indexOfPortStart = serverAndPort.indexOf(":");
		        if (indexOfPortStart == -1){
		            //in this case there was no port so just set the sername to the whole thing and forget about the port
		            f.m_connection_servername.value = serverAndPort;
		        } else {
                    //in this case we have a server and a port so need to take care of that
                    f.m_connection_servername.value =  serverAndPort.substring(0, indexOfPortStart);
                    f.m_connection_port.value =   serverAndPort.substring(indexOfPortStart + 1);  
		        }
		    }    
		}
		
		var urlEnd;
		var dbNameEnd = cs.indexOf(";", serverPortEnd + 1);
		if (dbNameEnd != -1) {
			f.m_connection_jdbc_database_name.value = cs.substring(serverPortEnd + 1, dbNameEnd);
			urlEnd = cs.indexOf(";DRIVER_NAME", dbNameEnd + 1);
			if (urlEnd != -1) {
				f.m_connection_jdbc_parameters.value = cs.substring(dbNameEnd + 1, urlEnd);
			}
		}
		
		f.m_connection_jdbc_sort_colseq.value = getFieldStartingAt(cs, urlEnd + 1, "LOCALSORT=", ";");
		f.m_connection_jdbc_sort_level.value = getFieldStartingAt(cs, urlEnd + 1, "LEVEL=", ";");

	}	
	else if (connectType == 'xml')
	{
		f.m_connection_database.value = cs.substring(11);	
	}
	else if (connectType == "sr3")
	{
		var connectionData = cs.substring(43);
		var indexOfLB = connectionData.indexOf("LB:");
		var endIndex = 0;
		if (indexOfLB == -1)
		{
			endIndex = connectionData.indexOf(":");
			f.m_connection_application_server.value = connectionData.substring(0,endIndex);
		    connectionData = connectionData.substring(endIndex + 1);
		    endIndex = connectionData.indexOf(":");
		    f.m_connection_system_number.value = connectionData.substring(0,endIndex);
		    connectionData = connectionData.substring(endIndex + 1);
		}
		else
		{
			f.m_connection_use_loadbalancing.checked = true; 
			f.m_connection_use_loadbalancing_hidden.value = "true";
			endIndex = connectionData.indexOf(":", indexOfLB + 3);
			f.m_connection_message_server.value = getFieldStartingAt(connectionData, 0, "LB:", ":");
		    connectionData = connectionData.substring(endIndex + 1);
		    endIndex = connectionData.indexOf(":");
		    f.m_connection_system_id.value = connectionData.substring(0,endIndex);
		    connectionData = connectionData.substring(endIndex + 1);
		    endIndex = connectionData.indexOf(":");
		    f.m_connection_logon_group.value = connectionData.substring(0,endIndex);
		    connectionData = connectionData.substring(endIndex + 1);
		}
		f.m_connection_router_string.value = getFieldStartingAt(connectionData, 0, "ROUTER_STRING=", ":");
		endIndex = connectionData.indexOf(":");
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf(":");
		f.m_connection_client.value = connectionData.substring(0,endIndex);
		connectionData = connectionData.substring(endIndex + 1);
		endIndex = connectionData.indexOf(";");
		f.m_connection_language.value = connectionData.substring(0,endIndex);
		connectionData = connectionData.substring(endIndex + 1);
		f.m_connection_max_conn_in_pool.value = getFieldStartingAt(connectionData, 0, "MAX_CONN=", ";"); 
		f.m_connection_abap_query_db_access_limit.value = getFieldStartingAt(connectionData, 0, "ABAP_QUERY_DB_ACCESSES=", ";");
		f.m_connection_table_row_count.value = getFieldStartingAt(connectionData, 0, "TABLE_READ_COUNT=", ";");
		f.m_connection_table_read_function.value = getFieldStartingAt(connectionData, 0, "READ_TABLE_FUNCTION_NAME=", ";");
	}
	else if (connectType == "sfdc")
	{
		if (cs.indexOf("^?Password:") != -1)
		{
			f.m_connection_use_pword.checked = true;
		}

		var startIndex = cs.indexOf("sfdc:");
		var connectionData = cs.substring(startIndex+5);
		var endIndex = connectionData.indexOf(";");
		f.m_connection_url.value = connectionData.substring(0,endIndex);
		f.m_connection_conc_calls_limit.value = getFieldStartingAt(connectionData, 0, "CONCURRENT_CALLS_LIMIT=", ";");
		f.m_connection_user_conc_calls_limit.value = getFieldStartingAt(connectionData, 0, "USER_CONCURRENT_CALLS_LIMIT=", ";");
		f.m_connection_timeout.value = getFieldStartingAt(connectionData, 0, "CONNECTION_TIMEOUT=", ";");
		f.m_connection_query_batch_size.value = getFieldStartingAt(connectionData, 0, "QUERY_BATCH_SIZE=", ";");
		f.m_connection_max_retries.value = getFieldStartingAt(connectionData, 0, "MAX_RETRIES=", ";");
		f.m_connection_wait_between_retries.value = getFieldStartingAt(connectionData, 0, "WAIT_BETWEEN_RETRIES=", ";");

		if (getFieldStartingAt(connectionData, 0, "PROXY_ENABLED=", ";") == "true") {
			f.m_connection_proxy_enabled.checked = true;
			disableProxyControls(false);
		} else {
			f.m_connection_proxy_enabled.checked = false;
			disableProxyControls(true);
		}
		
		setProxyControls();
		
		f.m_connection_proxy_host.value = getFieldStartingAt(connectionData, 0, "PROXY_HOST=", ";");
		f.m_connection_proxy_port.value = getFieldStartingAt(connectionData, 0, "PROXY_PORT=", ";");
	}	
	else if (connectType == "siebel")
	{
		var connectionData = cs.substring(49);
	    var endIndex = connectionData.indexOf(".");
	    f.m_connection_transport.value = connectionData.substring(0,endIndex);
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf(".");
	    f.m_connection_encryption.value = connectionData.substring(0,endIndex);
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf(":");
	    f.m_connection_compression.value = connectionData.substring(0,endIndex);
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf(":");
	    f.m_connection_gatewayserver.value = connectionData.substring(2,endIndex); 
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf("/");
	    f.m_connection_gatewayport.value = connectionData.substring(0,endIndex); 
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf("/");
	    f.m_connection_enterprise_name.value = connectionData.substring(0,endIndex); 
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf("_");
	    f.m_connection_aom.value = connectionData.substring(0,endIndex); 
	    connectionData = connectionData.substring(endIndex + 1);
	    endIndex = connectionData.indexOf(";");
	    f.m_connection_language.value = connectionData.substring(0,endIndex); 
	    connectionData = connectionData.substring(endIndex + 1);
	    f.m_connection_siebel_repo.value = getFieldStartingAt(connectionData, 0, "REPOSITORY_NAME=", ";");
	    f.m_connection_login_retries.value = getFieldStartingAt(connectionData, 0, "LOGIN_RETRY_COUNT=", ";");
	    f.m_connection_login_retry_delay.value = getFieldStartingAt(connectionData, 0, "LOGIN_RETRY_DELAY=", ";");
	    f.m_connection_local_sort.value = getFieldStartingAt(connectionData, 0, "LOCALSORT=", ";");
	    f.m_connection_level.value = getFieldStartingAt(connectionData, 0, "LEVEL=", ";");
	    f.m_connection_charset.value = getFieldStartingAt(connectionData, 0, "CHARSET=", ";");
	    f.m_connection_adv_parameters.value = getFieldStartingAt(connectionData, 0, "ADVANCED_PARAMETERS=", ";");
	}	
	else if (connectType == 'other')
	{
		f.m_other_connectionString.value = cs;
	}

}

function getFieldStartingAt(string, startingAt, startingWith, endingWith)
{
	var start = string.indexOf(startingWith, startingAt);
	if (start != -1) {
		var end = string.indexOf(endingWith, start + startingWith.length);
		if (end == -1) {
			return(string.substring(start + startingWith.length));
		}
		return(string.substring(start + startingWith.length, end));
	}
	return '';
}

// Searches the string for a given param and sets the frmField to the value found
function getField(string, param)
{
	start = string.indexOf(param);

	if (start != -1)
	{
		end = string.indexOf(";", start + param.length);
		if (end == -1)
		{
			return(string.substring(start + param.length));
		}
		
		return(string.substring(start + param.length, end));
	}
	return '';
}

function togglePasswordCheckbox()
{
	var f = document.pform;

	if (f.m_connection_default_signon && f.m_connection_default_signon.checked)
	{
		disablePasswordFields(!f.m_connection_use_pword.checked);	
	}
}

function toggleCreateSignon()
{
	var f = document.pform;
	var defaultSignonChecked = f.m_connection_default_signon && f.m_connection_default_signon.checked;
	
	disableUserIDField(!defaultSignonChecked);
	if (f.m_connection_use_pword)
	{
		disablePasswordFields(!(defaultSignonChecked && f.m_connection_use_pword.checked));
	}
	else
	{
		disablePasswordFields(!defaultSignonChecked);
	}
}

function toggleAssemblyCheckbox()
{
	var f = document.pform;

	disableAssemblyFields(f.m_connection_assembly.checked);
}

function updateRepositoryType() {
	var f = document.pform;
	if (f.m_connection_jdbc_driverclass.value == "FileSystem") {
		if (f.fsAliasRoot_select.length==0) {
			window.alert(repo_fs_none_msg);
			f.m_connection_jdbc_driverclass.selectedIndex=repoTypeSelectInd;
			return;
		}
	}
	
	var allowSwitch = true;
	if (f.m_connection_file.value!='' || f.m_connection_jdbc_parameters.value!='') {
		allowSwitch = confirm(repo_wmsg);
	} else {
		if (f.m_connection_jdbc_driverclass.options[repoTypeSelectInd].value == "FileSystem") {
			if (f.fsAliasRoot_select.selectedIndex!=0) {
				allowSwitch = confirm(repo_wmsg);
			}
		} else {
			if (f.cmisURL_input.value!='' || !f.m_connection_use_userid.checked || !f.m_connection_use_pword.checked  || (f.m_connection_default_signon!=null && !f.m_connection_default_signon.checked)
				|| (f.m_connection_userid!=null && f.m_connection_userid.value!='') || (f.m_connection_password!=null && f.m_connection_password.value!='') || (f.m_connection_confirm_password!=null && f.m_connection_confirm_password.value!='')) {
				allowSwitch = confirm(repo_wmsg);
			}
		}
	}
	
	if (allowSwitch) {
		f.m_connection_file.value='';
		f.m_connection_jdbc_parameters.value='';
		if (f.m_connection_jdbc_driverclass.options[repoTypeSelectInd].value == "FileSystem") {
			f.fsAliasRoot_select.selectedIndex=0;
			f.m_connection_jdbc_url.value='';
		} else {
			f.cmisURL_input.value='';
			f.m_connection_jdbc_url.value='';
			f.m_connection_use_userid.checked=false;
			f.m_connection_use_pword.checked=false;
			if (f.m_connection_default_signon) {
				f.m_connection_default_signon.checked=true;
				f.m_connection_userid.value='';
				f.m_connection_password.value='';
				f.m_connection_confirm_password.value='';
				updateSignonSection(false);
			}
		}
		repoTypeSelectInd=f.m_connection_jdbc_driverclass.selectedIndex;
		initRepositoryConnectionPage();
	} else {
		f.m_connection_jdbc_driverclass.selectedIndex=repoTypeSelectInd;
	}
}

function isSupportedCmisProvider(provider) {
	return provider == 'CM8' || provider == 'FileNet';
}

function cmisURL_input_changed() {
	var f = document.pform;
	f.m_connection_jdbc_url.value=f.cmisURL_input.value;
}

function fsAliasRoot_select_changed() {
	var f = document.pform;
	f.m_connection_jdbc_url.value=f.fsAliasRoot_select.value;
}

function updateTrustedContext()
{
	var f = document.pform;
	f.m_connection_identity_propagation.disabled = !f.m_connection_trusted_context.checked;
}

function initRepositoryConnectionPage()
{
	var f = document.pform;
	if (f.m_connection_jdbc_driverclass) {
		if (f.m_p_credentialNamespaces) {
			f.m_p_credentialNamespaces.value='';
		}
		var signonDiv = document.getElementById('gen-signon-section');
		f.fsAliasRoot_select.selectedIndex=0;
		if (f.m_connection_jdbc_driverclass.value == "FileSystem") {
			if (f.fsAliasRoot_select.length==0) {
				f.m_connection_jdbc_url.value='';
			} else {
				if (f.m_connection_jdbc_url.value == '') {
					f.m_connection_jdbc_url.value=f.fsAliasRoot_select.value;
				}
			}
			f.fsAliasRoot_select.value=f.m_connection_jdbc_url.value;
			showDynamicDiv('fileSystemDiv');
			hideDynamicDiv('cmisDiv');
			signonDiv.style.display = 'none';
		} else {
			f.cmisURL_input.value=f.m_connection_jdbc_url.value;
			f.m_connection_use_userid.checked=true;
			f.m_connection_use_pword.checked=true;
			if (f.m_connection_default_signon) {
				f.m_connection_default_signon.checked=true;
			}
			updateSignonSection(true);
			showDynamicDiv('cmisDiv');
			hideDynamicDiv('fileSystemDiv');
			signonDiv.style.display = 'inline';
		}
	}
}

function updateJdbcOracle()
{
	var f = document.pform;
	if (f.m_connection_jdbc_oracle_style) {
		if (f.m_connection_jdbc_oracle_style[0] && f.m_connection_jdbc_oracle_style[0].checked == true) {
			showDynamicDiv('serviceID');
			f.m_connection_servername.disabled = false;
			f.m_connection_port.disabled = false;
			f.m_connection_oracle_service_id.disabled = false;
			
			hideDynamicDiv('tnsNamesAlias');
			f.m_connection_oracle_tns_name.disabled = true;

			hideDynamicDiv('oracleNetDescriptor');
			f.m_connection_oracle_net_descriptor.disabled = true;

		} else if (f.m_connection_jdbc_oracle_style[1] && f.m_connection_jdbc_oracle_style[1].checked == true) {
			hideDynamicDiv('serviceID');
			f.m_connection_servername.disabled = true;
			f.m_connection_port.disabled = true;
			f.m_connection_oracle_service_id.disabled = true;
			
			showDynamicDiv('tnsNamesAlias');
			f.m_connection_oracle_tns_name.disabled = false;
			
			hideDynamicDiv('oracleNetDescriptor');
			f.m_connection_oracle_net_descriptor.disabled = true;
			
		} else if (f.m_connection_jdbc_oracle_style[2] && f.m_connection_jdbc_oracle_style[2].checked == true) {
			hideDynamicDiv('serviceID');
			f.m_connection_servername.disabled = true;
			f.m_connection_port.disabled = true;
			f.m_connection_oracle_service_id.disabled = true;
			
			hideDynamicDiv('tnsNamesAlias');
			f.m_connection_oracle_tns_name.disabled = true;
			
			showDynamicDiv('oracleNetDescriptor');
			f.m_connection_oracle_net_descriptor.disabled = false;
		}
	}
}

function updateJdbcSortOptions()
{
	var f = document.pform;
	if (f.m_connection_jdbc_sort_colseq && f.m_connection_jdbc_sort_level) {
		if (f.m_connection_jdbc_sort_colseq.value == '') {
			f.m_connection_jdbc_sort_level.disabled = true;
		} else {
			f.m_connection_jdbc_sort_level.disabled = false;
		}
	}
}

function updateSignonSection(rootChecked)
{
	var f = document.pform;
	if (f.m_connection_default_signon)
	{
		f.m_connection_default_signon.disabled = !rootChecked;
	}
	if (f.m_connection_use_pword)
	{
		f.m_connection_use_pword.disabled = !rootChecked;
	}

	// if the signon radio button isn't checked, then then disabled the userid and password fields 
	if (!rootChecked)
	{
		disableUserIDField(true);
		disablePasswordFields(true);		
	}
	// if the generate default signon isn't checked, then disabled the userid and password fields
	else if (f.m_connection_default_signon && !f.m_connection_default_signon.checked)
	{
		disableUserIDField(true);
		disablePasswordFields(true);				
	}
	else
	{
		disableUserIDField(false);
		disablePasswordFields(!((f.m_connection_use_pword && f.m_connection_use_pword.checked) || !f.m_connection_use_pword));
	}
}


// when the user switches between authentication types (no authentication, external namespace, signon, ...)
function onChangeAuthentication()
{
	var f = document.pform;

	for (var i=0; i < f.authentication.length; i++)
	{
		if (f.authentication[i].value == 'namespace')
		{
			if (f.m_p_credentialNamespaces)
			{
				f.m_p_credentialNamespaces.disabled = !f.authentication[i].checked;
				if (f.m_transformUserIdentification) {
					f.m_transformUserIdentification.disabled = !f.authentication[i].checked;
				}	
			}
		}
		else if (f.authentication[i].value == 'signon')
		{
			updateSignonSection(f.authentication[i].checked);
		}
	}
}	

function disableUserIDField(disabled)
{
	if (document.pform.m_connection_userid) {
		document.pform.m_connection_userid.disabled = disabled;
	}
}

function disablePasswordFields(disabled)
{
	if (document.pform.m_connection_password) {
		document.pform.m_connection_password.disabled = disabled;
	}
	if (document.pform.m_connection_confirm_password) {
		document.pform.m_connection_confirm_password.disabled = disabled;
	}
}

function disableAssemblyFields(disabled)
{
	if (document.pform.m_connection_schema) {
		document.pform.m_connection_schema.disabled = disabled;
	}
	if (document.pform.m_connection_http_method) {
		document.pform.m_connection_http_method.disabled = disabled;
	}
	if (document.pform.m_connection_http_message_body) {
		document.pform.m_connection_http_message_body.disabled = disabled;
	}
	if (document.pform.m_connection_json_path) {
		document.pform.m_connection_json_path.disabled = disabled;
	}
}

function isValidNameValuePairList(field, separator) {
 	if (field != null && field.value != '') {
		var pairs = field.value.split(separator);
		if (pairs != null && pairs.length != 0) {
			for (var i = 0; i < pairs.length; i++) {
				var regExp = new RegExp("^([^=]+)=([^=]*)$");
				if (regExp.test(pairs[i]) == false){
					return false;
				}
			}
		}
	}
	return true;
}

// In a dual-stack world a checkbox may be a checkbox or a hidden field by the time it 
// is used to build the connection string. This method takes care of the difference. 
function isCheckboxChecked(field){
	return (field && (field.checked || field.type != 'checkbox'))	
}

function isListItemSelected(select, item) {
	if (select && select.value == item) {
		return true;
	}
	return false;
}

// When creating a dual stack connection, fieldOrArrayOfFields may be 1) an array of input fields or 2) one hidden input.
// It is an array when the form is enabled and a hidden input when on the jdbc connection page.    
function isRadioButtonSelected(fieldOrArrayOfFields, name) {
	if (fieldOrArrayOfFields) {
		if (fieldOrArrayOfFields.length > 0) {
			for (var i = 0; i < fieldOrArrayOfFields.length; i++) {
				var input = fieldOrArrayOfFields[i];
				if (input.value == name) {
					return (input.checked || input.type == 'hidden');
				}
			}		
		} else {
			if (fieldOrArrayOfFields.value == name) {
				return (fieldOrArrayOfFields.checked || fieldOrArrayOfFields.type == 'hidden');
			}
		}
	}
	return false;
}

function selectRadioButton(radioButtongGroup, name) {
	for (var i = 0; i < radioButtongGroup.length; i++) {
		var input = radioButtongGroup[i];
		if (input.value == name) {
			input.checked = 'true';
		}
	}
}

function stripSpecialCharsFromOracleNetDesc(value) {
	return value.replace(new RegExp( "[\\t\\r\\n\\b\\f]", "g" ), "");
}

function formatOracleNetDesc(value) {
	var formattedValue = '';
	var indentLevel = 0;
	var lastBracket = null;
	for (var i = 0 ; i < value.length; i++) {
		var currChar = value.charAt(i);
		if (currChar == '(') {
			if (lastBracket == ')') {
				// )(
				formattedValue += '\n' + generateIndent(indentLevel) + currChar;
			} else {
				// ((
				if (lastBracket == null) {
					// for the very first bracket, don't newline or increase indentLevel
					formattedValue += generateIndent(indentLevel) + currChar;
				} else {
					indentLevel++;
					formattedValue += '\n' + generateIndent(indentLevel) + currChar;
				}
			}
			lastBracket = currChar;
		} else if (currChar == ')') {
			if (lastBracket == ')') {
				// ))
				indentLevel--;
				formattedValue += '\n' + generateIndent(indentLevel) + currChar;
			} else {
				// ()
				formattedValue += currChar;
			}
			lastBracket = currChar;
		} else {
			// all other chars
			formattedValue += currChar;
		}
	}
	return formattedValue;
}

function setProxyControls()
{
	frm = document.pform;
	if (frm.m_connection_proxy_enabled.checked == true)
	{
		frm.m_connection_proxy_enabled.value = "true";
		disableProxyControls(false)
	}
	else
	{
		frm.m_connection_proxy_enabled.value = "false";
		disableProxyControls(true)
	}
}
function disableProxyControls(disabled)
{
	frm = document.pform;
	frm.m_connection_proxy_host.disabled=disabled;
	frm.m_connection_proxy_port.disabled=disabled;
	frm.m_connection_proxy_user.disabled=disabled;
	frm.m_connection_proxy_password.disabled=disabled;
}


function generateIndent(indentLevel) {
	var indent = '';
	var j = indentLevel;
	while (j != 0) {
		indent += '\t';
		j--;
	}
	return indent;
}