/************************************************************************************************
# FloripaNegócios - www.flroripanegocios.com.br
# Scripts Gerais
*************************************************************************************************/
function ContinuarComprando(){
	history.back();
}
function elimina_virgula(obj, valor){	
	obj.value = valor.replace(',','.');
}
function controleCarrinho(produto,geraPedido){
	$('#botoesCarrinho').html('<img src="http://www.floripanegocios.com.br/_templates/_img/ajaxbar.gif">');
	x_controleCarrinho(produto,geraPedido,retornaControleCarrinho);
}
function calculaTotalCarrinho(id,valor,obj){
	if(valor>=1){
		$('#sub'+id).html('<img src="http://www.floripanegocios.com.br/_templates/_img/ajax.gif">');
		$('#carrinhoTotal').html('<img src="http://www.floripanegocios.com.br/_templates/_img/ajax.gif">');
		x_atualizaCarrinho(id,valor,retornaTotalCarrinho);
	}
	else{
		alert('A quantidade não pode ser inferior a 1, por favor, verifique!');
		obj.value = 1;
	}
}
function retornaTotalCarrinho(ret){
	$('#sub'+ret['id']).html(ret['sub']);
	$('#carrinhoTotal').html(ret['total']);
}
function removeItemCarrinho(id){
	if(confirm('Tem certeza que deseja remover esse item do carrinho?')){
		x_remCarrinhoTabela(id,retornaTabelaCarrinho);
	}
}
function retornaTabelaCarrinho(ret){
	$('#tabelaCarrinho').html(ret);
}
function retornaControleCarrinho(ret){
	$('#botoesCarrinho').html(ret);
}
function abreCarrinho(){
	window.open('?mod=carrinho','_self','');
}
function abrirPainel(acao){
	if(acao=='A'){
		$("#suaconta").slideDown("slow");
	}
	else{
		$("#suaconta").slideToggle("slow");
	}
}

function confsenha(frm){
	
}
function masc_cep(objeto,cep) 
{ 
    var mycep = ''; 
    mycep = mycep + cep; 
    if (mycep.length == 5) { 
        mycep = mycep + '-'; 
		objeto.value = mycep; 
    } 
}
function veremail(obj, email){
	if (email){
		reemail=/^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if (reemail.test(email)) {
			return true;
		}
		else {
			alert(email + " NÃO é um endereço de e-mail válido.");
			obj.focus();
			return false;
		}
	}
}
function formatTelefone(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)){
		return false;
	}
	campo = typeof(campo) == "object" ? campo : document.getElementById(campo);
	if(campo.value.charAt(0) != "(" && !isNaN(String.fromCharCode(t)))
		campo.value = "("+campo.value;
	if( typeof window.event != "undefined" ) {
		if(window.event.keyCode != 40) {
			if(campo.value.length == 0) {
				campo.value += '(';
			}
		}
		if(window.event.keyCode != 41) {
			if(campo.value.length == 3) {
				campo.value += ')';
			}
		}
		if(window.event.keyCode != 45) {
			if(campo.value.length == 8) {
				campo.value += '-';
			}
		}
	} else {
		if (e.which != 8) {
			if(e.which != 0) {
				if(e.which != 40) {
					if(campo.value.length == 0) {
						campo.value += '(';
					}
				}
			}
			if(e.which != 41) {
				if(campo.value.length == 3) {
					campo.value += ')';
				}
			}
			if(e.which != 45) {
				if(campo.value.length == 8) {
					campo.value += '-';
				}
			}
		}
	}
}

function masc_data(objeto,data) 
{ 
    var mydata = ''; 
    mydata = mydata + data; 
    if (mydata.length == 2) { 
        mydata = mydata + '/'; 
		objeto.value = mydata; 
    } 
	if (mydata.length == 5) { 
        mydata = mydata + '/'; 
		objeto.value = mydata; 
    } 
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
	if((tecla > 47 && tecla < 58)) return true;
		else{
		if ((tecla != 8)&&(tecla != 0)) return false;
		else return true;
		}
}


function carregandoDados(campo,load){
	if(load=='S'){
		$(campo).css('backgroundImage','url(http://www.floripanegocios.com.br/_templates/_img/ajax.gif)');
		$(campo).css('backgroundRepeat','no-repeat');
		$(campo).css('backgroundPosition','center center');
	}
	else $(campo).css('backgroundImage','none');
}

function retornoConfereUnico(ret){
	if (ret['temdados']=='S'){
		alert('Já exite '+ret['campo']+' '+ret['valor']+' no banco de dados! Por favor, informe outro valor.');
		document.getElementById(ret['campoform']).value = '';
		return false;
	}
	else{
		return true;
	}
}

function retornaEndereco(cep,camposRetorno){
	if(cep){
		$('#carregaEndereco').show();
		x_funcoesCustom('Ccidades','retornaEndereco',ArrayParaString(Array(cep,camposRetorno)),exibeEndereco);
	}
}

function exibeEndereco(ret){
	$('#carregaEndereco').hide();
	arrcampos = new Array();
	arrcampos = ret['campos'].split(',');
	if(ret['endereco']) document.getElementById(arrcampos[0]).value = ret['endereco'];
	if(ret['bairro']) document.getElementById(arrcampos[1]).value = ret['bairro'];
	if(ret['fk_uf']) document.getElementById(arrcampos[3]).value = ret['fk_uf'];
	if((ret['fk_uf'])&&(ret['fk_cidade'])){
		//Retorna a cidade via Ajax
		x_retornaSelect('div_'+arrcampos[2],ret['fk_cidade'],arrcampos[2],arrcampos[2],'campos','','cidades','and fk_uf=' + ret['fk_uf'],retornaHTML);
	}
}

function retornaHTML(ret){
	if(ret['imgload']){
		jQuery('#'+ret['imgload']).hide();
	}
	//alert(ret['html']);
	jQuery('#'+ret['div']).html(ret['html']).fadeIn();
}

function ArrayParaString(arr){
	txtstring = "";
	for(i=0;i<arr.length;i++){
		txtstring += "\'"+arr[i]+"\'";
		if(i<arr.length-1) txtstring += ",";
	}
	return 'Array('+txtstring+')';
}

$(document).ready(function() {	
		if(!Modernizr.input.placeholder){
		    $('[placeholder]').focus(function() {
		      var input = $(this);
		      if (input.val() == input.attr('placeholder')) {
		        input.val('');
		        input.removeClass('placeholder');
		      }
		    }).blur(function() {
		      var input = $(this);
		      if (input.val() == '' || input.val() == input.attr('placeholder')) {
		        input.addClass('placeholder');
		        input.val(input.attr('placeholder'));
		      }
		    }).blur();
		    $('[placeholder]').parents('form').submit(function() {
		      $(this).find('[placeholder]').each(function() {
		        var input = $(this);
		        if (input.val() == input.attr('placeholder')) {
		          input.val('');
		        }
		      })
		    });
		}
	});
