function getboxarray(){

	array = new Array(9);
	array[1] = 'cs_nw';
 	array[2] = 'cs_n';
 	array[3] = 'cs_ne';
	array[4] = 'cs_w';
 	array[5] = 'cs_center';
 	array[6] = 'cs_e';
	array[7] = 'cs_sw';
	array[8] = 'cs_s';
	array[9] = 'cs_se';
	return array;

}

function formtoboxes(boxSuffix){

	if ( ! boxSuffix ){
		boxSuffix = '';
	}

	array = getboxarray();
	
	for (i = 1; i <= 9; i++){
		thebox = document.getElementById(array[i]+boxSuffix);
		thefield = document.getElementById('form_'+array[i]);
		//thefield = document.getElementsByName(array[i])[0];

		if (thebox && thefield){
			thebox.className = 'cs_' + thefield.value;
		}
	}

}

function boxestoform(){

	array = getboxarray();
	
	for (i = 1; i <= 9; i++){

		thebox = document.getElementById(array[i]);
		thefield = document.getElementById('form_'+array[i]);
		

		if (thebox && thefield){
			classname = thebox.className;
			thefield.value = classname.substr(3);
			//thefield.value = thebox.className;
		}
	}

}

function changebox(p,formname,syncBoxSuffix){

	if (p.className == 'cs_xxx' || p.className == 'xxx'){
		p.className = 'cs_on';
	} else if (p.className == 'cs_on'){
		p.className = 'cs_off';
	} else if (p.className == 'cs_off'){
		p.className = 'cs_xxx';
	}
	boxestoform();
	if ( syncBoxSuffix ){
		formtoboxes(syncBoxSuffix);
	}

	if (formname){	
		theform = document.getElementsByName(formname)[0];
		theform.submit();
	}

}

function changesensitive(p, amount){

	for (i = 1; i <= 5; i++){
		name = 'sensitivity' + i;
		thediv = document.getElementById(name);
		thediv.className = 'sensitivity_off';
	}

	thefield = document.getElementsByName('form_cs_tolerance')[0];
	thefield.value = amount;

	p.className = 'sensitivity_on';
	
}
