if (!JmolPath)
{	var JmolPath = "../../../"
	document.writeln('<script src="' + JmolPath + 'Jmol.js" type="text/javascript"><' + '/script>')
}

var rootPath = "../../"
var comunPath = rootPath + "_comun/"

function _jmolFindApplet(target) // duplicated from Jmol.js in v.11.0.2 and customized
{
  // FIRST look for the target in MY frame
  var applet = _jmolSearchFrames(top.modelo, target);
  // THEN look for the target in the current window
  if (applet == undefined)
  applet = _jmolFindAppletInWindow(window, target);
  // THEN look for the target in child frames
  if (applet == undefined)
    applet = _jmolSearchFrames(window, target);
  // FINALLY look for the target in sibling frames
  if (applet == undefined)
    applet = _jmolSearchFrames(top, target); // look starting in top frame
  return applet;
}

function iniciaJmol()
{	jmolInitialize(JmolPath)
	jmolSetAppletColor("#09176E")	//como fondo de página modelo (en CSS)
}

function ponModelo()
{	iniciaJmol()
	jmolApplet(["100%","95%"], "set zoomLarge off; set spin Y 12; spin off")
	herram()
}

function button(scrp,t)
{	if (!t) { t = "X" }
	jmolSetButtonCssClass("btnX")
	jmolButton(scrp,t)
	jmolSetButtonCssClass("")
}	// Fija ancho de botón X --si no, demasiado estrecho en IE--


function pie(pa,ps,indSecTx,indSecUrl) 
{	var tx = '<form><div align="center"><hr>'
	if ( pa!="" || ps!="" ) { 
		tx += '<table width="100%"><tr>'
		if (pa!="") { tx += '<td align="left"><a href="' + pa + '"><img src="' + comunPath + 'pag-ant.gif" width="75" height="23" border="0" title="Previous page" alt="Previous page"></a></td>' }
		if (ps!="") { tx += '<td align="right"><a href="' + ps + '"><img src="' + comunPath + 'pag-sig.gif" width="75" height="23" border="0" title="Next page" alt="Next page"></a></td>' }
		tx += '</tr></table>'
	}
	document.writeln(tx)
	tx = ''
	if (indSecTx!="0") 
	{	if (indSecTx) { tx += '<input type="button" value="' + indSecTx + '" onClick="location.href=\'' + indSecUrl + '\'" style="margin-bottom:0.4em;">' }
		tx += '<div><input type="button" value="Main index" onClick="location.href=\'../contents.htm\'"></div>'
	}
	tx += '</div><hr class="hrInf"></form>'
	document.writeln(tx)
	document.close()
}
function regresarCerrar() 
{	var tx = '<p><div align="center">'
	tx += '<hr><img src="' + comunPath + 'pag-ant.gif" width="75" height="23" border="0" title="Previous page" alt="Previous page" '
	tx += 'onClick="window.close()" style="cursor:pointer;">'
	tx += '</div><hr>'
	document.writeln(tx)
	document.close()
}
function regresar() 
{	// No es conveniente si hay marcos
	var tx = '<p><div align="center">'
	tx += '<hr><img src="' + comunPath + 'pag-ant.gif" width="75" height="23" border="0" title="Previous page" alt="Previous page" '
	tx += 'onClick="history.back()" style="cursor:pointer;">'
	tx += '</div><hr>'
	document.writeln(tx)
	document.close()
}

function mideVentana(vent)
{	if (!vent) vent=self
	var x, y
	if (vent.innerWidth)
	{	x = vent.innerWidth; y = vent.innerHeight;
	}
	else if (vent.document.documentElement && vent.document.documentElement.clientWidth) // IE6 en modo Estricto
	{	x = vent.document.documentElement.clientWidth; y = vent.document.documentElement.clientHeight;
	}
	else if (vent.document.body && vent.document.body.clientWidth)  // otros IE e IE6 en modo Quirks (por ej., sin declaración <!DOCTYPE HTML )
	{	x = vent.document.body.clientWidth; y = vent.document.body.clientHeight;
	}
	else { x=600; y=550 }
	return [x,y]
}

var ventana1, vUtils
function abreVent(nomArch) 
{	ventana1 = window.open(nomArch,'', 'resizable,scrollbars')
	ventana1.focus()
}

function abreUtils(k)
{	if (k==1) f= "../_utiles.htm"
	else if (k==2) f= "../_colores.htm"
	else if (k==3) f= comunPath + "color-elem.htm"
	else if (k==4) f= comunPath + "mouse.htm"
	var d1 = mideVentana(self)
	var d2 = mideVentana(parent.texto)
	var barras = self.screen.height-self.screen.availHeight
	vUtils = window.open(f, "utilidades", "resizable, scrollbars, width=" + d2[0] + ", height=" + (self.screen.availHeight-barras) + ", left=" + (d1[0]+4) + ", top=0" )
	vUtils.focus()
}

