function holos_emailInvite(){
	var email = $F('invite_email');
	
	new Ajax.Request('/ajax/inviteuser', {
		parameters: 'email='+email,
		method: 'post',
		onCreate : function(transport) {$('inviteResponce').innerHTML = 'Sending the invite';},
		onSuccess: function(transport) {
			$('inviteResponce').innerHTML = transport.responseText;
		
		}

	});
}
function listComments(content_type,content_id,page){
	new Ajax.Request('/ajax/get-comments/'+content_type+'/'+content_id+'/'+page, {
		parameters: null,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
			$('commentArea').innerHTML = transport.responseText;
		}
	});
}
function postComment(){
	new Ajax.Request('/ajax/post-comment', {
		parameters: null,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
			$('commentArea').innerHTML = transport.responseText;
		}
	});
}

function saveComment(){
	
	Element.extend('description_field');
	var desValue = $('description_field').getValue().strip();
	
	if(desValue.empty()){
		//alert("please enter a comment");
		$('description_error').setStyle({display: 'block'});
		$('description_error').innerHTML = "Please Enter a Comment";
		var mW = $('modalWindow').getWidth();
		var mH= $('modalWindow').getHeight();
		Lightview.resize({ width: mW, height: mH });
	}else{
		/*$('commentForm').request({
			onComplete: function(){ alert(desValue);}
		})*/
		
		$('commentForm').submit();
	}
};

function joinGroup(id){
	new Ajax.Request('/ajax/join-group/'+id, {
		parameters: null,
		method: 'get',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
			$('AJAXresponce').innerHTML = transport.responseText;
			//alert('You have now joined this group');
			var url = window.location;
			url = cleanURL2(url);
			window.location.href=url+'/?message=You+have+joined+this+group';
			$('addMember').innerHTML = '<a href="#" onclick="leaveGroup('+id+')">Leave this group</a> ';
		}
	});
}
function leaveGroup(id){
	new Ajax.Request('/ajax/leave-group/'+id, {
		parameters: null,
		method: 'get',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
			$('AJAXresponce').innerHTML = transport.responseText;
			//alert('You have now left this group');
			var url = window.location;
			url = cleanURL2(url);
			window.location.href=url+'/?message=You+have+left+this+group';
			$('addMember').innerHTML = '<a href="#" onclick="joinGroup('+id+')"><img src="/assets/images/groups/joinGroup.jpg" alt="Join {$group.name}" width="180" height="35" /></a>';
		}
	});
}

function password_recover() {
	var opts = {
	  href: '/passsword-recover',
	  rel : 'ajax',
	  title: "Password recovery",
	  options: {
	    autosize: true,
	    topclose: true
	  }
	};
	Lightview.show(opts);


}
function lightview_pop(url,ttitle) {
	var opts = {
	  href: url,
	  rel : 'ajax',
	  //title: ttitle,
	  options: {
	    autosize: true,
	    topclose: true
	  }
	};
	Lightview.show(opts);


}

function lightview_popInline(url) {
	var opts = {
	  href: url,
	  rel : 'inline',
	  //title: ttitle,
	  options: {
	    autosize: true,
	    topclose: true
	  }
	};
	Lightview.show(opts);


}


function removePhoto(id){

	var url = '/image-manager/delete/'+id+'/'; 
	
	new Ajax.Request(url, {
		onComplete: function(transport) {
   			 if (200 == transport.status)
      			Effect.DropOut('image_'+id);
 		 	}
	});
}

function revealTopMessage(id){
	
	Effect.Appear(id, { delay: 0, duration: .8});
	//Effect.DropOut(id, { delay: 2, duration: 0.8 });
}

function deleteBlog(id){

	var url = '/blog/delete/'+id+'/'; 
	
	new Ajax.Request(url, {
		onComplete: function(transport) {
   			 if (200 == transport.status)
      			Effect.DropOut('blog_'+id);
 		 	}
	});
}


function force_login() {
	Lightview.show({
	  href: '/login',
	  rel : 'ajax',
	  //title: "Log In",
	  options: {
	    autosize: true,
	    topclose: true
	  }
	});


}
function tb_show(ttitle,url,group) {
	var opts = {
	  href: url,
	  rel : 'iframe',
	  title: ttitle,
	  options: {
	    autosize: true,
	    topclose: true
	  }
	};
	Lightview.show(opts);


}
hasRun = false;
function runSpinner(){
	
	if(hasRun){
	return false;
	}
	hasRun = true;
	$('loading_area').innerHTML = 'Uploading... <img src="/assets/images/loading.gif" />'

}

