var color='#D5517D'
var blanco='#FFFFFF'
function colorReset (field){
	field.style.backgroundColor = blanco;
}
// JScript source code
// Calendario
//Jul 06, 2006 www.internetxp.com.mx

var months = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array("D", "L", "M", "Mi", "J", "V", "S");

today = new getToday();	
var element_id;

function getDays(month, year) 
{
	// Test for leap year when February is selected.
	if (1 == month)
		return ((0 == year % 4) && (0 != (year % 100))) ||
			(0 == year % 400) ? 29 : 28;
	else
		return daysInMonth[month];
}

function getToday()
{
	// Generate today's date.
	this.now = new Date();
	this.year = this.now.getFullYear() ; // Returned year XXXX
	this.month = this.now.getMonth();
	this.day = this.now.getDate();
}

 
function newCalendar() 
{
	var parseYear = parseInt(document.all.year  [document.all.year.selectedIndex].text);
 	var newCal = new Date(parseYear , document.all.month.selectedIndex, 1);
	var day = -1;
	var startDay = newCal.getDay();
	var daily = 0; 

	today = new getToday(); // 1st call
	if ((today.year == newCal.getFullYear() ) &&   (today.month == newCal.getMonth()))
	   day = today.day;
	// Cache the calendar table's tBody section, dayList.
	var tableCal = document.all.calendar.tBodies.dayList;

	var intDaysInMonth =
	   getDays(newCal.getMonth(), newCal.getFullYear() );

	for (var intWeek = 0; intWeek < tableCal.rows.length;  intWeek++)
		   for (var intDay = 0;
			 intDay < tableCal.rows[intWeek].cells.length;
			 intDay++)
	 {
		  var cell = tableCal.rows[intWeek].cells[intDay];

		  // Start counting days.
		  if ((intDay == startDay) && (0 == daily))
			 daily = 1;

		  // Highlight the current day.
		  cell.style.color = (day == daily) ? "red" : "";
		  if(day == daily)
		  {
				//document.all.todayday.innerText= "Hoy: " +  day + "/" + (newCal.getMonth()+1) + "/" + newCal.getFullYear() ;
				document.all.todayday.innerText= "Hoy: " +  newCal.getFullYear()+" - "+(newCal.getMonth()+1)+" - "+day;
				
		  }
		  // Output the day number into the cell.
		  if ((daily > 0) && (daily <= intDaysInMonth))
			 cell.innerText = daily++;
		  else
			 cell.innerText = "";
	   }

}
	  
	 function getTodayDay()
	 {
			    //document.all[element_id].value = today.day + "/" + (today.month+1) + "/" + today.year;
			    //........
			    document.all[element_id].value = today.year + "-" + (today.month+1) + "-" + today.day; 
		        //document.all.calendar.style.visibility="hidden";
				document.all.calendar.style.display="none";
				document.all.year.selectedIndex =100;   
	            document.all.month.selectedIndex = today.month; 
	 }
 
        function getDate() 
		 {
            // This code executes when the user clicks on a day
            // in the calendar.
            if ("TD" == event.srcElement.tagName)
               // Test whether day is valid.
               if ("" != event.srcElement.innerText)
			   { 
				 var Year = document.all.year [document.all.year.selectedIndex].text;
    			 var mn = document.all.month.selectedIndex+1;

				 document.all[element_id].value=Year+"-"+ mn +"-"+event.srcElement.innerText;

				 document.all.calendar.style.display="none";
			 }
		 }
 
function GetBodyOffsetX(el_name, shift)
{
	var x;
	var y;
	x = 0;
	y = 0;

	var elem = document.all[el_name];
	do 
	{
		x += elem.offsetLeft;
		y += elem.offsetTop;
		if (elem.tagName == "BODY")
			break;
		elem = elem.offsetParent; 
	} while  (1 > 0);

	shift[0] = x;
	shift[1] = y;
	return  x;
}	

function SetCalendarOnElement(el_name,equis,ye)
{
	if (el_name=="") 
	el_name = element_id;
	var shift = new Array(2);
	GetBodyOffsetX(el_name, shift);
	document.all.calendar.style.pixelLeft  = shift[0] + equis; //  - document.all.calendar.offsetLeft;
	document.all.calendar.style.pixelTop = shift[1] + ye ;
}
	  
 	  
	           
function ShowCalendar(elem_name,equis,ye)
{
		if (elem_name=="")
		elem_name = element_id;

		element_id	= elem_name; // element_id is global variable
		newCalendar();
		SetCalendarOnElement(element_id,equis,ye);
		//document.all.calendar.style.visibility = "visible";
		document.all.calendar.style.display="inline";
}

function HideCalendar()
{
	//document.all.calendar.style.visibility="hidden";
	document.all.calendar.style.display="none";
}

function toggleCalendar(elem_name,equis,ye)
{

	//if (document.all.calendar.style.visibility == "hidden")
	if(document.all.calendar.style.display=="none")
		ShowCalendar(elem_name,equis,ye);
	else 
		HideCalendar();
}


function monthsToDocument(){
		//-- Month combo box 
		// Output months into the document.
		// Select current month.
		for (var intLoop = 0; intLoop < months.length; intLoop++) 
		document.write("<OPTION " +	(today.month == intLoop ? "Selected" : "") + ">" + months[intLoop]);
}

