function checkMovilMessageLength(objetoName, maximo)
{
	var obj = document.forms[0].elements[objetoName];
	if (obj && obj.value.length>maximo)
	{
		obj.value = obj.value.substring(0,maximo);
	}
}


function abrirVentana(pagina,marco,width,height)
{
	x = (screen.width/2) - (width/2);
	y = (screen.height/2) - (height/2) - 50;
	var gwa = window.open(pagina,marco,'height=' + height + ',width=' + width + ',top=' + y + ',left=' + x);
	if (gwa)
	{
		gwa.focus();
		gwa.resizeTo(width+12,height+36);
		gwa.moveTo(x,y);
	}
}
/****************************************
**
**	Validacion de fechas
**
*****************************************/
function validaFecha(source, arguments)
{
	arguments.IsValid = isFecha(arguments.Value);
}

function isFecha(fecha) 
{	
	var expr = /^(\d|\d{2})\/(\d|\d{2})\/(\d{4})$/;
	//var expr2 = /^(\d|\d{2})\/(\d|\d{2})\/(\d{2})$/;
	if (fecha==null || fecha=="" || expr.test(fecha) /*|| expr2.test(fecha)*/) {
		if (fecha!=null && fecha!=""){
			var aDiasMes = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
			var meses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
			var aFecha = fecha.split('/');
			var dia = aFecha[0];
			var mes = aFecha[1];
			var ano = aFecha[2];
			var diasFebrero = (ano % 4 == 0 && (!(ano % 100 == 0) || (ano % 400 == 0)) ? 29 : 28);
		
			if (ano.length==4 && (ano < 1900 || ano > 2100))
			{
		    	return false;		   
			}
			if (mes < 1 || mes > 12)
			{
				return false;
			}
			if	(dia < 1 || dia > aDiasMes[mes-1] || (mes == 2 && dia > diasFebrero))
			{
				return false;
			}
		} 
	}
	else {
		return false;
	}
	return true;
}

/****************************************
**
**	Area de configuración del calendario
**
*****************************************/
var aniosPost=20
var aniosAnt=110
var anniodosdigitos=false
var ancho_calendario=200
var xMenos= ancho_calendario / 2
var yMenos= 12

var fondo_atras="#FEF5D3"
var color_borde="#D1A806"
var familia_font="MS Sans Serif, sans-serif"
var tamano_font=8
var tamano_font_nts=1
var fondo_dias = "#FEF5D3"
var letra_dias = "#000099"
var fondo_dias_vacios = "#FFFDF7"
var fondo_dias_festivos = "#FBDC63"
var letra_dias_festivos = "black"
var fondo_dia_selecc= "red"
var letra_dia_selecc= "white"
var fondo_dia_actual = "tomato"
var letra_dia_actual = "#FFFFFF"

var familia_titulo_font = "Arial, Helvetica, sans-serif"
var tamano_combo_font = 8
var tamano_titulo_font=2
var fondo_global="#E7BC14"
var letra_global="#000000"

var Month_Label = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
var Day_Label = new Array('L','M','X','J','V','S','D')

var tipo_borde=' border="1" bordercolorlight="#FFFDF7" bordercolordark="#D1A806" '
/****************************************
**
**	Fin del area de configuración
**
*****************************************/
var Current_Date = new Date();
var Current_Month = Current_Date.getMonth();

var Days_in_Month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

var Current_Year = Current_Date.getYear();
if (Current_Year < 1000)
	Current_Year+=1900

var Selected_Month = Current_Month + 1
var Selected_Year = Current_Year


var Today = Current_Date.getDate();


var contenidoDiv =''
var tagTable = '<table cellspacing="1" cellpadding="2" bgcolor="' + fondo_atras +'" ' + (!ns4?tipo_borde:'border=1') + ' width="' + ancho_calendario + '" ' + (!ns4?'style="background-color:' + fondo_atras + ';width:' + ancho_calendario + '"':'') + '>'

var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

// resize fix for ns4
var origWidth, origHeight;
if (ns4) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

// Be sure to set tipWidth wide enough for widest image
var offX= - xMenos;	// how far from mouse to show tip
var offY= - yMenos; 

// preload images that are to appear in tooltip
// from arrays above
if (document.images) {
//	var imagenes= new Array('/comunes/images/close.gif');
	var imagenes= new Array();
	var theImgs = new Array();
	for (var i=0; i<imagenes.length; i++) {
 		theImgs[i] = new Image();
		theImgs[i].src = imagenes[i];
  }
}

////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip. 
//		Set styles for all but ns4. 
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
var tipFollowMouse= false;	


//window.onload = initTip;

/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes 
//			it to tipDiv
/////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
var asignar_valor=null;

var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}


/****************************************
**
**	Metodos validados
**
*****************************************/
var ppcTI=false;
var ocultar = null;
var estado_select = 0;

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop - yMenos;
	}
	// tooltip width and height
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
	else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
	else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function GetObj(nombre)
{
	return ((ns4)? null: (ie4)? document.all[nombre]: (ie5||ns5)? document.getElementById(nombre): null);
}

function ListaSeleccionada(valor)
{
	estado_select = valor;
}

function hideTip() 
{	
	ocultar = tipcss;
	t2=setTimeout("ocultar.visibility = 'hidden'",100);
	tipOn = false;
	ppcTI = false;
	estado_select=0
	asignar_valor=null	
}

function Ocultar()
{
	ppcTI=setTimeout('hideTip()',500);
}

function NoOcultar()
{
	if(ppcTI)
	{
		clearTimeout(ppcTI);
		ppcTI=false;
	}
}

function mostrar_calendario(evt,objeto,nombreDiv, nombreFrame) 
{
	ppcTI=false;
	estado_select = 0;
	if (nodyn) return;
	tooltip = GetObj(nombreDiv);
	if (!tooltip) return;
	if (tipcss!=null)
	{
		tipcss.visibility = 'hidden';
	}
	tipcss = (ns4)? null: tooltip.style;
	if (tooltip&&tipFollowMouse) {
		if (ns4) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = trackMouse;
	}
	asignar_valor = GetObj(objeto);
	window.frames[nombreFrame].setFecha(asignar_valor.value);
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='inherit'",100);	
}

function setValor(dia,mes,anno)
{
	valor = (dia<10?'0':'') + dia + '/' + (mes<10?'0':'') + mes + '/' + anno;
	asignar_valor.value = valor;
	hideTip();
}
