//Crea un objeto XML-http
function getXmlHttpObject() {
	var xmlhttp;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				try {
					xmlhttp = new XMLHttpRequest();
				}
				catch (e) {
					xmlhttp = false;
					alert ('Error');
				}
			}
		}
	return xmlhttp;
}
//Porcesar la peticion XMLHttpReuest
function procesarajax(archivo,id,metodo,datos) {
	//Obtener el objeto XMLHttpRequest a utilizar
	xmlhttp = getXmlHttpObject();
	if (metodo=="get") {
		xmlhttp.open("GET",archivo,true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==1) {
				document.getElementById(id).innerHTML = "<img align='center' src='imagen/cargar.gif' width='17' style='margin-right:5px; border:none' /> Cargando ...";
			} else if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById(id).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null); //Como es GET no mandamos nada en al cuerpo
	} else {
		xmlhttp.open("POST",archivo,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==1) {
				document.getElementById(id).innerHTML = "<div align='center' style='padding:5px 0px 5px 0px;text-align:center'><img src='imagen/cargar.gif' style='margin-right:10px' /> Cargando ...</div>";
			} else if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById(id).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(datos);
	}
}
function ingresarform(formulario,archivo,id) {
	var datos = datosformulario(formulario);
	procesarajax(archivo,id,"post",datos);
}

function emailES(formulario) {
	var a=0;
	if (formulario.elements["nombre"].value=="") alert("Debe ingresar su nombre"); else var a=a+1;
	if (formulario.elements["email"].value=="") alert("Debe ingresar un email de contacto"); else var a=a+1;
	if (formulario.elements["pais"].value=="") alert("Debe ingresar su país de residencia"); else var a=a+1;
	if (formulario.elements["asunto"].value=="") alert("Debe ingresar el asunto del mensaje"); else var a=a+1;
	if (a>3) {
		formulario.action=formulario.elements['accionform'].value;
		formulario.submit();
	}
}

function emailEN(formulario) {
	var a=0;
	if (formulario.elements["nombre"].value=="") alert("You must enter your name"); else var a=a+1;
	if (formulario.elements["email"].value=="") alert("You must enter your email"); else var a=a+1;
	if (formulario.elements["pais"].value=="") alert("You must enter your country"); else var a=a+1;
	if (formulario.elements["asunto"].value=="") alert("You must enter the message subject"); else var a=a+1;
	if (a>3) {
		formulario.action=formulario.elements['accionform'].value;
		formulario.submit();
	}
}
function suscribirseES(formulario) {
	var a=0;
	if (formulario.elements["nombre"].value=="") alert("Debe ingresar su nombre"); else var a=a+1;
	if (formulario.elements["apellido"].value=="") alert("Debe ingresar su apellido"); else var a=a+1;
	if (formulario.elements["email"].value=="") alert("Debe ingresar un email de contacto"); else var a=a+1;
	if (formulario.elements["pais"].value=="") alert("Debe ingresar su país de residencia"); else var a=a+1;
	if (a>3) {
		formulario.action=formulario.elements['accionform'].value;
		formulario.submit();
	}
}
function suscribirseEN(formulario) {
	var a=0;
	if (formulario.elements["nombre"].value=="") alert("You must enter your name"); else var a=a+1;
	if (formulario.elements["apellido"].value=="") alert("You must enter your surname"); else var a=a+1;
	if (formulario.elements["email"].value=="") alert("You must enter your email"); else var a=a+1;
	if (formulario.elements["pais"].value=="") alert("You must enter your country"); else var a=a+1;
	if (a>3) {
		formulario.action=formulario.elements['accionform'].value;
		formulario.submit();
	}
}
function mapa(idregion) {
	document.getElementById('mapa').style.background="url('imagen/mapa"+idregion+".jpg')";
	document.getElementById('textoregion2').style.display='none';
	document.getElementById('textoregion3').style.display='none';
	document.getElementById('textoregion4').style.display='none';
	document.getElementById('textoregion6').style.display='none';
	document.getElementById('textoregion'+idregion).style.display='block';
}

function moverpeli (anchototal,direccion) {
		margenactual=document.getElementById('pelicula').style.marginLeft;
		pos=margenactual.indexOf('p');
		margenactual=parseInt(margenactual.substring(0,pos));
		if (direccion=="der") {
			margen=margenactual-600;
			if (margenactual==-anchototal+600) margen=0;
		} else {
			margen=margenactual+600;
			if (margenactual==0) margen=-anchototal+600;
		}
		document.getElementById('pelicula').style.marginLeft=margen+"px";
}


