function isEmailAddress(theElement){
	var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s)){
		return true;
	}else{
		return false;
	}
} 

// c es un digito 
function isDigit (c) 
{   return ((c >= "0") && (c <= "9")) 
} 

// s es un numero entero (con o sin signo) 
function isInteger (s) 
{   var i; 
     
    for (i = 0; i < s.length; i++) 
    {    
        var c = s.charAt(i); 
        if( i != 0 ) { 
            if (!isDigit(c)) return false; 
        } else {  
            if (!isDigit(c) && (c != "-") || (c == "+")) return false; 
        } 
    } 
    return true; 
}

function stripCharsInBag (s, bag) 
{   var i; 
    var returnString = ""; 

    // Buscar por el string, si el caracter no esta en "bag",  
    // agregarlo a returnString 
     
    for (i = 0; i < s.length; i++) 
    {   var c = s.charAt(i); 
        if (bag.indexOf(c) == -1) returnString += c; 
    } 

    return returnString; 
}

// caracteres admitidos en nos de telefono 
var phoneChars = "()-+ "; 

// s es numero de telefono valido 
function isPhoneNumber (theElement) 
{   
		var s = theElement.value;
		var modString; 
    modString = stripCharsInBag( s, phoneChars ); 
    return (isInteger(modString)) 
} 


function formcheck() {
	var err = '';
	
	/*Reset*/
	document.getElementById('nombre_Error').innerHTML='';
	document.getElementById('email_Error').innerHTML='';
	document.getElementById('mensaje_Error').innerHTML='';

	if (document.frm004.nombre.value=='' || document.frm004.nombre.value=='Nombre y apellido...') { err = '1'; document.getElementById('nombre_Error').innerHTML='Ingrese Nombre';}
	if (document.frm004.email.value=='' || document.frm004.email.value=='Email...') { err = '1'; document.getElementById('email_Error').innerHTML='Ingrese E-mail';}
	
	var validMail = isEmailAddress(document.frm004.email);
	if( !validMail ){ err = '1'; document.getElementById('email_Error').innerHTML='Ingrese E-mail'; }
	
	if (document.frm004.mensaje.value=='' || document.frm004.mensaje.innerHTML=='Mensaje...') { err = '1'; document.getElementById('mensaje_Error').innerHTML='Ingrese Mensaje';}
	
	if (err!='') {
		return false; 
	} else {
		document.frm004.SB001.disabled = true;
		document.frm004.submit();
	}
}

