//prevent IE from submitting the chat form on enter press
function noEnterSubmit(form) {
  if(window.event && window.event.keyCode == 13)
  {
    submitMessage(form);
	return false;
  }
}

/*
* JS DEBUGGER
*/

if($('jsdebuggercontainer'))
{
	new Draggable('jsdebuggercontainer');
}

function writeDebug(string)
{
	$('jsdebugger').innerHTML += string + '<br />';
}

function debug(something)
{
	if (window.console)
	{
		console.log(something);
	}
	
	if($('jsdebugger'))
	{
		if(typeof(something) == 'object')
		{
			writeDebug(something);
			for(property in something)
			{
				writeDebug(property+': '+something[property]);
			}
		}
		else
		{
			writeDebug(something);
		}
	}
}

function buildAjaxUrl($function)
{
	return "index.php?ajax=1&ajaxfunction="+$function;
}

//slideout signup form on intro page
if($('signuplink'))
{
	$('signuplink').connect('click',function(event){
					Effect.SlideDown('signupdropdown'); 
					return false;}
					);
}	

//confirmation popup for "drastic" actions like deleting an order or product, or resetting the entire db (used on admin pages where you can delete stuff).
// the "actionRequested" argument should take the form of "delete this order" or "reset the entire shop"
function confirmSubmit(actionRequested)
{
//"confirm" shows an "OK and "Cancel" popup and returns 1 or 0 depending on what the user chose
var agree = confirm("Sure you want to " + actionRequested + "? You cannot undo this!");
	if(agree)
		return true;
	else
		return false;
}

Event.observe(window,'load',function()
{
	if($('opengames'))
	{
		refreshOpenGames();
	}
});

Event.observe(window,'load',function()
{

	if($('chatboxdragcontainer'))
	{
		DragCorner('chatboxdragcontainer','draghandle');
	}

	if($('jsdebuggercontainer'))
	{
		new Draggable('jsdebuggercontainer',{handle:'jsdebuggertitle'});
	}
	
	if($('chatboxdragcontainer'))
	{
		new Draggable('chatboxdragcontainer',{handle:'chatboxtitle'});
	}
	if($('comments') != null)
	{
		updateComments();
	}
	
	if($('iewarning') == null)
	{
		if ($('txt_username'))
		{
			$('txt_username').focus();
			$('txt_username').select();
			$('txt_username').observe('click',function(event){
					event.element().focus();
					event.element().select();
					});
		}
	}
	
	if($('whysignuplink'))
	{
		$('whysignuplink').observe('click',function(){
			Effect.Highlight('whysignup');
			});
	}
});

/*
* RESIZABLE DIVS
* source: http://www.cfchris.com/cfchris/index.cfm/2009/2/18/How-To-Prototype-Drag-Corner
*/

function DragCorner(container, handle) {
      var container = $(container);
      var handle = $(handle);
      
      /* Add property to container to store position variables */
      container.moveposition = {x:0, y:0};
      
      function moveListener(event) {
         /* Calculate how far the mouse moved */
         var moved = {
                     x:(event.pointerX() - container.moveposition.x),
                     y:(event.pointerY() - container.moveposition.y)
                  };
         /* Reset container's x/y utility property */
         container.moveposition = {x:event.pointerX(), y:event.pointerY()};
         /* Border adds to dimensions */
         var borderStyle = container.getStyle('border-width');
         var borderSize = borderStyle.split(' ')[0].replace(/[^0-9]/g,'');
         /* Padding adds to dimensions */
         var paddingStyle = container.getStyle('padding');
         var paddingSize = paddingStyle.split(' ')[0].replace(/[^0-9]/g,'');
         /* Add things up that change dimensions */
         var sizeAdjust = (borderSize*2) + (paddingSize*2);
         /* Update container's size */
         var size = container.getDimensions();
         container.setStyle({
               height: size.height+moved.y-sizeAdjust+'px',
               width:size.width+moved.x-sizeAdjust+'px'
            });
      }
      
      /* Listen for 'mouse down' on handle to start the move listener */
      handle.observe('mousedown', function(event) {
         /* Set starting x/y */
         container.moveposition = {x:event.pointerX(),y:event.pointerY()};
         /* Start listening for mouse move on body */
         Event.observe(document.body,'mousemove',moveListener);
      });
      
      /* Listen for 'mouse up' to cancel 'move' listener */
      Event.observe(document.body,'mouseup', function(event) {
         Event.stopObserving(document.body,'mousemove',moveListener);
      });
   }

   
   //DragCorner('DivTwo','DragHandleTwo');
