//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor="lightyellow"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous)) {
previous.style.backgroundColor='#F8F8F8';
previous.style.border='solid gray 1px';
}
previous=eventobj
if (checkel(eventobj)) {
eventobj.style.backgroundColor=highlightcolor;
eventobj.style.border='solid #E4B023 1px';
}
}
else{
if (checkel(eventobj))
{
eventobj.style.backgroundColor=highlightcolor;
eventobj.style.border='solid #E4B023 1px';
}

previous=eventobj
}
}




var no_permitidos = /[<>"']/;

function validar_email(texto) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(texto)){
	return (true)
	}
return (false)
}

function validar_numero(texto) {
if (/^[0-9]+$/.test(texto)){
	return (true)
	}
return (false)
}


function validar_texto(texto) {
if(texto.value.search(no_permitidos) == -1) {
	return true;
	}
else	{
	return false;
	}
}

function confirmacion_grabar(formulario,destino,valor) {
	if (confirm("¿Deseás guardar los cambios?")) {
		formulario.anterior.value=valor;
		if (validar_formulario()==true)
			formulario.submit();
	
	} else {
		document.location=destino;
	}
}



numeros="0123456789";
   separadorfecha="/";
   var separadorhora=":";
   error= new creaerror();  
   errores= new Array();
  
   errores[1]="Campo vacio no contiene ningún valor ";
   errores[2]="Carácter ilegal en una fecha";
   errores[3]="Faltan separadores en una fecha";
   errores[4]="Año incorrecto en una fecha";
   errores[5]="Mes incorrecto en una fecha";
   errores[6]="Día incorrecto en una fecha";
   errores[7]="Carácter ilegal en una hora";
   errores[8]="Faltan separadores en una hora";
   errores[9]="Hora incorrecta en una hora";
   errores[10]="Minutos incorrectos en una hora";
   errores[11]="Segundos incorrectos en una hora";
  
   // Crea un objeto que guarda un indice a la posición y al mensaje de error
   function creaerror()
   {
   this.valor=0;
   this.posicion=0;
   return this
   }
  
   // Determina si un caracter es un número
   function numero(car)
   {
   return (numeros.indexOf(car)>=0)
   }
   
   // Determina si un año es bisiesto
   function bisiesto(anio) 
   {
   if (((anio % 4 == 0) && anio % 100 != 0) || anio % 400 == 0) 
      return true;
   return false;
   }

   // Comprueba si una fecha es correcta
   function compruebafecha(contenido,error)
   {
   
   if ((contenido.length==0))
      {
      error.valor=1;
      error.posicion=1; 
      return false;
      } 
   var nsep=0;
   // Comprobación de la sintáxis de una fecha 
   for (var i=0; i<contenido.length; ++i)
      {
      var car=contenido.charAt(i);
      if (!numero(car)&&car!=separadorfecha)
         {
         error.valor=2;
         error.posicion=i+1; 
         return false;
         } 
      if (car==separadorfecha)
        nsep++ 
      }
   if (nsep!=2)
      {
      error.valor=3;
      error.posicion=i+1; 
      return false;
      }
   // Comprobación de la semántica de una fecha
   var pos1=contenido.indexOf(separadorfecha);
   var dia=contenido.substring(0,pos1);
   var pos2=contenido.indexOf(separadorfecha,pos1+1);
   var mes=contenido.substring(pos1+1,pos2); 
   var anio=contenido.substring(pos2+1,10);
   if (anio<1900||anio>2040)
      {
      error.valor=4;
      error.posicion=6; 
      return false;
      } 
   if (mes<1||mes>12)
      {
      error.valor=5;
      error.posicion=4;
      return false;
      }
   if ((dia<1 || dia>31)||(mes==4&&dia>30)||(mes==6&&dia>30)
         ||(mes==9&&dia>30)||(mes==11&&dia>30)
         ||(mes==2&&bisiesto(anio)&&dia>29)
         ||(mes==2&&!bisiesto(anio)&&dia>28)
         )
      {
      error.valor=6;
      error.posicion=2;
      return false;
      } 
   return true 
   }


function mostrarCantidad(aContar, elTexto) {
	var i;
	var cantidad =0;
	var texto = '';
	for (i=0; i < aContar.options.length; i++)
		if (aContar.options[i].selected) {
			if (cantidad>0)
				texto=texto+', '+aContar.options[i].text;
			else
				texto=aContar.options[i].text;
			cantidad++;
		}
	if (cantidad==1)
		elTexto.innerHTML = '<strong>' + cantidad + ' opción seleccionada</strong><br>'+texto;
	else
		if (cantidad==0)
			elTexto.innerHTML = '<strong>Ninguna opción seleccionada</strong>';
		else
			elTexto.innerHTML = '<strong>'+ cantidad +' opciones seleccionadas </strong><br>' + texto;
}




/***********************************************
* Highlight Table Cells Script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TABLE")
return
while(source.tagName!=highlightbehavior && source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}

