function abrePopPaciente(){
  var pLargura = 605;
  var pAltura = 350;
  var posX = (window.screen.width - pLargura - 17) / 2;
  var posY = (window.screen.height - pAltura) / 2;
  
  var win = window.open("pop_paciente.htm", "PacientesProximaConsulta", "width=" + pLargura + ",height=" + pAltura + ",top=" + posY + ",left=" + posX + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
  win.focus();
}

UpMessage = function(){
  var msgCt;
  
  function createBox(t, s){
    return ['<div class="msg">', '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>', '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><center><h3>', t, '</h3></center><center>', s, '</center></div></div></div>', '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>', '</div>'].join('');
  }
  return {
    msg: function(title, format){
      if (!msgCt) {
        msgCt = Ext.DomHelper.insertFirst(document.body, {
          id: 'msg-div'
        }, true);
      }
      msgCt.alignTo(document, 't-t');
      var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
      var m = Ext.DomHelper.append(msgCt, {
        html: createBox(title, s)
      }, true);
      m.slideIn('t').pause(1).ghost("t", {
        remove: true
      });
    },
    msg2: function(title, format){
      if (!msgCt) {
        msgCt = Ext.DomHelper.insertFirst(document.body, {
          id: 'msg-div'
        }, true);
      }
      msgCt.alignTo(document, 't-t');
      var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
      var m = Ext.DomHelper.append(msgCt, {
        html: createBox(title, s)
      }, true);
      m.slideIn('t').pause(6).ghost("t", {
        remove: true
      });
    },
    msg3: function(title, format, id , time){
      if (!msgCt) {
        msgCt = Ext.get(id);
      }
//      msgCt.alignTo(document, 't-t');
      var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
      var m = Ext.DomHelper.append(msgCt, {
        html: createBox(title, s)
      }, true);
      m.slideIn('t').pause(time).ghost("t", {
        remove: true
      });
    }
  };
}
();

// Example: obj = findObj("image1");
function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if (!theDoc) {
    theDoc = document;
  }
  
  if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p + 1)].document;
    theObj = theObj.substring(0, p);
  }
  
  if (!(foundObj = theDoc[theObj]) && theDoc.all) {
    foundObj = theDoc.all[theObj];
  }
  
  for (i = 0; !foundObj && i < theDoc.forms.length; i++) {
    foundObj = theDoc.forms[i][theObj];
  }
  
  for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) {
    foundObj = findObj(t1eObj, theDoc.layers[i].document);
  }
  
  if (!foundObj && document.getElementById) {
    foundObj = document.getElementById(theObj);
  }
  
  return foundObj;
}


// Exemplo: preloadImages('file.gif', 'http://www.x.com/y.gif');
function preloadImages(){
  if (document.images) {
    if (!document.imageArray) {
      document.imageArray = [];
    }
    var i, j = document.imageArray.length, args = preloadImages.arguments;
    
    for (i = 0; i < args.length; i++) {
      if (args[i].indexOf("#") !== 0) {
        document.imageArray[j] = new Image();
        document.imageArray[j++].src = args[i];
      }
    }
  }
}


// Exemplo: rgSwapImage('id_imagem_1,nome_imagem.gif,id_imagem_2,nome_imagem2.gif');
// Exemplo: rgSwapImage('id_imagem, nome_nova_imagem.gif');
var vArgsRestore = [];
function rgSwapImage(args){
  var vArgs = args.split(",");
  var i = 0;
  var path = 'media/images/';
  
  while (i < vArgs.length) {
    obj = findObj(vArgs[i]);
    
    vArgsRestore[i] = vArgs[i];
    vArgsRestore[i + 1] = obj.src;
    
    obj.src = path + vArgs[i + 1];
    i = i + 2;
  }
}


// Exemplo: rgSwapImageRestore();
function rgSwapImageRestore(){
  var i = 0;
  
  while (i < vArgsRestore.length) {
    obj = findObj(vArgsRestore[i]);
    obj.src = vArgsRestore[i + 1];
    i = i + 2;
  }
}

