// JavaScript ToolBox - Copyright - Jamespot 17/09/2007
// Enable Simple check for mandotory fields
// Ajax
var ns6=document.getElementById&&!document.all


// Graphical effect
function expandDiv(idContainer,idContent)
{
	new Effect.Morph(idContainer, {
	  style: 'width:300px;',
	  duration: 0.4,
	  afterFinish: function () {$(idContent).style.display='inline';}
	});
}

function expandDiv_v2(idContainer,idContent)
{
	
	jQuery('#'+idContainer).animate(
			{width:'550px'},
			'fast',
			function(){
				jQuery('#'+idContent).show();
			}
			);
}

function reductorDiv_v2(idContainer,idContent)
{
	jQuery('#'+idContent).hide();
	jQuery('#'+idContainer).animate(
			{width:'60px'},
			'fast'
			);
}

function show_formcomment(id)
{
	if (jQuery('#formc_'+id).is(':hidden'))
	{
		jQuery('#linkc_'+id).attr('src',imgclose);
		jQuery('#formc_'+id).show();
		jQuery('#formc_'+id).animate({height:'50px'},'fast');
		jQuery('#addc_'+id).show();
	}
	else
	{
		jQuery('#linkc_'+id).attr('src',imgopen);
		jQuery('#addc_'+id).hide();
		jQuery('#formc_'+id).animate({height:'5px'},'fast',function(){jQuery(this).hide()});
	}
}

function reductorDiv(idContainer,idContent)
{
	new Effect.Morph(idContainer, {
	  style: 'width:20px;',
	  duration: 0.4,
	  afterFinish: function () {$(idContent).style.display='none';}
	});
}

var IdContainer="cuv2_";
var IdBlockAction="cu_";
var IdContentBlockAction="ccu_";
var IdUserCurrent=0;
var BlockActionOpen=new Array();

function expandUserAction(idUser)
{
	$(IdBlockAction+idUser).style.display='block';
	$(IdContainer+idUser).onmouseover='';
	divContent=IdContentBlockAction+idUser;
	/*if (IdUserCurrent!=0){narrowUserAction();}*/
	IdUserCurrent=idUser;
	new Effect.Morph(IdBlockAction+idUser, {
	  style: 'top:-15px;left:-15px;width:88px;height:88px;',
	  duration: 0.2,
	  afterFinish: function () {setTimeout("makeBlockActionEnable("+idUser+")",10);}
	});
}

function makeBlockActionEnable(idUser)
{
	$(IdContentBlockAction+idUser).style.display='block';
	$(IdContentBlockAction+idUser).onmouseout=doNarrow;
	for (key in BlockActionOpen)
	{
		narrowUserActionExt(key);
	}
	BlockActionOpen=new Array();
	BlockActionOpen[idUser]=idUser;
	/*Event.observe(IdContentBlockAction+idUser, "mouseout", function(){narrowUserAction()})*/
}

function makeBlockActionDisable(idUser)
{
	$(IdBlockAction+idUser).style.display='none';
	IdUserCurrent=0;
	$(IdContainer+idUser).onmouseover=function () {expandUserAction(idUser)};
}

function doNarrow(wevt) {
	if (!wevt) var wevt = window.event;
	var tg = (window.event) ? wevt.srcElement : wevt.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (wevt.relatedTarget) ? wevt.relatedTarget : wevt.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	// Mouseout took place when mouse actually left layer
	// Handle event
	narrowUserAction()
}


//setTimeout("$('c"+idContainer+"').style.display='block';",1);
function narrowUserAction()
{
	narrowUserActionExt(IdUserCurrent);
}

function narrowUserActionExt(idUser)
{
	try
	{
		$(IdContentBlockAction+idUser).onmouseout='';
		$(IdContentBlockAction+idUser).style.display='none';
		new Effect.Morph(IdBlockAction+idUser, {
		  style: 'top:30px;left:25px;width:10px;height:10px;',
		  duration: 0.2,
		  afterFinish: function () {setTimeout("makeBlockActionDisable("+idUser+")",10);}
		});
	}catch(ex){};
}

//End Graphical effect


function see_all_properties(id)
{
	container=getElmt(id);
	var propLink;
	propLink="";
	for (prop in container)
	{
		propLink=propLink+ prop + " ---------> " + container[prop]+"<br />";
    }
   return propLink;
}

