ns = document.layers;
ie = document.all;
ns6 = (document.getElementById && !document.all);

function mostralayer(vcampo,ids){
 lay = vcampo+'id'+ids;
 layr = vcampo+ids;
 H = " <div style='position:absolute;width:350px' id='idPd'>";
 H = H + "<table width='100%' cellpadding='3' cellspacing='1' border='0' bgcolor='#CACACA' class='verd10-preto'>";
 H = H + " <tr bgcolor='#FFFFFF'>";
 H = H + "  <td align='right' onclick=closeid('"+lay+"') style='cursor:pointer;padding-right:5px'><b>X</b></td>";
 H = H + " </tr>";
 H = H + " <tr bgcolor='#FFFFFF'>";
 H = H + "  <td><textarea rows='2' id='veditup' style='width:400px' class='form'>"+document.getElementById(layr).innerHTML+"</textarea></td>";
 H = H + " </tr>";
 H = H + " <tr bgcolor='#FFFFFF'>";
 H = H + "  <td><input type='submit' name='' value='Salvar' onclick=salvar('"+vcampo+"','"+ids+"') class='botao2'></td>";
 H = H + " </tr>";
 H = H + "</table>";
 H = H + "</div>";
 document.getElementById(lay).innerHTML = H;
}

function salvarlayer(vcampo,ids) {
 acao('operindex','','oper=acao&op=alt&vcampo='+vcampo,ids,'veditup','','');
}

function returndate(dts) {
 var tmg = new Array(3);
 //alert(dts);
 if (dts.length == 8) {
  diad = dts.substring(6,8);
  if (diad.substr(0,1)=='0') { tmg[0] = eval(diad.substr(1,1)); } else { tmg[0] = eval(diad); }
  mesd = dts.substring(4,6);
  if (mesd.substr(0,1)=='0') { tmg[1] = eval(mesd.substr(1,1)); } else { tmg[1] = eval(mesd); }
  tmg[2] = dts.substring(0,4);
  //alert(dts + ' - ' + tmg[0] + ' - ' + tmg[1] + ' - ' + tmg[2]);
 } else {
  tmg[0] = ''; tmg[1] = ''; tmg[2] = '';
 }
 return tmg;
}

function fmtzero(idv) {
 idv = idv.toString();
 //alert(idv + '['+idv.length+']');
 if (idv.length == 1) { idv = '0'+idv; }
 return idv;
}

function closeid(idlayer) {
 if (idlayer != '') {
  if (document.getElementById(idlayer)) {
   if (idlayer.substr(0,2) == "pX") {
    document.getElementById(idlayer).style.visibility = 'hidden';
   } else {
    document.getElementById(idlayer).innerHTML = "<img src='/t.gif' width='1' height='1'>";
   }
  }
 }
}

function fmtsql(prs,tp){
 for (r=1;r<11;r++) {
  prs = prs.replace("`",'"');
  prs = prs.replace("´",'"');
  prs = prs.replace("'",'"');
  prs = prs.replace('""','"');
  prs = prs.replace("~",'');
  prs = prs.replace("^",'');
  prs = prs.replace("¨",'');
 }
 if ((tp == 'c') || (tp == 'v')) {
  prs = prs.replace("&",'C38;');
 }
 return prs;
}

function mudafonte(idp,ac){
 v = document.getElementById(idp).style.fontSize.split('px');
 var sizes = eval(v[0]);
 if (ac == '-') {
  sizes--;
 } else {
  sizes++;
 }
 //alert(idp + ' : ' + sizes + ':' + ac);
 document.getElementById(idp).style.fontSize= sizes + 'px';
}

function acao(idlayer,idlayret,oper,id,id1,id2,id3,idreturn) {
 var head = document.getElementById(idlayer);
 var eScript = document.createElement('script');
 pr = '';
 if (idlayer != '') { pr = pr + '&idlayer=' + idlayer; }
 if (idlayret != '') { pr = pr + '&idlayret=' + idlayret; }
 if (id != '') { pr = pr + '&id=' + id; }
 if ((id1 != '') && document.getElementById(id1)) { pr = pr + '&' + id1 + '=' + fmtsql(document.getElementById(id1).value,id1.substr(0,1)); }
 if ((id2 != '') && document.getElementById(id2)) { pr = pr + '&' + id2 + '=' + fmtsql(document.getElementById(id2).value,id2.substr(0,1)); }
 if ((id3 != '') && document.getElementById(id3)) { pr = pr + '&' + id3 + '=' + fmtsql(document.getElementById(id3).value,id3.substr(0,1)); }
 if (idreturn != '') { pr = pr + '&idreturn='+idreturn; }
 //alert('Ok - ['+idlayer+'] ['+idlayret+'] ['+oper+'] ['+id+'] ['+id1+']['+id2+']['+id3+']  ['+pr+']');
 if (idreturn == 'raiz') {
  eScript.setAttribute('src','/?'+fmtsql(oper,'')+pr);
 } else {
  eScript.setAttribute('src','?'+fmtsql(oper,'')+pr);
 }
 head.appendChild(eScript);
}
function Checker(fd,fdl,fmax) {
 if (fmax == '') { fmax = 2500; }
 (fd.value.length>fmax) ? fd.value=fd.value.substring(0,fmax) : document.getElementById(fdl).childNodes[0].data=(fmax-fd.value.length);
}
function carregandoic(idt,swidth){
 if (swidth != '') { swidth = 'width:'+swidth+'px'; }
 document.getElementById(idt).innerHTML = "<center><span style='padding:3px;text-align:center;"+swidth+"'><img src='/img/ic-carrega.gif' border='0'></span></center>";
}
var td='';
var inttitle=0;
var start='';
function colocatitle(tt){
 top.document.title=tt;
}
function reloadstop(tt){
 clearInterval(inttitle);
 this.start='';
 top.document.title=tt;
}
function reloadtitle(p,tt){
 clearInterval(inttitle);
 if (p == 3) { this.start = 1; }
 if (p == 1) { colocatitle("Diz: Mensagem"); pr = 2; } else { colocatitle(tt); pr = 1; }
 if (this.start == 1) {
  inttitle = window.setInterval( function() { reloadtitle(pr,tt); }, 1000);
  top.window.focus();
  parent.cafmainFrame.document.getElementById('msg').focus();
 } else {
  colocatitle(tt);
 }
}

