function addLink(theform, thefield)
{
	var name = prompt('Please enter the name of the website.');
	var link = prompt('Please enter the URL of the website.');
	
	if (link != null && link.length > 0)
	{
		if (link == null || name.length == 0) name = link;
		
		if (link.indexOf('http://') < 	0) link = 'http://' + link;
		
		var field = eval("document." + theform + '.' + thefield);
		
		field.value += '<a href=\"'+link+'\" target=\"_blank\">' + name + '</a>';
	}
}

function addEmail(theform, thefield)
{
	var name = prompt('Please enter the name for the e-mail address.');
	var email = prompt('Please enter the e-mail address.');
	
	if (email != null && email.length > 0)
	{
		if (email == null || name.length == 0) name = email;
		var field = eval("document." + theform + '.' + thefield);
		
		field.value += '<a href=\"mailto:'+email+'\">' + name + '</a>';
	} 
}

function italicize(theform, thefield)
{
	var phrase = prompt('Please enter the words you would like to italicize.');
	if (phrase != null && phrase.length > 0)
	{	
		var field = eval('document.' + theform + '.' + thefield);
		field.value += '<span class="italics">' + phrase + '</span>';
	}
}
 
function bold(theform, thefield)
{
	var phrase = prompt('Please enter the words you would like to bold.');
	if (phrase != null && phrase.length > 0)
	{
		var field = eval('document.' + theform + '.' + thefield);
		field.value += '<span class="bold">' + phrase + '</span>';
	}
} 

function addBlueHeader(theform, thefield) {
	var phrase = prompt('Please enter the header text.');
	if (phrase != null && phrase.length > 0)
	{
		var field = eval('document.' + theform + '.text');		
		field.value += '<span class="blueHeader">' + phrase + '</span>';
	}	
}

function addOrangeHeader(theform, thefield) {
	var phrase = prompt('Please enter the header text.');
	if (phrase != null && phrase.length > 0)
	{
		var field = eval('document.' + theform + '.' + thefield);		
		field.value += '<span class="orangeHeader">' + phrase + '</span>';
	}	
}

function addTM(theform, thefield) {
	var field = eval('document.' + theform + '.' + thefield);
	field.value += '&#8482;';
}
	
function removeOptions(select)
{
	var children = select.getElementsByTagName('option');
	for (var i = children.length - 1; i >= 0; i--)
	{
		var item = children.item(i);
		select.removeChild(item);	
	}	
}

function selectIndustry(industry){
	var input = document.getElementById('industry');
	input.value = industry;
}

