function marginBorder(obj)
{                
    var top = y + 15;
    var left = x - 10;
    var width = $(obj).width();
    var flag = false;
    
    if (((width + x) + 20) > resolution(0))
    {
    	left = ((width + x) - resolution(0)) + 50;
    	left = (x - left);

        flag = true;
    }
    
    if (($(obj).height() + y) > (resolutionHeight(0) - 100))
    {
        top = (($(obj).height() + y) - (resolutionHeight(0) - 100)) + 50;
        top = (y - top);

        flag = true;
    }

    if (flag)
    {
        $(obj).css({
            'top': top,
            'left': left
        });
    }
}

function resolution(subtract)
{
    return window.innerWidth - subtract;
}

function resolutionHeight(subtract)
{
    return window.innerHeight - subtract;
}

function effectShow(elemento)
{
  	$(elemento).fadeIn('slow');
}

function slide(obj, coordinate)
{
    if (coordinate)
    {
        $(obj).css({'position':'absolute', 'left': x, 'top':y+15});
    
        marginBorder(obj);
    }
    
    if ($(obj).css('display') != 'block')
    {
    	$(obj).slideDown();
    }
}

function close(obj)
{
	if ($(obj).attr('class') == 'popup')
	{
		$(obj).hide('slow');
		$(obj).empty();
	}
	else
	{
		$(obj).remove();
	}
}

function setLocation(url){
    window.location.href = url;
}

function emptyForm(obj)
{
	if ($.isArray(obj))
	{
		$.each(obj, function() {
			$('#' + this).val('');
		});
	}
	else
	{
		$(obj).val('');
	}
}


function postwith(to,p)
{
	var myForm = document.createElement('form');
	myForm.method = 'post';
	myForm.action = to;
	
	for (var k in p)
	{
		var myInput = document.createElement('input');
		myInput.setAttribute('name', k);
		myInput.setAttribute('value', p[k]);
		myForm.appendChild(myInput);
	}
	
	document.body.appendChild(myForm);
	myForm.submit();
	document.body.removeChild(myForm);
}