function fmtchr(t) { /* UPDATE IN FUNCTION.PHP */
 // retirar quebra
 msg = '';
 if (t != '') {
  for (i=0;i<t.length;i++) {
   if (t[i]) {
    //alert('['+i+']-['+t[i]+']-['+t[i].charCodeAt(0)+']');
    if (t[i].charCodeAt(0) == 10) {
     msg = msg + 'chr-14';
    } else {
     msg = msg + t[i];
    }
   }
  }
 }
 if (msg != '') { t = msg; }
 
 var CHARUP = new Array ("","Ç","À","Á","Â","Ã","Ä","È","É","Ê","Ë","ì","í","î","ï","Ò","Ó","Ô","Õ","Ö","Ù","Ú","Û","Ü");
 var CHARLO = new Array ("","ç","à","á","â","ã","ä","è","é","ê","ë","ì","í","î","ï","ò","ó","ô","õ","ö","ù","ú","û","ü");
 var CHARES = new Array ("","`","´","‘","’","'","°","×","","","","","","","","","","","","","","","","","");

 for (i=1;i<5;i++) {
  //alert('A1['+CHARUP[i]+']['+CHARUP[i].charCodeAt(0)+'] - ['+CHARLO[i]+']['+CHARLO[i].charCodeAt(0)+'] - ['+CHARES[i]+']['+CHARES[i].charCodeAt(0)+']');
 }
 for (i=1;i<10;i++) {
  t = t.replace('\n',"chr-13");
  t = t.replace('\r',"chr-14");
 }
 for (k=1;k<CHARUP.length;k++) {
  if (CHARUP[k]){
   var v0 = CHARUP[k].charCodeAt(0);
   var v1 = CHARUP[k].charCodeAt(1);
   //alert('A['+v0+']-'+v1+']');
   for (i=1;i<20;i++) {
    t = t.replace(CHARUP[k],"chr-"+v0+"");
   }
  }
  if (CHARLO[k]) { 
   var v0 = CHARLO[k].charCodeAt(0);
   var v1 = CHARLO[k].charCodeAt(1);
   //alert('B['+v0+']-'+v1+']');
   for (i=1;i<20;i++) {
    t = t.replace(CHARLO[k],"chr-"+v0+"");
   }
  }
  if (CHARES[k]) {
   var v0 = CHARES[k].charCodeAt(0);
   var v1 = CHARES[k].charCodeAt(1);
   //alert('C['+v0+']-'+v1+']');
   for (i=1;i<20;i++) {
    t = t.replace(CHARES[k],"chr-"+v0+"");
   }
  }
 }
 //alert(t);
 return(t);
}
function mostramsg(id,tits,msgs){
 pr = true;
 if (document.getElementById('pX'+id)) {
  if (document.getElementById('pX'+id).style.visibility == 'visible') {
   document.getElementById('pX'+id).style.visibility = 'hidden';
   pr = false;
  }
 }
 if (pr) {
  //alert('aqui - '+posx + ' - ' + posy);
  H = "<div id='pX"+id+"' style='position:absolute;width:200px;visibility:hidden;overflow:visible;background:#FFFFFF;top:"+(posy+10)+"px;left:"+posx+"px'>";
  if (tits) { H = H + "<div class='trr1'>" + tits + "</div>"; }
  if (msgs) { H = H + "<div class='trr2'>" + msgs + "</div>"; }
  H = H + "</div>";
  document.getElementById('iddebug').innerHTML = H;
  document.getElementById("pX"+id).style.visibility = 'visible';
 }
}
var checkflag = "false";
function check(field) {
 if (checkflag == "false") {
  for (i = 0; i < field.length; i++) {
   field[i].checked = true;}
   checkflag = "true";
   return "x"; 
 } else {
  for (i = 0; i < field.length; i++) { field[i].checked = false;  }
  checkflag = "false";
  return "x"; 
 }
}
function radioid(idp) {
 document.getElementById(idp).checked = true;
}
function checkid(idp) {
 //alert(document.getElementById(idp).checked);
 if (document.getElementById(idp).checked == true) {
  document.getElementById(idp).checked = false;
 } else {
  document.getElementById(idp).checked = true;
 }
}
function selcheck(acao,idsel) {
 for (i=1;i<200;i++) {
  if (document.getElementById(idsel+'-'+i)) {
   if (acao == 1) {
    document.getElementById(idsel+'-'+i).checked = true;
   } else {
    document.getElementById(idsel+'-'+i).checked = false;
   }
  }
 }
}
function janela(url, width, height, scroll, resizable, name) {
 var Win = window.open(url, name,'width=' + width + ',height=' + height +',scrollbars=' + scroll + ',resizable=' + resizable + ',menubar=no,status=no,left=50,top=50');
 Win.focus();
}
function actionhref(lnk,frm){
 if (document.getElementById('idestadosc')) {
  lnk = lnk + document.getElementById('idestadosc').value + '-';
 }
 window.location.href= lnk + frm.value;
}
function textCounter(field, countfield, maxlimit) {
 if (field.value.length > maxlimit)
  field.value = field.value.substring(0, maxlimit);
 else 
  countfield.value = maxlimit - field.value.length;
}
function disableForm(qtd) {
 if (document.getElementById('send1')) { document.getElementById('send1').disabled = true; }
 if (document.getElementById('send2')) { document.getElementById('send2').disabled = true; }
 return true;
}
function moveMouse(e){
 if(ie){
  posx = event.clientX;
  posy = event.clientY;
 } else if (ns){
  posx = e.x;
  posy = e.y;
 } else if (ns6){
  posx = e.clientX;
  posy = e.clientY;
 }
}
if(ns) { document.captureEvents(Event.MOUSEMOVE); }
document.onmousemove = moveMouse;
function validarlogin() {
 pr = '';
 if (document.getElementById('codadm')) {
  codadm = document.getElementById('codadm').value;
  if (codadm == '') {
   alert('Você tem que digitar o código da empresa');
   document.getElementById('codadm').focus();
   return false;
  }
  pr = '1';
 } else { pr = '1'; }
 loginadm = document.getElementById('loginadm').value;
 senhaadm = document.getElementById('senhaadm').value;
 if (pr == '1') {
 } else if (loginadm == '') {
  alert('Você tem que digitar o login');
  document.getElementById('loginadm').focus();
  return false;
 } else if (senhaadm == '') {
  alert('Você tem que digitar a senha');
  document.getElementById('senhaadm').focus();
  return false;
 } else {
  return true;
 }
}
function action_adm(msg,url) { 
 if(confirm('Você tem certeza que deseja '+msg+'?')) {
  if (url != '') { window.location.href=url; }
  return true;
 } else { return false; }
}
function validaNumber(idlayer,idlayerret,op,id,id1,id2,id3) {
 tp1 = document.getElementById(id1).value;
 H = "";
 if (tp1 != "") {
  tp = ""; tpe = false;
  if (id1.substr(0,5) == 'vfone') {
   id1 = 'vfone';
   if ( (tp1.length == 7) || (tp1.length == 8) ) {
    tpe = true;
   }
  } else if (id1.substr(0,8) == 'vcpfcnpj') {
   tp2 = document.getElementById(id2).value;
   id1 = 'vcpfcnpj';
   //alert(id1.substr(0,8) + ' - ' + id + ' - ' + tp1 + ' - ' + tp2);
   if (tp1.length == 11) { 
    tp = "CPF INVÁLIDO";
    if (tp2 == '2') { tpe = verificaCPF(tp1); } else { tp = "TEM QUE SER UM CNPJ"; }
   } else if ((tp1.length == 14) || (tp1.length == 15)) {
    tp = "CNPJ INVÁLIDO";
    if (tp2 == '1') { tpe = verificaCNPJ(tp1); } else { tp = "TEM QUE SER UM CPF"; }
   }
  }
  //alert(ids + ' - '+ tpe)
  if (tpe == true) {
   acao(idlayer,idlayerret,'oper=acao&op='+op+'&idp='+id1+'&tp='+tp1,id,'','','');
  } else {
   if (tp == "") { tp = "NÚMERO INVÁLIDO"; }
   H = "<div class='sa i32' onclick='mostramsg(&#39;"+idlayerret+"&#39;,&#39;Ocorreu um erro?&#39;,&#39;"+tp+"&#39;);' style='float:left'></div>"; // <div style='color:#AA0000;padding-top:2px'><b>&nbsp;"+tp+"</b></div>
  }
 }
 document.getElementById(idlayerret).innerHTML = H;
}
function verificaCPF(cpf){
 var numeros, digitos, soma, i, resultado, digitos_iguais;
 digitos_iguais = 1;
 cpf = cpf.replace(".","");
 cpf = cpf.replace(".","");
 cpf = cpf.replace(".","");
 cpf = cpf.replace(".","");
 cpf = cpf.replace("-","");
 if ((cpf == "00000000000") || (cpf == "11111111111") || (cpf == "22222222222") || 
     (cpf == "33333333333") || (cpf == "44444444444") || (cpf == "55555555555") || 
	 (cpf == "66666666666") || (cpf == "77777777777") || (cpf == "88888888888") || 
	 (cpf == "99999999999")) return false;
 if (cpf.length < 11) return false;
 if (cpf == '01234567890') return false;
 for (i = 0; i < cpf.length - 1; i++)
 if (cpf.charAt(i) != cpf.charAt(i + 1)){
  digitos_iguais = 0;
   break;
 }
 if (!digitos_iguais){
  numeros = cpf.substring(0,9);
  digitos = cpf.substring(9);
  soma = 0;
  for (i = 10; i > 1; i--)
  soma += numeros.charAt(10 - i) * i;
  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
  if (resultado != digitos.charAt(0))
   return false;
  numeros = cpf.substring(0,10);
  soma = 0;
  for (i = 11; i > 1; i--)
   soma += numeros.charAt(11 - i) * i;
  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
  if (resultado != digitos.charAt(1))
   return false;
  return true;
 }else
   return false;
}
function verificaCNPJ(cnpj) {
 var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
 digitos_iguais = 1;
 cnpj = cpnj.replace(".","");
 cnpj = cpnj.replace(".","");
 cnpj = cpnj.replace(".","");
 cnpj = cpnj.replace(".","");
 cnpj = cpnj.replace("-","");
 if (cnpj.length < 14 && cnpj.length < 15)
  return false;
 
 for (i = 0; i < cnpj.length - 1; i++)
  if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
   digitos_iguais = 0;
   break;
  }
  if (!digitos_iguais) {
   tamanho = cnpj.length - 2
   numeros = cnpj.substring(0,tamanho);
   digitos = cnpj.substring(tamanho);
   soma = 0;
  pos = tamanho - 7;
  for (i = tamanho; i >= 1; i--) {
   soma += numeros.charAt(tamanho - i) * pos--;
   if (pos < 2) pos = 9;
  }
  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
  if (resultado != digitos.charAt(0))
   return false;
  tamanho = tamanho + 1;
  numeros = cnpj.substring(0,tamanho);
  soma = 0;
  pos = tamanho - 7;
  for (i = tamanho; i >= 1; i--) {
   soma += numeros.charAt(tamanho - i) * pos--;
   if (pos < 2)
    pos = 9;
  }
  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
  if (resultado != digitos.charAt(1))
   return false;
  return true;
 } else
  return false;
}
function isNumeric(elem){
 var numericExpression = /^[0-9]+$/;
 if(elem.value.match(numericExpression)){
  return true;
 }else{
  elem.focus();
  elem.value = elem.value.substring(0, (elem.value.length -1));
  return false;
 }
}
function isChar(elem){
 var charExpression = /^[a-z]+$/;
 if(elem.value.match(charExpression)){
  return true;
 }else{
  elem.focus();
  elem.value = elem.value.substring(0, (elem.value.length -1));
  return false;
 }
}
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
 var x = Math.round(num * Math.pow(10,dec));
 if (x >= 0) n1=n2='';
 var y = (''+Math.abs(x)).split('');
 var z = y.length - dec; 
 if (z<0) z--; 
 for(var i = z; i < 0; i++) y.unshift('0'); 
 if (z<0) z = 1; 
 y.splice(z, 0, pnt); 
 if(y[0] == pnt) y.unshift('0'); 
 while (z > 3) {
  z-=3; 
  y.splice(z,0,thou);
 }
 var r = curr1+n1+y.join('')+n2+curr2;
 return r;
}
function FormataValor(frm,evento,op) {
 var tecla = evento.keyCode;
 //alert(tecla);
 var validos = "0123456789";
 if (tecla == 9) {
  return true;
 } else if ( (tecla == 8) || (tecla == 46) || ((tecla >= 48) && (tecla <= 57)) || ((tecla >= 96) && (tecla <= 105)) || 
             (((tecla == 110) || (tecla == 188) || (tecla == 190) || (tecla == 194)) && (op.substring(0,1) == 'd')) ) {
  valor = document.getElementById(op).value;
  if (op.substring(0,1) == 'd') {
   if ((tecla == 8) || (tecla == 46)) { // Backspace || Delete
    valor = valor.substring(0, (valor.length -1));
   } else {
    //alert(tecla);
	//valor = valor + 
	//valor = valor.substring(0, (valor.length));
	pr = 0;
    if ((tecla >= 48) && (tecla <= 57)) { vini = 48; vfim = 58; } else { vini = 96; vfim = 106; }
    for (i=vini;i<vfim;i++) {
     if (i == tecla) { valor = valor + pr; }
     pr = pr + 1;
    }
	pos = valor.indexOf(",");
	if (((tecla == 110) || (tecla == 188) || (tecla == 190) || (tecla == 194)) && (pos < 1)) {
     valor = valor + ",";
	}
   }
  } else {
   if ((tecla == 8) || (tecla == 46)) { // Backspace || Delete
    valor = valor.substring(0, (valor.length -1));
   } else { 
    pr = 0;
    if ((tecla >= 48) && (tecla <= 57)) { vini = 48; vfim = 58; } else { vini = 96; vfim = 106; }
    for (i=vini;i<vfim;i++) {
     if (i == tecla) { valor = valor + pr; }
     pr = pr + 1;
    }
   }
   if (valor.length > 4) {
    v = valor.substring(0, 1)
    if (v == '0') {
     valor = valor.substring(1, (valor.length));
    }
   }
   var val = "";
   for (var i=0; i < valor.length; i++) {
    aux = validos.indexOf(valor.substring(i, i+1));
    if (aux>=0) { val = val + aux; }
   }
   tam = val.length;
   if ( (tam > 2) && (tam <= 5) ){
    valor = val.substr( 0, tam - 2 ) + "," + val.substr( tam - 2, tam ) ; 
   } else if ( (tam >= 6) && (tam <= 8) ){
    valor = val.substr( 0, tam - 5 ) + "." + val.substr( tam - 5, 3 ) + "," + val.substr( tam - 2, tam ) ; 
   } else if ( (tam >= 9) && (tam <= 11) ){
    valor = val.substr( 0, tam - 8 ) + "." + val.substr( tam - 8, 3 ) + "." + val.substr( tam - 5, 3 ) + "," + val.substr( tam - 2, tam ) ;
   } else if ( (tam >= 12) && (tam <= 14) ){
    valor = val.substr( 0, tam - 11 ) + "." + val.substr( tam - 11, 3 ) + "." + val.substr( tam - 8, 3 ) + "." + val.substr( tam - 5, 3 ) + "," + val.substr( tam - 2, tam ) ;
   } else if ( (tam >= 15) && (tam <= 17) ){
    valor = val.substr( 0, tam - 14 ) + "." + val.substr( tam - 14, 3 ) + "." + val.substr( tam - 11, 3 ) + "." + val.substr( tam - 8, 3 ) + "." + val.substr( tam - 5, 3 ) + "," + val.substr( tam - 2, tam ) ;
   } else { valor = val; }
  }
  document.getElementById(op).value = valor;
 }
 return false;
}

