function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.form1s.length;i++) x=d.form1s[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ampliar_img(img,y){
var x       = 980;
LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
TopPosition =  0;
var _properties = new String("width=" + x + ",height=" + y + ",scrollbars=yes,menubar=no,statusbar=yes,status=no,location=no,toolbar=no,history=no,resizable=no,screenX=0,screenY=0,top="+TopPosition+",left="+LeftPosition);
window.open("ampliar_img.php?img="+img,'',_properties);	
}

function ampliar_gal(img,y){
var x       = 980;
LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
TopPosition =  0;
var _properties = new String("width=" + x + ",height=" + y + ",scrollbars=yes,menubar=no,statusbar=yes,status=no,location=no,toolbar=no,history=no,resizable=no,screenX=0,screenY=0,top="+TopPosition+",left="+LeftPosition);
window.open("ampliar_gal.php?img="+img,'',_properties);	
}

<!--
var nav4 = window.Event ? true : false;
function acceptNum(evt){	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
var key = nav4 ? evt.which : evt.keyCode;	
return (key <= 13 || (key >= 48 && key <= 57));
}
//-->




var form = "form1";
var submitted = false;
var error = false;
var error_message = "";

function validar_input(field_name, field_size, message) {
	
	for(d=0; d<form.elements; d++){
    	if(form.elements[d].name == field_name) {
			if (form.elements[d] && (form.elements[d].type != "hidden")) {
				var field_value = form.elements[d].value;
			
				if (field_value == '' || field_value.length < field_size) {
				  error_message = error_message + "· " + message + "\n";
				  error = true;
				}
			 }
		 }
	}
  
}





function validar_password(field_name_1, field_name_2, field_size, message_1, message_2) {

    var password = document.getElementById("password").value;
    var confirmation = document.getElementById("confirmation").value;

    if (password == '' || password.length < field_size) {
      error_message = error_message + "· " + message_1 + "\n";
      error = true;
    } else if (password != confirmation) {
      error_message = error_message + "· " + message_2 + "\n";
      error = true;
    }

}

function validar_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) {
  
    var password_current = document.getElementsByName(field_name_1).value;
    var password_new = document.getElementsByName(field_name_2).value;
    var password_confirmation = document.getElementsByName(field_name_3).value;

    if (password_current == '' || password_current.length < field_size) {
      error_message = error_message + "· " + message_1 + "\n";
      error = true;
    } else if (password_new == '' || password_new.length < field_size) {
      error_message = error_message + "· " + message_2 + "\n";
      error = true;
    } else if (password_new != password_confirmation) {
      error_message = error_message + "· " + message_3 + "\n";
      error = true;
    }
  
}

function validar_form(form_name) {
  if (submitted == true) {
    alert("Ya ha enviado el formulario. Pulse Aceptar y espere a que termine el proceso.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "El formulario no fue rellenado correctamente\nPor favor, haga las siguientes correciones:\n\n";
  validar_input("nombre", 4, "Su Nombre debe tener al menos 4 letras.");
  validar_input("apellidos", 4, "Sus apellidos deben tener al menos 4 letras.");
  validar_input("fech_nac", 10, "Su fecha de nacimiento debe tener este formato: DD/MM/AAAA (p.ej. 21/03/1966)");
  validar_input("email", 6, "Su dirección de E-Mail debe tener al menos 6 letras.");
  validar_input("telefono", 9, "Su número de teléfono debe tener al menos 9 carácteres.");
  validar_password("password", "confirmation", 6, "Su contraseña debe tener al menos 6 caracteres.", "La confirmación de la contraseña debe ser igual a la contraseña.");
 // validar_password_new("password_current", "password_new", "password_confirmation", 6, "Su contraseña debe tener al menos 6 caracteres.", "Su contraseña nueva debe tener al menos 6 caracteres.", "La confirmacion de su contraseña debe coincidir con su contraseña nueva.");
  validar_input("direccion", 8, "Su dirección debe tener al menos 8 letras.");
  validar_input("cp", 4, "Su código postal debe tener al menos 4 letras.");
  validar_input("poblacion", 3, "Su población debe tener al menos 3 letras.");
  validar_input("provincia", 3, "Su provincia/estado debe tener al menos 2 letras.");
  validar_input("pais", 3, "Seleccione un pais por favor.");
  
  if (error == true) {
    alert(error_message);
   // return false;
  } else {
    submitted = true;
    //return true;
	form1.submit();
  }
}
//FUNCIONES AJAX
		function GetXmlHttpObject()
		{ 
			var objXMLHttp=null
			if (window.XMLHttpRequest)
			{
			objXMLHttp=new XMLHttpRequest()
			}
			else if (window.ActiveXObject)
			{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			return objXMLHttp
		} 
////FIN FUNCIONES AJAX
function login(){
var http = new GetXmlHttpObject();
					//var url="http://ecutram.com/services2server/recept.php"
					var url="login.php?mail="+document.getElementById('mail').value+"&password="+document.getElementById('password').value;
					http.open("GET", url, true);
					http.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
					http.setRequestHeader("Connection", "close");
					http.onreadystatechange = function() {//
						if(http.readyState == 4 && http.status == 200) {
						alert(http.responseText);
							if (http.responseText=="Usuario validado"){
							document.getElementById('logeo').innerHTML="Bienvenido a Encobertura.com, para cerrar tu sesión pulsa <a href='javascript:unlogin()'>aqui</a>";
							}
						}
					}
					
				http.send(null)
				
}
function unlogin(){
var http = new GetXmlHttpObject();
					//var url="http://ecutram.com/services2server/recept.php"
					var url="unlogin.php?mail=&password=";
					http.open("GET", url, true);
					http.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
					http.setRequestHeader("Connection", "close");
					http.onreadystatechange = function() {//
						if(http.readyState == 4 && http.status == 200) {
							alert(http.responseText);
						document.getElementById('logeo').innerHTML="Usuario desconectado, para conectarse de nuevo pulse <a href='javascript:history.go(0)'>aqui</a>";
						}
					}
					
				http.send(null)
				
}

	function actualizar(linea){
	window.location.href="actualizar_carro.php?linea="+linea+"&cantidad="+document.getElementById(linea).value;
}


function mostrar_carrito(){
var http_carrito = new GetXmlHttpObject();
					//var url="http://ecutram.com/services2server/recept.php"
					var url="ver_carrito_mini.php";
					http_carrito.open("GET", url, true);
					http_carrito.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
					http_carrito.setRequestHeader("Connection", "close");
					http_carrito.onreadystatechange = function() {//
						if(http_carrito.readyState == 4 && http_carrito.status == 200) {
		
						document.getElementById('carrito').innerHTML=http_carrito.responseText;	;
						}
					}
					
				http_carrito.send(null)
				
}
function lineas_2_del()
{
var lineas = "";
for (var i=0; i < document.f_carrito.linea.length; i++)
   {
   if (document.f_carrito.linea[i].checked)
      {
      lineas=lineas + document.f_carrito.linea[i].value + ";";
      }
   }
   window.location.href="eliminar_producto.php?lineas="+lineas;
}

