
window.onscroll = function(){
	var obj = document.getElementById("DIV_LOADING");
	if (obj!=null) {
		obj.style.top = loadingPosition("y",obj);
	}
}

function GravaObsDelivery(_txt){	
	var ajax = startAjax(); // delivery.js
	if (ajax){
		Delivery.loading();		
		ajax.open("GET","../default/obs.aspx?txt=" + _txt + "",true);
		ajax.onreadystatechange = function(){		
			if (ajax.readyState==4){
				var text = ajax.responseText.replace(/\+/g," ");
				if (text!=""){
					document.getElementById("retorno_obs").innerHTML = text;
				}
				setTimeout("Delivery.loadingClear()",1000);
			}
		}
		ajax.send(null);		
	} else return;
}

function formatToCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))num = "0";
	
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10) cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + num + ',' + cents);
}


   
    var browser = new function(){
	        this.name = navigator.appName.toLowerCase();
	        this.version = navigator.appVersion;
	        this.userAgent = navigator.userAgent.toLowerCase();
	        this.opera = this.userAgent.indexOf("opera") > -1;
	        this.ie = !this.opera && this.name == "microsoft internet explorer";
	        this.ns = !this.opera && this.name == "netscape";
        }    
    
    function definitions(_obj,_n,_op){
		switch(_n){
			case 0: 
				_obj.style.position			= "absolute";
				_obj.style.border			= _op[0];
				_obj.style.backgroundColor	= _op[1];
				_obj.style.left				= _op[2]+"px";
				_obj.style.top				= _op[3]+"px";
				_obj.style.width			= _op[4]+"px";
				_obj.style.height			= _op[5]+"px";
				_obj.style.padding			= _op[6]+"px";
				_obj.style.filter			= "alpha(opacity="+_op[7]+")";
				_obj.style.MozOpacity		= ""+_op[7]/100+"";		
			break;
			case 1:
				_obj.style.left = (_op / 2) - (_obj.offsetWidth / 2) + "px";
			break;	
		}
    }
    
	function eraseback(){
		var ifrm = document.getElementById("cepIFrameFundo");
		var dtle = document.getElementById("cepDivTitle");
		var dmsg = document.getElementById("cepDivMsg");
		var ddet = document.getElementById("divDetailsCep");

		if (ifrm) ifrm.parentNode.removeChild(ifrm);
		if (dtle) dtle.parentNode.removeChild(dtle);
		if (dmsg) dmsg.parentNode.removeChild(dmsg);
		if (ddet) ddet.parentNode.removeChild(ddet);		
	}


String.prototype.trim = function(){
	this.replace(/\s+/g," "); 
	this.replace(/^ /,""); 
	this.replace(/ $/,""); 
	return this;	
}	


function checkKey(_o){
	if (!isNaN(_o.value)){
		if (_o.value.length >= 8){
			getClient(_o);
		}
	}
}

function getClientPagamento(_cep,_id){//CEP PAGAMENTO
			if (isNaN(_cep)){
				alert("Cep incorreto, verifique seus cadastro antes de continuar!");
				return false;
			}			
			if (_cep==""){
				return false;
			}
			var ajax = startAjax(); // delivery.js
			if (ajax){
				Delivery.loading();
				ajax.open("GET","../carrinho/getclient.aspx?cep=" + _cep + "&Controls=" + document.getElementById("inc_topo_Variables").value,true);
				ajax.onreadystatechange = function(){	
					if (ajax.readyState==4){					
						var text = ajax.responseText.replace(/\+/g," ");
						if (text!=""){							
							if (text=="00000") {
								alert("Sua sessão foi perdida.\nEntre novamente!");
								location.href = "../index.aspx";
								return false;
							}
							if (text.indexOf("[$]")==-1){
								document.getElementById('cepreturns').innerHTML = text;
							}else {
								text = text.split('[$]');
								document.getElementById('cepreturns').innerHTML = text[0];								
							}	
							document.getElementById('ValEndereco').value = _id;
						}
						setTimeout("Delivery.loadingClear()",1000);
					}
				}
				ajax.send(null);	
			} else return;
}

