// JavaScript Document

	


function permite(elEvento, permitidos, mensaje) 
	{
	  // Variables que definen los caracteres permitidos
	  var numeros = "0123456789";
	  var caracteres = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
	  var numeros_caracteres = numeros + caracteres;
	  var teclas_especiales = [8, 37, 39, 46];
	  // 8 = BackSpace, 46 = Supr, 37 = flecha izquierda, 39 = flecha derecha
	 
	 
	  // Seleccionar los caracteres a partir del parámetro de la función
	  switch(permitidos) {
		case 'num':
		  permitidos = numeros;
		  break;
		case 'car':
		  permitidos = caracteres;
		  break;
		case 'num_car':
		  permitidos = numeros_caracteres;
		  break;
	  }
	 
	  // Obtener la tecla pulsada 
	  var evento = elEvento || window.event;
	  var codigoCaracter = evento.charCode || evento.keyCode;
	  var caracter = String.fromCharCode(codigoCaracter);
	 
	  // Comprobar si la tecla pulsada es alguna de las teclas especiales
	  // (teclas de borrado y flechas horizontales)
	  var tecla_especial = false;
	  for(var i in teclas_especiales) {
		if(codigoCaracter == teclas_especiales[i]) {
		  tecla_especial = true;
		  break;
		}
	  }
	 
	  // Comprobar si la tecla pulsada se encuentra en los caracteres permitidos
	  // o si es una tecla especial
	  if(!(permitidos.indexOf(caracter) != -1 || tecla_especial))
	  {	
	  	document.getElementById(mensaje).style.display = "inline";
	  }
	  else
	  {
	  	document.getElementById(mensaje).style.display = "none";
	  }
	  
	  return permitidos.indexOf(caracter) != -1 || tecla_especial;
	  
	}	
	
function focusCT(valordefecto,id){
    var q = document.getElementById(id);
    q.style.color = '#000';
	q.style.textAlign = 'left';
	q.style.fontStyle = 'normal';
    if(q.value == valordefecto) q.value = '';
};
function blurCT(valordefecto,id){
    var q2 = document.getElementById(id);
    if(q2.value == ''){
		
        q2.style.color = '#999';
		q2.style.textAlign = 'center';
		q2.style.fontStyle = 'italic';
        q2.value = valordefecto;
    }
};

function nuevoAjax(){
	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 cargarContenidoget(){
	var t1, t2, contenedor;
	contenedor = document.getElementById('contenedor');
	t1 = document.getElementById('texto1').value;
	t2 = document.getElementById('texto2').value;
	ajax=nuevoAjax();
	ajax.open("GET", "funcion.php?t1="+t1+"&t2="+t2,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.send(null)
}
function cargarContenidopost(){
	var t1, t2, contenedor;
	contenedor = document.getElementById('contenedor');
	t1 = document.getElementById('texto1').value;
	t2 = document.getElementById('texto2').value;
	ajax=nuevoAjax();
	ajax.open("POST", "funcion.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("t1="+t1+"&t2="+t2);
}
function cargarformulariopost(form){
	var t1, t2, contenedor;
	contenedor = document.getElementById('contenedor');
	
	ajax=nuevoAjax();
	ajax.open("POST", "../php/actionregistrarpedido.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	var cadena=cadenaformulario(form);
	ajax.send(cadena);
}
 	function cadenaformulario(form)
	{	
		var res='';
		var tam=document.forms[form].elements.length;
		
		for(i=0; i<tam; i++)
		{
			var id=document.forms[form].elements[i].id;
			var valor = document.forms[form].elements[i].value;	
			if(i>0)
			{	
				res=res+"&"+id+"="+valor;					
			}
			else
			{
				res=res+id+"="+valor;
			}	
		}
		return res;
	}
function cargarformulariopostpedido(idcontenedor,pagina,form1,form2){
	var t1, t2, contenedor;
	contenedor = document.getElementById(idcontenedor);
	
	ajax=nuevoAjax();
	ajax.open("POST", pagina,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	var cadena=cadenaformulario(form1)+"&"+cadenaformulario(form2);
	ajax.send(cadena);
}	
	
	
	
function actualizarcontenedorporget(idcontenedor)
	{
		var t1, t2, contenedor;
		contenedor = document.getElementById(idcontenedor);
		t1 = document.getElementById('texto1').value;
		t2 = document.getElementById('texto2').value;
		ajax=nuevoAjax();
		ajax.open("GET", "funcion.php?t1="+t1+"&t2="+t2,true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
			}
		}
		ajax.send(null)
}
function confirmaraccion(mensaje,direccion) {
	pregunta = confirm(mensaje) ;
	if(pregunta) {
	//open('url','top=100,left=100,width=250,height=250') ;
	location.href=direccion;
	}
}

function desabilitarformulario(form)
	{	
		var tam=document.forms[form].elements.length;
		
		for(i=0; i<tam; i++)
		{			
			document.forms[form].elements[i].disabled=true;	
			
		}		
	}