var el_menu = new Array("Home","MySpot","Message","Community","Account");

function getIndex(elmt)
{
	for( var i = 0 ; i < el_menu.length ; i++ )
	{
		if (el_menu[i]==elmt)
			return i
	}
	return 0;
}

function display_submenu(id)
{
	/*prop=see_all_properties("link"+id);
	div_block('modal');
	div=getElmt('modal');
	div.innerHTML=prop;*/
	index_array=getIndex(id);
	div=getElmt("sub"+id);
	left=0;
	for ( var i = 0 ; i < index_array ; i++ )
	{
		div2=getElmt(el_menu[i]);
		left=left+5+div2.offsetWidth;
	}
	left=left+270+20;
	div.style.position="absolute";
	div.style.top="75px";
	div.style.left=left+"px";
	link=getElmt("link"+id);
	link.className="activate";
	div_block("sub"+id);
}

function undisplay_submenu(id)
{
	link=getElmt("link"+id);
	link.className="menu_el";
	div_none("sub"+id);
}


function restrictinput(maxlength,e,placeholder)
{
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
	{
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
		if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder)
{
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder))
	{
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(thename, theid, thelimit)
{
	var theform=theid!=""? document.getElementById(theid) : thename
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> chars maximum.'
	if (document.all||ns6)
		document.write(limit_text)
	if (document.all)
	{
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

function delete_image(type,id)
{
  new Ajax.Updater(
      'current_image',
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'delete-image',
                      page: 'spot',
                      type: type,
                      id: id  
                    }
      }
  );
  div_none('current_image');
}

function delete_background_image(id)
{
  new Ajax.Updater(
      'current_image',
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'delete-background-image',
                      page: 'spot',
                      id: id  
                    }
      }
  );
  div_none('current_background_image');
}

function ajax_change_photo(idSpot,new_img)
{
  div_none('changeLS');
  new Ajax.Updater(
      'logo_spot_editable',
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'change-spot-photo', 
                      page: 'spot', 
                      IdSpot: idSpot,
                      new_img: new_img 
                    }
      }
  );
}

function MakeFormPermission (div,nickname,iduser,level,idSpot)
{
  div_block(div);
  new Ajax.Updater(
      div,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'form-change-permission', 
                      page: 'spot', 
                      IdSpot: idSpot,
                      IdUser: iduser,
                      level: level,
                      nickname: nickname
                    }
      }
  );
}

function ChangePermissions (new_Perm,IdUser,IdSpot)
{
  div_none('form_permissions');
  div="levelName_"+IdUser;
  new Ajax.Updater(
      div,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'change-permission', 
                      page: 'spot', 
                      IdSpot: IdSpot,
                      IdUser: IdUser,
                      newPerm: new_Perm
                    }
      }
  );
}

//////////////
function MakeFormRole (div,nickname,iduser,level,idSpot)
{
  div_block(div);
  new Ajax.Updater(
      div,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'form-change-role', 
                      page: 'spot', 
                      IdSpot: idSpot,
                      IdUser: iduser,
                      level: level,
                      nickname: nickname
                    }
      }
  );
}

function ChangeRole (new_Perm,IdUser,IdSpot)
{
  div_none('form_change_role');
  div="levelName_"+IdUser;
  new Ajax.Updater(
      div,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'change-role', 
                      page: 'spot', 
                      IdSpot: IdSpot,
                      IdUser: IdUser,
                      newPerm: new_Perm
                    }
      }
  );
}
//////////////

function view_more_lastest(iddiv,updatediv,typestory,index)
{
  new Ajax.Updater(
      updatediv,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'view-more-lastest-news', 
                      page: 'search', 
                      TypeStory: typestory,
                      Index: index
                    }
      }
  );

}

function get_mouse(evt)
{
	if(!evt) evt = window.event;
	var de = document.documentElement;
    var b = document.body;
    if (de)
    {
		x = evt.clientX+ de.scrollLeft;
		y = evt.clientY+ de.scrollTop;
	}
	else if (b)
	{
		x = evt.clientX+ b.scrollLeft;
		y = evt.clientY+ b.scrollTop;
	}
}

