function showprop(button,show,hide,which){               
        if (!document.getElementById)   
        return
        myvalue=document.getElementById(button).value;
        if (myvalue==show)
        document.getElementById(button).value=hide;
        if (myvalue==hide)
        document.getElementById(button).value=show;

        if (which.style.display=="block")
        which.style.display="none"
        else
        which.style.display="block"
}
function sync_jmol(appletid){
    if ( document.getElementById("sync_box").checked == true  ) jmolScript("sync * on;sync * \"set syncMouse on\"");
    if ( document.getElementById("sync_box").checked == false ) jmolScript("sync * off;sync * \"set syncMouse off\"");
}
function write_sync_jmol(){
    var text = "";
    text += '<form><input type="checkbox" id="sync_box" onchange="sync_jmol()" >Synchronize Mouse</form>';
    document.write(text);
}
function spin_jmol(appletid){
    if ( document.getElementById("spin_box"+appletid).checked == true  ) jmolScript("spin on", appletid);
    if ( document.getElementById("spin_box"+appletid).checked == false ) jmolScript("spin off",appletid);
}
function write_spin_jmol(appletid){
    var text = "";
    text += '<form><input type="checkbox" id="spin_box'+appletid+'" onchange="spin_jmol(\''+appletid+'\')" >Spin Molecule</form>';
    document.write(text);
}
function spacefill_jmol(spacefill,appletid){
    if ( spacefill == 'bs'  ) jmolScript("spacefill 20%;  wireframe 0.15",appletid);
    if ( spacefill == 'vdw' ) jmolScript("spacefill 100%; wireframe off" ,appletid);
    if ( spacefill == 'wfm' ) jmolScript("spacefill off; wireframe on"   ,appletid);
}
function write_spacefill_jmol(appletid){
    var sfill_radio = "sfill_radio"+appletid;
    var text = "";
    text += '<form><input type="radio" name="'+sfill_radio+'" onclick="spacefill_jmol(\'bs\' ,\''+appletid+'\')" checked> Ball&Stick <br>';
    text += '      <input type="radio" name="'+sfill_radio+'" onclick="spacefill_jmol(\'vdw\',\''+appletid+'\')"        > VdW radii <br>';
    text += '      <input type="radio" name="'+sfill_radio+'" onclick="spacefill_jmol(\'wfm\',\''+appletid+'\')"        > Wireframe <br>';
    text += '</form>';
    document.write(text);
}
function label_jmol(label,appletid){
    if ( label == 'atom'  ) jmolScript("label %e    ;font label 20 sanserif bold;set labelAlignment center",appletid);
    if ( label == 'vdw'   ) jmolScript("labels %0.2V;font label 20 sanserif bold;set labelAlignment center",appletid);
    if ( label == 'ionic' ) jmolScript("labels %0.2I;font label 20 sanserif bold;set labelAlignment center",appletid);
    if ( label == 'charge') jmolScript("labels %0.2P;font label 20 sanserif bold;set labelAlignment center",appletid);
    if ( label == 'off'   ) jmolScript("labels off"                                                        ,appletid);
}
function write_label_jmol(appletid){
    var label_radio = "label_radio"+appletid;
    var text = "";
    text += '<form><table><tr>';
    text += '<td><input type="radio" name="'+label_radio+'" onclick="label_jmol(\'atom\'  ,\''+appletid+'\')"        >Atom Labels    </td>';
    text += '<td><input type="radio" name="'+label_radio+'" onclick="label_jmol(\'vdw\'   ,\''+appletid+'\')"        >VdW radii      </td>';
    text += '</tr><tr>';
    text += '<td><input type="radio" name="'+label_radio+'" onclick="label_jmol(\'ionic\' ,\''+appletid+'\')"        >Ionic radii    </td>';
    text += '<td><input type="radio" name="'+label_radio+'" onclick="label_jmol(\'charge\',\''+appletid+'\')"        >Partial charges</td>';
    text += '</tr><tr>';
    text += '<td><input type="radio" name="'+label_radio+'" onclick="label_jmol(\'off\'   ,\''+appletid+'\')" checked>Labels off     </td>';
    text += '<td></td></tr></table>';
    text += '</form>';
    document.write(text);
}
function geom_jmol(geom,appletid){
    if (geom == 'dist'){
        if ( document.getElementById("dist_box"+appletid).checked == true  ) jmolScript("measure ALLCONNECTED (*)(*);set measurements angstroms", appletid);
        if ( document.getElementById("dist_box"+appletid).checked == false ) jmolScript("measure DELETE ALLCONNECTED (*)(*)",appletid);
    }
    if (geom == 'angle'){
        if ( document.getElementById("angle_box"+appletid).checked == true  ) jmolScript("measure ALLCONNECTED (*)(*)(*)", appletid);
        if ( document.getElementById("angle_box"+appletid).checked == false ) jmolScript("measure DELETE ALLCONNECTED (*)(*)(*)",appletid);
    }
}
function write_geom_jmol(appletid){
    var text = "";
    text += '<form><input type="checkbox" id="dist_box' +appletid +'"  onchange="geom_jmol(\'dist\' ,\''+appletid+'\')" >Bonds ';
    text += '      <input type="checkbox" id="angle_box'+appletid +'"  onchange="geom_jmol(\'angle\',\''+appletid+'\')" >Angles </form>';
    document.write(text);
}
function propjmol(appletid){
    write_spin_jmol(appletid);
    write_spacefill_jmol(appletid);
    write_label_jmol(appletid);
    write_geom_jmol(appletid);
}
function dipole_jmol(dipole_value,appletid){
    if ( document.getElementById("dipole_box"+appletid).checked == true  ) jmolScript("dipole molecular width 0.1 offset 1.0;set echo dipo 100% 100%;echo Dipole "+dipole_value+" Debye", appletid);
    if ( document.getElementById("dipole_box"+appletid).checked == false ) jmolScript("dipole molecular delete; set echo dipo off",appletid);
}
function write_dipole_jmol(dipole_value,appletid){
    var text = "";
    text += '<form><input type="checkbox" id="dipole_box'+appletid+'" onchange="dipole_jmol(\''+dipole_value+'\',\''+appletid+'\')" >Molecular Dipole</form>';
    document.write(text);
}
function vib_properties(appletid){
var vibbutton  = '<form>';
    vibbutton += '<p><input type="checkbox" id="vibvector'+appletid+'" onClick="setviboptions(\'vectors\','+appletid+')" > Show Vectors.';
    vibbutton += '<p>Vibration Period: <input type="text" value=1.0 id="vibperiod'+appletid+'" size="4"> sec.';
    vibbutton += '<p>Vibration Amplitude: <input type="text" value=1.0 id="vibamplitude'+appletid+'" size=\"4\"> ';
    vibbutton += '<input type="button" onClick="setviboptions(\'options\','+appletid+')" value="set vibration options" >';
    vibbutton += '<p><input type="button" onClick="setviboptions(\'all\','+appletid+')" value="vibrate all modes" >';
    vibbutton += '<input type="button" onClick="setviboptions(\'offvib\','+appletid+')" value="stop vibration" >';
    vibbutton += '</p></form>';
document.write(vibbutton);
}
function mo_cutoff(appletid){
    var empty = " ";
    var mobutton  = '<form>';
    mobutton += '<p>MO cutoff: <input type="text" value=0.01 id="mocutoff'+appletid+'" size="5">';
    mobutton += '<input type="button" onClick="setmooptions(\'set\',\''+empty+'\',\''+appletid+'\')" value="set MO cutoff">';
    mobutton += '<input type="button" onClick="setmooptions(\'-\'  ,\''+empty+'\',\''+appletid+'\')" value="-" >';
    mobutton += '<input type="button" onClick="setmooptions(\'+\'  ,\''+empty+'\',\''+appletid+'\')" value="+" >';
    mobutton += '</form>';
    document.write(mobutton);
}
function mo_valence(homo,appletid){
    var text = "";
    text +='<form>';
    text +='<input type="radio" name="moopt'+appletid+'" id="offmo'+appletid+'" onclick="setmooptions(\'offmo\','+homo+',\''+appletid+'\')" checked> No MO <br>';
    text +='<input type="radio" name="moopt'+appletid+'" id= "homo'+appletid+'" onclick="setmooptions(\'homo\' ,'+homo+',\''+appletid+'\') "        > HOMO <br>';
    text +='<input type="radio" name="moopt'+appletid+'" id= "lumo'+appletid+'" onclick="setmooptions(\'lumo\' ,'+homo+',\''+appletid+'\') "        > LUMO <br>';
    text +='</form>';
    document.write(text);
}
function mo_properties(homo,appletid){
    mo_valence(homo,appletid);
    mo_cutoff(appletid);
}
function get_mep_cutoff(appletid){
// for mep: if the cutoff is with no sign it will show the surface with potential +/-value
// if a sign it is specified: + or - it will show only the blue(+) or the red(-) surface 
    var potmax = jmolEvaluate("{1.2}.partialCharge.max",appletid)*0.40;
    var potmin = jmolEvaluate("{1.2}.partialCharge.min",appletid)*0.40;
    potmax = Number(potmax).toFixed(4)
    potmin = Number(potmin).toFixed(4)
    if ( isNaN(potmax) ) potmax = "+0.1";
    if ( isNaN(potmax) ) potmin = "-0.1";
    return [potmin,potmax]
}
function mep_properties(appletid){
    var space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var mepmenu  = "";
    mepmenu += '<b>Molecular Electrostatic Potential (MEP) Surface:</b>';
    mepmenu += '<form>';
    mepmenu += '<input type="radio" name="mepopt'+appletid+'" id="offradio'+appletid+'" onclick="setmepoptions(\'off\',\''+appletid+'\')" checked> No Potential Surface<br>';
    mepmenu += '<input type="radio" name="mepopt'+appletid+'" id="mepradio'+appletid+'" onclick="setmepoptions(\'mep\',\''+appletid+'\')"        > MEP on Isopotential Surface';

    mepmenu += '&nbsp;&nbsp;<a href=\'javascript:alert("' + help_mepisopotential + '")\'>?</a><br>';

    mepmenu += '<input type="radio" name="mepopt'+appletid+'" id="vdwradio'+appletid+'" onclick="setmepoptions(\'vdw\',\''+appletid+'\')"        > MEP on Van der Waals Surface';

    mepmenu += "&nbsp;&nbsp;<a href=\'javascript:alert(\"" + help_mepvdw + "\")\'>?</a><br>";

    mepmenu += space + '<input type="button" onClick="setmepoptions(\'vol-\',\''+appletid+'\')" value="-"> ';
    mepmenu +=         '<input type="button" onClick="setmepoptions(\'vol+\',\''+appletid+'\')" value="+"> Scale VdW volume';

    mepmenu += '<input type="text" value="100" id="vdwscale'+appletid+'" size="4" readonly>%';
    mepmenu += '<br>';
    mepmenu += '<input type="radio" name="mepopt'+appletid+'" id="planeradio'+appletid+'" onclick="setmepoptions(\'plane\',\''+appletid+'\')"> MEP on a plane';
    mepmenu += "&nbsp;&nbsp;<a href=\'javascript:alert(\"" + help_mepplane + "\")\'>?</a><br>";
    document.write(mepmenu);

var mepplane  = space + '<input type="text" value="0 0 2 -1.0" id="planeeq'+appletid+'" size="10">';
    mepplane +=         '<input type="button" onClick="setmepoptions(\'plane\',\''+appletid+'\')" value="set plane equation"><br>';
    mepplane += space + '<input type="radio" align="bottom" name="plane'+appletid+'" onClick="xyzplane(\'0 0 1 0\',\''+appletid+'\')" value="xy">XY';
    mepplane +=         '<input type="radio" align="bottom" name="plane'+appletid+'" onClick="xyzplane(\'0 1 0 0\',\''+appletid+'\')" value="xz">XZ';
    mepplane +=         '<input type="radio" align="bottom" name="plane'+appletid+'" onClick="xyzplane(\'1 0 0 0\',\''+appletid+'\')" value="yz">YZ';
    mepplane += "<br><br><br>"
document.write(mepplane);
    var potrange = Array(2);
    //potrange = get_mep_cutoff(appletid);
    potrange = ["-0.1","+0.1"];
var mepbutton  = 'min:<input type="text" value="'+potrange[0]+'" id="negmepcutoff'+appletid+'" size="4"> ';
    mepbutton += 'max:<input type="text" value="'+potrange[1]+'" id="posmepcutoff'+appletid+'" size="4">';
    mepbutton += '<input type="button" onClick="setmepoptions(\'-\',        \''+appletid+'\')" value="-"                         >';
    mepbutton += '<input type="button" onClick="setmepoptions(\'+\',        \''+appletid+'\')" value="+"                         >';
    mepbutton += "&nbsp;&nbsp;<a href=\'javascript:alert(\"" + help_mepcutoff + "\")\'>?</a><br>";
    mepbutton += '<input type="button" onClick="setmepoptions(\'setcutoff\',\''+appletid+'\')" value="set this cutoff on surface">';
    mepbutton += '<input type="button" onClick="setmepoptions(\'adjust\',\''+appletid+'\')" value="adjust a cutoff">';
    mepbutton += '</form>';
document.write(mepbutton);
}
function setsymmoptions(symbol,appletid){
	/*
	if ( symbol == 'offsymm'){
	       	jmolScript('draw delete');
	}else{
	       	jmolScript('draw delete');
	}
	*/
	var symmElem = document.getElementById('symm_select_'+appletid);
	for (i=0; i<symmElem.options.length; i++) {
		if (symmElem.options[i].selected) {
			if ( i == 0 ){
				jmolScript('delete $pgv?_*',appletid);
			}else{
				var keyword = symmElem.options[i].value;
				jmolScript('draw pointgroup '+keyword+' scale 2;',appletid) ;
			}
		}else{
			var keyword = symmElem.options[i].value;
			var words = keyword.split(" ");
			if ( words[0] == 'cs' ){
				// remove disk and ring
				keyword = '\$pgv?_?_'+words[1]+'*';
			}else if ( words[0] == 'ci'){
				keyword = '\$pg0_1_inv';
			}else{
				keyword = '\$pgv?_?_'+words[0]+'_'+words[1];
			}
			jmolScript('delete '+keyword,appletid) ;
		}
	}

}
function setviboptions(sign,appletid){
    var vectors_box = document.getElementById('vibvector'+appletid);
    var vibration_menu = document.getElementById('vib_select_'+appletid);
    if ( sign == "offvib" ) {
        jmolScript("frame 2;vectors off;vibration off",appletid);
        // if menu of vibrations exists, make sure it shows "no vib" as selected and vectors is unchecked
        if ( vectors_box != null) vectors_box.checked = false ;
        if ( vibration_menu != null) vibration_menu.options[0].selected = true;
    }
    if ( sign == "all" ) {
        jmolScript("vibration on;frame 2-199;",appletid);
    }
    if ( sign == "vectors" ) {
        if ( vectors_box != null) {
            if ( vectors_box.checked == true ) jmolScript("set vectorScale 3.0;vectors on",appletid);
            if ( vectors_box.checked == false) jmolScript("vectors off",appletid);
        }
    }
    if ( sign > 0 ) {
        // gaussian has the vibrations on 3rd frame on
        var nmv = Number(sign)+2;
        jmolScript("frame "+nmv+";vibration on",appletid);
        if (vibration_menu != null ) vibration_menu.options[sign].selected = true;
    }
    if ( sign == "options" ) {
        var period = document.getElementById("vibperiod"+appletid).value;
        var amplitude = document.getElementById("vibamplitude"+appletid).value;
        jmolScript('set vibrationperiod '+period+';set vibrationScale '+amplitude+' ',appletid);
    }
}
function setmooptions(sign,homo,appletid){
    var mo_menu = document.getElementById('mo_select_'+appletid);
    var cutoff = "";
    var cutoffarea = document.getElementById("mocutoff"+appletid)
    if ( cutoffarea != null) {
        cutoff = document.getElementById("mocutoff"+appletid).value;
        if ( cutoff == "" ) cutoff = 0.01;
        incr = 0.02;
        if ( sign == '+'  ) cutoff = Number(cutoff) + Number(incr); 
        if ( sign == '-' )  cutoff = Number(cutoff) - Number(incr);
        if ( cutoff < 0  ) cutoff = 0;
        cutoff = Number(cutoff).toFixed(4);
        document.getElementById("mocutoff"+appletid).value = cutoff ;
    }
    if ( cutoff == "" ) cutoff = 0.01;
    var lumo = Number(homo)+1;
    if ( sign == 'offmo' ){
        if ( mo_menu != null ) mo_menu.options[0].selected = true;
        var box_off = document.getElementById('offmo'+appletid);
        if ( box_off != null ) box_off.checked = true;
        jmolScript("frame 2;mo off",appletid);
    }
    else if ( sign == 'homo'  ){
        jmolScript("frame 2;mo "+homo+";mo color yellow purple;mo cutoff "+cutoff+" ",appletid);
        if ( mo_menu != null ) mo_menu.options[Number(homo)].selected = true;
    }
    else if ( sign == 'lumo'  ){
        jmolScript("frame 2;mo "+lumo+";mo color yellow purple;mo cutoff "+cutoff+" ",appletid);
        if ( mo_menu != null ) mo_menu.options[Number(lumo)].selected = true;
    }
    else if ( sign > "0"      ){
        if ( sign == homo ){
            var box_homo = document.getElementById('homo'+appletid);
            if ( box_homo != null ) box_homo.checked = true;
        }
        else if ( sign == lumo ){
            var box_lumo = document.getElementById('lumo'+appletid);
            if ( box_lumo != null ) box_lumo.checked = true;
            if ( mo_menu != null ) mo_menu.options[lumo].selected = true;
        }
        else {
            var box_off = document.getElementById('offmo'+appletid);
            if ( box_off != null ) box_off.checked = true;
        }
        jmolScript("frame 2;mo "+sign+";mo color yellow purple;mo cutoff "+cutoff+" ",appletid);
    }
    else if ( sign == '+' || sign == '-' ) jmolScript( "frame 2;mo color yellow purple;mo cutoff "+cutoff+" ",appletid);
    else alert("wrong option="+sign);
}
function setmepoptions(sign,appletid){

    // Deal first with cutoffs
    var negmepcutoff = document.getElementById("negmepcutoff"+appletid).value;
    var posmepcutoff = document.getElementById("posmepcutoff"+appletid).value;
    //cutoff=cutoff.replace(/(^\s+)(\s+$)/, "");
    posmepcutoff=posmepcutoff.replace(/(^\+)/, "");
    negmepcutoff=negmepcutoff.replace(/(^\+)/, "");
    if ( negmepcutoff == "" ) negmepcutoff = "-0.1";
    if ( posmepcutoff == "" ) posmepcutoff = "+0.1";
    incr = 0.02;
    if ( sign == '+'  ) posmepcutoff = Number(posmepcutoff) + Number(incr); 
    if ( sign == '+'  ) negmepcutoff = Number(negmepcutoff) - Number(incr); 
    if ( sign == '-' )  posmepcutoff = Number(posmepcutoff) - Number(incr);
    if ( sign == '-' )  negmepcutoff = Number(negmepcutoff) + Number(incr);
    posmepcutoff = Number(posmepcutoff).toFixed(4);
    negmepcutoff = Number(negmepcutoff).toFixed(4);
    pos="+";
    if ( posmepcutoff > 0 ) posmepcutoff = pos.concat(posmepcutoff);
    if ( negmepcutoff > 0 ) negmepcutoff = pos.concat(negmepcutoff);
    document.getElementById("negmepcutoff"+appletid).value = negmepcutoff ;
    document.getElementById("posmepcutoff"+appletid).value = posmepcutoff ;

    // In case you need to scale the VdW surface
    var scale = document.getElementById("vdwscale"+appletid).value;
    if ( sign == 'vol+'  ) scale = Number(scale) + 100*Number(incr); 
    if ( sign == 'vol-'  ) scale = Number(scale) - 100*Number(incr); 
    scale = Number(scale).toFixed(4);
    document.getElementById("vdwscale"+appletid).value = scale ;
    var scale100   = scale;

    // modify sign argument based on what radio button is checked
    if (sign == '+' || sign == '-' ) {
       if (document.getElementById("mepradio"+appletid).checked) sign = 'mep';
       if (document.getElementById("vdwradio"+appletid).checked) sign = 'vdw';
       if (document.getElementById("planeradio"+appletid).checked) sign = 'plane';
    }
    else if ( sign == 'vol+' || sign == 'vol-' ){
       document.getElementById("vdwradio"+appletid).checked = true;
       sign = 'vdw';
    }
    else if ( sign == 'setcutoff' ){
       if (document.getElementById("mepradio"+appletid).checked) sign = 'mep';
       if (document.getElementById("vdwradio"+appletid).checked) sign = 'vdw';
       if (document.getElementById("planeradio"+appletid).checked) sign = 'plane';
    }
    else if ( sign == 'adjust' ){
       var potrange = Array(2);
       potrange = get_mep_cutoff(appletid);
       document.getElementById("negmepcutoff"+appletid).value = potrange[0];
       document.getElementById("posmepcutoff"+appletid).value = potrange[1];
       negmepcutoff = potrange[0];
       posmepcutoff = potrange[1];
       if (document.getElementById("mepradio"+appletid).checked) sign = 'mep';
       if (document.getElementById("vdwradio"+appletid).checked) sign = 'vdw';
       if (document.getElementById("planeradio"+appletid).checked) sign = 'plane';
    }
    // now the options
    if ( sign == 'off' ) {
      jmolScript('isosurface pos01 delete; isosurface neg01 delete;',appletid);
    }
    else if ( sign == 'mep' ){
      jmolScript('isosurface neg01 delete; isosurface pos01 delete;isosurface pos01 '+posmepcutoff+' resolution 12 mep;color isosurface blue translucent;isosurface neg01 '+negmepcutoff+' resolution 12 mep;color isosurface red translucent',appletid);
    }
    else if ( sign == 'vdw' ){
      posmepcutoff=posmepcutoff.replace(/(^\+)/, "");
      negmepcutoff=negmepcutoff.replace(/(^\+)/, "");
      jmolScript('isosurface neg01 delete; isosurface pos01 delete;isosurface pos01 vdw '+scale100+'% resolution 6 solvent mep;color isosurface absolute '+negmepcutoff+' '+posmepcutoff+';color isosurface translucent',appletid);
    }
    else if ( sign == 'plane' ){
      if ( ! document.getElementById("planeradio"+appletid).checked ) document.getElementById("planeradio"+appletid).checked = true;
      var equation = document.getElementById("planeeq"+appletid).value;
      jmolScript('isosurface neg01 delete; isosurface pos01 delete;isosurface pos01 plane {'+equation+'} mep;color isosurface absolute '+negmepcutoff+' '+posmepcutoff+';',appletid);
    }
}
function xyzplane(plane,appletid){
    document.getElementById("planeeq"+appletid).value = plane;
}
function openjmolwindow(id,molfile,sort){
    var woptions="menubar=yes,resizable=1,scrollbars,alwaysRaised,width=600,height=600,left=50"
    var sm=""+Math.random()
    sm=sm.substring(2,10)
    if (molfile=="-1"){
        alert("Choose a molecule first")
        return ""
    }
    else{
        var doc = "jmolnewwindow.php?id=" + id +"&molecule=" + molfile + "&sort=" + sort
        var newwin=window.open(doc,"jmol_"+sm,woptions)
        if (window.focus) {newwin.focus()}
    }
    return false;
}
function openmarvinwindow(molfile){
    var woptions="menubar=yes,resizable=1,scrollbars,alwaysRaised,width=600,height=600,left=50"
    var sm=""+Math.random()
        sm=sm.substring(2,10)
        if (molfile=="-1"){
            alert("Choose a molecule first")
            return ""
        }
        else{
            var doc = "marvin.php?molecule=" + molfile
            var newwin=open(doc,"jmol_"+sm,woptions)
        }
}
function openjcpwindow(molfile){
    var woptions="menubar=yes,resizable=1,scrollbars,alwaysRaised,width=600,height=600,left=50"
    var sm=""+Math.random()
        sm=sm.substring(2,10)
        if (molfile=="-1"){
            alert("Choose a molecule first")
            return ""
        }
        else{
            var doc = "jchempaint.php?molecule=" + molfile
            var newwin=open(doc,"jmol_"+sm,woptions)
        }
}
function openirspectrum(appletid,frequencies,intensities){
	var myfreq = frequencies.split("&");
	var myintens = intensities.split("&");
        var content  = '<script id="source" language="javascript" type="text/javascript">\n';
        content += '$(function () {\n'
        content += '                var d2 = [[0,0],\n';
        for ( var i = 0; i<myfreq.length ; i++){
            content += '[' +myfreq[i]+ ',' +myintens[i]+ '],\n';
        }
        content += '                         [4000,0]];\n ';
        content += '                 var plot = $.plot( $("#placeholder"), [{ data: d2, bars: { barWidth: 30, show: true, fillColor: "#e8073f" }, label: "IR intensities" }], \n';
        content += '                            { points: { show: true }, selection: { mode: "xy" },grid: { hoverable: true, clickable: true }, } \n';
        content += '                       );\n';
        content += '              }\n';
        content += ');\n';
        content += '$("#placeholder").bind("plotclick", function (event, pos, item) {\n';
        content += 'if (item) {\n';
        content += '    if (item.dataIndex == 0) {$("#clickdata").text("You clicked on point [0,0], click on a band >0 to see it in Jmol");} \n';
        content += '    else if (item.datapoint[0] == 4000 ) { $("#clickdata").text("This point does not correspond to a vibration, click on a band >0 to see it in Jmol");} \n';
        content += '    else { $("#clickdata").text("You clicked the vibration mode #" + item.dataIndex + ". This mode is shown in the Jmol applet.");\n';
	content += '            if (!opener) { alert("The page that opened this pop-up window is not available."); return ""; }\n';
        content += '            opener.setviboptions(item.dataIndex,'+appletid+');\n';
        content += '    }\n';
        content += '}\n';
        content += '});\n';
        //content += 'document.write("Hello world");';
        content += '<\/script>\n';
	var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
	//var ie7 = false;
	if(ie7){
		alert("this script does not work with IE7, try other browsers");
	}else{
        top.consoleRef=window.open('','myconsole',
            'width=674,height=513,left=50'
            +',menubar=0'
            +',toolbar=1'
            +',status=0'
            +',scrollbars'
            +',alwaysRaised'
            +',resizable=1')
    //    docRef = top.winRef.document.open("text/html","replace");
        top.consoleRef.document.writeln(
            '<html height="100%"><head><title>IR spectrum</title>\n'
	    +'<!--[if IE]>\n'
//	    +    '<script language="javascript" type="text/javascript" src="http://www.chemeddl.org/tools/flot/excanvas.pack.js"><\/script>\n'
	    +'<![endif]-->\n'
            +'<script language="javascript" type="text/javascript" src="http://www.chemeddl.org/tools/flot/jquery.js"><\/script>\n'
            +'<script language="javascript" type="text/javascript" src="http://www.chemeddl.org/tools/flot/jquery.flot.js"><\/script>\n'
            +'</head>\n'
            +'<body height="100%" bgcolor=white onLoad="self.focus()">\n'
            +'<script type="text/javascript" ><\/script>\n'
            +'<h2>IR spectrum</h2>\n'
            +'<p>click on the IR bands to see the vibration in Jmol</p>\n'
            +'<div id="placeholder" style="width:600px;height:300px"></div>\n'
            +content
            +'<p><span id="clickdata"></span></p>\n'
            +'<p><input type="button" value="Stop Vibration" onClick="opener.setviboptions(\'offvib\','+appletid+')" ></p>\n'
            +'</body></html>\n'
         )
         top.consoleRef.document.close()
	}
}
/* 
	"Exporting an image of the current view from Jmol applet" by Angel Herráez 
	Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Spain License.
		http://creativecommons.org/licenses/by-nc-sa/2.5/  
	Permissions beyond the scope of this license may be available at http://biomodel.uah.es/
*/
// v.0.14

function openJmolSnapshot(appletid)
{	var iW = jmolEvaluate("_width")
	var iH = jmolEvaluate("_height")
	var parms = 'resizable,scrollbars'
	if (parseInt(iW)==iW) 
	{	parms += ',width=' + (parseInt(iW) + 80)
		// allow some space for browser margin and chrome, and comments/help
	}
	if (parseInt(iH)==iH)
	{	parms += ',height=' + (parseInt(iH) + 100)
	}
        var url = 'jmol_snapshot.htm?appletid=' + appletid + '&';
	wSnap = window.open(url, '', parms)
}
