function saluda(){
	alert("holaaaa");
}
function validarAcceso(formu){
	if(formu.user.value!="" && formu.pass.value!=""){
		return true;
	}else{
		alert("Todos los campos son obligatorios");
		return false;
	}
}

function verTipo(tipo){
	tipo=tipo.value;
	var capa=parent.document.getElementById("datosProfesionales");
	switch(tipo){
		case "": alert("ATENCION: Debe elegir una opcion");
			parent.document.getElementById("formaPago").style.visibility="hidden";		
			capa.innerHTML="";
			break;
			
		case "noavs":
			capa.innerHTML='<span class="rojo" style="font-size:14px">Datos Profesionales</span><table style="border:solid 1px #cccccc; padding:5px; line-height:22px" width="100%"><tr><td class="gris" width="33%">Puesto/Cargo que desempe&ntilde;a:</td><td><input type="text" name="cargo" size="35" /> <span class="rojo">*</span></td></tr><tr><td class="gris">Empresa:</td><td><input type="text" name="entidad" size="40" /><span class="rojo">*</span></td></tr><tr><td class="gris">Ciudad de Trabajo:</td><td><input type="text" name="ciudadTrabajo" /></td></tr></table>';
			parent.document.getElementById("formaPago").style.visibility="visible";
		break;
			
		case "avs": 
			capa.innerHTML='<span class="rojo" style="font-size:14px">Datos Profesionales</span><table style="border:solid 1px #cccccc; padding:5px; line-height:22px" width="100%"><tr><td class="gris" width="33%">Puesto/Cargo que desempe&ntilde;a:</td><td><input type="text" name="cargo" size="35" /> <span class="rojo">*</span></td></tr><tr><td class="gris">Empresa:</td><td><input type="text" name="entidad" size="40" /><span class="rojo">*</span></td></tr><tr><td class="gris">Ciudad de Trabajo:</td><td><input type="text" name="ciudadTrabajo" /></td></tr></table>';			
			parent.document.getElementById("formaPago").style.visibility="visible";
		break;
	}
	doAjax2(capa,'scripts/servicios.scr.php?funcion=setTipo','valor='+tipo+'','','post',0);		
	dameInfoPago();
}

function discapacidad(formu){
	valor=formu.discapacitado;
	if(valor[1].checked){
		formu.tipoDiscapacidad.disabled=false;
		return false;
	}
	if(valor[0].checked){
		formu.tipoDiscapacidad.disabled=true;
		formu.tipoDiscapacidad.value="";
		return false;
	}
}

function verDoctorado(formu){
	valor=formu.doctorado;
	if(valor[1].checked){
		formu.departamento.disabled=false;
		return false;
	}
	if(valor[0].checked){
		formu.departamento.disabled=true;
		formu.departamento.value="";
		return false;
	}
}

