// JavaScript Document
var urlAnterior;
//informacionLogin.cogerHtml('peticionesOperador.php',2,'usuario='+document.getElementById('usuario').value+'&password='+document.getElementById('password').value;
																																				 
function sumarPorcentajes(nombre)
{
	
	var valor1=document.formNuevoAnuncio.porcentajeCargo.value;	
	var valor2=document.formNuevoAnuncio.porcentajeExperiencia.value;	
	var valor3=document.formNuevoAnuncio.porcentajeEspecializacion.value;	
	var valor4=document.formNuevoAnuncio.porcentajeCiudad.value;	
	var valor5=document.formNuevoAnuncio.porcentajeNivel.value;	
	
	var suma=parseInt(valor1)+parseInt(valor2)+parseInt(valor3)+parseInt(valor4)+parseInt(valor5);
	
	if(suma>100)
	{
		suma=suma-100;
		valor=document.getElementById(nombre).value;
		suma=parseInt(valor)-suma;
		document.getElementById(nombre).value=suma;
		alert("Por favor reduzca los porcentajes y luego vuelva a introducir el actual, los valores no deben sobrepasar el 100%.");
	}
	

}
																																				 
																																				 
function cambiarCalificacion(idCandidato)
{
	var nuevaCalificacion = prompt ("Cambiar calificación");
	if(nuevaCalificacion!=null)
	{
		
		objetoCalificacion.cogerHtml('../enlaceOperaciones/enlaceOperacionesAdmin.inc.php',2,'id_operacion=278&idCandidato='+idCandidato+'&nuevaCalificacion='+nuevaCalificacion); return false;
		
		
		
	}
}																																				 

function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
	{
        if(ctrl[i].checked)
		{
			return ctrl[i].value;
		}
	}
}

function validarRadios(ctrl)
{
	var devolvio=0;
    for(i=0;i<ctrl.length;i++)
	{
        if(ctrl[i].checked)
		{
			return true;
			devolvio=1;
			alert('Valor escogido= '+ctrl[i].checked);
		}
	}
	if (devolvio==0)
	{
		alert("Escoja una opción");
		return false;
	}
}

function validarOpcionRadio(mensaje, ctrl)
{
	var devolvio=0;
    for(i=0;i<ctrl.length;i++)
	{
        if(ctrl[i].checked)
		{
			return true;
			devolvio=1;
			alert('Valor escogido= '+ctrl[i].checked);
		}
	}
	if (devolvio==0)
	{
		alert(mensaje);
		return false;
	}
}


function devolverDatosFormularioLogin()
{
	var datosFormLogin='id_operacion=1&usuario='+document.getElementById('usuario').value+'&password='+document.getElementById('password').value;	
	return datosFormLogin;
}
//formulario login landin page 2.0
function devolverDatosFormularioLoginAnuncio()
{
	var datosFormLogin='id_operacion=1.1&usuario='+document.getElementById('usuario').value+'&password='+document.getElementById('password').value+'&idAnuncio='+document.getElementById('idAnuncio').value;	
	return datosFormLogin;
}

var urlAnteriorBarraSuperior;
function cambiarImagenes(urlImagen,objeto)
{
	urlAnterior=objeto.src;
	objeto.src=urlImagen;
}

function restaurarImagenes(objeto)
{
	objeto.src=urlAnterior;
}


function prenderBoton(urlPrender,objetoPrender, urlApagar, objetoApagar)
{
	urlAnteriorBarraSuperior=objetoPrender.src;
	objetoPrender.src=urlPrender;
	objetoApagar.src=urlApagar;
}


