//Variables usadas en la detección del navegador
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

function abreVentana(direccion,alto,ancho){

    //var nombre="word.htm"; //Nombre de la página

    //var alto=280;    //El alto de tu ventana

    //var ancho=400; //El ancho de tu ventana

    var y=(screen.availHeight/2)-(alto/2);

    var x=(screen.availWidth/2)-(ancho/2);

	window.open(direccion, "_blank", "height="+alto+",width="+ancho+",top="+y+"px,left="+x+"px");
}

function guardoEtiqueta(selectLabel,selectField)
{
	//selectLabel.value= selectField[selectField.selectedIndex].text;
}

// Confirmar baja
function confirm_box(script_baja)
{
 var where_to= confirm(txt_varias1);
 if (where_to== true)
 {
   document.frmBaja.submit()
 }
 else
 {
    window.location=script_baja+".php";
    //window.location="baja_candidato.php";
  }
}

// Confirmar baja
function confirm_baja_candidato(texto, cond)
{
 var where_to= confirm(texto);
 if (where_to== true)
 {
   document.getElementById('bEnviar').value=cond;	
   document.frmBaja.submit()
 }
 else
 {
    window.location="modificar_cv.php";
 }
}


// Confirmar baja
function confirm_baja_empresa(texto, cond)
{
 var where_to= confirm(texto);
 if (where_to== true)
 {
   document.getElementById('bEnviar').value=cond;	
   document.frmBaja.submit()
 }
 else
 {
    window.location="modificar_datos_empresa.php";
 }
}


// Confirmar baja
function confirm_baja_empresa_back(texto, cond)
{
 var where_to= confirm(texto);
 if (where_to== true)
 {
   document.getElementById('bEnviar').value=cond;	
   document.frmBaja.submit()
 }
 else
 {
    window.location="back_baja_empresa.php";
 }
}

function confirm_baja_boletin()
{
 //var where_to= confirm("Esta seguro que desea darse de baja del boletín?");
 //if (where_to== true)
 //{
   document.frmBaja.submit()
 //}
 //else
 //{
  //window.location=script_baja+".php";
  //window.location="baja_boletin.php";
  //}
}


