/*
 * Javascript functions that manage
 * communication with AstexViewer.
 */

function toggle(s){
  document.av.execute('molecule display ' + s + ' toggle;');
}

function object(s){
  document.av.execute('object display ' + s + ' toggle;');
}

function av_execute(command){
  document.av.execute(command);
  window.status = command;
}

function av_lipophilicity(obj){
  av_execute("run 'lipophilicity.properties';");
  av_execute("object '" + obj +"' texture lipophilicity u 7.0 aminoacid;");
}

function av_electrostatic(obj){
  av_execute("run 'electrostatic.properties';");
  av_execute("object '" + obj +"' texture electrostatic u 4.0 aminoacid;");
}

function av_texture(obj, tex){
  if(tex == 'off'){
    av_execute("object '" + obj + "' texture 'off';");
  }else{
    if(tex == 'simple'){
      av_execute("texture '" + tex + "' simple;");
    }else{
      av_execute("texture load '" + tex + "' '" + tex + "';");
    }
    av_execute("object '" + obj + "' texture '" + tex + "';");
  }
}

function av_transparency(obj, tr){
  av_execute("object '" + obj + "' transparency " + tr + ";");
}

function av_display(obj, tr){
  var command = "object display '" + obj + "' " + tr + ";";
  av_execute(command);
}

function av_colour(obj, tr){
  var command = "object '" + obj + "' color " + tr + ";";
  av_execute(command);
}

function av_background(tr){
  var command = "background '" + tr + "';";
  av_execute(command);
}





/*
 * Javascript functions that manage interaction with
 * controls on the page.
 */





/* Atom displays */





function js_atomcolour(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_execute(val);
}

function js_atoms(obj){
  if(obj.checked){
    av_execute('display lines on not solvent;');
  }else{
    av_execute('display lines off not solvent;');
  }
}

function js_solvent(obj){
  if(obj.checked){
    av_execute('display lines on solvent;');
  }else{
    av_execute('display lines off solvent;');
  }
}


function js_spheres(obj){
  if(obj.checked){
    av_execute('display spheres aminoacid;');
  }else{
    av_execute('display spheres none;');
  }
}







/* Atom rendering*/




function js_atomstyle_all(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_execute('display lines on molecule mol*;');
    av_execute('display sticks off molecule mol*;');
    av_execute('display cylinders off molecule mol*;');
    av_execute('display spheres off molecule mol*;');
    if(val=='1'){
      av_execute('bond_width '+ val + ' molecule mol*;');
    }else if(val=='2'){
      av_execute('bond_width '+ val + ' molecule mol*;');
    }else if(val=='3'){
      av_execute('bond_width '+ val + ' molecule mol*;');
    }else{
      av_execute('display '+ val + ' molecule mol*;');
    }
}

/* Colour atoms */




function js_colour_all_atoms(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val=='atom_green'){
    av_execute('select molecule mol*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
  }else if(val=='atom_grey'){
    av_execute('select molecule mol*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0xa9a9a9 atom C* and molecule mol*;');
  }else if(val=='atom_black'){
    av_execute('select molecule mol*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0x000000 atom C* and molecule mol*;');
  }else if(val=='atom_white'){
    av_execute('select molecule mol*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color white atom C* and molecule mol*;');
  }else{
    av_execute('color '+ val + ' molecule mol*;');
    }
}
function js_colour_all_atoms_ref(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val=='atom_green'){
    av_execute('select molecule ref*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
  }else if(val=='atom_grey'){
    av_execute('select molecule ref*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0xa9a9a9 atom C* and molecule ref*;');
  }else if(val=='atom_black'){
    av_execute('select molecule ref*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0x000000 atom C* and molecule ref*;');
  }else if(val=='atom_white'){
    av_execute('select molecule ref*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color white atom C* and molecule ref*;');
  }else{
    av_execute('color '+ val + ' molecule ref*;');
    }
}
function js_colour_all_atoms_protein(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val=='atom_green'){
    av_execute('select molecule protein*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
  }else if(val=='atom_grey'){
    av_execute('select molecule protein*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0xa9a9a9 atom C* and molecule protein*;');
  }else if(val=='atom_black'){
    av_execute('select molecule protein*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0x000000 atom C* and molecule protein*;');
  }else if(val=='atom_white'){
    av_execute('select molecule protein*;');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color white atom C* and molecule protein*;');
  }else{
    av_execute('color '+ val + ' molecule protein*;');
    }
}

