function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function fvalidaformularios(idnombrecampo, nombrecampo, tipocampo, imprescindible){
	error=""
	if (tipocampo=="email"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        - El campo "+nombrecampo+" es imprescindible."+"\n";
			}else if (document.getElementById(idnombrecampo).value.indexOf ("@")==-1 || document.getElementById(idnombrecampo).value.indexOf (".")==-1 || document.getElementById(idnombrecampo).value.indexOf (" ")!=-1){
				error = "        - El campo "+nombrecampo+" no contiene un email correcto."+"\n";
			}	
		}else if (document.getElementById(idnombrecampo).value!=""){ 
			if (document.getElementById(idnombrecampo).value.indexOf ("@")==-1 || document.getElementById(idnombrecampo).value.indexOf (".")==-1 || document.getElementById(idnombrecampo).value.indexOf (" ")!=-1){
				error = "        - El campo "+nombrecampo+" no contiene un email correcto."+"\n";
			}
		}
		
	} else if (tipocampo=="texto"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        - El campo "+nombrecampo+" es imprescindible."+"\n";
			}
		}
	} else if (tipocampo=="dni"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        - El campo "+nombrecampo+" es imprescindible."+"\n";
			}
		}else if (document.getElementById(idnombrecampo).value!=""){
			cadena="TRWAGMYFPDXBNJZSQVHLCKET";
			numeros = "1234567890"; 
			letrasynumeros = cadena+numeros
			atexto = document.getElementById(idnombrecampo).value.toUpperCase()
			atexto = atexto.split ("");
			for (k=0;k<atexto.length;k++){
				if (letrasynumeros.indexOf (atexto[k])==-1){
					error = "        - El campo "+nombrecampo+", no contiene un DNI-NIF valido."+"\n";
					error += "        no utilice simbolos como \"-\" ó \"espacio\""+"\r";
					error += "        ejemplo: 1234567L"+"\r";
					break
				}
			}
			if (error==""){
				numero = document.getElementById(idnombrecampo).value.substring (0,document.getElementById(idnombrecampo).value.length-1)
				posicion = numero % 23
	
				letra1 = cadena.substring(posicion,posicion+1).toUpperCase()
				letra2 = document.getElementById(idnombrecampo).value.substring ((document.getElementById(idnombrecampo).value.length)-1).toUpperCase()
				if (letra1 != letra2){
					error = "        - El campo "+nombrecampo+", no contiene un DNI-NIF valido."+"\n";
	
				}			
			}	
		}
	} else if (tipocampo=="combo"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==-1){
				error = "        - Selecciona una opcion del campo "+nombrecampo+"."+"\n";
			}
		}
	} else if (tipocampo=="ckeditor"){
		if (imprescindible=="si"){
		//	CKEDITOR.instances.descripcion1.getData()
			if (eval ("CKEDITOR.instances."+idnombrecampo).getData()==""){
				error = "        - El campo "+nombrecampo+" es imprescindible."+"\n";
			}
		}
	}
	return error;
}


function contar(form,name,result,cuantasLetras) {
  n = document.forms[form][name].value.length;
  t = cuantasLetras; 
  if (n > t) {
    document.forms[form][name].value = document.forms[form][name].value.substring(0, t);
  }
  else {
	  //alert (result)
	  document.getElementById(result).innerHTML="Caracteres restantes: "+(t-n)
   // document.forms[form][result].innerHTML = t-n;
  }
}

function copiaInput(form,name,result) {
  //document.forms[form][result].value=document.forms[form][name].value
}

// COMPROBAMOS QUE LOS CARACTERES DE CUALES CONTIENEN LOS CARACTERES
/*function fcompruebacioncaracteres (cuales, caracteres){
	acaracteres = caracteres.split ("");	
	acuales=cuales.split ("");	
		for (i=0;i<acuales.length;i++){
			z=0;
			for (k=0;k<acaracteres.length;k++){
				if (acuales[i]==acaracteres[k]){
						z=1;
						break
				}
			}	
			if (z==0){
				return false;
				break;		
			}
		}
	return true;
	
}*/
function focultofocus(){
	this.window.focus()
}
function fabrir(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=0'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// DEJA ESCRIBIR NADA MAS QUE CIERTOS CARACTERES EN VARIABLE PERMITIDO, SIN COMAS EJEMPLO "12345678990", SERIAN LOS NOMUMEROS PERMITIDOS
function caracteres_campo_permitidos(e,permitido) {
	
	apermitido=permitido.split("");
	
	tecla = (document.all) ? e.keyCode : e.which;

	x=0
	for (k=0;k<apermitido.length;k++){
		var chr = String.fromCharCode(tecla);
		
		if (chr==apermitido[k]){
			x=1;
			break;
		}
	}
	
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
	}else if (e) {
		keycode = e.which;
		if (keycode==8 || keycode==0){
			x=1;
		}
	}

  	if (x==0){
		return false	
	}else{
		return true	
	}
} 
 
 
function maxcaracteres (Object, MaxLen){
  return (Object.value.length < MaxLen);
}

