var limit = 600 ;

function count_chars ( textarea ) {
	if ( textarea.value.length > limit ) {
		textarea.value = textarea.value.substring ( 0 , limit ) ;
		alert ( limit + " caracteres são permitidos." ) ;
		return false ;
	}
	return true ;
}

function valida ( frm ) {
	// valida textarea.
	if ( !count_chars( frm.message ) ){
		return false ;
	}
	var campos = frm.elements.length ;

	for ( var i = 0 ; i < campos ; i++ ) {
		if ( frm.elements[i].type != "hidden" ) {
			if ( frm.elements[i].value == "" ){
				alert ( "Por favor, preencha todos os campos." ) ;
				return false ;
			}
		}
		if ( frm.elements[i].name == "texto" && frm.elements[i].value.length > limit ) {
			alert ( "O texto não deve ter mais que " + limit + " caracteres." ) ;
			return false ;
		}
	}
	return true ;
}

function printMe () {
	if ( window.print ) {
		window.print () ;
	}
}

function change_cookie ( obj ) {
	all_cookies = new String( unescape( document.cookie ) ) ;

	var now = new Date();
	now.setFullYear( now.getFullYear() + 10 );
	var my_cookie = "";
	var prefix = "";
	var sufix = "";

	if( all_cookies.indexOf( cookie_name ) != -1 ){
		var cookies = all_cookies.substr( all_cookies.indexOf( cookie_name ) + cookie_name.length ) ;

		if ( cookies.indexOf( ";" ) != -1 ){
			my_cookie = cookies.substr( 0 , cookies.indexOf( ";" ) ) ;
		}
		else{
			my_cookie = cookies ;
		}

		prefix = all_cookies.substr( 0 , all_cookies.indexOf( cookie_name ) ) ;
		sufix = all_cookies.substr( all_cookies.indexOf( my_cookie ) + my_cookie.length + 1 ) ;
		my_cookie = my_cookie.substr( my_cookie.indexOf( "=" ) + 1 ) ;

		if( obj.checked ){
			my_cookie += obj.value + "|" ;
		}
		else{
			my_cookie = my_cookie.replace( obj.value , "" ) ;
			my_cookie = my_cookie.replace( /\|\|+/ , "\|" ) ;
		}
	}
	else{
		prefix = all_cookies ;
		my_cookie += obj.value + "|" ;
	}

	if( prefix.lastIndexOf( ";" ) != ( prefix.length - 1 ) && prefix != "" )
		prefix += ";" ;
	if( sufix.lastIndexOf( ";" ) != ( sufix.length - 1 ) && sufix != "" )
		sufix += ";" ;

	all_cookies = cookie_name + "=" + escape( my_cookie ) + "; " + prefix + sufix + "path=/; domain=" + cookie_domain + "; expires=" + now.toGMTString() ;
	document.cookie = all_cookies ;

	if( obj.checked ){
		alert( "Anúncio incluído" ) ;
	}
	else{
		if( location.href.indexOf( "selecao" ) > -1 ){
			history.go(0) ;
		}
	}
}