function verificaEmail(email) {
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}

function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}

function timer(idlayer,h,m,s){
 //alert(idlayer);
 if (h.substr(0,1) == 0) { h = h.substr(1,1); }
 h = eval(h);
 if (m.substr(0,1) == 0) { m = m.substr(1,1); }
 m = eval(m);
 if (s.substr(0,1) == 0) { s = s.substr(1,1); }
 s = eval(s)+1;
 if (s == 60){
  s = 0;
  m++;
 }
 if (m == 60){
  m = 0;
  h++;
 }
 if (h.toString().length == 1) { h = '0'+h; }
 if (m.toString().length == 1) { m = '0'+m; }
 if (s.toString().length == 1) { s = '0'+s; }
 if (document.getElementById(idlayer)) {
  document.getElementById(idlayer).innerHTML = h + ":" + m + ":" + s;
  setTimeout("timer('" + idlayer + "','" + h + "','" + m + "','" + s + "')",1000);
 }
}

function verdata(obj) { 
 if (obj.value != '') {
  if (obj.value.substring(1,2) == "/") {
   dia = (obj.value.substring(0,1));
  } else {
   dia = (obj.value.substring(0,2));
  }
  if (dia.substr(0,1) == 0) { dia = dia.substr(1,1); }
  if (obj.value.substring(3,4) == "/") {
   mes = (obj.value.substring(2,3));
   ano = (obj.value.substring(4,8));
  } else if (obj.value.substring(4,5) == "/") {
   mes = (obj.value.substring(3,4));
   ano = (obj.value.substring(5,9)); 
   alert(ano);
  } else {
   mes = (obj.value.substring(3,5));
   ano = (obj.value.substring(6,10)); 
  }
  if (mes.substr(0,1) == 0) { mes = mes.substr(1,1); }
  pr2 = true;
  if ((dia) && (mes) && (ano)) {
   dia = eval(dia);
   mes = eval(mes);
   ano = eval(ano);
   // verifica o dia valido para cada mes 
   if ((dia < 1) || (((dia < 1 || dia > 30)) && ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))) || (dia > 31)) { 
      pr2 = false; 
   } 
   // verifica se o mes e valido 
   if (mes < 01 || mes > 12 ) { 
      pr2 = false; 
   } 
   // verifica se e ano bissexto 
   if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
      pr2 = false 
   } 
  } else { pr2 = false; }
  if (pr2 == false) {
   alert('Data inválida');
   obj.value = '';
  }
 }
} 

