/**redimensiona las imagenes conservando la proporcion, se llama en el evento onload del img*/
function guardaPedido(ruta, id){
	var rutaEnvio = ruta+"?id="+id;
	alert(ruta);
	ajax=objetoAjax();
	ajax.open("GET", rutaEnvio,true);
	ajax.onreadystatechange=function() {
	if (ajax.readyState==1){
		//divContenido.innerHTML= '';
	}
	else if (ajax.readyState==4) {
			if(ajax.status==200){
				if(ajax.responseText == "1"){
					alert("Pedido generado correctamente.");
				}
				else{
					alert(ajax.responseText);
				}
			}
			else{
				alert("Error guardando pedido.");
			}
		}
	}
	ajax.send(null);



}
function reDim(contenedor, maxAncho, maxAlto, id){
		//alert("redimensionando " + contenedor.name + "id : " + id );

		var paisa_ini = contenedor.width / contenedor.height;
		var paisa_fin = maxAncho / maxAlto;
		var k = 1;
		if(paisa_fin > paisa_ini){
			k = maxAlto / contenedor.height;
		}
		else{
			k = maxAncho / contenedor.width;
		}
		nuevoAlto = k * contenedor.height;
		nuevoAncho = k * contenedor.width;

		contenedor.width = nuevoAncho;
		contenedor.height = nuevoAlto;

		document.getElementById(id).style.display = "block";

		//contenedor.style.visibility = "visible";
		//document.getElementById("thumb").style.display = "block";
		//contenedor.style.display = "block";

}

function setLog(fld){
	document.getElementById(fld).focus();
}

function actualizaClase(obj){
	/*escondido = document.getElementById(obj);
	if(escondido.value == 0){
		escondido.value = "1";
		//alert(obj + " activado");
	}*/
}

//crea un objeto ajax
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;
}

//cargar ajax en la capa(id) que se le pasa
function enviaquery(id, archivo)
{
	divContenido = document.getElementById(id);

	if (divContenido){
		divContenido.style.display='block';
		ajax=objetoAjax();
		ajax.open("GET", archivo,true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==1){
			divContenido.innerHTML= '<div class=loader><ul><li><img src=img/loader.gif></li><li>Enviando datos......</li></ul></div>';
		}
		else if (ajax.readyState==4) {
				if(ajax.status==200){
					divContenido.innerHTML = ajax.responseText
				}
			}
		}
		ajax.send(null);
	}
}

// solo valores numéricos
function num(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));

    if (charCode > 31 && (charCode < 44 || charCode > 57)) {
        alert("Por favor, introduzca valores numéricos."); //se puede quitar
        return false;
    }
    return true;
}
