// JavaScript Document
// * Dependencies * 

// this function requires the following snippets:
// JavaScript/images/switchImage
//

// BODY Example:
// <body onLoad="mySlideShow1.play(); mySlideShow2.play();">
// <img src="originalImage1.gif" name="slide1">
// <img src="originalImage2.gif" name="slide2">
//

// SCRIPT Example:
 var mySlideList1 = ['Imagenes/Galeria/sitio-bardas-prefabricadas-01.jpg', 'Imagenes/Galeria/sitio-bardas-prefabricadas-02.jpg', 'Imagenes/Galeria/sitio-bardas-prefabricadas-03.jpg'];
 var mySlideShow1 = new SlideShow(mySlideList1, 'bgImg', 3000, "mySlideShow1");
// var mySlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];
// var mySlideShow2 = new SlideShow(mySlideList2, 'slide2', 1000, "mySlideShow2");

function SlideShow(slideList, image, speed, name)  {
  this.slideList = slideList;
  this.image = image;
  this.speed = speed;
  this.name = name;
  this.current = 0;
  this.timer = 0;
}


SlideShow.prototype.play = SlideShow_play;  
function SlideShow_play() {
  with(this) {
    if(current++ == slideList.length-1) current = 0;
    switchImage(image, slideList[current]);
    clearTimeout(timer);
    timer = setTimeout(name+'.play()', speed);
  }
}


// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

/*Forma de contacto*/
function validateEmail(email){var splitted = email.match("^(.+)@(.+)$");if(splitted == null) return false;if(splitted[1] != null ){var regexp_user=/^\"?[\w-_\.]*\"?$/;if(splitted[1].match(regexp_user) == null) return false;}if(splitted[2] != null){var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;if(splitted[2].match(regexp_domain) == null) {var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;if(splitted[2].match(regexp_ip) == null) return false;}return true;}return false;}
function isNumberKey(evt){var charCode = (evt.which) ? evt.which : event.keyCode;if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } else { return true;}}

function ClearPlaceHolder (input) {
	if (input.value == input.defaultValue) {
		input.value = "";
}
}
function SetPlaceHolder (input) {
	if (input.value == "") {
		input.value = input.defaultValue;
}
}

function CompDatos(){
	
	var nombre  =  document.getElementById('nombre').value;
	var mail =  document.getElementById('mail').value;	
	var telefono =  document.getElementById('telefono').value;
	var mts =  document.getElementById('mts').value;
	
	var nErrores = 0;
	var mErrores = 'El formulario contiene los sigientes errores: \n'; 
	
	if (nombre == "Nombre") { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- Tu nombre no puede estar vacio\n";
	}
	
	if (validateEmail(mail) == false) { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- La direccion de correo no es valida o esta vacia\n";
	}
	
	if (telefono.length != 10) { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- El telefono debe de contener 10 digitos (lada y numero)\n";
	}
	if (isNaN(telefono)) { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- El telefono solo puede contener numeros\n";
	}
	
	if (document.getElementById('estado').options[0].selected == true){
	nErrores = nErrores + 1;
	mErrores = mErrores + "- El campo del estado es obligatorio\n" } 
	
	if (mts == "Metros lineales") { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- El campo de metros lineales no puede estar vacio\n";
	}
	if (isNaN(mts)) { 
	nErrores = nErrores + 1; 
	mErrores = mErrores + "- El campo de metros lineales solo puede contener numeros\n";
	}
	
	
	if (nErrores == 0) { return true; } else { alert (mErrores); return false; }
	} 