function initFancyBox(){
	$(".inscripcion_boton").fancybox({
	'titlePosition'		: 'inside',
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'overlayShow'		  : false,
	'onComplete'      : function(itemArray, selectedIndex, selectedOpts) {
		document.frmPopup_2.curso_interes.value = itemArray[selectedIndex].getAttribute('alt');
		document.frmPopup_3.curso_interes.value = itemArray[selectedIndex].getAttribute('alt');
		document.frmPopup_8.clinica_interes.value = itemArray[selectedIndex].getAttribute('alt');
		document.frmPopup_13.charla_interes.value = itemArray[selectedIndex].getAttribute('alt');
		
	},
	'onClosed'      : function() {

		document.frmPopup_2.nombre.value='Nombre completo: ';
		document.frmPopup_2.telefono.value='Teléfono: ';
		document.frmPopup_2.mail.value='Mail: ';
		document.frmPopup_2.ciudad.value='Ciudad: ';
		document.frmPopup_2.provincia.value='Provincia: ';
		document.frmPopup_2.pais.value='País: ';
		document.frmPopup_2.curso_interes.value='Curso de interés: ';
		document.frmPopup_2.mensaje.value='Mensaje...';
		document.frmPopup_2.SB2.disabled = false;
		document.getElementById('popup_2_mensaje').innerHTML = '';
		
		document.frmPopup_3.nombre.value='Nombre completo: ';
		document.frmPopup_3.telefono.value='Teléfono: ';
		document.frmPopup_3.mail.value='Mail: ';
		document.frmPopup_3.ciudad.value='Ciudad: ';
		document.frmPopup_3.provincia.value='Provincia: ';
		document.frmPopup_3.pais.value='País: ';
		document.frmPopup_3.curso_interes.value='Curso de interés: ';
		document.frmPopup_3.mensaje.value='Mensaje...';
		document.frmPopup_3.SB3.disabled = false;
		document.getElementById('popup_3_mensaje').innerHTML = '';
		
		document.frmPopup_8.nombre.value='Nombre completo: ';
		document.frmPopup_8.telefono.value='Teléfono: ';
		document.frmPopup_8.mail.value='Mail: ';
		document.frmPopup_8.clinica_interes.value='Clinica de interés: ';
		document.frmPopup_8.mensaje.value='Mensaje...';
		document.frmPopup_8.SB8.disabled = false;
		document.getElementById('popup_8_mensaje').innerHTML = '';
		
		document.frmPopup_13.nombre.value='Nombre completo: ';
		document.frmPopup_13.telefono.value='Teléfono: ';
		document.frmPopup_13.mail.value='Mail: ';
		document.frmPopup_13.charla_interes.value='Charla de interés: ';
		document.frmPopup_13.mensaje.value='Mensaje...';
		document.frmPopup_13.SB13.disabled = false;
		document.getElementById('popup_13_mensaje').innerHTML = '';
		
	}
	});
}

$(document).ready(function() {

initFancyBox();

$(".mapa_boton").fancybox({
'titlePosition'		: 'inside',
'transitionIn'		: 'none',
'transitionOut'		: 'none',
'overlayShow'		  : false,
'onComplete'      : function() {
	initialize();
}
});


});


function formcheckPopup2() {
	var err = '';
	
	/*Reset*/
	document.getElementById('popup_2_nombre_Error').innerHTML='';
	document.getElementById('popup_2_telefono_Error').innerHTML='';
	document.getElementById('popup_2_mail_Error').innerHTML='';
	document.getElementById('popup_2_ciudad_Error').innerHTML='';
	document.getElementById('popup_2_provincia_Error').innerHTML='';
	document.getElementById('popup_2_pais_Error').innerHTML='';
	document.getElementById('popup_2_curso_Error').innerHTML='';
	document.getElementById('popup_2_mensaje_Error').innerHTML='';

	if (document.frmPopup_2.nombre.value=='' || document.frmPopup_2.nombre.value=='Nombre completo: ') { err = '1'; document.getElementById('popup_2_nombre_Error').innerHTML='Ingrese Nombre';}
	if (document.frmPopup_2.telefono.value=='' || document.frmPopup_2.telefono.value=='Teléfono: ') { err = '1'; document.getElementById('popup_2_telefono_Error').innerHTML='Ingrese Teléfono';}
	
	var validPhone = isPhoneNumber(document.frmPopup_2.telefono);
	if( !validPhone ){ err = '1'; document.getElementById('popup_2_telefono_Error').innerHTML='Ingrese Teléfono Correcto'; }
	
	if (document.frmPopup_2.mail.value=='' || document.frmPopup_2.mail.value=='Mail: ') { err = '1'; document.getElementById('popup_2_mail_Error').innerHTML='Ingrese Mail';}
	
	var validMail = isEmailAddress(document.frmPopup_2.mail);
	if( !validMail ){ err = '1'; document.getElementById('popup_2_mail_Error').innerHTML='Ingrese Mail';}
	
	if (document.frmPopup_2.ciudad.value=='' || document.frmPopup_2.ciudad.value=='Ciudad: ') { err = '1'; document.getElementById('popup_2_ciudad_Error').innerHTML='Ingrese Ciudad';}
	if (document.frmPopup_2.provincia.value=='' || document.frmPopup_2.provincia.value=='Provincia: ') { err = '1'; document.getElementById('popup_2_provincia_Error').innerHTML='Ingrese Provincia';}
	if (document.frmPopup_2.pais.value=='' || document.frmPopup_2.pais.value=='País: ') { err = '1'; document.getElementById('popup_2_pais_Error').innerHTML='Ingrese País';}
	if (document.frmPopup_2.curso_interes.value=='' || document.frmPopup_2.curso_interes.value=='Curso de interés: ') { err = '1'; document.getElementById('popup_2_curso_Error').innerHTML='Ingrese Curso de interés';}
	if (document.frmPopup_2.mensaje.value=='' || document.frmPopup_2.mensaje.innerHTML=='Mensaje...') { err = '1'; document.getElementById('popup_2_mensaje_Error').innerHTML='Ingrese Mensaje';}

	if (err!='') {
		return false; 
	} else {
		document.frmPopup_2.SB2.disabled = true;
		document.getElementById('popup_2_mensaje').innerHTML = '<img src="sonica/site_img/ajax-loader.gif">';
		$.ajax({
		type: "POST",
		cache: false,
		contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
		url: "sonica/ajax_cursos.php",
		data: "nombre="+document.frmPopup_2.nombre.value+"&telefono="+document.frmPopup_2.telefono.value+"&mail="+document.frmPopup_2.mail.value+"&ciudad="+document.frmPopup_2.ciudad.value+"&provincia="+document.frmPopup_2.provincia.value+"&pais="+document.frmPopup_2.pais.value+"&curso_interes="+document.frmPopup_2.curso_interes.value+"&mensaje="+document.frmPopup_2.mensaje.value+"&SX=P"
		}).done(function( msg ) {
			document.getElementById('popup_2_mensaje').innerHTML = msg; 
		});
		return false; 
	}
}