function maskInput(f, m) {
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[Àÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
} 
//Manipulador de Eventos: addEvent e removeEvent cross-browser
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};
removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

function CalendarSel(idlayer,diar,mesr,anor,dias,mess,anos) {
 //alert (idlayer + ' - ' + diar+'/'+mesr+'/'+anor + ' - ' + dias+'/'+mess+'/'+anos);
 if (document.getElementById(diar)) {
  document.getElementById(diar).value = dias; 
  document.getElementById(mesr).value = mess; 
  document.getElementById(anor).value = anos; 
 }
 closeid(idlayer)
// echo "dfafdas";
}

function CalendarAnoSel(idlayer,oper,id,diar,mesr,anor,dias,mess,anos,st,ss) {
 Calendar(idlayer,oper,id,diar,mesr,anor,dias,mess,anos,st,ss);
}

function Calendar(idlayer,oper,id,diar,mesr,anor,dias,mess,anos,st,ss) {
 /* sel - ativar ou desativar o calendário */
 if (document.getElementById(idlayer)) {
  //alert (idlayer + ' - ' + diar+'/'+mesr+'/'+anor + ' - ' + dias+'/'+mess+'/'+anos + ' - ' + st);
  if ((dias=='') || (mess=='') || (anos=='')) {
   if (document.getElementById('dtnow')) {
    dts = document.getElementById('dtnow').value;
	//alert(dts.substr(6,2) + ' - ' + dts.substr(4,2));
	dias = dts.substr(6,2);
	mess = dts.substr(4,2);
	anos = dts.substr(0,4);
    //alert(dts + ' - ' + dias + ' - ' + mess + ' - ' + anos);
   }
  }
  dias = dias + "";
  if (dias.substr(0,1)=='0') { dias = dias.substr(1,1); }
  dias = eval(dias);
  mess = mess + "";
  if (mess.substr(0,1)=='0') { mess = mess.substr(1,1); }
  mess = eval(mess);
  anos = eval(anos);
  var mn=new Array('JAN','FEV','MAR','ABR','MAI','JUN','JUL','AGO','SET','OUT','NOV','DEZ');
  var ULTIDIA = new Array (31,28,31,30,31,30,31,31,30,31,30,31);
  var HOJE = new Date(anos, (mess-1), dias);
  var PRIMDIA = new Date(anos, (mess-1), dias);
  if (anos < 1000) { anos +=1900; }
  if (((anos % 4 == 0) && (anos % 100 != 0)) || (anos % 400 == 0)) {
   ULTIDIA[1] = 29;
  }
  DIAS = ULTIDIA[HOJE.getMonth(anos, (mess-1), dias)]+1;
  // alert (DIAS + '-' + HOJE);
  PRIMDIA.setDate(1);
  INICIO = PRIMDIA.getDay(anos,(mess-1),dias);
  mesLast = mess;
  anoLast = anos;
  mesNext = mess;
  anoNext = anos;
  if (mess == 12) {
   mesLast=mesLast-1;
   mesNext=1;
   anoNext=anoNext+1;
  } else if (mess == 1) {
   mesLast=12;
   anoLast=anoLast-1;
   mesNext=mesNext+1;
  } else {
   mesLast=mesLast-1;
   mesNext=mesNext+1;
  }
  v = "<div id='pCalendar' style='width:220px; position: absolute; z-index: 100;'>";
  v = v + "<table width='100%' class='a12-preto' cellpadding='3' cellspacing='1' bgcolor='#EAEAEA'>";
  v = v + "<tr bgcolor='#FFFFFF' style='text-align:center;padding:0px'>";
  v = v + "<td align='center'><a href='javascript:Calendar(&#39;"+idlayer+"&#39;,&#39;"+oper+"&#39;,&#39;"+id+"&#39;,&#39;"+diar+"&#39;,&#39;"+mesr+"&#39;,&#39;"+anor+"&#39;,1,"+mesLast+","+anoLast+","+st+")'>"+(ss!='undefined'?'<b><</b>':"<div class='sa i25'></div>")+"</a></td>";
  v = v + "<td colspan='4' align='center'><select id='dssel' onchange=CalendarAnoSel('"+idlayer+"','"+oper+"','"+id+"','"+diar+"','"+mesr+"','"+anor+"','"+dias+"',this.value,'"+anos+"','"+st+"','"+ss+"') class='frm'>";
  for (i=1;i<13;i++) {
   v = v + "<option value='"+i+"' "+(i==mess?"selected":"")+">"+mn[parseInt(i-1)]+"</option>";
  }
  v = v + "</select> / <select id='anosel' onchange=CalendarAnoSel('"+idlayer+"','"+oper+"','"+id+"','"+diar+"','"+mesr+"','"+anor+"','"+dias+"','"+mess+"',this.value,'"+st+"','"+ss+"') class='frm'>";
  for (i=anos+10;i>anos;i--) {
   v = v + "<option value="+i+">"+i+"</option>";
  }
  for (i=anos;i>=2000;i--) {
   v = v + "<option value="+i+" "+(i==anos?"selected":"")+">"+i+"</option>";
  }
  v = v + "</select></td>";
  v = v + "<td align='center'><a href='javascript:Calendar(&#39;"+idlayer+"&#39;,&#39;"+oper+"&#39;,&#39;"+id+"&#39;,&#39;"+diar+"&#39;,&#39;"+mesr+"&#39;,&#39;"+anor+"&#39;,1,"+mesNext+","+anoNext+","+st+")'>"+(ss!='undefined'?'<b>></b>':"<div class='sa i24'></div>")+"</a></td>";
  v = v + "<td onclick=closeid('"+idlayer+"') title='Fechar' style='cursor:pointer;color:#AA0000;font-size:13px' align='center'>"+(ss!='undefined'?"<b>X</b>":"<div class='sa i62'></div>")+"</td></tr>";
  v = v + "<tr bgcolor='"+(ss!='undefined'?'#BABABA':'#3300cc')+"' style='color:#FFFFFF;text-align:center;font-weight:bold'><td>D</td><td>S</td><td>T</td><td>Q</td><td>Q</td><td>S</td><td>S</td></tr>";
  v = v + "<tr bgcolor='"+(ss!='undefined'?'#FFFFFF':'#A7BFE9')+"'>";
  COLUNA = 0;
  for (i=0;i<INICIO;i++) {
   v = v + ('<td>&nbsp;</td>');
   COLUNA++;
  }
  for (i=1;i<DIAS;i++) {
   v = v + ("<td style='cursor:pointer' class='tr4' onmouseover='this.className=&#39;tr2&#39;' onmouseout='this.className=&#39;tr4&#39;' align='center' ");
   if (st == 1) {
    v = v + ("onclick='javascript:acao(&#39;"+idlayer+"&#39;,&#39;&#39;,&#39;oper=acaofile&op="+oper+"&#39;,&#39;"+id+"-"+i+"-"+mess+"-"+anos+"-"+st+"&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;)'>");
   } else {
    if (i < 10) { diapr = '0'+i; } else { diapr = i; }
	if (mess < 10) { mespr = '0'+mess; } else { mespr = mess; }
    v = v + ("onclick='javascript:CalendarSel(&#39;"+idlayer+"&#39;,&#39;"+diar+"&#39;,&#39;"+mesr+"&#39;,&#39;"+anor+"&#39;,&#39;"+diapr+"&#39;,&#39;"+mespr+"&#39;,&#39;"+anos+"&#39;);'");
   }
   if (COLUNA == 0 && i == dias) {
     v = v + (dias.toString().fontcolor('blue').bold());
   } else {
    if (COLUNA == 0) {
     v = v + (i.toString().bold());
    } else {
     if (i == dias) {
      v = v + (i.toString().fontcolor('blue').bold());
     } else {
      v = v + (i.toString().fontcolor('black'));
     }
    }
   }
   v = v + "</td>";
   COLUNA++;
   if (COLUNA == 7) {
    v = v + "</tr><tr bgcolor='"+(ss!='undefined'?'#FFFFFF':'#A7BFE9')+"'>";
    COLUNA = 0;
   }
  }
  for (i=COLUNA;i<7;i++) { v = v + ('<td>&nbsp;</td>'); }
  v = v + "</tr></table></div>";
  document.getElementById(idlayer).innerHTML = v;
 }
}

