
function setFieldEmail(){
		$("#xmail").attr('value',App.textoEmail);

		$("#xmail").focus(function(){
			if($(this).attr('value')==App.textoEmail){
				$(this).attr('value','');
			}
		});

		$("#xmail").blur(function(){
				if(tiraespacos($(this).attr('value'))=='') $(this).attr('value',App.textoEmail);
		});
}

function setFieldBF(){

	/*
	 * jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
	 * (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
	 */

	(function() {
		var fieldSelection = {
			getSelection: function() {
				var e = this.jquery ? this[0] : this;
				
				return (
					/* mozilla / dom 3.0 */
					('selectionStart' in e && function() {
						var l = e.selectionEnd - e.selectionStart;
						return {
							start: e.selectionStart,
							end: e.selectionEnd,
							length: l,
							text: e.value.substr(e.selectionStart, l)};
					})
					
					/* exploder */
					|| (document.selection && function() {
						e.focus();
						
						var r = document.selection.createRange();
						if (r == null) {
							return {
								start: 0,
								end: e.value.length,
								length: 0};
						}
						
						var re = e.createTextRange();
						var rc = re.duplicate();
						re.moveToBookmark(r.getBookmark());
						rc.setEndPoint('EndToStart', re);
						
						// IE bug - it counts newline as 2 symbols when getting selection coordinates,
						//  but counts it as one symbol when setting selection
						var rcLen = rc.text.length,
							i,
							rcLenOut = rcLen;
						for (i = 0; i < rcLen; i++) {
							if (rc.text.charCodeAt(i) == 13) rcLenOut--;
						}
						var rLen = r.text.length,
							rLenOut = rLen;
						for (i = 0; i < rLen; i++) {
							if (r.text.charCodeAt(i) == 13) rLenOut--;
						}
						
						return {
							start: rcLenOut,
							end: rcLenOut + rLenOut,
							length: rLenOut,
							text: r.text};
					})
					
					/* browser not supported */
					|| function() {
						return {
							start: 0,
							end: e.value.length,
							length: 0};
					}

				)();

			},
			
			setSelection: function(start, end) {
				var e = document.getElementById($(this).attr('id')); // I don't know why... but $(this) don't want to work today :-/
				if (!e) {
					return $(this);
				} else if (e.setSelectionRange) { /* WebKit */ 
					e.focus(); e.setSelectionRange(start, end);
				} else if (e.createTextRange) { /* IE */
					var range = e.createTextRange();
					range.collapse(true);
					range.moveEnd('character', end);
					range.moveStart('character', start);
					range.select();
				} else if (e.selectionStart) { /* Others */
					e.selectionStart = start;
					e.selectionEnd = end;
				}
				
				return $(this);
			},
			
			replaceSelection: function() {
				var e = this.jquery ? this[0] : this;
				var text = arguments[0] || '';
				
				return (
					/* mozilla / dom 3.0 */
					('selectionStart' in e && function() {
						e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
						return this;
					})
					
					/* exploder */
					|| (document.selection && function() {
						e.focus();
						document.selection.createRange().text = text;
						return this;
					})
					
					/* browser not supported */
					|| function() {
						e.value += text;
						return this;
					}
				)();
			}
		};
		
		jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; });

	})();

		$("#expfacil").attr('value',App.textoBF);

		$("#expfacil").focus(function(){
			if($(this).attr('value')==App.textoBF){
				$(this).attr('value','');
			}
		});

		$("#expfacil").keypress(function(event){
			if($(this).attr('value')==App.textoBF){
				$(this).attr('value','');
			}
		});

		$("#expfacil").keyup(function(event){

			if((event.keyCode === 222))
			{
				if( $("#expfacil").val().substr( $("#expfacil").val().length - 2 ) == 'ão' )
					$("#expfacil").setSelection($("#expfacil").val().length - 2, $("#expfacil").val().length);
			}
			else if((event.keyCode === 188))
			{
				if( $("#expfacil").val().substr( $("#expfacil").val().length - 3 ) == 'ção' )
					$("#expfacil").setSelection($("#expfacil").val().length - 3, $("#expfacil").val().length);
			}

			if($(this).attr('value')==App.textoBF){
				$(this).attr('value','');
			}
		});

		$("#expfacil").blur(function(){
				if(tiraespacos($(this).attr('value'))=='') $(this).attr('value',App.textoBF);
		});

}

function getCookie(name) {
	 var dc = document.cookie;
	 var prefix = name + "=";
	 var begin = dc.indexOf("; " + prefix);
	 if (begin == -1) {
	 begin = dc.indexOf(prefix);
	 if (begin != 0) return null;
	 } else
	 begin += 2;
	 var end = document.cookie.indexOf(";", begin);
	 if (end == -1)
	 end = dc.length;
	 return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, path, domain, secure) {
  var expires = new Date();
  //para expirar daqui a quatro horas
  var futuro = expires.getTime()+(4*60*60*1000);
  expires.setTime(futuro);
  agoraMes = expires.getMonth()+1; agoraMes = (agoraMes>=10)?agoraMes:"0"+agoraMes;
  agoraDia = expires.getDate(); agoraDia = (agoraDia>=10)?agoraDia:"0"+agoraDia;
  agoraHora = expires.getHours(); agoraHora = (agoraHora>=10)?agoraHora:"0"+agoraHora;
  agoraMin = expires.getMinutes(); agoraMin = (agoraMin>=10)?agoraMin:"0"+agoraMin;
  // valor = expires.getFullYear()+""+agoraMes+""+agoraDia+""+agoraHora+""+agoraMin;
  var curCookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires.toGMTString() : "") +
	  ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : ""); 
	  document.cookie = curCookie;
}

function tiraespacos(tmpStr) {
  var atChar;
  if (tmpStr && tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (isSpace(atChar)) 
  {
		tmpStr = tmpStr.substring(1, tmpStr.length);
	atChar = tmpStr.charAt(0);
  }
  if (tmpStr && tmpStr.length > 0) 
		  atChar = tmpStr.charAt(tmpStr.length-1);
  while (isSpace(atChar)) 
  {
	tmpStr = tmpStr.substring(0,(tmpStr.length-1));
	atChar = tmpStr.charAt(tmpStr.length-1);
  }
  return tmpStr;
}

function isSpace(inChar) {
  return (inChar == ' ' || inChar == '\t' || inChar == '\n');
}

function abreHistoricoCliente(u){
	janHist = window.open('/caf/historico.php?u='+u,'janHistorico','scrollbars=1,menubar=0,statusbar=0,directories=0,resize=1,resizable=1');
}
