// Function scripts
document.onmousedown=noRightClick
document.onkeydown=keyWhat;
function noRightClick(b) {
  if(((navigator.appName=="Microsoft Internet Explorer")&&(event.button > 1))
  ||((navigator.appName=="Netscape")&&(b.which > 1))){
  alert('Direitos Autorais Reservados - LC3');
  return false;
  }
}
function keyWhat(e){
   if (navigator.appName == 'Microsoft Internet Explorer') {                 
     if(event.keyCode == 17 ||event.keyCode == 18 ){ 
          alert("Direitos Autorais Reservados - LC3");
         return false;
     }
   }
}

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

////////////////////////////////////////////////////////
function activateWaitingMessage (areaID,path) {
  var obj = document.getElementById(areaID);	
  obj.innerHTML = "<img src=\""+path+"imgs/ajax-loader.gif\" >Aguarde...";

}

function opt_slogan (ref) {
var areaID = 'content_slogan';
var page = "modulos/show_slogan.php?reload=true&ref="+ref;
  var str = "";
  activateWaitingMessage (areaID,"../../");
  processajax ("GET",page,areaID, "");
}
function conteudo (areaID, content_file) {
var page = "conteudo/"+content_file;
  var str = "";
  activateWaitingMessage (areaID,"");
  processajax ("GET",page,areaID, "");
}

function checklogin () {
 var login = Trim(document.loginform.loginname.value);
 var senha = Trim(document.loginform.loginsenha.value);
 var msgusr = "";
 var erro = false;
 if (login == ""){erro=true; msgusr = msgusr+">>Campo login não preenchido \n";}
 if (senha == ""){erro=true; msgusr = msgusr+">>Campo senha não preenchido \n";}
 if (erro) {
  	alert(msgusr);
 }else {
	document.loginform.submit();
 }
}
//////////////////////////////////////
// CONTATO / EMAIL
//////////////////////////////////////
function review_Email(email_in){
var email_out = email_in;
  if (email_out.indexOf("@hotmail.com.br") >= 0) {
     // O E-mail HOTMAIL não termina com .BR
	email_out = email_out.replace("hotmail.com.br", "hotmail.com");
  }

  if (email_out.indexOf("@aol.com.br") >= 0) {
		// O E-mail AOL não termina com .BR
		email_out = email_out.replace("aol.com.br", "aol.com");
  }
  
  if (email_out.indexOf(" ") >= 0){
		// E-mail não deve conter espaços em branco
 		while(email_out.indexOf(" ") >= 0) 
			email_out = email_out.replace(" ", "");
  }
  email_out = email_out.replace("/", "");
  email_out = email_out.replace("@.", "@");
  email_out = email_out.replace(".@", "@");
  email_out = email_out.replace(",", ".");
  email_out = email_out.replace(";", ".");
  
  return email_out;
}

function is_email(email_in){
var email = email_in;
 if (   (email.indexOf("@") <= 0) || 
		(email.indexOf(".") <=0)  || 
	  ( (email.length) == (email.indexOf(".")+1) ) ){
	 return false;
 }else {
  return true;
 }
}

//Mostra Formulário para Envio de Email (contato)
function validformcontato(theform, serverPage, areaID) {
var erro = false;
 var msg_err = "ERRO IDENTIFICADO:  \n\n";

	var nome = Trim(document.formcont.nome.value);
	var phone = Trim(document.formcont.phone.value);
	var email = Trim(document.formcont.email.value);
	var mess = Trim(document.formcont.msg.value);

    if (nome == "") {erro = true; msg_err  = msg_err+ ">> Campo NOME em branco \n";}
    email = review_Email(email);
	if (!(email_valido = is_email(email))) { erro = true; msg_err = msg_err + ">> Email incorreto \n";}
    if (phone == "") {erro = true; msg_err  = msg_err+ ">> Campo TELEFONE em branco \n";}
    if (mess == "") {erro = true; msg_err  = msg_err+ ">> Campo MENSAGEM em branco \n";}

   if (!erro) {
  	   var answer = confirm("Confirma envio dos dados ?");
	   if (answer) {
			var str = getformvalues(theform);
			processajax ("POST",serverPage, areaID, str);
	   }else {
   		    alert("Mensagem não enviada.");
	   }
   }else { alert (msg_err); }
}

function sendFormulario(){
var msg_usr = "";
var nlinhas = 1;
var erro = false;
var areaID = 'formcontarea';
var msg_usr = "POR FAVOR CORRIGIR OS CAMPOS  <br>";
	var nome = Trim(document.formcont.nome.value);
	var phone = Trim(document.formcont.phone.value);
	var email = Trim(document.formcont.email.value);
	var msg = Trim(document.formcont.msg.value);

    if (nome == "") {erro = true;nlinhas++; msg_usr  = msg_usr+ ">> Campo NOME em branco  <br>";}
    email = review_Email(email);
	if (!(email_valido = is_email(email))) { erro = true;nlinhas++; msg_usr += ">> Email incorreto  <br>";}
    if (phone == "") {erro = true;nlinhas++; msg_usr  += ">> Campo TELEFONE em branco <br>";}

    if (msg == "") {erro = true;nlinhas++; msg_usr  += ">> Campo MENSAGEM em branco <br>";}

    if (!erro) {
	        var theform = document.getElementById('formcont');
			var str = getformvalues(theform);
            var serverPage = "enviar_email.php";
            activateWaitingMessage('formcontarea',"");
			processajax ("POST",serverPage, areaID, str);
    }else {
      //  alert (msg_err);
        var areaAlert ='pnlalert';
        if (nlinhas == 2)nlinhas=3;
        openAlertaWin ('300',nlinhas,areaAlert,'emailid');
        activateWaitingMessage (areaAlert,"")
        var serverpage = "base/alerta.php?nli="+nlinhas+"&msg="+msg_usr;
        processajax ("GET",serverpage,areaAlert,"");
    }


}
