function switchShape(n,ags,hna){
	showHnA((n)?true:false);
	lbxChngProports((ags && !n)?99:n);
	if(n){
		document.thisForm.HnA.checked=false;
		document.thisForm.AGS0.checked=false;
	}else{
		document.thisForm.HnA.checked=hna;
		document.thisForm.AGS0.checked=ags;
	}
	EnableCut(document.thisForm.AGS0.checked);
}
function lbxChngProports(a){
	if(!document.thisForm.dpt) return;
	switch(a){
	case 99: //ideal h&a
		document.thisForm.dpt.value=58.7; document.thisForm.dpt2.value=62.3;
		document.thisForm.tbl.value=53; document.thisForm.tbl2.value=58;
		break;
	case 0: //round
		document.thisForm.dpt.value=58; document.thisForm.dpt2.value=63;
		document.thisForm.tbl.value=53; document.thisForm.tbl2.value=62;		
		break;
	case 1: case 7: //EM & RA
		document.thisForm.dpt.value=57; document.thisForm.dpt2.value=74;
		document.thisForm.tbl.value=56; document.thisForm.tbl2.value=79;
		break;
	case 6: //PR
		document.thisForm.dpt.value=56; document.thisForm.dpt2.value=76;
		document.thisForm.tbl.value=57; document.thisForm.tbl2.value=83;
		break;
	case 2: case 3:case 4: case 5://MQ, OV, HT & PS 
		document.thisForm.dpt.value=56; document.thisForm.dpt2.value=68.5;
		document.thisForm.tbl.value=51; document.thisForm.tbl2.value=67;
		break;
	default:
		document.thisForm.dpt.value=50; document.thisForm.dpt2.value=80;
		document.thisForm.tbl.value=50; document.thisForm.tbl2.value=83;
	}
}
function shpChng(){
	switchShape(document.thisForm.shp.selectedIndex,0,0);
}
function showHnA(dis){
	document.thisForm.HnA.disabled=dis;
	document.thisForm.AGS0.disabled=dis;
}
function checkAGS0(chkd){
	if(!chkd){
		document.thisForm.HnA.checked=false;
		switchShape(0,0,0);
	}else if(document.thisForm.shp.selectedIndex)
		document.thisForm.AGS0.checked=false;
	else
		switchShape(0,1,document.thisForm.HnA.checked);
	EnableCut(document.thisForm.AGS0.checked);
}
function clickAGS0(){
	checkAGS0(document.thisForm.AGS0.checked);
}
function clickHnA(){
	checkHnA(document.thisForm.HnA.checked);
}
function checkHnA(chkd){
	if(chkd){
		if(document.thisForm.shp.selectedIndex)
			document.thisForm.HnA.checked=false;
		else
			document.thisForm.AGS0.checked=true;
	}
	switchShape(0,1,chkd);
	
	EnableCut(document.thisForm.AGS0.checked);
}
function EnableCut(chkd){
	if(!document.thisForm.cut)return;
	if(chkd){
		document.thisForm.cut.selectedIndex=0;
		document.thisForm.cut2.selectedIndex=0;
		document.thisForm.cut.disabled=true;
		document.thisForm.cut2.disabled=true;
	}else{
		document.thisForm.cut.disabled=false;
		document.thisForm.cut2.disabled=false;
	}
}
function checkEdit(ctrl,name,minv,maxv){
	var s1=parseFloat(ctrl.value);
	if(isNaN(s1) || !(s1<=maxv && s1>=minv)){
		ctrl.focus();
		alert("Invalid "+name+": "+ctrl.value+"!\nPlease enter "+name+" from "+minv+" to "+maxv);
		return 1;
	}
	return 0;
}
function onSubmit(action){
	if(checkEdit(document.thisForm.crt,'Carat',0.2,30)) return false;
	if(checkEdit(document.thisForm.crt2,'Carat',0.2,30)) return false;
	if(document.thisForm.dpt){
		if(checkEdit(document.thisForm.dpt,'Depth %',40,90)) return false;
		if(checkEdit(document.thisForm.dpt2,'Depth',40,90)) return false;
		if(checkEdit(document.thisForm.tbl,'Table %',40,90)) return false;
		if(checkEdit(document.thisForm.tbl2,'Table',40,90)) return false;
	}
	document.thisForm.action=action;
	return true;
}