//chama o popup de imagens
function popupWin(URL,name,features,steal_focus) 
{
	if(!steal_focus)steal_focus = true;
  	var win = window.open(URL,name,features);
  	if(steal_focus)win.focus();
}//popuWin

//janela de confirmação
function confirmSubmit(msg)
{
   var agree = confirm(msg);
   if(agree)return true ;
	else return false ;
}//confirmSubmit

//muda o html de um objeto
function changeObjHTML(id, html)
{
	document.getElementById(id)['innerHTML'] = html;
}//changeObjHTML

//muda o estilo de um objeto
function changeObjStyle(id, atrb, style)
{
	document.getElementById(id).style[atrb] = style;
}//changeObjStyle

//retorna o valor do estilo display
function getDisplay(id)
{
	return getObjStyle(id, 'display')
}//getDisplay

//retorna o estilo de um objeto por id
function getObjStyle(id, atrb)
{	
	return document.getElementById(id).style[atrb];
}//getObjStyle

function changeValue(input_id, value)
{                                    
	document.getElementById(input_id).value = value;
}//changeValue

function changeName(input_id, name)
{                                    
	document.getElementById(input_id).name = name;
}//changeName

function swapValue(source_id, target_id)
{	
	document.getElementById(target_id).value = document.getElementById(source_id).value;
}//swapValue

function addToValue(input_id, value)
{                                    
	document.getElementById(input_id).value += value;	
}//changeValue

function hide(id)
{	
	changeObjStyle(id, 'display', 'none');
}//hide

function un_hide(id)
{
	changeObjStyle(id, 'display', '');
}//un_hide

function changeSRC(id, src)
{
	document.getElementById(id).src = src;
}//changeSRC

function btnOn(id)
{
	src = document.getElementById(id).src;
	if(src.indexOf('_off') > 0)src = src.replace('_off','_on');
	changeSRC(id, src);
}//btnOn

function btnOff(id)
{
	src = document.getElementById(id).src;
	if(src.indexOf('_on') > 0)src = src.replace('_on','_off');	
	changeSRC(id, src);
}//btnOff

function btnRollOver(img)
{
	var src = new String(img.src);
	if(src.indexOf('_on') > 0)
	{
		img.src = src.replace(/_on/g, '_off');
	}//if on
	else
	{
		img.src = src.replace(/_off/g, '_on');
	}//else off
}//btnRollOver

//tira um elemento de um array
function delFromAssoc(arr, element)
{
	var new_arr = new Array();
	for(key in arr)if(key != element)new_arr[key] = arr[key];
	return new_arr;
}//delFromAssoc

//pega só o nome do arquivo de uma URL
function getFileName(URL)
{
    if(URL.indexOf('/' != -1)) 
    {
        var url_arr = URL.split('/');
        return url_arr[url_arr.length - 1];
    }//if /
}//getFileName

function checkPopupBlocker(alert_msg)
{
	var popup = window.open('','p','width=1,height=1,left=0,top=0,scrollbars=no');
	if(popup)
	{
		var blocker = false;
		popup.close();
	}
	else var blocker = true;
	if(alert_msg)alert(alert_msg);
	return blocker;
}//checkPopupBlocker

function targetOpener(link, close)
{
	if(!(window.focus && window.opener))return true;
	window.opener.focus();
	window.opener.location.href = link.href;
	if(close)window.close();
	return false;
}//targetopener

function windowResize(width, height)
{
	window.resizeTo(width, height);
}//windowResize

function windowMaximize()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width, screen.height);	
}//windowMaximize

//define html de um fckeditor
function setFCKHTML(value, ins_name)
{
	var editor = FCKeditorAPI.GetInstance(ins_name);
  	return editor.SetHTML(value);
}//setFCKHTML

function checkBoxWrapper(chkbox_name, target, separator)
{	
	boxes = document.getElementsByName(chkbox_name);	
	var string = '';
	var sep = '';
	for(var i = 0; i < boxes.length; i++)
	{
		if(boxes[i].checked == true)
		{
			string += sep + boxes[i].value;
			sep = separator;
		}//boxes[i].checked
	}//for i
	document.getElementById(target).value = string;
}//checkBoxWrapper

function selectWrapper(sel, target, separator)
{
	var options = sel.options;
	var string = '';
	var sep = '';	
	for(var o = 0; o < options.length; o++)
	{
		if(options[o].selected == true)
		{
			string += sep + options[o].value;
			sep = separator;
		}//if selected
	}//for o
	changeValue(target, string);
}//selectWrapper

function selectReset()
{	
	for(var s = 0; s < arguments.length; s++)
	{
		var select = getElement(arguments[s]);
		for(var o = 0; o < select.options.length; o++)
		{
			select.options[o].selected = false;
		}//for o
	}//for s
}//selectReset

//Copiada da função $ em http://www.dustindiaz.com/top-ten-javascript

function getElement()
{
	var elements = new Array();
	for(var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if(typeof element == 'string')element = document.getElementById(element);
		if(arguments.length == 1)return element;
		elements.push(element);
	}//for i
	return elements;
}//getElement

//Copiada da função de http://www.dustindiaz.com/top-ten-javascript

function toggle(obj) 
{
	var el = document.getElementById(obj);
	if(el.style.display != 'none')el.style.display = 'none';
		else el.style.display = '';	
}//toggle

//retorna verdadeiro se obj for array
function isArray(obj)
{
    return isObject(obj) && obj.constructor == Array;
}//isArray

//retorna verdadeiro se obj for objeto
function isObject(obj)
{
    return (obj && typeof obj == 'object') || isFunction(obj);
}//isObject

function getRadioSelValue(radio_name)
{
	var radios = document.getElementsByName(radio_name);
	var r_len = radios.length;
	for(var r = 0; r < r_len; r++)
	{
		if(radios[r].checked == true)return radios[r].value;
	}//for r
	return false;
}//getRadioSelValue

/// Copiadas de: http://www.bigbold.com/snippets/posts/show/701

// Removes leading whitespaces
function ltrim(value)
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}//ltrim

// Removes ending whitespaces
function rtrim(value)
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}//rtrim

// Removes leading and ending whitespaces
function trim(value)
{
	return ltrim(rtrim(value));	
}//trim

function reloadOpener()
{
	if(!window.opener.closed)
	{
		window.opener.location.reload();
		window.opener.focus();
	}//if !closed
}//reloadOpener
