function getHTTPObject() {
    var xmlhttp;
    if(window.ActiveXObject){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    else{
        if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest()
        }
    }
    return(xmlhttp);
}

function enviarInscripcion(){
	var movil = document.getElementById('movil');
	if(movil.value != ''){
		movil.className = 'validate-mobile';
	}
	else{
		movil.className = '';
	}
	valid.validate();
}

function tildarOpcion(campo){
	var campo_r = document.getElementById('r_'+campo);
	var campo_v = document.getElementById('v_'+campo);
	if(campo_r.checked){
		campo_v.checked = true;
	}
}

function destildarOpcion(campo){
	var campo_r = document.getElementById('r_'+campo);
	var campo_v = document.getElementById('v_'+campo);
	if(!campo_v.checked){
		campo_r.checked = false;
	}
}

function licenciaFederado(check){
	var div = document.getElementById('licencia_federado');
	var field = document.getElementById('num_licencia');
	if(check.checked){
		div.style.visibility = 'visible';
		field.className = 'required';
	}
	else{
		div.style.visibility = 'hidden';
		field.className = '';
	}
}

function eliminarInscripcion(id){
	if(confirm('Seguro desea eliminar la inscripción permanentemente?')){
		location.href = 'operacion.php?eliminar_inscripcion&id='+id;
	}
}

function cargarOtro(value){
	var div = document.getElementById('otro_club');
	var field = document.getElementById('nombre_club');
	if(value == 1000){
		div.style.visibility = 'visible';
		field.className = 'required';
	}
	else{
		div.style.visibility = 'hidden';
		field.className = '';
	}
}

function verListadoAdmin(){
	var div = document.getElementById('id_competencia');
	location.href = 'ver_inscriptos.php?id='+div.value;
}

function importarInscriptos(){
	var div = document.getElementById('id_competencia');
	location.href = 'importar_inscriptos.php?id='+div.value;
}

function importarResultados(){
	var div = document.getElementById('id_competencia');
	location.href = 'importar_resultados.php?id='+div.value;
}

function borrarResultados(competencia){
	if(confirm('Realmente desea borrar todos los resultados para la competencia?\n(Esta acción no se podrá deshacer)')){
		location.href = 'operacion.php?borrar_resultados&id='+competencia;
	}
}

function buscarPorCriterio(){
	var f = document.getElementById('buscar_inscripciones');
	var nombre = document.getElementById('nombre');
	var club = document.getElementById('club');
	valid2.reset();
	if(f.criterio[0].checked){
		nombre.className = 'required';
		club.className = '';
	}
	else{
		nombre.className = '';
		club.className = 'validate-selection';
	}
	valid2.validate();
}

function cambiarInputNombre(val){
	var nombre = document.getElementById('nombre');
	var club = document.getElementById('club');
	if(val){
		club.disabled = true;
		nombre.disabled = false;
	}
	else{
		club.disabled = false;
		nombre.disabled = true;
	}
	valid2.reset();
}

function cambiarInputClub(val){
	var nombre = document.getElementById('nombre');
	var club = document.getElementById('club');
	if(val){
		club.disabled = false;
		nombre.disabled = true;
	}
	else{
		club.disabled = true;
		nombre.disabled = false;
	}
	valid2.reset();
}

function volver(){
	history.back();
}

function cambiarPrecioNo(){
	var div = document.getElementById('tipo_precio');
	var input = document.getElementById('precio');
	var input2 = document.getElementById('cuenta');
	div.style.visibility = 'hidden';
	input.className = '';
	input2.className = '';
}

function cambiarPrecioSi(){
	var div = document.getElementById('tipo_precio');
	var input = document.getElementById('precio');
	var input2 = document.getElementById('cuenta');
	div.style.visibility = 'visible';
	input.className = 'validate-currency-dollar';
	input2.className = 'required';
}

