var ancho=screen.width/2;
var alto=screen.height/2;
var me1;
var me0;
var car;
var IE = document.all?true:false;
var left;
var vA=null;
var barrasFT=Array();
var avatar_libre=false;
var cargandoDiv=null;
var cagandoIntervalo=null;
var ArchivosJS;
var ArchivosJS2;
var bannerActual=1;
var tO=Array();
var cloneIngrediente=null;
//tO["inicio_banner_frames"]=null;
function getPos(id){
	xx=0;yy=0;
	obj=document.getElementById(id);
	if(obj.offsetParent){
		xx=obj.offsetLeft;
		yy=obj.offsetTop;
		while(obj=obj.offsetParent){
			xx+=obj.offsetLeft;
			yy+=obj.offsetTop;
		}
	}
	r=new Array(xx,yy);
	return r;
}
function verificaEmail(correo){
	ret=true;
	var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
	var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	var reg1 = new RegExp(reg1str);
	var reg2 = new RegExp(reg2str);
	if (reg1.test(correo) || !reg2.test(correo)) ret=false;
	return ret;
}
function cuerpoHeight(){
	var ca=document.getElementById('cuerpo_admin');
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	myHeight = document.body.clientHeight;
	}
	ca.style.height=(myHeight-120)+"px";
	left=document.getElementById('papa').offsetLeft;
}
function Abre(archivo,w,h){
	window.open(archivo,"",'width='+w+',height='+h+',toolbar=no,menubar=no,resizable=yes,scrollbars=yes,location=no,left='+(ancho-w/2)+',top='+(alto-h/2));
}
function ajaxSEND(url,metodo,variables,f){
	http_request = false;
	if(window.XMLHttpRequest){
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	}else if(window.ActiveXObject){
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	if(!http_request){
		alert('Cannot create XMLHTTP instance');
		return false;
	}      
	http_request.onreadystatechange = function(){
		if(http_request.readyState == 4){
			if (http_request.status == 200) {
				f(http_request.responseText);
			}else{
				alert('There was a problem with the request.');
			}
		}
	}
	if(metodo=='GET'){
		http_request.open('GET', url, true);
		http_request.send('');
	}else{
		http_request.open('POST', url, true);
		//http_request.setCharacterEncoding("ISO-8859-1");
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", variables.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(variables);
	}
}
function parseScript(_source) {
	var source = _source;
	var scripts = new Array();
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);
		scripts.push(source.substring(s_e+1, e));
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	for(var i=0; i<scripts.length; i++) {
		try {
			alert(scripts[i]);
			eval(scripts[i]);
		}catch(ex) {
			alert(ex);
		}
	}
	return source;
}
function buscaCampana(val){
	try{
		clearTimeout(vA);
	}catch(e){}
	var div=document.getElementById('tablaCampanas');
	if(val.length>1){
		document.getElementById('campana').value=0;
		function f(){
			div.innerHTML="<div id='cargando'>cargando ...</div>";
			div.style.visibility='visible';
			div.style.display='block';
			function m(v){
				if(v.toString().indexOf('##VACIO##')>=0){
					div.style.visibility='hidden';
					div.style.display='none';
				}else div.innerHTML=v;
			}
			ajaxSEND("admin_cargacamps.php?txt="+val,"GET",'',m);
		}
		vA=setTimeout(f, 1000);
	}else{
		div.style.visibility='hidden';
		div.style.display='none';
	}
}
function editaInterno(v,t){
	var vars=v.split(",");
	for(var i in vars){
		var ini=vars[i].indexOf("=");
		var obj=vars[i].substr(0,ini);
		var val=vars[i].substr(ini+1);
		try{
			val=val.replace(/#coma#/g,",");
			document.getElementById(obj).value=val;
		}catch(e){
			alert(obj);
		}
	}
	document.getElementById('tituloPopup').innerHTML=t;
	var w=document.getElementById('popup');
	w.style.left=left+180+250;
	w.style.display='';
	var h=(w.offsetHeight)?w.offsetHeight:w.style.pixelHeight;
	w.style.top=(screen.availHeight-h-54)/2;
}
function cierraInterno(){
	document.getElementById('popup').style.display='none';
}
function eliminaInterno(id){
	if(confirm("Esta seguro que desea eliminar este valor")){
		document.getElementById('eliminaID').value=id;
		eliminaFORM.submit();
	}
}
function buscaCorreo(){
	var div=document.getElementById('resultado_busqueda_correo');
	div.innerHTML="<div id='cargando'><img src='images/cargando_16.gif' /> cargando ...</div>";
	var correo=document.getElementById('correo').value;
	function m(v){
		div.innerHTML="";
	}
	ajaxSEND("admin_correosbusca.php","POST","correo="+correo,m);
}
function cargaDetalle(id){
	var div=document.getElementById('estadisticasDetalle2');
	div.innerHTML="<div id='cargando'><img src='images/cargando_16.gif' /> cargando ...</div>";
	function m(v){
		var celda=document.getElementById("menuProductos");
		var rT=req.responseText;
		var fTtmp=rT.indexOf("fT=")+3;
		var fTtmp2=rT.indexOf(";",fTtmp);
		var fTt=rT.substr(fTtmp,fTtmp2-fTtmp);
		var fT=parseInt(fTt)*c;
		celda.innerHTML=req.responseText;
	}
	ajaxSEND("inicio_barra.php?tipo="+id,"GET","",m);
}
function muestraMapa(nom,lat,zoom){
	var src="http://maps.google.com/maps?q="+lat+"+("+nom+")&ie=UTF8&ll="+lat+"&spn=0.050351,0.06875&z="+zoom+"&iwloc=A&output=embed";
	var hre="http://maps.google.com/maps?q="+lat+"+("+nom+")&amp;ie=UTF8&amp;ll="+lat+"&amp;spn=0.050351,0.06875&amp;z="+zoom+"&amp;iwloc=A&amp;source=embed";
	document.getElementById('gmap_iframe').src=src;
	document.getElementById('gmap_a').href=hre;
	var gc=document.getElementById('gmap_container');
	gc.style.height=document.body.scrollHeight+"px";
	document.getElementById('gmap_todo').style.top=(document.body.offsetHeight/2-323)+"px";
	document.getElementById('gmap_todo').style.left=(document.body.offsetWidth/2-405)+"px";
	gc.style.display='';
	gc.style.visibility='visible';
	document.body.style.overflow='hidden';
}
function cierraMapa(){
	var gc=document.getElementById('gmap_container');
	gc.style.display='none';
	gc.style.visibility='hidden';
	document.body.style.overflow='scroll';
}
function cambiaPais(p,c){
	if(p==117){
		var celda=document.getElementById(c);
		function m(v){
			celda.innerHTML=v;
			try{document.getElementById('trDistritos').style.display='';}catch(e){};
		}
		celda.innerHTML="cargando ...";
		ajaxSEND("carga_ciudades.php?pais="+p,"GET","",m);
	}else{
		var tmp="<input name=\"ciudad\" type=\"text\" id=\"ciudad\" class=\"tdi3\" /><img src=\"images/asterisco.png\" width=\"16\" height=\"16\">";
		var celda=document.getElementById(c);
		celda.innerHTML=tmp;
		try{document.getElementById('trDistritos').style.display='none';}catch(e){};
	}
}
function cambiaDistrito(c){
	var celda=document.getElementById('distritoTD');
	if(c>0){
		function m(v){
			celda.innerHTML=v;
		}
		celda.innerHTML="cargando ...";
		ajaxSEND("carga_distritos.php?ciudad="+c,"GET","",m);
	}else{
		celda.innerHTML="Elegir una ciudad primero";
	}
}
function verificaAvatar(t){
	try{
		clearTimeout(vA);
	}catch(e){}
	if(t.length>=4){
		function f(){
			td=document.getElementById('avatarAlerta');
			td.innerHTML='&nbsp;&nbsp;verificando disponibilidad del avatar ...';
			function m(html){
				td.style.textAlign='left';
				if(html=='Este avatar est&aacute; libre'){
					avatar_libre=true;
				}else avatar_libre=false;
				td.innerHTML="&nbsp;&nbsp;&nbsp;"+html;
			}
			ajaxSEND("verificaavatar.php?t="+t,'GET','',m);
		}		
		vA=setTimeout(f, 500);
	}else{
		document.getElementById('avatarAlerta').innerHTML="&nbsp;&nbsp;El avatar debe de tener 4 o m&aacute;s letras";
	}
}
function muestraCargando(){
	var i=0;
	cargandoDiv=document.createElement("div");
	var d1=document.createElement("div");
	var d2=document.createElement("div");
	var img=document.createElement("img");
	//img.onclick=ocultaCargando;
	cargandoDiv.id="cargando";
	d1.id="cText";
	d2.id="cImg";
	d1.innerHTML="Cargando";
	d2.appendChild(img);
	cargandoDiv.appendChild(d1);
	cargandoDiv.appendChild(d2);
	document.body.appendChild(cargandoDiv);
	document.body.style.overflow='hidden';	
	function c(){
		if(i++>=4) i=1
		img.src="images/cargando"+i+".png";
	}
	cagandoIntervalo=setInterval(c,50);
}
function ocultaCargando(){
	if(cargandoDiv!=null) cargandoDiv.parentNode.removeChild(cargandoDiv);
	cargandoDiv=null;
	if(cagandoIntervalo!=null) clearInterval(cagandoIntervalo);
	cagandoIntervalo=null;
	document.body.style.overflow='scroll';
}

function verificaRegistro(){
	try{
	var r=true;
	var alerta='';
	var v=Array("nombre","apellidos","email","clave","clave2","ano","mes","dia","pais","ciudad","distrito","telefono","celular","avatar");
	var n=Array();
	for(i in v) try{n[v[i]]=document.getElementById(v[i]).value;}catch(e){};
	if(n['nombre'].length<=0 || n['apellidos'].length<=0) {r=false;alerta='El nombre o apellido ingresado no es válido\n';}
	if(!verificaEmail(n['email'])) {r=false;alerta+='El correo ingresado es invalido\n';}
	if(n['clave'].length<=4 || n['clave']!=n['clave2']) {r=false;alerta+='La clave es muy corta o no coincide la clave de verificacion\n';}
	if(n['ano']==0 || n['mes']==0 || n['dia']==0) {r=false;alerta+='La fecha de nacimiento es inválida\n';}
	if(n['pais']==0) {r=false;alerta+='Debe de elegir un pais\n';}
	if(Number(n['ciudad'])==0 && n['ciudad'].lenght<2) {r=false;alerta+='Debe de ingresar una ciudad valida\n';}
	if(n['telefono'].length<=4) {r=false;alerta+='Debe de ingresar un telefono valido\n';}
	if(avatar_libre==false) verificaAvatar(n['avatar']);
	if(avatar_libre==false || n['avatar'].length<4) {r=false;alerta+='Debe de ingresar un avatar de 4 más letras y que esté disponible\n';}
	if(!r) {
		alert(alerta);
		return false;
	}
	muestraCargando();
	function m(r){
		document.getElementById('cuerpoRegistro').innerHTML=r;
		ocultaCargando();
	}
	var vars="";
	for(i in v) vars+=v[i]+"="+encodeURIComponent(n[v[i]])+"&";
	ajaxSEND("registro_post.php","POST",vars,m);
	return r;
	}catch(e){alert(e.message); return false;}
}
function MuestraUpload(vi,vf){
	c=document.getElementById(vi);
	if(ArchivosJS==null) ArchivosJS=new MultiFiles(document.getElementById(vf));
	var new_element = document.createElement('input');
	new_element.type = 'file';
	new_element.className = 'Standard333-11px';
	new_element.style.width = '340px';
	new_element.style.display = 'block';
	c.appendChild(new_element);
	ArchivosJS.addElement(new_element);
}
function MuestraUpload2(vi,vf){
	c=document.getElementById(vi);
	if(ArchivosJS2==null) ArchivosJS2=new MultiFiles(document.getElementById(vf));
	var new_element = document.createElement('input');
	new_element.type = 'file';
	new_element.className = 'Standard333-11px';
	new_element.style.width = '340px';
	new_element.style.display = 'block';
	c.appendChild(new_element);
	ArchivosJS2.addElement(new_element);
}
function MultiFiles( list_target, max ){
	this.list_target = list_target;
	this.count = 0;
	this.id = 0;
	if( max ){
		this.max = max;
	} else {
		this.max = -1;
	};
	this.addElement = function( element ){
		if( element.tagName == 'INPUT' && element.type == 'file' ){
			element.name = 'imagen_' + this.id++;
			element.ArchivosJS = this;
			element.onchange = function(){
				this.ArchivosJS.addListRow( this );
				this.style.position = 'absolute';
				this.style.left = '-1000px';
			};
			if( this.max != -1 && this.count >= this.max ){
				element.disabled = true;
			};
			this.count++;
			this.current_element = element;

		} else {
			alert( 'Error: not a file input element' );
		};
	};
	this.addListRow = function( element ){
		var new_row = document.createElement( 'tr' );
		var new_cell1 = document.createElement( 'td' );
		var new_cell2 = document.createElement( 'td' );
		var new_cell3 = document.createElement( 'td' );
		var new_cell4 = document.createElement( 'td' );
		var new_row_button = document.createElement('input');
		new_row_button.type="image";
		new_row_button.src ="images/ico_del_24.png";
		new_row_button.style.width = '24px';
		new_row_button.style.height = '24px';
		var new_row_button2 = document.createElement( 'input' );
		new_row_button2.type = 'text';
		new_row_button2.value = 'descripcion';
		new_row_button2.name = 'desc_'+this.count;
		new_row_button2.style.width = '200px';
		new_row_button2.className = 'tdi3';
		new_cell1.element = element;
		new_cell2.style.color='#DDD';
		new_cell2.style.textAlign='left';
		new_row_button.onclick= function(){
			this.parentNode.parentNode.element.element.parentNode.removeChild( this.parentNode.parentNode.element.element);
			this.parentNode.parentNode.parentNode.removeChild( this.parentNode.parentNode );
			this.parentNode.parentNode.element.element.ArchivosJS.count--;
			this.parentNode.parentNode.element.element.ArchivosJS.current_element.disabled = false;
			return false;
		};
		img_cnt= this.count;
		if(img_cnt<10) img_cnt="0"+img_cnt;
		new_cell1.innerHTML = "Imagen "+img_cnt+": ";
		new_cell2.innerHTML = "..."+element.value.substr(element.value.lastIndexOf('\\'))+"&nbsp;";
		new_cell3.appendChild( new_row_button2 );
		new_cell4.appendChild( new_row_button );
		new_row.element=new_cell1;
		new_row.appendChild(new_cell1);new_row.appendChild(new_cell2);new_row.appendChild(new_cell3);new_row.appendChild(new_cell4);
		this.list_target.parentNode.insertBefore(new_row,this.list_target);
		//this.list_target.insertBefore( new_row,antes );
	};
}
function creaInput(nombre,tipo1,tipo2,valor,width,height,clase){
	var i=document.createElement(tipo1);
	i.name=nombre;
	i.id=nombre;
	if(tipo2.length>0) i.type=tipo2;
	if(valor.length>0) i.value=valor;
	if(width>0) i.style.width=width+"px";
	if(height>0) i.style.height=height+"px";
	if(clase.length>0) i.className=clase;
	return i;
}
function agregaComentario(id,seccion){
	if(document.getElementById('dummy')==null){
		try{
		var c=document.getElementById('detalle_contenedor_comentarios');
		var t=creaInput("comentarioIT","textarea","","Ingresar comentario",695,100,"tdi3");
		var s=creaInput("envia","input","submit","enviar",100,0,"tdi2");
		var l=creaInput("cancela","input","button","cancelar",100,0,"tdi2");
		var d=creaInput("detalle_comentario_boton","div","","",0,0,"");
		var e=creaInput("xxx","div","","",0,0,"");
		var x=creaInput("dummy","div","","",0,0,"detalle_comentario");
		t.onfocus=function(){
			if(this.value=='Ingresar comentario') this.value='';
		}
		t.onblur=function(){
			if(this.value=='') this.value="Ingresar comentario";
		}
		l.onclick=function(){
			c.removeChild(x);
		}
		s.onclick=function(){
			if(t.value=='Ingresar comentario' || t.value==''){
				alert("Debe de ingresar un comentario");
			}else{
				var comentario=encodeURIComponent(t.value);
				var vars="comentario="+comentario+"&id="+id+"&seccion="+seccion+"&papi=0";
				x.innerHTML='cargando...';
				function mm(rpta){
					var iio=rpta.indexOf(",");
					var iid=rpta.substr(0,iio)
					x.innerHTML=rpta.substr(iio+1);
					x.id=iid;
				}
				ajaxSEND("comentario_post.php","POST",vars,mm);
			}
		}
		d.appendChild(s);
		d.appendChild(l);
		e.appendChild(t);
		e.appendChild(d);
		x.appendChild(e);
		c.insertBefore(x,c.firstChild);
		}catch(e){alert(e.message); return false;}
	}
}
function respondeMensaje(id,aid,seccion,obj){
	if(document.getElementById('dummy')==null){
		try{
		var c1=obj.parentNode;
		var c=c1.parentNode;
		var t=creaInput("comentarioIT","textarea","","Ingresar comentario",c.clientWidth-44,100,"tdi3");
		var s=creaInput("envia","input","submit","enviar",100,0,"tdi2");
		var l=creaInput("cancela","input","button","cancelar",100,0,"tdi2");
		var d=creaInput("detalle_comentario_boton","div","","",0,0,"");
		var e=creaInput("xxx","div","","",0,0,"");
		//alert(c.clientWidth);
		var x=creaInput("dummy","div","","",0,0,"detalle_comentario");
		t.onfocus=function(){
			if(this.value=='Ingresar comentario') this.value='';
		}
		t.onblur=function(){
			if(this.value=='') this.value="Ingresar comentario";
		}
		l.onclick=function(){
			c.removeChild(x);
		}
		s.onclick=function(){
			if(t.value=='Ingresar comentario' || t.value==''){
				alert("Debe de ingresar un comentario");
			}else{
				var comentario=encodeURIComponent(t.value);
				var vars="comentario="+comentario+"&id="+aid+"&seccion="+seccion+"&papi="+id;
				x.innerHTML='cargando...';
				function mm(rpta){
					var iio=rpta.indexOf(",");
					var iid=rpta.substr(0,iio)
					x.innerHTML=rpta.substr(iio+1);
					x.id=iid;
				}
				ajaxSEND("comentario_post.php","POST",vars,mm);
			}
		}
		d.appendChild(s);
		d.appendChild(l);
		e.appendChild(t);
		e.appendChild(d);
		x.appendChild(e);
		//var ib=(c1.nextSibling!=null)?c1.nextSibling:null
		c.insertBefore(x,c1.nextSibling);
		}catch(e){alert(e.message); return false;}
	}
}
function recuerdaClave(c){
	if(verificaEmail(c)){
		muestraCargando();
		var vars="correo="+c;
		function mm(rpta){
			document.getElementById('cuerpoRegistro').innerHTML=rpta;
			ocultaCargando();
		}
		ajaxSEND("recordar_post.php","POST",vars,mm);
	}else{
		alert("El correo ingresado no es v\x1Elido");
	}
}
function muestraMI(id){
	if(id=='elige_mes') document.getElementById('elige_ano').style.display='none'; else document.getElementById('elige_mes').style.display='none'
	var pos=getPos('calendario_titulo');
	var h=document.getElementById('calendario_titulo').offsetHeight;
	var mes=document.getElementById(id);
	mes.style.top=(pos[1]+h)+"px";
	mes.style.left=(pos[0]+1)+"px";
	mes.style.display='';
}
function oculta(id){
	var t=document.getElementById(id);
	//t.style.visibility='hidden';
	t.style.display='none';
}
function cambiaFechaMI(m,a){
	var cal=document.getElementById('calendario');
	var vars="mes="+m+"&ano="+a;
	cal.innerHTML='cargando...';
	function mm(rpta){
		cal.innerHTML=rpta;
	}
	ajaxSEND("menui_cambia.php","POST",vars,mm);
}
function bannerCambia(d,i){
	if(tO['inicio_banner_frames']==null){
		if(d==0){
			d=bannerActual-i;
		}
		if(d!=0){
			bannerActual-=d;
			mueveEasing(d,'inicio_banner_frames',572);
		}
	}
}
function verificaLogin(){
	try{
	var r=true;
	var alerta='';
	var v=Array("usuario","clave");
	var n=Array();
	for(i in v) try{n[v[i]]=document.getElementById(v[i]).value;}catch(e){};
	if(!verificaEmail(n['usuario'])) {r=false;alerta='El usuario ingresado no es valido, el usuario es la cuenta de correo con la que se registro\n';}
	if(n['clave'].length<=4) {r=false;alerta+='La clave es muy corta o no es valida\n';}
	if(!r) {
		alert(alerta);
		return false;
	}
	return r;
	}catch(e){alert(e.message); return false;}
}
function muestraImagenes(seccion,id){
	var i=0;
	cargandoDiv=document.createElement("div");
	var d1=document.createElement("div");
	var d2=document.createElement("div");
	var img=document.createElement("img");
	//img.onclick=ocultaCargando;
	cargandoDiv.id="fotos_sombra";
	d1.id="cText";
	d2.id="cImg";
	d1.innerHTML="Cargando";
	d2.appendChild(img);
	cargandoDiv.appendChild(d1);
	cargandoDiv.appendChild(d2);
	document.body.style.overflow='hidden';
	document.body.appendChild(cargandoDiv);		
	function c(){
		if(i++>=4) i=1
		img.src="images/cargando"+i+".png";
	}
	var cagandoIntervalo=setInterval(c,50);	
	function mm(rpta){
		cargandoDiv.innerHTML=rpta;
		clearInterval(cagandoIntervalo);
		cagandoIntervalo=null;
		var img2=document.createElement("img");
		img2.src="images/cierra2.png";
		img2.style.position='absolute';
		img2.style.cursor='pointer';
		pos=getPos('fotos_grande');
		img2.style.top=(pos[1]-20)+"px";
		img2.style.left=(pos[0]+780)+"px";
		cargandoDiv.appendChild(img2);
		img2.onclick=ocultaImagenes;
	}
	ajaxSEND("carga_imagenes.php?seccion="+seccion+"&id="+id,"GET",'',mm);
}
function ocultaImagenes(){
	if(cargandoDiv!=null) cargandoDiv.parentNode.removeChild(cargandoDiv);
	cargandoDiv=null;
	if(cagandoIntervalo!=null) clearInterval(cagandoIntervalo);
	cagandoIntervalo=null;
	document.body.style.overflow='scroll';
}
function eliminaFoto(id){
	document.getElementById('elimina_fid').value=id;
	fef.submit();
}
function clonaIngredientes(){
	cloneIngrediente=document.getElementById('ing0').cloneNode(true);
}
function agregaIng(){
	var d=document.createElement("div");
	var t=creaInput("cant"+numeroIngredientes,"input","text","0",100,0,"tdi3");
	var e=creaInput("","input","button","elimina",70,0,"tdi3");
	var dummy=numeroIngredientes;
	e.onclick=function(){
		eliminaIng(dummy);
	}
	var con=document.getElementById('contenedorIngredientes');
	var ref=document.getElementById('agregaIngrediente');
	var nue=cloneIngrediente.cloneNode(true);
	nue.name='ing'+numeroIngredientes;
	nue.id='ing'+numeroIngredientes;
	nue.value=0;
	d.appendChild(nue);
	d.appendChild(t);
	d.appendChild(e);
	d.id='divIng'+numeroIngredientes;
	con.insertBefore(d,ref);
	numeroIngredientes++;
}
function eliminaIng(i){
	var c=document.getElementById('contenedorIngredientes');
	var e=document.getElementById('divIng'+i);
	c.removeChild(e);
}
function cambiaIng(t){
	var gc=document.getElementById('cargando');
	var id=t.name.substr(3);
	document.getElementById('nombreIng').value='';
	document.getElementById('significadoIng').value='';
	document.getElementById('idIng').value=id;
	if(t.value==100000){
		var st=scrollTop();
		gc.style.top=st+"px";
		gc.style.display='';
		gc.style.visibility='visible';
		document.body.style.overflow='hidden';
	}else{
		gc.style.display='none';
		gc.style.visibility='hidden';
		document.body.style.overflow='scroll';
	}
}
function enviaIngrediente(){
	var ni=document.getElementById('nombreIng').value;
	var si=document.getElementById('significadoIng').value;
	var id=document.getElementById('idIng').value;
	if(ni.length>0 && si.length>5){
		ni=encodeURIComponent(ni);
		si=encodeURIComponent(si);
		function m(v){
			document.getElementById("divIng"+id).innerHTML=v;
			var gc=document.getElementById('cargando');
			gc.style.display='none';
			gc.style.visibility='hidden';
			document.body.style.overflow='scroll';
		}
		ajaxSEND("ingrediente_post.php","POST","nombre="+ni+"&significado="+si+"&id="+id,m);
	}else{
		alert("Debes de ingresar el nombre y el significado del ingrediente");
	}
}
function cancelaIngrediente(){
	var gc=document.getElementById('cargando');
	gc.style.display='none';
	gc.style.visibility='hidden';
	document.body.style.overflow='scroll';
	try{
		var s=document.getElementById('ing'+document.getElementById('idIng').value).value=0;
	}catch(e){}
}
function scrollTop(){
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function muestraTour(id,ag,tm){
	function m(ih){
		document.getElementById("ata_dummy").innerHTML=ih;
		var v=document.getElementById('agencias_tours_agrega');
		var st=scrollTop();
		v.style.top=st+"px";
		v.style.display='';
		v.style.visibility='visible';
		document.body.style.overflow='hidden';
	}
	ajaxSEND("agencias_viaje_tours.php","POST","id="+id+"&agencia="+ag+"&tempid="+tm,m);
}
function eliminaFotoTour(fid,id){
	document.getElementById('elimina_tfid').value=fid;
	document.getElementById('tour_id').value=id;
	feft.submit();
}
function eliminaTour(id){
	document.getElementById('elimina_tid').value=id;
	fet.submit();
}
function insertaTour(n,id){
	try{
	var t=document.getElementById('admin_tours');
	var dummy=document.getElementById('lista_tours_dummy');
	var tr=document.createElement("tr");
	var td1=document.createElement("td");
	var td2=document.createElement("td");
	var td3=document.createElement("td");
	var b1=document.createElement("input");
	var b2=document.createElement("input");
	b1.type="button";
	b2.type="button";
	b1.className="tdi2c";
	b2.className="tdi2c";
	b1.value="Editar";
	b2.value="Eliminar";
	b1.onclick=function(){muestraTour(id);};
	b2.onclick=function(){eliminaTour(id);};
	td1.innerHTML=n;
	td2.appendChild(b1);
	td3.appendChild(b2);
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	//td1.className=td2.className=td2.className=
	dummy.parentNode.insertBefore(tr,dummy);
	ocultaTour();
	}catch(e){alert(e.message);}
}
function ocultaTour(){
	var v=document.getElementById('agencias_tours_agrega');
	v.style.display='none';
	v.style.visibility='hidden';
	document.getElementById("ata_dummy").innerHTML="";
	document.body.style.overflow='scroll';
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