function getClient(_cep){//CEP CARRINHO
	
			if (isNaN(_cep.value)){
				alert("Cep incorreto");
				_cep.value = "";
				_cep.focus();
				return false;
			}			
			if (_cep.value==""){
				return false;
			}
			var ajax = startAjax(); // delivery.js
			if (ajax){
				Delivery.loading();
				_cep.disabled = true;
				ajax.open("GET","../carrinho/getclient.aspx?cep=" + _cep.value + "&Controls=" + document.getElementById("inc_topo_Variables").value,true);
				ajax.onreadystatechange = function(){		
					if (ajax.readyState==4){
						var text = ajax.responseText.replace(/\+/g," ");
						if (text!=""){							
							if (text=="00000") {
								alert("Sua sessão foi perdida.\nEntre novamente!");
								location.href = "../index.aspx";
								return false;
							}
							if (text.indexOf("[$]")==-1){
								document.getElementById('cepreturns').innerHTML = text;
								document.getElementById('btnFecharCompra').style.display = 'none';
								document.getElementById('DeliveryVlrFrete').innerHTML = "0,00";
								Delivery.atualizaValorTotal(document.getElementById('DeliveryPrecoTotal').innerHTML);
							}else {
								text = text.split('[$]');
								document.getElementById('cepreturns').innerHTML = text[0];
								document.getElementById('DeliveryVlrFrete').innerHTML = text[1];
								document.getElementById('btnFecharCompra').style.display = '';
								Delivery.atualizaValorTotal(document.getElementById('DeliveryPrecoTotal').innerHTML);
							}	
						}
						setTimeout("Delivery.loadingClear()",1000);
					}
				}
				ajax.send(null);
				_cep.disabled = false;
				_cep.select();
				_cep.focus();
				// FUNCAO RECALCULA VALOR TOTAL ----- *** ++// / //
				
			} else return;
}


function openCEP(_n){
	window.open('../cep/cep.aspx?idec='+_n, '', 'width=380, height=300, top=120, left=200, scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no'); 
	return false;
}

function getCepValues(_n,_idec){
	var nmCep = document.getElementById("nmcep"+_n).innerHTML.trim();
	var nmRua = document.getElementById("nmrua"+_n).innerHTML.trim();
	var nmBairro = document.getElementById("nmbairro"+_n).innerHTML.trim();
	var nmCityUf = document.getElementById("nmcidade"+_n).innerHTML.split('/');
	var nmUf	= document.getElementById("nmuf"+_n).innerHTML.replace(" ","");	
	
	var fields	=	[
						window.opener.document.getElementById("cep"),
						window.opener.document.getElementById("endereco"),
						window.opener.document.getElementById("bairro"),
						window.opener.document.getElementById("cidade"),
						window.opener.document.getElementById("estado")						
					];
					
	var vlrs	= [nmCep,nmRua,nmBairro,nmCityUf[0],nmUf];
	
	if (_idec==0){ // cadastro de endereco	
		for (var i = 0; i < fields.length; i++){
			fields[i].value = vlrs[i];
		}
		
		for (var i = 1; i < 4; i++){
			if (vlrs[i] != ""){
				fields[i].readOnly = true 
				fields[i].className = "input_cadastro_disabled";				
			}
			else {
				fields[i].readOnly = false;
				fields[i].className = "input_carrinho";
			}			
		}
		window.opener.document.getElementById("estado_hidden").value = nmUf;
		window.opener.document.getElementById("estado_h").value = nmUf;
		fields[4].disabled = true;
		
		if (!fields[1].readOnly) fields[1].focus();
		else window.opener.document.getElementById("numero").focus(); 		
		
	} else { // carrinho de compras
		window.opener.document.getElementById("cep").value = "";
		window.opener.document.getElementById("cep").value = nmCep;
		window.opener.checkKey(window.opener.document.getElementById("cep"));		
	}	
	window.close();
}
	
function showCepResults(_m){
		var wdt = (browser.ie) ? document.documentElement.offsetWidth:window.innerWidth;
		var hgt = (browser.ie) ? document.documentElement.offsetHeight:window.innerHeight;
		
        // IFRAME
        var iFrameFundo = document.createElement("iFrame");  
        iFrameFundo.id = "cepIFrameFundo";
        definitions(iFrameFundo,0,[0,"#ffffff",0,0,wdt,hgt,0,50]);
        iFrameFundo.style.zIndex = 2;
        document.body.appendChild(iFrameFundo);
        
        // DIV TITLE
        var divTitle = document.createElement("div");
        divTitle.id = "cepDivTitle";
        definitions(divTitle,0,[0,"#a80000",0,15,350,20,3,80]);
        divTitle.style.zIndex = 3;
        document.body.appendChild(divTitle);
        definitions(divTitle,1,wdt);
        divTitle.innerHTML = "<table cellpadding='0' border='0' cellspacing='0' width='326' bgcolor='#efefef'>" + 
								"<tr bgcolor='#a80000' height='20px'>" + 
									"<td class='txt10_branco' style='padding-left:1px'>Logradouro</td>" +
									"<td class='txt10_branco' width='40' style='padding-left:1px'>CEP</td>" + 
								"</tr>"+
							"</table>"; 
							
		// DIV MSG
        var divMsg = document.createElement("div");
        divMsg.id = "cepDivMsg";
        var Hgt = (browser.ie)?160:155;
        definitions(divMsg,0,["1px solid #aaaaaa","#efefef",0,40,350,Hgt,3,80]);
        divMsg.style.zIndex = 4;
        divMsg.style.overflow = "auto";
        document.body.appendChild(divMsg);
        definitions(divMsg,1,wdt);
        divMsg.innerHTML =	"<table cellpadding='0' border='0' cellspacing='0' width='326' bgcolor='#efefef'>" + _m + "</table>";
						
		// DIV DETAILS
		var divDetails = document.createElement("div");
		divDetails.id = "divDetailsCep";
		var Hgt = (browser.ie)?70:60;
		definitions(divDetails,0,["1px solid #aaaaaa","#efefef",0,210,350,Hgt,3,80]);
        divDetails.style.zIndex = 1001;
        document.body.appendChild(divDetails);
        definitions(divDetails,1,wdt);
        divDetails.innerHTML = document.getElementById('cepDetails0').innerHTML;
}



