/* akisha gen */
function activarCampo(id){
	get(id).disabled="";
	}
function showSaved(){
	$('savedMsg').style.display='';
	new Effect.Pulsate($('savedMsg'),{direction: 'top-left'});
	setTimeout("new Effect.Fade($('savedMsg'),{direction: 'top-left'});",2000);
	}
function saveVal(obj,params,dFile,fieldP){
	//get(obj.id).disabled="disabled";
	var xP = 'logic=updateInPlace&fieldP'+fieldP+'&'+params;
	xP += '&name=' + fieldP;
	xP += '&value=' + escape(obj.value);
	var exec = 'activarCampo(\'' + obj.id + '\');showSaved();';
//	alert(dFile+'|'+xP);
	//
	get(fieldP).disabled='disabled';
	goAJAX('',dFile,xP,exec,'','0','0');
	//alert(dFile+'----'+xP+'----'+exec);
	}
	
function mOvr(src,clrIn) {//on mouse in
	src.style.cursor = 'hand';
	src.bgColor = clrIn;	
	}
function mOut(src,clrIn) {// on mouse out
	src.style.cursor = 'default';
	src.bgColor = clrIn;
	}
function mClk(src) {//on click
	//src.bgColor = "#ffcc99";
	}
var nav4 = window.Event ? true : false;
function acceptNum(evt){
var key = nav4 ? evt.which : evt.keyCode;
if (key == null || key == ''){return true}
return (key <= 13 || (key >= 48 && key <= 57));
}

function checkNacimiento(){
	if(get('dob').value<1 || get('dob').value > 31 || get('yob').value < 1990 || get('yob').value > 1995){
		}else{	
			}
	}
	
function loadUsuariosLinks(){
	goAJAX('main','ajax.php','control=p.mis.perfiles&acc=load','sortableUsuariosLinks();');
}

function sortableUsuariosLinks(){
var clases=new Array('link');// que clases se van a aceptar
   Sortable.create('lista_links',{tag:'div',hoverclass:'hoverSortable',constraint: false,
      onChange:function(){
	  //var order=Sortable.serialize('main');
	  }
    })
}
function deleteUsrLink(id){
	if(confirm('Confirmas eliminar este link?')){
		goAJAX('','ajax.php','control=p.mis.perfiles&acc=delLink&id='+id,'$(\'lnk_'+id+'\').remove();sortableUsuariosLinks();','','0','0');
		
		}
	
	return false;
	}
	
function saveUsrLinksOrder(){
	var order=Sortable.serialize('lista_links');
	goAJAX('','ajax.php','control=p.mis.perfiles&acc=saveOrder&'+order,'alert(\'guardado\');','','','0','0');
	}
	
function fijarPrefNot(i){
	goAJAX('','ajax.php','control=p.fijarPrefNot&i='+i,'alert(respuesta);','','','0','0');
	return false;
	}
/* ************************************************************************ */
/* ************************** VENTANAS  **************************** */
/* ************************************************************************ */
function akiSysAjax(a,b,exec){
	//alert(a+'&ajax=yeah');
	goAJAX(b,a+'&ajax=yeah','');
//alert(b+'-\n'+a);
	return false;
	}
function akiSysAjaxPost(a,b,c){
	//alert(b+'-\n'+a);
	goAJAX(b,a,c+'&ajax=yeah');
	return false;
	}
function akiSysAjaxG(a,b){
	GetId('sSecName').innerHTML=b;
	goAJAX('sMain',a+'&ajax=yeah','');
	return false;
	}
