
// Script para hacer los banners aleatorios.

var Found=false
var Current = new Array()
var MaxValue=3 //(Example 2 is equal to: 0,1,2)
var NumUnique=4  //The number of unique numbers required
var Count=0
var Current = new Array(NumUnique)
GetUnique()

function GetUnique()
  {
    for (i=0;Count<NumUnique;Count++)
    {
      Found=false
      var rndValue = get_random()
      var j=0
      for (j=0;j<Current.length;j++)
      {
        if (Current[j] == rndValue)
        {
          Found=true
          break
        }
      }
      if (Found)
      {
        Count--
      } else {
        Current[Count]=rndValue
      }
    }
  }
  function get_random()
  {
    var ranNum= Math.round(Math.random()*MaxValue);
    return ranNum;
  }
// End -->

function loadImage(div,source) {
			  
			  var img = new Image();
			  
			  // wrap our new image in jQuery, then:
			  $(img)
				// once the image has loaded, execute this code
				.load(function () {
				  // set the image hidden by default    
				  $(this).hide();
				
				  // with the holding div #loader, apply:
				  $(div)
					// remove the loading class (so no background spinner), 
					.removeClass('loading')
					// then insert our image
					.append(this);
				
				  // fade our image in to create a nice effect
				  $(this).fadeIn();
				})
				
				// if there was an error loading the image, react accordingly
				.error(function () {
				  // notify the user that the image could not be loaded
				})
				
				// *finally*, set the src attribute of the new image to our image
				.attr('src', 'img/'+source);
			};
			
			
	function valContact(cual) {
	
			var cantidad = $("#"+cual+" '[required=true]'").length;
			var elementos = $("#"+cual+" '[required=true]'");
			var i = 0;
			
			$.each(
				elementos,
				function( indice, valor ){
				
				var idObj = $(this).attr('id');
				var val = $(this).val();
				 
				if ( val == ""){
					alert("Complete el campo "+idObj);
					return false;
				} else {
					i++;
				}
	
				});
			
			if ( i == cantidad ) {
				$("#"+cual).submit();
			}
			
		}	
		
$(document).ready(function() {

	loadImage ('#b'+Current[0],'banner_central.jpg');
	loadImage ('#b'+Current[1],'banner_blade.jpg');
	loadImage ('#b'+Current[2],'banner_system_x.jpg');
	loadImage ('#b'+Current[3],'storage_banner.jpg');

});

