$(document).ready(function() {
	$('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	
	$("input[type=text][name*=usu_nascimento]").mask("99/99/9999");

});

function getAjax(url,parametro,localdiv) {
	$.get(url+'?'+parametro, function(r){ $("#"+localdiv).html(r); });
}

function marcados(reg) {
	for (count = 0; count < reg.length; count++) {
		if (listapro[reg[count]] == '1') {
			$('#pro_'+reg[count]).attr('checked',true);
		}
	}

}

function enderecoEntrega() {
	if ($('#end_igual').attr('checked')) {
		$('#usu_entcep').val($('#usu_cep').val());
		$('#usu_entendereco').val($('#usu_endereco').val());
		$('#usu_entnumero').val($('#usu_numero').val());
		$('#usu_entcomplemento').val($('#usu_complemento').val());
		$('#usu_entbairro').val($('#usu_bairro').val());
		$('#usu_entcidade').val($('#usu_cidade').val());
		$('#usu_entestado').val($('#usu_estado').val());
	}
}


function checaprod(situacao,valor) {
	var olax = '';
	var tot = 0;
	for (count = 0; count < listapro.length; count++) {
		if (listapro[count] == '1') {
			tot++;
		}
	}
	if (tot>=3 && situacao)	{
		$('#pro_'+valor).attr('checked',false);
		alert("Selecione apenas 3 produtos");
		return true;
	}
	if (situacao==true) {
		listapro[valor] = '1';
	} else {
		delete(listapro[valor]);
	}
	for (count = 0; count < listapro.length; count++) {
		if (listapro[count] == '1') {
			olax = olax+'-'+count;
		}
	}
	$('#usu_desejo').val(olax);
}

function apenasNumero(objCampo,e) {
	var scan	= getKey(e);
	var tecla	= String.fromCharCode(scan);
	var mask	= "0123456789"
	if (scan == 13 || scan == 8 || scan == 0) return true;
	if (mask.indexOf(tecla) == -1) {
		return false;
	}
	return true;
}

function apenasValor(objCampo,e) {
	var scan	= getKey(e);
	var tecla	= String.fromCharCode(scan);
	var mask	= "0123456789."
	if (scan == 13 || scan == 8 || scan == 0) return true;
	if (mask.indexOf(tecla) == -1) {
		return false;
	}
	return true;
}
function getKey(e)
{
	return (window.event) ? event.keyCode : e.which
}

function verificacupom() {
	if ($('#cupom').val().length==18) {
		return true;
	} else {
		alert('Preencha o código do Cupom de Desconto corretamente');
		return false;
	}
}

function trocapadraocad (tipo) {
	if (tipo=='fisica') {
		$('#cadastro').attr('class','cad_fisica');
		$('#titendereco').html('Meu Endere&ccedil;o');
	} else {
		$('#cadastro').attr('class','cad_juridica');
		$('#titendereco').html('Endere&ccedil;o Comercial');
	}
	getAjax('_meiocadastro.php','tipo='+tipo,'meiocadastro');
}

function checaopcproduto() {
	var ar = $('caixaopcao').getElementsByTagName('input');
	var tem = false;
	for(var i=0; i < ar.length; i++) {
		if(ar[i].checked){ 
			tem = true;
			$('opcid').value = ar[i].value;
		}
	}
	if ($('quant').value<1)	{
		alert("A quantidade deve ser maior que zero"); 
		return false; 
	}
	if(tem == false) { 
		alert("Selecione uma opção do produto!"); 
		return false; 
	} 
	return true;
}

function verificacep() {
	if ($('#cep').val().length==8) {
		return true;
	} else {
		alert('Preencha o CEP corretamente');
		return false;
	}
}

function checaopcpagamento() {
	var boolValid = false;
	var sele;
	$('.opcPagamento').each(function() {
		if ( $(this).is(':checked') ) {
			boolValid = true;
			sele = $(this).val();
		}
	});
	if(boolValid == false) { 
		alert("Selecione uma opção pagamento!"); 
		return false; 
	} 
	if ($('#interface_'+sele).val()=='pgto_visa') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=540");
		window.location="https://www.feitobrasilcosmeticos.com.br/redirecionacbp.php";
	}
	if ($('#interface_'+sele).val()=='pgto_mastercielo') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=540");
		window.location="https://www.feitobrasilcosmeticos.com.br/redirecionacbp.php";
	}
	if ($('#interface_'+sele).val()=='pgto_mastercard') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=780,height=540");
		window.location="aguardemaster.php";
	}
	if ($('#interface_'+sele).val()=='pgto_diners') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=780,height=540");
		window.location="aguardediners.php";
	}
	if ($('#interface_'+sele).val()=='pgto_itaushop') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open('', 'mpg_popup', 'toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');	
		window.location="aguardeitau.php";
	}
	if ($('#interface_'+sele).val()=='pgto_caixadeb') {
		$('#formPgto').attr('target','mpg_popup');
		mpg_popup = window.open('', 'mpg_popup', 'toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');	
		window.location="aguardecaixa.php";
	}

	return true;
}

function popWin(URL,NAME,WIDTH,HEIGHT,RESIZE,SCROLL) {
   winId = window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',resizable='+RESIZE+',scrollbars='+SCROLL+',menubar=no,toolbar=no,location=no,directories=no,status=no');
	var clientWidth = screen.availWidth;
	var clientHeight = screen.availHeight;
	var xPos = (clientWidth - WIDTH)/2;
	var yPos = (clientHeight - HEIGHT)/2;
	winId.moveTo(xPos,yPos);
}

var arrPageSizes = new Array();
var arrPageScroll =  new Array();

function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;}
function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;}

function fechaJAN() {
	$('#jquery-conteudo').html('');
	$('#jquery-overlay,#jquery-lightbox,#jquery-conteudo').fadeOut(function(){$('#jquery-overlay,#jquery-lightbox').remove();});$('embed, object, select').css({'visibility':'visible'});
}

function abreJANx() {
	$('embed, object, select').css({'visibility':'hidden'});
	$('body').append('<div id="jquery-overlay"></div>');
	arrPageSizes = ___getPageSize();
	arrPageScroll = ___getPageScroll();
	$('#jquery-overlay').css({backgroundColor:'#000',opacity:0.8,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();

	$('body').append('<div id="jquery-lightbox"></div><div id="jquery-conteudo"></div>');
	$('#jquery-overlay').click(function(){ fechaJAN(); });
	$('#jquery-lightbox').css({width:'620px',height:'600px',top:arrPageScroll[1]+(arrPageSizes[3]/10),left:(arrPageSizes[2]/2)-3100}).show();
	$('#jquery-conteudo').css({width:'600px',height:'500px',top:(arrPageScroll[1]+(arrPageSizes[3]/10))+20,left:(arrPageSizes[2]/2)-300}).show();
	$.get("revenda_cad.php", function(r){ $("#jquery-conteudo").html(r); });	
}

jQuery(document).ready(function() {
	$("#fancy_dep_ver").fancybox({
		'width'				: 960,
		'height'			: 586,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$("#fancy_dep_enviar").fancybox({
		'width'				: 780,
		'height'			: 340,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
});


