 function fblogin() {
            FB.login(function(response) {
              //...
            }, {perms:'email,user_birthday,user_hometown,user_location, user_likes,user_about_me,offline_access'});
          }
		  
function login(email, password, location) {
	$.post('/users/loginUser', {
		email:email,
		password:password
	},
	function(data) {
    if(data=="1") {
      if(location=="")
        window.top.location.reload();
      else
        window.top.location = location;
    } else {
		$('#signup_error').hide();
      	$('#invalid_info').show();
    }
	},
	"json"
  );
};

function signup(email, password, location) {
	$.post('/users/signupUser', {
		email:email,
		password:password
	},
	function(data) {
	if(data=="1"){
	  if(location=="")
        window.top.location.reload();
      else
        window.top.location = location;
    } else {
	  $('#invalid_info').hide();
      $('#signup_error').show();
	  $('#signup_error p').html(data);
    }
	}
  );
};    

function requestshare(pid) {
	$.post('/wishlists/requestShare/'+pid, {	},
	function(data) {
    if(data=="1") {
      notify("success", "Your share request has been sent successfully");
    } else {
      alert("An error while sending your request");
    }
	},
	"json"
  );
};   

function validateEmail(id) 
{ 
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(id); 

} 

function sendNewPassword(form) {
	//alert('Into sendNewPassword');
	//alert(form);
	var emailaddress = document.getElementById('email').value;
	var isEmailValid = validateEmail(emailaddress);
	//alert('isEmailValid = '+isEmailValid);
	if(!isEmailValid) {
	 notify("failure", "Please enter valid email address");
	       return;
		//alert('Please enter valid email address');
		//return;
	}
	
	$.post('/users/sendnewpassword', {
				email:emailaddress
				},
	       function(data) {
		//alert('received message from server 'data);
		notify("success", "Your new password has been sent to your email address");
		  	
		    
	       }, "json"
	);
}

	function notify(status, message) {
		$.notifyBar({ cls: status, html: message });
	}
	
//This is script to change the text of a password input box from "text" to "password" - on landing page;
    $(document).ready(function() {
 
	$('#password-clear').show();
	$('#password-password').hide();
 
	$('#password-clear').focus(function() {
		$('#password-clear').hide();
		$('#password-password').show();
		$('#password-password').focus();
	});
	$('#password-password').blur(function() {
		if($('#password-password').val() == '') {
			$('#password-clear').show();
			$('#password-password').hide();
		}
	});
 
	$('.filterinputpassword').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});
 
});


