

var ie  = document.all;
var ocultados=false;

function submitToProcess(url)
{
		if (document.forms[0])
			if(document.forms[0].__VIEWSTATE)
				{
					document.forms[0].__VIEWSTATE.name='ignore';
					document.forms[0].__VIEWSTATE.value='';
				}
		document.forms[0].action=path + url;
		document.forms[0].submit();	
}


/* Este es el script de Validaciones de la Aplicación

Este Contiene Básicamente las Funciones:

- validacampo(control,requerido,nombre,tipo,longitud_max,longitud_min,caracteres_permitidos)
	+control: es el id del Control
	+requerido: es un flag para saber si debe tener algo siempre
	+nombre: Es solo una cadena para referenciarnos al campo para hacer la validacion en el control
	+tipo: es el Tipo de Dato, puede ser:
		-numero
		-decimal
		-fecha
		-hora
		-texto
		-no_cero
		-otro
		-email
	+longitud_max: maximo de Caracteres 	
	+longitud_min: minimo de Caracteres
	+caracteres_permitidos: numero de Caracteres que permite el control

- ShowError(mensaje) - Añade el mensaje de error en el control de errorDisplay y lo muestra 
- clearErrors() -Borra los mensajes de error en el ErrorDisplay
*/


function showError(mensaje){
	var browser_type=navigator.appName;
	var browser_version=parseInt(navigator.appVersion);
	if (browser_type=="Microsoft Internet Explorer")
	{	
		if (document.getElementById("errors")){
			var errCtl = document.getElementById("errors")
			var errLstCtl = document.getElementById("errorList")
			errLstCtl.insertAdjacentHTML("beforeEnd", mensaje);
			errCtl.lastChild.style.display='block';
			errCtl.style.display='block';
			window.scroll(0,0);
			Esconder();
			
		}
		else{
			re = /<li>/gi;
			mensaje=mensaje.replace(re, "");
			re = /li>/gi;
			mensaje=mensaje.replace(re, "");
			alert(mensaje)
		}	
	}
	else{
		re = /<li>/gi;
		mensaje=mensaje.replace(re, "");
		re = /li>/gi;
		mensaje=mensaje.replace(re, "");
		alert(mensaje)
	}	
}

function clearErrors(){
	if (document.getElementById("errors")){
		var errLstCtl = document.getElementById("errorList")
		errLstCtl.innerHTML='';
	}
}


