var psForm;
function switchShape(n,ags,hna){
psForm.shp.selectedIndex=n;
lbxChngProports((ags && !n)?99:n);
showHnA((n)?true:false);
if(n){psForm.HnA.checked=false;psForm.AGS0.checked=false;}
else{psForm.HnA.checked=hna;psForm.AGS0.checked=ags;}
}
function shpChng(){switchShape(psForm.shp.selectedIndex,0,0);}
function showHnA(dis){psForm.HnA.disabled=dis;psForm.AGS0.disabled=dis;}
function clickHnA(){checkHnA(psForm.HnA.checked);}
function clickAGS0(){checkAGS0(psForm.AGS0.checked);}
function checkAGS0(chkd){
n=psForm.shp;
if(!chkd){psForm.HnA.checked=false;switchShape(0,0,0);}
else switchShape(0,1,psForm.HnA.checked);
}
function checkHnA(chkd){
n=psForm.shp.selectedIndex;
if(chkd) psForm.AGS0.checked=true;
switchShape(0,1,chkd);
}
function lbxChngProports(a){
switch(a){
case 99: //ideal h&a
	psForm.dpt.value=58.7;psForm.dpt2.value=62.3;psForm.tbl.value=53;psForm.tbl2.value=58;break;
case 0:
	psForm.dpt.value=58;psForm.dpt2.value=63;psForm.tbl.value=53;psForm.tbl2.value=62;break;
case 1: case 7: //EM & RA
	psForm.dpt.value=57;psForm.dpt2.value=74;psForm.tbl.value=56;psForm.tbl2.value=79;break;
case 6: //PR
	psForm.dpt.value=56;psForm.dpt2.value=76;psForm.tbl.value=57;psForm.tbl2.value=83;break;
case 2: case 3:case 4: case 5://MQ, OV, HT & PS 
	psForm.dpt.value=56;psForm.dpt2.value=68.5;psForm.tbl.value=51;psForm.tbl2.value=67;break;
default: psForm.dpt.value=50;psForm.dpt2.value=80;psForm.tbl.value=50;psForm.tbl2.value=83;
}
}
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 btnFindClck(){
if(checkEdit(psForm.crt,'Carat',0.2,20)) return false;
if(checkEdit(psForm.crt2,'Carat',0.2,20)) return false;
if(checkEdit(psForm.dpt,'Depth %',40,90)) return false;
if(checkEdit(psForm.dpt2,'Depth',40,90)) return false;
if(checkEdit(psForm.tbl,'Table %',40,90)) return false;
if(checkEdit(psForm.tbl2,'Table',40,90)) return false;
if(checkEdit(psForm.prc,'Price',0,1000000)) return false;
if(checkEdit(psForm.prc2,'Price',0,1000000)) return false;
psForm.md.value='2';
return true;
}