/* Viewer controls */



function js_antialias(sel){
  if(sel.checked){
    av_execute("view -antialias true;");
  }else{
    av_execute("view -antialias false;");
  }
}

function js_shadows(sel){
  if(sel.checked){
    av_execute("view -realspheres true; view -shadows true;");
  }else{
    av_execute("view -realspheres false; view -shadows false;");
  }
}

function js_background(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_execute("view -gradient false;");
  av_background(val);
}
function js_background2(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_execute('view -gradient true -gradientbottom black -gradienttop '+ val+';');
}


/* browser controls (for ligands) */



function js_displayoff(){
  av_execute("molecule display mol* off;");
}

function js_displayon(){
  av_execute("molecule display mol* on;");
}

function js_displaymol(val){
  var mol = "mol" + val;
  av_execute("molecule display mol* off;");
  av_execute("molecule display " + mol + " on;");
}

function js_atomstyle(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  var mol = "mol" + mol;
    av_execute('display lines on molecule ' + mol + ';');
    av_execute('display sticks off molecule ' + mol + ';');
    av_execute('display cylinders off molecule ' + mol + ';');
    av_execute('display spheres off molecule ' + mol + ';');
    if(val=='1'){
      av_execute('bond_width '+ val + ' molecule ' + mol + ';');
    }else if(val=='2'){
      av_execute('bond_width '+ val + ' molecule ' + mol + ';');
    }else if(val=='3'){
      av_execute('bond_width '+ val + ' molecule ' + mol + ';');
    }else{
      av_execute('display '+ val + ' molecule ' + mol + ';');
    }
}

function js_colouratoms(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  var mol = "mol" + mol;
  if(val=='atom_green'){
    av_execute('select molecule ' + mol + ';');
    av_execute('color_by_atom;');
    av_execute('select none;');
  }else if(val=='atom_grey'){
    av_execute('select molecule ' + mol + ';');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0xa9a9a9 atom C* and molecule ' + mol + ';');
  }else if(val=='atom_black'){
    av_execute('select molecule ' + mol + ';');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color 0x000000 atom C* and molecule ' + mol + ';');
  }else if(val=='atom_white'){
    av_execute('select molecule ' + mol + ';');
    av_execute('color_by_atom;');
    av_execute('select none;');
    av_execute('color white atom C* and molecule ' + mol + ';');
  }else{
    av_execute('color '+ val + ' molecule ' + mol + ';');
    }
}

function js_displaysurface(val){
  var molsurface = "molsurface" + val;
  var mol = "mol" + val;
  av_display('molsurface*', 'off');
  if(!molsurface.surface){
    av_execute('surface -solid true ' + molsurface + ' white molecule ' + mol + ';');
  }else{
      av_display('molsurface', 'on');
    }
}
function js_displaysurface_off(val){
  var molsurface = "molsurface" + val;
  av_display('molsurface*', 'off');
}

function js_coloursurface(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  var molsurface = "molsurface" + mol;
  av_colour(molsurface, val);
}

function js_transparencysurface(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  var molsurface = "molsurface" + mol;
  av_transparency(molsurface, val);
}

function js_texturesurface(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  var molsurface = "molsurface" + mol;
  if(!sel.textured){
    av_lipophilicity_mol(molsurface);
    sel.textured = true;
  }
  av_texture(molsurface, val);
}

function js_displaymesh(val){
  var molmesh = "molmesh" + val;
  var mol = "mol" + val;
  av_display('molmesh*', 'off');
  if(!molmesh.surface){
    av_execute('surface -solid false ' + molmesh + ' white molecule ' + mol + ';');
  }else{
      av_display('molmesh', 'on');
    }
}

