$(document).ready(function() { 
//chama o dialog de mensagem no onload.
$(function() {


//datas do sistema
/*---------------------------------------------------------------------------------------------*/

$('#dtPreferenciaVisita').datepicker({dateFormat:"dd/mm/yy"});

//modulo eventos
$('#txt_data_inicio').datepicker({dateFormat:"dd/mm/yy"});
$('#txt_data_fim').datepicker({dateFormat:"dd/mm/yy"});
//modulo cotacao
$('#txt_data_de').datepicker({dateFormat:"dd/mm/yy"});
$('#txt_data_ate').datepicker({dateFormat:"dd/mm/yy"});
$('#txt_data').datepicker({dateFormat:"dd/mm/yy"});
//cadastro de anuncios
$('#txt_vencimento').datepicker({dateFormat:"dd/mm/yy"});


/*---------------------------------------------------------------------------------------------*/   		   


$("#AgendaLogotipoRet").autocomplete("/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaImagens&tipo=3", {
//document.getElementById('txt_logotipo').value
  width: 450,
  max: 10,
  highlight: false,
  scroll: true,
  scrollHeight: 350,
  formatItem: function(data, i, n, value) {	 
    return value.split("^")[0] + "<br / ><img src='/guiadasindustrias/media/_UPLOADS/1/MIDIA_GDI/" + value.split("^")[1] + "'/> "
	//+ value.split(".")[0];
  },
  formatResult: function(data, value) {
	 document.getElementById('txt_logotipo').value = value.split("^")[1];
    return value.split("^")[1];
  }
});


$("#txt_midiaBusca").autocomplete("/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaImagens&tipo=1,2", 
{
//document.getElementById('txt_logotipo').value
  width: 750,
  max: 14,
  highlight: false,
  scroll: true,
  scrollHeight: 450,
  
  formatItem: function(data, i, n, value) {	 
	var s = "";
	var strObjeto = value.split("^")[1] ;
	
	if(Right(strObjeto,3) =="swf")
	{
		s = s + value.split("^")[0]
		s = s + " <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "
		s = s + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='720' height='90'> "
		s = s + "   <param name='movie' value='/guiadasindustrias/media/_UPLOADS/1/MIDIA_GDI/2010051148_BANNER_FULL.swf' /> "
		s = s + "   <param name='quality' value='high' /> "
		s = s + "   <param name='wmode' value='opaque' /> "
		s = s + "   <embed src='/guiadasindustrias/media/_UPLOADS/1/MIDIA_GDI/2010051148_BANNER_FULL.swf' quality='high' wmode='opaque' "
		s = s + "   pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' "
		s = s + "   type='application/x-shockwave-flash' width='720' height='90'></embed> "
		s = s + " </object>"	
	}
	else
	{
		s = s + "<br><img src='/guiadasindustrias/media/_UPLOADS/1/MIDIA_GDI/" + value.split("^")[1] + "' />"				
	};
	
     return s;
	//value.split("^")[0] + s
	//return value.split("^")[0] + "<br / ><img src='/guiadasindustrias/media/_UPLOADS/1/MIDIA_GDI/" + value.split("^")[1] + "'/> "
	//+ value.split(".")[0];
  },
  formatResult: function(data, value) {
	 document.getElementById('txt_midia').value = value.split("^")[1];
    return value.split("^")[1];
  }
});

///
$("#txt_cadProduto").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

$("#txt_cadProduto").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

$("#txt_cadProduto").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

$("#descf1").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

$("#descf2").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

$("#descf3").autocomplete(
	"/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaProduto",
	{
	delay:10,
//	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true
	}
);

//busca pelo cliente,(modulo anuncio)
$("#descf4").autocomplete("/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaCliente",
	{
	delay:10,
	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true,
	width: 450,
	max: 10,
	highlight: false,
	scroll: true,
	scrollHeight: 350

});
//busca pelo cliente,(modulo anuncio)
$("#descf5").autocomplete("/guiadasindustrias/includes/app/callAjax.asp?chamada=buscaCliente",
	{
	delay:10,
	minChars:2,
	matchSubset:4,
	matchContains:1,
	cacheLength:10,
	autoFill:true,
	width: 450,
	max: 10,
	highlight: false,
	scroll: true,
	scrollHeight: 350

});

/*
fcnFiltroId = function (id,idPaste)
{
	var intId =document.getElementById('txt_idcadastroBuscaCliente').value.split('^');	
	document.getElementById('txt_idcadastro').value = 	intId[0]
}*/





$("#erro").dialog({
			dialogClass: 'alert',
			bgiframe: true,
			modal: true,
			overlay: 
			{
				backgroundColor: '#F00',
				opacity: 1.5				
			},			
			buttons: {
				Ok: function() {
					history.back();
					//history.go(-1);
					$(this).dialog('close');
					
				}
			}
		});
		   
		//------------------------------------------------------------------------------	  
		//alerta
		$("#alerta").dialog({
			bgiframe: true,
			//height: 140,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
					history.go(-2);
				}
			}
		});
		//usado no portal.
		$("#alerta2").dialog({
			bgiframe: true,
			//height: 140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 4.5
			},			
			buttons: {
				Ok: function() {
					$(this).dialog('close');	
					window.parent.location= '/guiadasindustrias/portal/?pagina=portal';
				}
			}
		});
		
		$("#errosite").dialog({
			bgiframe: true,
			//height: 140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 9.1
			},			
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});		

		$("#alertalogin").dialog({
			bgiframe: true,
			//height: 140,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
					window.parent.location= '/guiadasindustrias/painel/';
				}
			}
		});

		$("#update").dialog({
			bgiframe: true,
			//height: 140,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
					history.go(-2);
				}
			}
		});
		
		//------------------------------------------------------------------------------	  
		//confirm
		$("#confirm").dialog({
			bgiframe: true,
			//height: 140,
			resizable: false,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 1.5
			},
			buttons: {
				'Ok': function() {
					$(this).dialog('close');
				},
				'Cancelar': function() {
					$(this).dialog('close');
					//alert('exec callback')
				}				
			}
		});
});
		
	//cria a mensagem de top de lista amarela
	//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	$(window).load(function()
	{
  		$('#message_box').animate({top:$(window).scrollTop()+"px" },{queue: true, duration: 1100});  
		$('#message_box').animate({ top:"+=15px",opacity:0 }, "slow");
	});
    //when the close button at right corner of the message box is clicked 
	$('#close_message').click(function()
	{
  		//the messagebox gets scrool down with top property and gets hidden with zero opacity 
		$('#message_box').animate({ top:"+=15px",opacity:0 }, "slow");
	});