function formcheckPopup3() {
	var err = '';
	
	/*Reset*/
	document.getElementById('popup_3_nombre_Error').innerHTML='';
	document.getElementById('popup_3_telefono_Error').innerHTML='';
	document.getElementById('popup_3_mail_Error').innerHTML='';
	document.getElementById('popup_3_ciudad_Error').innerHTML='';
	document.getElementById('popup_3_provincia_Error').innerHTML='';
	document.getElementById('popup_3_pais_Error').innerHTML='';
	document.getElementById('popup_3_curso_Error').innerHTML='';
	document.getElementById('popup_3_mensaje_Error').innerHTML='';

	if (document.frmPopup_3.nombre.value=='' || document.frmPopup_3.nombre.value=='Nombre completo: ') { err = '1'; document.getElementById('popup_3_nombre_Error').innerHTML='Ingrese Nombre';}
	if (document.frmPopup_3.telefono.value=='' || document.frmPopup_3.telefono.value=='Teléfono: ') { err = '1'; document.getElementById('popup_3_telefono_Error').innerHTML='Ingrese Teléfono';}
	
	var validPhone = isPhoneNumber(document.frmPopup_3.telefono);
	if( !validPhone ){ err = '1'; document.getElementById('popup_3_telefono_Error').innerHTML='Ingrese Teléfono Correcto'; }
	
	if (document.frmPopup_3.mail.value=='' || document.frmPopup_3.mail.value=='Mail: ') { err = '1'; document.getElementById('popup_3_mail_Error').innerHTML='Ingrese Mail';}
	
	var validMail = isEmailAddress(document.frmPopup_3.mail);
	if( !validMail ){ err = '1'; document.getElementById('popup_3_mail_Error').innerHTML='Ingrese Mail';}
	
	if (document.frmPopup_3.ciudad.value=='' || document.frmPopup_3.ciudad.value=='Ciudad: ') { err = '1'; document.getElementById('popup_3_ciudad_Error').innerHTML='Ingrese Ciudad';}
	if (document.frmPopup_3.provincia.value=='' || document.frmPopup_3.provincia.value=='Provincia: ') { err = '1'; document.getElementById('popup_3_provincia_Error').innerHTML='Ingrese Provincia';}
	if (document.frmPopup_3.pais.value=='' || document.frmPopup_3.pais.value=='País: ') { err = '1'; document.getElementById('popup_3_pais_Error').innerHTML='Ingrese País';}
	if (document.frmPopup_3.curso_interes.value=='' || document.frmPopup_3.curso_interes.value=='Curso de interés: ') { err = '1'; document.getElementById('popup_3_curso_Error').innerHTML='Ingrese Curso de interés';}
	if (document.frmPopup_3.mensaje.value=='' || document.frmPopup_3.mensaje.innerHTML=='Mensaje...') { err = '1'; document.getElementById('popup_3_mensaje_Error').innerHTML='Ingrese Mensaje';}

	if (err!='') {
		return false; 
	} else {
		document.frmPopup_3.SB3.disabled = true;
		document.getElementById('popup_3_mensaje').innerHTML = '<img src="sonica/site_img/ajax-loader.gif">';
		$.ajax({
		type: "POST",
		cache: false,
		contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
		url: "sonica/ajax_cursos.php",
		data: "nombre="+document.frmPopup_3.nombre.value+"&telefono="+document.frmPopup_3.telefono.value+"&mail="+document.frmPopup_3.mail.value+"&ciudad="+document.frmPopup_3.ciudad.value+"&provincia="+document.frmPopup_3.provincia.value+"&pais="+document.frmPopup_3.pais.value+"&curso_interes="+document.frmPopup_3.curso_interes.value+"&mensaje="+document.frmPopup_3.mensaje.value+"&SX=P"
		}).done(function( msg ) {
			document.getElementById('popup_3_mensaje').innerHTML = msg; 
		});
		return false; 
		
	}
}


