// Corrector de Bug PNG para Explorer. Opera y Mozilla funcionan correctamente sin este JS
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }

   }
var ua = navigator.userAgent.toLowerCase();
function detect(text) {
   stringposition = ua.indexOf(text) + 1;
   data = text;
   return stringposition;
}

if (detect('opera')) {
	 
 } else if (detect('firefox')){
	 
} else if (detect('msie')){
	 window.attachEvent("onload", correctPNG);	
}	 


/* SUBMENU DESPLEGABLE */

function MostrarSubMenu() {
	document.getElementById('SubMenu').style.display="block";
	document.getElementById('OpcionDesplegable').style.color="#ffda00";	
	document.getElementById('OpcionDesplegable').style.backgroundPosition="left";	
	document.getElementById('OpcionDesplegable').style.backgroundImage="url(../img/fondo_menu_on.jpg)";
}

function OcultarSubMenu() {
	document.getElementById('SubMenu').style.display="none";
	document.getElementById('OpcionDesplegable').style.color="#fff";
	document.getElementById('OpcionDesplegable').style.backgroundImage="none";	
}


/* SUBMENU DESPLEGABLE2 */

function MostrarSubMenu2() {
	document.getElementById('SubMenu2').style.display="block";
	document.getElementById('OpcionDesplegable2').style.color="#ffda00";	
	document.getElementById('OpcionDesplegable2').style.backgroundPosition="left";	
	document.getElementById('OpcionDesplegable2').style.backgroundImage="url(../img/fondo_menu_on.jpg)";
}

function OcultarSubMenu2() {
	document.getElementById('SubMenu2').style.display="none";
	document.getElementById('OpcionDesplegable2').style.color="#fff";
	document.getElementById('OpcionDesplegable2').style.backgroundImage="none";	
}



function CheckEmailAddress(value){
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
			return true;
		}else{
			return false;
		}
	}
	function validar(form){
		if(document.getElementById('Nombre').value==''){
			alert('El campo Nombre y Apellidos es obligatorio');
			document.getElementById('Nombre').focus();
			return false;
		}else{
			if(document.getElementById('Nombre').value.length<3){
				alert('El campo Nombre y Apellidos es demasiado corto (mínimo 3 carácteres)');
				document.getElementById('Nombre').focus();
				return false;
			}	
		}
		if(document.getElementById('Localidad').value==''){
			alert('El campo Localidad es obligatorio');
			document.getElementById('Localidad').focus();
			return false;
		}else{
			if(document.getElementById('Localidad').value.length<3){
				alert('El campo Localidad es demasiado corto (mínimo 3 carácteres)');
				document.getElementById('Localidad').focus();
				return false;
			}	
		}
		if(document.getElementById('Telefono').value==''){
			alert('El campo Teléfono es obligatorio');
			document.getElementById('Telefono').focus();
			return false;
		}else{
			if(document.getElementById('Telefono').value.length<3){
				alert('El campo Teléfono es demasiado corto (mínimo 3 carácteres)');
				document.getElementById('Telefono').focus();
				return false;
			}	
		}		
		if(document.getElementById('Email').value==''){
			alert('El campo E-mail es obligatorio');
			document.getElementById('Email').focus();
			return false;
		}else{
			if(!CheckEmailAddress(document.getElementById('Email').value)){
				alert('Revise su E-mail, es incorrecto');
				document.getElementById('Email').focus();
				return false;
			}
		}
		if(document.getElementById('ContraEtiqueta').value==''){
			alert('Por favor, introduzca el código de participación que encontrará en la contra etiqueta de la botella');
			document.getElementById('ContraEtiqueta').focus();
			return false;
		}else{
			if(document.getElementById('ContraEtiqueta').value.length<3){
				alert('El código introducido no es correcto');
				document.getElementById('ContraEtiqueta').focus();
				return false;
			}	
		}
		return true;
	}