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 = "        • Seleccione una opción del campo "+nombrecampo+"."+"\n";
			}
		}
	} else if (tipocampo=="fckeditor"){
		if (imprescindible=="si"){
			if (FCKeditorAPI.GetInstance(idnombrecampo).GetXHTML()==""){
				error = "        • El campo "+nombrecampo+" es imprescindible."+"\n";
			}
		}
	}
	return error;
}
// 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 ftabindex(donde){
	if (donde =="artistas"){
		index = new Array ('nombre', 'web', 'descripcion' , 'descripcion_i')
			for (k=0;k<index.length;k++){

				document.getElementById(index[k]).tabIndex =k+1
			}
	}
}
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 fpreguntas_experto_nutricion(datos, id){
	randomnumber=Math.floor(Math.random()*9999999999)
	divResultado = document.getElementById(id);
	divResultado.style.display = 'block';
	divResultado.innerHTML = "<div style='padding-left:180px;padding-top:100px'>Cargando datos...</div>";
	ajax=objetoAjax();
	ajax.open("GET", datos+"&rand="+randomnumber, true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			cadena=unescape(ajax.responseText);
			cadenafinal=cadena.replace(/\+/gi," ");
			
			divResultado.innerHTML = cadenafinal
		}
	}
	ajax.send(null)
}


function fdesayuno(){
	document.getElementById("no_desayuno").checked=false 
}

function fnodesayuno(){
	for (k=0;k<14;k++){
		document.getElementById("alimento"+k).checked=false
	}
	for (k=0;k<9;k++){
		document.getElementById("bebida"+k).checked=false
	}
	document.getElementById("otros").value=""
}
// olvido de login y pass


function flogin(donde){
	document.getElementById("form_login").action =donde;
	document.form_login.submit();
}




function replace_login_pass(obj,cual){
	var newO=document.createElement('input');
	if (cual=="password_plan" || cual=="password"){
		newO.setAttribute('type','password');
	}
	newO.setAttribute('name',obj.getAttribute('name'));
	newO.setAttribute('id',obj.getAttribute('id'));
	obj.parentNode.replaceChild(newO,obj);
	newO.focus();
 	setTimeout('document.getElementById("'+cual+'").focus()', 200)
}




<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->


function fimprimir(php,id,descarga){
	randomnumber=Math.floor(Math.random()*9999999999)
	ajax=objetoAjax();
	ajax.open("GET", php+"?id="+id, true);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) {
			
			document.getElementById("operaciones").src = 'imprimir_sk.php?file='+descarga+id+'.pdf&tipo=imprime_sk&rand='+id;		
			
		}
	}
	ajax.send(null)
}