function formcheckPopup8() {
	var err = '';
	
	/*Reset*/
	document.getElementById('popup_8_nombre_Error').innerHTML='';
	document.getElementById('popup_8_telefono_Error').innerHTML='';
	document.getElementById('popup_8_mail_Error').innerHTML='';
	document.getElementById('popup_8_clinica_Error').innerHTML='';
	document.getElementById('popup_8_mensaje_Error').innerHTML='';

	if (document.frmPopup_8.nombre.value=='' || document.frmPopup_8.nombre.value=='Nombre completo: ') { err = '1'; document.getElementById('popup_8_nombre_Error').innerHTML='Ingrese Nombre';}
	if (document.frmPopup_8.telefono.value=='' || document.frmPopup_8.telefono.value=='Teléfono: ') { err = '1'; document.getElementById('popup_8_telefono_Error').innerHTML='Ingrese Teléfono';}
	
	var validPhone = isPhoneNumber(document.frmPopup_8.telefono);
	if( !validPhone ){ err = '1'; document.getElementById('popup_8_telefono_Error').innerHTML='Ingrese Teléfono Correcto'; }
	
	if (document.frmPopup_8.mail.value=='' || document.frmPopup_8.mail.value=='Mail: ') { err = '1'; document.getElementById('popup_8_mail_Error').innerHTML='Ingrese Mail';}
	
	var validMail = isEmailAddress(document.frmPopup_8.mail);
	if( !validMail ){ err = '1'; document.getElementById('popup_8_mail_Error').innerHTML='Ingrese Mail';}
	
	if (document.frmPopup_8.clinica_interes.value=='' || document.frmPopup_8.clinica_interes.value=='Clinica de interés: ') { err = '1'; document.getElementById('popup_8_clinica_Error').innerHTML='Ingrese Clinica de interés';}
	if (document.frmPopup_8.mensaje.value=='' || document.frmPopup_8.mensaje.innerHTML=='Mensaje...') { err = '1'; document.getElementById('popup_8_mensaje_Error').innerHTML='Ingrese Mensaje';}

	if (err!='') {
		return false; 
	} else {
		document.frmPopup_8.SB8.disabled = true;
		document.getElementById('popup_8_mensaje').innerHTML = '<img src="sonica/site_img/ajax-loader.gif">';
		$.ajax({
		type: "POST",
		cache: false,
		contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
		url: "sonica/ajax_clinicas.php",
		data: "nombre="+document.frmPopup_8.nombre.value+"&telefono="+document.frmPopup_8.telefono.value+"&mail="+document.frmPopup_8.mail.value+"&clinica_interes="+document.frmPopup_8.clinica_interes.value+"&mensaje="+document.frmPopup_8.mensaje.value+"&SX=P"
		}).done(function( msg ) {
			document.getElementById('popup_8_mensaje').innerHTML = msg; 
		});
		return false;
		
	}
}


