user = {};


user.goToProfile = function(duid){

	window.location = '/profile.php?u='+duid;

}


user.featuredUserRemove = function(duid){

		var dialogDiv = document.createElement("div");
		dialogDiv.id = "dialog_"+duid;
		dialogDiv.className='flora';

		htmlStr = "<div id='dialogMessage'>Are you sure you want to remove this user as the featured user?</div>";
		$(dialogDiv).html(htmlStr);
		$("#bodyRight").append(dialogDiv);
		
		var removedDialog = document.createElement("div");
		removedDialog.id = "remove_"+duid;
		removedDialog.className='flora';
		$(removedDialog).html("<div id='dialogMessage2'>This user has been removed from the featured user list</div>");
		
		$(dialogDiv).dialog({
		 buttons: {
		 "Ok": function(){	
		
		   url = "/api/featured.php?c=removeUser&uid="+duid;
			var dialogFoo = $(this);				
				$.getJSON(url, function(response){
					  $(dialogFoo).dialog("close");
					  $(dialogFoo).remove();
					  $("#bodyRight").append(removedDialog);
					  $(removedDialog).dialog({
					  	buttons: {
					  		"Ok": function(){
					  			$(removedDialog).dialog("close");
					  			$(removedDialog).remove();
					  			
					  			var surl = unescape(window.location.href);
					  			window.location=surl;
					  			
					  		}}});
					  
				});      	      	

		 },
		 
		 "Cancel": function(){
		 
		 	$(dialogDiv).dialog("close");
		 	$(dialogDiv).remove();
		 }
		 
		 }
		});



};



user.featuredUser = function(duid){

	var dialogDiv = document.createElement("div");
		dialogDiv.id = "dialog_"+duid;
		dialogDiv.className='flora';
		
		htmlStr = "<div id='dialogMessage'>This is a preview of what the card will look like. Click OK to accept</div>";
		htmlStr += "<div id='dialogContent'></div><div id='optionalContent'>If you'd prefer different Text type it in here!";
		htmlStr += "<textarea id='optionalText' style='width: 400px;'></textarea></div>";
		var scr = document.createElement("script");
			$(scr).attr("type","text/javascript");
		txtStr = "$('#optionalText').keyup(function(){$('.featuredUserTxt').text($('#optionalText').val());});";
		$(scr).text(txtStr);		

		$(dialogDiv).html(htmlStr);
		dialogDiv.appendChild(scr);

		var cs = document.getElementById("content");
		cs.appendChild(dialogDiv);
		
		$("#dialogContent").load("/api/featured.php?c=getUser&uid="+duid);				
		$("#dialog_"+duid).dialog(
			{
			width: 525,
			height: 500,
			buttons: { 
      		  "Ok": function() { 
				  var optionalText = $('#optionalText').val();
				  url = "/api/featured.php?c=setUser&uid="+duid+"&optionalText="+optionalText;
					
					var dialogFoo = $(this);
								
					$.getJSON(url, function(response){
						 $(dialogFoo).dialog("close");
						  $(dialogFoo).remove();
						  window.location = "/";
					});      	      	
       		   }, 
       		 "Cancel": function() { 
          	  $(this).dialog("close"); 
          	  $(this).remove();
        	} 
  	  		}});

}

user.inviteUser = function(emailAddress,userName){
		try{
	var subject = "You've been invited to join the Motherhood!";
	var message = "Hello! "+userName+" recently invited you to join the Motherhood!";
		
		message +="<p>To accept this invitation, please visit <a href='http://www.themotherhood.com'>The Motherhood</a> </p>";
		message +="<p>Hope to see you there!<br> Emily and Cooper from the Motherhood</p>";
	
	var sendingDialog = document.createElement("div");
		sendingDialog.id="sendingDialog";
		sendingDialog.className="flora";
		
		
		$(sendingDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Your invite is being sent...<Br><img src='/facebox/loading.gif'></div>" );
	
	$("#bodyRight").append(sendingDialog);
	$(sendingDialog).dialog({
		buttons: {
		"Ok":function(){
		}
		
		}
	});
	
	$('.ui-dialog-buttonpane button').hide();
	
	var url = "/api/sendInvite.php";
	var params = {
		"to": emailAddress,
		"message": message,
		"subject": subject
	};
	$.getJSON(url, params, function(data){
		
		$(sendingDialog).dialog("close");
		$(sendingDialog).remove();
		
		var successDialog = document.createElement("div");
		successDialog.id="sendingDialog";
		successDialog.className="flora";
		$("#bodyRight").append(successDialog);
		$(successDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Your invite has been sent.</div>" );
	
	$(successDialog).dialog({
		buttons: {
		"Ok":function(){
			$(successDialog).dialog("close");
			$(successDialog).remove();
			$("#inviteFriendInput").val("");
		}
		
		}
	});

		
	
		
	
	});
	}catch(e){
	}
}