/*	OBJETO	DELIVERY  */
var Delivery = {	
	getCep: function(){
	
	
				document.getElementById('tdwait').align='right';
				document.getElementById("tdwait").innerHTML = "<img src='../imagens/loadingcirc.gif' align='absmiddle' /> Aguarde...";
				var uf	 = document.getElementById("uf").value;
				var city = document.getElementById("cidade").value;
				var tipo = document.getElementById("tipo").value;
				var rua  = document.getElementById("rua").value;
				var idec = document.getElementById("idec").value;
				var ajax = startAjax();				
				if (ajax){
					ajax.open("POST","runtime.aspx",true);
					ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
					ajax.onreadystatechange = function(){
							if (ajax.readyState==4){
								var text = ajax.responseText.replace(/\+/g," ");								
								if (text=="00000") {
									alert("Sua sessão foi perdida.\nEntre novamente!");
									location.href = "../index.aspx";
									return false;
								}							
							
								if (text != "ERRO"){
									showCepResults(text);
									document.getElementById("tdwait").innerHTML = "";
								}else if(text == "CORREIO"){
									document.getElementById('tdwait').align='left';
									document.getElementById("tdwait").innerHTML = "Problemas de comunicação com o sistema dos correios!<br>"+
																					"&#149; Em alguns minutos tente novamente.<br>";
								}else{
									document.getElementById('tdwait').align='left';
									document.getElementById("tdwait").innerHTML = "Endere&ccedil;o n&atilde;o encontrado!<br>"+
																					"&#149; A localidade pode estar incorreta.<br>"+
																					"&#149; O logradouro pode n&atilde;o existir nesta localidade.<br>"+
																					"&#149; N&atilde;o use sinais ou acentos.";
								}
							}
					}					
					ajax.send("uf=" + uf + "&city=" + city + "&tipo=" + tipo + "&rua="+ rua +"&idec="+ idec);
				}
				
				return false;

			},
	browser: new function(){
		this.name = navigator.appName.toLowerCase();
		this.version = navigator.appVersion;
		this.userAgent = navigator.userAgent.toLowerCase();
		this.opera = this.userAgent.indexOf("opera") > -1;
		this.ie = !this.opera && this.name == "microsoft internet explorer";
		this.ns = !this.opera && this.name == "netscape";
	},
	
	removetrCompra:	function(){
						var qtdItens = document.getElementById("DeliveryQtdeItens");
						var trFecharCompra = document.getElementById("trFecharCompra");
						var trObs =  document.getElementById("trObs");
						if(qtdItens)
						{							
							if(trFecharCompra) {
								trFecharCompra.style.display = "none";
							}
							if(trObs){
								 trObs.style.display = "none";
							}
							if(parseInt(qtdItens.innerHTML) > 0)
							{								
								if(trFecharCompra){
									trFecharCompra.style.display = "";
								}								
								if(trObs){
									trObs.style.display = "";
								}
								//if(document.getElementById("DivFechamento"))document.getElementById("DivFechamento").style.display = "";
								//if(document.getElementById("DivFechamentoOff"))document.getElementById("DivFechamentoOff").style.display = "none";
							}
							else
							{
								//if(document.getElementById("DivFechamento"))document.getElementById("DivFechamento").style.display = "none";
								//if(document.getElementById("DivFechamentoOff"))document.getElementById("DivFechamentoOff").style.display = "";
							}							
						}
	}, 

	
	removetr:	function(_obj,_n){
					var colors = ["#ffdd3d","#ffe87a","#fff0ac","#fff7d1","#ffffff"];
					for (var j = 0; j < _obj.cells.length; j++){
						_obj.cells[j].style.backgroundColor = colors[_n];
						_obj.cells[j].style.color = colors[_n];
					}
					if (_n < 4) setTimeout(function(){Delivery.removetr(_obj,_n+1)},50);
					else _obj.parentNode.removeChild(_obj);
				},
				
	loading:	function(){
					var div = document.createElement("div");
					div.id = "DIV_LOADING";
					div.innerHTML = "<div><img src='../imagens/loading_14.gif' width='28' height='28' align='absmiddle'> Carregando...</div>"
					document.body.appendChild(div);
					div.style.left = loadingPosition("x",div)+"px";
					div.style.top = loadingPosition("y",div)+"px";					
				},
				
				
	loadingClear:	function(){
						var div = document.getElementById("DIV_LOADING");
						if (div) div.parentNode.removeChild(div);
					},
									
	calling:	function(_pag){
	
					var ajax = startAjax();
					var appc = document.getElementById("applicationDelivery");
					if (ajax){
						this.loading();
						if (document.getElementById("inc_menu_controlFoto")){
							if (document.getElementById("inc_menu_controlFoto").value == 2){
								_pag = _pag.replace("listaprodutos.aspx","listaprodutossf.aspx");
							}else{
								_pag = _pag.replace("listaprodutossf.aspx","listaprodutos.aspx");
							}  
						}
						_pag = _pag.replace(".aspx","Async.aspx");
						ajax.open("GET",_pag,true);
						ajax.onreadystatechange = function(){					
							if (ajax.readyState==4){							
								if (ajax.status==200){								
									var text = ajax.responseText.replace(/\+/g," ");
									
									if (text=="00000") {
										alert("Sua sessão foi perdida.\nEntre novamente!");
										location.href = "../index.aspx";
										return false;
									}
									
									text = text.split("[@$@]");
									var conteudo = text[0];		
																		
									if(text[2] != null)
										appc.innerHTML = conteudo.replace("Listagem de Produtos",text[2]);
									else
										appc.innerHTML = conteudo;
																										
									Delivery.removetrCompra();
									if (text[1]!=null) document.getElementById("inc_menu_controlFoto").value = text[1];
									setTimeout("Delivery.loadingClear()",1000);
								} else {
									appc.innerHTML = text;
								}
							}
						}
						ajax.send(null);
						return false;
					} else{
						return true;
					}		
				},
	callPage:	function(_pag){
					setHash(_pag);
				},
				
			
	atualizaValorTotal: function(_vlr){
							var vlrtmp = parseFloat(_vlr.replace(".","").replace(",",".")).toString();
							vlrtmp = formatToCurrency(vlrtmp)
							document.getElementById("DeliveryVlrClose").innerHTML = vlrtmp;		
												
						},
				
	runtime: "../carrinho/runtime.aspx",
	runclear: "../carrinho/clear.aspx",
	Question: false,
	Carrinho:{
		reload:	function(_nrseq,_qtd,_null){
						var success = false;
						var ajax = startAjax();
						if (ajax){
							Delivery.loading();
							ajax.abort();							
							ajax.open("POST",Delivery.runtime,true);
							ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
							
							function callback(){			
								if (ajax.readyState==4){									
									if (success = (ajax.status==200)){
										var text = ajax.responseText.replace(/\+/g," ");
										text = text.split("?");
										
										if (text=="00000") {
											alert("Sua sessão foi perdida.\nEntre novamente!");
											location.href = "../index.aspx";
											return false;
										}
									
										for (var i = 0; i < 3; i++){
											if (text[0].length < 4) text[0] = "0" + text[0];
										}																				

										document.getElementById("DeliveryQtdeItens").innerHTML = text[0];
										document.getElementById("DeliveryPrecoTotal").innerHTML = text[1];
										Delivery.removetrCompra();						
										if (_null==1)
										{
											var tri = document.getElementById("tri"+_nrseq); // get TRI
											var trj = document.getElementById("trj"+_nrseq); // get TRJ
											document.getElementById("DeliveryTotalItem"+_nrseq).innerHTML = text[2];
											
											//Total da Compra
											Delivery.atualizaValorTotal(text[1]);
											//--- 						
											
											if (text[2].toString()=="0,00")
											{
												setTimeout(function(){Delivery.removetr(tri,trj,0)},50);
											}											
										}										
										Delivery.loadingClear();							
									} else {										
										document.write (text);
									}
								}
							}
							ajax.onreadystatechange = callback;
							ajax.send("nrseq="+_nrseq+"&qtd="+_qtd+"&Controls=" + document.getElementById("inc_topo_Variables").value);							
							
							//if (!this.success && Nav.ff){ 
							//	try{ 
							//		callback.call();									
							//	} 
							//	catch(e){}
							//}
							
							
						} else {
							alert("Seu navegador deve ser atualizado\npara suportar este script.")
						}						
					}
					
				},
	
	itens:{	
		QtdCurr: 0,
		clear:	function(_id){
					var temp = document.getElementById(_id);
					this.QtdCurr = temp.value;
					temp.value = "0";
					this.refreshQtd(temp);
				},
				
				
		clearbasket:  function(_n){
		
						if (_n==1){
							var ajax = startAjax();
							if (ajax){
								ajax.open("POST",Delivery.runclear,true);
								ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
								ajax.onreadystatechange = function(){
									if (ajax.readyState==4){
										if (ajax.status==200){
										var text = ajax.responseText.replace(/\+/g," ");
										
										if (text=="00000") {
											alert("Sua sessão foi perdida.\nEntre novamente!");
											location.href = "../index.aspx";
											return false;
										}
							
											document.getElementById("DeliveryQtdeItens").innerHTML = "0000";
											document.getElementById("DeliveryPrecoTotal").innerHTML = "00000,00";
											Delivery.callPage("../default/index.aspx?Controls=" + document.getElementById("inc_topo_Variables").value);
										}
									}
								}
								ajax.send("Controls=" + document.getElementById("inc_topo_Variables").value);
							} else {
								alert("Seu navegador deve ser atualizado\npara suportar este script.")
							}						
						} else{
							if (confirm("Tem certeza que deseja limpar sua cesta?")){
								Delivery.itens.clearbasket(1);
							}
						}	
					  },
					  				
				
		maxValueRechead:	function(_obj,_bool){
								if (_bool)
									_obj.className = "input_carrinho_fill";
								else
									_obj.className = "input_carrinho";
							},
						
		 // SETAS MAIS E MENOS	
		//	LISTAPRODUTOS.ASPX							
		Qtd:	function(_obj){
					// add.Qtd302.5 
					var temp = _obj.id.split('.'); 
					var type = temp[0].toUpperCase(); // add
					var id = temp[1].replace("Qtd",""); // 302
					var qtdmax = temp[2]; // 5
					var inpQtd = document.getElementById(temp[1]+'.'+temp[2]);
					var increment = inpQtd.getAttribute("increment");
					var initialInc = inpQtd.getAttribute("initialInc");
					if (isNaN(inpQtd.value) || parseInt(inpQtd.value) < 0 || inpQtd.value == "") inpQtd.value = 0;
					var vlr = (parseInt(inpQtd.value) > 0)?inpQtd.value:0;					
					this.QtdCurr = inpQtd.value;
					
					var calc = 0;

					if (type=="ADD"){
						calc = parseFloat(inpQtd.value) + parseFloat(increment);
						if (parseFloat(calc) < parseFloat(initialInc)) increment = initialInc;
						inpQtd.value = (parseFloat(vlr) < parseFloat(qtdmax))?parseFloat(inpQtd.value)+parseFloat(increment):inpQtd.value;
					} else {
						calc = parseFloat(inpQtd.value) - parseFloat(increment);
						if (parseFloat(calc) < parseFloat(initialInc)) increment = initialInc;
						inpQtd.value = (parseFloat(vlr) < 1)?"0":parseFloat(inpQtd.value)-parseFloat(increment);
					}
					
					if (parseFloat(inpQtd.value) < parseFloat(increment)){
						inpQtd.value = 0;
					}
					
					if (parseFloat(inpQtd.value) >= parseFloat(qtdmax)){
						inpQtd.value = qtdmax;
						this.maxValueRechead(inpQtd,true);
					} else this.maxValueRechead(inpQtd,false);							
										
					
					if (parseFloat(this.QtdCurr)!=parseFloat(inpQtd.value))
						Delivery.Carrinho.reload(id,inpQtd.value);
						
				},
				
		 // SETAS MAIS E MENOS	
		//	CARRINHO.ASPX		
		QtdCarrinho:	function(_obj){	
				
							// add.Qtd302.5 
							var temp = _obj.id.split('.'); 
							var type = temp[0].toUpperCase(); // add
							var id = temp[1].replace("Qtd",""); // 302
							var qtdmax = temp[2]; // 5
							var inpQtd = document.getElementById(temp[1]+'.'+temp[2]);
							var increment = parseFloat(inpQtd.getAttribute("increment"));
							var initialInc = inpQtd.getAttribute("initialInc");
							if (isNaN(inpQtd.value) || parseInt(inpQtd.value) < 0 || inpQtd.value == "") inpQtd.value = 0;
							var vlr = (parseInt(inpQtd.value) > 0)?inpQtd.value:0;
							var tri = document.getElementById("tri"+id); // get TRI							
							this.QtdCurr = inpQtd.value;


							var calc = 0;
							if (type=="ADD"){
								calc = parseFloat(inpQtd.value) + parseFloat(increment);
								if (parseFloat(calc) < parseFloat(initialInc)) increment = initialInc;
								inpQtd.value = (parseFloat(vlr) < parseFloat(qtdmax))?parseFloat(inpQtd.value)+increment:inpQtd.value;
							} else {
								calc = parseFloat(inpQtd.value) - parseFloat(increment);
								if (parseFloat(calc) < parseFloat(initialInc)) increment = initialInc;							
								if (type=="REM") inpQtd.value = (parseFloat(vlr) < 1)?"0":parseFloat(inpQtd.value)-increment;
								else inpQtd.value = "0";
							}
							
							if (parseFloat(inpQtd.value) < increment){
								inpQtd.value = 0;
							}
							
							if (parseInt(inpQtd.value)==0 || inpQtd.value==""){
								if (!confirm('Tem certeza que deseja remover este produto?')){
									inpQtd.value = this.QtdCurr;
									return false;
								}
							}
							
			
							if (parseInt(inpQtd.value) >= parseInt(qtdmax)){
								inpQtd.value = qtdmax;
								this.maxValueRechead(inpQtd,true);
							} else this.maxValueRechead(inpQtd,false);
							
							
							if (parseInt(this.QtdCurr)!=parseInt(inpQtd.value)){								
								var ajax = startAjax();
									if (ajax){
										ajax.abort();
										Delivery.loading();
										ajax.open("POST",Delivery.runtime,false);
										ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
										ajax.onreadystatechange = function(){
											if (ajax.readyState==4){
												if (ajax.status==200){
													var text = ajax.responseText.replace(/\+/g," ");
													text = text.split("?");													
													
													if (text=="00000") {
														alert("Sua sessão foi perdida.\nEntre novamente!");
														location.href = "../index.aspx";
														return false;
													}
									
													for (var i = 0; i < 3; i++){
														if (text[0].length < 4) text[0] = "0" + text[0];
													}
													
													document.getElementById("DeliveryQtdeItens").innerHTML = text[0];
													document.getElementById("DeliveryPrecoTotal").innerHTML = text[1];
													document.getElementById("DeliveryTotalItem"+id).innerHTML = text[2];
																								
													// Total da Compra
													Delivery.atualizaValorTotal(text[1]);													
																																			
													if (text[2].toString()=="0,00"){
														setTimeout(function(){Delivery.removetr(tri,0)},50);																											
													}
													
													/* se nao existir mais itens no carrinho redireciona para o inicio */
													var vlrtotal = document.getElementById("DeliveryPrecoTotal").innerHTML.replace(",",".");
													if (!parseFloat(vlrtotal) > 0) Delivery.calling("../default/index.aspx?newDataSet=true&Controls=" + document.getElementById("inc_topo_Variables").value);
													/* -- -- */
													Delivery.loadingClear();
												} else {
													alert (text);
												}
											}
										}
										ajax.send("nrseq="+id+"&qtd="+inpQtd.value+"&Controls=" + document.getElementById("inc_topo_Variables").value);
									} else {
										alert("Seu navegador deve ser atualizado\npara suportar este script.")
									}						
							}	
						},				
		
		 // EVENTO ON BLUR	
		// LISTAPRODUTOS.ASPX - CARRINHO.ASPX
		refreshQtd:	function(_obj,_null){
						var temp = _obj.id.replace("Qtd","").split('.');
						var id = temp[0];
						var qtdmax = temp[1];
						var increment = _obj.getAttribute("increment");
						var initialInc = _obj.getAttribute("initialInc");
						var typeinc = _obj.getAttribute("typeinc");
						if (_obj.value.indexOf(".")!=-1) _obj.value = 0;
						var v = _obj.value;
												
						if (isNaN(v) || v == "" || parseFloat(v) < 0){
							v = 0;
						}
						
						var major = 0;
						var minor = 0;
						var calc = 0;
						
						v = parseFloat(v);						
						increment = parseFloat(increment);
						initialInc = parseFloat(initialInc);
						
						
						if (parseFloat(this.QtdCurr) < v){
							if (v < initialInc)	{
								v = initialInc;
								alert("Quantidade mínima inicial: " + initialInc + " " + typeinc.toLowerCase());
							}
						} else {
							if (parseFloat(this.QtdCurr) > v){
								if (v < initialInc) {
									if (v > Math.floor(initialInc / 2)){
										v = initialInc;
										alert("Quantidade mínima inicial: " + initialInc + " " + typeinc.toLowerCase());
									} else {
										v = 0;
									}
								}
							}
						}
						
						
						/*	increment = 1; */
			            
						if ((v%increment) != 0){
							major = Math.ceil(v/increment)*increment;
							minor = major-increment;
							v = ((major-v) > (v-minor)) ? minor : major;
						}
						
						_obj.value = v;						
						
						var vlr = v;

						if (v >= parseFloat(qtdmax)){
							_obj.value = qtdmax;
							this.maxValueRechead(_obj,true);
							alert("Quantidade máxima permitida: " + qtdmax + " " + typeinc.toLowerCase());
						} else this.maxValueRechead(_obj,false);
						
					
						if (_null!=null){
							if (parseFloat(_obj.value)==0 || _obj.value==""){
								if (!confirm('Tem certeza que deseja remover este produto?')){
									_obj.value = this.QtdCurr;
									return false;
								}
							}						
						}

						if (parseFloat(this.QtdCurr)!=parseFloat(_obj.value))
							Delivery.Carrinho.reload(id,_obj.value,_null);
					},
					
		removeItem:	function(_obj){
						Delivery.itens.QtdCarrinho(_obj);
					}
		
	}		
}