function commentDelete(id){
	if(!confirm('Are you sure you want to delete this?')){
		return false;
	}
	//$('comment_'+id).style.display = 'none';
	Effect.DropOut('comment_'+id);
	new Ajax.Request('/ajax/removecomment', {
		parameters: 'comment='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
		}

	});
}
function eventDelete(id){
	if(!confirm('Are you sure you want to delete this?')){
		return false;
	}
	Effect.DropOut('event_'+id);
	new Ajax.Request('/ajax/removeevent', {
		parameters: 'event='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
		}

	});
}
function removeFriend(id){
	if(!confirm('Are you sure you want to delete this?')){
		return false;
	}
	$('friend_'+id).style.display = 'none';
	new Ajax.Request('/ajax/removefriend', {
		parameters: 'user='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
		}

	});

}
function removeMessage(id){
	if(!confirm('Are you sure you want to delete this?')){
		return false;
	}
	$('message_'+id).style.display = 'none';
	new Ajax.Request('/ajax/removemessage', {
		parameters: 'message='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
		}

	});

}
function markRead(id){
	$('readstatus_'+id).innerHTML = '<a href="#messagetop" onclick="markUnread(\''+id+'\')">Mark as unread</a>';
	new Ajax.Request('/ajax/readmessage', {
		parameters: 'message='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
		
		}

	});
}
function markUnread(id){
	$('readstatus_'+id).innerHTML = '<a href="#messagetop" onclick="markRead(\''+id+'\')">Mark as read</a>';
	new Ajax.Request('/ajax/unreadmessage', {
		parameters: 'message='+id,
		method: 'post',
		onCreate : function(transport) {},
		onSuccess: function(transport) {
			
		}

	});
}
function cleanURL(url){
	
	var t_url = new String(url);
	
	if(t_url.indexOf('#') > 0){
		t_url = t_url.substring(0,t_url.indexOf('#'));
	}
	return t_url;
}
function cleanURL2(url){
	
	var t_url = new String(url);
	
	if(t_url.indexOf('#') > 0){
		t_url = t_url.substring(0,t_url.indexOf('#'));
	}
	if(t_url.indexOf('/?') > 0){
		t_url = t_url.substring(0,t_url.indexOf('/?'));
	}
	return t_url;
}
var collapsedDays = [false,false,false,false,false,false,false];
function collapseDay(day){
	var collapseButton = $(day+'_img');
	if(collapsedDays[day] == true){
	 collapseButton.src = '/assets/images/profile/workouts/icons/minimize.gif';
	 $(day+'_listing')
	 collapsedDays[day] = false;
	 $(day+'_listing').style.display = 'block';
	}else{
	  collapseButton.src = '/assets/images/profile/workouts/icons/expand.gif';
	  collapsedDays[day] = true;
	  $(day+'_listing').style.display = 'none';
	}
	
}
function expandAllDays(){
	collapsedDays.each(function(boolvalue,day) {
	
		if(boolvalue == true){
			collapseDay(day);
		}
	});
}

 weightGoal = 0;
weightCur = 0;
function weightTrackerUpdate(){
	weightGoal = $F('goalWeight');
	weightCur = $F('curWeight');
	new Ajax.Request('/ajax/weighttracker', {
		parameters: 'weight='+weightCur+'&goal='+weightGoal,
		method: 'post',
		onCreate : function(transport) {$('AJAXresponce').innerHTML = 'AJAX request pending!';},
		onSuccess: function(transport) {
			$('AJAXresponce').innerHTML = transport.responseText;
			$('weightCur').innerHTML = weightCur;
			$('weightGoal').innerHTML = weightGoal;
			$('weightToGo').innerHTML = weightCur-weightGoal;
		}          
	});
	$('weightInput').style.display='none';
	$('weightSubmit').style.display='block';
  return false;

}
function weightTrackerLoad(goal,cur){
	weightGoal = goal;
	weightCur = cur;
	$('weightToGo').innerHTML = weightCur-weightGoal;
}
var req;

function navigate(month,year) {
	   var url = "/ajax/calendar/"+month+"/"+year;
	   if(window.XMLHttpRequest) {
			 req = new XMLHttpRequest();
	   } else if(window.ActiveXObject) {
			 req = new ActiveXObject("Microsoft.XMLHTTP");
	   }
	   req.open("GET", url, true);
	   req.onreadystatechange = callback;
	   req.send(null);
}

function callback() {        
	   obj = document.getElementById("calendar");
	   setFade(0);
	   
		if(req.readyState == 4) {
			 if(req.status == 200) {
				    response = req.responseText;
				    obj.innerHTML = response;
				    fade(0);
			 } else {
				    alert("There was a problem retrieving the data:\n" + req.statusText);
			 }
	   }
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
}

function setFade(amt) {
	obj = document.getElementById("calendar");
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}


