function validarEmail(email){
	var tmpArr = email.split('@')
	if(!tmpArr.length) return false
	if(!tmpArr[0]) return false
	if(!tmpArr[1]) return false
	tmpArrB = tmpArr[1].split('.')
	if(!tmpArrB.length) return false
	if(!tmpArrB[0]) return false	
	if(!tmpArrB[1]) return false	
	return true
}
function hideComent(id) {
	d = document.getElementById(id)
	if(!d){
		alert('err af3sdfawer')
		return false
	}else {
		d.style.visibility = 'hidden';		
	}
}
function extraerExtensionDeArchivo (nombreArchivo) {
	return nombreArchivo.substring(nombreArchivo.lastIndexOf('.')+1,nombreArchivo.length)
}
function extraerNombreDeArchivo (nombreArchivo) {
	return nombreArchivo.substring(nombreArchivo.lastIndexOf('/')+1,nombreArchivo.length)
}
function faqCambiarCat () {
	selObj=document.getElementById('combo_faq')
	if(!selObj.value)return
	self.self.location = '?sec='+selObj.value;
}
function addEvent(elm, evType, fn, useCapture){
	// PARA CREAR EVENTOS ONLOAD... Usado por tokenizer y sus amigos
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Please upgrade your browser to use full functionality on this page");
	}
}
function revisarLink(strLink){
	strLink = strLink.replace(/^\s*|\s*$/g,"")
	if(strLink=='http://')strLink=''
	return(strLink)
}
function seleccionarFila(fe, OnOff) {
	var row_on_color = '#F4B093';
	var row_off_color = '';
	var parent = fe.parentNode;
	if (OnOff == 'on') {
		row_color = row_on_color;
	} 
	else {
		row_color = row_off_color;
	}
	fe.style.background = row_color;
}	
// SECCIONES IDEO SITE - Sitio con secciones administrables
/*	Entender las secciones:
		En PHP está el objeto $arr_ideofolio_categorias_arbol (ver ideofolio_categorias_menu.php)
		En JS está arrSeccionesIdeoSite['id_'+id_cont]
			.id_cont 
			.nombre 
			.parent 
			.nivel
			.innerHtmlMenuDesplegable // Si es menú de primer nivel
*/
var arrSeccionesIdeoSite = new Array() 
function seccionIdeoSite (id_cont,parent,nombre,nivel,tieneHijos,redireccionar) {
	this.id_cont = id_cont
	this.parent = parent
	this.nombre = nombre
	this.nivel = nivel
	if(parent==0 ){
		this.innerHtmlMenuDesplegable = '<div  style=" position:absolute; width:15px; height:0px; left: 641px; top: 105px; overflow: visible; z-index: 1; visibility: hidden;">'
				  +'<div lock=0 id="menu_'+id_cont+'" class="menu_desplegable" papa=0 hija=0 style=" height:1px; overflow: hidden;">'
					+'<ul id="tabla_desplegable" >'
						+'<tmp>'
					  +'</ul>'
				  +'</div>'
			+'</div>';
	}else {
		if (tieneHijos) {
			this.innerHtmlMenuDesplegable = '<div  style=" position:absolute; width:15px; height:0px; left: 641px; top: 105px; overflow: visible; z-index: 1; visibility: hidden;">'
					  +'<div lock=0 id="menu_'+id_cont+'" class="menu_desplegable" papa='+parent+' hija=0 style="height:1px; overflow: hidden;">'
						+'<ul id="tabla_desplegable" >'
							+'<tmp>'
						  +'</ul>'
					  +'</div>'
				+'</div>';
		}
		if (redireccionar) {
			tmpHref = redireccionar 
			tmpTarget = ' target="blank" '			
		}else {
			tmpHref = "?sec="+id_cont
			tmpTarget = ''
		}
		var tmpStr = arrSeccionesIdeoSite['id_'+parent].innerHtmlMenuDesplegable
		var tmpOnMouseOver = tieneHijos ? 'menutopsubmenu(\'menu_'+id_cont+'\',this.parentNode.id,135,0,this.parentNode.parentNode.parentNode.id);' : ''
		// Recortar el nombre si es muy largo
		if(nombre.length>paramjs_menutop_maxWidth){
			var tmpNombre = nombre.substring(0,paramjs_menutop_maxWidth) 
			tmpNombre = tmpNombre.replace(/^\s*|\s*$/g,"");
			tmpNombre = tmpNombre.replace(/^\.*|\.*$/g,"");
			tmpNombre += '...'
			var tmpTitle = 'title="'+nombre+'"'
		}else{
			var tmpNombre = nombre		
			var tmpTitle = ''
		}
		var tmpNewStr = '<li id="mtli_'+id_cont+'"><a '+tmpTitle+tmpTarget+' onMouseOut="encima=0;" onMouseOver="encima=1;'+tmpOnMouseOver+'" href="'+tmpHref+'" >'+tmpNombre+'</a></li>'+'<tmp>'
		arrSeccionesIdeoSite['id_'+parent].innerHtmlMenuDesplegable = tmpStr.replace('<tmp>',tmpNewStr)
	}
}
function crearMenusDesplegablesIdeoSite () {
	// Se corre onLoad, basado en el script onLoad_iniciarSeccionesIdeoSite(), que inserta index.php en el HTML con todos los arrays de las secciones
	var tmpStr = ''
	for (var item in arrSeccionesIdeoSite){
		if (arrSeccionesIdeoSite[item].innerHtmlMenuDesplegable) {
			tmpStr += arrSeccionesIdeoSite[item].innerHtmlMenuDesplegable
		} 
	}
	document.getElementById('menusDesplegablesVanAqui').innerHTML = tmpStr
	yaCreoLasSeccionesIdeoSite=true
}