function agregarCategoria(){
	var tabla = document.getElementById('theTable');
	var form = document.getElementById('categoria');
	var num = tabla.rows.length;
	var fila = tabla.insertRow(num);
	var c0 = fila.insertCell(0);
	var c1 = fila.insertCell(1);
	var c2 = fila.insertCell(2);
	var c3 = fila.insertCell(3);
	var c4 = fila.insertCell(4);
	c0.className = 'center';
	c1.className = 'center';
	c2.className = 'center';
	c3.className = 'center';
	c4.className = 'center';
	c0.innerHTML = form.nombre.value;
	c1.innerHTML = form.codigo.value;
	c2.innerHTML = form.edad_inicio.value+'-'+form.edad_fin.value;
	if(form.sexo[0].checked){
		c3.innerHTML = 'Masculino';
	}
	else{
		c3.innerHTML = 'Femenino';
	}
	c4.innerHTML = '<a href="javascript:eliminarCategoria(\''+form.codigo.value+'\');">Eliminar</a>';
	form.nombre.value = '';
	form.codigo.value = '';
	form.edad_inicio.value = '';
	form.edad_fin.value = '';
	form.sexo[0].checked = false;
	form.sexo[1].checked = false;
}

function eliminarCategoria(cod){
	var tabla = document.getElementById('theTable');
	var num = -1;
	for(var c=1; c<tabla.rows.length; c++){
		if(tabla.rows[c].cells[1].innerHTML == cod){
			num = c;
		}
	}
	tabla.deleteRow(num);
}

function rellenarCategorias(){
	var tabla = document.getElementById('theTable');
	if(tabla.rows.length == 0){
		alert('Ingrese al menos una categoría para la competencia.');
		return(false);
	}
	var form = document.getElementById('form_categorias');
	var campo = form.categorias;
	campo.value = '';
	for(var c=1; c<tabla.rows.length; c++){
		campo.value = campo.value + tabla.rows[c].cells[0].innerHTML + '||' + tabla.rows[c].cells[1].innerHTML + '||' + tabla.rows[c].cells[2].innerHTML + '||' + tabla.rows[c].cells[3].innerHTML + '@@'
	}
	return(true);
}

function altaClub(){
	var a = document.getElementById('alta_club');
	var club = document.getElementById('nombre_club');
	a.href = 'alta_club.php?n=' + club.value;
}

function borrarInscriptosPendientes(){
	if(confirm('Realmente desea borrar todos las inscripciones pendientes de la competencia?\n(Esta acción no se podrá deshacer)')){
		var div = document.getElementById('id_competencia');
		location.href = 'operacion.php?borrar_inscriptos_pendientes&id='+div.value;
	}
}

function eliminarCompetenciaCompleta(id){
	if(confirm('ATENCIÓN:\nRealmente desea eliminar la competencia y todo lo relacionado a esta?\n(Esta acción no se podrá deshacer)')){
		location.href = 'operacion.php?eliminar_competencia&id='+id;
	}
}

function verDiploma(competencia,resultado){
	img = new Image();
	img.src = 'dep_res/img_'+competencia+'.jpg';
	w = img.width + 20;
	h = img.height + 55;
	ventana = window.open('ver_diploma.php?id='+resultado,'Diploma','toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h);
}

function cerrarVentana(){
	window.close();
}

function guardarResultados(){
	if(valid.validate()){
		var form = document.getElementById('guardar_res');
		form.submit();
	}
}

function descargarResultadosPDF(){
	if(valid.validate()){
		var div = document.getElementById('id');
		location.href = 'desc_resultados.php?id='+div.value;
	}
}

function descargarResultadosPDFDe(id){
	location.href = 'desc_resultados.php?id='+id;
}

function validarGuardarConfig(){
	var f = document.getElementById('config');
	var clave = document.getElementById('clave');
	var clave2 = document.getElementById('clave2');
	valid.reset();
	if(f.clave.value == ''){
		clave.className = '';
		clave2.className = '';
	}
	else{
		clave.className = 'validate-password';
		clave2.className = 'validate-password-confirm';
	}
	valid.validate();
}

function verMastercardSecureCode(){
	var param = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=470,top=50,left=50';
	window.open('include/mastercardsecurecode.html','Mastercard_SecureCode',param);
}

function verVisaSecureCode(){
	var param = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=470,height=375,top=50,left=50';
	window.open('include/visasecurecode.html','Mastercard_SecureCode',param);
}
