document.write('<OBJECT ID="AgentControl" width=0 height=0 CLASSID="CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F" \n');
document.write(' CODEBASE="#VERSION=2,0,0,0"><br> \n');
document.write('</OBJECT><br> \n');
document.write('<OBJECT ID="TruVoice" width=0 height=0 \n');
document.write(' CLASSID="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575" \n');
document.write(' CODEBASE="#VERSION=6,0,0,0"> \n');
document.write('</OBJECT>');


var Merlin;

// Vars
var UsedChars;
var MerlinID;
var MerlinACS;
var MerlinLoaded;
var LoadReq;
var HideReq;
var MerlinLeftX, MerlinCenterX, MerlinRightX;
var MerlinTopY, MerlinCenterY, MerlinBottomY;

// Ini
UsedChars = "Merlin";

// Merlin
MerlinID = "Merlin";
MerlinACS = "merlin.acs";
MerlinLoaded = false;


OnLoad();


function OnLoad() {



		AgentControl.Connected = true;

		MerlinLoaded = LoadLocalChar(MerlinID, MerlinACS);

		if (!MerlinLoaded) {
			
			MerlinLoaded = LoadLocalChar(MerlinID, "");
		}

		if (MerlinLoaded) {
			SetCharObj();
		}
		Load();
}

function LoadLocalChar(CharID, CharACS) {

    AgentControl.RaiseRequestErrors = false;
    if (CharACS == "") {

        LoadReq = AgentControl.Characters.Load(CharID);
    }
    else {
        LoadReq = AgentControl.Characters.Load(CharID, CharACS);
    }
    AgentControl.RaiseRequestErrors = true;

    if (LoadReq.Status != 1) {
        return(true);
    }
    return(false);
}

function SetCharObj() {

    Merlin = AgentControl.Characters.Character(MerlinID);
    Merlin.LanguageID = 0x409;
}

function Load() {

    if (!MerlinLoaded) {
        LoadError();
        return(false);
    }

    window.status = "";
    Begin();
    return(true);
}

function LoadError() {
    //var strMsg;
    //window.status = "";
    //strMsg = "Error cargando el Agente: " + MerlinID + "\n";
    //strMsg = strMsg + "Necesita instalar el muneco:\n";
    //strMsg = strMsg + UsedChars;
    //alert(strMsg);
}

function Position() {
    var ScreenWidth = window.screen.width;
    var ScreenHeight = window.screen.height;

    if ((ScreenWidth == 0) || (ScreenHeight == 0)) {
        ScreenWidth = 800;
        ScreenHeight = 600;
    }

    MerlinCenterX = (parseInt(ScreenWidth / 2) - parseInt(Merlin.Width / 2));
    MerlinRightX = (ScreenWidth - Merlin.Width);
    MerlinCenterY = (parseInt(ScreenHeight / 2) - parseInt(Merlin.Height / 2));
    MerlinBottomY = (ScreenHeight - Merlin.Height);
}

function Begin() {

	//Position();
    Merlin.Show();
    Merlin.MoveTo(MerlinRightX, MerlinBottomY);
    //Merlin.Hide();
	//Merlin.Show();
	//Merlin.Speak("Hello");
	//Merlin.Hide();

}
function Say(texto) {

    Merlin.Speak(texto);


}