function copyHeightDiv(idReferer,idTarget, idSubtarget, modifier)
{
	div_r=getElmt(idReferer);
	div_t=getElmt(idTarget);
	div_t.style.height=div_r.offsetHeight+"px";
	if (idSubtarget!="")
	{
		div_st=getElmt(idSubtarget);
		subHeight=div_r.offsetHeight-modifier;
		div_st.style.height=subHeight+"px";
	}
}

function div_position(idDiv,width)
{
	div_block(idDiv);
	hint_div=getElmt(idDiv);
}

function GetRadioValue(radioGroupName)
{
	var group = document.getElementsByName(radioGroupName);
	
	for( var i = 0 ; i < group.length ; i++ )
	{
		if( group[i].checked ) return group[i].value;
	}
}

function unCheckAll(group)
{
  if (group=='contact')
    nb=document.getElementById('NbContacts').value;
  else
    nb=document.getElementById('NbUmails').value;
	for( var i = 0 ; i < nb ; i++ )
	{
	 document.getElementById(group+"_"+i).checked=false;
	}
}

function CheckAll(group)
{
  	nb=document.getElementById('nbInvitation').value;
	for( var i = 0 ; i < nb ; i++ )
	{
	 document.getElementById(group+"_"+i).checked=true;
	}
}


function view_createspot(value)
{
  if (value==-1)
  {
    div_block("create_spot_it");
  }
  else
  {
    div_none("create_spot_it");
  }
}

function play_video()
{
  div=getElmt('video1');
  div.innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="290" height="218"><param name="movie" value="flash/jamespot_video_1.swf"><param name="quality" value="high"><embed src="flash/jamespot_video_1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="290" height="218"></embed></object>';
}

function makeFormEditMail(idSpot,NameSpot)
{
  title=getElmt('title_edit_mail');
  content='content_edit_mail';
  id='edit_mail_spot';
  div_block(id);
  title.innerHTML=NameSpot;
  new Ajax.Updater(
      content,
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
                      fonction: 'edit-mail', 
                      page: 'spot', 
                      IdSpot: idSpot 
                    }
      }
  );
}

function changeInput(blank_div,div)
{
  div_none(blank_div);
  input=getElmt(div);
  input.style.display="block";
  setTimeout('input.focus();', 10);
}

function onFocusElement(idElement)
{
   input=getElmt(idElement);
   setTimeout('input.focus();', 10);
}

function getElmt(id)
{
  var div
	if (document.layers)
	{
		div= document.layers[id];
	}
	else if (document.all)
	{
		div= document.all[id];
	}
	else if (document.getElementById)
	{
		div= document.getElementById(id);
	}
  return div;
}

function div_none(id)
{
	var div
	if (document.layers)
	{
		div= document.layers[id];
	}
	else if (document.all)
	{
		div= document.all[id];
	}
	else if (document.getElementById)
	{
		div= document.getElementById(id);
	}
		div.style.display="none";
}

function div_block(id)
{
	var div
	if (document.layers)
	{
		div= document.layers[id];
	}
	else if (document.all)
	{
		div= document.all[id];
	}
	else if (document.getElementById)
	{
		div= document.getElementById(id);
	}
		div.style.display="block";
}

function fieldVerification(field)
{
	if (field == "")
	{ 
		alert("Mail Field is not filled");
		return false;
	}
	return true;
}

function erreur(ErreurImage, size)
{
	if (size == '64' || size == '128')
	  ErreurImage.src="img/default_" + size + ".jpg";
	else
	   ErreurImage.src="img/default.jpg";
}

last_video_see="";
function SetMainVideo (div,feedTitle,MajDate,html,title,description)
{
  if (last_video_see!="")
  {
    last_video=getElmt(last_video_see);
    last_video.style.background="#FFFFFF";
  }
  div_list=getElmt(div);
  last_video_see=div;
  div_player=getElmt('main_video');
  feedTitle=Url.decode(feedTitle);
  MajDate=Url.decode(MajDate);
  html=Url.decode(html);
  title=Url.decode(title);
  description=Url.decode(description);
  ret='<div id="header_main_video">'+feedTitle+'&nbsp;-&nbsp;'+MajDate+'<br /><h4><a href="#" class="medium_title_story">'+title+'</a></h4></div>';
  ret=ret+'<div id="player_video">'+html+'</div>';
  ret=ret+'<div id="content_player_video">'+description;
  ret=ret+'</div>';
  div_list.style.background="#d2b2eb";
  div_player.innerHTML=ret;
}