function loadIndustryFilter(indVal)
{
	var val = document.getElementById('industryFilter').value;
	
	var secFilter = document.getElementById('profitIndustry');
	
	removeOptions(secFilter);
	
	var option = document.createElement('option');
	option.value = '';
	option.appendChild(document.createTextNode('Please Select'));
	secFilter.appendChild(option);
	
	if (!indVal) indVal = '';
	selectIndustry(indVal);
	
	switch (val)
	{
		case 'oil':
			var array = new Array('Exploration & Production', 'Integrated Oil & Gas', 'Oil Equipment & Services', 'Pipelines');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];
				if (indVal == array[i]) option.selected = 'selected';
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}
			secFilter.style.display = 'inline';
			return; 		
		case 'basic':
			var array = new Array('Commodity Chemicals','Specialty Chemicals','Forestry','Paper','Aluminum','Nonferrous Metals','Steel','Coal','Diamonds & Gemstones','General Mining','Gold Mining','Platinum & Precious Metals');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];
				if (indVal == array[i]) option.selected = 'selected';
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return;
		case 'industrial':
			var array = new Array('Building Materials & Fixtures','Heavy Construction','Aerospace','Defense','Containers & Packaging','Diversified Industrials','Electrical Components and Equipment','Electronic Equipment','Commercial Vehicles & Trucks','Industrial Machinery','Delivery Services','Marine Transportation','Railroads','Transportation Services','Trucking','Business Support Services','Business Training & Employment Agencies','Financial Administration','Industrial Suppliers','Waste & Disposal Services');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];		
				if (indVal == array[i]) option.selected = 'selected';		
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return; 		
		case 'goods':
			var array = new Array('Automobiles','Auto Parts','Tires','Brewers','Distillers & Vintners','Soft Drinks','Farming & Fishing','Food Products','Durable Household Products','Non-durable Household Products','Furnishings','Home Construction','Consumer Electronics','Recreational Products','Toys','Clothing & Accessories','Footwear','Personal Products','Tobacco');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];	
				if (indVal == array[i]) option.selected = 'selected';			
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return; 			
		case 'health':
			var array = new Array('Health Care Providers','Medical Equipment','Medical Supplies','Biotechnology','Pharmaceuticals');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];		
				if (indVal == array[i]) option.selected = 'selected';		
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return; 	
		case 'service':
			var array = new Array('Drug Retailers','Food Retailers & Wholesalers','Apparel Retailers','Broadline Retailers','Home Improvement Retailers','Specialized Customer Services','Specialty Retailers','Broadcasting & Entertainment','Media Agencies','Publishing','Airlines','Gambling','Hotels','Recreational Services','Restaurants & Bars','Travel & Tourism');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];		
				if (indVal == array[i]) option.selected = 'selected';		
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return; 			
		case 'telecommunications':
			var array = new Array('Fixed Line Communications','Mobile Communications');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];	
				if (indVal == array[i]) option.selected = 'selected';			
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return;
		case 'utilities':
			var array = new Array('Electricity','Gas Distribution','Multi-utilities','Water' );
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];	
				if (indVal == array[i]) option.selected = 'selected';			
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return;				
		case 'financial':
			var array = new Array('Banks','Full Line Insurance','Insurance Brokers','Property & Casualty Insurance','Reinsurance','Life Insurance','Real Estate Holding & Development','Real Estate Investment Trusts','Asset Managers','Consumer Finance','Specialty Finance','Investment Services','Mortgage Finance','Equity Investment Instruments','Non-equity Investment Instruments');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];	
				if (indVal == array[i]) option.selected = 'selected';			
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return;		
		case 'tech':
			var array = new Array('Computer Services','Internet','Software','Computer Hardware','Electronic Office Equipment','Semiconductors','Telecommunications Equipment');
			for (var i = 0; i < array.length; i++)
			{	
				var option = document.createElement('option');
				option.value = array[i];	
				if (indVal == array[i]) option.selected = 'selected';			
				option.appendChild(document.createTextNode(array[i]));
				secFilter.appendChild(option);
			}	
			secFilter.style.display = 'inline';
			return;
		default:
			secFilter.style.display = 'none'; 
			return;
	}
}

function addRow(indx)	{
	var lastRow = document.getElementById('row' + (indx - 1));
	
	var labelDiv = document.createElement('div');
	labelDiv.className = 'label';
	
	var textField = document.createElement('input');
	textField.type = 'text';
	textField.name = 'dept[]';
	
	var fieldDiv = document.createElement('div');
	fieldDiv.className = 'field';
	fieldDiv.appendChild(textField);
	
	var row = document.createElement('div');
	row.className = 'row';
	row.id = 'row' + indx	;
	row.appendChild(labelDiv);
	row.appendChild(fieldDiv);
	
	lastRow.parentNode.insertBefore(row, lastRow.nextSibling);
	
	indx++;
	
	var addLink = document.getElementById('addLink');
	addLink.onclick = function() { addRow(indx);return false; };
	
	textField.focus();
}

