

function click(type) {
	new Ajax.Request("public-tools/click.php", {
    onSuccess : function(resp) {
    },
    onFailure : function(resp) { alert(resp.responseText); },
    parameters : "type="+type
  	});
}





var uid;
function emotty(content,id)
{
  uid = id;
  if (content=='ripemoticons')
  {
    var pe = new PeriodicalExecuter(update_emo_display,5);
    if (document.getElementById('msn-account-number')) {
    	//document.getElementById('msn-account-number').innerHTML = getMsnId(getEmail());
    }
  }
  else if (content=='home'||content=='index'||content==''||content=='test')
  {
    random_panel_start();
  }
}


var count_random_clicks = 1;
function random_panel_start()
{
	if (count_random_clicks > 2) {

		document.getElementById("random-panel-button").innerHTML = "<a href=\"register\">register your free account</a> &gt;&gt;";
	}

	new Ajax.Request("public-tools/random_panel.php", {
    onSuccess : function(resp) {
    	//alert(resp.responseText);
        document.getElementById('random-panel').innerHTML = resp.responseText;//andom_panel_load(resp.responseText);
    },
    onFailure : function(resp) { alert(resp.responseText); },
    parameters : "type=generate"
  });
  count_random_clicks++;

}




function getEmail()
{
  var r;
  new Ajax.Request("public-tools/get.php", {
    onSuccess : function(resp) {
        r = resp.responseText;
    },
    onFailure : function(resp) {  },
    parameters : "id="+uid+"&type=email"
  });
  return r;
}

function getMsnId(email)
{
    var x = 0;
    for (var i = 0; i < email.length; i++) {
        x = x * 101;
        x = x + email[i];
    }
    if (x)
      return x;
    else 
      return "MSN ACCOUNT NUMBER";
}

var response = '';
function update_emo_display()
{
   new Ajax.Request("public-tools/emoticon.php", {
    onSuccess : function(resp) {
      if (response != resp.responseText)
      {
        document.getElementById('emoticon-panel').innerHTML = resp.responseText;
        response = resp.responseText;
      }
    },
    onFailure : function(resp) { alert(resp.responseText);  },
    parameters : "type=crawl"
  });
}

function addToFavourites(id)
{
        new Ajax.Request("public-tools/add_to_favourites.php",
        {
                onSuccess : function(resp) {
                	
                        $("add-to-list").innerHTML = 'This emoticon is now one of your favourites';
                },
                onFailure : function(resp) {
                                $("add-to-list").innerHTML = 'Failed to add this emoticon to your favourites';
                },
                parameters : "emoticon_id="+id
        });
}


function browse (l,type)
{
  new Ajax.Request("public-tools/browse.php", {
    onSuccess : function(resp) {
      draw(resp.responseText);
    },
    onFailure : function(resp) {  },
    parameters : "type="+type+"&l="+l
  });
}

function draw(text)
{
  alert(text);
}

var tool_switch = -1;
function emoticon_tool (type)
{
  tool_switch *= -1;
  if (tool_switch == 1)
  {
  new Ajax.Request("public-tools/emoticon_tool.php", {
    onSuccess : function(resp) {
      document.getElementById('syncd').innerHTML = 
  '<input type="button" class="button-2" value="Hide syncronized emoticons" onclick="emoticon_tool(\'sync\')" /><br />'
       + resp.responseText;
    },
    onFailure : function(resp) {  },
    parameters : "type="+type+"&uid="+uid
  });
  }
  else if (type == 'sync' && tool_switch == -1)
  {
    document.getElementById('syncd').innerHTML 
      = '<input type="button" class="button-2" value="Show syncronized emoticons" onclick="emoticon_tool(\'sync\')" />';
    
  }
}

function select ( input )
{
  if (document.getElementById(input.id).className != 'selected')
    document.getElementById(input.id).className = 'selected';
  else
    document.getElementById(input.id).className = '';
}

function selectAll ( )
{
  elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
       elements[x].className='selected';
  }
}


function deselectAll ( )
{
  elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
    elements[x].className='';
  }
}

function submit()
{
	
  var files = '';
  elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
    if (elements[x].className == 'selected')
    { 
      files += elements[x].id + '/';
    }
  }
  if (files)
  {
   document.getElementById('files').value = files;
   document.getElementById('submit-emoticon').submit();
  }
}

function unmask()
{
	return;
	update_emo_display();
 /* elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
    if (elements[x].className == 'selected')
    { 
      elements[x].src = 'usr/'+uid+'/'+elements[x].id;
    }
  }*/
}

function mask()
{
		return;

  elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
    if (elements[x].className == 'selected')
    { 
      elements[x].src = 'images/masked.gif';
    }
  }
}

function delete_emoticon( src )
{
  var files='';
  elements = document.getElementsByName('emoticon-tool');
  for (x = 0; x < elements.length; x++)
  {
    if (elements[x].className == 'selected')
    { 
      var yn = confirm ("Are you sure you want to delete " + elements[x].id);
      if (yn)
      {
        elements[x].className = '';
        elements[x].style.display = 'none';
        files += elements[x].id + '/';
      } 
    }
  }
  if (files) 
  {
    new Ajax.Request("public-tools/delete.php", {
      onSuccess : function(resp) { 
      },
      onFailure : function(resp) {  },
      parameters : "files="+files
    });
  } 
}