function playthisvideo(index,title,url,width,height)
{
	last_div=getElmt("video_div_"+activeVid);
	new_div=getElmt("video_div_"+index);
	title_div=getElmt("header_video_player");
	flash_div=getElmt("content_video_player");
	last_div.className="inactive_video";
	new_div.className="active_video";
	title_div.innerHTML=title;
	content='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
	content=content+'<param name="movie" value="'+url+'">';
	content=content+'<param name="quality" value="high">';
	content=content+'<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed></object>';
	flash_div.innerHTML=content;
	activeVid=index;
}

/* LS : Spot edit confirm update before show the spot */
function confirm_view(str, idSpot)
{
  if (confirm(str)) {
    document.form_all.submit();
  } else {
    window.location.href='?action=spot&IdSpot='+idSpot;
  }
}


function ajax_add_contact(idUserToAdd)
{
  seeOperationInProgress();
  new Ajax.Request(
		  urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: 'fonction=add-contact&page=global&IdUser='+idUserToAdd,
        onComplete: function(transport)
        {
        			showResponseAddContact(transport);return true;
      	}
      }
      );
}

function ajax_remove_contact(idUserToRemove)
{
  seeOperationInProgress();
  new Ajax.Request(
		  urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: 'fonction=remove-contact&page=global&IdUser='+idUserToRemove,
        onComplete: showResponseRemoveContact
      }
      );
}

function showResponseAddContact(requete) 
{
	reponseArray=eval(requete.responseJSON);
	idUserToAdd=reponseArray['IdUser'];
	if (reponseArray['Error']=="1")
	{
		divAoip=getElmt('operation_in_progress');
		divAoip.style.backgroundColor="#FFFFFF";
		divAoip.innerHTML='<p>'+reponseArray['Message']+'</p>';
		setTimeout("closeOperationInProgress()",2000);
	}else
	{
		closeOperationInProgress();
		divAdd=getElmt(IdBlockAction+idUserToAdd);
		divAdd.style.backgroundColor="#FFEED7";
		div_none('link_addContact_u'+idUserToAdd);
	}
	return true;
}

function showResponseRemoveContact(requete)
{
	reponseArray=eval(requete.responseJSON);
	idUserToRemove=reponseArray["IdUser"];
	
	if (reponseArray['Error']=="1")
	{
		divRoip=getElmt('operation_in_progress');
		divRoip.innerHTML='<p>'+reponseArray["Message"]+'</p>';
		setTimeout("closeOperationInProgress()",2000);
	}
	else
	{
		closeOperationInProgress();
		divRemove=getElmt(IdContainer+idUserToRemove);
		divRemove.style.display="none";
	}
	return true;
}

function ajax_modal_jquery(fx, p, t, m, w, h, x, y, icon) {
  setModalJQuery(w,h,x,y);
  jQuery('#modal').load(urlbase+'inc/ajax.i.php',{
		fonction: fx,
		page: p,
	  	token: t,
	  	modifiers: m,
	  	width: w,
	  	height: h,
	  	x: x,
	  	y: y,
	  	icon: icon
	  	}, function (responseText, textStatus, XMLHttpRequest) {
    	  	if (textStatus == 'success') {
    	  		closeOperationInProgressExt();
    	  		div_block('modal');
    	  	} else {
    	  		closeOperationInProgress();
    	  	}
      }
  	);
}

function setModalJQuery(w, h, x, y)
{
	screenSize=seeOperationInProgress();
	divforsize=getElmt('unactivate_action');
	div=getElmt('modal');
	if ((w != 0) || (w != "")) {
		div.style.width=w+"px";
	}
	if ((h != 0) || (h != "")) {
		div.style.height=h+"px";
	}
	if ((x != 0) || (x != "")) {
		posLeft=(x/1);
	} else {
		posLeft=((screenSize["W"]-w)/2);
	}
	div.style.left=posLeft.toFixed(0)+"px";
	if ((y != 0) || (y != "")) {
		posTop=(y/1);
	} else {
	 	posTop=((screenSize["H"]-h)/2);
	}
 	div.style.top=posTop.toFixed(0)+"px";
}

