function formatIntl(intl){
	if(intl){
		$('add_state_text').setProperties({'id':'add_state_select','name':'add_state_select'});
		$('add_state_text').setStyles({'display':'none'});
		$('add_state_select').setProperties({'id':'add_state_text','name':'add_state_text'});
		$('add_state_select').setStyles({'display':'none'});
	}
}
function showCEmessage(){
	var license_ct = $('license_container').getElements('div[id^=license_row]');
	//alert('licenses = '+license_ct.length);
	if(license_ct.length > 1){
		$('ce_charge_msg').setStyle('display', 'block');
	}else{
		$('ce_charge_msg').setStyle('display', 'none');
	}
}


function showCE() {
	var table = $('ce_table');
	table.setStyle('display', 'block');
	
	showCEmessage();
}

function hideCE() {
	var table = $('ce_table');
	var newfi = table.setStyle('display', 'none');
}

function addNewRow(rowName){
	
	var license_box = $('license_box');
	var licenseRows = $('license_box').getElements('div[id^=license_row]');
	var rowCt = licenseRows.length;
	
	if(rowCt >= 5) {
		$('license_row').getElement('select').selectedIndex = 0;
		$('license_row').getElement('input').value = '';
		alert('At this time you can only add up to five (5) state licenses.');
		return;
	}
	var row = $(rowName);
	var newrow = row.clone();
	
	newrow.setProperty('id', rowName+String(rowCt+1));	
	newrow.setStyle('padding-right:6px;display:inline;width:60px;');
	
	var state_select_arr = newrow.getElements('select[name^=license_state]');
	var old_state_select_arr = row.getElements('select[name^=license_state]');
	var selIndex = old_state_select_arr[0].selectedIndex;
	var state_option_selected = newrow.getElements('option[value='+old_state_select_arr[0].selected+']');
	state_select_arr[0].selectedIndex = selIndex;
	var license_text_arr = newrow.getElements('input[name^=license_num]');
	var old_license_text_arr = row.getElements('input[name^=license_num]');
	license_text_arr[0].value = old_license_text_arr[0].value;
	
	if(old_license_text_arr[0].value == '' || old_state_select_arr[0].selectedIndex == 0){
		alert('Please enter both a state and license number.');
		return;
	}
	old_license_text_arr[0].value = '';
	old_state_select_arr[0].selectedIndex = 0;
	
	var remove_btn = new Element('div', {
	    'id': 'removeButton'+String(rowCt+1),
	    'html': '<input type="button" name="Remove'+String(rowCt+1)+'" value="Remove" onclick="removeLicense('+(rowCt+1)+');"/>',
	    'styles': {
	        'display': 'inline'
	    }
	});

	var input_button = remove_btn.getElement('input');
	input_button.setProperty('onclick', 'removeLicense('+String(rowCt+1)+')');
	
	var license_text_input = newrow.getElements('div');
	license_text_input[0].setProperty('id', 'license_text_input'+String(rowCt+1));
	license_text_input[0].setProperty('style', 'display:inline;');
	remove_btn.inject(license_text_input[0], 'after');	
	newrow.setStyle('padding-right', '4px');
	newrow.inject(license_box, 'top');
	
	//Show CE charge message:
	showCEmessage();
}

function removeLicense(rowNum){
	//alert('removeLicense('+rowNum+')');
	var row = $('license_row'+rowNum);
	row.dispose();
}