// JavaScript Document
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function PonerRojo(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
if (NombreCampo=="Email"){
  if (!nombre.value) alert(""+NombreCampo+"");
  else alert("Direccion de Email invalida");
} else if (NombreCampo=="Sexo" || NombreCampo=="Pais") {
  alert("Debe elegir una opcion del campo de seleccion "+NombreCampo);
} else {
  alert(""+NombreCampo+"");
}
nombre.focus();
}

function PonerRojoNOJS(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
nombre.focus();
}

function Normalizar(iD){
// var nombre = document.getElementById(iD);
// var nombre = iD;
iD.style.borderColor="";
iD.style.borderStyle="";
iD.style.borderWidth="";
}
//
//
// Validador del Contacto
//
//
function Validar_contacto(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var comentarios = document.getElementById("idcomentarios");

Normalizar(nombre);
Normalizar(email);
Normalizar(comentarios);
  if (!nombre.value){
    PonerRojo('idnombre','El campo Nombre es Obligatorio');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','El campo email es Obligatorio');
    return false;
  }
  if (!comentarios.value){
    PonerRojo('idcomentarios','El campo Comentario es Obligatorio');
    return false;
  }
}
//
// Funcion habilitar otra forma de contacto
//
function otros_fun(){
	if (document.getElementById('idconocio').value=="Otros") {
	document.getElementById('idotros').disabled="";
	document.getElementById('idotros').style.borderColor="#888888";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}	
	else
	{
	document.getElementById('idotros').disabled="disabled";
	document.getElementById('idotros').style.borderColor="#FFFFFF";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}
}
//
function PonerRojo(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="";
nombre.style.borderStyle="";
nombre.style.borderWidth="";
if (NombreCampo=="Email"){
  if (!nombre.value) alert("El campo "+NombreCampo+" esta vacio");
  else alert("Direccion de Email invalida");
} else if (NombreCampo=="Sexo" || NombreCampo=="Pais") {
  alert("Debe elegir una opcion del campo de seleccion "+NombreCampo);
} else {
  alert("El campo "+NombreCampo+" esta vacio");
}
nombre.focus();
}

function PonerRojoNOJS(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
nombre.focus();
}

function Normalizar(iD){
// var nombre = document.getElementById(iD);
// var nombre = iD;
iD.style.borderColor="";
iD.style.borderStyle="";
iD.style.borderWidth="";
}
//
//
// Validador del Contacto
//
//
function Validar_contacto(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var asunto = document.getElementById("idasunto");
  var comentario = document.getElementById("idcomentario");

Normalizar(nombre);
Normalizar(email);
Normalizar(asunto);
Normalizar(comentario);
  if (!nombre.value){
    PonerRojo('idnombre','Nombre');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
  if (!asunto.value){
    PonerRojo('idasunto','Asunto');
    return false;
  }
  if (!comentario.value){
    PonerRojo('idcomentario','Comentario');
    return false;
  }
}
//
//
// comprar
//
//
function Validar_comprar() {
var pepez=0; 
for(i=0; ele=document.pedido.elements[i]; i++){ 
if (ele.type=='checkbox') 
if (ele.checked){pepez=1;break;}} 
if (pepez==1){document.pedido.submit();}else{ 
alert('Para Continuar Debe seleccionar alguno de los Items'); return false;}
}
//
//
// Validador Paso1
//
//
function Validar_paso1(){
  var nombre = document.getElementById("idnombre");
  var telefono = document.getElementById("idtelefono");
  var email = document.getElementById("idemail");
  var direccion = document.getElementById("iddireccion");
  var localidad = document.getElementById("idlocalidad");
  var provincia = document.getElementById("idprovincia");

Normalizar(nombre);
Normalizar(telefono);
Normalizar(email);
Normalizar(direccion);
Normalizar(localidad);
Normalizar(provincia);
  if (!nombre.value){
    PonerRojo('idnombre','Nombre');
    return false;
  }
  if (!telefono.value){
    PonerRojo('idtelefono','Telefono');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
    if (!direccion.value){
    PonerRojo('iddireccion','Dirección');
    return false;
  }
    if (!localidad.value){
    PonerRojo('idlocalidad','Localidad');
    return false;
  }
    if (!provincia.value){
    PonerRojo('idprovincia','Provincia');
    return false;
  }
}
