$(document).ready(function(){
	$('#telefone').mask('(99) 9999.9999');
	$('#celular').mask('(99) 9999.9999');
	$('#apli_telefone').mask('(99) 9999.9999');
	$('#apli_celular').mask('(99) 9999.9999');
	$('.telefone').mask('(99) 9999.9999');
	$('.ano').mask('9999');
	var windowWidth = $(window).width();
	if(windowWidth >950){
		//$('body').css('overflow-x','hidden');
	}
	$('#atendimento_online').css('display','none');
})

$(document).load(function(){
	var windowWidth = $(window).width();
	if(windowWidth >950){
		//$('body').css('overflow-x','hidden');
	}
})

function enviaparaurl(combo){
	var url = $('#'+combo).val();
	if(url!=0){
		window.location = 'http://www.nwmidia.com.br/'+url;
	}
}

function trocar(){
	$('#spandoblog').css('color','#fff');
}

function voltar(){
	$('#spandoblog').css('color','#f58220');
}

function check_um_email(mail){
	var total_erros = 0;
	total_erros = check_email($('#'+mail).val());
	return total_erros;
}

function validar_varios_emails(mail){
	var erro = 0;
	emails = $('#'+mail).val();
	var ret = emails.replace(/,/g, ";")
	ret = ret.replace(/ /g, "");
	var aemail = ret.split(";");
	var totalerros = 0;
	for (var i = 0; i < aemail.length; i++) {
		totalerros += check_email(aemail[i]);
	}
	return totalerros;
}

function check_email(mail){
	var erro = 0;
	demail = mail.split("@");
	if(demail.length==2){
		if(demail[0].length>=2){
			dominio = demail[1].split(".");
			if(dominio.length == 2){
				if((dominio[0].length>1) && ((dominio[1].length==3)||(dominio[1].length==2))){
					erro = 0;
				}else{
					erro = 1;
				}
			}else{
				if(dominio.length == 3){
					if((dominio[0].length>1) && ((dominio[1].length==3)||(dominio[1].length==2)) && (dominio[2].length==2)){
						erro = 0;
					}else{
						erro = 1;
					}
				}else{
					erro = 1;
				}
			}
			
		}else{
			erro = 1;
		}
	}else{
		erro = 1;
	}
	return erro;
};

function post(arquivo,form,div){
	$('#'+div).fadeIn();
	$('#'+div).html('<img src="http://www.nwmidia.com.br/imagens/load.gif" alt="" />');
	var serializeDados = $('#'+form).serializeArray();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: serializeDados,
		type: 'POST',
		success: function(data, textStatus) {
			$('#'+div).html('');
			var retorno = data.split('|',3);
			if(retorno[0].length >=  1){
				if(retorno[0]=='I'){
					alert(retorno[1]);
					$('#'+form)[0].reset();
				}else{
					if(retorno[0]!='A'){
						alert(retorno[2]);
						$('#'+div).html('');
						$('#'+retorno[1]).focus();
					}else{
						alert(retorno[1]);
						window.location = '/franquia-marketing-digital';
					}
				}
			}
		},
	});
}

function franquia(arquivo,form,div){
	$('#'+div).fadeIn();
	$('#'+div).html('<img src="http://www.nwmidia.com.br/imagens/load.gif" alt="" />');
	var serializeDados = $('#'+form).serializeArray();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: serializeDados,
		type: 'POST',
		success: function(data, textStatus) {
			$('#'+div).html('');
			var retorno = data.split('|',3);
			if(retorno[0].length >=  1){
				if(retorno[0]=='I'){
					alert(retorno[1]);
					$('#'+form)[0].reset();
					window.location = '/cadastro-de-fraquia-segunda-parte.html';
				}else{
					alert(retorno[2]);
					$('#'+retorno[1]).focus();
				}
			}
		},
	});
}

function carregar_pop(){
	//alert('teste123')
	$('#atendimento_online').toggle(750)
}

function abrir_wc_popup() {
	$('#atendimento_online').toggle(750);
	window.open('https://nwmidia.webchatlw.com.br/clients/emailContact', 'Atendimento_por_email', 'menubar=no,width=510,height=570,toolbar=no,resizable=no');
}

function fechar_a_div(div){
	$('#'+div).fadeOut();
}

setTimeout("carregar_pop()",90000)