function validacampo(control,requerido,nombre,tipo,longitud_max,longitud_min,caracteres_permitidos)
		{  
			var mensaje="";
			var Formato="";
			valor=control.value;
			tipo=tipo.toLowerCase();
			
			while(''+valor.charAt(0)==' ')
			{
			  valor=valor.substring(1,valor.length);
			}
			
			
			control.value=valor;
			
			
			
			if (requerido && (valor==""))
			{
				//alert("El campo " + nombre + " no puede quedar en blanco");
				mensaje= "<li>El campo " + nombre + " no puede quedar en blanco</li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return (false);
			}
			
			
			
			
			if (!requerido && valor!="")
			  {
			     requerido=true
			  }
			  
			  
//_______________________________________________________________________________________________________			  
			  			 
			if (tipo=="fecha"  && requerido)
			{
				// ahora será requisito que las páginas que usen fechas declaren la variable shortDatePattern
				if(!ChecarFecha(valor,shortDatePattern,nombre))
				{
				// Fecha incorrecta
				mensaje += "<li></li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return(false);
				}
				
			}
			
//_______________________________________________________________________________________________________	
			



//_______________________________________________________________________________________________________	

		
		if ((tipo=="numero" || tipo=="texto" || tipo=="email" || tipo=="otro" || tipo=="no_cero" || tipo=="decimal")  && requerido)
		{
			
			if (valor.length >longitud_max)
			{
				//alert ("La longitud en el campo "+ nombre + " debe ser menor o igual a "+ longitud_max.toString());
				
				mensaje="<li>La longitud en el campo "+ nombre + " debe ser menor o igual a "+ longitud_max.toString(); +"</li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				if (control.visible == true) control.focus();
				return(false);
			}
			
			
						
			if (valor.length < longitud_min)
			{
				//alert ("La longitud en el campo "+ nombre + " debe ser mayor o igual a "+ longitud_min.toString());
				mensaje="<li>La longitud en el campo "+ nombre + " debe ser mayor o igual a "+ longitud_min.toString();+"</li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return(false);
			}
			
		}
		
		
		if (tipo=="otro" && requerido)
		{
			for (i = 0;  i < valor.length;  i++)
			{
			  ch = valor.charAt(i);
			  for (j = 0;  j < caracteres_permitidos.length;  j++)
			    if (ch == caracteres_permitidos.charAt(j))
			      break;
			  if (j == caracteres_permitidos.length)
			  {
				alert ("El campo "+ nombre + " contiene caracteres no válidos");
				mensaje="<li>El campo "+ nombre + " contiene caracteres no válidos </li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return(false);
			  }
			}
		}
		
		
		if ((tipo=="numero" || tipo=="no_cero" || tipo=="entero" || tipo=="decimal") && requerido)
		{
			if (isNaN(valor) || valor.substring(valor.indexOf(".")+1)=="" || valor < "0")
			{
				//alert ("El valor del campo "+ nombre + " debe ser un numero");
				mensaje="<li>El valor del campo "+ nombre + " debe ser un numero válido</li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return(false);
			}
	
		if(tipo=="entero")
		{	
			
			if(valor!=parseInt(valor))	
			{
				mensaje="<li>El campo " +  nombre + " debe ser Entero</li>"
				showError(mensaje);				
				if (control.visible == true) control.focus();
				return(false);
			
			}		
		
		}
		
		if(tipo=="decimal")
		{	valor = valor.replace(",","");
			control.value = valor ;
			if (isNaN(parseFloat(valor)))
					{
					mensaje="<li>El campo " +  nombre + " debe ser Entero</li>"
					showError(mensaje);				
					if (control.visible == true) control.focus();
					return(false);
					}	
		
		}
}
		
if (tipo=="no_cero" && requerido)
		{
			if (valor==0)
			{
				//alert ("El campo "+ nombre + " no puede ser cero.");
				mensaje="<li>El valor del campo "+ nombre + " debe ser válido o no cero</li>"
				showError(mensaje);				
				if (control.visible == true) control.focus();
				return(false);
			}
}
		
		
		if (tipo == "telefono" && requerido)
		{
			if (/^[\d+|(\(\d+\))]([\d+|\s+|\-+|(\(\d+\))+])*$/.test(valor))
			{
				// todo está bien
			}
			else
			{
				mensaje = "<li>El teléfono " + control.value + " es incorrecto</li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return (false);
			}
		}
		
		
		if (tipo=="email" && requerido)
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
			{
				// todo está bien
			}
			else 
			{
			   	//alert("La dirección de email es incorrecta.");
			   	mensaje="<li>La direccion de email " + control.value + " es incorrecta</li>"
			   	showError(mensaje);
			   	if (control.visible == true) control.focus();
			    return (false);
			}

		}
		
if (tipo=="hora" && requerido)
		{
		
	
	var horario = valor;
	if(horario!="")
		{
			if(horario.search(":")== -1)
			{	
				mensaje="<li>La hora debe estar en formato hh:mm, en el Campo: " + nombre +" </li>"
				showError(mensaje);
				if (control.visible == true) control.focus();
				return(false);
			
			//alert("La hora debe estar en formato hh:mm");
			}
			
			else
			{
				var horas =horario.split(":")[0];
				var minutos = horario.split(":")[1];
		
				if((isNaN(horas)) || (isNaN(minutos)))
				{
					//alert("El formato de horas solo debe tener números");
				
					mensajes="<li>El formato de horas solo debe tener números, en el Campo: " + nombre +" </li>"
					showError(mensaje);
					if (control.visible == true) control.focus();
					return(false);
				}
				else
				{
				//var horas = parseInt(horario.split(":")[0])
				//var minutos = parseInt(horario.split(":")[1])
				}
		
				if((horas.length<1) || (minutos.length<2))
				{
					//alert("La hora debe estar en formato hh:mm");
					
						
					mensaje="<li>La hora debe estar en formato hh:mm, en el Campo: " + nombre +" </li>"
					showError(mensaje);
					if (control.visible == true) control.focus();
					return(false);
				}
				
				if((horas<0) || (horas>23))
				{
					//alert("El valor de la hora es invalido");
					
					mensaje="<li>El valor de la hora es invalido, en el Campo: " + nombre+" </li>"
					showError(mensaje);
					if (control.visible == true) control.focus();
					return(false);
				}
				else if((minutos<0) || (minutos>59))
				{
					//alert("El valor de los minutos es invalido");
					
					mensaje="<li>El valor de los minutos es invalido, en el Campo: " + nombre+" </li>"
					showError(mensaje);
					if (control.visible == true) control.focus();
					return(false);
				}
			}
		}
	}
		return(true);
}
	
	