function js_displaymesh_off(val){
  var molmesh = "molmesh" + val;
  av_display('molmesh*', 'off');
}

function js_colourmesh(sel, mol){
  var val = sel.options[sel.selectedIndex].value;
  var molmesh = "molmesh" + mol;
  av_colour(molmesh, val);
}


/* Protein controls */

/* Texture of protein surfaces */

function js_texture_protein_elec(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_electrostatic('protein_surface');
    sel.textured = true;
  av_texture('protein_surface', val);
}
function js_texture_protein_lip(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_lipophilicity('protein_surface');
    sel.textured = true;
  av_texture('protein_surface', val);
}
function js_texture_protein(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(!sel.textured){
    av_lipophilicity('protein_surface');
    sel.textured = true;
  }
  av_texture('protein_surface', val);
}
function js_texture_protein2(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(!sel.textured){
    av_lipophilicity('protein2_surface');
    sel.textured = true;
  }
  av_texture('protein2_surface', val);
}

/* Transparancy of protein surfaces */

function js_transparency_protein(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val == 'mesh'){
      av_execute('surface -solid false protein_surface white molecule protein;');
      obj.surface = true;
  }else{
    val = Math.round(val * 2.55);
    av_transparency('protein_surface', val);
  }
}
function js_transparency_protein2(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val == 'mesh'){
      av_execute('surface -solid false protein2_surface white molecule protein2;');
      obj.surface = true;
  }else{
    val = Math.round(val * 2.55);
    av_transparency('protein2_surface', val);
  }
}
function js_transparency_cofactor(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val == 'mesh'){
      av_execute('surface -solid false cofactor_surface white molecule protein2;');
      obj.surface = true;
  }else{
    val = Math.round(val * 2.55);
    av_transparency('cofactor_surface', val);
  }
}
/* Make protein surfaces */

function js_protein_surface(obj){
  if(obj.checked){
    av_execute('surface -solid true protein_surface white molecule protein and sphere 9 around molecule mol*;');
    av_execute('object protein_surface texture distance v molecule mol*;');
    av_execute('object protein_surface texture vrange 0 6.5;');
    av_execute('object protein_surface clip v;');
    av_execute('object protein_surface backface on;');
    obj.surface = true;
  }else{
    av_display('protein_surface', 'off');
  }
}
function js_protein2_surface(obj){
  if(obj.checked){
    av_execute('surface -solid true protein2_surface white molecule protein2 and sphere 9 around molecule mol*;');
    av_execute('object protein2_surface texture distance v molecule mol*;');
    av_execute('object protein2_surface texture vrange 0 6.5;');
    av_execute('object protein2_surface clip v;');
    av_execute('object protein2_surface backface on;');
    obj.surface = true;
  }else{
    av_display('protein2_surface', 'off');
  }
}
function js_cofactor_surface(obj){
  if(obj.checked){
    av_execute('surface -solid true cofactor_surface white molecule cofactor;');
    av_execute('object cofactor_surface texture distance v molecule mol*;');
    av_execute('object cofactor_surface texture vrange 0 6.5;');
    av_execute('object cofactor_surface clip v;');
    av_execute('object cofactor_surface backface on;');
    obj.surface = true;
  }else{
    av_display('cofactor_surface', 'off');
  }
}

function js_mesh_protein(obj){
  if(obj.checked){
    av_execute('surface -solid false protein_meshsurface white molecule protein;');
    obj.surface = true;
  }else{
    av_display('protein_meshsurface', 'off');
  }
}
function js_mesh_protein2(obj){
  if(obj.checked){
    av_execute('surface -solid false protein2_meshsurface white molecule protein2;');
    obj.surface = true;
  }else{
    av_display('protein2_meshsurface', 'off');
  }
}

/* Colour protein surfaces */

