//Validar campos
function validarFormaMedicamentos(form){ 
  if (form.codigo.value ==""){
    alert("Debes llenar el campo CARGO!!");
    form.cargo.focus();
    return false;
   }
} 

//********* AUTO AJUSTAR IFRAME *************

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["frame","frameenfermeria"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
//********* FIN AUTO AJUSTAR IFRAME *************

//  ABRIR VENTANA
function popup (URL){
   window.open(URL,"ventana1","width=120,height=300,scrollbars=NO")
}

function muestraReloj() {
	// Compruebo si se puede ejecutar el script en el navegador del usuario
	if (!document.layers && !document.all && !document.getElementById)
		return
	
	// Obtengo la hora actual y la divido en sus partes
	var fechacompleta = new Date()
	var horas = fechacompleta.getHours()
	var minutos = fechacompleta.getMinutes()
	var segundos = fechacompleta.getSeconds()
	var mt = "AM"
	
	// Pongo el formato 12 horas
	if (horas > 12) {
		mt = "PM"
		horas = horas - 12
	}
	if (horas == 0)
		horas = 12

	// Pongo minutos y segundos con dos dígitos
	if (minutos <= 9)
		minutos = "0" + minutos;
	if (segundos <= 9)
		segundos = "0" + segundos;

	// En la variable 'cadenareloj' puedes cambiar los colores y el tipo de fuente
	//document.title = horas + ':' + minutos + ':' + segundos
	cadenareloj = horas + ":" + minutos + ":" + segundos + " " + mt

	// Escribo el reloj de una manera u otra, según el navegador del usuario
	if (document.layers) {
		document.layers.spanreloj.document.write(cadenareloj)
		document.layers.spanreloj.document.close()
	} else if (document.all) {
		document.all["spanreloj"].innerHTML = cadenareloj
	} else if (document.getElementById) {
		document.getElementById("spanreloj").innerHTML = cadenareloj
	}
	
	/*if(segundos == 10 || segundos == 20 || segundos == 30 || segundos == 40 || segundos == 50){
		if (document.layers) {
			document.layers.eventos.document.write('<?php scroll($baseDatos); ?>')
			document.layers.eventos.document.close()
		} else if (document.all) {
			document.all["eventos"].innerHTML = '<?php scroll($baseDatos); ?>'
		} else if (document.getElementById) {
			document.getElementById("eventos").innerHTML = '<?php scroll($baseDatos); ?>'
		}	
	}*/

	// Ejecuto la función con un intervalo de un segundo
	setTimeout("muestraReloj()", 1000)
}
window.onload = muestraReloj;
if (document.captureEvents) {			//N4 requiere invocar la funcion captureEvents
	document.captureEvents(Event.LOAD)
}


/*
	*******} Codigo para el menu {*******
*/
///No need to edit below this line/////////////////


var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;

		var delay = 4000; //set delay between message change (in miliseconds)
		var maxsteps=30; // number of steps to take to change from start color to endcolor
		var stepdelay=40; // time in miliseconds of a single step
		//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
		var startcolor= new Array(255,255,255); // start color (red, green, blue)
		var endcolor=new Array(163,187,192); // end color (red, green, blue)
		var fcontent=new Array();
		var fwidth='270px'; //set scroller width
		var fheight='80px'; //set scroller height
		
		var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.
		
		var ie4=document.all&&!document.getElementById;				


/*Rafael Raposo edited function*/
//function to change content
function changecontent(){
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
    document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
    if (fadelinks)
      linkcolorchange(1);
    colorfade(1, 15);
  }
  else if (ie4)
    document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {	
    document.getElementById("fscroller").style.color=getstepcolor(step);
    if (fadelinks)
      linkcolorchange(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    clearTimeout(fadecounter);
    document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    setTimeout("changecontent()", delay);
	
  }   
}

/*Rafael Raposo's new function*/
function getstepcolor(step) {
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor[i]-endcolor[i]);
    if(diff > 0) {
      newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}


/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
	dropmenuobj=document.getElementById("hintbox")
	dropmenuobj.innerHTML=menucontents
	dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=tipwidth
	}
	dropmenuobj.x=getposOffset(obj, "left")
	dropmenuobj.y=getposOffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
	dropmenuobj.style.visibility="visible"
	obj.onmouseout=hidetip
	}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

function hintVariable(texto,elemento,event){
	showhint(texto, elemento, event, '200px')
}

//*** PARA APARECER/DESAPARECER CAPAS POR ID
    function mostrarCapas(Fila) {
    var elementos = document.getElementsByName(Fila);
        for (i = 0; i< elementos.length; i++) {
            if(navigator.appName.indexOf("Microsoft") > -1){
                   var visible = ''
            } else {
                  var visible = '';
           }
   elementos[i].style.display = visible;
           }
   }
    
   function ocultarCapas(Fila) {
       var elementos = document.getElementsByName(Fila);
       for (k = 0; k< elementos.length; k++) {
                  elementos[k].style.display = "none";
       }
   }  
   
   function ocultarmostrarcapas(Fila,opcion){
		if(opcion == 0){
			ocultarCapas(Fila);
		}
		else if(opcion == 1){
			mostrarCapas(Fila);
		}
   }

/// ******** FACTURAS FINALES

function escondereditarnombre(){
	ocultarmostrarcapas("editarnombre",0);
	ocultarmostrarcapas("nombreeditado",1);
	document.getElementById("nombreeditado").innerHTML=document.getElementById("nombre").value;
}
function mostrareditarnombre(){
	ocultarmostrarcapas("editarnombre",1);
	ocultarmostrarcapas("nombreeditado",0);		
}
///////////////////////
function escondereditardomicilio(){
	ocultarmostrarcapas("editardomicilio",0);
	ocultarmostrarcapas("domicilioeditado",1);
	document.getElementById("domicilioeditado").innerHTML=document.getElementById("domicilio").value;
}
function mostrareditardomicilio(){
	ocultarmostrarcapas("editardomicilio",1);
	ocultarmostrarcapas("domicilioeditado",0);		
}
/////////////////
function escondereditarciudad(){
	ocultarmostrarcapas("editarciudad",0);
	ocultarmostrarcapas("ciudadeditado",1);
	document.getElementById("ciudadeditado").innerHTML=document.getElementById("ciudad").value;
}
function mostrareditarciudad(){
	ocultarmostrarcapas("editarciudad",1);
	ocultarmostrarcapas("ciudadeditado",0);		
}
/////////////////
function escondereditarrfc(){
	ocultarmostrarcapas("editarrfc",0);
	ocultarmostrarcapas("rfceditado",1);
	document.getElementById("rfceditado").innerHTML=document.getElementById("rfc").value;
}
function mostrareditarrfc(){
	ocultarmostrarcapas("editarrfc",1);
	ocultarmostrarcapas("rfceditado",0);		
}