function check_uncheck_all(field, id) {
	//test if all checked
	var flag = false;
	for (i = 0; i < field.length; i++) {
		if ((field[i].id == id) && (field[i].checked == false)) {
			flag = true;
			break ;
		}
	}
	// flag = true => all will be checked
	for (i = 0; i < field.length; i++) {
		if (field[i].id == id) {
			field[i].checked = flag;
		}
	}
}

function ajax_modal(fx,id,w,h,m,r,x,y,icon)
{
  setModal(w,h,r,x,y);
  new Ajax.Updater(
      'modal',
      urlbase+'inc/ajax.i.php',
      {
        method: 'post',
        parameters: {
        			  page: 'global',
                      fonction: fx,
                      idFather:id,  
                      width: w,
                      height: h,
                      modifiers: m,
                      x: x,
                      y: y,
                      icon: icon
                    },
        onSuccess: closeOperationInProgressExt
      }
  );
}

function makeMessageSubmit(nameform,fx)
{
	ajax_modal(fx,"",400,350,nameform,"","","","setting");
}

function setModal(w,h,r,x,y)
{
	screenSize=seeOperationInProgress();
	div_block('modal');
	divforsize=getElmt('unactivate_action');
	div=getElmt('modal');
	if (w!=0 || w!="")
		div.style.width=w+"px";
	if (h!=0 || h!="")
		div.style.height=h+"px";
	posLeft=((screenSize["W"]-w)/2);
 	div.style.left=posLeft.toFixed(0)+"px";
 	posTop=((screenSize["H"]-h)/2);
 	div.style.top=posTop.toFixed(0)+"px";
}

function seeOperationInProgress()
{
	div_block('unactivate_action');
	div_block('operation_in_progress');
	divforsize=getElmt('unactivate_action');
	if (window.innerWidth)
    {
      var screenW=window.innerWidth;
      var screenH=window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) 
    { 
		var screenW = document.documentElement.clientWidth;
		var screenH = document.documentElement.clientHeight;
		divforsize.style.width=screenW;
		divforsize.style.height=screenH;
	}
    else
    {
    	var screenW=divforsize.offsetWidth;
    	var screenH=divforsize.offsetHeight;
    }
    div=getElmt('operation_in_progress');
    w=260;
    h=50;
	div.style.width=w+"px";
	div.style.height=h+"px";
	posLeft=((screenW-w)/2);
	div.style.left=posLeft.toFixed(0)+"px";
  	posTop=((screenH-h)/2);
  	div.style.top=posTop.toFixed(0)+"px";
  	div.innerHTML='<img src="'+urlbase+'img/ajax-loader.gif" style="display:block;margin:auto;margin-top:10px;" />';
  	var ret=new Array();
  	ret["W"]=screenW;
  	ret["H"]=screenH;
  	return ret;
  }
  	

function closeOperationInProgress()
{
	div_none('unactivate_action');
	closeOperationInProgressExt();
}

function closeOperationInProgressExt()
{
	div_none('operation_in_progress');
	div=getElmt('operation_in_progress');
	div.style.backgroundColor="transparent";
	div.innerHTML='';
}

function closeModal()
{
	div_none('modal');
	div_none('unactivate_action');
}

var currentBubbleActive=0;
var currentmodifytop=0;
var currentmodifyleft=0;
var bubbleTimeoutObj = null;
var bubbleXMouse = null;
var bubbleYMouse = null;

function bubble_setTimeout()
{
	if (bubbleTimeoutObj != null)
	{
		clearTimeout(bubbleTimeoutObj);
	}
	bubbleTimeoutObj = setTimeout("unsee_bubble()",400);
}


