function redirPedido(url){
	var id;
	var conf;
	id = prompt("..::: Digite o numero do pedido :::..","");
	if(id == ""){
		do{
			conf = confirm("Pedido nao informado\nQuer informar novamente?")
			if(conf){
				id = prompt("..::: Digite o numero do pedido :::..","");
			}
		}while(conf)
	}
	if(id != null){
		location.href=""+url+"?pedido="+id;
	}				
}
function calcUnidRet(){
	QndtCX = document.getElementById("cx_ret");
	ProdCX = document.getElementById("ip_qt_prod_cx");
	QntdUnd = document.getElementById("und_ret");
	QntdUnd.value = QndtCX.value * ProdCX.value;
}
//######
function MostrarInfo(id, id2, Form){
	var obj = document.getElementById(id);
	var obj2 = document.getElementById(id2);
	var form = document.getElementById(Form);
	if(obj.style.display == "none"){
		obj.style.display = "block";
		obj2.style.display = "none";
		form.pedido.focus();
	}else{
		obj.style.display = "none";
	}
}
//###########
//#####
function Limpar(valor, validos) {
// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal	
	if (tam < tammax && tecla != 8){
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ){
		tam = tam - 1 ;
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
		if ( tam <= dec ){
			campo.value = vr ; 
		}
		if ( (tam > dec) && (tam <= 5) ){			
			campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "" + vr.substr( tam - 14, 3 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - 2, tam ) ;
		}
} 

}
//#####
function Maisc(id){
	document.getElementById(id).value = document.getElementById(id).value.toUpperCase()
}
//######
function AtivaInput(inicio) {
 var input = document.getElementsByTagName('input');
 for(var x = inicio; x < input.length; x++) {
  var _input = input[x];  
  _input.disabled = (_input.disabled) ? 0 : 1;
 }
}
//###########
function ConfP_Contas(){
	var V_Venda = document.getElementById('valor_venda');
	var Boleto = document.getElementById('boleto');
	var Prom = document.getElementById('prom');
	var Cheque = document.getElementById('cheque');
	var Dinh = document.getElementById('dinh');
	//Correcoes
	Boleto.value = (Boleto.value.replace(",",""));
	Prom.value = (Prom.value.replace(",",""));
	Cheque.value = (Cheque.value.replace(",",""));
	V_Venda.value = (V_Venda.value.replace(",",""));
	var Soma = Boleto.value + Prom.value + Cheque.value + Dinh.value;
	var C1 = parseFloat(Boleto.value) + parseFloat(Prom.value) + parseFloat(Cheque.value);
	if(C1 > V_Venda.value){
		alert("O valor total esta maior que o total vendido, verifique os valores");
		alert(
		"Verifique se o valores abaixos:::::\n\nBoleto: R$ "+ Boleto.value +"\n\nPromissorias: R$ "+ Prom.value +"\n\nCheque: R$ "+ Cheque.value +"\n\nDinheiro: R$ "+ Dinh.value +"\n\nClique em OK para editar")
		return false;
	}else{
		alert("Verifique os valores a seguir, se estiver corretos clique em \n(OK), para prosseguir ou \n(CANCELAR) , para voltar e corrigir o valor \n\nAgora Clique em OK para ver os valores");
		//--
		var Conf = confirm(
		"Verifique se o valores abaixos estao corretos::\n\nBoleto: R$ "+ Boleto.value +"\n\nPromissorias: R$ "+ Prom.value +"\n\nCheque: R$ "+ Cheque.value +"\n\nDinheiro: R$ "+ Dinh.value +"\n\nSe todos os valores estiverem corretos, clique em OK.\nSe nao clique em CANCELAR para editar os valores."
		);
		if(Conf == false){
			return false			
		}
		if(Conf){
			alert("Valores corretos, agora voce pode confirmar a prestacao de contas.");
			/*var BtVerf = document.getElementsById('bt_verf');
			var BtConf = document.getElementsById('bt_conf');
			BtVerf.disabled = true;
			BtConf.disabled = false;*/
			document.getElementById("bt_conf").disabled = false; //habilitar
			document.getElementById('bt_verf').disabled = true; // desabilitar
		}
	}
}
//#############
function NoLetra(evento){
 var tecla;

 if(window.event) { // Internet Explorer
  tecla = event.keyCode;
 }
 else { // Firefox
  tecla = evento.which;
 } 
 
      if(tecla >= 48 && tecla <= 57 || tecla == 8 || tecla == 9 || tecla == 46 || tecla == 44){
		return true;
	  }else{
   	  	return false;
	  }
}
function NoDigitar(evento){
	var tecla;
	if(window.event) { // Internet Explorer
		tecla = event.keyCode;
		return false;
	}
	else { // Firefox
		tecla = evento.which;
		return false;
	} 
}
function help(id){
	obj = document.getElementById(id);	
	if(obj.style.display == "block"){
		obj.style.display = "none";
	}else{
		obj.style.display = "block"
	}
}
function conf(){
	var cf = confirm("Deseja realmete remover o produto do pedido? \nSe sim, clique em ( Ok ); \nSe nao, clique em ( Cancelar )");
	if(cf == true){
		return true;
	}else{
		return false;
	}
}
function show(id){
	var box = document.getElementById(id);	
	if(box.style.display == "none"){
		box.style.display = "";		
	}else{
		box.style.display = "none";	
	}
	
}
function show2(id, i){
	var box = document.getElementById(id);
	var img = document.getElementById(i);
	if(box.style.display == "none"){
		box.style.display = "";
		img.innerHTML = '<img src="img/bt_up.png" width="14" height="14" />';
	}else{
		box.style.display = "none";
		img.innerHTML = '<img src="img/bt_down.png" width="14" height="14" />';
	}
	
}