function Abrir(ubicacion,nombre,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,status=yes,MenuBar=yes,ToolBar=no,resizable';
	win = window.open(ubicacion,nombre,opciones);
	win.window.focus();
}

function AbrirCat(ubicacion,nombre,w,h){ alert('ventana');
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='fullscreen,scrollbars=yes,status=yes,MenuBar=yes,ToolBar=no,resizable';
	win = window.open(ubicacion,nombre,opciones);
	win.window.focus();
}

function IsNumeric(valor)
{
	var log=valor.length; var sw="S";
	for (x=0; x<log; x++)
	{ v1=valor.substr(x,1);
	v2 = parseInt(v1);
	//Compruebo si es un valor numérico
	if (isNaN(v2)) { sw= "N";}
	}
	if (sw=="S") {return true;} else {return false; }
}
var diaslap=false;
var meseslap=false;
var horaslap=false;
var minutoslap=false;
function formateafechahora(fecha)
{
	var long = fecha.length;
	var dia;
	var mes;
	var ano;
	var hora;
	var min;
	var seg;
	if ((long>=2) && (diaslap==false)) { dia=fecha.substr(0,2);
	if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); diaslap=true; }
	else { fecha=""; diaslap=false;}
	}
	else
	{ dia=fecha.substr(0,1);
	if (IsNumeric(dia)==false)
	{fecha="";}
	if ((long<=2) && (diaslap=true)) {fecha=fecha.substr(0,1); diaslap=false; }
	}
	if ((long>=5) && (meseslap==false))
	{ mes=fecha.substr(3,2);
	if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); meseslap=true; }
	else { fecha=fecha.substr(0,3);; meseslap=false;}
	}
	else { if ((long<=5) && (meseslap=true)) { fecha=fecha.substr(0,4); meseslap=false; } }
	if (long>=7)
	{ ano=fecha.substr(6,4);
	if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); }
	else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } }
	}
	if (long>=10)
	{
		fecha=fecha.substr(0,19);
		dia=fecha.substr(0,2);
		mes=fecha.substr(3,2);
		ano=fecha.substr(6,4);
		// Año no bisiesto y es febrero y el dia es mayor a 28
		if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; }
	}

	if ((long>=13) && (horaslap==false)) 
  { hora=fecha.substr(11,2);
	if ((IsNumeric(hora)==true) && (hora<=23) && (hora>=00)) { fecha=fecha.substr(0,13)+":"+fecha.substr(14,5); horaslap=true; }
	else { fecha=fecha.substr(0,11); horaslap=false;} 
	} 
	else
	{ hora=fecha.substr(11,2);
	if (IsNumeric(hora)==false)
	{fecha=fecha.substr(0,11);}
	if ((long<=13) && (horaslap=true)) {fecha=fecha.substr(0,12); horaslap=false; }
	} 
	if ((long>=16) && (minutoslap==false))
	{ min=fecha.substr(14,2);
	if ((IsNumeric(min)==true) && (min<=59) && (min>=00)) { fecha=fecha.substr(0,16)+":"+fecha.substr(17,2); minutoslap=true; }
	else { fecha=fecha.substr(0,14);; minutoslap=false;}
	}
	else { if ((long<=16) && (minutoslap=true)) { fecha=fecha.substr(0,15); minutoslap=false; } }
	if (long>=18)
	{ seg=fecha.substr(17,2);
	if (IsNumeric(seg)==false) { fecha=fecha.substr(0,19); }
	else { if (long==19){ if ((seg<0) || (seg>59)) { fecha=fecha.substr(0,17); } } }
	}

//alert('fecha9:'+fecha);  
	return (fecha);
}

function formateafecha(fecha)
{
	var long = fecha.length;
	var dia;
	var mes;
	var ano;
	if ((long>=2) && (diaslap==false)) { dia=fecha.substr(0,2);
	if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); diaslap=true; }
	else { fecha=""; diaslap=false;}
	}
	else
	{ dia=fecha.substr(0,1);
	if (IsNumeric(dia)==false)
	{fecha="";}
	if ((long<=2) && (diaslap=true)) {fecha=fecha.substr(0,1); diaslap=false; }
	}
	if ((long>=5) && (meseslap==false))
	{ mes=fecha.substr(3,2);
	if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); meseslap=true; }
	else { fecha=fecha.substr(0,3);; meseslap=false;}
	}
	else { if ((long<=5) && (meseslap=true)) { fecha=fecha.substr(0,4); meseslap=false; } }
	if (long>=7)
	{ ano=fecha.substr(6,4);
	if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); }
	else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } }
	}
	if (long>=10)
	{
		fecha=fecha.substr(0,10);
		dia=fecha.substr(0,2);
		mes=fecha.substr(3,2);
		ano=fecha.substr(6,4);
		// Año no viciesto y es febrero y el dia es mayor a 28
		if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; }
	}
	return (fecha);
}