function validacombo(control,campo)
	{
	 	if(control.selectedIndex<0)
		{
			//alert("No ha Seleccionado el campo "+campo+ ")
			mensaje="<li>No ha Seleccionado el campo "+campo+ "</li>"
			showError(mensaje);
			//control.focus()
			return (false)
		}
		return(true);
}
	
	

//_______________________________________

function rango(ctrl,nombre,num1,num2)
	{
	var a=ctrl.value;
	if(a<num1 || a>num2)
	{
		mensaje="<li>El campo "+ nombre +" debe estar entre "+ num1 +" y "+ num2 +"</li>"
		showError(mensaje);
		return (false);
	}
	
	return (true);
}


//_______________________________________	
	

//_______________________________________	

function compara(ctr1, ctr2, nom1, nom2, signo)
{
		var a=parseFloat(ctr1.value);
		var b=parseFloat(ctr2.value);
	
		if(signo=='mayor' || signo=='>')
		{
			if (a<=b)
			{
				mensaje="<li>El campo "+ nom1 +" no puede ser menor o igual al campo "+nom2+ "</li>"
				showError(mensaje);
				return (false);
			}
		}
		
		if(signo=="menor" || signo=="<")
		{
			if (a>=b)
			{
				mensaje="<li>El campo "+ nom1 +" no puede ser mayor o igual al campo "+nom2+ "</li>"
				showError(mensaje);	
				return (false);
			}
		}
		
		
		if(signo=="igual" || signo=="=")
		{
			if (a==b)
			{
				mensaje="<li>El campo "+ nom1 +" no puede ser igual al campo "+nom2+ "</li>"
				showError(mensaje);	
				return (false)
			}
		}
		
		
		return (true);

	}
//_______________________________________
	
	
	
	
// ________ Esta Funcion sirve para validar el traslape de los limites______
		
		
		
		function Traslape(ctrl1, ctrl2, div1, div2, cant, nom1, nom2, divfecha, fecha)
		{
			a=parseFloat(ctrl1.value);
			b=parseFloat(ctrl2.value);
			
	
			if(cant<=1)
			{
			
			if(divfecha.innerText==fecha )
			{
			
				 if( a >= parseFloat(div1.innerText) && a <= parseFloat(div2.innerText) )
				   {
					mensaje="<li>El Campo "+ nom1 +" se traslapa con algun valor de la Tabla</li>"
					showError(mensaje);
					return (false)
				   }
				   
				   if( b >= parseFloat(div1.innerText) && b <= parseFloat(div2.innerText)  )
				   {
				   
					mensaje="<li>El Campo "+ nom2 +" se traslapa con algun valor de la Tabla</li>"
					showError(mensaje);   
					return (false)
						
				   }
				   
			
			}
			} 
			else
			{
				for(i=0; i<cant; i++)
				{
				
				if(divfecha(i).innerText==fecha )
					{
				
				   if( a >= parseFloat(div1(i).innerText) && a <= parseFloat(div2(i).innerText) )
				   {
					mensaje="<li>El Campo "+ nom1 +" se traslapa con algun valor de la Tabla</li>"
					showError(mensaje);			
					return (false)
				   }
				   
				   if( b >= parseFloat(div1(i).innerText) && b <= parseFloat(div2(i).innerText)  )
				   {
				   
					mensaje="<li>El Campo "+ nom2 +" se traslapa con algun valor de la Tabla</li>"
					showError(mensaje);   
					return (false);
						
				   }
				   
				   }
				
				}
			
			}
			
			return (true);
}
	


function Suma(arreglo)
    { 	
	var s;
	n=arreglo.length;
	
	s=0;	
	for(i=0; i<n; i++)
	{
		s+=parseInt(arreglo[i].value)
	}
	
	Return(s);
	
}  

	
	
	
	
	
// ___________  Funciones para mostrar y esconder combos _________________	

