﻿function getUrlParameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function clearChilds(objContainer)
{
    if ( objContainer.hasChildNodes() )
    {
        while ( objContainer.childNodes.length >= 1 )
        {
            objContainer.removeChild( objContainer.firstChild );       
        } 
    }
}

/* 
--------------------------------------------------------------------
Returns grid X,Y according cursor position
-------------------------------------------------------------------- 
*/
function getGridXY(cursorX, cursorY)
{
    var gridPosition = new Array(2);
    
    gridPosition[0] = getGridPosition(cursorX);
    gridPosition[1] = getGridPosition(cursorY);

    return gridPosition;
}

/* 
--------------------------------------------------------------------
Calculate a grid position
-------------------------------------------------------------------- 
*/
function getGridPosition(cursorPosition)
{
    var valueRounded = Math.round((cursorPosition / _tileWidth));
    var valueDecimal = Math.round((cursorPosition / _tileWidth)*10)/10;
    
    if (valueDecimal > valueRounded)
    {
        valueRounded = valueRounded + 1;
    }
    
    return valueRounded;
}

function send(message)
{
    Game.EreptoriaService.sendMessage(message);
}