function yearsToDocument(){
		//-- Year combo box
		// Output years into the document.
		// Select current year.
		for (var intLoop = 2006; intLoop < 2015; intLoop++)
		document.write("<OPTION " + (today.year == intLoop ? "Selected" : "") + ">" + intLoop);
}

function columnDays(){
		//-- Generate column for each day. 
		for (var intLoop = 0; intLoop < days.length; intLoop++)
		document.write("<TD align=center><FONT face=arial size=1>" +"<b>"+ days[intLoop]+"</b>" + "</TD>");
}


function grid(){
		//-- Generate grid for individual days.
		for (var intWeeks = 0; intWeeks < 6; intWeeks++)
		{
			//document.write("<FONT face=arial size=1>");
			document.write("<TR>");
			
		for (var intDays = 0; intDays < days.length; intDays++)
			document.write("<TD align=center style='font-size: 10; font-family: arial;'></TD>");
			document.write("</TR>");
		}
}
//fin del calendario


// numeros.js
function isNumberInput(field, event)
{
	var key, keyChar;
	if (window.event)
		key = window.event.keyCode;
	else if (event)
		key = event.which;
	else
		return true;

	// Check for special characters like backspace
	if (key == null || key == 0 || key == 8 || key == 13 || key == 27 || key==45)
		return true;
	// Check to see if it's a number
	keyChar = String.fromCharCode(key);
	if (/\d/.test(keyChar))
	{
		window.status = "";
		return true;
	}
	else
{
	window.status = "Este campo sólo acepta números.";
	return false;
}
}

// fin de los numeros





function colorField(field){
	field.style.backgroundColor = '#9BC1F0';
}



// para cambiar el focus al otro elemento
function fNext(field, next){
	if (field.value.length == 4){
		next.focus();
	}	
}


/*****************************************************************
**		VALIDACION DINAMICA GENERAL
**		Esta función recibe 3 parámetros;
**		el primer parámetro debe ser el nombre de la forma como string,
**		el segundo parámetro es el número de radio´s.
**
**		El arreglo de los radio's se llama busqueda[]
**		El arreglo de los elementos de llama elemId
**		
**		Los elementos de la forma deben tener como id=e0,e1...en
**
**		Esta función va en el tag de body
**		onload="return validar('nombreForma',x);"
**		y en cada tag de cada radio
**		onclick="return validar('nombreForma',x);"
**		donde x es el numero de elementos
**
**		Nota: Solo en el tag de form lleva el 3er parámetro
**		onsubmit="return validar('nombreForma',x,true);"
******************************************************************/
function validar(recibeForma, totElem, alerta){
	var flag = true;
	var forma = document.forms[recibeForma];
	var elemId = new Array();
	for (var i = 0; i <= totElem; i++){
		elemId[i] = 'e'+i;						//e1,e2...en es el numero de elementos de la forma
		elem = elemId[i];
		forma.elements[elem].disabled = true;
		forma.elements[elem].style.backgroundColor = blanco;
		if (forma.busqueda[i].checked){			//busqueda es el arreglo de radio's
			forma.elements[elem].disabled = false;
			if (forma.elements[elem].value == ""){
				if (alerta == true){
					forma.elements[elem].style.backgroundColor = color;
					alert ('Faltan campos por capturar');
					flag = false;
					return flag;
				}				
			}
		}
	}
	return flag;
}

/*****************************************************************
**		VALIDACION DINAMICA GENERAL VACIOS
**		
**		Esta función recibe 2 parámetros;
**		el primer parámetro debe ser el nombre de la forma como string,
**		el segundo parámetro es el número de elementos que queremos
**		validar que no sean vaciós,
**		estos elementos deben tener como id=e0, e1...en
**		solo los elementos que no pueden ser nulos reciben el id
**		si un elemento puede ser nulo no se le pone id
**
**		Esta función va dentro del tag de la forma 
**		onsubmit="return noVacios('nombreForma',x);"
**		donde x es el numero de elementos
******************************************************************/
function noVacios(recibeForma, totElem){
	var flag = true;
	var forma = document.forms[recibeForma];
	var elemId = new Array();
	for (var i = 0; i <= totElem; i++){
		elemId[i] = 'e'+i;
		elem = elemId[i];
		//alert (forma.elements[elem].value);
		if (forma.elements[elem].value == ""){
			forma.elements[elem].style.backgroundColor = color;
			flag = false;
		}
	}
	if (flag == false){
		alert ('Faltan campos por capturar');
	}
	return flag;	
}
//fin noVacios

function Optin(recibeForma, totElem){
	var flag = true;
	var forma = document.forms[recibeForma];
	var elemId = new Array();
	for (var i = 0; i <= totElem; i++){
		elemId[i] = 'e'+i;
		elem = elemId[i];
		//alert (forma.elements[elem].value);
		if (forma.elements[elem].value == ""){
			forma.elements[elem].style.backgroundColor = color;
			flag = false;
		}
	}
	if (flag == false){
		alert ('Faltan campos por capturar');
	}
	return flag;	
}
//fin Optin