 var floatingMenuId = 'movel';  
 
 var floatingMenu =  
 {  
     targetX: 40,  
     targetY: 10,  
   
     hasInner: typeof(window.innerWidth) == 'number',  
     hasElement: document.documentElement && document.documentElement.clientWidth,  
   
     menu: '' 
 };  
    
 floatingMenu.move = function ()  
 {  
     if (document.layers)  
     {  
         floatingMenu.menu.left = floatingMenu.nextX;  
         floatingMenu.menu.top = floatingMenu.nextY;  
     }  
     else  
     {  
         floatingMenu.menu.style.left = floatingMenu.nextX + '%';  
         floatingMenu.menu.style.top = floatingMenu.nextY + 'px';  
     }  
 }  
   
 floatingMenu.computeShifts = function ()  
 {  
     var de = document.documentElement;  
   
     floatingMenu.shiftX =  
         floatingMenu.hasInner  
         ? pageXOffset  
         : floatingMenu.hasElement  
           ? de.scrollLeft  
           : document.body.scrollLeft;  
     if (floatingMenu.targetX < 0)  
     {  
         if (floatingMenu.hasElement && floatingMenu.hasInner)  
         {  
             // Handle Opera 8 problems  
             floatingMenu.shiftX +=  
                 de.clientWidth > window.innerWidth  
                 ? window.innerWidth  
                 : de.clientWidth  
         }  
         else  
         {  
             floatingMenu.shiftX +=  
                 floatingMenu.hasElement  
                 ? de.clientWidth  
                 : floatingMenu.hasInner  
                   ? window.innerWidth  
                   : document.body.clientWidth;  
         }  
     }  
   
     floatingMenu.shiftY =   
         floatingMenu.hasInner  
         ? pageYOffset  
         : floatingMenu.hasElement  
           ? de.scrollTop  
           : document.body.scrollTop;  
     if (floatingMenu.targetY < 0)  
     {  
         if (floatingMenu.hasElement && floatingMenu.hasInner)  
         {  
             // Handle Opera 8 problems  
             floatingMenu.shiftY +=  
                 de.clientHeight > window.innerHeight  
                 ? window.innerHeight  
                 : de.clientHeight  
         }  
         else  
         {  
             floatingMenu.shiftY +=  
                 floatingMenu.hasElement  
                 ? document.documentElement.clientHeight  
                 : floatingMenu.hasInner  
                   ? window.innerHeight  
                   : document.body.clientHeight;  
         }  
     }  
 }  
   
 floatingMenu.doFloat = function()  
 {  
     var stepX, stepY;  
   
     floatingMenu.computeShifts();  
   
     stepX = (floatingMenu.shiftX +   
         floatingMenu.targetX - floatingMenu.nextX) * .07;  
     if (Math.abs(stepX) < .5)  
     {  
         stepX = floatingMenu.shiftX +  
             floatingMenu.targetX - floatingMenu.nextX;  
     }  
   
     stepY = (floatingMenu.shiftY +   
         floatingMenu.targetY - floatingMenu.nextY) * .07;  
     if (Math.abs(stepY) < .5)  
     {  
         stepY = floatingMenu.shiftY +   
             floatingMenu.targetY - floatingMenu.nextY;  
     }  
   
     if (Math.abs(stepX) > 0 ||  
         Math.abs(stepY) > 0)  
     {  
         floatingMenu.nextX += stepX;  
         floatingMenu.nextY += stepY;  
         floatingMenu.move();  
     }  
   
     setTimeout('floatingMenu.doFloat()', 20);  
 };  
   
 // addEvent designed by Aaron Moore  
 floatingMenu.addEvent = function(element, listener, handler)  
 {  
     if(typeof element[listener] != 'function' ||   
        typeof element[listener + '_num'] == 'undefined')  
     {  
         element[listener + '_num'] = 0;  
         if (typeof element[listener] == 'function')  
         {  
             element[listener + 0] = element[listener];  
             element[listener + '_num']++;  
         }  
         element[listener] = function(e)  
         {  
             var r = true;  
             e = (e) ? e : window.event;  
             for(var i = element[listener + '_num'] -1; i >= 0; i--)  
             {  
                 if(element[listener + i](e) == false)  
                     r = false;  
             }  
             return r;  
         }  
     }  
   
     //if handler is not already stored, assign it  
     for(var i = 0; i < element[listener + '_num']; i++)  
         if(element[listener + i] == handler)  
             return;  
     element[listener + element[listener + '_num']] = handler;  
     element[listener + '_num']++;  
 };  
   
 floatingMenu.init = function()  
 {  
     floatingMenu.initSecondary();  
     floatingMenu.doFloat();  
 };  
   
 // Some browsers init scrollbars only after  
 // full document load.  
 floatingMenu.initSecondary = function()  
 {  
     floatingMenu.computeShifts();  
     floatingMenu.nextX = floatingMenu.shiftX + floatingMenu.targetX;  
     floatingMenu.nextY = floatingMenu.shiftY + floatingMenu.targetY;  
     floatingMenu.move();  
 } 
 