// TAN PRONTO CARGA ESTE JS, creamos los menús
//onLoad_iniciarSeccionesIdeoSite()

// PARA MOSTRAR U OCULTAR DIVS
var sendToTop = 500
var showDivAbsolute=false
function hideDivId(id) {
	if (document.getElementById(id)) {
		hideDiv(document.getElementById(id))
		return true
	}
	return false
}
function hideDiv(d) {
	if (!d) return false;
	if(d.getAttribute('esContent')){
		dvCont = document.getElementById('content')
		d.setAttribute('lastScrollTop', dvCont.scrollTop)
		dvCont.style.top = dvCont.getAttribute('originalTop')
	}
	d.style.position = 'absolute';
	d.style.visibility = 'hidden';
	d.style.overflow = 'hidden';	
	d.style.height= '1px';
	d.style.display = 'none'
}
function showDivId(id) {
	if (document.getElementById(id)) {
		showDiv(document.getElementById(id))
		return true
	}
	return false
}
function showDiv(d) {
	if (!d) return false;
	if(!showDivAbsolute){
		d.style.position = 'relative';
	}else {		
		d.style.position = 'absolute';
	}
	d.style.visibility = 'visible';
	d.style.overflow = 'visible';	
	d.style.height = 'auto';	
	// Si showDivTrasError es que active el DIV tras divErr

		d.style.visible = 'visible'
		d.style.display = 'block'	


	d.style.zIndex = sendToTop++
	if(d.getAttribute('esContent'))	document.getElementById('content').scrollTop= d.getAttribute('lastScrollTop') 
	showDivAbsolute=false
}

function getElementPosition(elem, idObjetoRelativoA, sentido){
	// Si quiero obtener posicion general en la pag,  idObjetoRelativoA= document.id
	// idObjetoRelativoA  id del objeto con relación al cual se espera la medida
	// sentido = left, top, bottom, right
	Pos = sentido== 'top' ? elem.offsetTop : sentido== 'right' ? elem.offsetRight : sentido== 'bottom' ? elem.offsetBottom : elem.offsetLeft
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		if (tempEl.id==idObjetoRelativoA){
			tempEl = null;
		}else{
			Pos += sentido== 'top' ? tempEl.offsetTop : sentido== 'right' ? tempEl.offsetRight : sentido== 'bottom' ? tempEl.offsetBottom : tempEl.offsetLeft
			tempEl = tempEl.offsetParent;
		}
	}
	return Pos
}
function getDocHeight() {
	// Devuelve altura del documento como tal...
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}
var calendario_instanciaActual = false
function cal_Cambiar(instancia){
	calendario_instanciaActual = instancia
	calendarioReturnFunction='cal_setFecha'; 
	node = calendarioCrear()
	var contenedor = document.getElementById('cal_cambiar_'+instancia)
	contenedor.appendChild(node)
	calendario(document.getElementById('cal_ano_'+instancia).value, document.getElementById('cal_mes_'+instancia).value , document.getElementById('cal_dia_'+instancia).value)
	// Posición
	nodeAmigo = document.getElementById('cal_link_'+instancia)
	node.style.top = getElementPosition(nodeAmigo, 'content', 'top')
	node.style.left = getElementPosition(nodeAmigo, 'content', 'left')
	showDivAbsolute = true
	showDiv(node)
	return false;
}
function cal_setFecha_onLoad(ano,mes,dia,instancia) {
	calendario_instanciaActual = instancia
	cal_setFecha(ano,mes,dia)
}
function cal_setFecha(ano,mes,dia){
	instancia=calendario_instanciaActual
	// COMPROBACIONES DE FECHAS
	document.getElementById('cal_string_'+instancia).firstChild.nodeValue = arr_l_meses[mes]+" "+dia+' '+ano
	document.getElementById('cal_ano_'+instancia).value = ano
	document.getElementById('cal_mes_'+instancia).value = mes
	document.getElementById('cal_dia_'+instancia).value = dia
}