function formcheckPopup13() {
	var err = '';
	
	/*Reset*/
	document.getElementById('popup_13_nombre_Error').innerHTML='';
	document.getElementById('popup_13_telefono_Error').innerHTML='';
	document.getElementById('popup_13_mail_Error').innerHTML='';
	document.getElementById('popup_13_clinica_Error').innerHTML='';
	document.getElementById('popup_13_mensaje_Error').innerHTML='';

	if (document.frmPopup_13.nombre.value=='' || document.frmPopup_13.nombre.value=='Nombre completo: ') { err = '1'; document.getElementById('popup_13_nombre_Error').innerHTML='Ingrese Nombre';}
	if (document.frmPopup_13.telefono.value=='' || document.frmPopup_13.telefono.value=='Teléfono: ') { err = '1'; document.getElementById('popup_13_telefono_Error').innerHTML='Ingrese Teléfono';}
	
	var validPhone = isPhoneNumber(document.frmPopup_13.telefono);
	if( !validPhone ){ err = '1'; document.getElementById('popup_13_telefono_Error').innerHTML='Ingrese Teléfono Correcto'; }
	
	if (document.frmPopup_13.mail.value=='' || document.frmPopup_13.mail.value=='Mail: ') { err = '1'; document.getElementById('popup_13_mail_Error').innerHTML='Ingrese Mail';}
	
	var validMail = isEmailAddress(document.frmPopup_13.mail);
	if( !validMail ){ err = '1'; document.getElementById('popup_13_mail_Error').innerHTML='Ingrese Mail';}
	
	if (document.frmPopup_13.charla_interes.value=='' || document.frmPopup_13.charla_interes.value=='Charla de interés: ') { err = '1'; document.getElementById('popup_13_clinica_Error').innerHTML='Ingrese Charla de interés';}
	if (document.frmPopup_13.mensaje.value=='' || document.frmPopup_13.mensaje.innerHTML=='Mensaje...') { err = '1'; document.getElementById('popup_13_mensaje_Error').innerHTML='Ingrese Mensaje';}

	if (err!='') {
		return false; 
	} else {
		document.frmPopup_13.SB13.disabled = true;
		document.getElementById('popup_13_mensaje').innerHTML = '<img src="sonica/site_img/ajax-loader.gif">';
		$.ajax({
		type: "POST",
		cache: false,
		contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
		url: "sonica/ajax_charlas.php",
		data: "nombre="+document.frmPopup_13.nombre.value+"&telefono="+document.frmPopup_13.telefono.value+"&mail="+document.frmPopup_13.mail.value+"&charla_interes="+document.frmPopup_13.charla_interes.value+"&mensaje="+document.frmPopup_13.mensaje.value+"&SX=P"
		}).done(function( msg ) {
			document.getElementById('popup_13_mensaje').innerHTML = msg; 
		});
		return false;
		
	}
}