function showSysWindow(winName,winTitle,winDivId,File,w,h){
 	if(!isDefined(get(winName))){
  var win = new Window({id: winName, className: "mac_os_x", title: winTitle, width:w, height:h, wiredDrag: true,showEffectOptions:{duration:'0.0'},hideEffectOptions:{duration:'0.0'},recenterAuto:true}); 
  win.setDestroyOnClose(); 
  win.showCenter();
  win.setConstraint(true, {left:0, right:0, top: 30, bottom:10});
  win.toFront();
  win.setHTMLContent('<div class="winContent"><div id="'+winDivId+'"></div></div>');
  
   goAJAX(winDivId,File,'');
	}else{
			get(winName).toFront;
			}

}
function showWin(href,title,w,h,winDivId,winTitle){
	if(!isDefined(w)||(w=='')){w=600;}
	if(!isDefined(h)||(h=='')){h=400;}
	if(!isDefined(winDivId)||(winDivId=='')){
		var winDivId='div'+str_replace(' ','',title);
		}
	if(!isDefined(winTitle)||(winTitle=='')){
		var winTitle='win'+str_replace(' ','',title);
		}
	
	href=href+'&hwnd='+Math.floor(Math.random( ) * 999 - 2) + 1;
	showSysWindow(winTitle,title,winDivId,href,w,h);
	return false;
	}
/* ************************************************************************ */
/* ************************** EDITAR MI PERFIL  **************************** */
/* ************************************************************************ */
function showEditNames(){
	showWin('ajax.php?control=edit.perfil.nombres','Editar mis nombres','500','200','ajaxEditNames','winEditarmisnombres');
	return false;
	}
function showEditAcercaDe(){
	showWin('ajax.php?control=edit.perfil.acerca.de','Acerca de mi ','580','300','ajaxAcercaDe','winAcercademi');
	return false;
	}
function showEditSocial(){
	showWin('ajax.php?control=edit.perfil.social','Social ','400','300','ajaxEditSocial','winEditarSocial');
	return false;
	}
function showEditIntereses(){
	showWin('ajax.php?control=edit.perfil.intereses','Intereses ','620','350','ajaxEditIntereses','winEditarIntereses');
	return false;
	}
function showEditUbicacion(){
	showWin('ajax.php?control=edit.perfil.ubicacion','Mi Ubicación','440','300','ajaxEditUbicacion','winEditMiUbicacion');
	return false;
	}
	
function loadRegions(id){
	get('tr_regiones').style.display='';
	get('tr_ciudades').style.display='none';
	goAJAX('dynRegions','ajax.php','control=edit.perfil.ubicacion&acc=loadRegions&id='+id);
	}
function loadCiudades(id){
	get('tr_regiones').style.display='';
	get('tr_ciudades').style.display='';
	goAJAX('dynCiudades','ajax.php','control=edit.perfil.ubicacion&acc=loadCiudades&id='+id);
	}
function getSelectionCiudadId(text, li) {/*deprecated*/
    //alert (li.id);
	get('id_ciudad').value=li.id;
	get('ciudad').value=text.value;
	
}
function createAutoCompleteCiudad(e){
	new Ajax.Autocompleter('ciudad', 'ciudad_choices', 'ajax/edit.perfil.ubicacion.ciudad.php?id_pais='+get('id_pais').value, {minChars: 2,afterUpdateElement : getSelectionCiudadId
});
	}
function showEditVincular(){
	showWin('ajax.php?control=edit.perfil.vincular','Perfiles Vinculados','440','300','ajaxEditVincular','winEditVincular');
	return false;
	}

function showEditPrivacidadBloques(){
	showWin('ajax.php?control=edit.perfil.privacidad.bloques','Privacidad de bloques','500','300','ajaxPrivacidadBloques','winEditPrivacidadBloques');
	return false;
	}
	
function loaddbNombres(){
if($('dbNombres')){goAJAX('dbNombres','ajax.php?control=edit.perfil.ajax','acc=getNombres');}
}
function loaddbPerfilesVinculados(){
if($('dbPerfilesVinculados')){goAJAX('dbPerfilesVinculados','ajax.php?control=edit.perfil.ajax','acc=getPerfilesVinculados');}
}

function loaddbUbicacion(){
if($('dbUbicacion')){
goAJAX('dbUbicacion','ajax.php?control=edit.perfil.ajax','acc=getUbicacion');}
}
function loaddbAcercaDe(){
if($('dbAcercaDe')){goAJAX('dbAcercaDe','ajax.php?control=edit.perfil.ajax','acc=getAcercaDe');}
}
function loaddbSocial(){
if($('dbSocial')){goAJAX('dbSocial','ajax.php?control=edit.perfil.ajax','acc=getSocial');}
}

