// JavaScript Document
jQuery.noConflict();

function corretorOnLine(idform){
	var msgErro ="";
	var form = document.getElementById(idform);
	var nome = form.col_nome.value;
	var email = form.col_email.value;

	if(nome==""){
		msgErro ="<p>-Seu Nome</p>";
	}

	if(!checkMail(email)){
		msgErro +="<p>-Email válido</p>";
	}

	if(msgErro != ""){
		mensagemErro("<p>Por favor, informe:</p>"+msgErro+"<p>Capa Engenharia</p>");
		return false;
	} else{
		window.open("http://www.aspserver.divex.com.br/smartweb/bitpress/PainelDeControle/SmartSuport/chat_capa/ProcEntradaUser.asp?cod_empresa=2&txtIdentificador="+nome+"&txtEmail="+email,"suporte","width=431,height=430");
		fecharPopUpCorretor();
		return true;
	}
}

var esconder = function(){
	$("divEsconde").style.display = "none";
	$("divMsg").style.display = "none";  
}

function fecharPopUp(){
	$("divEsconde").style.display = "none";
	$("divMsg").style.display = "none";  
	$("divMsg").style.height = "auto";
	try{
		jQuery("#testeesconde").show();
	} catch(e){}
	return false;
}
function fecharPopUpCorretor(){
	$("divEsconde").style.display = "none";
	$("divCorretorOnLine").style.display = "none";  
	$("divCorretorOnLine").style.height = "auto";
	try{
		jQuery("#testeesconde").show();
	} catch(e){}
	return false;
}
function formCorretorOnLine(){
	jQuery("#divCorretorOnLine").css("top","100px");
	jQuery("#divCorretorOnLine").width("400px");
	jQuery("#divEsconde").height(jQuery(document).height());
	jQuery("#divCorretorOnLine").css("margin","0 0 0 -200px");
	jQuery("#divCorretorOnLine").css("background", "none");
	try{
	jQuery("#testeesconde").hide();
	} catch(e){}

	$("divEsconde").style.display = "block";
	$("divCorretorOnLine").style.display = "block";

}


function buscarConteudo(codConteudo){
	jQuery("#divMsg").css("top","120px");
	jQuery("#divMsg").width("720px");
	//jQuery("#divMsg").height("500px");
	jQuery("#divEsconde").height(jQuery(document).height());
	jQuery("#divMsg").css("margin","0 0 0 -360px");
	jQuery("#divMsg").css("background", "#FFFFFF");
	
	jQuery("#divEsconde").show();
	jQuery("#divMsg").show();
	jQuery("#divMsg").html("<img src='../_img/loading.gif' /><br />Carregando...");

	jQuery.post("../ajax/buscarConteudo.php",{codConteudo:codConteudo},function(retorno){
		jQuery("#divMsg").html(retorno);
	});

	jQuery(document).ajaxError(function(event, request, settings){
		mensagemErro("Desculpe. Não foi possível buscar o conteúdo. Tente novamente mais tarde.")
		window.setTimeout(esconder, 3000);
	});
}


function mensagemErro(msgErro, srcbg){
	if(srcbg == undefined){
		srcbg = "../../_img/bg_mensagem.jpg";
	}
	var arrayPageScroll = document.viewport.getScrollOffsets();

	//var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 12);
	var lightboxTop =  arrayPageScroll[1] + 50;
	//var lightboxLeft = arrayPageScroll[0];

	msgErro = "<div id='div_header_msg'><a href='#' onclick='return fecharPopUp();' class='enviar_formnews'>Fechar</a></div>"+msgErro+"<p>&nbsp;</p>";
	jQuery("#divMsg").css("top",lightboxTop+"px");
	jQuery("#divMsg").width("400px");
	jQuery("#divEsconde").height(jQuery(document).height());
	jQuery("#divMsg").css("margin","0 0 0 -200px");
	jQuery("#divMsg").css("color","#fff");
	jQuery("#divMsg").css("background", "#006633 url('"+srcbg+"') repeat-x");
	try{
	jQuery("#testeesconde").hide();
	} catch(e){}
	jQuery("#divMsg").html(msgErro);
	jQuery("#divEsconde").show();
	jQuery("#divMsg").show();
	//window.location.href = "#";
}

function playerVideo(pathvideo){
	jQuery("#divMsg").css("top","120px");
	jQuery("#divMsg").width("600px");
	jQuery("#divMsg").height("500px");
	jQuery("#divEsconde").height(jQuery(document).height());
	jQuery("#divMsg").css("margin","0 0 0 -300px");
	jQuery("#divMsg").css("background", "none");

	$("divMsg").innerHTML = '<center><a href="#" onclick="return fecharPopUp();">[Fechar]</a><embed src="'+pathvideo+'" height="450px" width="580px"/></center>';
	$("divEsconde").style.display = "block";
	$("divMsg").style.display = "block";
}

function abreFrame(srcframe){
	jQuery("#divMsg").css("top","50px");
	jQuery("#divMsg").width("950px");
	jQuery("#divMsg").height("480px");
	jQuery("#divEsconde").height(jQuery(document).height());
	jQuery("#divEsconde").width(jQuery(document).width());
	jQuery("#divMsg").css("margin","0 0 0 -490px");
	jQuery("#divMsg").css("background", "#ffffff");
	$("divMsg").innerHTML = '<div class="fechar_maps"><a href="#" onclick="return fecharPopUp();"><img src="../../_img/bt_fechar_maps.gif" border="0" /></a></div><iframe src="'+srcframe+'" width="950" height="530" frameborder="0"  scrolling="auto"/>';
	$("divEsconde").style.display = "block";
	$("divMsg").style.display = "block";
}

/*********************************
VALIDA EMAIL
*********************************/
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function Trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}

function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;
 
 		case 'CEP' :
			if (tam == 6)
				campo.value = s +'-';

		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}


/*********************************
PERMITE SOMENTE NUMEROS NO CAMPO
onkeypress="return somenteNumero(event);"
*********************************/
function somenteNumeros(e) {
	if (!e) e = window.event;
	var tecla;		
	if(e.keyCode)    tecla = e.keyCode;
	else if(e.which) tecla = e.which; //Netscape 4.?	

	if ((tecla > 47 && tecla < 58) || (tecla == 44 && campo.value.indexOf(",") == -1) || (tecla == 8) || (tecla == 9)){
		return true;			
	} else{
		return false;
	}
}


