function update(source, destination) {
	document.getElementById(destination).innerHTML  = source.value;
}

function update_mult(source, destination) {
	//multiple paragraphs in text area
	if (window.RegExp) {
		var linebreak = /[\r\n]+/g;
		document.getElementById(destination).innerHTML  = 
			source.value.replace(linebreak, "<br /><br />");
	} else {
		document.getElementById(destination).innerHTML  = source.value;
	}
}
function setvalue(source, destination) {
	var j = source.selectedIndex;
	document.getElementById(destination).innerHTML  = source.options[j].value;
}

function setlist(source, destination) {
	var j = document.getElementById(source).selectedIndex;
	document.getElementById(destination).innerHTML =  document.getElementById(source).options[j].value;
	if (j > 0) {
		document.getElementById(destination).style.display = 'list-item';
	} else {
		document.getElementById(destination).style.display = 'none';
	}
}

function inline(id) {
	document.getElementById(id).style.display = 'inline';
}

function cell(id) {
	document.getElementById(id).style.display = 'table-cell';
}

function showdepth(){
	//color depth is pertinent only to TIFF (and J2K ?)
	//all color options are irrelevant to DNG
	inline('depthpref');
	inline('pleaseconvert');
	cell('coloropts');
	switch (document.f.fileformat.selectedIndex) {
	case 0: //nothing selected
		hide('pleaseconvert');
		break;
	case 1: //JPEG format
		hide('depthpref');
		break;
	case 2: //TIFF format
		break;
	case 3: //TIFF+Zip format
		break;
	case 4: //PSD format
		break;
	case 5: //DNG format
		hide('depthpref');
		hide('coloropts');
		break;
	case 6: //JPEG-2000 format
		break;
	default:
		break;
	}
}

function implode() {
	//gather the values of 5 metadata selectors
	document.getElementById('metanotes').style.display = 'none';
	document.getElementById('nometa').style.display = 'table-cell';
	setlist('metadata1', 'meta1');
	setlist('metadata2', 'meta2');
	setlist('metadata3', 'meta3');
	setlist('metadata4', 'meta4');
	setlist('metadata5', 'meta5');
	if (document.f.metadata1.selectedIndex > 0 ||
	    document.f.metadata2.selectedIndex > 0 ||
	    document.f.metadata3.selectedIndex > 0 ||
	    document.f.metadata4.selectedIndex > 0 ||
	    document.f.metadata5.selectedIndex > 0) 
	{
		document.getElementById('metanotes').style.display = 'table-cell';
		document.getElementById('nometa').style.display = 'none';
	}
}

function pop(fname) {
	var url = fname+".php";
	wind = window.open(url, "Details", "width=500,height=400,status,resizable=1,scrollbars=1");
}

function wants_advice(flag) {
	var state = 'none';
	if (flag.checked) state = 'block';
	var ids = new Array('a1', 'a2', 'a3', 'a4', 'a5', 
						'a6', 'a7', 'a8', 'a9', 'a10');
	for (j=0; j<ids.length; j++) {
		document.getElementById(ids[j]).style.display = state;
	}
}


function rescalc() {
	var freq = parseInt(document.getElementById('screen').value);
	document.getElementById('respref1').innerHTML  = freq;
	
	var factor = 1;
	if (document.getElementById('units').selectedIndex == 0
	  || document.getElementById('units').selectedIndex == 1) factor = 5;
	minres = factor * Math.round(1.3 * (freq/factor));
	document.getElementById('respref2').innerHTML  = minres;
	maxres = factor * Math.round(2.0 * (freq/factor));
	document.getElementById('respref3').innerHTML  = maxres;
}

function resunits() {
	setvalue(document.f.units, "unitpref1");
	setvalue(document.f.units, "unitpref2");
	rescalc();
}