function loaddbIntereses(){
if($('dbIntereses')){goAJAX('dbIntereses','ajax.php?control=edit.perfil.ajax','acc=getIntereses');}
}
function loaddbAvatares(){
if($('dbAvatares')){goAJAX('dbAvatares','ajax.php?control=edit.perfil.ajax','acc=getAvatars');}
}


function showWinImportarContactos(){
	showWin('ajax.php?control=edit.contactos.importar','Buscar Contactos','750','500','ajaxBuscarContactos','winBuscarContactos');
	return false;
	}
function eliminarContacto(id){
	if(confirm('¿Confirmas borrar este contacto?')){
		get('delLnk'+id).style.display='none';
		//get('ak_row'+id).style.display='none';
		var exec = 'get(\'ak_row'+ id +'\').style.display=\'none\';';
		goAJAX('','ajax/edit.contacts.inplace.php','logic=deleteInPlace&id='+id,exec,'','0','0');
	}
return false;	
}



function showNuevoMensaje(tipo, id){
	if(!isDefined(tipo)||(tipo=='')){
		var tipo='';
		}
	if(!isDefined(id)||(id=='')){
		var id='';
		}
	showWin('ajax.php?control=mensajes.nuevo&tipo='+tipo+'&id='+id,'Nuevo Mensaje','500','400','ajaxWinMensajeNuevo','winMensajeNuevo');
	return false;
	}
	
function createAutoCompleteUsuarioMsg(e){
	new Ajax.Autocompleter('para', 'usuarios_choices', 'ajax/mensajes.buscar.usuario.php', {minChars: 3,afterUpdateElement : getSelectionUserId
});
	}
	
function getSelectionUserId(text, li) {
    //alert (li.id);
	get('user_id').value=li.id;
	get('gPara').innerHTML=text.value;
	get('envMsgResetLnk').style.display='';
}
function  enviarMsgResetUser(){
	get('gPara').innerHTML=' <input name="para" type="text" id="para" size="40" onfocus="createAutoCompleteUsuarioMsg(event);" />';
	get('user_id').value='';
	get('envMsgResetLnk').style.display='none';
	}
function enviarMensaje(){
	var errores='';
	if(get('tipo').value=='0' && get('user_id').value==''){
		errores+='- No has seleccionado a una persona.<br>';
		}
	if(get('tipo').value=='1' && get('group_id').value=='1'){
		errores+='- Debes seleccionar un grupo.<br>';
		}
	if(get('mensaje').value==''){
		errores+='- No has introducido ningun mensaje.<br>';
		}
	if(errores==''){
		goAJAX('ajaxWinMensajeNuevo','ajax.php','control=mensajes.nuevo&'+akiSfrm('frmNuevoMensaje'),'checkMsgExito();');
		}else{
			get('msgError').innerHTML=errores;
			get('msgError').style.display='';
			get('btnEnviar').disabled='';
			}
	}
function checkMsgExito(){
	if(get('envMsgExito').value=='1'){
		Windows.close('ajaxWinMensajeNuevo');
		}
	}
	
function showWinMsgRed(){
	showWin('ajax.php?control=red.nuevomsg','Nuevo mensaje de red','500','400','ajaxWinRedMsg','winRedMsg');
	return false;
	}
	
	
function msgRedDel(id){
	get('confirmDelMsg'+id).style.display='';
	return false;
	}
	
function msgRedDel2(id){
	var xP = 'control=red.delmsg&id='+id;
	goAJAX('','ajax.php',xP,'','','0','0');
	get('redMsgItem'+id).style.display='none';
	return false;
	}
	
function msgRedCommShow(id){
	get('commList'+id).style.display='';
	get('dynZoneMsgComm'+id).style.display='';
	get('frmSubmitForm'+id).mensaje.focus();
	return false;
	}
	