function Esconder() {

	if(!box.style.display=="block")
	{
		
	
	}
	else
	{
	
		if(ie) {
		elmID="SELECT";
		overDiv="box";
		
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags( elmID )[i];
				if(!obj || !obj.offsetParent) continue;

				// Find the element's offsetTop and offsetLeft relative to the BODY tag.
				objLeft   = obj.offsetLeft;
				objTop    = obj.offsetTop;
				objParent = obj.offsetParent;

				while(objParent.tagName.toUpperCase() != 'BODY') {
					objLeft  += objParent.offsetLeft;
					objTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}

				objHeight = obj.offsetHeight;
				objWidth  = obj.offsetWidth;
				if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
				else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
				/* CHANGE by Charlie Roche for nested TDs*/
				else if(overDiv.offsetTop >= (objTop + objHeight + obj.height));
				/* END CHANGE */
				else if(overDiv.offsetLeft >= (objLeft + objWidth));
				else {
					if (obj.style.display=='none')
						{
						obj.style.display = 'none';
						obj.name='ITXNON'+obj.name;
						}
					else
						obj.style.display = 'none';
					ocultados=true;
					
				}
			}
		}
	}
	}
	
	
	



function VerCombos() {
		
		if(box.style.display=="block")
		{
			Esconder();
			
		}
		else
		{
		if(ocultados){
		if(ie) {
		elmID="SELECT";
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags(elmID)[i];
				if(!obj || !obj.offsetParent) continue;
				if(obj.name.indexOf('ITXNON')>=0)
					{
					obj.name=obj.name.replace('ITXNON','');
					obj.style.display= 'none';
					}
				else
					obj.style.display= '';
			}
		}
		}
		}
	}








//_____________________ Funciones para validar las fechas___________________________________________


/* Here's the list of tokens we support:
   m (or M) : month number, one or two digits.
   mm (or MM) : month number, strictly two digits (i.e. April is 04).
   d (or D) : day number, one or two digits.
   dd (or DD) : day number, strictly two digits.
   y (or Y) : year, two or four digits.
   yy (or YY) : year, strictly two digits.
   yyyy (or YYYY) : year, strictly four digits.
   mon : abbreviated month name (April is apr, Apr, APR, etc.)
   Mon : abbreviated month name, mixed-case (i.e. April is Apr only).
   MON : abbreviated month name, all upper-case (i.e. April is APR only).
   mon_strict : abbreviated month name, all lower-case (i.e. April is apr 
         only).
   month : full month name (April is april, April, APRIL, etc.)
   Month : full month name, mixed-case (i.e. April only).
   MONTH: full month name, all upper-case (i.e. APRIL only).
   month_strict : full month name, all lower-case (i.e. april only).
   h (or H) : hour, one or two digits.
   hh (or HH) : hour, strictly two digits.
   min (or MIN): minutes, one or two digits.
   mins (or MINS) : minutes, strictly two digits.
   s (or S) : seconds, one or two digits.
   ss (or SS) : seconds, strictly two digits.
   ampm (or AMPM) : am/pm setting.  Valid values to match this token are
         am, pm, AM, PM, a.m., p.m., A.M., P.M.
*/
// Be careful with this pattern.  Longer tokens should be placed before shorter
// tokens to disambiguate them.  For example, parsing "mon_strict" should 
// result in one token "mon_strict" and not two tokens "mon" and a literal
// "_strict".

var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mins|MINS|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");

// lowerMonArr is used to map months to their numeric values.

var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}

// monPatArr contains regular expressions used for matching abbreviated months
// in a date string.

var monPatArr=new Array();
monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');

// monthPatArr contains regular expressions used for matching full months
// in a date string.

var monthPatArr=new Array();
monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);

// cutoffYear is the cut-off for assigning "19" or "20" as century.  Any
// two-digit year >= cutoffYear will get a century of "19", and everything
// else gets a century of "20".

var cutoffYear=50;

// FormatToken is a datatype we use for storing extracted tokens from the
// format string.

function FormatToken (token, type) {
this.token=token;
this.type=type;
}

function parseFormatString (formatStr) {
var tokArr=new Array;
var tokInd=0;
var strInd=0;
var foundTok=0;
    
while (strInd < formatStr.length) {
if (formatStr.charAt(strInd)=="%" &&
(matchArray=formatStr.substr(strInd+1).match(tokPat)) != null) {
strInd+=matchArray[0].length+1;
tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
} else {

// No token matched current position, so current character should 
// be saved as a required literal.

if (tokInd>0 && tokArr[tokInd-1].type=="literal") {

// Literal tokens can be combined.Just add to the last token.

tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
}
else {
tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
      }
   }
}
return tokArr;
}