function mTresetFecha(instancia){
	// Fechas
	d=new Date()
	document.getElementById('cal_string_'+instancia).firstChild.nodeValue = arr_l_meses[d.getMonth()+1]+' '+d.getDate()+' '+d.getFullYear()	
	document.getElementById('cal_ano_'+instancia).value = d.getFullYear()
	document.getElementById('cal_mes_'+instancia).value = d.getMonth()+1
	document.getElementById('cal_dia_'+instancia).value = d.getDate()
}
function onLoad_config_interfazSubirImagenes () {
	tmpObj = document.getElementById('insertarAutomaticamente')
	tmpObj.checked= getCookie('insertarAutomaticamente')=='false' ? false : true
	tmpObj = document.getElementById('cerrarAlSubir')
	tmpObj.checked= getCookie('cerrarAlSubir')=='false' ? false : true
	document.getElementById('check_permitirSizeOriginal').checked = false	
}
function cambiar_insertarAutomaticamente(){
	tmpObj = document.getElementById('insertarAutomaticamente')
	setCookie('insertarAutomaticamente', tmpObj.checked)	
}
function cambiar_cerrarAlSubir() {
	tmpObj = document.getElementById('cerrarAlSubir')
	setCookie('cerrarAlSubir', tmpObj.checked)	
}
function setCookie(name, value, expires, path, domain, secure){
	    document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	}
	else
	{
	begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
	end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
	document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function cita_reprogramar(miDiv) {
	mostrarAdvertencia(lang_16,lang_11,lang_17,lang_10,lang_9)
	but = document.getElementById('divAdvertenciaBut')
	txt = document.getElementById('divAdvertenciaText')
	but.onclick= function(){self.location='?accion=act_agenda&subaccion=sub_pedirCita&&id_cita='+miDiv.getAttribute('id_cita'); terminarPopUp();}	
}

function cita_eliminar(miDiv) {
	mostrarAdvertencia(lang_12,lang_11,lang_13,lang_10,lang_9)
	but = document.getElementById('divAdvertenciaBut')
	txt = document.getElementById('divAdvertenciaText')
	but.onclick= function(){self.location='?accion=act_agenda&subaccion=sub_eliminarCita&id_rueda='+miDiv.getAttribute('id_rueda')+'&id_cita='+miDiv.getAttribute('id_cita'); terminarPopUp();}	
}
function cita_rechazar(miDiv) {
	mostrarAdvertencia(lang_15,lang_11,lang_14,lang_10,lang_9)
	but = document.getElementById('divAdvertenciaBut')
	txt = document.getElementById('divAdvertenciaText')
	but.onclick= function(){self.location='?accion=act_agenda&subaccion=sub_bloquearUsuario&id_rueda='+miDiv.getAttribute('id_rueda')+'&id_cita='+miDiv.getAttribute('id_cita'); terminarPopUp();}	
}

function citas_abrirMenuEdicion(id_cita,x1,esCitaPropia,id_rueda) {
	document.getElementById('agenda_menu_1').firstChild.href="?accion=act_agenda&subaccion=sub_aceptarCita&id_cita="+id_cita
	tmp_div = document.getElementById('agenda_link_3')
	tmp_div.setAttribute('id_cita',id_cita)
	tmp_div.setAttribute('x1',x1)
	tmp_div.setAttribute('id_rueda',id_rueda)
	tmp_div = document.getElementById('agenda_link_2')
	tmp_div.setAttribute('id_cita',id_cita)
	tmp_div.setAttribute('x1',x1)
	tmp_div.setAttribute('id_rueda',id_rueda)
	tmp_div = document.getElementById('agenda_link_4')
	tmp_div.setAttribute('id_cita',id_cita)
	tmp_div.setAttribute('x1',x1)
	tmp_div.setAttribute('id_rueda',id_rueda)
	//ESTADO DE LA CITA
	// Si yo pedí la cita, no deja rechazar ni confirmar
	if(x1==1 || esCitaPropia==1){
		hideDivId('agenda_menu_1') 
		hideDivId('agenda_menu_2') 
	}else{ 
		showDivId('agenda_menu_1')
		showDivId('agenda_menu_2') 
	}
//	document.getElementById('agenda_menu_1').className = esCitaPropia==1 ? 'invisible' : ''
//	document.getElementById('agenda_menu_4').className = esCitaPropia==1 ? 'invisible' : ''
	

	
}
var lastScroll_v = 0
function mostrarAdvertencia(titulo,alerta,comentario,butName,butCancelName) {
	// Requiere al menos que se envíe titulo
	iniciarPopUp()
	lastScroll_v = document.body.scrollTop
	window.scroll(document.body.scrollLeft, 0)
	dvAlerta = document.getElementById('divAdvertenciaTitle')
	if(alerta!='') {
		dvAlerta.firstChild.nodeValue = alerta
	}else{
		dvAlerta.firstChild.nodeValue = 'Atención'
	}
	if(titulo!='') document.getElementById('divAdvertenciaText').firstChild.nodeValue = titulo
	dvComent = document.getElementById('divAdvertenciaComent')
	if(comentario!='') {
		dvComent.firstChild.nodeValue = comentario
		showDiv(dvComent)
	}else{
		hideDiv(dvComent)
	}
	but = document.getElementById('divAdvertenciaBut')
	butCancel = document.getElementById('divAdvertenciaButCancel')
	but.value = butName!='' ? butName : 'Continuar'
	butCancel.value = butCancelName!='' ? butCancelName : 'Cancelar'
}
var iniciarPopUpRestaurarOtras = false
function iniciarPopUp(esParticular){
	// Es particular cuando se trata de una ventana emergente privada, no de la general de la mesa
	// Llamarla desde ese tipo de emergentes nos permite ocultar objetos como los controles flash de tareas eficientemente
	iniciarPopUpRestaurarOtras=false
	if (!esParticular) {
		divInvisible = document.getElementById('divFondoInvisible')
		divInvisible.style.visibility='visible'
		divInvisible.style.zIndex =  sendToTop++
		divInvisible.style.height = getDocHeight()+'px'
		showDivId('divAdvertencia')
//		divAdvert.zIndex = new  Date().getTime() 		
	}
}
function terminarPopUp(esParticular){
	if (iniciarPopUpRestaurarOtras) {
		showDivAbsolute=true
	}
	iniciarPopUpRestaurarOtras=false
	if (!esParticular) {
		divInvisible = document.getElementById('divFondoInvisible')
		divInvisible.style.visibility='hidden'
		hideDivId('divAdvertencia')
		hideDivId('divAdvertenciaComent')
	}
	window.scroll(document.body.scrollLeft, lastScroll_v)
}
function mostrarVideo(id_cont){
	ocultarVideos()
	showDivId('video_'+id_cont)
	document.getElementById('vid_enPlay').innerHTML = document.getElementById('vid_tit_'+id_cont).innerHTML
}
function ocultarVideos(){
	tmpArr = plat_listaDeVideos.split(',')
	var item
	for (item in tmpArr){
		if(tmpArr[item]) hideDivId('video_'+tmpArr[item])
	}
}
function mostrarAudio(id_cont){
	ocultarAudios()
	showDivId('audio_'+id_cont)
	document.getElementById('aud_enPlay').innerHTML = document.getElementById('aud_tit_'+id_cont).innerHTML
}
function ocultarAudios () {
	tmpArr = plat_listaDeAudios.split(',')
	var item
	for (item in tmpArr){
		if(tmpArr[item]) hideDivId('audio_'+tmpArr[item])
	}
}