Event.observe(window, 'load', function() {
  var banner =  $(floatingMenuId);
  if(banner != null){
	  floatingMenu.menu = banner;	
	  floatingMenu.init();  
  }
});

 /*
 if (document.layers){  
     floatingMenu.addEvent(window, 'onload', floatingMenu.init);  
 else  
 {  
     floatingMenu.init();  
     floatingMenu.addEvent(window, 'onload', floatingMenu.initSecondary);  
 } 
 */
function bannerPopup( obj, L, T ) { 
	with( obj.style ) {
		display = "block";
		position = "absolute";
		left = L;
		top = T; 
	}
}

function bannerSlideDown(obj){
	with( obj.style ) {
		left = '280px';
		top = '0px'; 
	}

	Effect.SlideDown(obj);
}

function bannerSlideUp(obj){
	Effect.SlideUp(obj);
}

function unpop( obj ) { 
	//Effect.SlideUp(obj);
	obj.style.display = "none"; 
}

function pesquisarCEP(objeto){
	var url = "http://www.x25.com.br/flavio/verificar.php?cep="+objeto.value;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess:function(t, json){
			if(json != null && json != false){
				$('cliente[cliEndereco]').value = json.endereco_logradouro;
				$('cliente[cliCidade]').value = json.cidade_descricao;
				$('cliente[cliEstado]').value = json.uf_sigla;
				$('cliente[cliBairro]').value = json.bairro_descricao;
				$('cliente[cliComplemento]').value = json.endereco_complemento;
			}else{
				$('cliente[cliEndereco]').value = '';
				$('cliente[cliCidade]').value = '';
				$('cliente[cliEstado]').value = '';
				$('cliente[cliBairro]').value = '';
				$('cliente[cliComplemento]').value = '';					
				
				Element.update($('wf_CEP-H'), 'Endereço n&atilde;o encontrado!');
			}
		},
		onFailure:function(t){
			Element.update($('wf_CEP-H'), 'Endereço n&atilde;o encontrado!');
		},
		onLoading:function(t){
			Element.setStyle('out_cep', {'display':'block'});
		},
		onLoaded:function(t){
			Element.setStyle('out_cep', {'display':'none'});
		}
	});
}

function recuperarDados(campo){
	
	if(campo.value != ''){
		var params = 'cliente[cliCPF]='+campo.value;
		
		new Ajax.Request('/cliente/findByCPF' , {
			method: 'post',
			postBody: params,
			onSuccess:function(request, json){
				
				if(json != null){ 
					var resSize = json.length;
					for (var i = 0; i < resSize; i++){
						try{
							$(json[i][0]).value =  json[i][1];
						}catch(e){	}					   	
					}
					Element.update($('cpf_obrigatorio'), '');					
				}else{
					//informa que nao foi encontrado nenhum registro
					
					Element.update($('cpf_obrigatorio'), 'CPF n&atilde;o cadastrado!');
					var frm = document.forms[0]; 
					var inputs = frm.getInputs('text');
					inputs.each(function(campo) {
  							if(campo.name!='cliente[cliCPF]'){
  								campo.value="";
  							}
					});
					
				}
			  	
			},
			onLoaded:function(){
				//apresenta o spin
				Element.setStyle('out', {'display':'none'});
				
			},
		    onLoading:function(){
				//mostra o sping
				Element.setStyle('out', {'display':'block'});
				
			},
			onFailure:function(t){
				//alert(t.responseText);
				
			}
			
		});
	}
}



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_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_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 somenteNumerico(e){
	var nav4 = window.Event ? true : false;
	if (nav4){
		var tecla = e.which
	}else{
		var tecla = e.keyCode
	}	
	if (tecla < 48 || tecla > 57){
		if(tecla == 8 || tecla==0 || tecla == 13)
			return true;
		
		alert('Informe somente dígitos!');	
		return(false);
	}
	return(true);
}
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
        }
}


function mostrar_dialog(idHtml){
	
			var dialog = new YAHOO.ext.BasicDialog(idHtml, {
				modal: true, 
		        autoTabs:false, 
		        autoScroll:false,
		        fixedcenter: true,
		        width:450,
		        height:200,
		        shadow:true,
		        resizable:false,
		        closable:false
		});
		dialog.addKeyListener(27, function(){window.location='/treinamento';}, dialog);
		dialog.addButton('Fechar', function(){dialog.hide;window.location='/treinamento';}, dialog);
		dialog.show();
		dialog.toFront();
}
function formatar(src, mask, e){
	var i = src.value.length;
	var tecla = e.keyCode
	if(tecla==8){
		return;
	}
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
}

function carregarFotos(album){
    //carrega as fotos do yahoo
    var url = "/fotos/"+album;
    new Ajax.Request(url, 
        {
            method: 'get',
    		onSuccess:function(request, json){
    			if(json != ''){
    				var resSize = json.length;
    				for (var i = 0; i < resSize; i++)
    				{
    				    new Insertion.Bottom('thumbs_div', '<li><img src="'+json[i][1]+'" alt="" /></li>');
    				}					
    			}
    		  	
    		},
    		onFailure:function(t){
    			alert(t.responseText);
    		}
    	}	
    );
    
}