function createCalendar (input_id, button_id) {
	if(Calendar)
		Calendar.setup({
			inputField     :    input_id,      // id of the input field
			ifFormat       :    "%d/%m/%Y",       // format of the input field
			showsTime      :    false,            // will display a time selector
			button         :    button_id,   // trigger for the calendar (button ID)
			singleClick    :    false,           // double-click mode
			step           :    1                // show all years in drop-down boxes (instead of every other year as default)
		});
}

function createTimeCalendar (input_id, button_id) {
	if(Calendar)
		Calendar.setup({
			inputField     :    input_id,      // id of the input field
			ifFormat       :    "%d/%m/%Y %H:%M",       // format of the input field
			showsTime      :    true,            // will display a time selector
			button         :    button_id,   // trigger for the calendar (button ID)
			singleClick    :    false,           // double-click mode
			step           :    1                // show all years in drop-down boxes (instead of every other year as default)
		});
}

function confirmarAccion (msg) {
	if(!msg) {
		msg = "¿Está seguro que quiere seguir con esta acción?";		
	}
	var respuesta = confirm(msg);	
	if(respuesta)
		return true;
	else
		return false;
}
/* Rechazar la tecla ENTER */
function noEnterKey () {
	alert (!(window.event && window.event.keyCode == 13));
	return !(window.event && window.event.keyCode == 13);
}

function setFocus(id) {
	var el = document.getElementById(id);
	el.focus();
}

var winpopup=false;

function openpop(wpop,width,height,scrollbars)
{
	if(scrollbars!="YES")
		scrollbars == "NO";
	//winpopup = 
	window.open(wpop,'popup','left='+((screen.width-width)/2)+',top='+((screen.height-height)/2)+',width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scrollbars+',resizable=0');
	//winpopup.onunload = function () {winpopup = false;};
}

function showHideDiv(id) {
	var thediv = document.getElementById(id);
	if (thediv.style.display=="none" || thediv.style.display=="")
		thediv.style.display="block";
	else
		thediv.style.display="none";
}

function cambiaDiv(valor,id) {
	var thediv = document.getElementById(id);
	if (valor)
		thediv.style.display="block";
	else
		thediv.style.display="none";
}


function checkAll (checksname, value) {
	var checks = document.getElementsByName(checksname);
	var ncheks = checks.length;
	for(i=0;i<ncheks;i++) {
		checks[i].checked = value;
	}
}

function showinfo(info) {
	//alert(info);
	var frame = document.getElementById('val_info');
	if(info =='') info='Pasa con el raton sobre las casillas para ver la info.';
	frame.innerHTML = info;
	
}

function showinfo_(id,info) {
	//alert(info);
	var frame = document.getElementById(id);
	if(info =='') info='Pasa con el raton sobre las casillas para ver la info.';
	frame.innerHTML = info;
	
}
	

function readonly() {
	var fields = document.getElementsByTagName('input');
	for(i=0;i<fields.length;i++) {
		if( (fields[i].type=='submit') || (fields[i].type=='radio')
				|| (fields[i].type=='checkbox')) {
			fields[i].disabled = true;	
		}
		else
			fields[i].readOnly = true;
	}
	fields = document.getElementsByTagName('textarea');
	for(i=0;i<fields.length;i++) {
		fields[i].readOnly = true;
	}
	fields = document.getElementsByTagName('select');
	for(i=0;i<fields.length;i++) {
		fields[i].disabled = true;
	}
	fields = document.getElementsByTagName('button');
	for(i=0;i<fields.length;i++) {
		fields[i].disabled = true;	
	}			
}


function getXMLHttp () {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function diffDate (fini, ffin) {
	
	/* Hay que restarle que restar 1 al mes, ya que javascript empieza la cuenta
	   de los meses desde 0, y si no, se lia (al comparar las fechas 1/1 y 31/2,
       x ejemplo).
	   http://www.elguruprogramador.com.ar/foros/mensaje.asp?id=485           */
	
	var fIni = fini.split('/');
	fIni[1] = fIni[1] -1;
	var fFin = ffin.split('/');
	fFin[1] = fFin[1] -1;
		
	var iFecha = new Date(fIni[1],fIni[0],fIni[2]);
	var fFecha = new Date(fFin[1],fFin[0],fFin[2]);
	
	// var dias = Math.abs(Math.round((fFecha-iFecha)/86400000));
	// return dias;

	var dd=(Math.round((Date.parse(fFecha)-Date.parse(iFecha))/(24*60*60*1000))*1)
	return dd;
}

/* Necesario tener en el formulario orden y direccion */
function ordenar(campo,dir, idBoton, idOrden, idDireccion) {
	/* Campos no obligatorios se rellenan con valores */
	if(!idBoton) idBoton = "busca";
	if(!idOrden) idOrden = "orden";
	if(!idDireccion) idDireccion = "direccion";
	
	var inputOrden = document.getElementById(idOrden);
	var direccion = document.getElementById(idDireccion);
	var botonEnviar = document.getElementById(idBoton);
	
	direccion.value = dir;
	inputOrden.value = campo;
	botonEnviar.click();
}


// Si en COmo conociste esta actividad se selecciona Otros, muestra el campo Indicar. Si no lo oculta
function cambiarConocerActividad (objSelect) {

	if (objSelect.options[objSelect.selectedIndex].value == 'Otros') {
		document.getElementById('conocer-otros1').style.visibility = "visible";
		document.getElementById('conocer-otros2').style.visibility = "visible";
	} else {
		document.getElementById('conocer-otros1').style.visibility = "hidden";
		document.getElementById('conocer-otros2').style.visibility = "hidden";
	}
	
}


// Si en titulacion Otros, muestra el campo Especificar. Si no lo oculta
function cambiarTitulacion (objSelect) {

	if (objSelect.options[objSelect.selectedIndex].value == 'Otros') {
		document.getElementById('titulacion-otros').style.visibility = "visible";
	} else {
		document.getElementById('titulacion-otros').style.visibility = "hidden";
	}
	
}
