function showDialog(aviso, titulo, url){
	
	if(titulo=="")
		titulo="&nbsp;";//para aparecer o topo sempre
		
	if(url!=""){
		jAlert(aviso, titulo,function(){location=url;});
	}else{
		jAlert(aviso, titulo);
	}
}

function setTipoPagamento(valor){
	
	var tp_pag = document.getElementById('tp_pag_cartao');
	
	tp_pag.value=valor;
	
}
function mostraParcelasCartao(for_pag_id){
	
	for(x=2;x<=3;x++){
		var div = document.getElementById('for_pag_idParcelas'+x);
		if(x==for_pag_id){
			div.style.display='block';
		}else{
			div.style.display='none';
		}
		
	}
}
function carregaDadosCep(cep, estado, cidade, endereco, bairro){
	
	valorCep = document.getElementById(cep).value;
	valorCep = replaceAll(valorCep,'_','');
		
	if(valorCep.length == 9){
		
		urlBack = escape('http://www.ellitecelular.com.br/retorno_cep.php?cu='+estado+'&cc='+cidade+'&ce='+endereco+'&cb='+bairro+'&cp='+cep);
		url = 'http://comercio.locaweb.com.br/correios/calcula_sedex.asp?cepDest='+valorCep+'&urlback='+urlBack;
		//alert(unescape(url));
		Iframe = document.getElementById("carregaCep");
		Iframe.src = url;			
	
	}
}
function janela(www,h,w)
{
	var height = window.screen.height - 160;
	var width = window.screen.width;
	var top = (height- h)/2;
	var left = (width - w)/2;
	win = window.open(www,"nova","top=" + top + ",left="+ left +",width="+w+",height="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,scrolling=no,resizable=no")
	win.focus();
}

function mudaFotoDestaqueProduto(idFoto,foto){
	
	var imgFoto = document.getElementById(idFoto);
	
	if(foto!=""){
		imgFoto.src = foto;
	}
	
}

function mudaQtdePaginacao(index){
    
    div = document.getElementById("qtdePaginacao");
    sel = document.getElementById("qtde_pag");
    sel2 = document.getElementById("qtde_pagBaixo");

    sel.selectedIndex = index;
    sel2.selectedIndex = index;
    div.innerHTML=sel.value;
  
}

function carregaOrdenacao(url,valor){
    url = unescape(url);
    url = url.split('&tp_ord');
    location = url[0] +"&tp_ord="+valor;
}

function verificaTipoCliente(tipo){

    divPF = document.getElementById('divPessoa');
    divPJ = document.getElementById('divJuridica');

    if(tipo==0){//PJ
        divPF.style.display='none';
        divPJ.style.display='block';
    }else{//PF
        divPF.style.display='block';
        divPJ.style.display='none';
    }
}

function mostraDiv(divString)
{
	obj = document.getElementById(divString);
	
	if(obj.style.display=='none' || obj.style.display=='')
		obj.style.display='block';
	else
		obj.style.display='none';
}

function hover(div,op,h,hover)
{
	var isIE = /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	
	if(isIE)
	{
		if(op=='on')
			div.className=hover;
		else
			div.className=h;
	}
}

function exibeFlash(swf, width, height, wmode, cache)
{
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	if(wmode==undefined) wmode="opaque";

	monta_swf = "";
	monta_swf += "<object id=\""+ swf+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" >";
	monta_swf += "<param name=\"quality\" value=\"high\" >";
	monta_swf += "<param align=\"center\" >";
	monta_swf += "<param name=\"menu\" value=\"0\" >";
	monta_swf += "<param name=\"allowScriptAccess\" value=\"always\" >";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" >";
	monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" menu=\"0\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";

	document.write(monta_swf);
}

function highlight(div,op)
{
	
	
	if(op=='on')
	{
		var prefixo = div.className;
		div.className+=' '+prefixo+'Highlight';
	}
	else
	{
		var classe = div.className.split(' ');
		div.className=classe[0];
	}
}

function link(url)
{
    window.location=url;
}

function evita_letra(tecla)
{
	var keyCode = tecla.keyCode ? tecla.keyCode : tecla.which ? tecla.which : tecla.charCode;
	//alert(keyCode);
	if(keyCode !=8 && keyCode !=13 && keyCode !=9)
	{
		if (keyCode < 48 || keyCode > 57)
		{
			if (window.event) //IE
			tecla.returnValue = false;
			else //Firefox
			tecla.preventDefault();
		}
	}
}

function subElemento(dados,ele){
		var aux='';
		var novo='';

		aux = dados.split(',');

		for(x=0;x<aux.length;x++){
			if(aux[x]!=ele){

				if(novo!='')
					novo+=','+aux[x];
				else
					novo+=aux[x];

			}

		}

		return novo;

}

function delEnderecoCadastro(id,atual){
	obj = document.getElementById('divEnderecosAdicionais');//pai
	obj2 = document.getElementById('divEnderecoEnd'+id);//filho
	obj.removeChild(obj2);

	obj2 = document.getElementById(atual);//campo que guarda os itens
	//alert(id);
	obj2.value = subElemento(obj2.value,id);
	

}

function replaceAll(string, token, newtoken) {

	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
        
	return string;
        
}

function addEnderecoCadastro(){
        
	obj = document.getElementById('divEnderecosAdicionais');//pai

	obj3 = document.getElementById('idAtual');//atual
	obj3.value = parseFloat(obj3.value)+1;

	cli_end_id = obj3.value;
	obj4 = document.getElementById('idInsere');

	if(obj4.value!='')
		obj4.value+=','+cli_end_id;
	else
		obj4.value+=cli_end_id;

	//coloca o nó no pai
	var novo = document.createElement('DIV');
	var clone = document.getElementById('cloneEndereco');
	var x = document.getElementById('contEndereco');
	var html='';
	html = clone.innerHTML;
	x.value = parseFloat(x.value)+1;

	html = replaceAll(html,'@@',cli_end_id);
	//alert(html);
	novo.id='divEnderecoEnd'+cli_end_id;
	novo.name='divEnderecoEnd'+cli_end_id;
	novo.innerHTML=html;

	obj.appendChild(novo);
	

}

function getCidade(cpc, cpuVal, cpcVal, cpcNome, parent){//pega a cidade colocando a div cidade com o id abaixo,
	
	//alert(cpc+' - '+cpuVal);	
	url = 'cadastroAjaxCidade.php?cpc='+cpc+'&cpuVal='+cpuVal+'&cpcVal='+cpcVal+'&cpcNome='+cpcNome;
	div = 'divCidade_'+cpc;
	//alert(cpcNome);
	if(parent){			
		getPageParent(url,div);
	}else{
		getPage(url,div);	
	}
	 
}

function menuOver()
{
	
	$("#menuMain").hover(
		function () {
			$("#menuMainBody").show("600");
		},
		function () {
			setTimeout(function() {
			    	$("#menuMainBody").hide("fast");
			}, 500); 
		}
	);
}
function filtroCidade(div,uf,prefixo){	
	getPage('ajaxCidade.php?uf='+uf+'&prefixo='+prefixo,div);	
}