// NO DEJA ESCRIBIR NADA MAS QUE CIERTOS CARACTERES EN VARIABLE NOPERMITIDO, SIN COMAS EJEMPLO "12345678990", SERIAN LOS NOMUMEROS NO PERMITIDOS
function caracteres_campo_nopermitidos(e,nopermitido) {
	apnopermitido=nopermitido.split("");
	tecla = (document.all) ? e.keyCode : e.which;
	//alert (e.keyCode);
	x=0
	for (k=0;k<apnopermitido.length;k++){
		var chr = String.fromCharCode(tecla);
		if (chr==apnopermitido[k]){
			x=1;
			break;
		}
	}
	if (e.keyCode==9){
		x=0;
	}
  	if (x==0){
		return true	
	}else{
		return false	
	}
} 


function fvisible(cual){
	document.getElementById(cual).style.display = 'block';	
}
function finvisible(cual){
	document.getElementById(cual).style.display = 'none';	
}
function HTMLEncode(wText){
if(typeof(wText)!="string"){
	wText=wText.toString();
}
	wText=wText.replace(/&/g, "@amp@") ;
	wText=wText.replace(/"/g, "@quot@") ;
	wText=wText.replace(/'/g, "@146@") ;
	wText=wText.replace(/[+]/g,'@mas@'); 
	return wText;
}
function HTMLdecode(wText){
if(typeof(wText)!="string"){
	wText=wText.toString();
}
	wText=wText.replace(/&amp;/g, "&") ;
	wText=wText.replace(/&quot;/g, "\"") ;
	wText=wText.replace(/&#039;/g, "'") ;
	//wText=wText.replace(/[+]/g,'@mas@'); 
	return wText;
}
PositionX = 590;
PositionY = 590;
var winl1 = (screen.width - PositionX) / 2;
var wint1 = (screen.height - PositionY) / 2;
defaultWidth  = PositionX
defaultHeight = PositionY;
PositionX = winl1;
PositionY = wint1;


//kinda important
var AutoClose = true;

function popImage(imageURL,imageTitle){
  var imgWin = window.open('','_blank','scrollbars=no,resizable=0,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
  if( !imgWin ) { return true; } //popup blockers should not cause errors
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
    'function resizeWinTo() {\n'+
    'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
    'var oH = document.images[0].height, oW = document.images[0].width;\n'+
    'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
    'window.doneAlready = true;\n'+ //for Safari and Opera
    'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
    'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
    'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
    'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
    'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
    'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
    'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
    'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
    'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
    'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
    '}\n'+
    '<\/script>'+
    '<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur=""':'')+'>'+
    (document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
    '<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
    (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
  imgWin.document.close();
  if( imgWin.focus ) { imgWin.focus(); }
  //return false;
}
//ampliar imagen//////////////////////////////////////////////////////////////////////////////////// desde aqui
// estos dos parametros son opcionales a la pagina que abrimos

/////////////////////////////////////////////////////////////////////////////////////////// hasta qui

function fiframe (elige){
	document.getElementById(elige).height =eval("window.frames."+elige+".document.body.scrollHeight");//alto
}


function noEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
	return false;
	} else {
	return true;
	} 
}

function maximaLongitudTextArea(texto,maxlong) {
  var tecla, in_value, out_value;
  if (texto.value.length > maxlong) {
    in_value = texto.value;
    out_value = in_value.substring(0,maxlong);
    texto.value = out_value;
    return false;
  }
  return true;
} 


function gridToList(idioma, categoria, opcion){
	
	ajax=objetoAjax();
	
	randomnumber=Math.floor(Math.random()*9999999999)
	
	ajax.open("GET", "trabajos_ajax.php?idioma="+idioma+"&categoria="+categoria+"&opcion="+opcion+"&rand="+randomnumber, true);	
	
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			cadena=unescape(ajax.responseText);
			//cadenafinal=cadena.replace(/\+/gi," ");
			//alert (cadena);
			document.getElementById("content").innerHTML=cadena
			debnAColor()
			
		}
    }
	ajax.send(null)
}

pulsados=new Array();
function Inicio(cual, opcion, iniciar){
	
	ajax=objetoAjax();
	
	randomnumber=Math.floor(Math.random()*9999999999)
	
	ajax.open("GET", "index_ajax.php?cual="+cual+"&opcion="+opcion+"&iniciar="+iniciar+"&rand="+randomnumber, true);	
	
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			cadena=unescape(ajax.responseText);
			cadenafinal=cadena.replace(/\+/gi," ");
			aidioma=cadena.split("/");
			if (aidioma[0]=="es"){
				document.getElementById("form_espanol").action =cadenafinal;
			}else if (aidioma[0]=="en"){
				document.getElementById("form_english").action =cadenafinal;
			}
			
			//document.getElementById("form_login_espaciok").action ="espaciok.php";
		}
    }
	ajax.send(null)
		
}