$(function() {
$('a.itemMenu').click(function(e) {

$.ajax({
  url: $(this).attr('alt')+$(this).attr('rel'),
	cache: false,
  success: function(data) {
		var $boxes = $('.contenidoOculto').html(data); //Los items que traigo
		var $boxesAca = $('.contenidoOculto').find('.noticia');
		var $items = $('.contenido').find('.noticia'); //Los items que tengo
		
		//Recorro cada item que tengo
		$items.each(function(index, value) { 	
			var elm = $(this);
			var idActual = $(this).attr('rel'); //Obtengo el ID del Elemento actual
			
			$boxesAca.each(function(index2, value2) { 
				//Comparo si ese id esta en el set que traigo por ajax.
				if(idActual == $(this).attr('rel')){
					elm.attr('alt','1'); //En el set actual identico con rel=1 los items que vienen repetidos por ajax
					$(this).attr('alt','2'); //Identifco con rel=2 los items del set que traigo por ajax que ya se encontraban en el set actual.
				}
			});
			
		});
		
		//Tomo los items del set que traje por ajax, que NO tengan rel=2 y hago el append en el set actual
			var htmlNuevo = '';
			$('.contenidoOculto .noticia').each(function(index3,value3){
				if($(this).attr('alt') == '1'){
					htmlNuevo = htmlNuevo + '<div class="noticia">'+$(this).html()+'</div>';
				}
			});
			
			$('.contenido').append(htmlNuevo);
		
		var $itemsParaeliminar = $('.contenido').find('div[alt=2]'); //Los items que voy a eliminar
		
		$('.contenido').masonry( 'remove', $itemsParaeliminar );
		$('.contenido').masonry( 'reload' );
		
		//Cufon.refresh('.noticia h1');
		initFancyBox();
		$("a.lightbox").colorbox();
		
		$('.contenido .noticia').each(function(index4,value4){
			$(this).attr('alt','2');
		});
  }
});

});

$('.contenido').masonry({
// options
itemSelector : '.noticia',
columnWidth : 298,
isAnimated: true
});
});


function showItemsInternos(elm){
	$.ajax({
		url: $(elm).attr('alt')+$(elm).attr('rel'),
		cache: false,
		success: function(data) {
			var $boxes = $('.contenidoOculto').html(data); //Los items que traigo
			var $boxesAca = $('.contenidoOculto').find('.noticia');
			var $items = $('.contenido').find('.noticia'); //Los items que tengo
			
			//Recorro cada item que tengo
			$items.each(function(index, value) { 	
				var elm = $(this);
				var idActual = $(this).attr('rel'); //Obtengo el ID del Elemento actual
				
				$boxesAca.each(function(index2, value2) { 
					//Comparo si ese id esta en el set que traigo por ajax.
					if(idActual == $(this).attr('rel')){
						elm.attr('alt','1'); //En el set actual identico con rel=1 los items que vienen repetidos por ajax
						$(this).attr('alt','2'); //Identifco con rel=2 los items del set que traigo por ajax que ya se encontraban en el set actual.
					}
				});
				
			});
			
			//Tomo los items del set que traje por ajax, que NO tengan rel=2 y hago el append en el set actual
				var htmlNuevo = '';
				$('.contenidoOculto .noticia').each(function(index3,value3){
					if($(this).attr('alt') == '1'){
						htmlNuevo = htmlNuevo + '<div class="noticia">'+$(this).html()+'</div>';
					}
				});
				
				$('.contenido').append(htmlNuevo);
			
			var $itemsParaeliminar = $('.contenido').find('div[alt=2]'); //Los items que voy a eliminar
			
			$('.contenido').masonry( 'remove', $itemsParaeliminar );
			$('.contenido').masonry( 'reload' );
			
			//Cufon.refresh('.noticia h1');
			initFancyBox();
			$("a.lightbox").colorbox();
			
			$('.contenido .noticia').each(function(index4,value4){
				$(this).attr('alt','2');
			});
		}
	});
}

$("a.lightbox").colorbox();
