var isWorkingMostrar = false;
var isWorkingUpdate = false;
var isWorkingList = false;
var searchfor;
var seleccion='';
var tipoInicio='no';
var tipo='';

function searchBidding() {
 	// Obtener tituílo
	title = document.getElementById("search_name").value;
	// Obtener provincia
	state = document.getElementById("search_state").value;
		if(state==0){state="";}
	// Obtener categoria
	category = document.getElementById("search_category").value;
		if(category==0){category="";}
	// Obtener nivel de estudios
	educational = document.getElementById("search_educational").value;
		if(educational==0){educational="";}
	// Obtener nivel de experiencia
	experience = document.getElementById("search_experience").value;
		if(experience==0){experience="";}
	// Obtener tipo de contrato
	contract = document.getElementById("search_contract").value;
		if(contract==0){contract="";}
	// Obtener tipo de jornada laboral
	workday = document.getElementById("search_workday").value;
		if(workday==0){workday="";}
	// Obtener cantidad de salario
	wage = document.getElementById("search_wage_number").value;
		if(wage==0){wage="";}
	// Obtener tipo de salario
	wage_type = document.getElementById("search_wage").value;
		if(wage_type==0){wage_type="";}
	// Se manda la url
	$location = String(document.location);
	$location = replace($location,"http://","");
	$location=$location.split('/');
	
	$url = '/busqueda/' ;
	//Comprobamos que campos se van a mandar
	if(title != ''){
		$url=$url+"clave-"+title+"/";
	}
	if(state != ''){
		$url=$url+"provincia-"+state+"/";
	}
	if(category != ''){
		$url=$url+"categoria-"+category+"/";
	}
	if(educational != ''){
		$url=$url+"estudios-"+educational+"/";
	}
	if(experience != ''){
		$url=$url+"experiencia-"+experience+"/";
	}
	if(contract != ''){
		$url=$url+"contrato-"+contract+"/";
	}
	if(workday != ''){
		$url=$url+"jornada-"+workday+"/";
	}
	if(wage != ''){
		$url=$url+"salario-"+wage+"/";
	}
	if(wage_type != ''){
		$url=$url+"tipo_salario-"+wage_type+"/";
	}
	document.location=$url;

}
function searchJobseeker() {
 	
	// Obtener provincia
	sstate = document.getElementById("state").value;
		if(sstate==0){sstate="";}
	// Obtener categoria
	ccategory = document.getElementById("id_category").value;
		if(ccategory==0){ccategory="";}
	// Se manda la url
	$location = String(document.location);
	$location = replace($location,"http://","");
	$location=$location.split('/');
	
	$url = '/panel_de_control/empresas/listado_de_demandantes/busqueda/' ;
	//Comprobamos que campos se van a mandar
	if(ccategory != ''){
		$url=$url+"tipo_de_trabajo-"+ccategory+"/";
	}
	if(sstate != ''){
		$url=$url+"provincia-"+sstate+"/";
	}
	document.location=$url;

}
function busqueda_empresa(){
	// Obtener tituílo
	title = document.getElementById("buscar_nombre").value;
	if(title==0){
		title='';
	}
	sector = document.getElementById("buscar_sector").value;
	if(sector==0){
		sector='';
	}
	$location = String(document.location);
	$location = replace($location,"http://","");
	$location=$location.split('/');
	
	$url = '/directorio_empresas/' ;
	
	if(title != ''){
		$url=$url+"busqueda/nombre-"+title+"/";
		if(sector != ''){
			$url=$url+"sector-"+sector+"/";
		}
	}else{
		if(sector != ''){
			$url=$url+"busqueda/sector-"+sector+"/";
		}
	}
	
	document.location=$url;
}

function replace(texto, s1, s2) {
	return texto.split(s1).join(s2);
}

function handleHttpResponse() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
          	if(tipo=='inicio'){
				calendario_agenda1 = document.getElementById('calendario_1');
			
				if(calendario_agenda1 != null){
					calendario_agenda1.innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
				}
			}else{
				calendario_agenda2 = document.getElementById('calendario_2');
			
				if(calendario_agenda2 != null){
					calendario_agenda2.innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
				}
			}
            isWorking = false;
		}
    }
}
function calendarioInicio(fech){
	tipo='inicio';
    http = new XMLHttpRequest();
    //calendario_agenda.innerHTML = "";
    if (!isWorking && http)
    {
        if (!fech)
        {
            alert("Poner error publico");   
        }
        else
        {
         
        
            var url = "/inc/calendario.php?date="+fech+"&tipo=inicio";
            
            http.open("GET", url, true);
            http.onreadystatechange = handleHttpResponse;
           
            isWorking = true;
            http.send(null);
            
        }
   }
   
}
function calendarioFin(fech){
 	tipo='fin';
    http = new XMLHttpRequest();
    //calendario_agenda.innerHTML = "";
    if (!isWorking && http)
    {
        if (!fech)
        {
            alert("Poner error publico");   
        }
        else
        {
         
        
            var url = "/inc/calendario.php?date="+fech+"&tipo=fin";
            
            http.open("GET", url, true);
            http.onreadystatechange = handleHttpResponse;
           
            isWorking = true;
            http.send(null);
            
        }
   }
   
}
isWorking = false;
