var xmlHttp;
var villaG = 1;
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function createXMLHttpRequest(){
	if (window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}
function calendario(mes, anio, villa){

	// alert(villa);
	document.getElementById('indicador').style.visibility = 'visible';

	var villa_hidden = document.getElementById("villa_hidden").value;

	if(villa == 0) {
		if (villa_hidden == 0){
			villaG = 1;
		} else {
			villaG = villa_hidden;
		}
	}


	if (form_calendar.villaSelect.value!=''){
	}
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handle_calendario;
		xmlHttp.open('GET', 'calendario.php?mes='+mes+'&anio='+anio+'&villa='+villaG, true);
		xmlHttp.send(null);


}
function handle_calendario(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			resultado_calendario();
		} else {alert("Error mientras se realizaba el proceso.");}
	}
}
function resultado_calendario(){
	var response = xmlHttp.responseText;
	if (response){
		document.getElementById('indicador').style.visibility = 'hidden';
		document.getElementById('contenedor').innerHTML = response;

	}
}
function select(mes, anio){
	var miselect = document.getElementById('villaSelect');
	
	id_select = miselect.value;
	nm_select = miselect.options[miselect.selectedIndex].text;

	document.getElementById('villaTitle').innerHTML = nm_select;

	if((nm_select!='') && (id_select!=0)) {
		villaG = id_select;
		calendario(mes,anio,id_select);
	}
	else{
		villaG = 0;
		calendario(mes,anio,0);

	}
}
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);

function onlyInteger(InputText, evt) {
		var charCode = (evt.which) ? evt.which : event.keyCode;
		var strValue = '';
		
		//Antes de que el Caracter sea agregado al Text, obtengo c�mo quedar�.
	  var selectionStart = getSelectionStart(InputText);
	  var selectionEnd = getSelectionEnd(InputText);
	  strValue = InputText.value.substring(0, selectionStart) + String.fromCharCode(charCode) + InputText.value.substring(selectionEnd);
		
		//El valor tiene que ser un n�mero decimal, o el ENTER, BACKSPACE, TAB, DELETE, etc
		if (!isInteger(strValue) && charCode > 31) {
			return false;
		}
		return true/*EnterToTab(InputText, evt)*/;
}
function getSelectionStart(input) {
	if (is_gecko)
		return input.selectionStart;
	var range = document.selection.createRange();
	var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0;
	if (!isCollapsed)
		range.collapse(true);
	var b = range.getBookmark();
	return b.charCodeAt(2) - 2;
}
function getSelectionEnd(input) {
	if (is_gecko)
		return input.selectionEnd;
	var range = document.selection.createRange();
	var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0;
	if (!isCollapsed)
		range.collapse(false);
	var b = range.getBookmark();
	return b.charCodeAt(2) - 2;
}
function isInteger(inputVal) {
		inputStr = inputVal.toString();
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.charAt(i);
			if (i == 0 && oneChar == "-") {
				continue;
			}
			if (oneChar < "0" || oneChar > "9") {
				return false;
			}
		}
		return true;
}
function verCard() {
	document.getElementById('tdx').style.visibility = 'visible';
}