function msgRedSubmitComm(id){
	var xP = 'control=red.new.comm&id='+id+'&'+akiSfrm('frmSubmitForm'+id);
	goAJAX('dynZoneMsgComm'+id,'ajax.php',xP);
	return false;
	}
	
function msgRedCommShowAll(id){
	var xP = 'control=red.all.comm&id='+id;
	goAJAX('commList'+id,'ajax.php',xP);
	return false;
	}

function showAContactos(id){
	var xP = 'control=perfil.agregar.contacto&id='+id;
	showWin('ajax.php?'+xP,'Agregar Contacto','300','200','ajaxAgregarContacto','winAgregarContacto');
	return false;
	}
function showNotificationsArea(e){
	var xP = 'acc=show1';
	showWin('notificaciones.php?'+xP,'Notificaciones','300','200','ajaxWNotificaciones','winWNotificaciones');
	return false;
}
function showWinAddRss(e){
	var xP = 'control=rss.add&acc=show';
	showWin('ajax.php?'+xP,'Agregar Feed RSS','400','200','ajaxWAddRSS','winWAddRSS');
	return false;
}
function showWinRssNewPage(){
	var xP = 'control=rss.new.page&acc=show';
	showWin('ajax.php?'+xP,'Nueva Pagina RSS','300','100','ajaxWRssNewPage','winWRssNewPage');
	return false;
}
function rssBlockDelete(id){
var winName = 'winRssBlockDelete'+id;
if(!isDefined(get(winName))){
	var html = "<div style='padding:10px;font-size:13px;text-align:center;'>&iquest;Eliminar este bloque RSS?<br /><a href='#' onclick=" + '"Windows.close(\''+winName+'\', event);return rssBlockDelete2(\''+id+'\');"' + " class=\"dialogYes\">Si, Eliminar</a> - <a href='#' onclick=" + '"Windows.close(\''+winName+'\', event);return false;"' + " class=\"dialogNo\">No, Cancelar</a></div>"
	var win = new Window({id:winName,className: "mac_os_x", width:350, height:70, zIndex: 100, resizable: false, title: "Eliminar Bloque RSS", showEffectOptions:{duration:'0.0'},hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true,destroyOnClose:true});
	win.getContent().innerHTML= html;
	//win.setStatusBar("Status bar info"); 
	win.showCenter();
}else{
	get(winName).toFront;
	}
return false;
}
function rssBlockDelete2(id){
	var xP = 'control=rss&acc=deleteBlock&id='+id;
	goAJAX('debug','ajax.php',xP,'','','0','0');
	$('rss_'+id).remove();	
}


function rssPageDelete(id){
var winName = 'winRssPageDelete'+id;
if(!isDefined(get(winName))){
	var html = "<div style='padding:10px;font-size:13px;text-align:center;'>&iquest;Eliminar esta p&aacute;gina RSS y todo su contenido?<br /><a href='#' onclick=" + '"Windows.close(\''+winName+'\', event);return rssPageDelete2(\''+id+'\');"' + " class=\"dialogYes\">Si, Eliminar</a> - <a href='#' onclick=" + '"Windows.close(\''+winName+'\', event);return false;"' + " class=\"dialogNo\">No, Cancelar</a></div>"
	var win = new Window({id:winName,className: "mac_os_x", width:350, height:70, zIndex: 100, resizable: false, title: "Eliminar Pagina RSS", showEffectOptions:{duration:'0.0'},hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true,destroyOnClose:true});
	win.getContent().innerHTML= html;
	//win.setStatusBar("Status bar info"); 
	win.showCenter();
}else{
	get(winName).toFront;
	}
return false;
}
function rssPageDelete2(id){
	var xP = 'control=rss&acc=rssPageDelete&id='+id;
	goAJAX('debug','ajax.php',xP,'window.location.href="/?logic=pn&view=rss"','');
	$('rss_'+id).remove();	
}

function rssPageEdit(pid){
	var xP = 'control=rss.edit.page&pid='+pid;
	showWin('ajax.php?'+xP,'Editar Pagina RSS','300','200','ajaxWRssEditPage','winWRssEditPage');
	return false;
}
function rssPageSend(pid){
	var xP = 'control=rss.send.page&pid='+pid;
	showWin('ajax.php?'+xP,'Enviar Pagina RSS','300','200','ajaxWrssPageSend','winWrssPageSend');
	return false;
}

