/**
 *	CONTACTS JS
 *	http://www.ioscoop.com
 *
 *	Copyright 2011, Nescio Hermitage
 *	
 *	@version 2011/02/25
 *	@author Thijs Zandvliet
 */

	function contacts()
	{
	
		/* set the location of the ajax file */
		this.dest = '/engine/ajax/ajax.php';
		
		
		/**
		 *	Initialize
		 */
		this.init = function()
		{
			$('img').tooltip({
				showURL: false
			});
		
			$('a').tooltip({
				showURL: false
			});
		}
    
    
    /**
     *  Initialize the dialog
     */
    this.initDialog = function()
    {
      $('#keyword').keyup(function(e) {
        if(e.keyCode == 13) contacts.search();
      });
    }
    
    
    /**
     *  Show contact dialog
     */
    this.dialog = function()
    {
      req = "f=contacts&action=dialog";

      var buttons = {};
			buttons[contacts_dialog_search] = function() { contacts.search(); };
			$('#dialog').dialog('option', 'buttons', buttons);
    
      $.get(this.dest, req, function(data) {
        main.showOverlay(contacts_dialog_header, data);
      });
    }
    
    
    /**
     *  Search contact
     */
    this.search = function()
    {
      $('#dialog').dialog('close');
      window.location = "/contacts/search/" + $('#keyword').val();
    }
    
    
    /**
     *  Add contact
     */
    this.add = function(id)
    {
      req = "f=contacts&action=add&id=" + id;
      $('#dialog').dialog('option', 'buttons', { "OK": function() { $('#dialog').dialog('close'); } });
      
      $.get(this.dest, req, function(data) {
        main.showOverlay('Contact toevoegen', data);
        setTimeout("location.reload(true);", 200);
      });
    }
    
    
    /**
     *  Remove contact
     */
    this.remove = function(id)
    {
      req = "f=contacts&action=remove&id=" + id;
  
      if(confirm ("Weet je zeker dat je deze contact wilt verwijderen ?"))
      {
        $.get(this.dest, req, function(data) {
          main.fadeOut(id);
        });
      }
    }
		
	
	}
	
	
	/**
	 *	Create a new contacts js object
	 */
	$(document).ready(function() {
		contacts = new contacts();
	});
