
	var xmlhttp;

	function getObjAjax() {
	
		objXML = null;

		var arrXml = new Array(
			'Msxml2.XMLHTTP.6.0',
			'Msxml2.XMLHTTP.5.0',
			'Msxml2.XMLHTTP.4.0',
			'Msxml2.XMLHTTP.3.0',
			'Msxml2.XMLHTTP',
			'Microsoft.XMLHTTP');

		try {
			objXML = new XMLHttpRequest();
		} catch (e) {
			for (var i = 0; i < arrXml.length; i++) {
				try {
					objXML = new ActiveXObject(arrXml[i]);
				} catch (ee) {
					objXML = null;
				}
			}
		}

		return objXML;

	}

	function getAjax(Metodo, Endereco, Funcao, Parametros){
	
		xmlhttp = getObjAjax();

		if(xmlhttp){

			xmlhttp.onreadystatechange = Funcao;

			if(Metodo=="post" && !Parametros==false && Parametros!= ""){
				xmlhttp.open("POST", antiCacheRand(Endereco), true);
				xmlhttp.setRequestHeader("Cache-Control", "no-cache");
				xmlhttp.setRequestHeader("Pragma", "no-cache");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
				xmlhttp.send(Parametros);
			}else{
				xmlhttp.open("GET", antiCacheRand(Endereco), true);
				xmlhttp.setRequestHeader("Cache-Control", "no-cache");
				xmlhttp.setRequestHeader("Pragma", "no-cache");
				xmlhttp.send(null);
			}
			
			return true;

		}else{
			
			return false;
			
		}

	}

	function antiCacheRand(enderecoajax){
		
		var datatemp = new Date();
		
		if (enderecoajax.indexOf("?") >= 0){
			return enderecoajax + "&" + encodeURI(Math.random() + "_" + datatemp.getTime());
		}else{
			return enderecoajax + "?" + encodeURI(Math.random() + "_" + datatemp.getTime());
		}
		
	}
	
	function listarCampos(frm){
	
		var listagem = "";
		var FormCampos = frm.elements;
		var qtdCampos = frm.elements.length;
		var campo;

		this.juntarCampo = function(nome,valor) { 
								if (listagem.length > 0) { 
									listagem += "&";
								}
								listagem += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
							}

		for (var i=0; i < qtdCampos; i++) {
			campo = FormCampos[i];
			if (!campo.disabled) {
				switch(campo.type) {
					case 'text': case 'password': case 'hidden': case 'textarea': 
						this.juntarCampo(campo.name, campo.value);
						break;
					case 'select-one':
						if (campo.selectedIndex >= 0) {
							this.juntarCampo(campo.name, campo.options[campo.selectedIndex].value);
						}
						break;
					case 'select-multiple':
						for (var j=0; j < campo.options.length; j++) {
							if (campo.options[j].selected) {
								this.juntarCampo(campo.name, campo.options[j].value);
							}
						}
						break;
					case 'checkbox': case 'radio':
						if (campo.checked) {
							this.juntarCampo(campo.name, campo.value);
						}
						break;
				}
			}
		}	

		return(listagem);

	}

	function $(campo){
		
		return document.getElementById(campo);
		
	}
	
	function printID(id,texto){
		
		document.getElementById(id).innerHTML = texto;
		
	}

	function flash(arquivo, largura, altura){
	
		document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + largura + '" height="' + altura + '">');
		document.writeln('  <param name="movie" value="' + arquivo + '">');
		document.writeln('  <param name="quality" value="high">');
		document.writeln('  <param name="allowScriptAccess" value="sameDomain" />');
		document.writeln('  <param name="wmode" value="transparent" />');
		document.writeln('  <param name="menu" value="false" />');
		document.writeln('  <param name="bgcolor" value="#ffffff" />');
		document.writeln('  <embed src="' + arquivo + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
		document.writeln('</object>');

	}

	function AbreJanela(linkjanela, x, y, s) {
	
		var t = (screen.height - y) / 2;
		var e = (screen.width - x) / 2;

		window.open(linkjanela,'','width=' + x + ',height=' + y + ',scrollbars=' + s + ',toolbar=0,location=0,status=0,menubar=0,resizable=0,left=' + e + ',top=' + t + '');

	}

	function mascara(o,f){
		v_obj=o;
		v_fun=f;
		setTimeout("execmascara()",1);
	}

	function execmascara(){
		v_obj.value=v_fun(v_obj.value);
	}

	function leech(v){
		v=v.replace(/o/gi,"0");
		v=v.replace(/i/gi,"1");
		v=v.replace(/z/gi,"2");
		v=v.replace(/e/gi,"3");
		v=v.replace(/a/gi,"4");
		v=v.replace(/s/gi,"5");
		v=v.replace(/t/gi,"7");
		return v
	}

	function numero(v){
		return v.replace(/\D/g,"");
	}

	function telefone(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
		v=v.replace(/(\d{4})(\d)/,"$1-$2");
		return v
	}

	function cep(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d{5})(\d)/,"$1-$2");
		return v
	}


	function cpf(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
		return v
	}

	function cnpj(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d{2})(\d)/,"$1.$2");
		v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3");
		v=v.replace(/\.(\d{3})(\d)/,".$1/$2");
		v=v.replace(/(\d{4})(\d)/,"$1-$2");
		return v
	}

	function rg(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/(\d{2})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
		return v
	}
	
	function data(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/(\d{2})(\d)/,"$1/$2");
		v=v.replace(/(\d{2})(\d)/,"$1/$2");
		return v
	}

	
	/* AJAX */

	function chamarProdutos(ano){

		var produto = document.getElementById("produto");
		while( produto.options.length > 0 ) produto.options[0]=null;
		produto.options[0]=new Option("","")
		
		getAjax('get', 'ajax/produto.asp?ano='+ano, chamarProdutos_fun);

	}

	function chamarProdutos_fun(){

		if(xmlhttp.readyState==4){ 
			if(parseInt(xmlhttp.status)==200){
				
				$('lista_produtos').style.display='';
				$('msg_ajax').style.display='none';
			
				var produto = document.getElementById("produto");
				while( produto.options.length > 0 ) produto.options[0]=null;
				var jsLista = eval((xmlhttp.responseText));
				
				if(jsLista.length==1){
					
					$('lista_produtos').style.display='none';
					$('msg_ajax').style.display='none';
					
					
				}else{
					
					for(var i=0;i<jsLista.length;i++){
						jsLista[i]=unescape(jsLista[i])
						arrjsLista=jsLista[i].split( "|" );
						produto.options[produto.options.length]=new Option(arrjsLista[1],arrjsLista[0]);
					}
				
				}
				
			}
		}else{
			
			$('lista_produtos').style.display='none';
			$('msg_ajax').style.display='';
			$('msg_ajax').innerHTML='<br><br><center><img src=\'images/ajax.gif\'><br><br>Carregando...</center><br><br>';
			
		}

	}
	
	function chamarIndice(ano){

		var indice = document.getElementById("indice");
		while( indice.options.length > 0 ) indice.options[0]=null;
		indice.options[0]=new Option("","")
		
		getAjax('get', 'ajax/indice.asp?ano='+ano, chamarIndice_fun);

	}

	function chamarIndice_fun(){

		if(xmlhttp.readyState==4){ 
			if(parseInt(xmlhttp.status)==200){
				
				$('lista_indice').style.display='';
				$('msg_ajax').style.display='none';
			
				var indice = document.getElementById("indice");
				while( indice.options.length > 0 ) indice.options[0]=null;
				var jsLista = eval((xmlhttp.responseText));
				
				if(jsLista.length==1){
					
					$('lista_indice').style.display='none';
					$('msg_ajax').style.display='none';
					
					
				}else{
					
					for(var i=0;i<jsLista.length;i++){
						jsLista[i]=unescape(jsLista[i])
						arrjsLista=jsLista[i].split( "|" );
						indice.options[indice.options.length]=new Option(arrjsLista[1],arrjsLista[0]);
					}
				
				}
				
			}
		}else{
			
			$('lista_indice').style.display='none';
			$('msg_ajax').style.display='';
			$('msg_ajax').innerHTML='<br><br><center><img src=\'images/ajax.gif\'><br><br>Carregando...</center><br><br>';
			
		}

	}
	
	
	function validarPesquisaFornecedores(frm){
	
		if(frm.categoria.value=='0'){
			alert('Informe a Categoria');
			frm.categoria.focus();
			return false;
		}

	}
	
	function validarPesqFornRazao(frm){
	
		if(frm.empresa.value==''){
			alert('Informe a Razão Social');
			frm.empresa.focus();
			return false;
		}

	}
	
	function validarPesqFornFantasia(frm){
	
		if(frm.nomefantasia.value==''){
			alert('Informe o Nome Fantasia');
			frm.nomefantasia.focus();
			return false;
		}

	}
	
	

	function validarCadOferta(frm){
	
		if(frm.Fornecedor.value==''){
			alert('Informe o Fornecedor');
			frm.Fornecedor.focus();
			return false;
		}
		
		if(frm.Contato.value==''){
			alert('Informe o Contato');
			frm.Contato.focus();
			return false;
		}
		
		if(frm.Telefone.value==''){
			alert('Informe o Telefone');
			frm.Telefone.focus();
			return false;
		}

		frm.Email.value=frm.Email.value.replace(" ", "");
		
		if(frm.Email.value=='' || frm.Email.value.match(/(\w+)@(.+)\.(\w+)$/)==null){
			alert('Informe o E-mail');
			frm.Email.focus();
			return false;
		}

		if(frm.Produto.value==''){
			alert('Informe o Produto');
			frm.Produto.focus();
			return false;
		}

		if(frm.Caracteristicas.value==''){
			alert('Informe a Caracteristicas');
			frm.Caracteristicas.focus();
			return false;
		}

		if(frm.LocalEntrega.value==''){
			alert('Informe os Locais de Entrega');
			frm.LocalEntrega.focus();
			return false;
		}

		if(frm.CondicaoPagamento.value==''){
			alert('Informe as Condições de Pagamento');
			frm.CondicaoPagamento.focus();
			return false;
		}

		if(frm.ValorMinimo.value==''){
			alert('Informe o Valor Mínimo');
			frm.ValorMinimo.focus();
			return false;
		}

		if(frm.QuantidadeDisponivel.value==''){
			alert('Informe a Quantidade Disponível');
			frm.QuantidadeDisponivel.focus();
			return false;
		}

		if(frm.Preco.value==''){
			alert('Informe o Preço');
			frm.Preco.focus();
			return false;
		}

		if(frm.PrazoValidadeProduto.value==''){
			alert('Informe o Prazo de Validade do Produto');
			frm.PrazoValidadeProduto.focus();
			return false;
		}

		if(frm.PrazoValidadeOferta.value==''){
			alert('Informe o Prazo de Validade de Oferta');
			frm.PrazoValidadeOferta.focus();
			return false;
		}

		if(frm.Site.value==''){
			alert('Informe o Site');
			frm.Site.focus();
			return false;
		}
		
		if(frm.Informacoes.value==''){
			alert('Informe as Informações');
			frm.Informacoes.focus();
			return false;
		}

	}
	
	function validarPesquisaCesta(frm){
	
		if(frm.ano.value=='0'){
			alert('Informe o Ano');
			frm.ano.focus();
			return false;
		}
		
		if(frm.produto.value=='0'){
			alert('Informe o Produto');
			frm.produto.focus();
			return false;
		}

	}
	
	function validarPesquisaIndice(frm){
	
		if(frm.ano.value=='0'){
			alert('Informe o Ano');
			frm.ano.focus();
			return false;
		}
		
		if(frm.indice.value=='0'){
			alert('Informe o Indíce');
			frm.indice.focus();
			return false;
		}

	}
	
	
	
	

