// JavaScript Document
var rutaImasBot = "A_imas/A_menu/";


var paises = new Array ();
paises ["belgica"] = "nutriciababy.be";
paises ["finlandia"] = "nutricia.fi";
paises ["francia"] = "nutricia.fr";
paises ["alemania"] = "pfrimmer-nutricia.de";
paises ["grecia"] = "nutricia.gr";
paises ["irlanda"] = "cow-gate.ie";
paises ["italia"] = "nutricia.it";
paises ["noruega"] = "nutricia.no";
paises ["polonia"] = "nutricia.com.pl";
paises ["portugal"] = "nutricia.pt";
paises ["holanda"] = "nutricia.nl";
paises ["turquía"] = "nutricia.com.tr";
paises ["granBretana"] = "cowandgate.com";
paises ["argentina"] = "nutricia-bago.com.ar";
paises ["china"] = "nutricia.com.cn";
paises ["indonesia"] = "nutricia.co.id";
paises ["malasia"] = "nutricia.com.my";
paises ["nuevaZelanda"] = "babytimes.co.nz";
paises ["emiratosArabes"] ="nutriciame.com";


function MM_preloadImages() { //v3.0
  var d=document; 
  
  if(d.images){ 
  	if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		
	for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src= rutaImasBot + a[i];
				};
			}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0

	var eleccion = paises [selObj.options[selObj.selectedIndex].value];
	if (eleccion){
		var loc = "http://www." + eleccion ;
		window.open (loc, "eleccion");
 		if (restore) selObj.selectedIndex=0;
	}else{
		return;
	}
	
}

function preloadImas (){

	MM_preloadImages(
		'bb_0_over.jpg',
		'bb_1_over.jpg',
		'bb_2_over.jpg',
		'bot_club_over.jpg',
		'bot_contactanos_over.jpg',
		'bot_elbebe_over.jpg',
		'bot_embarazo_over.jpg',
		'bot_nutinforma_over.jpg',
		'bot_productosN_over.jpg',
		'cN_0_over.jpg',
		'cN_1_over.jpg',
		'cN_2_over.jpg',
		'cN_3_over.jpg',
		'emb_0_over.jpg',
		'emb_1_over.jpg',
		'emb_2_over.jpg',
		'emb_3_over.jpg',
		'emb_4_over.jpg',
		'emb_5_over.jpg',
		'inf_0_over.jpg',
		'inf_1_over.jpg',
		'prod_0_over.jpg',
		'prod_1_over.jpg'
		);
}

// Control de PopUps

/**
 * popUpWindow
 *
 * Abre una ventana en PopUp y cierra la que haya en ese instante.
 *
 * @param url     Página que hay que abrir
 * @param options Objeto con los miembros relativos a las propiedades de la ventana
 *
 */
function popUpWindow(url,name,options, mod) {
  var opt = new Array();
  var i = 0;
  
  for (option in options) {
    switch (option) {
      case 'status':
      case 'scrollbars':
        opt[i++] = option;
        break;
      default:
        opt[i++] = option + '=' + options[option];
        break;
    }
  }
  
if (document.all&&window.print&&mod){
	window.showModelessDialog(url, name, opt.join(','));
	return false;
	}
  window.open(url,name,opt.join(','));
  
  return false;
}

/**
 * Funciones para abrir las ventanas de la web (por tener más limpio el HTML).
 */