/*	FUNÇÕES	 */

// Inicializa o uso do Ajax
function startAjax(){
	try { xmlhttp = new XMLHttpRequest(); } 
	catch(e) { 	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
	  		catch(ee){	try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} 
						catch(E){xmlhttp = false;}
						}
			} return xmlhttp;
}

function loadingPosition(_xy,_obj){
	if (Delivery.browser.ie){
	
		if (_xy.toLowerCase()=="x"){
			return (document.documentElement.offsetWidth)-(_obj.offsetWidth+40);
		} else {
			return 20+window.document.body.scrollTop;
		}
	
	} else {
	
		if (_xy.toLowerCase()=="x"){
			return (window.innerWidth)-(_obj.offsetWidth+30);
		} else {
			return 20+window.document.body.scrollTop;
		}		
		
	}
		
}


// Permite somente a entrada de valores numéricos (input)

/****************************************************/
function Image(_this,agua,_id){
	document.getElementById("img0").src = "../thumbs/thumbs.aspx?w=160&h=160&path=" + _this + "&agua=" + agua + "&id=" + _id;
	if (_id != "0"){
		document.getElementById("img0").onclick = function(){ ZoomImage(_id) }
	}
}

function ZoomImage(_id){
	window.open('../zoom/zoom.aspx?id='+_id, '', 'width=380, height=300, top=120, left=200, scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no'); 
}