function showWinWebObjUrl(url){
	if(!isDefined(url)||(url=='')){
		var url='';
		}
	var xP = 'control=web.obj.url&url='+url;
	showWin('ajax.php?'+xP,'Objeto Web desde Url','300','200','ajaxWWebObjUrl','winWWebObjUrl');
	return false;
}

function showCambiarPass(){
	var xP = 'control=edit.password';
	showWin('ajax.php?'+xP,'Cambiar Contrase&ntilde;a','400','200','ajaxCambiarPass','winCambiarPass');
	return false;
	}
function showCambiarEmail(id){
	var xP = 'control=edit.email';
	showWin('ajax.php?'+xP,'Cambiar Email','500','300','ajaxCambiarEmail','winCambiarEmail');
	return false;
	}	
function removeProfile(id){
	var xP = 'control=edit.perfil.vincular&acc=RP&id='+id;
	goAJAX('','ajax.php',xP,'$(\'pvinc' + id +'\').prototip.hide();$(\'pvinc' + id +'\').remove();','','0','0');
	return false;
}
function alertsMarkRead(web_id,time_from,time_to,adic){
	if($('listAlertsDyn'+adic+'b').style.display=='none'){
		var xP = 'control=alerts&acc=MR&web_id='+web_id + '&time_from=' + time_from + '&time_to=' + time_to;
		goAJAX('listAlertsDyn'+adic+'b','ajax.php',xP);
		}
	if($('listAlertsDyn'+adic).style.display=='none'){
		$('listAlertsDyn'+adic).style.display='';
		$('listAlertsDynLeidas'+adic).style.display='none';
		}else{
			$('listAlertsDyn'+adic).style.display='none';
			$('listAlertsDynLeidas'+adic).style.display='';
			}
return false;
}
function alertsShowLeidas(adic){
	$('listAlertsDyn'+adic).style.display='none';
	if($('listAlertsDynLeidas'+adic).style.display=='none'){
		$('listAlertsDynLeidas'+adic).style.display='';
		}else{
			$('listAlertsDynLeidas'+adic).style.display='none';
			}
	
	return false;
}

function cleanWebAlerts(web_id,time_from,time_to,adic){
	$('lnk_cfg_WebAlert'+adic).prototip.remove();
	$('al_web_'+adic).remove();
	var xP = 'control=alerts&acc=clean&web_id='+web_id + '&time_from=' + time_from + '&time_to=' + time_to;
	goAJAX('','ajax.php',xP,'','','0','0');
	return false;
	}

function alertsNoRecibir(web_id,adic){
	var xP = 'control=alerts&acc=norecibir&web_id='+web_id;
	goAJAX('al_nrm_'+adic,'ajax.php',xP);
	return false;
	}
	
function alertsTip(obj,url){
//	alert (obj.id);
	new Tip(obj.id, {
  ajax: {
    url: 'ajax.php?control=inicio.url.preview&url='+url,
    options: {
      onComplete: function() { }
    }
  }
});
	obj.removeAttribute('onmouseover');
}
function tipObflow(obj){
//	alert (obj.id);
	new Tip(obj.id,obj.innerHTML,{hideOthers:true});
	obj.removeAttribute('onmouseover');
}

function tipAlertsCH(obj){
//	alert (obj.id);
new Tip(obj.id, '<b>'+obj.innerHTML+'</b><br>&iquest;Deseas dejas de recibir alertas de este canal?<br>',{
  title: 'Canal de alertas:',
  stem: 'topRight',
  style: 'darkgrey',
  hook: {tip: 'topRight'},
  offset: { x: 90, y: 10},
//  showOn: 'click',
//  closeButton: true, 
  hideAfter: 1,
  hideOn: false,
  hideOthers: true,
  width: 200
});
Tips.hideAll();
$(obj.id).prototip.show();
//	obj.removeAttribute('onmouseover');
}