//fim de ready
}); 



function fcnFiltroId(id,idPaste)
{
	if(id!='undefined')
	{
	var intId = document.getElementById('txt_idcadastroBuscaCliente').value.split('^');			
	document.getElementById('txt_idcadastro').value = 	intId[0]; 
	//document.getElementById('txt_idcadastroBuscaCliente').value = intId[1]; 
	}
}

function fcnFiltroIdAgenda(id,idPaste)
{
	if(id!='undefined')
	{
	var intId = document.getElementById('AgendaLogotipoRet').value.split('^');			
	document.getElementById('txt_logotipo').value = 	intId[0]; 
	//document.getElementById('txt_idcadastroBuscaCliente').value = intId[1]; 
	}
}


function fcnbuscaTipoHome(idstr){
	if(idstr.length >= 2 && idstr!=="")
	{
		$.ajax(
			{
			  type: "POST",
			  url: "/guiadasindustrias/includes/app/callAjax.asp?",
			  data: "chamada=buscaTipoHome&idstr=" + idstr ,
			  beforeSend: function() {
				// enquanto a função esta sendo processada, você
				$('#divbuscaTipoHome').html('<img src="/guiadasindustrias/media/grid/load.gif" width="16" height="16" border="0" />&nbsp;Processando...');
				
				// msg de carregando
			  },
			  success: function(txt) 
			  {	
				if(txt!='ERRO'){					
					if(txt)
					{
						$('#divbuscaTipoHome').show("slow");
						$('#divbuscaTipoHome').html(txt);
						$('#msg').html('');						
					}
					else
					{
						$('#divbuscaTipoHome').hide();
					};
				}
				else
				{			
					// se nao encontrar o cep, insiro esta pequena mensagem na div de id=msg
					$('#msg').html('erro...');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
				{							
					//$('#msg').html(XMLHttpRequest.responseText);
					alert(XMLHttpRequest);
					alert('Houve um problema interno. tente novamente mais tarde.' + idstr);	
			  }			  
			}
		);
		
	}
	else{
		$('#divbuscaTipoHome').hide();
		}
}


function buscaCidade(idUF){
	if(idUF.length == 2)
	{
		$.ajax(
			{
			  type: "POST",
			  url: "/guiadasindustrias/includes/app/callAjax.asp?",
			  data: "chamada=buscaCidade&idUF=" + idUF ,
			  beforeSend: function() {
				// enquanto a função esta sendo processada, você
				$('#msg').html('Processando...');
				// msg de carregando
			  },
			  success: function(txt) 
			  {	
				if(txt!='ERRO'){
					$('#idCidadeDiv').html(txt);
					$('#msg').html('');
				}
				else
				{
					// se nao encontrar o cep, insiro esta pequena mensagem na div de id=msg
					$('#msg').html('erro...');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
				{							
					//$('#msg').html(XMLHttpRequest.responseText);
					alert(XMLHttpRequest);
					alert('Houve um problema interno. tente novamente mais tarde.' + idUF);	
			  }			  
			}
		);
		
	}
}

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//SCRIPT USADO NA COMPOSIÇÃO DO SISTEMA DE UPLOADS.
	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 high(which2){
		theobject=which2
		highlighting=setInterval("highlightit(theobject)",50)
	}
	function low(which2){
		clearInterval(highlighting)
		which2.filters.alpha.opacity=20
	}
	function highlightit(cur2){
	if (cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=5
	else if (window.highlighting)
	clearInterval(highlighting)
	}
	function confirm_delete(form) {
		if (confirm("Tem certeza que deseja excluir o arquivo?")) {
			document[form].submit();
		}
	}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//Portal
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


function cadCotacao()
{
if(document.DataForm.txt_nome.value =="")
{
	alert('Por favor informe o seu nome.') ;
	return false;
}
if(document.DataForm.txt_email.value =="")
{
	alert('Por favor informe o seu e-mail.') ;
	return false;
}
if(document.DataForm.txt_telefone.value =="")
{
	alert('Por favor informe o seu telefone.') ;
	return false;
}
if(document.DataForm.txt_cadProduto.value =="")
{
	alert('Por favor informe o produto de interesse.') ;
	return false;
}
	document.DataForm.action = "/guiadasindustrias/portal/?pagina=portal&acao=cadastroCotacaoRapida";
	document.DataForm.submit();		 
}


function cadNewsletter()
{		
	if(document.DataForm.sNome.value =="")
	{
		alert('Por favor informe o seu nome.') ;
		return false;
	}	

	if(emailCheck(document.DataForm.sEmail.value)==false)
	{
		return false;
	}	
	document.DataForm.action = "/guiadasindustrias/portal/?pagina=portal&acao=cadastroNewsletter";
	document.DataForm.submit();		
}


function cadNewsletter2()
{		


	
	if(document.DataForm.sNome.value =="")
	{
		alert('Por favor informe o seu nome.') ;
		return false;
	}	

	if(emailCheck(document.DataForm.sEmail.value)==false)
	{
//		alert('Por favor informe o e-mail.') ;
		return false;
	}	

	if(document.DataForm.sSexo.value =="0")
	{
		alert('Por favor informe o sexo.') ;
		return false;
	}	
	
	if(document.DataForm.sUF.value =="0")
	{
		alert('Por favor informe o seu estado.') ;
		return false;
	}	
	if(document.DataForm.sCidade.value =="0")
	{
		alert('Por favor informe sua cidade.') ;
		return false;
	}

	document.DataForm.action = "/guiadasindustrias/portal/?pagina=newsletter&acao=cadastroNewsletter";
	document.DataForm.submit();		
}

function EnviaContato()
{
	if(document.DataForm.varNome.value =="")
	{
		alert('Por favor informe o seu nome.') ;
		return false;
	}	

	if(emailCheck(document.DataForm.varEmail.value)==false)
	{
//		alert('Por favor informe o e-mail.') ;
		return false;
	}	
	
	if(document.DataForm.varTel.value =="")
	{
		alert('Por favor informe o seu telefone.') ;
		return false;
	}	

	if(document.DataForm.varAssunto.value =="")
	{
		alert('Por favor informe o assunto.') ;
		return false;
	}

	if(document.DataForm.varMensagem.value =="")
	{
		alert('Por favor informe a mensagem.') ;
		return false;
	}
	
	document.DataForm.action = "/guiadasindustrias/portal/?pagina=contato&acao=enviaContato";
	document.DataForm.submit();		
	
	
}


function fcnBuscaHome()
{
	document.DataForm.action = "/guiadasindustrias/portal/?pagina=buscaEmpresaProdutoServicos&buscaTipoHome="+ document.getElementById('buscaTipoHome').value ;
	document.DataForm.submit();	
}

function callContent(conteudo)
{
	$.ajax(
	{
	  type: "POST",
	  url: "/guiadasindustrias/includes/app/callAjax.asp?",
	  data: "chamada=conteudo_portal&conteudo=" + conteudo ,
	  beforeSend: function() {
		// enquanto a função esta sendo processada, você
		$('#conteudo_portal_desc').html('<img src="/guiadasindustrias/media/grid/load.gif" width="16" height="16" border="0" />&nbsp;Processando...');
		
		// msg de carregando
	  },
	  success: function(txt) 
	  {	
		if(txt!='ERRO'){					
			if(txt)
			{
				$('#conteudo_portal_desc').show("slow");
				$('#conteudo_portal_desc').html(txt);
				$('#msg').html('');						
			}
			else
			{
				$('#conteudo_portal_desc').hide();
			};
		}
		else
		{			
			// se nao encontrar o cep, insiro esta pequena mensagem na div de id=msg
			$('#msg').html('erro...');
		}
	},
	error: function(XMLHttpRequest, textStatus, errorThrown)
		{							
			//$('#msg').html(XMLHttpRequest.responseText);
			alert(XMLHttpRequest);
			alert('Houve um problema interno. tente novamente mais tarde.' + conteudo);	
	  }			  
	}
	);
}

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//Portal
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

