/**
 *   Todas estas funciones son llamadas desde Flash con FSCOMMAND,
 *   por lo cual deben tener un único argumento de tipo cadena
 */

/**
 *   Funciones llamadas desde la pelicula Flash
 */

function viewSourceCode( foo ){
	var sourceCode = document.theMovie.GetVariable("theSourceCode");
	var w = window.open("about:blank","sourceCodeWindow","");
	w.document.open();
	w.document.write( "<tt>" );
	w.document.write( sourceCode );
	w.document.write( "<\/tt>" );
	w.document.close();
}

/**
 *   Cambia el tamaño y color de fondo de la película Flash
 */
function setCanvasLook( foo ){
	var nWidth = Number( document.theMovie.GetVariable("canvasWidth") );
	var nHeight = Number( document.theMovie.GetVariable("canvasHeight") );
	var sColor = document.theMovie.GetVariable("canvasBgColor");

	// Tamaño
	// cambio de <object width=80 height=100 ...>
	var obj = document.getElementById("theMovie");
	if( obj ){
		if( obj.getAttribute("width")!=nWidth ){
			obj.setAttribute("width",nWidth);
		}
		if( obj.getAttribute("height")!=nHeight ){
			obj.setAttribute("height",nHeight);
		}
	}
	// cambio de <embed width=80 height=100 ...>
	obj = document.getElementById("theMovieEmbed");
	if( obj ){
		if( obj.getAttribute("width")!=nWidth ){
			obj.setAttribute("width",nWidth);
		}
		if( obj.getAttribute("height")!=nHeight ){
			obj.setAttribute("height",nHeight);
		}
	}
	// Color de fondo
	// cambio de <param name=bgcolor value=#ffffff>
	obj = document.getElementById("theMovieBgcolor");
	if( obj && obj.getAttribute("value")!=sColor ){
		obj.setAttribute("value",sColor);
	}
	// cambio de <embed bgcolor=#ffffff ...>
	obj = document.getElementById("theMovieEmbed");
	if( obj && obj.getAttribute("bgcolor")!=sColor ){
		obj.setAttribute("bgcolor",sColor);
	}
}

/**
 *   Establece el título de la página
 */
function setTitle( sTitle ){
	document.title = sTitle;
}

/**
 *  Muestra un mensaje al usuario
 */
function showMessage( message ){
    alert( message );
}

/**
 *  Establece el mensaje de la barra de estado
 */
function showStatusMessage( message ){
	// En Mozilla no funcina en la configuración
	// por defecto. Hace falta permitir a los
	// scripts "cambiar texto de la barra de estado"
	// en la configuración (Javascript avanzado)

	// FIXME: Desactivado temporalmente porque salen tags
 	//   window.status = message;
}

/**
 *   Muestra un mensaje de error e invita a recargar
 *   la página
 **/
function showError404( sMessage ){
	var divItem = document.createElement("div");
	var contentStr = '<center><div class="error404">'+
		'No ha sido posible cargar todos los elementos de la p&aacute;gina. <br /><br />'+
		'<i>(' + sMessage + ')</i><br /><br />'+
		'&iquest;<a href="javascript:hideError404()">Ignorar</a>, '+
		'<a href="javascript:document.location.reload()">Recargar</a> o '+
		'<a href="javascript:createCookie(\'visualMode\',\'XHTML\');document.location.reload()">'+
		'Ver la versi&oacute;n HTML</a>? <br /><br />'+
		'</div></center>';
	divItem.innerHTML = contentStr;
	document.body.insertBefore( divItem, document.body.firstChild );
}

/** Oculta el mensaje anterior */
function hideError404(){
	// FIXME: error-prone, firstChild podría ser otro; usar getElementById
	document.body.removeChild( document.body.firstChild );
}