function formateahora(tiempo)
{
	var long = tiempo.length;
	var hora;
	var min;
	var seg;
	if ((long>=2) && (horaslap==false)) { hora=tiempo.substr(0,2);
	if ((IsNumeric(hora)==true) && (hora<=23) && (hora>=00)) { tiempo=tiempo.substr(0,2)+":"+tiempo.substr(3,5); horaslap=true; }
	else { tiempo=""; horaslap=false;}
	}
	else
	{ hora=tiempo.substr(0,1);
	if (IsNumeric(hora)==false)
	{tiempo="";}
	if ((long<=2) && (horaslap=true)) {tiempo=tiempo.substr(0,1); horaslap=false; }
	}
	if ((long>=5) && (minutoslap==false))
	{ min=tiempo.substr(3,2);
	if ((IsNumeric(min)==true) &&(min<=59) && (min>=00)) { tiempo=tiempo.substr(0,5)+":"+tiempo.substr(6,2); minutoslap=true; }
	else { tiempo=tiempo.substr(0,3);; minutoslap=false;}
	}
	else { if ((long<=5) && (minutoslap=true)) { tiempo=tiempo.substr(0,4); minutoslap=false; } }
	if (long>=7)
	{ seg=tiempo.substr(6,4);
	if (IsNumeric(seg)==false) { tiempo=tiempo.substr(0,6); }
	else { if (long==8){ if ((seg<0) || (seg>59)) { tiempo=tiempo.substr(0,6); } } }
	}
	return (tiempo);
}

function sqlize(fechahora) 
{
  fechahora=fechahora.substr(6,4)+'-'+fechahora.substr(3,2)+'-'+fechahora.substr(0,2)+' '+fechahora.substr(11,8)
  return fechahora;
}

function cambiaTipo (wmod,tipo,idf,sbc,foto,sq) { 
  var modo=document.getElementById('listmode').value; 
  var src='http://www.auditoriumonline.com/eventos_list.php?'+idf+sbc+'&type='+tipo+'&mode='+modo+'&foto='+foto+'&sq='+sq;   
  document.getElementById(wmod).src = src;
}

function dameTipo () {
  return document.getElementById('listmode').value;
}

//Carga ventana con post desde js
function loadWindow(url) { 
  document.form_start.action=url;
  document.getElementById('form_start').submit();
}

// Modifica las condiciones del iframe de la lista de videos
function cambiaListaVideo(tipo,idaf,lang,dir,thm,cls,sq) {

  var base='http://www.auditoriumonline.com/';
  var src=base+'videos_list.php?idaf='+idaf+'&lang='+lang+'&dir='+dir+'&thm='+thm+'&cls='+cls+'&sq='+sq;

  if (thm == 1 ) {
    document.getElementById('dv_resaltado').style.display = 'none';
    document.getElementById('dv_oyente').style.display = '';
    document.getElementById('dv_ponente').style.display = 'none';
    document.getElementById('dv_afiliado').style.display = 'none';
  } else if (thm == 2) {
    document.getElementById('dv_resaltado').style.display = 'none';
    document.getElementById('dv_oyente').style.display = 'none';
    document.getElementById('dv_ponente').style.display = '';
    document.getElementById('dv_afiliado').style.display = 'none';
  } else if (thm == 3) {
    document.getElementById('dv_resaltado').style.display = 'none';
    document.getElementById('dv_oyente').style.display = 'none';
    document.getElementById('dv_ponente').style.display = 'none';
    document.getElementById('dv_afiliado').style.display = '';
  } else  {
    document.getElementById('dv_resaltado').style.display = '';
    document.getElementById('dv_oyente').style.display = 'none';
    document.getElementById('dv_ponente').style.display = 'none';
    document.getElementById('dv_afiliado').style.display = 'none';
  }
  document.getElementById(tipo).src = src;
}

// cambia el vídeo que se está mostrando
function cambiavideo(idaf,lang,idCanal,idVideo,autoPlay) {
  var vidSrc='http://www.auditoriumonline.com/video_frame.php?idaf='+idaf+'&lang='+lang+'&idCanal='+idCanal+'&idVideo='+idVideo+'&autoPlay=';
  var strSrc='<iframe id="video_F" name="video_F" width="780" height="550" align="absmiddle" frameborder="0" scrolling="no" src="'+vidSrc+'1"></iframe>';
  window.top.document.getElementById('dv_tmbhn').style.display='none';
  window.top.document.getElementById('dv_video').style.display='';
  window.top.document.getElementById('dv_video').innerHTML=strSrc;
//  window.top.document.getElementById('video_F').src = vidSrc;
}