function unsee_bubble()
{
   	if ( jQuery("#bubble_content:visible").size() != 0)
   	{
		var cnt = jQuery("#bubble_content");
		var bbl = cnt.offset();
		if ((  bbl.left<= bubbleXMouse && (bbl.left + cnt.width())   >= bubbleXMouse &&
				bbl.top<= bubbleYMouse &&   (bbl.top + cnt.height()) >= bubbleYMouse ) // In bubble_content
				
			 ||
		 	(bbl.left<= bubbleXMouse && (bbl.left + 65) >= bubbleXMouse &&
				(bbl.top + cnt.height())<= bubbleYMouse &&   (bbl.top + cnt.height()+70) >= bubbleYMouse )) // A square below bubble_content
		{
			bubble_setTimeout();
		}
		else
		{
			divcontent=getElmt("bubble_content");
			divcontent.style.display='none';
			div=getElmt("bubble");
			div.style.width="0px";
			div.style.height="0px";
			div.style.display='none';
			currentBubbleActive=0;
		} 
	}

}

function see_bubble(divid,modifytop,modifyleft)
{
	var txtbrowser="";
    /*jQuery.each(jQuery.browser, function(i, val) {
    	txtbrowser=txtbrowser+i+ " : " + val + " | ";
	    });
    alert (txtbrowser);*/
	if (currentBubbleActive!=0)
	{
		unsee_bubble();
	}
	var parents;
	var left;
	var position;
	var top;
	parents=jQuery("#global_"+divid).parents("div");
	top=0;
	left=0;
	for (i=0;i<parents.length;i++)
	{
			position=jQuery(parents[i]).position();
			left=left+position.left;
			top=top+position.top;
	}
	position=jQuery("#global_"+divid).position();
	left=left+position.left;
	top=top+position.top;
	var div;
	div=getElmt("bubble");
	var divcontent;
	divcontent=getElmt("bubble_content");
	var html;
	html=jQuery("#"+divid).html();
	jQuery("#bubble_content").html(html);
	jQuery("#bubble_content").show();
	div.style.display='block';
	top=top-divcontent.offsetHeight-15+modifytop;
	left=left+modifyleft;
	if (jQuery.browser.safari)
	{
		left=left+150;
	}
	div.style.top=top+"px";	
	div.style.left=left+"px";
	currentmodifytop=modifytop;
	currentmodifyleft=modifyleft;
	currentBubbleActive=divid;
	bubble_setTimeout();
}
function outTracker(IdSpot,IdArticle,Url,Domain)
{
  new Ajax.Request(urlbase+'inc/ajax.i.php', {
        method: 'post',
        parameters: {
          page: 'spot',
          fonction: 'outracker',
          IdSpot:IdSpot,  
          IdArticle: IdArticle,
          Url: encodeURIComponent(Url),
          Domain: encodeURIComponent(Domain)
        }
      });
}

function doCommentsForms(divid,idCom)
{
	if(jQuery('#'+divid+idCom).is(':hidden'))
	{
		jQuery('#'+divid+idCom).show();
		getCommentsForms(divid,idCom);
	}
	else
	{
		jQuery('#'+divid+idCom).html('&nbsp;');
		jQuery('#'+divid+idCom).hide();
	}
}


function getCommentsForms(divid,idCom)
{
	jQuery('#form_comment').appendTo('#'+divid+idCom).show();
	jQuery('#form_comment form').attr('name','myforms_'+idCom);
	jQuery('#form_comment input[name=IdParent]').val(idCom);
	jQuery('#form_comment div.btn_submit_comment a').click(function(){
		jQuery('#form_comment form').submit();
		return false;});
}


jQuery(document).ready(function(){
   jQuery().mousemove(function(e){
   	  bubbleXMouse = e.pageX;
   	  bubbleYMouse = e.pageY;
   }); 
})

function see_wall_spot(type,size)
{
	if (current_wallspot!=type)
	{
		if (size_wallspot=="all")
		{
			jQuery("#all_"+current_wallspot).hide();
			jQuery("#first_"+current_wallspot).hide();
		}
		else
		{
			jQuery("#first_"+current_wallspot).hide();
		}
		jQuery("#link_"+current_wallspot).attr("class","spot_filter");
		jQuery("#first_link_"+current_wallspot).show();
	}
	jQuery("#"+size+"_"+type).show();
	jQuery("#link_"+type).attr("class","active_spot_filter");
	if (size=="all")
		jQuery("#first_link_"+current_wallspot).hide();
	current_wallspot=type;
	size_wallspot=size;
}

function show_all_contact()
{
	jQuery("#all_contact").show();
	jQuery("#link_allcontact").hide();
}

function hide_all_contact()
{
	jQuery("#all_contact").hide();
	jQuery("#link_allcontact").show();
}