function enviarAmigo() { return popUpWindow('form_enviar_amigo.php','recomendar',{width:365,height:282,top:100,left:100}); }
function enviarConsejo() { return popUpWindow('form_enviar_consejo.php','consejo',{width:354,height:358,top:100,left:100}); }
function nutriciaResponde() { return popUpWindow('form_nutricia_responde.php','contacto',{width:394,height:539,top:100,left:100}); }
function copy() {return popUpWindow('copy.html','copyRight',{resizable:'yes',width:500,height:382,top:100,left:100, scrollbars:'yes'});}
function avisoLegal() {return popUpWindow('avisoLegal.html','avisoLegal',{resizable:'yes',width:500,height:382,top:100,left:100, scrollbars:'yes'});}
function microsite() { popUpWindow('almiron_nutricia.html','inmundad',{width:977,height:625,top:100,left:100,resizable:'yes'});}
function popAldeas (){popUpWindow('aldeas_milupa.html','aldeas',{width:760,height:550,top:100,left:100});}
function popInstDiaPadre (){return popUpWindow('instrucciones_dia_del_padre.html','',{help:'yes', resizable:'yes', width:360, height:420, top:10, left:10, scrollbars:'yes'}, true);}
function popTV (){popUpWindow('http://www.almiron.es/es/A_imas/video/video_almiron.html','anuncio',{width:325,height:245,top:100,left:100});}
function promo (){popUpWindow('http://www.almiron.es/es/almiron3crecimiento/index.html','promo',{width:693,height:541,top:100,left:100});}
function promo_descubre (){popUpWindow('http://www.almiron.es/es/almiron3crecimiento/consigue_almiron_gratis.html','promo',{width:693,height:541,top:100,left:100});}
//
function promo_lego_bases_legales (){return popUpWindow('bases_legales_promo_lego.pdf','avisoLegal',{resizable:'yes',width:500,height:382,top:100,left:100, scrollbars:'yes'});}
//

