
var helpwin = null;
var helploc = null;
function deleteRec(url) {
	if (confirm("Tem certeza que deseja apagar?")) {
		document.location = url;
	}
}

function deleteRec2(msg,url) {
	if (confirm(msg))
		document.location = url;
}

function help(loc) {
	if (helpwin && !helpwin.closed) {
			helpwin.close();
			helpwin = '';
      helploc = loc;
			setTimeout("openhelp()",500)
	} else {
  	helploc = loc;
		openhelp();
  }
}

function openhelp() {
helpwin=window.open(helploc,"help",'screenX=100,screenY=100,width=350,height=350,scrollbars=yes');
  if (window.focus) {helpwin.focus()}
}
function print_self(){
  window.focus();
  if (typeof(window.print) != "undefined"){
    window.print();
  } else {
    show_print_alert();
  }
}

function show_print_alert() {
   alert("Please use your browser's print button");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var pic = null;
var t_url;
var t_w;
var t_h;
//window.onunload =  closePic;

function viewImage(url,w,h) {
   openpic(url,w,h);
}

function openpic(url,w,h) {
    if (w == null || w == 0) {
		w = 120;
    }
    if (h == null || h == 0){
	h = 120;
    }

    if (pic){
	pic.close();
	pic = null;
	t_url = url;
	t_w = w;
	t_h = h;
	setTimeout("openit()",500);
	} else {
	do_openpic(url,w,h);
	}
}

function openit() {
	do_openpic(t_url,t_w,t_h);
	t_url = null;
	t_w = null;
	t_h = null;
}

function do_openpic(url,w,h) {
    w +=30;
    h +=30;
    //var features = "scrollbars=auto,toolbar=yes,location=yes,menubar=yes,screenx=150,screeny=150";
    var	features = "dependent=yes,width=" + w + ",height=" + h + ",noresize,scrollbars=auto,toolbar=no,location=no,menubar=no,screenx=150,screeny=150";
//    alert(features);
    pic = window.open(url,"picwin",features);
    //    setTimeout("createContent()",100);

}
function createContent(){
    if (!pic.document){
	setTimeout("createContent()",100);
    } else {
	var url ="aaa";
	var w=100;
	var h=200;
	pic.document.write('<html><head><style>body{margin:0}</style></head><body>');
	pic.document.write('<img border=0 src=\"');
	pic.document.write(url);
	pic.document.write('\" width=');
	pic.document.write(w);
	pic.document.write(' height=');
	pic.document.write(h);
	pic.document.write('></body></html>');
	if (window.focus){pic.focus();}
    }
}

function validarEmail(email){

  var re = new RegExp("^[\\w\.\_\-]+@[\\\w\_\-]\.+[\\w\_\-]$");
  if (email.value.length == 0) {
      alert("É necessário informar um e-mail");
      email.focus();
      return false;
  }
  if (!email.value.match(re)) {
      alert("O formato do e-mail informado não é válido");
      email.focus();
      return false;
  }
  return true;
}

/////
var marcados=0;
function incr(chk)
{
        marcados = (chk) ? marcados + 1 : marcados - 1;
}

function confirma(formul)
{
        if(marcados == 0)
                return;
        if(confirm("Tem certeza que deseja apagar? ("+marcados+") selecionados"))
        {
                formul.confDel.value = 1;
                formul.submit();
        }
        formul.confDel.value = 0;
}
function marcarTodos(field, box)
{
  if(!field.length)
  	field.checked = box.checked;
  for (i = 0; i < field.length; i++){
  	field[i].checked = box.checked;
  }
}
function desmarcarTodos(field)
{
  if(!field.length)
  	field.checked = '';
  for (i = 0; i < field.length; i++){
  	field[i].checked = '';
  }
}
function marcarEbloquearTodos(field, box)
{
  if(field==null){
  	return;
  }
  if(!field.length){
  	field.checked = box.checked;
	if(field.checked)
		field.disabled = true;
	else
		field.disabled = false;
  }
  for (i = 0; i < field.length; i++){
  	field[i].checked = box.checked;
	if(field[i].checked)
		field[i].disabled = true;
	else
		field[i].disabled = false;
  }
}

function bloquearTodos(field, box)
{
  if(field==null){
  	return;
  }
  if(!field.length){
	if(box.checked)
		field.disabled = true;
	else
		field.disabled = false;
  }
  for (i = 0; i < field.length; i++){
	if(box.checked)
		field[i].disabled = true;
	else
		field[i].disabled = false;
  }
}


function marcarTodosCount(el)
{
  var formu = el.form;
  var i=0;

  for(i=0; i< formu.length; i++)
  {
    if(formu[i].type == "checkbox" && formu[i].name != el.name)
    {
      formu[i].checked = el.checked;
      el.checked ? marcados++ : marcados--;
    }
  }
}

function isDefined(variable)
{
	return (!(!( variable||false )))
}

function mostraDiv(id, type){
	if(!isDefined(type)){
		type = 'block';
	}
	$$(id).style.display = type;
}

function escondeDiv(id){
	$$(id).style.display = 'none';
}

function mostraEsconde_div(div,padrao) {
  var e = document.getElementById(div);
  if(padrao || "") {
    if(padrao=='table-row-custom'){
      e.style.display = e.style.display=='none'? '':'none';
    }
    else{
      e.style.display = padrao;
    }
  }
  else {
    e.style.display = e.style.display=='none'? 'block':'none';
  }
}

function mostraEsconde_inline(elemento) {
  var e = document.getElementById(elemento).style;
  e.display = e.display=='none'? 'inline':'none';
}

function mostraEsconde_rows(tableId, rowId, tag){
	var table = document.getElementById(tableId);
	var len = table.rows.length;
	for(var row=0; row<len; row++){
		if(table.rows[row].id == rowId){
			if(table.rows[row].style.display == ''){
				table.rows[row].style.display = 'none';
				tag.innerHTML = "mostrar";
			}
			else{
				table.rows[row].style.display = '';
				tag.innerHTML = "esconder";
			}
		}
	}
}

function mudaAba_div(div,a,classA,classB) {

  document.getElementById("div_conteudo").style.display = "none";
  document.getElementById("div_teste").style.display = "none";
  document.getElementById("div_agendar").style.display = "none";
  document.getElementById("div_grupos").style.display = "none";
  document.getElementById("div_upgrade").style.display = "none";

  document.getElementById("a_conteudo").className = "";
  document.getElementById("a_teste").className = "";
  document.getElementById("a_agendar").className = "";
  document.getElementById("a_grupos").className = "";
  document.getElementById("a_upgrade").className = "";

  var e = document.getElementById(div).style;
  e.display = e.display? "":"block";

  var x = document.getElementById(a);
  x.className = x.className==classB? classA : classB;

  document.getElementById("send_button").style.display = document.getElementById("div_agendar").style.display;
}

function mudaAba_div2(div,a,classA,classB) {

  document.getElementById("div_imp").style.display = "none";
  document.getElementById("div_hist").style.display = "none";

  document.getElementById("a_imp").className = "";
  document.getElementById("a_hist").className = "";

  var e = document.getElementById(div).style;
  e.display = e.display? "":"block";

  var x = document.getElementById(a);
  x.className = x.className==classB? classA : classB;
}

function callAPI(funcao, parametros, pop, titulo, yPos, divId, divLoadingId, callBack){
/*
	funcao: qual funcionalidade da api vai ser utilizada
	parametros: os parametros q serao passados para o api.php via post (param1=val1&param2=val2)
	pop: verdadeiro se o conteúdo é para ser mostrado na popup, falso para colocar em outra div (divId)
	titulo: titulo que deve aparecer no popup
	yPos: posição do topo da popup
	divId: se não for popular a popup, usar esse parametro para indicar qual div contera a resposta
*/
	if(pop){
		if($$('pop-conteudo').style.display == 'none')
			interface.overlay();
		interface.display('pop-conteudo', 'block');
		divId = 'pop-conteudo-main';
		if(titulo)
			$$('pop-conteudo-titulo').innerHTML = titulo;
	}
	if(yPos){
		$$('pop-conteudo').style.top = yPos;
	}
	if(!divLoadingId){
		divLoadingId='div_loading_topo';
	}

	interface.proAjax(
						"api.php",					 				// url
						"funcao="+funcao+"&"+parametros,				// parametros (completos)
						divId,										// id da div de retorno
						"block", 									// parametro css display da div de retorno (block/none/inline, etc)
						"sim",										// permitir retorno innerHTML (sim/nao)
						divLoadingId,										// id do elemento loading
						"nao",										// utilizar alert ao finalizar procedimento (sim/nao)
						"n",											// mensagem para o alert (se sim)
						callBack
					);

}

//function callAPI2(funcao, parametros, pop, titulo, yPos, divId, divLoadingId){
function callAPIClass(par){
/*
	funcao: qual funcionalidade da api vai ser utilizada
	parametros: os parametros q serao passados para o api.php via post (param1=val1&param2=val2)
	pop: verdadeiro se o conteúdo é para ser mostrado na popup, falso para colocar em outra div (divId)
	titulo: titulo que deve aparecer no popup
	yPos: posição do topo da popup
	divId: se não for popular a popup, usar esse parametro para indicar qual div contera a resposta
*/
par = par || {};
classe = par.classe || '';
metodo = par.metodo || '';
parametros = par.parametros || '';
pop = par.pop || '';
titulo = par.titulo || '';
yPos = par.yPos || '';
xPos = par.xPos || '';
divId = par.divId || '';
divLoadingId  = par.divLoadingId || 'div_loading_topo';
callBack = par.callBack || function (){};
display = par.display || "block";
largura = par.largura || '800px';

	if(!xPos){
		xPos = (largura=='600px') ? '50%' : '43%';
	}

	if(!metodo){
		alert('Falta parametro funcao na chamada do callAPI2');
		return;
	}
	if(!classe){
		alert('Falta parametro classe na chamada do callAPI2');
		return;
	}

//funcao, parametros, pop, titulo, yPos, divId, divLoadingId
	if(pop){
		if($$('pop-conteudo').style.display == 'none')
			interface.overlay();
		interface.display('pop-conteudo', 'block');
		divId = 'pop-conteudo-main';
		if(titulo)
			$$('pop-conteudo-titulo').innerHTML = titulo;
	}
	if(yPos){
		$$('pop-conteudo').style.top = yPos;
	}
	if(xPos){
		$$('pop-conteudo').style.left = xPos;
	}
	if(largura) {
		$$('pop-conteudo').style.width = largura;
	}

	interface.proAjax(
						"ajax/classRouter.php",					 				// url
						"metodo="+metodo+"&classe="+classe+"&"+parametros,				// parametros (completos)
						divId,										// id da div de retorno
						display, 									// parametro css display da div de retorno (block/none/inline, etc)
						"sim",										// permitir retorno innerHTML (sim/nao)
						divLoadingId,								// id do elemento loading
						"nao",										// utilizar alert ao finalizar procedimento (sim/nao)
						"n",											// mensagem para o alert (se sim)
						callBack
					);

}

if (typeof window.event != 'undefined')
	document.onkeydown = cancelBackSpaceIE;
else
	document.onkeypress = cancelBackSpaceFF;

function cancelBackSpaceFF(e)
{
	element = e.target;
	tagName = element.nodeName.toUpperCase();
	if (tagName != 'INPUT' && tagName != 'TEXTAREA' && tagName != 'PASSWORD'){
		return (e.keyCode != 8);
	}
	else{
		return !element.readOnly;
	}
}

function cancelBackSpaceIE(){
	element = event.srcElement;
	tagName = element.tagName.toUpperCase();
	if (tagName != 'INPUT' && tagName != 'TEXTAREA' && tagName != 'PASSWORD'){
		return (event.keyCode != 8);
	}
	else{
		return !element.readOnly;
	}
}

function get_template(form){
	nValue=0;
	if(!form.templateids.length){
		nValue = form.templateids.value;
	}
	for(i=0; i<form.templateids.length; i++){
		if(form.templateids[i].checked){
			nValue = form.templateids[i].value;
			break;
		}
	}
	return nValue;
}

function get_message(form){
	nValue=0;
	if(!form.messageids.length){
		nValue = form.messageids.value;
	}
	for(i=0; i<form.messageids.length; i++){
		if(form.messageids[i].checked){
			nValue = form.messageids[i].value;
			break;
		}
	}
	return nValue;
}

function confirmLoadMessage(msgId){
	if(!msgId){
		alert("Para opção é necessário escolher uma mensagem.");
		return false;
	}
	if(confirm("Deseja criar uma nova mensagem a partir da mensagem ID " + msgId + "?")){
		window.location.href = '?page=send_core&create_from_msg_id=' + msgId;
	}
	else{
		return false;
	}
}
function confirmLoadTemplate(tid){
	if(!tid){
		alert("Para opção é necessário escolher um template.");
		return false;
	}
	if(confirm("Deseja criar uma nova mensagem a partir do template ID " + tid + "?")){
		window.location.href = '?page=send_core&templateid=' + tid;
	}
	else{
		return false;
	}
}
function submitBuscaAPI(form,paramsExtras,funcao,titulo){
	parametros = "&busca=1" + paramsExtras;
	nSelected = form.filtro_status.selectedIndex;
	if(nSelected!=0){
		parametros += "&filtro_status=" + form.filtro_status.options[nSelected].value;
	}
	if(form.grupoids){

		if(!form.grupoids.length){
			parametros += '&grupoids[]='+form.grupoids.value;
		}
		else{
			for(i=0; i<form.grupoids.length; i++){
				if(form.grupoids[i].checked)
					parametros += '&grupoids[]='+form.grupoids[i].value;
			}
		}
		if(form.sem_listas.checked){
			parametros += '&sem_listas=1';
		}
	}
	parametros += '&busca_valor=' + form.busca_valor.value;
	parametros += '&filtro_bounce=' + form.filtro_bounce.value;
	//alert(parametros);

	callAPI(funcao, parametros, true, titulo, '200px');
	return false;
}

function enableDisableMessageActions(){
	var nChecked=0;
	var arrStatus = new Array();
	var acaoSelecionada;

	var arrMsgsChecked = jQuery.makeArray($('.messageids:checked'));

	for(i=0;i<arrMsgsChecked.length;i++){
		if(arrMsgsChecked[i].checked){
			nChecked++;
			idMsg =	arrMsgsChecked[i].value;
			var status = $('#message_status_'+idMsg).val();
			arrStatus[arrStatus.length] = status;
		}
	}

	//desabilita todos os botoes por padrao
	DisableAllMessageActions();

	if(nChecked==0){
		return;
	}

	var arrAcoes = new Array();
	//para cada tipo de opção do combo verifica se pode exibir dependendo dos status selecionados
	$('#div_disable_preview').css('z-index','-200');
	$('#div_disable_create').css('z-index','-200');

	if(in_array('draft',arrStatus)||in_array('failed',arrStatus)||in_array('suspended',arrStatus)||in_array('erro_limite',arrStatus)){
		$('#div_disable_edit').css('z-index','-200');
		$('#div_disable_send').css('z-index','-200');
	}
	if(in_array('submitted',arrStatus)||in_array('submitted2',arrStatus)){
		$('#div_disable_cancel').css('z-index','-200');
	}
	if(in_array('draft',arrStatus)||in_array('suspended',arrStatus)){
		$('#div_disable_remove').css('z-index','-200');
		$('#div_disable_cancel').css('z-index','200');
	}
	if(in_array('sent',arrStatus)||in_array('inprocess2',arrStatus)||in_array('inprocess3',arrStatus)){
		$('#div_disable_stats').css('z-index','-200');
		$('#div_disable_cancel').css('z-index','200');
		$('#div_disable_remove').css('z-index','200');
	}

	if(nChecked!=1){
		$('#div_disable_create').css('z-index','200');
		$('#div_disable_send').css('z-index','200');
		$('#div_disable_preview').css('z-index','200');
		$('#div_disable_edit').css('z-index','200');
		$('#div_disable_stats').css('z-index','200');
	}
}

function serialize(_obj)
{
   // Let Gecko browsers do this the easy way
   if (typeof _obj.toSource !== 'undefined' && typeof _obj.callee === 'undefined')
   {
      return _obj.toSource();
   }
   // Other browsers must do it the hard way
   switch (typeof _obj)
   {
      // numbers, booleans, and functions are trivial:
      // just return the object itself since its default .toString()
      // gives us exactly what we want
      case 'number':
      case 'boolean':
      case 'function':
         return _obj;
         break;

      // for JSON format, strings need to be wrapped in quotes
      case 'string':
         return '\'' + _obj + '\'';
         break;

      case 'object':
         var str;
         if (_obj.constructor === Array || typeof _obj.callee !== 'undefined')
         {
            str = '[';
            var i, len = _obj.length;
            for (i = 0; i < len-1; i++) { str += serialize(_obj[i]) + ','; }
            str += serialize(_obj[i]) + ']';
         }
         else
         {
            str = '{';
            var key;
            for (key in _obj) { str += key + ':' + serialize(_obj[key]) + ','; }
            str = str.replace(/\,$/, '') + '}';
         }
         return str;
         break;

      default:
         return 'UNKNOWN';
         break;
   }
}

function DisableAllMessageActions()
{
	$('#div_disable_stats').css('z-index','200');
	$('#div_disable_preview').css('z-index','200');
	$('#div_disable_edit').css('z-index','200');
	$('#div_disable_remove').css('z-index','200');
	$('#div_disable_send').css('z-index','200');
	$('#div_disable_cancel').css('z-index','200');
	$('#div_disable_create').css('z-index','200');
}


function in_array(needle,arr) {
	for(xx=0; xx<arr.length; xx++){
		if(arr[xx]==needle)
			return true;
	}
	return false;
	//return new RegExp('(^|\,)'+needle+'(\,|$)','gi').test(haystack);
}


function abre_sugestoes(){
	window.open("http://sugestao.locaweb.com.br/sugestao/","sugestoes","width=363,height=424,top=30,left=30,resizable=yes,toolbar=0,location=0,directories=0,status=no,menubar=0");
}

function getMsgsCampanha(form){

	strMsgs='';

	if(isDefined(form.messageids.value)){
		if(form.messageids.checked){
			strMsgs += '&messageids[]='+form.messageids.value;
		}
	}
	else{
		for(i=0;i<form.messageids.length;i++){
			if(form.messageids[i].checked){
				strMsgs += '&messageids[]='+form.messageids[i].value;
			}
		}
	}
	return strMsgs;
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
function URLDecode( str ) {

    var histogram = {};
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';

    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
}
function showDivAndHideAllOthers(classToHide, divIdToShow, classToUncheck, radioIdToCheck){
	actualDisplay = $('#'+divIdToShow).css('display');
	$('.'+classToHide).hide();
	$('.session-title').attr('class','session-title clickable');
	$('.'+classToUncheck).attr('checked', '');

	if(actualDisplay=='none'){
		$('#'+divIdToShow).show();
		$('#'+divIdToShow+'_title').attr('class','session-title clickable');
		$('#'+radioIdToCheck).attr('checked', 'checked');
	}
	else{
		$('#'+divIdToShow).hide();
		$('#'+divIdToShow+'_title').attr('class','session-title clickable');
	}
}
function changeMoreOptionsImg(imgId){
	imgId = '#'+imgId;
	if($(imgId).attr('src') == 'images/icone-seta-busca-up-branco.gif'){
		$(imgId).attr('src','images/icone-seta-busca-down.gif');
	}
	else{
		$(imgId).attr('src','images/icone-seta-busca-up-branco.gif');
	}
}
function changeMoreOptionsImg2(imgId){
	imgId = '#'+imgId;
	if($(imgId).attr('src') == 'images/icone-seta-right.gif'){
		$(imgId).attr('src','images/icone-seta-busca-down.gif');
	}
	else{
		$(imgId).attr('src','images/icone-seta-right.gif');
	}
}
function changeMoreOptionsImg3(imgId){
	imgId = '#'+imgId;
	if($(imgId).attr('src') == 'images/icone-seta-busca-down-preta.gif'){
		$(imgId).attr('src','images/icone-seta-busca-up.gif');
	}
	else{
		$(imgId).attr('src','images/icone-seta-busca-down-preta.gif');
	}
}
function showContextMenu(tdId, divId, offsetTop) {
	var left = $('#'+tdId).offset().left;
	var top = $('#'+tdId).offset().top;
	var	widthDiv =	$('#'+tdId + ' span:first').width() + 25;
	showContextMenuPosition(left, top, widthDiv, divId, offsetTop);
}
function showContextMenuPositionLeft(tdId, divId, positionLeft, offsetTop) {
	var left = $('#'+tdId).offset().left - positionLeft;
	var top = $('#'+tdId).offset().top;
	showContextMenuPosition(left, top, 0, divId, offsetTop);
}
function showContextMenuPosition(left, top, widthDiv, divId, offsetTop) {
	$('#'+divId).css('left', left + widthDiv);
	$('#'+divId).css('top', top + offsetTop);
}
function changeImagemAndResetOthers(imgId, imgClass, imgSrc1, imgSrc2){
	actualArc = $('#'+imgId).attr('src')
	$('.'+imgClass).attr('src',imgSrc1);

	imgSrc = (actualArc == imgSrc1 ? imgSrc2 : imgSrc1)
    $('#'+imgId).attr('src',imgSrc);

}
function validateUrl(url){
	if(url == null || url.value == ''){
		alert('Campo URL não pode ser vazio');
		return false;
	}
	var urlregex = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
	if(urlregex.test(url)){
		return(true);
	}
	else{
		alert('É necessário digitar uma URL válida.');
		return(false);
	}

}
function showDivAndHideOthers(divIdToShow, imgIdToChange, offsetLeft){

	//seta valores default
	$('.image-arrow2').attr('src','images/icone-seta-incluir-contatos.gif');
	$('.image-arrow-in_table').attr('src','images/icone-seta-incluir-contatos.gif');
	$('.image-arrow-in_table-enabled').attr('src','images/icone-seta-incluir-contatos-azul.gif');
	$('.modal-extremehard').hide();

	//mostra div e inverte imagem da seta
	if(divIdToShow)	{
		$('#'+divIdToShow).css('left',$('#'+imgIdToChange).offset().left + $('#'+imgIdToChange).width() - $('#'+divIdToShow).width() + offsetLeft);
		$('#'+divIdToShow).css('top',$('#'+imgIdToChange).offset().top + $('#'+imgIdToChange).height());
		$('#'+divIdToShow).show();
		$('#'+imgIdToChange).attr('src','images/icone-seta-incluir-contatos-up.gif');
		$('#modal-overlay').css('opacity',0);
		$('#modal-overlay').css('filter','alpha(opacity=0)');
		$('#modal-overlay').css('width',$(window).width());
		$('#modal-overlay').css('height',$('#geral').height()+40);
		$('#modal-overlay').show();
	}
}

function closePopup(){
	interface.display('pop-conteudo', 'none');
	interface.overlay();
}

function checkOrUncheckId(checkboxId){
	if($('#'+checkboxId).attr('checked')){
		$('#'+checkboxId).attr('checked','');
	}
	else{
		$('#'+checkboxId).attr('checked','checked');
	}
}
function checkOrUncheckClass(checkBoxIdReference, checkboxClass){
	if(!$('#'+checkBoxIdReference).attr('checked')){
		$('.'+checkboxClass).attr('checked','');
	}
	else{
		$('.'+checkboxClass).attr('checked','checked');
	}
}
function checkOrUncheckClassAndDisableIfChecked(checkBoxIdReference, checkboxClass){
	if(!$('#'+checkBoxIdReference).attr('checked')){
		$('.'+checkboxClass).attr('checked','');
		$('.'+checkboxClass).attr('disabled','');
	}
	else{
		$('.'+checkboxClass).attr('checked','checked');
		$('.'+checkboxClass).attr('disabled','disabled');
	}
}