function herram()
{	var tx = '<table border="0" width="100%" cellpadding="0" cellspacing="0"><tr align="center">'
	tx += '<td><span id="herram" onClick="abreUtils(3)" title="colour key" class="leyenda" style="cursor:pointer;">&nbsp;<span class="C">C</span> <span class="H">H</span> <span class="O">O</span> <span class="N">N</span> <span class="P">P</span> <span class="S">S</span> <span class="Fe">Fe</span>&nbsp;</span></td>'
	tx += '<td><img src="' + comunPath + 'paleta.gif" onClick="abreUtils(2)" width="24" height="24" border="0" title="colour schemes" alt="colour schemes" style="cursor:pointer;"></td>'
	tx += '<td><img src="' + comunPath + 'herram.gif" onClick="abreUtils(1)" width="29" height="24" border="0" title="tools" alt="tools" style="cursor:pointer;"></td>'
	tx += '<td><span onClick="abreUtils(4)" style="cursor:pointer;"><img src="' + comunPath + 'mouse.png" width="24" height="24" border="0" title="help using the mouse" alt="mouse"></span></td>'
	tx += '<td><img src="' + comunPath + 'varillas.gif" width="16" height="16" class="btn" onClick="jmolScript(\'wireframe 45; spacefill off;\')" title="sticks" alt="sticks">'
	tx += '&nbsp;<img src="' + comunPath + 'bolas-y-var.gif" width="16" height="16" class="btn" onClick="jmolScript(\'wireframe 55; spacefill 110;\')" title="ball-and-stick" alt="ball-and-stick">'
	tx += '&nbsp;<img src="' + comunPath + 'esferas.gif" width="16" height="16" class="btn" onClick="jmolScript(\'wireframe off; spacefill on;\')" title="spheres" alt="spheres">'
	tx += '</td>'

	tx += '<td><img src="' + comunPath + 'lupa-mas.gif" width="16" height="16" class="btn" onClick="jmolScript(\'move 0 0 0 100 0 0 0 0 1\')" title="zoom in" alt="zoom in">'
	tx += '&nbsp;<img src="' + comunPath + 'lupa-menos.gif" width="16" height="16" class="btn" onClick="jmolScript(\'move 0 0 0 -100 0 0 0 0 1\')" title="zoom out" alt="zoom out">'
	tx += '</td>'

	tx += '<td><img src="' + comunPath + 'giro.gif" width="16" height="16" class="btn" onClick="jmolScript(\'spin on\')" title="spin" alt="spin">'
	tx += '&nbsp;<img src="' + comunPath + 'giro-no.gif" width="16" height="16" class="btn" onClick="jmolScript(\'spin off\')" title="don\'t spin" alt="don\'t spin">'
	tx += '</td>'
	tx += '</tr></table>'
	document.writeln(tx)
}
/* hay que añadir esto a la cabecera de las páginas (de modelos) que usen herram(), para mostrar correctamente el icono de ratón:
	<!--[if lt IE 7.]>
	<script defer type="text/javascript" src="../../_comun/pngfix.js"></script>
	<![endif]-->
*/

function leeRadio(ctl)
{	for (var i=0; i<ctl.length; i++)
	{	if ( ctl[i].checked ) { return ctl[i].value }
	}
	return null
}

function formsReset()
{	for (var i=0; i<document.forms.length; i++) { document.forms[i].reset() }
}

function unModelo()
{	var pag = parent.modelo.location.href
	pag = pag.substring(pag.lastIndexOf("/")+1)
	if (pag != "modelo.htm") { parent.modelo.location.href = "modelo.htm"  }
}

function scr_trabajando(k)
{	if ( k ) return ("set echo top right; echo working...; font echo 22 serif; color echo cyan; ")
	else return ("set echo off; ")
}

var scr_colorProtein1 = "color [xcbbe8a]; " //copied from DRuMS
var scr_colorProtein2 = "color [x98b868]; " //verdoso metálico, derivado del anterior
function scr_colorProteins(a,b)
{	var tx = "select " + a + "; " + scr_colorProtein1 + "select " + b + "; " + scr_colorProtein2
	return tx
}

var scr_colorDNA1 = "color [xae00fe]; " //copied from DRuMS
var scr_colorDNA2 = "color [xc63e83]; " //burdeos, derivado del anterior
function scr_colorDNAs(a,b)
{	var tx = "select " + a + "; " + scr_colorDNA1 + "select " + b + "; " + scr_colorDNA2
	return tx
}

/* ============   COLORING SCHEMES    ============ */

/* These scripts act on the whole molecule, not on selected portion.
	(This could be changed to be as in DRuMS)
*/

/* Not yet used, maybe in the future:
FGiJ-extended "protein" is ((protein,ALA,ARG,ASN,ASP,CYS,GLN,GLU,GLY,HIS,ILE,LYS,LEU,MET,PHE,PRO,SER,THR,TRP,TYR,VAL) and not calcium)
*/
var scr_colorMacroMicro = "define temp selected; "
+ "select protein; color [xcbbe8a]; "
+ "select dna; color [xae00fe]; "
+ "select rna; color [xfd0162]; "
+ "select calcium, not (protein, nucleic, water); color [x6dfa36]; "
+ "select solvent; color [x3a79bc]; "
+ "select temp; "

var scr_colorStructure = "define temp selected; select protein; color structure; select temp; "

function scr_colorPolarity(k)
{	var tx =  "define temp selected; "
	tx += "select protein; color [xc8c8c8]; "	// .nonpolar
	tx += "select protein and polar; color [xff33ff]; "	// .polar
	if (k>2) tx	+= "select protein and backbone; color [xb000b0]; "	// .backbone
	if (k>3) 
	{	tx	+= "select protein and acidic and not backbone; color [xdd0000]; "
		tx	+= "select protein and basic and not backbone; color [x3366ff]; "
	}
	if (k>5) tx	+= "select protein and aromatic and not backbone; color [x007700]; "
	tx += "select temp; "
	return tx
}

var colorNt = "select a; color [x5050FF]; "
+ "select t; color [xE6E600]; "
+ "select g; color [x00C000]; "
+ "select c; color [xE00000]; "
+ "select u; color [xCC9900]; "
var scr_colorNt = "define temp selected; " + colorNt + "select temp; "
var scr_colorNtBb = "define temp selected; " + colorNt 
+ "select (dna and backbone); color [xAE00FE]; "
+ "select (rna and backbone); color [xFD0162]; "
+ "select temp; "
