//addEvent( document.getElementById('topo'), 'click', function(e) {	window.location='/sitemedico.php'; }	); 
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;
};

MaskInput = function(f, m){ //v1.0
    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);
};

String.prototype.superTrim = superTrim; //Implementa o método superTrim() no objeto String.
String.prototype.strim = superTrim;
function superTrim(){ return( this.replace( /^\s+|\s+$/gi, "" ).replace( /\s{2,}/gi, " " ) ) }

String.prototype.trim = function() {return this.replace(/^\s*|\s*$/g,'')};

function is_email(trab){
	trab=trab.toLowerCase().toString().superTrim();
	if (
			(trab.indexOf("@" , 2) == -1) || 
			(trab.indexOf("." , 3) == -1) || 
			(trab.indexOf("@.", 1) != -1) || 
			(trab.indexOf(".@", 1) != -1)
		) return false;
	
	var pode="0123456789.@_-abcdefghijklmnopqrstuvwxyz"
	for (i=0;i<=trab.length;i++){
		swork = trab.charAt(i);
		if (pode.indexOf(swork, 0) == -1) return false;
	}
	
	var arroba = trab.indexOf("@");
	var arrobaprimeiro = trab.lastIndexOf(".");
	var space = trab.indexOf(" ");
	
	if (
			(arroba != -1) && 
			(arroba != 0) && 
			(arrobaprimeiro != -1) && 
			(arrobaprimeiro > arroba + 1) && 
			(arrobaprimeiro < trab.length -1) && 
			(space == -1) 
		)	
	{
		return true;
	}else{
		return false;
	}//if
}//is_email

/* função abaixo
String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String
    Returns the string with a substring padded on the left, right or both sides.

    length
        amount of characters that the string must have
    substring
        string that will be concatenated
    type
        specifies the side where the concatenation will happen, where: 0 = left, 1 = right and 2 = both sides


*/
String.prototype.pad = function(l, s, t){ //v1.0
    return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
        + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
        + this + s.substr(0, l - t) : this;
};


function gE(tI) {
       var d;
       return (d = document).getElementById(tI) || d.all[tI] || false;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function abre(campo)
{
  var link = campo.value.split('|');

  if (link[1] == '_blank')
  {
    window.open(link[0]);
  }
  else if (link[0].length > 0)
  {
    top.location = link[0];
  }
}