//
// Java Functions 
// 

function do_popup( u )
	{
	w = window.open( u, 'MemberHelp','scrollbars=yes,toolbar=no,resizable=yes,width=515,height=550,screenx=10,screeny=10',1 );
	w.focus();
	}

function list_properties( target )
	{
	var names = '';
	for( var i in target )
		names += i + ', ';
	alert( names );
	}

function defaultFieldFocus()
	{
	if( document.forms.length == 0 )
		return;
	e = document.forms[0].elements;
	for( var i=0 ; i<e.length ; i++ )
		{
		switch( e[i].type )
			{
			case 'button':
			case 'checkbox':
			case 'radio':
			case 'text':
			case 'textarea':
			case 'password':
			case 'file':
			case 'select-one':
			case 'select-multiple':
				e[i].focus();
				return;
				break;
			default:
				break;
			}
		}
	}

	// Get the field index # for a particular input field - Used by multi_fields()

function getElementIndex(obj) 
	{
	var theform = obj.form;
	for (var i=0; i<theform.elements.length; i++) 
		{
		if (obj.name == theform.elements[i].name) 
			{
			return i;
			}
		}
	return -1;
	}

	// Check for all field lines in use and create additional line if required

function multi_fields( fname, cur_field, width )
	{

	var lines = 0;
	var unused = 0;
	var saved = new Array();
	while( document.getElementById( fname + '_' +  (lines+1) + '_1' ) )
		{
		lines++;

			// Check if line is used
		if( document.getElementById( fname + '_' + lines + '_1' ).value == '' )
			unused++;

			// Save all data in case we need to add a line
		saved[lines] = new Array();
		for( i=1 ; i<=width ; i++ )
			{
			saved[lines][i] = document.getElementById( fname + '_' +  lines + '_' + i ).value;
			}
		}

		// If we need an additional field, rewrite everything

	if( lines > 0 && unused == 0 )
		{
		new_num = lines + 1;																// Add one to line count for new field
		
		new_text = document.getElementById( fname + '_text' ).value;

		t = new_text.replace( /\{line_numb\}/gi, new_num );											// Replace {n} parameters

		for( i=1 ; i<=width ; i++ )
			{
			reg = new RegExp( '\{field_' + i + '\}', 'g' );
			t = t.replace( reg, '<input type=\"text\" name=\"' + fname + '_' + new_num + '_' + i + '\" id=\"' + fname + '_' + new_num + '_' + i + '\" onChange=\"multi_fields(\'' + fname + '\', this, ' + width + ');\">' );
			} 

		document.getElementById( fname + '_fields' ).innerHTML += t;				// Write out new line

			// Fill values back in
		for( i=1 ; i<=lines ; i++ )
			for( j=1 ; j<=width ; j++ )
				document.getElementById( fname + '_' + i + '_' + j ).value = saved[i][j];

			// Focus on next field
		cf = document.getElementById( cur_field.name );		
		x = getElementIndex( cf );
		cf.form.elements[x+1].focus();
		}

	}

function OpenCertDetails() 
	{ 
	
thewindow=window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USMETR219-2','anew',config='height=500,width=500,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes'); 
	} 