function telefoneMask(f, q){
  if (q) {
    f.value = q.value;
  }
  f.value = f.value.replace(/[^0-9]/g, "");
  
  tel = '';
  var val = f.value.split('');
  var max = val.length;
  if(max > 10) {
    max = 10;
  }
  for (var i = 0; i < max; i++) {
    if (i === 0) {
      val[i] = '(' + val[i];
    }
    if (i == 2) {
      val[i] = ') ' + val[i];
    }
    if (i == 6) {
      val[i] = ' - ' + val[i];
    }
    tel = tel + val[i];
  }
  f.value = tel;
  if (q) {
    q.value = tel;
  }
}

function NascimentoMask(f, q){
  if (q) {
    f.value = q.value;
  }
  f.value = f.value.replace(/[^0-9]/g, "");
  
  nasc = '';
  var val = f.value.split('');
  for (var i = 0; i < val.length; i++) {
    if (i == 2) {
      val[i] = '/' + val[i];
    }
    if (i == 4) {
      val[i] = '/' + val[i];
    }
    nasc = nasc + val[i];
  }
  f.value = nasc;
  if (q) {
    q.value = nasc;
  }
}

function changePerfilScript(valor, beforeUser){
  window.beforeUser = beforeUser;
  var prefilsV = valor.split("");
  var perfil = [];
  var nome = "";
  for (var i = 0; i < prefilsV.length; i++) {
    if (prefilsV[i] == 2) {
      if (i === 0) {
        nome = "Secretária";
      }
      else 
        if (i == 1) {
          nome = "Profissional da Saúde";
        }
        else 
          if (i == 2) {
            nome = "Paciente";
          }
      perfil[perfil.length] = [i, nome];
    }
  }
  
  new Ext.Window({
    autoCreate: true,
    title: "Selecione a categoria...",
    resizable: false,
    frame: true,
    minimizable: false,
    maximizable: false,
    stateful: false,
    modal: true,
    shim: true,
    buttonAlign: "center",
    width: 400,
    height: 150,
    minHeight: 80,
    plain: false,
    footer: true,
    closable: true,
    scope: this,
    animCollapse: true,
    animateTarget: 'btLogon',
    items: [{
      xtype: 'panel',
      baseCls: '',
      height: 40,
      items: [{
        xtype: 'box',
        autoEl: {
          html: '<table width="100%"><tbody class="formCadastrese"><tr valign="middle"><td align="center">Selecione a categoria desejada para esta sessão:</td></tr></tbody></table>'
        },
        baseCls: ''
      }]
    }, {
      xtype: 'form',
      id: 'chooseLoginForm',
      baseCls: '',
      layout: 'column',
      frame: false,
      items: [{
        xtype: 'panel',
        baseCls: '',
        items: [{
          xtype: 'box',
          fieldClass: 'formCadastrese',
          autoEl: {
            html: '<table width="100%"><tbody class="formCadastrese"><tr valign="middle"><td align="right">Categoria:</td></tr></tbody></table>'
          },
          width: 150,
          baseCls: ''
        }]
      }, {
        xtype: 'panel',
        baseCls: '',
        items: [{
          xtype: 'combo',
          fieldClass: 'formCadastrese',
          width: 150,
          mode: 'local',
          emptyText: "Selecione a categoria...",
          editable: false,
          hiddenName: 'choiceLogin',
          store: new Ext.data.SimpleStore({
            fields: ['value', 'display'],
            data: perfil
          }),
          blankText: 'Campo obrigatório',
          allowBlank: false,
          displayField: 'display',
          valueField: 'value',
          triggerAction: 'all',
          baseCls: ''
        }]
      }]
    }],
    buttons: [{
      text: "Continuar",
      handler: selectedCategoriaLogonGeral,
      scope: this
    }]
  }).show();
}

function selectedCategoriaLogonGeral(e){
  if (e.ownerCt.findByType('combo')[0].isValid()) {
    window.location = "../index/exchangeAccout?b=" + window.beforeUser + "&n=" + e.ownerCt.findByType('combo')[0].value;
  }
}

