
function trim( inputString ) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while ( ch == " " ) { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}

	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}

	// Tira os &nbsp; e os <br /> do começo da string
	var re = /^(&nbsp;|<br \/>| <br \/>|\n|\s)*(.*)$/;
	var matchArray = re.exec( retValue );

	if ( matchArray )
		return matchArray[2]; // Return the trimmed string back to the user
	else
		return retValue;
} // Ends the "trim" function


/**
FUNCAO QUE VALIDA O FORMULARIO DO FALE CONOSCO
**/
function enviarFormularioContato(){
   
   var objForm     = document.getElementById('formContato');
   var objNome     = document.getElementById('txtNome');
   var objMail     = document.getElementById('txtMail');
   var objFone     = document.getElementById('txtTelefone');
   var objCidade   = document.getElementById('txtCidade');
   var objMensagem = document.getElementById('txtMensagem');
   
   // valida os campos (Nome, Msg e email sao obrigatórios)
   if(trim(objNome.value) == '') {
	   alert("O campo nome não está preenchido corretamente.");
	   objNome.focus();
	   return;
   }
   
   if(trim(objMail.value) == ''){
	   alert("O campo e-mail não está preenchido corretamente.");
	   objMail.focus();
	   return;
   } 
   
   if(trim(objMensagem.value) == ''){
	   alert("O campo mensagem não está preenchido corretamente.");
	   objMensagem.focus();
	   return;
   }
   
   
   objFone.value = trim(objFone.value);
   objCidade.value = trim(objCidade.value);
   
   objForm.submit();   
}


var imgAtual = '';
var idAtual = '';

function SS_trocarImagem(id, botaoAlternativo){
    var objImg = document.getElementById(id);
	
	idAtual  = id;
	imgAtual = objImg.src;
	
	objImg.src=botaoAlternativo;
}

function SS_restoreImagem(){
	var objImg  = document.getElementById(idAtual);
	objImg.src = imgAtual;
	
	imgAtual = '';
	idAtual  = '';
}

// FUNCOES QUE GERENCIAM AS DIVS.....
var divAberta = "";

function setDivAbertaInicio( id ){
	var objInicial = document.getElementById( id );
	divAberta = id;
	objInicial.style.display = "inline";
}

function mostrarDiv( id ){
	var objAtual = document.getElementById( divAberta );
	var objAbrir = document.getElementById( id );
	
	divAberta = id;

	objAtual.style.display = "none";
	objAbrir.style.display = "inline";
}


function mostraImagemModal( imagem, largura, altura ){
	
	altura = altura + 30;
	largura = largura + 18;
	
	Modalbox.show( 'imagem.php?imagem=' + imagem, {title: 'Destaques', width: largura, height:altura});
	//Modalbox.show('<div class=\'imagem\'><p>Are you sure to delete this item?</p> <input type=\'button\' value=\'Yes, delete!\' onclick=\'Modalbox.hide()\' /> or <input type=\'button\' value=\'No, leave it!\' onclick=\'Modalbox.hide()\' /></div>', {title: this.title, width: 300});
}