function toggleIndustry(type)	{
	
	var eduRow = document.getElementById('eduRow');
	var industryRow = document.getElementById('industryRow');
	var typeRow = document.getElementById('typeRow');
	
	if (type == 'For-Profit')	{
		if (eduRow) eduRow.parentNode.removeChild(eduRow);
		industryRow = createIndustryRow();
		typeRow.parentNode.insertBefore(industryRow, typeRow.nextSibling);
	} else if (type == 'Educational Institution')	{
		if (industryRow) industryRow.parentNode.removeChild(industryRow);
		eduRow = createEduRow();
		typeRow.parentNode.insertBefore(eduRow, typeRow.nextSibling);
	} else 	{
		if (eduRow) eduRow.parentNode.removeChild(eduRow);
		if (industryRow) industryRow.parentNode.removeChild(industryRow);
	}
	selectIndustry('');	
}

function createEduRow()	{
	
	var label = document.createElement('div');
	label.className = 'label';
	label.appendChild(document.createTextNode('*Type of School:'));
	
	var select = document.createElement('select');
	select.id = 'schoolType';
	select.name = 'schoolType';
	select.onchange = function() { selectIndustry(this.value); };
	
	select.appendChild(createOption('Please Select', ''));
	select.appendChild(createOption('K-12 (public, private or charter)', 'K-12 (public, private or charter)'));
	select.appendChild(createOption('College/University (public or private)','College/University (public or private)'));
	
	var field = document.createElement('div');
	field.className = 'field';
	field.appendChild(select);
	
	var longLabelContainer = document.createElement('div');
	longLabelContainer.className = 'longLabelContainer';
	longLabelContainer.appendChild(label);
	longLabelContainer.appendChild(field);
	
	var eduRow = document.createElement('div');
	eduRow.id = 'eduRow';
	eduRow.className = 'row';
	eduRow.appendChild(longLabelContainer);
	
	return eduRow;	
}

function createIndustryRow()	{
	var label = document.createElement('div');
	label.className = 'label';
	label.appendChild(document.createTextNode('*Industry and Sub-sector:'));
	
	var select = document.createElement('select');
	select.id = 'industryFilter';
	select.name = 'industryFilter';
	select.onchange = loadIndustryFilter;
	
	select.appendChild(createOption('Please Select', ''));
	select.appendChild(createOption('Oil & Gas','oil'));
	select.appendChild(createOption('Basic Materials','basic'));
	select.appendChild(createOption('Industrials','industrial'));
	select.appendChild(createOption('Consumer Goods','goods'));
	select.appendChild(createOption('Health Care','health'));
	select.appendChild(createOption('Consumer Services','service'));
	select.appendChild(createOption('Telecommunications','telecommunications'));
	select.appendChild(createOption('Utilities','utilities'));
	select.appendChild(createOption('Financials','financial'));
	select.appendChild(createOption('Technology','tech'));
	
	var secSelect = document.createElement('select');
	secSelect.id = 'profitIndustry';
	secSelect.name = 'profitIndustry';
	secSelect.onchange = function() { selectIndustry(this.value); };
	secSelect.style.display = 'none';
	
	var field = document.createElement('div');
	field.className = 'field';
	field.appendChild(select);
	field.appendChild(secSelect);	
	
	var longLabelContainer = document.createElement('div');
	longLabelContainer.className = 'longLabelContainer';
	longLabelContainer.appendChild(label);
	longLabelContainer.appendChild(field);	
	
	var rowInfo = document.createElement('div');
	rowInfo.className = 'rowInfo';
	rowInfo.appendChild(document.createTextNode('After you select your Industry, a second drop-down list will appear where you can select your Sub-sector.  Please make your selections carefully. This information will be used to identify appropriate comparison organizations.'));
	
	var industryRow = document.createElement('div');
	industryRow.id = 'industryRow';
	industryRow.className = 'row';
	industryRow.appendChild(longLabelContainer);
	industryRow.appendChild(rowInfo);
	
	return industryRow;
}

function createOption(name, val)	{
	var option = document.createElement('option');
	option.value = val;
	option.appendChild(document.createTextNode(name));	
	
	return option;
}