(function ($) {
// custom css expression for a case-insensitive contains()
  jQuery.expr[':'].Contains = function(a,i,m){
    return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

function listFilter(header, list) { // header is any element, list is an unordered list
  // create and add the filter form to the header
  var form = $("<form>").attr({"class":"filterform","action":"#"}),
      input = $("<input>").attr({"class":"filterinput clearFieldBlurred clearField","type":"text", "value":"Start typing a Name"});
  $(form).append(input).appendTo(header);

  $(document).ready(function() {
$('.clearField').clearField();
  }); 
  
  $(input)
    .change( function () {
      var filter = $(this).val();
      if(filter) {
          // this finds all links in a list that contain the input,
        // and hide the ones not containing the input while showing the ones that do
        $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
        $(list).find("a:Contains(" + filter + ")").parent().slideDown();
      } else {
        $(list).find("li").slideDown();
      }
      return false;
    })
  .keyup( function () {
      // fire the above change event after every letter
      $(this).change();
  });
} 
//ondomready
$(function () {
  listFilter($("#friendssearchbox"), $("#friendslist"));
});
}(jQuery));


$(function(){
  $(".friendsflybox").tipTip();
});

  $(function(){

$(".profileimagepicture").click(function (e) {
var source = $(this).attr("src");

var overlayhtml = '<form name = "file_upload_form" method="post" enctype="multipart/form-data" action="/users/uploadprofileimage"><p class="changeprofilepicturewords">Change Your Profile Picture</p> '+
	'<div class="profilepic"> '+
	    '<p>Profile Picture:</p> '+
	   ' <img width="50" height="50" src="'+source+'" alt="profile picture" class="profileimagepicture" title="Upload your image to Liv"> '+
	   ' <div class="uploadphoto"> '+
		    '<input id="fileToUpload" name="fileToUpload" size="15" type="file">   '+
	    '</div> '+
	'</div> '+
	'<div> '+
	   ' <input type="submit" class="settingssave" value="Save" id="close"> '+
	'</div> ' +
	'</form>';

	


 $(".changeprofileimage").html(overlayhtml);
  $(".changeprofileimage").dialog({

modal: true,

minHeight:300,

minWidth: 420,

	    open: function (e, ui) {

	var $container = $(this);

	$container.find('#close').click(function(){

		$container.dialog("close");

	});

    },

    beforeClose: function (e, ui) {

	var $container = $(this);

	$container.find('#close').unbind('click');

    }

  });

});
});
  
$(function(){
  $(".leftsidefriendface").tipTip();
});

$(function(){
  $(".addedbyimage").tipTip();
});
    
$(function(){
  $(".chatface").tipTip();
});

$(function(){
  $(".chatfacesmall").tipTip();
});

$(function(){
  $(".likehoverlink").tipTip();
});



function PopupCenter(pageURL, title,w,h) {
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);
  var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

function shareTwitter(url) {
  PopupCenter('http://twitter.com/share?url='+url,'Share on Twitter',400,400);
}

function shareFacebook(url) {
  link = 'http://www.facebook.com/dialog/feed?app_id=123050457758183&redirect_uri=http://test.livthis.com/users/response&link='+url;
  PopupCenter(link,'Share on Twitter',400,400);
}

function addtoMyItems() {
  
}

    $(function(){
	$(".nofriendsimportcontactsbuttonfacebooksmall").click(function (e) {
	$(".importcontactsfacebook").dialog({
	    modal: true,
	    minHeight:362,
	    minWidth: 775,
	    open: function (e, ui) {
		var $container = $(this);
		$container.find('#close').click(function(){
			$container.dialog("close");
		});
	    },
	    beforeClose: function (e, ui) {
		var $container = $(this);
		$container.find('#close').unbind('click');
	    }
	    });
	    });
	});
  
  <!--On click of contact us, this creates the overlay-->
    $(function(){
	$("#importfacebook").click(function (e) {
	$(".importcontactsfacebook").dialog({
	    modal: true,
	    minHeight:362,
	    minWidth: 775,
	    open: function (e, ui) {
		var $container = $(this);
		$container.find('#close').click(function(){
			$container.dialog("close");
		});
	    },
	    beforeClose: function (e, ui) {
		var $container = $(this);
		$container.find('#close').unbind('click');
	    }
	    });
	    });
	});
  
  <!--On click of contact us, this creates the overlay-->
    $(function(){
	$(".importcontactsbuttonfacebookwithgmail").click(function (e) {
	$(".importcontactsfacebook").dialog({
	    modal: true,
	    minHeight:362,
	    minWidth: 775,
	    open: function (e, ui) {
		var $container = $(this);
		$container.find('#close').click(function(){
			$container.dialog("close");
		});
	    },
	    beforeClose: function (e, ui) {
		var $container = $(this);
		$container.find('#close').unbind('click');
	    }
	    });
	    });
	});
  
  <!--On click of Add Facebook friends, this creates the overlay-->
    $(function(){
	$("#addfriendsfacebook").click(function (e) {
	$(".importcontactsfacebook").dialog({
	    modal: true,
	    minHeight:350,
	    minWidth: 644,
	    open: function (e, ui) {
		var $container = $(this);
		$container.find('#close').click(function(){
			$container.dialog("close");
		});
	    },
	    beforeClose: function (e, ui) {
		var $container = $(this);
		$container.find('#close').unbind('click');
	    }
	    });
	    });
	});