// Modifica las condiciones del iframe de la lista de eventos
function cambiaListaEvento(tipo,idf,sbc,mode,opc,status,foto,sq) {
  var modollamada=mode;
  if (status!='0') {
    modollamada=document.getElementById('listmode').value;
  }
  
//alert(modollamada);
  var base='http://www.auditoriumonline.com/';
  var src=base+'eventos_list.php?'+idf+sbc+'&mode='+modollamada+'&opc='+opc+'&status='+status+'&foto='+foto+'&tipo='+tipo;
  if( foto == true) {
    if (mode == 'N' ) {         // PrÃ³ximos eventos
      document.getElementById('foto_lado').src = base+'images/proximos_foto.jpg';
      document.getElementById('imagen_titulo').src = base+'images/proximos1.gif';
  //    document.getElementById('imagen_titulo').width = '133';
    } else if (mode == 'H' ) {  // Historial de eventos
      document.getElementById('foto_lado').src = base+'images/historial_foto.jpg';
      document.getElementById('imagen_titulo').src = base+'images/historial1.gif';
  //    document.getElementById('imagen_titulo').width = '156';
    } else if (mode == 'W' ) {  // Presentacion Webs
      document.getElementById('foto_lado').src = base+'images/webs_foto.jpg';
      document.getElementById('imagen_titulo').src = base+'images/webs.gif';
  //    document.getElementById('imagen_titulo').width = '199';
    } else if (mode == 'F' ) {  // FormaciÃ³n
      document.getElementById('foto_lado').src = base+'images/formacion_foto.jpg';
      document.getElementById('imagen_titulo').src = base+'images/formacion.gif';
  //    document.getElementById('imagen_titulo').width = '204';
    } else if (mode == 'V' ) {  // Ferias Virtuales
      document.getElementById('foto_lado').src = base+'images/ferias_foto.jpg';
      document.getElementById('imagen_titulo').src = base+'images/ferias.gif';
  //     document.getElementById('imagen_titulo').width = '204';
    }
  }
  
  document.getElementById('listmode').value = mode;
  document.getElementById(tipo).src = src;

  document.getElementById('comunicacionxml').src='../../includes/opciones_tipos.php?idf='+idf+'&mode='+mode+'&opc='+opc+'&status='+status; 


  if ( status == '0' && opc != '' ) {
    document.getElementById('rd_act').checked='checked';
    document.getElementById('rd_iac').checked='';
    document.getElementById('rd_pay').checked='';
  }

  
}

/*
* ValidaEmail: Comprobamos que siga el patrón de una direccióin de email válida
*/
function ValidaEmail(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if (regex.test(src)) {
		return true;
	} else {
		return false;
	}
}

// calcula diferencia entre 2 horas (por defecto en minutos)
function TimeDiff (t1,t2) {
  var hdiff=0;
  var mdiff=0;
  var mtotl=0;
  var h1=t1.substring(0,2);
  var m1=t1.substring(3,5);
  var h2=t2.substring(0,2);
  var m2=t2.substring(3,5);
  ph1 = parseInt(h1);
  ph2 = parseInt(h2);
  pm1 = parseInt(m1);
  pm2 = parseInt(m2);

  if( ph1 > ph2) ph2 = ph2 + 24;
  if(pm2 < pm1){
    pm2 = pm2 + 60;
    ph2 = ph2 - 1;
  } 

  mdiff = pm2 - pm1;
  hdiff = (ph2 - ph1);
  mtotl = ( hdiff * 60 )  + mdiff;
  
  return mtotl;
}

function desActiva(modulo) {
  var oy=document.getElementById('oy').value;
  var po=document.getElementById('po').value;
  var af=document.getElementById('af').value;
  var base=document.getElementById('base').value;
  
  if (modulo == 'OY') {
    oy=0;
  }
  if (modulo == 'PO') {
    po=0;
  }
  if (modulo == 'AF') {
    af=0;
  }
  window.location=base+'/index.php?af='+af+'&po='+po+'&oy='+oy;
  
}


/* FUNCIONES DE GESTION DE PAGINAS EN LISTADOS */

// Pagina Siguiente
function  nextPage() {
  document.getElementById('actpag').value = Number(document.getElementById('actpag').value) + 1;
  document.getElementById('form_filtro').submit();
}

// Pagina anterior
function  prevPage() {
  document.getElementById('actpag').value = document.getElementById('actpag').value - 1;
  document.getElementById('form_filtro').submit();
}

// Gestionar la clasificación de página
function sortPage(sortValue,startdir) {
  var sdir = 'ASC';
  if ( startdir ) {
    sdir = startdir;
  }
  if ( document.getElementById('order').value == sortValue ) {  // ya esta ordenado por este campo, cambiamos dirección
    if ( document.getElementById('sdir').value == 'ASC' ) {
      document.getElementById('sdir').value = 'DESC' ;
    } else {
      document.getElementById('sdir').value = 'ASC' ;
    }
  } else {  // No estaba ordenado, lo ordenamos  por omision ascendente  segun lo que le pasemos en startdir
    document.getElementById('order').value =  sortValue;
    document.getElementById('sdir').value = sdir ;
  }
  document.getElementById('actpag').value = 1;
  document.getElementById('form_filtro').submit();
}

// Llamada a Mantenimiento
function  MaintProc() {
alert('bb');
/*
alert(ida);
  document.getElementById('id').value = id;
alert(actiona);
  document.getElementById('action').value = action;
alert(modulea);
  document.getElementById('form_maint').value = module;
alert('fin');
//  document.getElementById('form_filtro').submit();
*/
}