function enviafrm(idt,idp,sstipo,sspessoa,idfrm){
 pr = '';
 vnomes = document.getElementById("vnomefantasia").value;
 if ((vnomes == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o nome'); document.getElementById("vnomefantasia").focus(); }
 if ((vnomes != "") && (pr == "")) {
  v = vnomes.split(" ");
  //alert(v.length);
  if (v.length == 1) {
   pr = "1";
   alert('Você tem que digitar o nome completo'); document.getElementById("vnomefantasia").focus();
  }
 }
 //alert(document.getElementById("vcpfcnpj").value.length);
 if (document.getElementById("dtnasc")) {
  if ((verifica_data(document.getElementById("dtnasc"))==false) && (pr == "")) { pr = "1"; alert("Data nascimento inválida"); document.getElementById("dtnasc").focus(); }
 } else if (document.getElementById("dianasc")) {
  if (document.getElementById('dianasc').value == '') {
   alert('Você tem que preencher o dia da data de nascimento');
   document.getElementById('dianasc').focus();
   pr = "1";
  } else if ( (document.getElementById('dianasc').value < 1) || (document.getElementById('dianasc').value > 32) ) {
   alert('O dia da data de nascimento é inválido');
   document.getElementById('dianasc').focus();
   pr = "1";
  } else if (document.getElementById('mesnasc').value == '') {
   alert('Você tem que preencher o mês da data de nascimento');
   document.getElementById('mesnasc').focus();
   pr = "1";
  } else if ( (document.getElementById('mesnasc').value < 1) || (document.getElementById('mesnasc').value > 12) ) {
   alert('O mês da data de nascimento é inválido');
   document.getElementById('mesnasc').focus();
   pr = "1";
  } else if (document.getElementById('anonasc').value == '') {
   alert('Você tem que preencher o ano da data de nascimento');
   document.getElementById('anonasc').focus();
   pr = "1";
  }
 }
 if (sspessoa == '') { sspessoa = 'CPF'; }
 if ((document.getElementById("vcpfcnpj").value == "") && (pr == "")) { 
  pr = "1"; 
  alert('Você tem que digitar o '+sspessoa); 
  document.getElementById("vcpfcnpj").focus();
 } else if ((sspessoa == 'CPF') && (pr == "")) {
  if (document.getElementById("vcpfcnpj").value.length != 11) { pr = "1"; alert('CPF é inválido'); } 
  else if (verificaCPF(document.getElementById("vcpfcnpj").value) == false)  { pr = "1"; alert('CPF é inválido'); document.getElementById("vcpfcnpj").focus(); }
 } else if (pr == "") {
  tam = document.getElementById("vcpfcnpj").value.length;
  if ((tam >= 12) && (tam <= 15)) {
   // 012345678901234
  } else if (pr == "") {
   pr = "1"; alert('CNPJ Inválido'); document.getElementById("vcpfcnpj").focus();
  }
 } 
 if (document.getElementById('vsenha')) {
  if ((document.getElementById('vsenha').value != "") && (pr == '')) {
   if (((document.getElementById("vemail").value.indexOf("@") == -1) || (document.getElementById("vemail").value.indexOf(".") == -1)) && (pr == "")) { pr = "1"; alert("E-mail inválido!"); document.getElementById("vemail").focus(); }
  }
  if ((idt == '') && (pr == '')) {
   if (document.getElementById('vsenha').value == "") {
    pr = "1";
    alert ("Você tem que preencher a senha");
    document.getElementById('vsenha').focus();
   }
  }
  if ((document.getElementById('vsenha').value != document.getElementById('vsenhacon').value) && (pr == '')) {
   pr = "1";
   alert ("Você tem que preencher a senha igual a confirmação dela");
   document.getElementById('vsenha').focus();
  }
 }
 if ((document.getElementById("vdddfone").value == "") && (pr == "")) { pr = "1";  alert('Você tem que digitar o ddd do telefone'); document.getElementById("vdddfone").focus(); }
 vfones = document.getElementById("vfone").value;
 if ((vfones == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o telefone'); document.getElementById("vfone").focus(); }
 else if ((vfones.length != 8) && (pr == "")) { pr = "1"; alert('O Telefone é inválido'); document.getElementById("vfone").focus(); }
 if (document.getElementById("idcidade")) {
  if ((document.getElementById("idcidade").value == '') && (pr == "")) { pr = "1"; alert('Você tem que selecionar a cidade'); document.getElementById("idcidade").focus(); } 
 }
 if (document.getElementById("idindica")) {
  if ((document.getElementById("idindica").value == "") && (pr == "")) { pr = "1"; alert('Como ficou sabendo do site?'); document.getElementById("idindica").focus(); }
 }
 if ((document.getElementById("vendereco").value == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o endereço'); document.getElementById("vendereco").focus(); }
 if ((document.getElementById("vnumero").value == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o número'); document.getElementById("vnumero").focus(); }
 if ((document.getElementById("vbairro").value == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o bairro'); document.getElementById("vbairro").focus(); }
 vceps = document.getElementById("vcep").value;
 if ((vceps == "") && (pr == "")) { pr = "1"; alert('Você tem que digitar o CEP'); document.getElementById("vcep").focus(); }
 else if ((vceps.length != 8) && (pr == "")) { pr = "1"; alert('O CEP é inválido'); document.getElementById("vcep").focus(); }
 codval = '';
 if (document.getElementById("codval") && (pr == "")) {
  codval = document.getElementById("codval").value;
  if (codval == "") { pr = "1"; alert('Você tem que digitar o código de validação'); document.getElementById("codval").focus(); }
 }
 if (pr == "") {
  prn = '';
  if (document.getElementById('sconfirm')) {
   if (document.getElementById('sconfirm').checked == true) {
    prn = '1';
   } else {
    alert('Você tem que confirmar o contrato de adesão');
	document.getElementById('sconfirm').focus();
   }
  } else if (confirm("Você confirma o envio dos seus dados?")) {
   prn = '1';
  }
  if (prn == '1') {
   acao('operindex','','oper=acao&op=captchasend&idfrm='+idfrm+'&codval='+codval+'&id='+idp+'&idcidade='+document.getElementById("idcidade").value,'','','','');
  }
 }
 return false;
}

function verifica_data(obj) { 
 dia = (obj.value.substring(0,2)); 
 mes = (obj.value.substring(3,5)); 
 ano = (obj.value.substring(6,10)); 
 pr2 = true; 
 if ((dia) && (mes) && (ano)) {
  dia = eval(dia);
  mes = eval(mes);
  ano = eval(ano);
  // verifica o dia valido para cada mes 
  if ((dia < 1) || (((dia < 1 || dia > 30)) && ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))) || (dia > 31)) { 
      pr2 = false; 
  } 
  // verifica se o mes e valido 
  if (mes < 01 || mes > 12 ) { 
      pr2 = false; 
  } 
  // verifica se e ano bissexto 
  if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
      pr2 = false 
  } 
 } else { pr2 = false; }
 return pr2;
} 

function copydata(){
 if (document.getElementById('idestadocob').value == document.getElementById('idestado').value) {
  document.getElementById('idcidadecob').value = document.getElementById('idcidade').value;
 } else {
  document.getElementById('idcidadecob').value = null;
 }
 document.getElementById('venderecocob').value = document.getElementById('vendereco').value;
 document.getElementById('vnumerocob').value = document.getElementById('vnumero').value;
 document.getElementById('vcomplementocob').value = document.getElementById('vcomplemento').value;
 document.getElementById('vbairrocob').value = document.getElementById('vbairro').value;
 document.getElementById('vcepcob').value = document.getElementById('vcep').value;
}
var td='';
var inttitle=0;
var start='';
function colocatitle(tt){
 top.document.title=tt;
}
function reloadstop(tt){
 clearInterval(inttitle);
 this.start='';
 top.document.title=tt;
}
function reloadtitle(p,tt){
 clearInterval(inttitle);
 if (p == 3) { this.start = 1; }
 if (p == 1) { colocatitle("Diz: Mensagem"); pr = 2; } else { colocatitle(tt); pr = 1; }
 if (this.start == 1) {
  inttitle = window.setInterval( function() { reloadtitle(pr,tt); }, 1000);
  top.window.focus();
  parent.chatmainFrame.document.getElementById('msg').focus();
 } else {
  colocatitle(tt);
 }
}

/* OPTION-SELECT-MULTIPLE */

var swapbox_init = new Array();
var swapbox_left_init = new Array();
var swapbox_right_init = new Array();

function swapbox_load (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;
  var leftalias = form + "_" + leftfield;
  var rightalias = form + "_" + rightfield;

  if (swapbox_init[fullalias] != 1)
  {
    var left = document.getElementById(leftfield);
    var right = document.getElementById(rightfield);

    swapbox_left_init[leftalias] = new Array();

    for (var x = 0; x < left.length; x++)
    {
      swapbox_left_init[leftalias][x] = document.createElement("OPTION");
      swapbox_left_init[leftalias][x].text = left.options[x].text;
      swapbox_left_init[leftalias][x].value = left.options[x].value;
    }

    swapbox_right_init[rightalias] = new Array();

    for (var x = 0; x < right.length; x++)
    {
      swapbox_right_init[rightalias][x] = document.createElement("OPTION");
      swapbox_right_init[rightalias][x].text = right.options[x].text;
      swapbox_right_init[rightalias][x].value = right.options[x].value;
    }
  }

  swapbox_init[fullalias] = 1;
}

function swapbox_reset (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;
  var leftalias = form + "_" + leftfield;
  var rightalias = form + "_" + rightfield;

  if (swapbox_init[fullalias] == 1)
  {
    var left = document.getElementById(leftfield);
    var right = document.getElementById(rightfield);
    var left_length = left.length;
    var right_length = right.length;

    for (var x = 0; x < left_length; x++)
    {
      left.remove(0);
    }

    for (var x = 0; x < right_length; x++)
    {
      right.remove(0);
    }

    for (var x = 0; x < swapbox_left_init[leftalias].length; x++)
    {
      left[left.length] = swapbox_left_init[leftalias][x];
    }

    for (var x = 0; x < swapbox_right_init[rightalias].length; x++)
    {
      right[right.length] = swapbox_right_init[rightalias][x];
    }
  }
}

function swapbox_all_right (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;

  if (swapbox_init[fullalias] != 1)
  {
    swapbox_load (form, leftfield, rightfield);
  }

  var left = document.getElementById(leftfield);
  var right = document.getElementById(rightfield);

  var options = new Array();
  var length = left.length;

  for (var x = 0; x < length; x++)
  {
    options[x] = document.createElement("OPTION");
    options[x].text = left.options[x].text;
    options[x].value = left.options[x].value;
  }

  for (var x = 0; x < length; x++)
  {
    right[right.length] = options[x];
    left.remove(0);
  }
}

function swapbox_all_left (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;

  if (swapbox_init[fullalias] != 1)
  {
    swapbox_load (form, leftfield, rightfield);
  }

  var left = document.getElementById(leftfield);
  var right = document.getElementById(rightfield);

  var options = new Array();
  var length = right.length;

  for (var x = 0; x < length; x++)
  {
    options[x] = document.createElement("OPTION");
    options[x].text = right.options[x].text;
    options[x].value = right.options[x].value;
  }

  for (var x = 0; x < length; x++)
  {
    left[left.length] = options[x];
    right.remove(0);
  }
}

function swapbox_to_right (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;

  if (swapbox_init[fullalias] != 1)
  {
    swapbox_load (form, leftfield, rightfield);
  }

  var left = document.getElementById(leftfield);
  var right = document.getElementById(rightfield);

  var length = left.length;

  for (var x = 0; x < length; x++)
  {
    if (left.options[x] && left.options[x].selected)
    {
      var option = document.createElement("OPTION");

      option.text = left.options[x].text;
      option.value = left.options[x].value;

      right[right.length] = option;
    }
  }

  for (var x = 0; x < length; x++)
  {
    if (left.options[x] && left.options[x].selected)
    {
      left.remove(x); x--;
    }
  }
}

function swapbox_to_left (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;

  if (swapbox_init[fullalias] != 1)
  {
    swapbox_load (form, leftfield, rightfield);
  }

  var left = document.getElementById(leftfield);
  var right = document.getElementById(rightfield);

  var length = right.length;

  for (var x = 0; x < length; x++)
  {
    if (right.options[x] && right.options[x].selected)
    {
      var option = document.createElement("OPTION");

      option.text = right.options[x].text;
      option.value = right.options[x].value;

      left[left.length] = option;
    }
  }

  for (var x = 0; x < length; x++)
  {
    if (right.options[x] && right.options[x].selected)
    {
      right.remove(x); x--;
    }
  }
}

function swapbox_submit (form, leftfield, rightfield)
{
  var fullalias = form + "_" + leftfield + "_" + rightfield;
  if (swapbox_init[fullalias] != 1)
  {
    swapbox_load (form, leftfield, rightfield);
  }

  var left = document.getElementById(leftfield);
  var right = document.getElementById(rightfield);

  //var left = eval("document.getElementById(" + leftfield + ")");
  //var right = eval("document.getElementById(" + rightfield + ")");
  for (var x = 0; x < left.length; x++)
  {
    left[x].selected = true;
  }
  for (var x = 0; x < right.length; x++)
  {
    right[x].selected = true;
  }
}
