var params = '';
function change_visibility_status(id,visible)
{
  if(visible /*document.getElementById(id).style.display == 'none'*/)
  {
    document.getElementById(id).style.display = 'inline';
  }
  else
  {
     document.getElementById(id).style.display = 'none';
  }
}


function change_visibility_status2(id)
{
  if(document.getElementById(id).style.display != '' && document.getElementById(id).style.display == 'none')
  {
    document.getElementById(id).style.display = 'inline';
  }
  else
  {
     document.getElementById(id).style.display = 'none';
  }
}

function change_visibility_status_info(id)
{
	change_visibility_status2('info'+id);

  if(document.getElementById('info_link'+id).innerHTML == 'ver ajuda')
  {
    document.getElementById('info_link'+id).innerHTML = 'ocultar ajuda';
  }
  else
  {
     document.getElementById('info_link'+id).innerHTML = 'ver ajuda';
  }
}

function change_visibility_status_erros(id)
{
	change_visibility_status2('display_'+id);

  if(document.getElementById(id).innerHTML == 'ver')
  {
    document.getElementById(id).innerHTML = 'ocultar';
  }
  else
  {
     document.getElementById(id).innerHTML = 'ver';
  }
  return false;
}


var IE = document.all?true:false;

/*
if (!IE)
{
	document.captureEvents(Event.onmousedown)
}
*/

document.onmousedown = mouse_down_event;


function mouse_down_event(e)
{
	getMouseXY(e);
	oculta_ajuda();
}

var mouse_position_X = 0;
var mouse_position_Y = 0;
function getMouseXY(e)
{
	if(!e) e = window.event;
	if (e.pageX) { // grab the x-y pos.s if browser is IE
    	mouse_position_X = e.pageX;
        mouse_position_Y = e.pageY;
	}
	else if (e.clientX)
	{  // grab the x-y pos.s if browser is NS
	   mouse_position_X = e.clientX;
	   mouse_position_Y = e.clientX;
    }
	if (mouse_position_X < 0){mouse_position_X = 0;}
	if (mouse_position_Y < 0){mouse_position_Y = 0;}

	return true;
}


function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x){
        curleft += obj.x;
    }
    return curleft;
}


function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x){
        curtop += obj.x;
    }
    return curtop;
}


function findPositionObj(obj){
    var pos = new Array();
    pos['X'] = findPosX(obj);
    pos['Y'] = findPosY(obj);
    return pos;
}

function info_text_input_blur(obj_id,val_default)
{
    var obj = document.getElementById(obj_id);
    if(obj.value=='')
    {
        obj.value = val_default
    }
}

function info_text_input_focus(obj_id,val_default)
{
    var obj = document.getElementById(obj_id);
    if(obj.value==val_default)
    {
        obj.value = '';
    }
}

function mostra_ajuda(nome, texto)
{
	//var arPos = findPositionObj(document.getElementById(nome));
	var arPos = new Array();
	arPos['X'] = mouse_position_X;
	arPos['Y'] = mouse_position_Y;

	var ajuda_obj = document.getElementById('ajuda_popup');
	if(arPos['X'] > 400) arPos['X'] = 400;
	ajuda_obj.style.left = arPos['X']+"px";
	ajuda_obj.style.top = arPos['Y']+"px";
	ajuda_obj.style.display = "inline";
	ajuda_obj.innerHTML = texto;
}

function oculta_ajuda()
{
	var ajuda_obj = document.getElementById('ajuda_popup');
	if(ajuda_obj)
	{
		ajuda_obj.style.display = "none";
	}
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}