function barraAnunciosHome(objetoEncendido)
{
	
	switch (objetoEncendido)
	{
		case 1:
			document.getElementById('ultimasDestacadas').src='../imagenes_sitio/boton_ultimas_destacadas.jpg';
			document.getElementById('ofertasIndustria').src='../imagenes_sitio/boton_ofertas_industrias_off.jpg';
			document.getElementById('ofertasCiudad').src='../imagenes_sitio/boton_ofertas_ciudad_off.jpg';
			document.getElementById('ofertasCargo').src='../imagenes_sitio/boton_ofertas_cargo_off.jpg';
		break;
		
		case 2:
			document.getElementById('ultimasDestacadas').src='../imagenes_sitio/boton_ultimas_destacadas_off.jpg';
			document.getElementById('ofertasIndustria').src='../imagenes_sitio/boton_ofertas_industrias.jpg';
			document.getElementById('ofertasCiudad').src='../imagenes_sitio/boton_ofertas_ciudad_off.jpg';
			document.getElementById('ofertasCargo').src='../imagenes_sitio/boton_ofertas_cargo_off.jpg';
		break;
		
		case 3:
			document.getElementById('ultimasDestacadas').src='../imagenes_sitio/boton_ultimas_destacadas_off.jpg';
			document.getElementById('ofertasIndustria').src='../imagenes_sitio/boton_ofertas_industrias_off.jpg';
			document.getElementById('ofertasCiudad').src='../imagenes_sitio/boton_ofertas_ciudad.jpg';
			document.getElementById('ofertasCargo').src='../imagenes_sitio/boton_ofertas_cargo_off.jpg';
		break;
		
		case 4:
			document.getElementById('ultimasDestacadas').src='../imagenes_sitio/boton_ultimas_destacadas_off.jpg';
			document.getElementById('ofertasIndustria').src='../imagenes_sitio/boton_ofertas_industrias_off.jpg';
			document.getElementById('ofertasCiudad').src='../imagenes_sitio/boton_ofertas_ciudad_off.jpg';
			document.getElementById('ofertasCargo').src='../imagenes_sitio/boton_ofertas_cargo.jpg';
		break;
	}
}
//FUNCION PARA LA CARGA DE IMAGENES
function resultadoUpload(estado, contenidoRespuesta, idDondeInsertar) {

	if (estado == 0)
	{
		var mensaje = contenidoRespuesta;
		document.getElementById(idDondeInsertar).innerHTML=mensaje;
	}
	
	if (estado == 1)
	{
		alert('Error ! - El Archivo no llego al servdor');
	}
	if (estado == 2)
	{
		alert('Error ! - El tipo de archivo que intenta subir es incorrecto');
	}
	if (estado == 3)
	{
		alert('Error ! - No se pudo copiar Archivo. Posible problema de permisos en server');
	}

} 


//FUNCION PARA LA CARGA DE NUMEROS ENVIO MASIVO SMS
function resultadoUpload2(estado) 
{

	if (estado == 0)
	{
		//alert('El archivo se ha subido correctamente');
	}
	
	if (estado == 1)
	{
		alert('Error ! - El Archivo no llego al servdor');
	}
	if (estado == 2)
	{
		alert('Error ! - El tipo de archivo que intenta subir es incorrecto');
	}
	if (estado == 3)
	{
		alert('Error ! - No se pudo copiar Archivo. Posible problema de permisos en server');
	}

} 


//CONTROLAR SOLO NUMEROS EN LA CAJA DE TEXTO
function validarSoloNumeros(e)
{
	tecla_codigo = (document.all) ? e.keyCode : e.which;
	patron =/[0-9\b]/;
	tecla_valor = String.fromCharCode(tecla_codigo);
	return patron.test(tecla_valor);
}

//FUNCIONES PARA SIMULAR TRIM
function ltrim(s) {
   return s.replace(/^\s+/, "");
}

function rtrim(s) {
   return s.replace(/\s+$/, "");
}

function trim(s) {
   return rtrim(ltrim(s));
}
//FIN FUNCIONES PARA SIMULAR TRIM

/*function validarSubdominio(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) 
	{
		return true; // 3
	}
	//alert(tecla);
	if(tecla==109)
	{
		return false;
	}
	else
	{
    patron =/\w/; // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
	}
	
}*/

function validarSubdominio(elEvento, permitidos)
{
// Variables que definen los caracteres permitidos
	tecla = (document.all) ? elEvento.keyCode : elEvento.which; // 2
    if (tecla==8) 
	{
		return true; // 3
	}
	
	var numeros ="0123456789";
	var caracteres ="abcdefghijklmnopqrstuvwxyz-";
	var numeros_caracteres = numeros + caracteres;
	// Seleccionar los caracteres a partir del parámetro de la función
	switch(permitidos)
	{
		case'num':permitidos = numeros;
		break;
		
		case'car':permitidos = caracteres;
		break;
		
		case'num_car':permitidos = numeros_caracteres;
		break;
	}
	// Obtener la tecla pulsada
	var evento = elEvento || window.event;
	var codigoCaracter = evento.charCode|| evento.keyCode;
	var caracter = String.fromCharCode(codigoCaracter);
	// Comprobar si la tecla pulsada se encuentra en los caracteres permitidos
	return permitidos.indexOf(caracter)!=-1;
}

function validarFormEncuestaSalarial()
{
	return validarOpcionRadio("Escoja una opción para la primera pregunta", document.formEncuestaSalarial.p1);
	
	if(document.formEncuestaSalarial.p2.value==0)
	{
		
	}
}

function comprobarCajaNumerica(caja)
{
	if(caja.value=="")
	{
		caja.value=0;
	}
}