//para el ordenar
function setValorHidden(valor)
{
	var order = document.getElementById('sOrder').value = valor;	
	
	
}

	//para la pagina de creacion y modificacion de ofertas
	function borro(idObjeto) {
		oLI=document.getElementById(idObjeto);
		cant=oLI.childNodes.length;

		for(i=0;i<cant;i++)
		{
			sa=oLI.childNodes;
			obj=sa[cant-i-1]
			oLI.removeChild(obj);
		}

		document.getElementById('ul1').removeChild(oLI);
		oPC=document.getElementById("preguntasCandidatos");
		oOP=document.getElementById(idObjeto+'select');
		oPC.removeChild(oOP);
		//oLI.removeNode(true);

	}
	
	function guardaPreguntaValores(){
				
		var max_preguntas = 3;
		var num_preguntas = 0;
		var num_noexcluir = 0;
				
		for (i=0; i<document.getElementById('ul1').childNodes.length; i++){
			if (document.getElementById('ul1').childNodes[i].nodeName=="LI"){
				num_preguntas ++;
			}						
		}		
		
		if(num_preguntas >= max_preguntas){
			alert(txt_varias2);
			return;
		}
		if(document.getElementById('preguntaFiltrado').value!='') 
		{	
			var num_respuestas=0;
			for(i = 1 ; i <= 5 ; i++ )
			{
				if(document.getElementById('resp'+i).value != '')
				{
					num_respuestas++;
				}
				// Comprobamos si alguna es diferente de EXCLUIR
				if(document.getElementById('nota'+i).value != -1){
					num_noexcluir++;
				}
				
			}
			if(num_noexcluir >= 1){				
				
				if(num_respuestas>1){
					
					oLI=document.createElement('LI');
					oUL=document.getElementById('ul1');
					oUL.appendChild(oLI);
					fecha = new Date();
					oLI.id=fecha.getMinutes()+ fecha.getSeconds() + fecha.getMilliseconds();
					oLI.innerHTML=document.getElementById('preguntaFiltrado').value + "  <a href='javascript:borro("+ oLI.id +");'> "+txt_varias4+"</a>";
					oUL2=document.createElement('UL');
					oUL2.id="algo";
					oLI.appendChild(oUL2);
			
					oPC=document.getElementById("preguntasCandidatos");
					oOP=document.createElement('OPTION');
					oPC.appendChild(oOP);
					oOP.id=oLI.id + 'select';
					oOP.selected=true;
					oOP.text= document.getElementById("preguntaFiltrado").value + '|';
			
					for(i = 1 ; i <= 5 ; i++ )
					{
						if(document.getElementById('resp'+i).value != '')
						{
							oLI2=document.createElement('LI');
							oUL2.appendChild(oLI2);
		
							//para el UL
							oLI2.innerHTML = document.getElementById('resp'+i).value + ' (' + document.getElementById('nota'+i).value + ')';					
						
							//para el hidden
							if(i==1) {
								oOP.text=oOP.text + document.getElementById('resp'+i).value + '~' + document.getElementById('nota'+i).value;
							}
							else {
								oOP.text=oOP.text + ';' + document.getElementById('resp'+i).value  + '~' + document.getElementById('nota'+i).value;;						
							}	
						}
					}
					oOP.text= oOP.text + '###1';
					document.getElementById('preguntaAbierta').value='';
	            	document.getElementById('noPreguntas').style.display = 'none';
				}else{
					alert(txt_varias3);
				}
				
			}else{
				//alert('A la mierda!');
				alert(txt_varias5);
			}
			
		}
	} 
	
	function guardaPreguntatexto(){
		//if(navigator.appName && navigator.appName == "Microsoft Internet Explorer") max_preguntas = 3;
		//else max_preguntas = 4;

		var max_preguntas = 3;
		var num_preguntas = 0;		
				
		for (i=0; i<document.getElementById('ul1').childNodes.length; i++){
			if (document.getElementById('ul1').childNodes[i].nodeName=="LI"){
				num_preguntas ++;
			}						
		}		
		
		
		//alert("num_preguntas: " + num_preguntas);
		
		if(num_preguntas >= max_preguntas){
			alert(txt_varias2);
			return;
		}

		/*
		if(document.getElementById('ul1').childNodes.length >= max_preguntas){
			alert(txt_varias2);
			return;
		}*/

		if(document.getElementById('preguntaAbierta').value!='')
		{
			oLI=document.createElement('LI');
			oUL=document.getElementById('ul1');
			oUL.appendChild(oLI);
			fecha = new Date();
			oLI.id=fecha.getMinutes()+ fecha.getSeconds() + fecha.getMilliseconds();
			oLI.innerHTML=document.getElementById('preguntaAbierta').value + " <a href='javascript:borro("+ oLI.id +");'> " + txt_varias4 + "</a>";
			
			
			oPC=document.getElementById("preguntasCandidatos");
			oOP=document.createElement('OPTION');
			oPC.appendChild(oOP);
			oOP.id=oLI.id + 'select';
			oOP.selected=true;
			oOP.text=document.getElementById('preguntaAbierta').value;
			oOP.text= oOP.text + '###2';
			document.getElementById('preguntaAbierta').value='';
            document.getElementById('noPreguntas').style.display = 'none';
		}
	}


	function inrow (e)
	{
		e.style.cursor = "pointer";	 
		e.style.backgroundColor='';
		e.className='listado_over';		
	}
	
	function outrow(e, color)
	{
		e.style.cursor = "";	 
		e.style.backgroundColor=color;
	}	
	
	function posa_detall(nada)
	{ // nada.
	}
	
	function SetFocus()
	{
		if(document.frmBusqueda.busqueda != null)
			document.frmBusqueda.busqueda.focus();
	}	
	
	function checktextlength(x,y)
	{
		var detectIE = navigator.userAgent.toLowerCase().indexOf('msie') + 1;	
	
		if (detectIE)
			return (x.value.length<y);
	
	
		//Esto es para Firefox
		tempstr = x.value
		if(tempstr.length>y)
		{
			x.value = tempstr.substring(0,y);
		}
	}
	
	
	function maxtext(x,y)
	{
		tempstr = x.value
		if(tempstr.length>y)
		{
			x.value = tempstr.substring(0,y);
		}
	}	

	function checkIt(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}
	
	
	function getBrowser()
	{

		if (checkIt('konqueror'))
		{
			browser = "Konqueror";
			OS = "Linux";
		}
		else if (checkIt('safari')) browser = "Safari"
		else if (checkIt('omniweb')) browser = "OmniWeb"
		else if (checkIt('opera')) browser = "Opera"
		else if (checkIt('webtv')) browser = "WebTV";
		else if (checkIt('icab')) browser = "iCab"
		else if (checkIt('msie')) browser = "Internet Explorer"
		else if (!checkIt('compatible'))
		{
			browser = "Netscape Navigator"
			version = detect.charAt(8);
		}
		else browser = "An unknown browser";
		
		if (!version) version = detect.charAt(place + thestring.length);
		
		if (!OS)
		{
			if (checkIt('linux')) OS = "Linux";
			else if (checkIt('x11')) OS = "Unix";
			else if (checkIt('mac')) OS = "Mac"
			else if (checkIt('win')) OS = "Windows"
			else OS = "an unknown operating system";
		}
		
	}
	
	
	getBrowser(); 