function get_content_with_ajax(selector,page,fx,idTpl)
{
	jQuery(selector).load(urlbase+'inc/ajax.i.php',
			  {page: page,
		      fonction: fx,
		      idtpl: idTpl
			  }
	);
}

function ajax_spot_proposition(selector,page,fx,idSpot)
{
	seeOperationInProgress();
	jQuery(selector).load(urlbase+'inc/ajax.i.php',
			  {page: page,
		      fonction: fx,
		      idSpot: idSpot,
		      fromProposition:1
			  },
			  function (){closeOperationInProgress();}
	);
}

function ajax_refresh_spot_proposition()
{
	clearTimeout("ajax_refresh_spot_proposition()");
	selector="#home_spot_proposition";
	jQuery(selector).load(urlbase+'inc/ajax.i.php',
			  {page: "spot",
		      fonction: "refresh-spot-propositions"
			  }
	);
}

function ajax_refresh_activities()
{
	jQuery("#my_wall_activities").load(urlbase+'inc/ajax.i.php',
			  {page: "smarty",
	      fonction: "refresh-activities"
		  });
}

function makeFormCommentOnWall(idArticle,idSpot)
{
	selector="#addFormComment_"+idArticle;
	selector_add="#addComment_"+idArticle;
	img='<center><img src="'+urlbase+'img/ajax-preloader.gif" align="center" /></center>';
	jQuery(selector).click(function(){return 0;});
	jQuery(selector).html(img);
	jQuery(selector).load(urlbase+'inc/ajax.i.php',
				{page: "smarty",
		      	fonction: "make-form-comment",
		      	IdArticle: idArticle,
		      	IdSpot: idSpot
				},
		function(){
					jQuery('textarea#comment_area_'+idArticle).focus();
		}
	);
	jQuery(selector_add).hide();
	jQuery(selector).show();
}

function hideFormCommentOnWall(idArticle)
{
	selector="#addFormComment_"+idArticle;
	selector_add="#addComment_"+idArticle;
	jQuery(selector_add).show();
	jQuery(selector).hide();
}

function submit_comment_ajax(idArticle,idSpot)
{
	selector_display="#comment_article_event_"+idArticle;
	selector="#addFormComment_"+idArticle;
	selector_add="#addComment_"+idArticle;
	jQuery(selector_add).show();
	jQuery(selector).hide();
	comment_to_add=jQuery('textarea#comment_area_'+idArticle).val();
	html=jQuery(selector_display).html();
	jQuery(selector_display).load(urlbase+'inc/ajax.i.php',
			{page: "smarty",
	      	fonction: "store_comment_to_home",
	      	IdArticle: idArticle,
	      	IdSpot: idSpot,
	      	comment: comment_to_add
			},
			function(){
				html2=jQuery(this).html();
				jQuery(this).html(html+html2);
			}
	);
}

function ajax_add_feed_rss(idSpot,idUser)
{
	seeOperationInProgress();
	selector_display="#feed_rss";
	feed_to_add=jQuery('input#urlToAdd').val();
	jQuery('input#urlToAdd').val("");
	html=jQuery(selector_display).html();
	jQuery(selector_display).load(urlbase+'inc/ajax.i.php',
			{page: "smarty",
	      	fonction: "add-feed-to-spot",
	      	IdUser: idUser,
	      	IdSpot: idSpot,
	      	feed: feed_to_add
			},
			function(){
				closeOperationInProgress();
			}
	);
}

function ajax_refresh_feed(idSpot)
{
	seeOperationInProgress();
	selector_display="#feed_rss";
	jQuery(selector_display).load(urlbase+'inc/ajax.i.php',
			{page: "smarty",
	      	fonction: "refesh-feed-to-spot",
	      	IdSpot: idSpot
			},
			function(){
				closeOperationInProgress();
			}
	);
}

function ajax_delete_feed(idFeed,idSpot)
{
	seeOperationInProgress();
	selector_display="#feed_rss";
	jQuery(selector_display).load(urlbase+'inc/ajax.i.php',
			{page: "smarty",
	      	fonction: "delete-feed-to-spot",
	      	IdSpot: idSpot,
	      	IdFeed: idFeed
			},
			function(){
				closeOperationInProgress();
			}
	);
}