// VALIDAÇÃO DE FORMS
function isEmpty( str){
	regexp = '^[\s ]*$';
	if (str.value.search(regexp) == -1)	{ 
		return false;
	} else {
		return true;
	}
}

function notValidEmail( str ){
	regexp = '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$';
	if (str.value.search(regexp) == -1)	{ 
		return true;
	} else {
		return false;
	}	
}

function notChecked( box ){
    if( box.checked ){
        return false;
    }
    else{
        return true;
    }
}



function troca(id){
var img_id = 'img_' + (id); 

	if (document.getElementById)
	{
		if(document.getElementById(id).style.display == 'none')
		{
		   document.getElementById(id).style.display = 'block';
		   if(document.getElementById(img_id)){
			   document.getElementById(img_id).src="/images/ico_menos.gif";
		   }	   

		} else 
		{
		   document.getElementById(id).style.display = 'none';
		   if(document.getElementById(img_id)){
			   document.getElementById(img_id).src="/images/ico_mais.gif";
		   }

		}
		
		return false;
	}
}
				


function moveTam(campo,limite,proximo)
{
	if(document.getElementById(campo).value.length==limite){
		document.getElementById(proximo).focus();
	}
}

function limitaTam(limitField, limitNum) {

	if (limitField.value.length > limitNum) {

		limitField.value = limitField.value.substring(0, limitNum);

	}
}


function formataValor(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	s = s.split(".").join(",");
	return s;
}

function ajuda(texto){
	$('ajuda').innerHTML = texto;
}

function in_array(myValue,myArray) {
    function equals(a,b) {
        return (a === b);
    }

    for (var i in myArray) {
        if (equals(myArray[i],myValue))
            return true;
    }

    return false;
}

function enviaComentario( ){
	
	var form = document.getElementById('formComentario');

	if( isEmpty( form.nome ) ){
		alert( 'Por favor, complete o campo nome.' );
		document.formComentario.nome.focus();
		return false;
	}


	if( isEmpty( form.comentario ) ){
		alert( 'Por favor, complete o campo comentário.' );
		document.formComentario.comentario.focus();										
		return false;
	}
	
	
	if( notValidEmail( form.email ) ){
		alert( 'O endereço de e-mail especificado não é válido.' );
		document.formComentario.email.focus();										
		return false;
	}

	document.formComentario.submit();
}





