function confirmarLink(Link, Msg) {
  var is_confirmed = confirm(Msg + '\n\nClique OK para confirmar');
  if (is_confirmed) { Link.href += '&is_js_confirmed=1'; }
  return is_confirmed;
}

function abre(Arquivo, Local, WWidth,WHeight){
  window.open(Arquivo, Local,"alwaysRaised=yes,toolbar=0,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=" + WWidth + ",height=" + WHeight)
}

function mOvr(src,clrOver) {
  if (!src.contains(event.fromElement)) {
    src.style.cursor = 'hand';
    src.bgColor = clrOver;
  }
}

function mOut(src,clrIn) {
  if (!src.contains(event.toElement)) {
    src.style.cursor = 'default';
    src.bgColor = clrIn;
  }
}
                                                                   
function mClk(src) {
  if(event.srcElement.tagName=='TD'){
    src.children.tags('A')[0].click();
  }
}

function checar_form(f,msg) {
  qt = document.forms[f].length;
  erro = "";
  i = 0;
  erro2 = 1;
  for ( i = 0; i < qt; i++ ) {
    if (document.forms[f].elements[i].type == "radio"){ // || document.forms[f].elements[i].type == "checkbox") {
      if (i == 0) {
        if (document.forms[f].elements[i].checked == true) erro2 = 0;
        i++;
        if (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
          while (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
            if (document.forms[f].elements[i].checked == true) erro2 = 0;
            i++;
          }
        }
        else {
          if (document.forms[f].elements[i].checked == true) erro2 = 0;
          i++;
          while (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
            if (document.forms[f].elements[i].checked == true) erro2 = 0;
            i++;
          }
        }
      }
      else {
        if (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
          while (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
            if (document.forms[f].elements[i].checked == true) erro2 = 0;
            i++;
          }
        }
        else {
          if (document.forms[f].elements[i].checked == true) erro2 = 0;
          i++;
          while (document.forms[f].elements[i].name == document.forms[f].elements[i - 1].name) {
            if (document.forms[f].elements[i].checked == true) erro2 = 0;
            i++;
          }
        }
      }
      if (erro2 == 1) erro += "1";
      i--;
    }
    else {
      if (document.forms[f].elements[i].value == "") erro += "1";
    }
  }
  if (erro != "") {
    alert("\n" + msg + "\n");
    return false;
  } else return true;
}

function Checa_Ext() {
  var msg = "";
  var extensoesOk = ",.gif,.jpg,.png,";
  if (form_foto.foto.value != "") {
    var extensao1 = "," + form_foto.foto.value.substr( form_foto.foto.value.length - 4 ).toLowerCase() + ",";
    if( extensoesOk.indexOf( extensao1 ) == -1 ) msg = "\nO arquivo não possui uma extensão válida\n\n\nSó é aceito: gif, jpg ou png";
  }
  if (form_foto.foto.value == "") msg = "Não há arquivo para ser enviado!!\n\nPor favor, clique em procurar para selecionar o arquivo da foto";
  if (msg == "") return true; else {
  alert(msg);
  return false;
  }
}

var total_fotos;
total_fotos = 0;
function atualiza_foto(id_atual, valor) {
  if (document.forms['form'].elements['add['+id_atual+']'].checked == true) {
  	total_fotos = total_fotos + 1; 
  	document.forms['form'].elements['qt['+id_atual+']'].disabled = false;
  }
  else {
  	total_fotos = total_fotos - 1;
  	document.forms['form'].elements['qt['+id_atual+']'].disabled = true;
  }
  qt_fotos.innerHTML = total_fotos;
  total_RS.innerHTML = FormataValor(total_fotos * valor, 2);
}

function atualiza_qtfoto(id_atual, valor, qt) {
  total_fotos = 0;
  for ( i = 0; i < qt; i++ ) {
    if (document.forms['form'].elements[i].type == "select-one") {
//    	alert(total_fotos + " | "+ document.forms['form'].elements[i].disabled + " | "+	document.forms['form'].elements[i].value);
    	if (document.forms['form'].elements[i].disabled == false) {
    		total_fotos = total_fotos + (document.forms['form'].elements[i].value * 1);
    	}
    }
    
  }
  qt_fotos.innerHTML = total_fotos;
  total_RS.innerHTML = FormataValor(total_fotos * valor, 2);
  if (total_fotos > 0) document.forms['form'].elements['enviar'].disabled = false;
  else                 document.forms['form'].elements['enviar'].disabled = true;
}

function FormataValor(num, casas ) {
  if (!casas || casas == "") casas = 2;
  if (casas == 0) tcasas = 1;
  if (casas == 1) tcasas = 10;
  if (casas == 2) tcasas = 100;
  if (casas == 3) tcasas = 1000;
  if (casas == 4) tcasas = 10000;
//  num = num.toString().replace('.', '');
  num = num.toString().replace(',', '.');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*tcasas+0.50000000001);
  cents = num%tcasas;
  num = Math.floor(num/tcasas).toString();
  if (cents == 0) {
  if (casas == 2) cents = "00";
  if (casas == 3) cents = "000";
  if (casas == 4) cents = "0000";
  } else {
  if (casas == 2 && cents < 10) cents = "0" + cents;
  if (casas == 3) {
  if (cents < 10) {
    cents = "00" + cents;
    } else if (cents > 10 && cents < 100) {
      cents = "0" + cents;
    }
  }
  if (casas == 4) {
  if (cents < 10) {
  cents = "000" + cents;
  } else if (cents > 10 && cents < 100) {
  cents = "00" + cents;
  } else if (cents > 100 && cents < 1000) {
  cents = "0" + cents;
  }
  }
  }
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+'.'+
  num.substring(num.length-(4*i+3));
  num = (((sign)?'':'-') + num + ',' + cents);
  return num;
}