function searchDelivery(_query,_dept){
	if (_query!="" || _dept!=""){
		Delivery.callPage("../lista/listaProdutos.aspx?newDataSet=true&section=0&query=" + escape(_query) + "&dept=" + _dept + "&Controls=" + document.getElementById("inc_topo_Variables").value);
		document.getElementById("inc_busca_chave").value = "";
		document.getElementById("inc_busca_dropdepartamento").value = "";
	}else return false;
}



	/*	Retorna a posição X e Y de um objeto  */
	function getxy(obj) {
		var xpos = ypos = 0;
		if (obj.offsetParent) {
			xpos = obj.offsetLeft
			ypos = obj.offsetTop
			while (obj = obj.offsetParent) {
				xpos += obj.offsetLeft
				ypos += obj.offsetTop
			}
		}
		return [xpos,ypos];
	}


	/*  Identificador de Browser  */
	var Nav = new function(){
		this.userA = navigator.userAgent.toLowerCase();
		this.op = this.userA.indexOf("opera") > -1;
		this.ie = this.userA.indexOf("msie") > -1 && document.all && !this.op;
		this.ff = this.userA.indexOf("firefox") > -1;
	}
	


	/*	BEGIN TOOLTIP	*/
	var tooltip = {
		changeOpacity: function(_n,_obj,_vlr){
							if (_n==1){
								if (_vlr <= 100){
									(Nav.ff)?_obj.style.MozOpacity = _vlr/100:_obj.style.filter = "alpha(opacity="+_vlr+")";
									setTimeout(function(){tooltip.changeOpacity(1,_obj,_vlr+25)},30);
								}	
							} else {
								if (_vlr > 0) {
									(Nav.ff)?_obj.style.MozOpacity = _vlr/100:_obj.style.filter = "alpha(opacity="+_vlr+")";
									setTimeout(function(){tooltip.changeOpacity(0,_obj,_vlr-25)},30);
								} else _obj.parentNode.removeChild(_obj);
							}
						},
						
		show: 	function(_obj,_txt){
					var div = document.getElementById("shtooltip");
					if (div) div.parentNode.removeChild(div);
					div = document.createElement("div");
					div.id = "shtooltip";
					div.innerHTML = _txt;
					document.body.appendChild(div);
					_obj.onmouseout = 	function(){
											var div = document.getElementById("shtooltip");
											setTimeout(function(){tooltip.changeOpacity(0,div,100)},30);
										};
					var div = document.getElementById("shtooltip");
					div.style.left = getxy(_obj)[0]+_obj.offsetWidth*2+"px";
					div.style.top = getxy(_obj)[1]+"px";
					div.style.visibility = "visible";
					div.style.MozOpacity = 0.0;
					div.style.filter = "alpha(opacity=0)";
					setTimeout(function(){tooltip.changeOpacity(1,div,0)},30);
				}
	}
	/*  END TOOLTIP	 */
	
	
	function showCepDetails(_n){
		var cepDetails = document.getElementById('cepDetails'+_n).innerHTML;
		document.getElementById("divDetailsCep").innerHTML = cepDetails;
	}
	/*	HASH	*/
	
	var hashListener = {
	ie:		/MSIE/.test(navigator.userAgent),
	ieSupportBack:	true,
	hash:	document.location.hash,
	pag: null,
	check:	function () {
		var h = document.location.hash;
		if (h != this.hash) {
			this.hash = h;
			this.onHashChanged(this.pag);
		}
	},
	init:	function () {

		// for IE we need the iframe state trick
		if (this.ie && this.ieSupportBack) {
			var frame = document.createElement("iframe");
			frame.id = "state-frame";
			frame.style.display = "none";
			frame.src = "../blank/blank.aspx";
			document.body.appendChild(frame);
			this.writeFrame("");
		}

		var self = this;

		// IE
		if ("onpropertychange" in document && "attachEvent" in document) {
			document.attachEvent("onpropertychange", function () {
				if (event.propertyName == "location") {
					self.check();
				}
			});
		}
		// poll for changes of the hash
		window.setInterval(function () { self.check() }, 50);
	},
	setHash: function (s) {
		// Mozilla always adds an entry to the history
		if (this.ie && this.ieSupportBack) {
			this.writeFrame(s);
		}
		
		if (location.href.toLowerCase().indexOf("index.asp") == -1 && location.href.toLowerCase().indexOf("listaprodutos.aspx") == -1 && location.href.toLowerCase().indexOf("listaprodutossf.aspx") == -1 && location.href.toLowerCase().indexOf("detalhes.aspx") == -1 && location.href.toLowerCase().indexOf("lista.aspx") == -1 && location.href.toLowerCase().indexOf("receitas/detalhes.aspx") == -1 && location.href.toLowerCase().indexOf("promocoes.aspx") == -1 && location.href.toLowerCase().indexOf("exclusividades.aspx") == -1){
			location.href(hashListener.pag);
		}
			
		
		document.location.hash = s;
	},
	
	getHash: function () {
		return document.location.hash;
	},
	writeFrame:	function (s) {
		var f = document.getElementById("state-frame");
		if (f){
			var d = f.contentDocument || f.contentWindow.document;
			d.open();
			d.write("<script>window._hash = '" + s + "'; window.onload = parent.hashListener.syncHash;<\/script>");
			d.close();				
		} else {
			location.href(hashListener.pag) 
		}
		
	},
	syncHash:	function () {
		var s = this._hash;
		if (s != document.location.hash) {
			document.location.hash = s;
		}
	},
	onHashChanged:	function () { }
};