/* buildDate does all the real work.It takes a date string and format string,
 tries to match the two up, and returns a Date object (with the supplied date
 string value).If a date string doesn't contain all the fields that a Date
 object contains (for example, a date string with just the month), all
 unprovided fields are defaulted to those characteristics of the current
 date. Time fields that aren't provided default to 0.Thus, a date string
 like "3/30/2000" in "%mm/%dd/%yyyy" format results in a Date object for that
 date at midnight.formatStr is a free-form string that indicates special
 tokens via the % character.Here are some examples that will return a Date
 object:

 buildDate('3/30/2000','%mm/%dd/%y') // March 30, 2000
 buildDate('March 30, 2000','%Mon %d, %y') // Same as above.
 buildDate('Here is the date: 30-3-00','Here is the date: %dd-%m-%yy')

 If the format string does not match the string provided, an error message
 (i.e. String object) is returned.Thus, to see if buildDate succeeded, the
 caller can use the "typeof" command on the return value.For example,
 here's the dateCheck function, which returns true if a given date is
 valid,and false otherwise (and reports an error in the false case):

 function dateCheck(dateStr,formatStr) {
 var myObj=buildDate(dateStr,formatStr);
 if (typeof myObj=="object") {
 // We got a Date object, so good.
 return true;
 } else {
 // We got an error string.
 alert(myObj);
 return false;
 }
 }

*/

///////////////////////////////////////////////////////////////////////////////

