// Variables para setear
//onload=function() 
//{
//	cAyuda=document.getElementById("mensajesAyuda");
//	cNombre=document.getElementById("ayudaTitulo");
//	cTex=document.getElementById("ayudaTexto");
//	divTransparente=document.getElementById("transparencia");
//	divMensaje=document.getElementById("transparenciaMensaje");
//	form=document.getElementById("formulario");
//	urlDestino="mail.php";
//	
//	claseNormal="input";
//	claseError="inputError";
//	
//	ayuda=new Array();
//	ayuda["Nombre"]="Ingrese su nombre. De 4 a 50 caracteres. OBLIGATORIO";
//	ayuda["Direccion"]="Ingrese su dirección completa. De 4 a 100 caracteres. OBLIGATORIO";
//	//ayuda["Telefono"]="Ingrese un teléfono de contacto.";
//	ayuda["Correo"]="Ingresa un e-mail válido. OBLIGATORIO";
//	//ayuda["Comentario"]="Ingresa tus comentarios. De 5 a 500 caracteres. OBLIGATORIO";
//	
//	preCarga("img/ok.gif", "img/loading.gif", "img/error.gif");
//}

function preCarga()
{
	imagenes=new Array();
	for(i=0; i<arguments.length; i++)
	{
		imagenes[i]=document.createElement("img");
		imagenes[i].src=arguments[i];
	}
}

function nuevoAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// No IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}

function limpiaForm()
{
	for(i=0; i<=4; i++)
	{
		document.form1.elements[i].className=claseNormal;
	}
	//document.getElementById("inputComentario").className=claseNormal;
}

function campoError(campo)
{
	//campo.className=claseError;
	error=1;
}

function ocultaMensaje()
{
	divTransparente.style.display="none";
}

function muestraMensaje(mensaje)
{
	divMensaje.innerHTML=mensaje;
	divTransparente.style.display="block";
}

function eliminaEspacios(cadena)
{
	// Funcion para eliminar espacios delante y detras de cada cadena
	while(cadena.charAt(cadena.length-1)==" ") cadena=cadena.substr(0, cadena.length-1);
	while(cadena.charAt(0)==" ") cadena=cadena.substr(1, cadena.length-1);
	return cadena;
  
}

function validaLongitud(valor, permiteVacio, minimo, maximo)
{
	var cantCar=valor.length;
	if(valor==0)
	{
		if(permiteVacio) return true;
		else return false;
	}
	else
	{
		if(cantCar>=minimo && cantCar<=maximo) return true;
		else return false;
	}
}

function validaCorreo(valor)
{
	var reg=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(valor)) return true;
	else return false;
}