function setHash(_p) {
	hashListener.pag = _p;
	hashListener.setHash("Dm" + Math.random(1000));
}


hashListener.onHashChanged = function (_p) {
	arrCreate(document.location.hash,_p);
};


var hashArray = new Array();
function arrCreate(h,p){
	var flag = false;

	if (h.length > 1 && h.substring(0,3) == "#Dm"){
		for (var i = 0; i < hashArray.length; i++){
			if (hashArray[i][0]==h){
				flag = true;
			}
		}
		if (!flag)	hashArray.push([h,p]);	
		
		var bbb = ""
		for (var i = 0; i < hashArray.length; i++){
			bbb += hashArray[i][0] + "[ " + hashArray[i][1] + " ]\n\n";
		}
		
		for (var i = 0; i < hashArray.length; i++){
			if (hashArray[i][0]==h) Delivery.calling(hashArray[i][1]);
		}
	} else {
		if (h.lenght < 15){
			Delivery.calling("../default/index.aspx?Controls=" + document.getElementById("inc_topo_Variables").value);
		}
	}
}	



function GLOpcoes(){
	var Ext = document.getElementById("radioext");
	var New = document.getElementById("radionew");
	
	document.getElementById("mylists").disabled = true;
	document.getElementById("listname").disabled = true;
	document.getElementById("listname").className = "input_ds";
	if (Ext.checked) document.getElementById("mylists").disabled = false;
	else{
		document.getElementById("listname").disabled = false;
		document.getElementById("listname").className = "input_ab";
	} 
}

function callFlash(_path,_w,_h){
	var flash = "";		
	flash = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + _w + "' height='" + _h + "'>";
	flash += "<param name='movie' value='" + _path + "' />";
	flash += "<param name='quality' value='high' />";
	flash += "<param name='wmode' value='transparent' />";
	flash += "<embed src='" + _path + "' quality='high' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + _w + "' height='" + _h + "'></embed>";
	flash += "</object>";		
	document.write(flash);		
}