//<![CDATA[
function scroll_down(div) {
	var obj = document.getElementById(div);
	obj.scrollTop += 5;
}

function scroll_up(div) {
	var obj = document.getElementById(div);
	obj.scrollTop -= 5;
}

function descer(div){
	tempo = window.setInterval(function(){ scroll_down(div); }, 100);
}


function subir(div){
	tempo = window.setInterval(function(){ scroll_up(div); }, 100);
}

function parar_scroll(){
	window.clearInterval(tempo);
}
	
function campo_focus(campo, force_clear) {
	if (force_clear) {
		campo.value = '';
	}
	campo.select();
}

// Array.unique( strict ) - Remove duplicate values
function remove_duplicated(b, array) {
 var a = new Array();
 var i = 0;
 var l = array.length;
 for( i=0; i<l; i++ ) {
	if( a.indexOf( array[i], 0, b ) < 0 ) {
		a.push(array[i]);
	}
 }
 return a;
};

var a_palavras = new Array();
function adicionar_palavra(box, palavra, textfield) {
	var class_atual = box.className;
	var campo = document.getElementById(textfield);
	if (class_atual != 'clicado') {
		var elem = document.getElementById('palavras');
		var myDiv = document.getElementById( "palavras" );
		var aArr = myDiv.getElementsByTagName( "a" );
			for(var i = 0; i < aArr.length; i++)
			{
				aArr[i].className = 'desclicado';
			} 
		box.className='clicado';
		remover_todas_palavras();
		a_palavras.push(palavra);
		//a_palavras = remove_duplicated(palavra, a_palavras);
		campo.value = a_palavras;
	} else {
		remover_palavra(box, palavra, textfield);
	}	
}
function remover_todas_palavras() {
	a_palavras = new Array();
}
var last_frase = null;
function adicionar_frase(box, palavras, textfield) {
	var class_atual = box.className;
	var campo = document.getElementById(textfield);
	if (last_frase != null) {
		remover_frase(last_frase, textfield);
	}
	last_frase = box;
	box.className='clicado';
	campo.value = palavras;
}
function remover_frase(box, textfield) {
	box.className = 'desclicado';
	var campo = document.getElementById(textfield);
	campo.value = '';
}
function add_frase_unica(frase, textfield) {
	var campo = document.getElementById(textfield);
	campo.value = frase;
}

function remover_palavra(box, palavra, textfield) {
	box.className = 'desclicado';
	var a = new Array();
	var i = 0;
	var tamanho = a_palavras.length;
	var campo = document.getElementById(textfield);
	campo.value = removeItem(a_palavras, palavra);
}

function detectItem(originalArray, itemToDetect) {
	var j = 0;
	while (j < originalArray.length) {
		if (originalArray[j] == itemToDetect) {
			return true;
		} else { j++; }
	}
	return false;
}

//remove item (string or number) from an array
function removeItem(originalArray, itemToRemove) {
	var j = 0;
	while (j < originalArray.length) {
		// alert(originalArray[j]);
		if (originalArray[j] == itemToRemove) {
			originalArray.splice(j, 1);
		} else { j++; }
	}
	// assert('hi');
	return originalArray;
}
	//]]>




<!--
/************************************************************
// Nome do script: Turbano formulário
// Autor: Thomas Gonzalez Miranda ( thomasgm@php.net )
// Ambiente: Multi-plataforma
// Data da criação: 02/04/2004
// Data da última modificação: 02/04/2004
// Descrição: A criação deste script visa criar um validador de formulário que valide qualquer 
// tipo de dado que um formulário para web possa contar. O script foi feito para rodar em navegadores que tem ou  
// não suporte à JavaScript.
************************************************************/

function validarNumero(campo, msg, min, max) {
if (!min) { min = 0 }
if (!max) { max = 255 }
msg = msg.split('|');
if ((parseInt(campo.value) != campo.value) || campo.value.length < min || campo.value.length > max) {
if (campo.value.length < min || campo.value.length > max) {
	alert(msg[0]);
} else {
	alert(msg[1]);
}
campo.focus();
campo.select();
return false;
}

return true;
}

function validarString(campo, msg, min, max, padrao) { 
if (!min) { min = 1 }
if (!max) { max = 65535 }
msg = msg.split('|');
if (campo.value == padrao)
	{
		//alert(msg[0]);
		//campo.focus();
		//campo.select();
		return false;
	}
if (!campo.value || campo.value.length < min ||  campo.value.length > max) {
if (campo.value == '') {
	//alert(msg[0]);
} else {
	//alert(msg[1]);
}
//campo.focus();
//campo.select();
return false;
}

return true;
}

function validarEmail(email, msg, opcional) { 
if (!email.value && opcional) { 
return true; 
} 

var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
if (!re_mail.test(email.value)) { 
//alert(msg); 
//email.focus(); 
//email.select(); 
return false; 
} 

return true; 
}

function limitarCampo(campo, countcampo, limitemaximo) {
	if (campo.value.length > limitemaximo) {
		campo.value = campo.value.substring(0, limitemaximo);
	} else {
		countcampo.value = limitemaximo - campo.value.length;
	}
}

function validarCheckBox(checkbox, msg) {
	if (!checkbox.checked) {
		alert(msg);
		checkbox.focus();
		return false;
	}
	return true;
}

function validarSenha(campo1, campo2) {
if (campo1.value == '' || campo2.value == '') {
	return false;
}
if (campo1.value != campo2.value) {
	return false;
}
	return true;
}

function campo_focus(campo, force_clear) {
	if (force_clear) {
		campo.value = '';
	}
	campo.select();
}
// -->