function tiraAcento(value){
  if (value === null || value === "") {
    return "";
  }
  value = value.replace('á', 'a');
  value = value.replace('é', 'e');
  value = value.replace('í', 'i');
  value = value.replace('ó', 'o');
  value = value.replace('ú', 'u');
  value = value.replace('Á', 'A');
  value = value.replace('É', 'E');
  value = value.replace('Í', 'I');
  value = value.replace('Ó', 'O');
  value = value.replace('Ú', 'U');
  
  value = value.replace('à', 'a');
  value = value.replace('è', 'e');
  value = value.replace('ì', 'i');
  value = value.replace('ò', 'o');
  value = value.replace('ù', 'u');
  value = value.replace('À', 'A');
  value = value.replace('È', 'E');
  value = value.replace('Ì', 'I');
  value = value.replace('Ò', 'O');
  value = value.replace('Ù', 'U');
  
  value = value.replace('â', 'a');
  value = value.replace('ê', 'e');
  value = value.replace('î', 'i');
  value = value.replace('ô', 'o');
  value = value.replace('û', 'u');
  value = value.replace('Â', 'A');
  value = value.replace('Ê', 'E');
  value = value.replace('Î', 'I');
  value = value.replace('Ô', 'O');
  value = value.replace('Û', 'U');
  
  value = value.replace('ã', 'a');
  value = value.replace('õ', 'o');
  value = value.replace('ü', 'u');
  value = value.replace('Ã', 'A');
  value = value.replace('Õ', 'O');
  value = value.replace('Ü', 'U');
  value = value.replace('ç', 'c');
  value = value.replace('Ç', 'C');
  return value;
}

function encode(text) {
  return encodeURIComponent(text);
}

function decode(text) {
  if(text === undefined) {
    return undefined;
  }
  if(text === null) {
    return null;
  }
  return decodeURIComponent(text);
}

function comboLostFocus (field) {
  field.store.clearFilter(false);
}
  
function  comboKeyPressed (field, event) {
   var code = field.getKey();
   var obj = null;
  if((code > 64 && code < 91) || (code > 96 && code < 123)) {
    obj = Ext.getCmp(event.id);
    obj.store.clearFilter(false);
    obj.store.grabbedKey = field.getKey();
    obj.store.filterBy(comboFilterOnFirstKey);
  } else if(code == 8 || code == 32 || code == 27){
    obj = Ext.getCmp(event.id);
    obj.store.clearFilter(false);
  }
}
  
function  comboFilterOnFirstKey (record, recordID) {
  var content = String.fromCharCode(record.store.grabbedKey);
  var searchReg = new RegExp("^" + content,"i");
  if(searchReg.test(record.get("label"))) {
    return true;
  }
  return false;
}

function validaCPF (cpf) {
	if (!(/^\d+$/.test(cpf))) {
		return false;
	}
	if (cpf.length == 11)  { 
		if (cpf == "00000000000" ||   
				cpf == "11111111111" ||   
				cpf == "22222222222" ||   
				cpf == "33333333333" ||   
				cpf == "44444444444" ||   
				cpf == "55555555555" ||   
				cpf == "66666666666" ||   
				cpf == "77777777777" ||   
				cpf == "88888888888" ||   
				cpf == "99999999999") {  
			return false;  
		}  
		var a = [];  
		var b = 0;  
		var c = 11;  
		for (i=0; i<11; i++){  
			a[i] = cpf.charAt(i);  
			if (i < 9){
				 b += (a[i] * --c);
			}  
		}
		if ((x = b % 11) < 2) {
			a[9] = 0;
		} else { 
			a[9] = 11-x;
		}  
		b = 0;  
		c = 11;  
		for (y=0; y<10; y++) {
			b += (a[y] * c--);
		}   
		if ((x = b % 11) < 2) { 
			a[10] = 0; 
		} else { 
			a[10] = 11-x; 
		}
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {  
			return false; 
		}
	} else {  
		return false;
	}
	return true;
}

// Carregamento das pï¿½ginas

window.status = 'Próxima Consulta - Especialista em Agendamentos';