function js_colour_protein(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('protein_surface', val);
}
function js_colour_protein2(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('protein2_surface', val);
}
function js_colour_cofactor(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('cofactor_surface', val);
}

function js_colour_mesh_protein(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('protein_meshsurface', val);
}
function js_colour_mesh_protein2(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('protein2_meshsurface', val);
}

/* Cartoon representation */

function js_schematic_protein(obj){
  if(obj.checked){
    if(!obj.schematic){
      av_execute('color_by_rainbow molecule protein; secstruc all; schematic -name protein_schematic molecule protein; color_by_atom;');
      obj.schematic = true;
    }else{
      av_display('protein_schematic', 'on');
    }
  }else{
    av_display('protein_schematic', 'off');
  }
}
function js_schematic_protein2(obj){
  if(obj.checked){
    if(!obj.schematic){
      av_execute('color_by_rainbow molecule protein2; secstruc all; schematic -name protein2_schematic molecule protein2; color_by_atom;');
      obj.schematic = true;
    }else{
      av_display('protein2_schematic', 'on');
    }
  }else{
    av_display('protein2_schematic', 'off');
  }
}


/* Atom rendering controls */



function js_cylinder_radius(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_cylinder(val);
}
function av_cylinder(val){
  av.execute("select molecule *;");
  av.execute("cylinder_radius " + val + " current;");
  av.execute("select none;");
}

function js_ball_radius(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_ball(val);
}
function av_ball(val){
  av.execute("select molecule *;");
  av.execute("ball_radius " + val + " current;");
  av.execute("select none;");
}

function js_stick_radius(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_stick(val);
}
function av_stick(val){
  av.execute("select molecule *;");
  av.execute("stick_radius " + val + " current;");
  av.execute("select none;");
}
function js_atomstyle_prot(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_execute('display lines on molecule protein*;');
    av_execute('display sticks off molecule protein*;');
    av_execute('display cylinders off molecule protein*;');
    av_execute('display spheres off molecule protein*;');
    if(val=='1'){
    av_execute('bond_width '+ val + ' molecule protein*;');
    }
    if(val=='2'){
    av_execute('bond_width '+ val + ' molecule protein*;');
    }
    if(val=='3'){
    av_execute('bond_width '+ val + ' molecule protein*;');
    }else{
    av_execute('display '+ val + ' molecule protein*;');
    }
}
function js_atomstyle_lig(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_execute('display lines on molecule mol*;');
    av_execute('display sticks off molecule mol*;');
    av_execute('display cylinders off molecule mol*;');
    av_execute('display spheres off molecule mol*;');
    if(val=='1'){
    av_execute('bond_width '+ val + ' molecule mol*;');
    }
    if(val=='2'){
    av_execute('bond_width '+ val + ' molecule mol*;');
    }
    if(val=='3'){
    av_execute('bond_width '+ val + ' molecule mol*;');
    }else{
    av_execute('display '+ val + ' molecule mol*;');
    }
}
function js_atomstyle_ref(sel){
  var val = sel.options[sel.selectedIndex].value;
    av_execute('display lines on molecule ref*;');
    av_execute('display sticks off molecule ref*;');
    av_execute('display cylinders off molecule ref*;');
    av_execute('display spheres off molecule ref*;');
    if(val=='1'){
    av_execute('bond_width '+ val + ' molecule ref*;');
    }
    if(val=='2'){
    av_execute('bond_width '+ val + ' molecule ref*;');
    }
    if(val=='3'){
    av_execute('bond_width '+ val + ' molecule ref*;');
    }else{
    av_execute('display '+ val + ' molecule ref*;');
    }
}


/* Protein-ligand interactions */

/* Contact residues */


function av_contact(val){
  av_execute("label clear atom CA;");
    av.execute("select atom CA and byresidue sphere 4 around molecule mol" + val + ";");
    av_execute("label '<color=white,justify=vh,points=18>%f%r' current;");
    av.execute("select none;");
}
function js_contact_ref(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_ref_contact(val);
}
function av_ref_contact(val){
  av_execute("label clear atom CA;");
    av.execute("select atom CA and byresidue sphere 4 around molecule ref" + val + ";");
    av_execute("label '<color=white,justify=vh,points=18>%f%r' current;");
    av.execute("select none;");
}
function av_contact_off(val){
  av_execute("label clear atom CA;");
}