function validaForm()
{
	document.getElementById('transparenciaMensaje').innerHTML='';
	
	//limpiaForm();
	error=0;
	var nombre=eliminaEspacios(document.form1.inputNombre.value);
	//var empresa=eliminaEspacios(form.inputEmpresa.value);
	var direccion=eliminaEspacios(document.form1.inputDireccion.value);
	var telefono=eliminaEspacios(document.form1.inputTelefono.value);
	var correo=eliminaEspacios(document.form1.inputEmail.value);
	var localidad=eliminaEspacios(document.form1.inputLocalidad.value);
	var cp=eliminaEspacios(document.form1.inputCP.value);
	var provincia=eliminaEspacios(document.form1.inputProvincia.value);
	//var comentarios=eliminaEspacios(form.inputComentario.value);
	

//	
	if(!validaLongitud(nombre, 1, 4, 50)) campoError(nombre);
	if(!validaLongitud(direccion, 1, 4, 100)) campoError(direccion);
	if(!validaLongitud(telefono, 0, 9, 9)) campoError(telefono);
	if(!validaLongitud(localidad, 1, 3, 50)) campoError(localidad);
	if(!validaLongitud(cp, 1, 5, 5)) campoError(cp);
	if(!validaLongitud(provincia, 1, 4, 50)) campoError(provincia);	
  if(!validaCorreo(correo)) campoError(correo);
	//if(!validaLongitud(comentarios, 0, 5, 500)) campoError(form.inputComentario);
	
	if(error==1)
	{
		var texto="<img src='img/error.gif' alt='Error'>&nbsp;&nbsp;&nbsp;Error: &nbsp; revise los campos y vuelva a intentarlo.<br><br><br>";
		muestraMensaje(texto);
		//document.getElementById('transparenciaMensaje').innerHTML=texto;
		//document.getElementById("transparencia").style.display="block";
	}
	else
	{
	  /*
		var texto="<img src='img/loading.gif' alt='Enviando'>&nbsp;&nbsp;&nbsp;Enviando. Por favor, espere.<br><br>";
		muestraMensaje(texto);
		alert("1");
		*/
		
		
		var cajas1=document.getElementById("miSelect").value;
    var cajas2=document.getElementById("miSelect2").value;
    var precio1=document.getElementById("Pru").value;
    var precio2 = document.getElementById("Pru2").value;
    var gastosdeenvio=document.getElementById("Gastos").value;
    var subtotal = document.getElementById("Subt").value;
    var iva = document.getElementById("IVA").value;
    var total = document.getElementById("Total").value;
    
    
		var ajax=nuevoAjax();
		ajax.open("POST", urlDestino, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("nombre="+nombre+"&telefono="+telefono+"&correo="+correo+"&localidad="+localidad+"&CP="+cp+"&provincia="+provincia+"&direccion="+direccion+"&cajas1="+cajas1+"&cajas2="+cajas2+"&precio1="+precio1+"&precio2="+precio2+"&gastosdeenvio="+gastosdeenvio+"$subtotal="+subtotal+"&iva="+iva+"&total"+total);
				
		//ajax.send();
		var texto="<img src='img/ok.gif' alt='Ok'> &nbsp;&nbsp;&nbsp;Gracias por su pedido.&nbsp;&nbsp;Le responderemos a la mayor brevedad.<br><br>";
		muestraMensaje(texto);
		
		/*		
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{
				var respuesta=ajax.responseText;
				if(respuesta=="OK")
				{
					var texto="<img src='img/ok.gif' alt='Ok'><br>Gracias por su pedido.<br>Le responderemos a la brevedad.<br><br><button style='width:45px; height:18px; font-size:10px;' onClick='ocultaMensaje()' type='button'>Ok</button>";
				}
				else
				{
					 var texto="<img src='img/error.gif'><br><br>Error: por favor, intentelo de nuevo más tarde.<br><br><button style='width:45px; height:18px; font-size:10px;' onClick='ocultaMensaje()' type='button'>Ok</button>";
				}
				muestraMensaje(texto);
			}
		}
		*/
	}
}

// Mensajes de ayuda

//if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
//Else navegador=1;

function colocaAyuda(event)
{
	if(navegador==0)
	{
		var corX=window.event.clientX+document.documentElement.scrollLeft;
		var corY=window.event.clientY+document.documentElement.scrollTop;
	}
	else
	{
		var corX=event.clientX+window.scrollX;
		var corY=event.clientY+window.scrollY;
	}
	cAyuda.style.top=corY+20+"px";
	cAyuda.style.left=corX+15+"px";
}

function ocultaAyuda()
{
	cAyuda.style.display="none";
	if(navegador==0) 
	{
		document.detachEvent("onmousemove", colocaAyuda);
		document.detachEvent("onmouseout", ocultaAyuda);
	}
	else 
	{
		document.removeEventListener("mousemove", colocaAyuda, true);
		document.removeEventListener("mouseout", ocultaAyuda, true);
	}
}

function muestraAyuda(event, campo)
{
	colocaAyuda(event);
	
	if(navegador==0) 
	{ 
		document.attachEvent("onmousemove", colocaAyuda); 
		document.attachEvent("onmouseout", ocultaAyuda); 
	}
	else 
	{
		document.addEventListener("mousemove", colocaAyuda, true);
		document.addEventListener("mouseout", ocultaAyuda, true);
	}
	
	cNombre.innerHTML=campo;
	cTex.innerHTML=ayuda[campo];
	cAyuda.style.display="block";
}

// Variables mantener capa flotante
<!-- funciones float -->
<!-- copa  de vino -->
window.onerror = null;
var topMargin = 1;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie7 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
if (ns6) {
this.obj = document.getElementById(id).style;
this.obj.left = left;
return this.obj;
}
else if(ie7) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
else if(ns4) {
this.obj = document.layers[id];
this.obj.left = left;
return this.obj;
   }
}
function layerSetup() {
floatLyr = new layerObject('floatLayer', pageWidth * .5);
window.setInterval("main()", 10)
}
function floatObject() {
if (ns4 || ns6) {
findHt = window.innerHeight;
} else if(ie7) {
findHt = document.body.clientHeight;
   }
} 
function main() {
if (ns4) {
this.currentY = document.layers["floatLayer"].top;
this.scrollTop = window.pageYOffset;
mainTrigger();
}
else if(ns6) {
this.currentY = parseInt(document.getElementById('floatLayer').style.top);
this.scrollTop = scrollY;
mainTrigger();
} else if(ie7) {
this.currentY = floatLayer.style.pixelTop;
this.scrollTop = document.body.scrollTop;
mainTrigger();
   }
}
function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}
animator();
   }
}
function floatStart() {
var now = new Date();
this.A = this.targetY - this.currentY;
this.B = Math.PI / ( 2 * this.slideTime );
this.C = now.getTime();
if (Math.abs(this.A) > this.findHt) {
this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
this.A = this.A > 0 ? this.findHt : -this.findHt;
}
else {
this.D = this.currentY;
   }
}
function animator() {
var now = new Date();
var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
newY = Math.round(newY);
if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
if ( ie7 )document.all.floatLayer.style.pixelTop = newY;
if ( ns4 )document.layers["floatLayer"].top = newY;
if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
   }
}
function start() {
	
//document.getElementById('transparenciaMensaje').innerHTML="prueba comienzo";
	
	///////////////////////////////////////////////////
	cAyuda=document.getElementById("mensajesAyuda");
	cNombre=document.getElementById("ayudaTitulo");
	cTex=document.getElementById("ayudaTexto");
	divTransparente=document.getElementById("transparencia");
	divMensaje=document.getElementById("transparenciaMensaje");
	form=document.getElementById("formulario");
	urlDestino="js/mail.php";
	
	claseNormal="input";
	claseError="inputError";
	
	ayuda=new Array();
	ayuda["Nombre"]="Ingrese su nombre. De 4 a 50 caracteres. OBLIGATORIO";
	ayuda["Direccion"]="Ingrese su dirección completa. De 4 a 100 caracteres. OBLIGATORIO";
	//ayuda["Telefono"]="Ingrese un teléfono de contacto.";
	ayuda["Correo"]="Ingresa un e-mail válido. OBLIGATORIO";
	//ayuda["Comentario"]="Ingresa tus comentarios. De 5 a 500 caracteres. OBLIGATORIO";
	
	preCarga("img/ok.gif", "img/loading.gif", "img/error.gif");
	///////////////////////////////////////////////////////
	
if(ns6||ns4) {
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
else if(ie4) {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
   }
}
//  Finito -->