function buildDate(dateStr,formatStr) {
// parse the format string first.
var tokArr=parseFormatString(formatStr);
var strInd=0;
var tokInd=0;
var intMonth;
var intDay;
var intYear;
var intHour;
var intMin;
var intSec;
var ampm="";
var strOffset;

// Create a date object with the current date so that if the user only
// gives a month or day string, we can still return a valid date.

var curdate=new Date();
intMonth=curdate.getMonth()+1;
intDay=curdate.getDate();
intYear=curdate.getFullYear();

// Default time to midnight, so that if given just date info, we return
// a Date object for that date at midnight.

intHour=0;
intMin=0;
intSec=0;

// Walk across dateStr, matching the parsed formatStr until we find a 
// mismatch or succeed.

while (strInd < dateStr.length && tokInd < tokArr.length) {

// Start with the easy case of matching a literal.

if (tokArr[tokInd].type=="literal") {
if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd) {

// The current position in the string does match the format 
// pattern.

strInd+=tokArr[tokInd++].token.length;
continue;
}
else {

// ACK! There was a mismatch; return error.

//return "\"" + dateStr + "\" does not conform to the expected format: " + formatStr;

return "\"" + dateStr + "\" no se Ajusta al Formato:  " + formatStr +"";

   }
}

// If we get here, we're matching to a symbolic token.
switch (tokArr[tokInd].token) {
case 'm':
case 'M':
case 'd':
case 'D':
case 'h':
case 'H':
case 'min':
case 'MIN':
case 's':
case 'S':

// Extract one or two characters from the date-time string and if 
// it's a number, save it as the month, day, hour, or minute, as
// appropriate.

curChar=dateStr.charAt(strInd);
nextChar=dateStr.charAt(strInd+1);
matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
if (matchArr==null) {

// First character isn't a number; there's a mismatch between
// the pattern and date string, so return error.

switch (tokArr[tokInd].token.toLowerCase()) {
case 'd': var unit="Dia"; break;
case 'm': var unit="Mes"; break;
case 'h': var unit="Hora"; break;
case 'min': var unit="Minuto"; break;
case 's': var unit="Segundo"; break;
}
//return "Bad " + unit + " \"" + curChar + "\" or \"" + curChar + nextChar + "\".";
//return unit + "Invalido" + " \"" + curChar + "\" or \"" + curChar + nextChar + "\".";

return "" + unit + " Invalido" + " \"" + curChar + "\" or \"" + curChar + nextChar + "\".";


}
strOffset=matchArr[0].length;
switch (tokArr[tokInd].token.toLowerCase()) {
case 'd': intDay=parseInt(matchArr[0],10); break;
case 'm': intMonth=parseInt(matchArr[0],10); break;
case 'h': intHour=parseInt(matchArr[0],10); break;
case 'min': intMin=parseInt(matchArr[0],10); break;
case 's': intSec=parseInt(matchArr[0],10); break;
}
break;
case 'mm':
case 'MM':
case 'dd':
case 'DD':
case 'hh':
case 'HH':
case 'mins':
case 'MINS':
case 'ss':
case 'SS':

// Extract two characters from the date string and if it's a 
// number, save it as the month, day, or hour, as appropriate.

strOffset=2;
matchArr=dateStr.substr(strInd).match(/^\d{2}/);
if (matchArr==null) {

// The two characters aren't a number; there's a mismatch 
// between the pattern and date string, so return an error
// message.

switch (tokArr[tokInd].token.toLowerCase()) {
case 'dd': var unit="day"; break;
case 'mm': var unit="month"; break;
case 'hh': var unit="hour"; break;
case 'mins': var unit="minute"; break;
case 'ss': var unit="second"; break;
}
//return "Bad " + unit + " \"" + dateStr.substr(strInd,2) + "\".";
	return ""+ unit + "Invalido \"" + dateStr.substr(strInd,2) + "\".";

}
switch (tokArr[tokInd].token.toLowerCase()) {
case 'dd': intDay=parseInt(matchArr[0],10); break;
case 'mm': intMonth=parseInt(matchArr[0],10); break;
case 'hh': intHour=parseInt(matchArr[0],10); break;
case 'mins': intMin=parseInt(matchArr[0],10); break;
case 'ss': intSec=parseInt(matchArr[0],10); break;
}
break;
case 'y':
case 'Y':

// Extract two or four characters from the date string and if it's
// a number, save it as the year.Convert two-digit years to four
// digit years by assigning a century of '19' if the year is >= 
// cutoffYear, and '20' otherwise.

if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {

// Four digit year.

intYear=parseInt(dateStr.substr(strInd,4),10);
strOffset=4;
}
else {
if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {

// Two digit year.

intYear=parseInt(dateStr.substr(strInd,2),10);
if (intYear>=cutoffYear) {
intYear+=1900;
}
else {
intYear+=2000;
}
strOffset=2;
}
else {

// Bad year; return error.
//return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two or four digits.";

return " Año Invalido \"" + dateStr.substr(strInd,2) + "\". Debe ser de 2 ó 4 digitos.";

   }
}
break;
case 'yy':
case 'YY':

// Extract two characters from the date string and if it's a 
// number, save it as the year.Convert two-digit years to four 
// digit years by assigning a century of '19' if the year is >= 
// cutoffYear, and '20' otherwise.

if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {

// Two digit year.

intYear=parseInt(dateStr.substr(strInd,2),10);
if (intYear>=cutoffYear) {
intYear+=1900;
}
else {
intYear+=2000;
}
strOffset=2;
} else {
// Bad year; return error
//return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two digits.";

return " Año Invalido \"" + dateStr.substr(strInd,2) + "\". Debe ser de 2 digitos.";


}
break;
case 'yyyy':
case 'YYYY':

// Extract four characters from the date string and if it's a 
// number, save it as the year.

if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {

// Four digit year.

intYear=parseInt(dateStr.substr(strInd,4),10);
strOffset=4;
}
else {

// Bad year; return error.

//return "Bad year \"" + dateStr.substr(strInd,4) + "\". Must be four digits.";
return "Año Invalido \"" + dateStr.substr(strInd,2) + "\". Debe ser de 4 digitos.";
}

break;
case 'mon':
case 'Mon':
case 'MON':
case 'mon_strict':

// Extract three characters from dateStr and parse them as 
// lower-case, mixed-case, or upper-case abbreviated months,
// as appropriate.

monPat=monPatArr[tokArr[tokInd].token];
if (dateStr.substr(strInd,3).search(monPat) != -1) {
intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
}
else {

// Bad month, return error.

switch (tokArr[tokInd].token) {
case 'mon_strict': caseStat="lower-case"; break;
case 'Mon': caseStat="mixed-case"; break;
case 'MON': caseStat="upper-case"; break;
case 'mon': caseStat="between Jan and Dec"; break;
}
// return "Bad month \"" + dateStr.substr(strInd,3) + "\". Must be " + caseStat + ".";
return "Mes Invalido \"" + dateStr.substr(strInd,3) + "\". Debe ser " + caseStat + ".";

}
strOffset=3;
break;
case 'month':
case 'Month':
case 'MONTH':
case 'month_strict':

// Extract a full month name at strInd from dateStr if possible.

monPat=monthPatArr[tokArr[tokInd].token];
matchArray=dateStr.substr(strInd).match(monPat);
if (matchArray==null) {

// Bad month, return error.

//return "Can't find a month beginning at \"" +dateStr.substr(strInd) + "\".";
return "No se puede encontrar un mes en: \"" +dateStr.substr(strInd) + "\".";

}

// It's a good month.

intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
strOffset=matchArray[0].length;
break;
case 'ampm':
case 'AMPM':
matchArr=dateStr.substr(strInd).match(/^(am|pm|AM|PM|a\.m\.|p\.m\.|A\.M\.|P\.M\.)/);
if (matchArr==null) {

// There's no am/pm in the string.Return error msg.

//return "Missing am/pm designation.";
return "Falta especificar am/pm";


}

// Store am/pm value for later (as just am or pm, to make things
// easier later).

if (matchArr[0].substr(0,1).toLowerCase() == "a") {

// This is am.

ampm = "am";
}
else {
ampm = "pm";
}
strOffset = matchArr[0].length;
break;
}
strInd += strOffset;
tokInd++;
}
if (tokInd != tokArr.length || strInd != dateStr.length) {

/* We got through the whole date string or format string, but there's 
 more data in the other, so there's a mismatch. */

//return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: " + formatStr;
return "\"" + dateStr + "\" Falta Informacion Requerida o hay mas informacion de la que se especifica en el formato:" + formatStr +"";
}

