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

////////////////////////////////////////////////////////
// Function scripts
function conteudo(page,path_info) {
//  set_path_info (path_info);
  var serverPage = page;
  var areaID = "main";
  var str = "";
  processajax ("GET",serverPage,areaID, "");
}

//Conteudo para produto
function prodContent(page,path) {
  var serverPage = path+'conteudo/produtos/'+page+'.php?realod=true&ph='+path;
  var areaID = "contentID";
  var str = "";
  processajax ("GET",serverPage,areaID, "");
}
function show_main (file) {
 var serverPage = "conteudo/produtos/"+file;
  var areaID = "main";
  var str = "";
  processajax ("GET",serverPage,areaID, "");
}
function show_main_img (file) {
 var serverPage = "imgs/"+file;
  var areaID = "main";
  var str = "";
  processajax ("GET",serverPage,areaID, "");
}

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 = "";
	var nome = Trim(document.formcont.nome.value);
	var email = Trim(document.formcont.email.value);
	var assunto = Trim(document.formcont.assunto.value);
	var mess = Trim(document.formcont.msg.value);
	var phone = Trim(document.formcont.phone.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 (assunto == "") {erro = true; msg_err  = msg_err+ ">> Campo ASSUNTO 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 next_result () {
var result_ref = parseInt(document.getElementById("result_refID").value);
var max_foto = parseInt (document.getElementById("max_fotoID").value);

if (result_ref == max_foto) {
   result_ref = 1;
}else {
   result_ref = result_ref + 1;	
}

document.getElementById("result_refID").value = result_ref;
var obj = document.getElementById("perder-peso-resultado");
obj.innerHTML = "<img src=\"resultados/img"+result_ref+".gif\">";

}