function validarInscripcion(formu){
	if((formu.nombre.value=="")||(formu.apellidos.value=="")||(formu.dni.value=="")||(formu.domicilio.value=="")||(formu.email.value=="")){
		alert("ATENCION: Hay DATOS PERSONALES obligatorios sin completar");

		return false;
	}
	if(formu.email.value.search(/^[A-Za-z][A-Za-z0-9._-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/)){
        alert("ATENCION: Formato de E-Mail no valido.");
        return false;
    }	
	if((formu.pais.value=="-1")||(formu.provincia.value=="-1")||(formu.localidad.value=="-1")){
		alert("ATENCION: PAIS, PROVINCIA y LOCALIDAD, son campos obligatorios");
		return false;
	}
	if(formu.tipo.value=="-1"){
		alert("ATENCION: Debe elegir un TIPO DE INSCRIPCION");
		return false;
	}
	switch(formu.tipo.value){
		case 'estudiante':
			if((formu.escuela.value=="")||(formu.titulacion.value=="")||(formu.cursoActual=="")){
				alert("ATENCION: Hay DATOS PROFESIONALES obligatorios sin completar");
				return false;
			}
			break;
		case 'profesional':
			if((formu.cargo.value=="")||(formu.entidad.value=="")){
				alert("ATENCION: Hay DATOS PROFESIONALES obligatorios sin completar");
				return false;
			}		
			break;
	}
	document.getElementById("cpfinformu").innerHTML="<img width='15' src='images/loading.gif'>";
	doAjax3('inscripciones/scripts/actividadesCompatibles.scr.php?dni='+formu.dni.value+'&idact='+formu.actividad.value+'&','','actividadesCompatibles_','get',0);
	
}

function actividadesCompatibles_(html){
	switch(html){
		case '--':
			document.fninscripcion.submit();
			break;
		case 'valido': 
			document.fninscripcion.submit();
			break;
		case 'repetida':
			alert("ERROR: Ya esta registrado/a en esta actividad");
			document.getElementById("cpfinformu").innerHTML="";			
			break;
		case 'incompatibles':
			alert("ERROR: Actividad incompatible con algunas de las que ya esta cursando");
			document.getElementById("cpfinformu").innerHTML="";
			break;
	}
}

function validaNacimiento(valor){
	fecha=valor.value;
	if(fecha!=""){
		if(fecha.length < 4){
			alert("ERROR: Formato erroneo.  ej: 1977"); 
			valor.value="";
			return false;
		}
		if((fecha>2000)||(fecha<1940)){
			alert("ERROR: Fecha fuera de rango");
			valor.value="";
			return false;
		}
		return true;
	}
}

function validaDni(valor) {
	dni=valor.value;
	if(dni!=""){
		numero = dni.substr(0,dni.length-1);
		let =dni.substr(dni.length-1,1);
		let=let.toUpperCase();
		
		numero = numero % 23;
		letra='TRWAGMYFPDXBNJZSQVHLCKET';
		letra=letra.substring(numero,numero+1);
		if (letra!=let){
			alert('ERROR: NIF erroneo. ej: 11222333A');
			valor.value="";
			return false;
		}else{
			numero=dni.substr(dni.lenght-1,8);
			valor.value=numero+""+let;
			var capa=parent.document.getElementById("dnivalido");
			capa.innerHTML="<img style='vertical-align:middle' src='images/loading21.gif'>";
			doAjax2(capa,'scripts/servicios.scr.php?funcion=dni','valor='+valor.value+'','dniDuplicado','post',0);		
		}
	}
}

function dniDuplicado(html){
	var capa=document.getElementById("dnivalido");
	if(html=="0"){
		capa.innerHTML=arreglaTexto("<span style='font-size:12px'>ERROR: DNI ya registrado</span>");
		var formu=parent.document.getElementById("finscripcion");
		formu.dni.value="";
		
	}
	if(html=="1"){
		document.getElementById("dnivalido").innerHTML="";
	}
	document.getElementById("dnivalido").innerHTML="*";	
}

function wopen(url, name, w, h)
{
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
function wopen2(url, name, w, h)
{
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}

function saludar(){
	alert("hola");
}

function dameProvincias(idpais){
	document.getElementById("cploading1").innerHTML="<img width='15' src='images/loading.gif'>";
	doAjax3('inscripciones/scripts/dameProvincias.scr.php','idpais='+idpais.value+'','dameProvincias_','post',0);
}
function dameProvincias_(html){
	var inner = html; 
	cargaINNER(document.getElementById("provincias"),inner);	
	document.getElementById("cploading1").innerHTML="";	
}

function dameMunicipios(idprovincia){	
	document.getElementById("cploading2").innerHTML="<img width='15' src='images/loading.gif'>";
	doAjax3('inscripciones/scripts/dameProvincias.scr.php','idprovincia='+idprovincia.value+'','dameMunicipios_','post',0);
}
function dameMunicipios_(html){
	document.getElementById("cploading2").innerHTML="";	
	var inner = html; 
	cargaINNER(document.getElementById("localidades"),inner);	
}

function cargaINNER(objeto,innerHTML){
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');	
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

function abrirVentana (pagina) {
	var opciones="toolbar=no, Location=false, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=600, height=400, top=85, left=140";
	window.open(pagina,"",opciones);
}

function dameInfoActividad(valor){
	var capa=parent.document.getElementById("infoActividad");	
	capa.innerHTML="<img src='images/loading.gif' />";
	doAjax2(capa,'scripts/servicios.scr.php?funcion=infoActividad','valor='+valor.value+'','dameInfoActividad_','post',0);
}
function dameInfoActividad_(html){
	var capa=parent.document.getElementById("infoActividad");
	capa.innerHTML=html;
	dameInfoPago();
}

function dameInfoPago(){
	var capa=parent.document.getElementById("infoPago");
	capa.innerHTML="<img src='images/loading.gif' />";
	doAjax2(capa,'scripts/servicios.scr.php?funcion=infoPago','valor=1','dameInfoPago_','post',0);	
}

function dameInfoPago_(html){
	var capa=parent.document.getElementById("infoPago");
	capa.innerHTML=html;		
}

function subedocumento(value, campo){
	valor=value.value;
	extension = (valor.substring(valor.lastIndexOf("."))).toLowerCase(); 

	if((extension!=".jpg")&&(extension!=".pdf")&&(extension!=".doc")&&(extension!=".docx")){
		alert("Formato erroneo. Solo se adminten archivos doc, docx, jpg y pdf");
	}else{
		document.getElementById("loading").innerHTML="subiendo "+campo+" <img src='images/loading.gif' />";
		document.getElementById("docum").action="scripts/subedocumentos.scr.php?t="+campo+"";
		document.getElementById("docum").submit();
	}
}
function resultadoUpload(estado, tipo, nfinal, tamanio) {
	var capa=document.getElementById("loading");
	var capa2=document.getElementById(tipo);
	
	if (estado == 0){
		var mensaje = 'Documento subido correctamente.';
	}
	if (estado == 1)
		var mensaje = 'Error 1 ! - El Archivo no llego al servidor';
	if (estado == 2)
		var mensaje = 'Error 2 ! - Formato Erroneo.';
	if (estado == 3)
		var mensaje = 'Error 3 ! - No se pudo copiar Archivo.';
		
	capa.innerHTML="";
	capa2.innerHTML=" ...subido correctamente...";			
}

function setActividadSeleccionada(id){
	var capa=parent.document.getElementById("loadingpagos");
	capa.innerHTML="<img src='images/loading.gif' />";
	doAjax2(capa,'scripts/servicios.scr.php?funcion=setActividadSeleccionada','valor='+id+'','setActividadSeleccionada_','post',0);	
}
function setActividadSeleccionada_(html){
	oculta.location.href='menu.php?op=99';			
}