/* Bumps - close contacts */

function av_bumps(val){
    av_execute("distance -delete bumps_mol*;");
    av_execute("distance -name bumps_mol1 -mode pairs -from { molecule mol" + val + " } -to { molecule protein or solvent } -contact -0.4 -colour yellow -on 0.3 -off 0.4 -radius 0.03 -format '<justify=vh,points=16>%.1f' ;");
    av_execute("distance -name bumps_mol1 -mode pairs -from { molecule mol" + val + " } -to { molecule protein2 or solvent } -contact -0.4 -colour yellow -on 0.3 -off 0.4 -radius 0.03 -format '<justify=vh,points=16>%.1f' ;");
}
function js_bumps_ref(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_ref_bumps(val);
}
function av_ref_bumps(val){
    av_execute("distance -delete bumps_ref*;");
    av_execute("distance -name bumps_ref1 -mode pairs -from { molecule ref" + val + " } -to { molecule protein or solvent } -contact -0.4 -colour yellow -on 0.3 -off 0.4 -radius 0.03 -format '<justify=vh,points=16>%.1f' ;");
    av_execute("distance -name bumps_ref1 -mode pairs -from { molecule ref" + val + " } -to { molecule protein2 or solvent } -contact -0.4 -colour yellow -on 0.3 -off 0.4 -radius 0.03 -format '<justify=vh,points=16>%.1f' ;");
}
function av_bumps_off(val){
    av_execute("distance -delete bumps_mol*;");
}

/* Hydrogen bonds */

function av_hb(val){
    av_execute("distance -delete hbonds_mol*;");
    av_execute("distance -name hbonds_mol1 -mode pairs -from { element 7 8 and molecule mol" + val + " or (solvent and sphere 4 around molecule mol" + val + ") } -to { element 7 8 and (molecule protein or solvent) } -contact 0.2 -colour white -on 0.3 -off 0.4 -radius 0.06 -format '<justify=vh,points=16>%.1f' ;");
    av_execute("distance -name hbonds_mol1 -mode pairs -from { element 7 8 and molecule mol" + val + " or (solvent and sphere 4 around molecule mol" + val + ") } -to { element 7 8 and (molecule protein2 or solvent) } -contact 0.2 -colour white -on 0.3 -off 0.4 -radius 0.06 -format '<justify=vh,points=16>%.1f' ;");
}
function js_hb_ref(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_ref_hb(val);
}
function av_ref_hb(val){
    av_execute("distance -delete hbonds_ref*;");
    av_execute("distance -name hbonds_ref1 -mode pairs -from { element 7 8 and molecule ref" + val + " or (solvent and sphere 4 around molecule ref" + val + ") } -to { element 7 8 and (molecule protein or solvent) } -contact 0.2 -colour white -on 0.3 -off 0.4 -radius 0.06 -format '<justify=vh,points=16>%.1f' ;");
    av_execute("distance -name hbonds_ref1 -mode pairs -from { element 7 8 and molecule ref" + val + " or (solvent and sphere 4 around molecule ref" + val + ") } -to { element 7 8 and (molecule protein2 or solvent) } -contact 0.2 -colour white -on 0.3 -off 0.4 -radius 0.06 -format '<justify=vh,points=16>%.1f' ;");
}
function av_hb_off(val){
    av_execute("distance -delete hbonds_mol*;");
}




/* Cofactor controls */


function js_zn_surface(obj){
  if(obj.checked){
    av_execute('surface -solid true zn_surface white molecule zn;');
    obj.surface = true;
  }else{
    av_display('zn_surface', 'off');
  }
}

function js_colour_zn(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('zn_surface', val);
}