function escucharmusica1 (){return popUpWindow('A_descargas/musbb/musica_almiron_theme.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica2 (){return popUpWindow('A_descargas/musbb/musica_sleepy_baby_and_the_sea.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica3 (){return popUpWindow('A_descargas/musbb/musica_tender_italian_concerto.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica4 (){return popUpWindow('A_descargas/musbb/lovely_little_night_music.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica5 (){return popUpWindow('A_descargas/musbb/musica_magical_singing_baby.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}

function escucharmusica6 (){return popUpWindow('A_descargas/musbb/musica_free_as_a_bird.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica7 (){return popUpWindow('A_descargas/musbb/musica_im_going_to_sleep_now.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica8 (){return popUpWindow('A_descargas/musbb/musica_lullaby.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica9 (){return popUpWindow('A_descargas/musbb/musica_my_first_blues.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}
function escucharmusica10 (){return popUpWindow('A_descargas/musbb/musica_swing_baby_swing.html','',{width:350, height:100,top:100,left:100, resizable:'yes', scrollbars:'no'});}


//



function HandleFileButtonClick(){
        document.frmUpload.miIma.click();
        document.frmUpload.txtFakeText.value = document.frmUpload.miIma.value;
    }
 
/*para comprobacion del formulario*/
//define los caracteres de espacios en blanco;
	var whiteSpace = " \t\n\r";
function isEmpty(s){
	 	var i;
		if ((s == null) || (s.length == 0))
			{
		return true;
				//busca la cadena para comprobar que tenga caracteres
				//que no sean espacios en  blanco
			}

		for(i = 0; i < s.length; i++){
				var c = s.charAt (i);
				if(whiteSpace.indexOf (c) == -1){
					return false;
				}
			}
		return true;
			//todos los caracteres son espacios en blanco
	}
	//

function email (field, nomf)
{
	
	//para validar e mail
		var positionOfAt;
		var s = field.value;
		if(isEmpty(s))
		{
			alert ("Debes ingresar la dirección de email valida");
			field.focus();
			return false;
		}
		positionOfAt = s.indexOf ('@',1);
		if ((positionOfAt == -1) || (positionOfAt == (s.length-1))){
		  alert ('dirección de e-mail no valida');
		  field.focus()
		  return false;
		}
	return true;
	}
	
	
	function verificarNacimiento (){
			/* la forma de verificar el formato es la que ya comentamos */

		
			var f = document.formulario.dd_bebe.value + "/" + document.formulario.mm_bebe.value + "/" + document.formulario.yy_bebe.value;
			
			var field = document.formulario.dd_bebe;

			re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
			if(f.length==0 || !re.exec(f))
			{
				alert("La fecha no tiene formato correcto.")
				field.focus ();
				return false;
			}
			 
			/* comprobamos que la fecha es válida */
			var d = new Date()
			/* la función tiene como entrada: año, mes, día */
			d.setFullYear(f.substring(6,10), 
				      f.substring(3,5)-1,
				      f.substring(0,2))
			 
			/* ¿el mes del objeto Date es el mes introducido por el usuario?
			   OJO: getMonth() devuelve el número de mes del 0 al 11
			 
			   ¿el día del objeto Date es el día introducido por el usuario?
			   OJO: getDate() devuelve el día del mes */
			if(d.getMonth() != f.substring(3,5)-1 
				|| d.getDate() != f.substring(0,2))
			{
				alert("Fecha no válida.")
				field.focus ();
				return false;
			}
			
			return true;
	}
	
	
	function validateZIP(field) {
			var valid = "0123456789";
			var hyphencount = 0;
			var f = field.value;	
			if (f.length!=5 && field.length!=10) {
			alert("Por favor, entre un codigo de 5 digitos");
			field.focus();
			return false;
			}
			
			for (var i=0; i < f.length; i++) {
				
					temp = "" + f.substring(i, i+1);
					
					if (temp == "-") hyphencount++;
					
					if (valid.indexOf(temp) == "-1") {
						alert("Codigo Postal no valido. Por favor, entrelo otra vez.");
						field.focus();
						return false;
					}
			}
			return true;
	} 

function checkPw(field1, field2) {
	
		
		pw1 =	field1.value;
		pw2 = field2.value;
		if(pw1=='')
		{
		 alert('Introduzca su clave');
		 field1.focus();
		 return false;
		}
		else if(pw2=='')
		{
		 alert('Introduzca la repeticion de su clave');
		 field2.focus();
		 return false;
		}
		else if (pw1 != pw2) {
		alert ("\nlas contraseqas introducidas no coinciden. Por favor, vuelva a introducirlas.")
		return false;
		}
		return true;
} 
	/*
	*los campos del formularios
	*/
	
function validate(nombre_form, destinatario, remitente, asunto )
	{
		if (!email(document.forms[nombre_form][destinatario], "destinatario")){
				return false;
			}
			
		if (!email(document.forms[nombre_form][remitente], "remitente")){
				return false;
			}
			
		if (isEmpty(document.forms[nombre_form][asunto].value))
			{
				alert("por favor debes ingresar una frase en el campo asunto");
				 document.forms[nombre_form][asunto].focus();
				return false;
			}

			
		return true;
	}

function validateRegister()
	{
		
		var validationsblank = ["nombre", "apellido1", "nombre_via", "numero_via", "poblacion", "nombre_bebe"];
		//verificamos espacios en blanco
		
		for (var i=0; i < validationsblank.length; i++){
				var temp = eval ("document.formulario." + validationsblank[i]);
				if (isEmpty(temp.value))
				{
					alert("Este campo no puede quedar vacio");
					temp.focus();
					return false;
				}
		}
		
		if (!validateZIP (document.formulario.codigo_postal)){
			return false;
		}
		
		if (!checkPw(document.formulario["password"], document.formulario["password2"])){
			return false;
		}
		
		if (!email(document.formulario["mail_cli"])){
				return false;
		}
		
		
		if (!verificarNacimiento ()){
			return false;
		}

		return true;
	}	
	
	
function validate2(f) {
	
	errors = false;
	msg = 'Se han encontrado los siguientes\nerrores en el formulario:\n\n';
	
	
	for (var i=0; i < f.length; i++) {
		e = f.elements[i];
		if ((e.type=="text") || (e.type == "textarea")) {
		      if (((e.value == null) ||(e.value == "") || esVacio(e.value))  && (e.optional=="false")) {
			msg += '-- '+e.label+' es un campo obligatorio.\n';
			errors = true;
			continue;
		      }
		}
		
	}

	  if (!errors)
	  {   
		if (!email(f["mail_dest"], "destinatario") || !email(f["mail_remite"], "remitente") ) return false;
		return true;
	  }else{
		  alert(msg  + "\n por favor corrige estos errores e intentalo nuevamente");
		  return false;
	  } 

}	


/**
*para la campaña del dia de la madre
*/
 function validate3(f) {
  
	var auxArr = ["mail_dest", "mail_remite", "mail_asunto",
	"nombre", "apellidos", "nombre_via", "numero_via",
	"codigo_postal", "poblacion", "provincia" , "telefono_fijo", 
	"nombre_bebe", "dd_bebe", "mm_bebe", "yy_bebe"];
	
	var labelsArr = ["mail del destinatario", "mail del remitente", "asunto" ,
	"nombre", "apellidos" , "nombre de vía", "numero de la vía", 
	"codigo postal", "poblacion", "provincia" , "telefono fijo",
	"nombre del bebe", "día de naciomiento del bebe", "mes  de naciomiento del  bebe", "año de naciomiento del  bebe"
	]
	
	var  errors = false;
	var  msg = 'Se han encontrado los siguientes\nerrores en el formulario:\n\n';
  
	for (i=0; i < auxArr.length; i++) {
		e = f.elements[auxArr[i]];
		if ((e.type=="text") || (e.type == "textarea")) {
		      if (((e.value == null) ||(e.value == "") || esVacio(e.value))) {
			msg += '-- '+ labelsArr [i] +'\n';
			errors = true;
			continue;
		      }
		}
	}
		
	 if (!errors){   
		 if (!email(f["mail_dest"], "destinatario") || !email(f["mail_remite"], "remitente") ) return false;
		return true;
	  }else{
		  alert (msg  + "\n\nson campos obligatorios \n por favor corrige estos errores e inténtalo nuevamente");
		  return false;
	  }
}	


function validateformLogin (nombre_form, _email, pass )
{
		if (!email(document.forms[nombre_form][_email], _email)){
				return false;
			}
			
			
		if (isEmpty(document.forms[nombre_form][pass].value))
			{
				alert("por favor debes ingresar una cotraseña");
				 document.forms[nombre_form][pass].focus();
				return false;
			}

			
		return true;
}


function validateformComparte (nombre_form, tu_nombre, tu_email, su_nombre, su_email )
{
		
			
		if (isEmpty(document.forms[nombre_form][tu_nombre].value))
			{
				alert("por favor debes ingresar tu nombre");
				 document.forms[nombre_form][tu_nombre].focus();
				return false;
			}
			
		if (!email(document.forms[nombre_form][tu_email], tu_email)){
				return false;
			}
			
			

		if (isEmpty(document.forms[nombre_form][su_nombre].value))
			{
				alert("Por favor debes ingresar el nombre de la persona a quien se lo enviaras.");
				 document.forms[nombre_form][su_nombre].focus();
				return false;
			}
			
			
		if (!email(document.forms[nombre_form][su_email ], su_email )){
				return false;
			}

			
		return true;
}

/**
*	para la firma en la carta 
*	
*/
function frasecarta (nombre_form, imagen, fras){
	var ima = document.forms[nombre_form][imagen];
	var frase = document.forms[nombre_form][fras];
	
	if(isEmpty(ima.value)){
			alert ("debes ingresar una imagen.");
			ima.focus();
			return false;
		}
	
	if(isEmpty(frase.value)){
			alert ("No has puesto la frase…");
			frase.focus();
			return false;
		}
	return true;
}
	

	
/**/
function menuhandler(value){
	switch (value){
		case 0:
			window.location.href  = "club_almiron_zona_familiar_album_fotos.php";
		break;
		case 1:
			window.location.href  = "club_almiron_zona_familiar_musica_bebe.php";
		break;
		case 2:
			window.location.href  = "club_almiron_zona_familiar_calendario.php";
		break;
		case 3:
			window.location.href  = "club_almiron_zona_familiar_alimentos.php";
		break;
			case 4:
			window.location.href  = "club_almiron_zona_familiar_tabla_denticion.php";
		break;

	}
}


/*para el pie */
function piejumpto(x){if (document.prodpie.selCombo.value != "null") {document.location.href = x}}

/*menu de la zona familiar*/
function btnZsHandler(){
	var divmenu = document.getElementById('menu_zona_familiar');
	var imabtnhandler = document.images['btnhandler'];
	if (divmenu.style.display == ''){
			divmenu.style.display = 'none';
			imabtnhandler.src = "A_imas/ClubNutricia/menu_zon_fam/btn_down.jpg";
	}else{
			divmenu.style.display = '';
			imabtnhandler.src = "A_imas/ClubNutricia/menu_zon_fam/btn_up.jpg";
	}
}
				

	