// JavaScript Document

function onlyNumber(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}


function rTamanho(campo){
	var compA = document.getElementById('menu_conteudo_lateral').offsetHeight; 
	var compB = document.getElementById('iframe').offsetHeight;
	var result = (compA > compB) ? compA : compB;
	document.getElementById(campo).style.height = result+0+'px';
}


function slide(campo){
	var status = document.getElementById(campo).style.display;
	if(status == 'none'){
		Effect.SlideDown(campo);
	}
	else{		
		Effect.SlideUp(campo);
	}
}


function verificaPedidoMinimo(valueA,valueB,host){
	if(valueA>valueB){
		location.href = host+"/?p=inf_pg/pedidoB";
	}
	else{
		alert("ATENÇÃO:\nPedido não possui o valor mínimo de R$ "+valueB+',00');
	}
}


function actionPedido(local,host){
	
	var elem = document.getElementById("voltagem");
	if(elem != null)
	  var voltagem = elem.value;
	else
	  var voltagem = "000";
	  
	location.href = host+"/?p=inf_pg/pedidoA&produto="+local+","+voltagem+"&quantidade="+document.getElementById(local).value+"&act=add";
	
}




function updatePedido(local,host){
	location.href = host+"/?p=inf_pg/pedidoA&produto="+local+"&quantidade="+document.getElementById(local).value+"&act=add#iframe";
}

function deleteItem(itempedido,host){
	location.href = host+"/?p=inf_pg/pedidoA&item="+itempedido+"&act=sub#iframe";
}



function avisa(host){
	var valor = document.getElementById('filialfaturar').value;
	if(valor != ""){
		parent.location.href = host+"/inf_exe/exe_login.php?filialfaturamento="+document.getElementById('filialfaturar').value;
	}
}



function executa(evt){  
	var code = evt.keyCode;
	if(code == 13) srcEnvia();
}

function srcEnvia(){
	
	var va = document.getElementById('campo_procura').value;
	var vb = 1;
	va = va.replace(/ {1}/gi,"+");
	if(va != '' && va.length > 1) location.href = '/src/'+vb+'/0/0/1/'+va+'#iframe';
	
}

function pedidovenda(cartlink,campo){
	
	var dados = cartlink.split("/");
	if(dados.length == 9){
		var qtn = document.getElementById(campo).value;
		location.href = cartlink+qtn;
	}
	else{
		var elem = document.getElementById("voltagem");
		var qtn = document.getElementById(campo).value;
		
		if(elem != null) 
		  var voltagem = elem.value;
		else
	  	var voltagem = "000";
		location.href = cartlink+voltagem+'/'+qtn;
	}
  
}


/* Classe banner */
function banner(params){

	this.img;
	this.posarray;
	this.posmax;
	this.host;
	this.div;

	this.setvars = function(){
    	this.posarray = 0;
	    this.posmax = this.img.length-1;
	};

	this.front = function(){
		var newpos = (this.posarray >= this.posmax) ? 0 : this.posarray+1;
		if(this.posarray != newpos){
			this.posarray = newpos;
			this.atualiza();
		} 
	};
	
	this.back = function(){
		var newpos = (this.posarray <= 0) ? this.posmax : this.posarray-1;
		if(this.posarray != newpos){
			this.posarray = newpos;
			this.atualiza();
		} 
	};

	this.close = function(){
		$(this.div).visualEffect('Opacity', { from: 0, to: 1.0, duration: 0.5});
	};

	this.open = function(){
		$(this.div).visualEffect('Opacity', { from: 1.0, to: 0, duration: 0.5, afterFinish: function() {
			banner.setimage();
			banner.close();
		}});
	};
    
    this.atualiza = function(){
    	banner.open();
	 };

	this.setimage = function(){
		var string = this.img[this.posarray].split(";");
		document.getElementById(this.div).style.background = 'url('+this.host+string[0]+')';
		document.getElementById(this.div).onclick = function(){ location.href = banner.host+string[1]; };
	};

	this.start = function(){
		this.setimage();
		setInterval('banner.front()', 10000);
	};
	
}