function js_transparency_zn(sel){
  var val = sel.options[sel.selectedIndex].value;
  if(val == 'mesh'){
      av_execute('surface -solid false zn_surface white molecule zn;');
      obj.surface = true;
  }else{
    val = Math.round(val * 2.55);
    av_transparency('zn_surface', val);
  }
}





/* Reference ligand controls */


function js_transparency_ref81(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref81_surface', val);
}
function js_transparency_ref82(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref82_surface', val);
}
function js_transparency_ref83(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref83_surface', val);
}
function js_transparency_ref84(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref84_surface', val);
}
function js_transparency_ref85(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref85_surface', val);
}
function js_transparency_ref86(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref86_surface', val);
}
function js_transparency_ref87(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref87_surface', val);
}
function js_transparency_ref88(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref88_surface', val);
}
function js_transparency_ref89(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref89_surface', val);
}
function js_transparency_ref90(sel){
  var val = sel.options[sel.selectedIndex].value;
  val = Math.round(val * 2.55);
  av_transparency('ref90_surface', val);
}

function js_ref81_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref81_surface white molecule ref81;');
      obj.surface = true;
    }else{
      av_display('ref81_surface', 'on');
    }
  }else{
    av_display('ref81_surface', 'off');
  }
}
function js_ref82_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref82_surface white molecule ref82;');
      obj.surface = true;
    }else{
      av_display('ref82_surface', 'on');
    }
  }else{
    av_display('ref82_surface', 'off');
  }
}
function js_ref83_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref83_surface white molecule ref83;');
      obj.surface = true;
    }else{
      av_display('ref83_surface', 'on');
    }
  }else{
    av_display('ref83_surface', 'off');
  }
}
function js_ref84_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref84_surface white molecule ref84;');
      obj.surface = true;
    }else{
      av_display('ref84_surface', 'on');
    }
  }else{
    av_display('ref84_surface', 'off');
  }
}
function js_ref85_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref85_surface white molecule ref85;');
      obj.surface = true;
    }else{
      av_display('ref85_surface', 'on');
    }
  }else{
    av_display('ref85_surface', 'off');
  }
}
function js_ref86_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref86_surface white molecule ref86;');
      obj.surface = true;
    }else{
      av_display('ref86_surface', 'on');
    }
  }else{
    av_display('ref86_surface', 'off');
  }
}
function js_ref87_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref87_surface white molecule ref87;');
      obj.surface = true;
    }else{
      av_display('ref87_surface', 'on');
    }
  }else{
    av_display('ref87_surface', 'off');
  }
}
function js_ref88_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref88_surface white molecule ref88;');
      obj.surface = true;
    }else{
      av_display('ref88_surface', 'on');
    }
  }else{
    av_display('ref88_surface', 'off');
  }
}
function js_ref89_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref89_surface white molecule ref89;');
      obj.surface = true;
    }else{
      av_display('ref89_surface', 'on');
    }
  }else{
    av_display('ref89_surface', 'off');
  }
}
function js_ref90_surface(obj){
    if(obj.checked){
    if(!obj.surface){
      av_execute('surface -solid true ref90_surface white molecule ref90;');
      obj.surface = true;
    }else{
      av_display('ref90_surface', 'on');
    }
  }else{
    av_display('ref90_surface', 'off');
  }
}

function js_colour_ref81(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref81_surface', val);
}
function js_colour_ref82(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref82_surface', val);
}
function js_colour_ref83(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref83_surface', val);
}
function js_colour_ref84(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref84_surface', val);
}
function js_colour_ref85(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref85_surface', val);
}
function js_colour_ref86(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref86_surface', val);
}
function js_colour_ref87(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref87_surface', val);
}
function js_colour_ref88(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref88_surface', val);
}
function js_colour_ref89(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref89_surface', val);
}
function js_colour_ref90(sel){
  var val = sel.options[sel.selectedIndex].value;
  av_colour('ref90_surface', val);
}

