	function pop_up_scroll(href, titulo,  w,h, left, top )
	{
		window.open(href, titulo, "menubar=0,toolbar=0,scrollbars=1,directories=0,resize=0,width="+w+",height="+h+",left="+left+", top="+top);
	}
	
	jQuery.fn.delay = function(time,func){
		return this.each(function(){ setTimeout(func,time); });
	};
	
	function mostrarCalc() {
		$('#calculadora').show();
		return false;
	}
	
	function ocultarCalc() {
		$('#calculadora').hide();
		return false;
	}
	
	function mostrarLocal(valor) {
		$('#menuLocales').val('0');
		pop_up_scroll('locales?loc='+valor,'ConsorcioLocal','630','460','10','10');
	}
	
	function ocultarDelay() {
		$(this).delay(500,function(){
		  if (!over) {$(".submenu").hide();$(".menu").removeClass('menuOver');}
		});
	}
	
	function cambiarIntro(idMostrar)
	{
		$('#intro1').hide();
		$('#intro2').hide();
		$('#intro3').hide();
		$('#btn1').attr("src","img/n1-a.png");
		$('#btn2').attr("src","img/n2-a.png");
		$('#btn3').attr("src","img/n3-a.png");
		$('#intro'+idMostrar).show();
		$('#btn'+idMostrar).attr("src","img/n"+idMostrar+"-b.png");
		return false;
	}

       function cambiarImgIntro(id) {
           $(this).delay(10000,function(){
                        cambiarIntro(id);
                        if (id==3)
                        {
                            nuevoId = 1;
                        }else
                        {
                            nuevoId = id + 1;
                        }
                        cambiarImgIntro(nuevoId);
                    });
        }

	function validarContacto() {
		if ($('#nombre').val()=='') {
			alert('Debes ingresar un Nombre');
			$('#nombre').focus();
			return false;
		}else if ($('#apellido').val()=='') {
			alert('Debes ingresar un Apellido');
			$('#apellido').focus();
			return false;
		}else if ($('#telefono').val()=='') {
			alert('Debes ingresar un Telefono');
			$('#telefono').focus();
			return false;
		}else if ($('#email').val()=='') {
			alert('Debes ingresar un Email');
			$('#email').focus();
			return false;
		}else if ($('#horario').val()=='') {
			alert('Debes ingresar un Horario en el que estes disponible');
			$('#horario').focus();
			return false;
		}else if ($('#localidad').val()=='') {
			alert('Debes seleccionar una localidad');
			$('#localidad').focus();
			return false;
		}else if (emailCheck($('#email').val()) != true) {
			alert('Email invalido');
			return false;
		}else{
			$('#enviar').hide();
			$('#mensajeEnviando').show();
			return true;
		}
	}

	function validarContactoRepresentante() {
		if ($('#nombre').val()=='') {
			alert('Debes ingresar un Nombre');
			$('#nombre').focus();
			return false;
		}else if ($('#apellido').val()=='') {
			alert('Debes ingresar un Apellido');
			$('#apellido').focus();
			return false;
		}else if ($('#ciudad').val()=='') {
			alert('Debes especificar la ciudad donde vives');
			$('#ciudad').focus();
			return false;
		}else if ($('#celular').val()=='') {
			alert('Debes ingresar tu telefono celular');
			$('#celular').focus();
			return false;
		}else if ($('#ci').val()=='') {
			alert('Debes ingresar tu Cedula de Identidad');
			$('#ci').focus();
			return false;
		}else if ($('#direccion').val()=='') {
			alert('Debes ingresar tu direccion');
			$('#direccion').focus();
			return false;
		}else if ($('#email').val()=='') {
			alert('Debes ingresar un Email');
			$('#email').focus();
			return false;
		}else if (emailCheck($('#email').val()) != true) {
			alert('Email invalido');
			return false;
		}else{
			$('#enviar').hide();
			$('#mensajeEnviando').show();
			return true;
		}
	}

	function calcularCuota()
	{
		params='pro='+$('#prod').val()+'&cantidad='+$('#cantidades').val()+'&moneda='+$('#moneda').val();
		$.get('includes/calcula_cuota.php',params,function(data){
				if ($('#prod').val()!='diferencial')  {
					if(data.length<20){
						$('.resultado').html(data);
						$('#error').hide(); 
					}else
					{
						$('#error').html(data);  
						$('.resultado').html('');
						$('#error').show();
					}
				}else
				{
					if(data.length<20){
						var datos = data.split(",");
						$('.resultado1').html(datos[0]);
						$('.resultado2').html(datos[1]);
						$('#error').hide(); 
					}else
					{
						$('#error').html(data);  
						$('.resultado1').html('');
						$('.resultado2').html('');
						$('#error').show();
					}
				}
	});
	}

	(function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
	    var args_len = arguments.length;
	    for (var i = args_len; i--;) {
	      var cacheImage = document.createElement('img');
	      cacheImage.src = arguments[i];
	      cache.push(cacheImage);
	    }
	  }
	})(jQuery)
	
	function emailCheck(emailStr) {
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */
		
		var checkTLD=1;
		
		/* The following is the list of known TLDs that an e-mail address must end with. */
		
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		
		/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
		
		var emailPat=/^(.+)@(.+)$/;
		
		/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
		
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		
		/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
		
		var validChars="\[^\\s" + specialChars + "\]";
		
		/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		
		var quotedUser="(\"[^\"]*\")";
		
		/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
		
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		
		/* The following string represents an atom (basically a series of non-special characters.) */
		
		var atom=validChars + '+';
		
		/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
		
		var word="(" + atom + "|" + quotedUser + ")";
		
		// The following pattern describes the structure of the user
		
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		
		/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
		
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		
		/* Finally, let's start trying to figure out if the supplied address is valid. */
		
		/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
		
		var matchArray=emailStr.match(emailPat);
		
		if (matchArray==null) {
		
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		return ("Direcci�n de email invalida (verificar @ y .)");
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		
		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		return ("Direcci�n de email contiene caracteres inv�lidos.");
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		return ("Direcci�n de email contiene caracteres inv�lidos.");
	
		   }
		}
		
		// See if "user" is valid 
		
		if (user.match(userPat)==null) {
		
		// user is not valid
		
		return ("Direcci�n de email invalida.");
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
		
		// this is an IP address
		
		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		return ("Direcci�n de email invalida.");
		   }
		}
		return true;
		}
		
		// Domain is symbolic name.  Check if it's valid.
		 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		return ("Direcci�n de email invalida.");
		   }
		}
		
		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
		
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return ("Direcci�n de email invalida.");
		}
		
		// Make sure there's a host name preceding the domain.
		
		if (len<2) {
		return ("Direcci�n de email invalida.");
		}
		
		// If we've gotten this far, everything's valid!
		return true;
	}