// Make sure all components are in the right ranges.

if (intMonth < 1 || intMonth > 12) {
//return "Month must be between 1 and 12.";
return "El mes debe estar entre 1 y 12";
}
if (intDay < 1 || intDay > 31) {
//return "Day must be between 1 and 31.";
return "El día debe estar entre 1 y 31";
}

// Make sure user doesn't put 31 for a month that only has 30 days

if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31) 
{
//return "Month "+intMonth+" doesn't have 31 days!";
return "Mes " +intMonth+ " no tiene 31 días!";
}

// Check for February date validity (including leap years) 

if (intMonth == 2) {

// figure out if "year" is a leap year; don't forget that
// century years are only leap years if divisible by 400

var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
if (intDay > 29 || (intDay == 29 && !isleap)) {
//return "February " + intYear + " doesn't have " + intDay + " days!";
return "Febrero " + intYear + " no tiene " + intDay + " dias!";
   }
}

// Check that if am/pm is not provided, hours are between 0 and 23.

if (ampm == "") {
if (intHour < 0 || intHour > 23) {
return "Hour must be between 0 and 23 for military time.";
   }
}
else {

// non-military time, so make sure it's between 1 and 12.

if (intHour < 1|| intHour > 12) {
return "Hour must be between 1 and 12 for standard time.";
   }
}

// If user specified amor pm, convert intHour to military.

if (ampm=="am" && intHour==12) {
intHour=0;
}
if (ampm=="pm" && intHour < 12) {
intHour += 12;
}
if (intMin < 0 || intMin > 59) {
return "Minute must be between 0 and 59.";
}
if (intSec < 0 || intSec > 59) {
return "Second must be between 0 and 59.";
}
return new Date(intYear,intMonth-1,intDay,intHour,intMin,intSec);
}


///////////////////////////////////////////////////////////////////////
function ChecarFecha(dateStr,formatStr,campo) {
var myObj = buildDate(dateStr,formatStr);
if (typeof myObj == "object") {

// We got a Date object, so good.

return true;
}
else {

// We got an error string.

//alert(myObj);

	mensaje= "<li>" + myObj + " en el Campo: " + campo+ "</li>";
				
	errors.style.display="block";
	errors.children(1).children(1).children(0).insertAdjacentHTML("beforeEnd", mensaje);


return false;
   }
}
//-->


function validacombo2(control,campo)
{
	 	if(control.selectedIndex<=0)
		{
			//alert("No ha Seleccionado el campo "+campo+ ")
			mensaje="<li>No ha Seleccionado el campo "+campo+ "</li>"
			showError(mensaje);
			//control.focus()
			return (false)
		}
		return(true);
}		


function trim(s) 
{
  while (s.substring(0,1) == ' ') 
  {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') 
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}