<HTML>
<HEAD>
<TITLE>Microsoft Out-of-Box Experience</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="stylesheet" TYPE="text/css" HREF="actsetup\aregstyl.css">
<script language=jscript src="oobeutil.js"></script>
<script language=jscript src="dialmgr.js"></script>
<script language=jscript src="error.js"></script>
<script language=jscript src="icsmgr.js"></script>
<script language=jscript>

// This is intended to hold all the script needed
// in the default & offline OOBE HTML pages.
//
// We want to separate the layout (HTML) from the script.
// At the same time, it's helpful to have all the code
// in one place to make it easier to understand the flow
// from page to page.

// Status location constants
var STATUS_MSN = 0;
var STATUS_OEM = 1;
var STATUS_NONE = 2;
var STATUS_OFF = 3;
var STATUS_MAX = 4;
var SNDX_WELCOME = 0;
var SNDX_MSN_ISP = 1;
var SNDX_MSN_REG = 2;
var SNDX_MSN_FINISH = 3;
var SNDX_OEM_REG = 1;
var SNDX_OEM_ISP = 2;
var SNDX_OEM_FINISH = 3;
var SNDX_NONE_REG = 1;
var SNDX_NONE_FINISH = 2;
var SNDX_OFF_EULA = 1;
var SNDX_OFF_PID = 2;
var SNDX_OFF_FINISH = 3;
function CheckPoint(strURL, i1, i2, i3, i4)
{
  this.strURL = strURL;
  this.rgindex = new Array(STATUS_MAX);
  this.rgindex[STATUS_MSN] = i1;
  this.rgindex[STATUS_OEM] = i2;
  this.rgindex[STATUS_NONE] = i3;
  this.rgindex[STATUS_OFF] = i4;
}

// Types of dialing using ISP files. e.g. Dial to registration, ISP, referral server
var CONNECTED_REFFERAL       = 1;
var CONNECTED_ISP_SIGNUP     = 2;
var CONNECTED_ISP_MIGRATE    = 3;
var CONNECTED_REGISTRATION   = 4;


// Checkpoint constants
var CKPT_ACTIV     =         1;
var CKPT_ACTDONE   =         2;
var CKPT_ACTIVERR  =         3;
var CKPT_ACTIVSVC  =         4;
var CKPT_REGISTER1 =         5;
var CKPT_REGISTER3 =         6;
var CKPT_ACTCONN   =         7;
var CKPT_ACTLAN    =         8;
var CKPT_REGDIAL   =         9;
var CKPT_ACT_MSG   =        10;
var CKPT_DONE      =        11;
var CKPT_MAX       =        12;   // ALWAYS set this to be the biggest value!

var CKPT_ISPDIAL =  CKPT_MAX;
var CKPT_REFDIAL =  CKPT_MAX;
var CKPT_MIGDIAL =  CKPT_MAX;
var CKPT_ISPSIGNUP = CKPT_DONE;


var dnCKPT = new Array(CKPT_MAX);

// Checkpoint breadcrumbs
var g_CurrentCKPT = null;
var g_DialCKPT = null;
var HKEY_LOCAL_MACHINE = 0x80000002;
var OOBE_MAIN_REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OOBE";
var CKPT_REG_KEY = "\\CKPT";
var TOS_REG_VALUE = "TOS";

// CheckDialReady errors
var ERR_COMM_NO_ERROR            = 0;
var ERR_COMM_OOBE_COMP_MISSING   = 1;
var ERR_COMM_UNKNOWN             = 2;        // Unknow error, check input parameters
var ERR_COMM_NOMODEM             = 3;        // There is no modem installed
var ERR_COMM_RAS_TCP_NOTINSTALL  = 4;
var ERR_COMM_ISDN                = 5;
var ERR_COMM_PHONE_AND_ISDN      = 6;


// Dialing errors. Look at raserror.h for details
var DERR_DIALTONE           = 680;
var DERR_BUSY               = 676;
var DERR_VOICEANSWER        = 677;
var DERR_NOANSWER           = 678;
var DERR_NO_CARRIER         = 679;
var DERR_HARDWARE_FAILURE   = 630;   // modem turned off
var DERR_PORT_ALREADY_OPEN  = 602;   // procomm/hypertrm/RAS has COM port
var DERR_PORT_OR_DEVICE     = 692;   // got this when hypertrm had the device open -- jmazner
var DERR_PPP_TIMEOUT        = 718;
var DERR_REMOTE_DISCONNECT  = 629;   // Connection interrupted

// Finish errors
var FINISH_OK           = 0x00000000;
var FINISH_REBOOT       = 0x00000001;
var FINISH_BAD_PID      = 0x00000002;
var FINISH_BAD_EULA     = 0x00000004;
var FINISH_BAD_STAMP    = 0x00000008;

// keycode consts
var KeyEsc = 0x1B;
var KeyEnter = 0xD;
var KeyBackSpc = 0x8;
var KeyDelete = 0x2E;
var KeyTab = 0x9;
var KeyDwnArrow = 0x28;
var KeyUpArrow = 0x26;
var KeyLeftArrow = 0x25;
var KeyRightArrow = 0x27;

// Language reboot return codes
var LANGUAGE_REBOOT_NEVER   = 0;
var LANGUAGE_REBOOT_NOW     = 1;
var LANGUAGE_REBOOT_END     = 2;

// on-the-fly button hiding
var HIDE_BACK = 0x0001;
var HIDE_NEXT = 0x0002;
var HIDE_CANCEL = 0x0004;
var HIDE_RESTORE = 0x0008;


// BUGBUG temp GUIDs
var NOLAUNCHISPSIGNUP = "{C37D92A5-CA34-11d2-B71C-00C04F794977}";
var MSNCOMPLETED = "{1C0A22F2-CB6B-11d2-B544-00A0C949DA70}";

// window.external object caches
var TapiObj = null;
var InfoObj = null;
var EulaObj = null;
var LangObj = null;
var PidObj  = null;
var StatusObj = null;
var DirObj = null;
var ApiObj = null;
var RegisterObj = null;

// general globals and status
var g_strISPFile = "";
var g_bStartup;
var g_LastButtonText = null;
var g_FirstFocusElement = null;
var g = null;
var g_SpecialChars = ".'-` ";
var g_bRedial = false;
var g_LineProblem = 0;
var g_bFirstServerError = true;
var g_status = STATUS_OFF;
var g_ServerErrorCount = 0;
var g_IMEExists = false;
var g_OEMAddBackURL = "";
var g_DialingAvailableInCountry = true;
var g_ModalDialogUp = false;
var MS_REGISTRATION  = "{1C956940-8617-11D3-8B99-00A0C91E7F3C}";
var OEM_REGISTRATION = "{ECD24360-B210-11D3-8B99-00A0C91E7F3C}";
var g_bTapiDone = false;
var g_OEMNameStr=window.external.Signup.get_OEMName();
var g_Activation_Install_ID = "";
var g_PID_ENTERED_ONRECORD = "";
var g_Activation_CODE_ENTERED = "";
var g_Activation_CODE_ENTERED_status = "";
var g_InitAutodial = false;
var g_CameFromFirstPage = false;

var L_CheckConnectivity_Text = "Checking for connectivity...";
var L_BlankTitle_Text = "";

var ACTIVATION_TIMEOUT = 1800000; // 30 minutes

// Mandatory Initialization Code
if (null == ApiObj)
{
    ApiObj = new Object;
    ApiObj = window.external.API;
}
if (null == StatusObj)
{
    StatusObj = new Object;
    StatusObj = window.external.Status;
}
if (null == DirObj)
{
    DirObj = new Object;
    DirObj = window.external.Directions;
}
if (null == InfoObj)
{
    InfoObj = new Object;
    InfoObj = window.external.UserInfo;
}
if (null == RegisterObj)
{
    RegisterObj = new Object;
    RegisterObj = window.external.Register;
}
if (null == TapiObj)
{
    TapiObj = new Object;
    TapiObj = window.external.Tapi;
}
if (null == LangObj)
{
    LangObj = new Object;
    LangObj = window.external.Language;
}


// END Initialization Code

// AGENT: SelectClick is used by Agent
function OnSelectClick() {}

// AGENT: OnClick is used by Agent
function OnClick() {}

// AGENT: Focus functions are used by Agent
function OnFocus() {}

// these handle next/back navigation for non-checkpoint pages

function ShowSimpleNavBack()
{
    g.window.history.back();
    SetTimerShowIFrame(100);
}

function SimpleNavBack()
{
    ShowIFrame('False');
    window.setTimeout("ShowSimpleNavBack();",500);
}

function HandleTextAreaFocus() {
  g.event.srcElement.style.borderStyle="ridge";
}

function HandleTextAreaBlur() {
  g.event.srcElement.style.borderStyle="";
}

function CheckContrastMode()
{
    try
    {
        var InHighContrastMode = window.external.InHighContrastMode();
    }
    catch(e)
    {
        var L_HighContrastMode1_Text = "InHighContrastMode API not available";
        alert(L_HighContrastMode1_Text);
        InHighContrastMode = false;
    }

    if (InHighContrastMode)
    {
        g.deskstyle1.disabled = true;
        g.deskstyle2.disabled = false;
    }
}

function GetPageTitle()
{
    Span_WPA_MainTitle.innerText = g.Title_Text.innerText;
}


//////////////////////////////////////////////////////////////////////////////////////
// actdone.htm
//////////////////////////////////////////////////////////////////////////////////////

function Actdone_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    g_FirstFocusElement = g.btnQuit;
    InitButtons();

    if (g_FirstFocusElement != null)
        window.setTimeout("DoFocus();",1000);
}



//////////////////////////////////////////////////////////////////////////////////////
// activ.htm
//////////////////////////////////////////////////////////////////////////////////////
function DoFocus()
{
    //
    // During the transition between pages, the pages are hidden and focus()
    // will fail.  If this happens we try again after a short delay.
    //
    try
    {
        if (g_FirstFocusElement != null)
        {
            g_FirstFocusElement.focus();
        }
    }
    catch(e)
    {
        window.setTimeout("DoFocus();",1000);
    }
}

function Activ_BtnTelephoneHandler()
{
    GoNavigate(CKPT_ACTIVSVC);
}

var g_ActivationRadioSticky = null;
function Activation_LoadMe()
{
    g_CameFromFirstPage = false;

    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    if (g_ActivationRadioSticky == null)
        g.btnNext.disabled = true;
    else if (g_ActivationRadioSticky == 1)
        g.rb_act_1.checked = true;
    else if (g_ActivationRadioSticky == 2)
        g.rb_act_2.checked = true;
    else if (g_ActivationRadioSticky == 3)
        g.rb_act_3.checked = true;

    if (g_ActivationRadioSticky != null)
    {
        WPA_ActivationRadioClicked();
    }

    var ndaysleft = ""
    try
    {
        ndaysleft = window.external.GetActivationDaysLeft();
    }
    catch(e)
    {
        ndaysleft = "0";
    }

    var L_LogMeOff_Text = "N<u>o</u>, log me off";

    if (ndaysleft == "0")
    {
        g.act_par01_ZeroDays.style.display = "inline";
        g.act_spn3.innerHTML = L_LogMeOff_Text;
        if (window.external.HasTablet())
        {
            g.act_par03_Tablet.style.display = "inline";
        }
    }
    else
    {
        g.act_par01_HaveDays.style.display = "inline";
        g.act_par02_HaveDays.style.display = "inline";
        g.NumberDaysLeft1.innerText = ndaysleft;
    }

    InitButtons();

    if (g_ActivationRadioSticky == null)
        g_FirstFocusElement = g.document.body;
    else
        g_FirstFocusElement = g.btnNext;

    window.setTimeout("DoFocus();",1000);
}


function WPA_ActivationRadioClicked()
{
    if (g.rb_act_1.checked)
        g_ActivationRadioSticky = 1;
    else if (g.rb_act_2.checked)
        g_ActivationRadioSticky = 2;
    else
        g_ActivationRadioSticky = 3;

    if (g.btnNext.disabled)
    {
        g.btnNext.disabled = false;
        g.btnNext.onclick = GoNext;
        g.btnNext.focus();
    }
}


//////////////////////////////////////////////////////////////////////////////////////
// activerr.htm
//////////////////////////////////////////////////////////////////////////////////////

function Activerr_RetryBtnHandler()
{
    DisableAllButtons();
    if (CheckForAnyConnection())
        GoNavigate(CKPT_ACTIV);
    else
        GoNavigate(CKPT_ACTIVERR);
}

function ActivationErr_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    InitButtons();

    g.btnTelephone.onmouseover = HandleButtonMouseOver;
    g.btnTelephone.onmouseout  = HandleButtonMouseOut;
    g.btnTelephone.onclick = GoNext;

    g.btnNext.onclick   = Activerr_RetryBtnHandler;
    g_FirstFocusElement = g.btnNext;

    if (g_FirstFocusElement != null)
        window.setTimeout("DoFocus();",1000);
}

//////////////////////////////////////////////////////////////////////////////////////
// actconn.htm
//////////////////////////////////////////////////////////////////////////////////////
var g_ActConnRadioSticky = 1;

function ActConn_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    if (g_ActConnRadioSticky == 1)
    {
        g_FirstFocusElement = g.rb_conn_lan;
        g.rb_conn_lan.checked = true;
    }
    else
    {
        g_FirstFocusElement = g.rb_conn_modem;
        g.rb_conn_modem.checked = true;
    }

    InitButtons();

    window.setTimeout("DoFocus();",1000);

}

//////////////////////////////////////////////////////////////////////////////////////
// actlan.htm
//////////////////////////////////////////////////////////////////////////////////////
var ProxySettingsObj = null;

function ProxySettings(ConfigString)
{
    this.UseAuto = false;
    this.UseScript = false;
    this.ScriptUrl = "";
    this.UseProxy = false;
    this.Server = "";
    this.Port = "";

    if (ConfigString != null)
    {
        var i, j;
        var Args = ConfigString.split(/ /);

        for (i = 0; i < Args.length; i++)
        {
            switch (Args[i])
            {
            case 'u':
                var ProxyList = Args[++i];
                var HttpProxy = null;

                // only care about proxy server for HTTP
                if (ProxyList.indexOf("=") == -1)
                {
                    HttpProxy = ProxyList;
                }
                else
                {
                    var Proxys = ProxyList.split(/;/);
                    if (Proxys != null)
                    {
                        for (j = 0; j < Proxys.length; j++)
                        {
                            if (Proxys[j].indexOf("http=") == 0)
                            {
                                HttpProxy = Proxys[j].substring(5, Proxys[j].length);
                                break;
                            }
                        }
                    }
                }

                if (HttpProxy)
                {
                    j = HttpProxy.lastIndexOf(':');
                    if (j == -1)
                    {
                        this.Server = HttpProxy;
                    }
                    else
                    {
                        this.Server = HttpProxy.substring(0, j);
                        this.Port = HttpProxy.substring(j+1, HttpProxy.length);
                    }
                }
                break;

            case 'a':
                this.UseAuto = true;
                break;

            case 'm':
                this.UseProxy = true;
                break;
            }
        }
    }

}

function ActLan_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    InitButtons();

    if (ProxySettingsObj == null)
    {
        var ConfigString = window.external.get_ProxySettings();
        ProxySettingsObj = new ProxySettings(ConfigString);
    }

    g.cb_auto_detect.checked = ProxySettingsObj.UseAuto;
    g.cb_use_proxy.checked = ProxySettingsObj.UseProxy;
    g.txt_proxy_url.value = ProxySettingsObj.Server;
    g.txt_proxy_port.value = ProxySettingsObj.Port;

    ActLan_upClickHandler();

    g_FirstFocusElement = g.btnNext;
    window.setTimeout("DoFocus();",1500);
}

function ActLan_upClickHandler()
{
    if (g.cb_use_proxy.checked)
    {
        g.txt_proxy_url.style.backgroundColor = "#ffffff";
        g.txt_proxy_url.disabled = false;
        g.txt_proxy_port.style.backgroundColor = "#ffffff";
        g.txt_proxy_port.disabled = false;
    }
    else
    {
        g.txt_proxy_url.style.backgroundColor = "#dddddd";
        g.txt_proxy_url.disabled = true;
        g.txt_proxy_port.style.backgroundColor = "#dddddd";
        g.txt_proxy_port.disabled = true;
    }
}

function ActLan(Stage)
{
    if (Stage == null)
    {
        //
        // Do the internet connectivity checking ...
        //
        Span_WPA_MainTitle.innerText = L_BlankTitle_Text;
        ShowIFrame('False', L_CheckConnectivity_Text);
        ResetConnectedToInternetEx();
        ConnectedToInternetEx(true, "ActLan(1);");
    }
    else
    {
        //
        // Use the existing connectivity value
        //
        if (ConnectedToInternetEx(false))
        {
            IcsConnect(ICS_CONN_TYPE_REG);
            SetTimerShowIFrame(ACTIVATION_TIMEOUT);
        }
        else
        {
            g_ActivationStatus = ERR_ACT_NETWORK_FAILURE;
            GoNavigate(CKPT_ACT_MSG);
        }
    }
}

//////////////////////////////////////////////////////////////////////////////////////
// PID functions
//////////////////////////////////////////////////////////////////////////////////////
var g_TabForward = false;
var g_TabBackward = false;
var g_LastFocusedPidBox;
var g_SelectionExistsBeforeKeyPress=null;
var g_keyPressKeyCode = 0;
var g_CharCode0_plus1=("0".charCodeAt(0))+1;

function RetrievePid()
{
    // retrieves the pid if avialable.
    var strPid = PidObj.get_PID();

    // if there is no PID then we set the
    // focus to the first field
    if (strPid.length == 0)
    {
        g.edtProductKey[0].focus();
    }
    // else we populate the fields with the
    // sections of the PID
    else
    {
        var re = new RegExp("(.*)-(.*)-(.*)-(.*)-(.*)","");
        if(re.exec(strPid) == null) {
            throw "Internal error:  RegExp pattmatch failed!";
        }

        g.edtProductKey[0].value = RegExp.$1;
        g.edtProductKey[1].value = RegExp.$2;
        g.edtProductKey[2].value = RegExp.$3;
        g.edtProductKey[3].value = RegExp.$4;
        g.edtProductKey[4].value = RegExp.$5;
    }
}

function PID_CheckLength(KnownIncomplete)
{
    // call this only if box reaches length 5 for speed?

    if(KnownIncomplete) {
        g.btnNext.disabled = true;
        g.btnNext.className="buttons-disabled";
        return;
    }

    var TotLength=g.edtProductKey[0].value.length+g.edtProductKey[1].value.length+
        g.edtProductKey[2].value.length+g.edtProductKey[3].value.length+
        g.edtProductKey[4].value.length;

    if (TotLength == 25)
    {
        g.btnNext.disabled = false;
        g.btnNext.className="buttons";
    }
    else
    {
        g.btnNext.disabled = true;
        g.btnNext.className="buttons-disabled";
    }
}

function PIDBox_HandleBlur() {
    g_LastFocusedPidBox=g.event.srcElement;
}

function PIDBox_HandleFocus() {
    g_LastFocusedPidBox=g.event.srcElement;
    OnFocus();
}

function IsProductIDKey(keyCode)
{
    var str = String.fromCharCode(keyCode);

    var result = str.match(/B|C|D|F|G|H|J|K|M|P|Q|R|T|V|W|X|Y|2|3|4|6|7|8|9/);

    return (null != result);
}

function CursorAtEndOfField(currentEdit) {
    // assumes selection is current edit field

    var tr = g.edtProductKey[currentEdit].createTextRange();
    var tr2 = g.document.selection.createRange();

    tr2.moveStart("textedit",-1);

    if(tr.isEqual(tr2)){
        return true;
    } else {
        return false;
    }
}

function ProductIDKeyDown()
{
    try
    {
        if (g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    var keyCode = g.event.keyCode;

    g_SelectionExistsBeforeKeyPress=(g.document.selection.type!="None");

    if(g.event.srcElement.tagName=="INPUT") {
        var i=g.event.srcElement.id.charCodeAt(3)-g_CharCode0_plus1;
    } else {
        var i=-1;
    }

    switch(keyCode) {

        case KeyTab:
            if(g.event.srcElement == g.edtProductKey[i]) {
                if(g.event.shiftKey)
                    TabBackward(i,true);
                else TabForward(i,true);

                g.event.returnValue = false;
                g.event.keyCode = 0;
                g.event.cancelBubble = true;
                break;
            }
            break;

        case KeyLeftArrow:
            if((i>0) && CursorAtStartOfField(i)) {
                TabBackward(i,false);
                g.event.returnValue = false;
            }
            break;

        case KeyRightArrow:
            if((i<4) && CursorAtEndOfField(i)) {
                TabForward(i,false);
                g.event.returnValue = false;
            }
            break;

        case KeyBackSpc:
        case KeyDelete:

            // if there is already 5 characters in a field, and the user puts the cursor in it, we want to
            // fill in the next box with the character.  we have to do this here because there is no propertychange,
            // and keyup is too late
            //if(g.edtProductKey[i].value.length == 5 && IsProductIDKey(keyCode) && g.document.selection==null)
            //    TabForward(i);
            // cgeorges note: I enabled this feature tried it and didnt like it

            ////////
            // we want the delete/backspace to move the previous edit box if:

            // there is 0 characters, and the user puts the cursor in it, and selection is non-null
            // OR backspc && cursor is at start of field

            if ((i > 0) &&
                    (   ((g.document.selection.type=="None") && (g.edtProductKey[i].value.length == 0))
                        ||((keyCode==KeyBackSpc)&& CursorAtStartOfField(i)))) {

                TabBackward(i,false);
                g.event.returnValue = false; // so no deletion occurs when backspace moves to prev pidbox
                g.event.keyCode = 0;
            }

            break;

        case KeyEnter:
            if((g.btnNext.disabled == false)&&(g.event.srcElement!=g.btnBack)) {
                g.btnNext.click();
                g.event.returnValue = false;
                g.event.keyCode = 0;
                g.event.cancelBubble = true;
            }
            break;
    }
}

function ProductIDPropertyChange()
{
    try
    {
        if (g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    // enable Next Btn when PID is full, and automatically move to
    // next/previous field when entering/deleting chars

    if ("value" == g.event.propertyName) {

        // find the index at which we are.
        var i=g.event.srcElement.id.charCodeAt(3)-g_CharCode0_plus1;

        // our g_Tab variables can be booleans instead of counts because they can
        // have a max value of 1, becase there will only ever be 1 call to OnPropertyChange if the
        // length of the edit is 0 or 5
        switch(g.edtProductKey[i].value.length) {
            case 5:
                g_TabForward = (i<4);  // dont tab forward if on last PID box
                PID_CheckLength(false);
                break;

            case 4:
            case 0:
            case 1:
                PID_CheckLength(true);  //change from 25char-state could have occurred with any of these lengths
        }

        // see if we want to tab backward
        // if pixbox is empty, and last keypress was not a pidkey (which adds a char),
        // and nothing was selected.

        // BUGBUG: this currently only fully works for the delete key.  when backspace
        // is pressed, g.document.selection.type is always "None" even if there was a selection
        if ((g.edtProductKey[i].value.length == 0) && (i > 0) &&
                (g_keyPressKeyCode==KeyBackSpc)&&(g_keyPressKeyCode==KeyDelete)&&
                (g.document.selection.type=="None")) {

            g_TabBackward = true; // IsProd check is to handle the case where they select everything then press a 2, etc.
        }
    }

    g_keyPressKeyCode = 0;
}

function ProductIDKeyPress()
{
    try
    {
        if (g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (g.event.keyCode == KeyBackSpc) {
        ProductIDKeyDown();
        return;
    }

    KeyCodeToUpper();

    g_keyPressKeyCode = g.event.keyCode;

    if (!IsProductIDKey(g_keyPressKeyCode)) {
        g.event.keyCode = 0;
        return;
    } else {

        var i=g.event.srcElement.id.charCodeAt(3)-g_CharCode0_plus1;

        if((i<4) && (g.edtProductKey[i].value.length == 5) && CursorAtEndOfField(i) && (!g_SelectionExistsBeforeKeyPress)) {
            TabForward(i,false);
        }
    }
}

function ProductIDKeyUp()
{
    try
    {
        if (g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if((!g_TabForward) && (!g_TabBackward)) {
        return;
    }

    var i=g.event.srcElement.id.charCodeAt(3)-g_CharCode0_plus1;

    if (g_TabBackward) {
        TabBackward(i,false);
        return;
    } else
        if(g_TabForward) {
            TabForward(i,false);
        }
}

function TabForward(currentEdit,DoSelectAll)
{
    g_TabForward = false;

    if(currentEdit==4) {
        // deselect any existing selection before moving focus to back button
        if(g.document.selection.type!="None") {
            g.document.selection.empty();
        }
        g.btnTelephone.focus();
        return;
    }

    currentEdit++;

    g.edtProductKey[currentEdit].focus();

    if(DoSelectAll) {
        g.edtProductKey[currentEdit].select();
        return;
    }

    var tr = g.edtProductKey[currentEdit].createTextRange();
    tr.collapse(true);
    tr.moveStart("word", 0);
    tr.select();

}

function TabBackward(currentEdit,DoSelectAll)
{
    g_TabBackward = false;

    if (currentEdit == 0) {
        // deselect any existing selection before moving focus to button
        if(g.document.selection.type!="None") {
            g.document.selection.empty();
        }
        if(g.btnNext.disabled) {
            g.btnQuit.focus();
        } else {
            g.btnNext.focus();
        }

        return;
    }

    currentEdit--;

    g.edtProductKey[currentEdit].focus();

    if(DoSelectAll) {
        g.edtProductKey[currentEdit].select();
        return;
    }

    var tr = g.edtProductKey[currentEdit].createTextRange();
    tr.collapse(false);
    tr.moveStart("word", 1);
    tr.select();
}

function CursorAtStartOfField(currentEdit) {
    var tr = g.edtProductKey[currentEdit].createTextRange();
    var tr2 = g.document.selection.createRange();

    tr2.moveEnd("textedit",1);

    if(tr.isEqual(tr2)){
        return true;
    } else {
        return false;
    }
}

function CursorAtEndOfField(currentEdit) {
    // assumes selection is current edit field

    var tr = g.edtProductKey[currentEdit].createTextRange();
    var tr2 = g.document.selection.createRange();

    tr2.moveStart("textedit",-1);

    if(tr.isEqual(tr2)){
        return true;
    } else {
        return false;
    }
}

function StorePid()
{
    var strPid = "";
    for (var i = 0; i < 4; i++)
    {
        strPid += g.edtProductKey[i].value;
        strPid += '-';
    }
    strPid += g.edtProductKey[i].value;
    PidObj.set_PID(strPid);
}


//////////////////////////////////////////////////////////////////////////////////////
// adeskerr.htm
//////////////////////////////////////////////////////////////////////////////////////

function Activation_ResetNetworking()
{
    if (window.external.CheckOnlineStatus)
    {
        ResetDialing();
    }

    if (g_InitAutodial)
    {
        window.external.InternetAutodialHangup();
        g_InitAutodial = false;
    }
}

function Activation_RetryBtnHandler()
{
    DisableAllButtons();
    if ((g_ActivationStatus == ERR_ACT_INVALID_PID) ||
        (g_ActivationStatus == ERR_ACT_USED_PID) ||
        (g_ActivationStatus == ERR_ACT_BLOCKED_PID) ||
        (g_ActivationStatus == ERR_ACT_DEDICATED_PID_ENTRY))
    {
        StorePid();
        if (PidObj.get_PID.length != 0 && PidObj.ValidatePID())
        {
            if (ReturnToTelephonePage)
            {
                // Must reload our Installation ID since we're successful in updating our PID
                g_Load_InstallID = true;

                // Also clear out the confirmation ID boxes
                g_ConfirmID_A = "";
                g_ConfirmID_B = "";
                g_ConfirmID_C = "";
                g_ConfirmID_D = "";
                g_ConfirmID_E = "";
                g_ConfirmID_F = "";
                g_ConfirmID_G = "";

                GoNavigate(CKPT_ACTIVSVC);  // This is where we go when we click on "Update" to change our product key in the update PID page
            }
            else
                GoNavigate(CKPT_REGDIAL);
        }
        else
        {
            // Must show "Invalid PID" page
            g_ActivationStatus = ERR_ACT_INVALID_PID;
            GoNavigate(CKPT_ACT_MSG);
        }
    }
    else
    {
        // If our error has nothing to do with the PID, then the RETRY button should fall here...
        GoNavigate(CKPT_REGDIAL);
    }
}


var L_EnterNewKey_Text   = "Enter new key:";
var L_EnterKey_Text      = "Enter key:";
var L_NewKey_Text        = "New key:";
var L_MessageNumber_Text = "Message number: %1";
var L_FinishButton_Text  = "OK";
var L_UpdateButton_Text  = " <u>U</u>pdate ";
function act_desktop_error_LoadMe()
{
    var Accesskey_U = "U";
    var Accesskey_O = "O";
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    Activation_ResetNetworking();

    var ndaysleft = ""
    try
    {
        ndaysleft = window.external.GetActivationDaysLeft();
    }
    catch(e)
    {
        ndaysleft = "0";
    }

    if (g_ActivationStatus == ERR_ACT_SUCCESS)
    {
        var L_ActThankYou_Text       = "Thank You!";
        Span_WPA_MainTitle.innerText = L_ActThankYou_Text;
        if (g_PostToMS)
            g.acterror_description_SUCCESS1.style.display="inline";
        else
            g.acterror_description_SUCCESS2.style.display="inline";
    }
    else if (g_ActivationStatus == ERR_ACT_INACCESSIBLE)
    {
        var L_ActUnable1_Text        = "Unable to activate Windows";
        Span_WPA_MainTitle.innerText = L_ActUnable1_Text;

        if (ndaysleft == "0")
        {
            g.acterror_description1Post.style.display="inline";
        }
        else
        {
            g.acterror_description1Pre.style.display="inline";
            g.NumberDaysLeft1.innerText  = ndaysleft;
        }
    }
    else if (g_ActivationStatus == ERR_ACT_INVALID_PID)
    {
        var L_ActIncorrectKey_Text  = "Incorrect product key";
        Span_WPA_MainTitle.innerText = L_ActIncorrectKey_Text;

        var WPAOEMMode01 = window.external.IsOemSKU();
        if (WPAOEMMode01)
        {
            // OEM
            g.acterror_description2_OEM.style.display="inline";
            g.acterror_after_pid_entry_OEMText.style.display="inline";
        }
        else
        {
            // Retail
            g.acterror_description2_RETAIL.style.display="inline";
        }
        g.acterror_pid_entry.style.display="inline";
        g.acterror_after_pid_entry_text1.style.display="inline";
        g.acterror_description_verify_key.innerHTML = L_NewKey_Text;
    }
    else if (g_ActivationStatus == ERR_ACT_USED_PID)
    {
        var L_ActProductKey_Text    = "Product key";
        Span_WPA_MainTitle.innerText = L_ActProductKey_Text;

        var WPAOEMMode02 = window.external.IsOemSKU();
        if (WPAOEMMode02)
        {
            // OEM
            g.acterror_description3OEM.style.display="inline";
            g.acterror_after_pid_entry_OEMText.style.display="inline";
        }
        else
        {
            // Retail
            g.acterror_description3Retail.style.display="inline";
        }
        g.acterror_pid_entry.style.display="inline";
        g.acterror_description_verify_key.innerHTML = L_NewKey_Text;
        g.acterror_after_pid_entry_text2.style.display="inline";
    }
    else if (g_ActivationStatus == ERR_ACT_INTERNAL_WINDOWS_ERR)
    {
        var L_ActUnable2_Text  = "Unable to activate Windows";
        Span_WPA_MainTitle.innerText = L_ActUnable2_Text;

        if (ndaysleft == "0")
        {
            g.acterror_description4Post.style.display="inline";
        }
        else
        {
            g.acterror_description4Pre.style.display="inline";
            g.NumberDaysLeft2.innerText  = ndaysleft;
        }
    }
    else if (g_ActivationStatus == ERR_ACT_BLOCKED_PID)
    {
        var L_ActUnauthorKey_Text   = "Unauthorized product key";
        Span_WPA_MainTitle.innerText = L_ActUnauthorKey_Text;

        var WPAOEMMode03 = window.external.IsOemSKU();
        if (WPAOEMMode03)
        {
            // OEM
            g.acterror_description5OEM.style.display="inline";
            g.acterror_after_pid_entry_OEMText.style.display="inline";
        }
        else
        {
            // Retail
            g.acterror_description5Retail.style.display="inline";
        }
        g.acterror_pid_entry.style.display="inline";
        g.acterror_description_verify_key.innerHTML = L_NewKey_Text;
        g.acterror_after_pid_entry_text2.style.display="inline";
    }
    else if (g_ActivationStatus == ERR_ACT_CORRUPTED_PID)
    {
        g.acterror_description6.style.display="inline";
        g.NumberDaysLeft3.innerText  = ndaysleft;
    }
    else if (g_ActivationStatus == ERR_ACT_NETWORK_FAILURE)
    {
        g.acterror_description7.style.display="inline";
    }
    else if (g_ActivationStatus == ERR_ACT_DEDICATED_PID_ENTRY)
    {
        var L_ActUpdateKey_Text  = "Change product key";
        Span_WPA_MainTitle.innerText = L_ActUpdateKey_Text;

        var WPAOEMMode04 = window.external.IsOemSKU();
        if (WPAOEMMode04)
        {
            // OEM
            g.acterror_description_dedicated_pid_OEM.style.display="inline";
            g.acterror_after_pid_entry_OEMText.style.display="inline";
        }
        else
        {
            // Retail
            g.acterror_description_dedicated_pid_RETAIL.style.display="inline";
        }
        g.acterror_pid_entry.style.display="inline";
        g.acterror_description_verify_key.innerHTML = L_NewKey_Text;
        g.btnNext.innerHTML = L_UpdateButton_Text;
        g.btnNext.accessKey = Accesskey_U;
    }
    else
    {
        g.acterror_description4.style.display="inline";
        g.NumberDaysLeft2.innerText  = ndaysleft;
    }


    if (g_ActivationStatus != ERR_ACT_SUCCESS)
    {
        if ((g_act_specific_error != 0) && (g_act_specific_error != null))
        {
            g.acterror_specific_error_code.innerText = ApiObj.FormatMessage(L_MessageNumber_Text, g_act_specific_error.toString());
            g.acterror_specific_error_code.style.display = "inline";
        }
    }

    InitButtons();

    if (g_ActivationStatus != ERR_ACT_SUCCESS)
    {
        if ((g_ActivationStatus == ERR_ACT_INVALID_PID) ||
            (g_ActivationStatus == ERR_ACT_USED_PID) ||
            (g_ActivationStatus == ERR_ACT_BLOCKED_PID) ||
            (g_ActivationStatus == ERR_ACT_DEDICATED_PID_ENTRY))
        {
            if (null == PidObj)
            {
                PidObj = new Object;
                PidObj = window.external.ProductID;
            }

            g_FirstFocusElement = g.edtProductKey[0];
            ShowIFrame();
            RetrievePid();

            var rangefocus = g_FirstFocusElement.createTextRange();
            rangefocus.collapse();
            rangefocus.moveStart("word", 0);
            rangefocus.select();

            g_TabForward = false;
            g_TabBackward = false;

            PID_CheckLength(false);

            for (i = 0; i <= 4; i++)
            {
                g.edtProductKey[i].onblur=PIDBox_HandleBlur;
                g.edtProductKey[i].onfocus=PIDBox_HandleFocus;
            }

            g_LastFocusedPidBox=g.edtProductKey[0];
        }
        else
        {
            g_FirstFocusElement = g.btnNext;
            ShowIFrame();
        }

        g.btnTelephone.onmouseover = HandleButtonMouseOver;
        g.btnTelephone.onmouseout  = HandleButtonMouseOut;
        g.btnTelephone.onclick = GoNext;
        g.btnNext.onclick = Activation_RetryBtnHandler;
    }
    else
    {
        g.btnTelephone.style.visibility = "hidden";
        g.btnQuit.style.visibility = "hidden";
        g.btnNext.innerHTML = L_FinishButton_Text;
        g.btnNext.accessKey = Accesskey_O;
        g_FirstFocusElement = g.btnNext;
        ShowIFrame();
    }

    window.setTimeout("DoFocus();",1000);
}


//////////////////////////////////////////////////////////////////////////////////////
// activsvc.htm
//////////////////////////////////////////////////////////////////////////////////////

function ValidateConfirmIDBox(Box_Number)
{
var Box_Value = null;
var Box_Valid = null;

    if (Box_Number=='1')
        Box_Value = g.ActCodeBox1.value;

    if (Box_Number=='2')
        Box_Value = g.ActCodeBox2.value;

    if (Box_Number=='3')
        Box_Value = g.ActCodeBox3.value;

    if (Box_Number=='4')
        Box_Value = g.ActCodeBox4.value;

    if (Box_Number=='5')
        Box_Value = g.ActCodeBox5.value;

    if (Box_Number=='6')
        Box_Value = g.ActCodeBox6.value;

    if (Box_Number=='7')
        Box_Value = g.ActCodeBox7.value;

    Box_Valid = window.external.VerifyCheckDigits(Box_Value);

    if (!Box_Valid)
    {
        var L_ConfirmIDInvalid1_Text = "The confirmation ID entered in this field is invalid. Please check the number and try again.";
        alert(L_ConfirmIDInvalid1_Text);

        // Set focus on the invalid confirmation id box
        if (Box_Number=='1')
        {
            g.ActCodeBox1.focus();
            g.ActCodeBox1.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='2')
        {
            g.ActCodeBox2.focus();
            g.ActCodeBox2.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='3')
        {
            g.ActCodeBox3.focus();
            g.ActCodeBox3.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='4')
        {
            g.ActCodeBox4.focus();
            g.ActCodeBox4.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='5')
        {
            g.ActCodeBox5.focus();
            g.ActCodeBox5.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='6')
        {
            g.ActCodeBox6.focus();
            g.ActCodeBox6.select();
            g_DoFieldChecking = false;
        }
        if (Box_Number=='7')
        {
            g.ActCodeBox7.focus();
            g.ActCodeBox7.select();
            g_DoFieldChecking = false;
        }
    }
    else
    {
        // Set focus on the next confirmation id box if valid
        if (Box_Number=='1')
            g.ActCodeBox2.focus();
        if (Box_Number=='2')
            g.ActCodeBox3.focus();
        if (Box_Number=='3')
            g.ActCodeBox4.focus();
        if (Box_Number=='4')
            g.ActCodeBox5.focus();
        if (Box_Number=='5')
            g.ActCodeBox6.focus();
        if (Box_Number=='6')
            g.ActCodeBox7.focus();
        if (Box_Number=='7')
        {
            // Do nothing, focusing will be done automatically by IsConfirmIDComplete() when this function returns.
            // Note: Don't take out the curly braces here...
        }

        g_DoFieldChecking = true;
    }
}

function UpdateConfirmIDFields(FieldToEdit)
{
    if (FieldToEdit == '1')
    {
        g_ConfirmID1 = g.ActCodeBox1.value;
    }

    if (FieldToEdit == '2')
    {
        g_ConfirmID2 = g.ActCodeBox2.value;
    }

    if (FieldToEdit == '3')
    {
        g_ConfirmID3 = g.ActCodeBox3.value;
    }

    if (FieldToEdit == '4')
    {
        g_ConfirmID4 = g.ActCodeBox4.value;
    }

    if (FieldToEdit == '5')
    {
        g_ConfirmID5 = g.ActCodeBox5.value;
    }

    if (FieldToEdit == '6')
    {
        g_ConfirmID6 = g.ActCodeBox6.value;
    }

    if (FieldToEdit == '7')
    {
        g_ConfirmID7 = g.ActCodeBox7.value;
    }

    // If user presses Backspace, move focus to previous field if current field is empty. Unless we are in field 1.
    if (g_DoBackSpace)
    {
        g_DoBackSpace = false;
        var tr = null;

        if (FieldToEdit == '1')
        {
            // Do nothing.
        }
        else if (FieldToEdit == '2')
        {
            if (g.ActCodeBox2.value == "")
                tr = g.ActCodeBox1.createTextRange();
        }
        else if (FieldToEdit == '3')
        {
            if (g.ActCodeBox3.value == "")
                tr = g.ActCodeBox2.createTextRange();
        }
        else if (FieldToEdit == '4')
        {
            if (g.ActCodeBox4.value == "")
                tr = g.ActCodeBox3.createTextRange();
        }
        else if (FieldToEdit == '5')
        {
            if (g.ActCodeBox5.value == "")
                tr = g.ActCodeBox4.createTextRange();
        }
        else if (FieldToEdit == '6')
        {
            if (g.ActCodeBox6.value == "")
                tr = g.ActCodeBox5.createTextRange();
        }
        else if (FieldToEdit == '7')
        {
            if (g.ActCodeBox7.value == "")
                tr = g.ActCodeBox6.createTextRange();
        }


        // This will cause the insertion point to move to the end of the text range
        if ((FieldToEdit != '1') && (tr != null))
        {
            tr.collapse(false);
            tr.moveStart("word", 1);
            tr.select();
        }
    }
}


function DeleteLastCharacter(FieldToEdit)
{
    if (FieldToEdit == '1')
    {
        g.ActCodeBox1.value = g_ConfirmID1;
    }

    if (FieldToEdit == '2')
    {
        g.ActCodeBox2.value = g_ConfirmID2;
    }

    if (FieldToEdit == '3')
    {
        g.ActCodeBox3.value = g_ConfirmID3;
    }

    if (FieldToEdit == '4')
    {
        g.ActCodeBox4.value = g_ConfirmID4;
    }

    if (FieldToEdit == '5')
    {
        g.ActCodeBox5.value = g_ConfirmID5;
    }

    if (FieldToEdit == '6')
    {
        g.ActCodeBox6.value = g_ConfirmID6;
    }

    if (FieldToEdit == '7')
    {
        g.ActCodeBox7.value = g_ConfirmID7;
    }

    var L_OnlyNumbersAllowed_Text = "Only numbers can be used for the confirmation ID.";
    alert(L_OnlyNumbersAllowed_Text);

    if (FieldToEdit == '1')
        g.ActCodeBox1.focus();
    else if (FieldToEdit == '2')
        g.ActCodeBox2.focus();
    else if (FieldToEdit == '3')
        g.ActCodeBox3.focus();
    else if (FieldToEdit == '4')
        g.ActCodeBox4.focus();
    else if (FieldToEdit == '5')
        g.ActCodeBox5.focus();
    else if (FieldToEdit == '6')
        g.ActCodeBox6.focus();
    else if (FieldToEdit == '7')
        g.ActCodeBox7.focus();
}

var g_ConfirmID1 = "";
var g_ConfirmID2 = "";
var g_ConfirmID3 = "";
var g_ConfirmID4 = "";
var g_ConfirmID5 = "";
var g_ConfirmID6 = "";
var g_ConfirmID7 = "";
var g_DoBackSpace = false;

var g_DoFieldChecking = true;
function activate_OnKeyUp(WhatField)
{
    var keyCode = g.event.keyCode;
    var str = String.fromCharCode(keyCode);

    // Evidently, numkeypad 0 with the NumLock on gives us x60 or single back quote
    // LocStudio doesn't understand regexp, so we refer to this character by ascii code \x60

    // The small letters a-i represent the keycodes for the numeric keypad 1-9 (If Numlock is on).
    // We only allow "Numbers" to be entered in the Confirmation ID fields.

    var result           = str.match(/\x60|a|b|c|d|e|f|g|h|i|1|2|3|4|5|6|7|8|9|0/);
    var NonNumericresult = str.match(/A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z/);
    var BackSpc          = str.match(/\x08/);

    var validchar = false;
    if (null != result)
    {
        validchar = true;
    }
    else
    {
        validchar = false;

        if (null != NonNumericresult)
        {
            DeleteLastCharacter(WhatField);
        }
        else
        {
            if (null != BackSpc)
                g_DoBackSpace = true;

            UpdateConfirmIDFields(WhatField);
        }
    }

    if (validchar)
    {
        if (WhatField == '1')
        {
            g_ConfirmID1 = g.ActCodeBox1.value;
            if (g.ActCodeBox1.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '2')
        {
            g_ConfirmID2 = g.ActCodeBox2.value;
            if (g.ActCodeBox2.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '3')
        {
            g_ConfirmID3 = g.ActCodeBox3.value;
            if (g.ActCodeBox3.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '4')
        {
            g_ConfirmID4 = g.ActCodeBox4.value;
            if (g.ActCodeBox4.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '5')
        {
            g_ConfirmID5 = g.ActCodeBox5.value;
            if (g.ActCodeBox5.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '6')
        {
            g_ConfirmID6 = g.ActCodeBox6.value;
            if (g.ActCodeBox6.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (WhatField == '7')
        {
            g_ConfirmID7 = g.ActCodeBox7.value;
            if (g.ActCodeBox7.value.length == 6)
            {
                ValidateConfirmIDBox(WhatField);
            }
        }

        if (g_DoFieldChecking)
            IsConfirmIDComplete();
        // We set focus here instead of inside the IsConfirmIDComplete() function to have
        // proper focus behaviour when we use certain keys like Tab, space, arrow keys...
        if (!g.btnNext.disabled)
            g.btnNext.focus();
    }
    else
    {
        IsConfirmIDComplete();
    }

}


function IsConfirmIDComplete()
{
    if ((g.ActCodeBox1.value.length == 6) && (g.ActCodeBox2.value.length == 6) && (g.ActCodeBox3.value.length == 6) && (g.ActCodeBox4.value.length == 6) && (g.ActCodeBox5.value.length == 6) && (g.ActCodeBox6.value.length == 6) && (g.ActCodeBox7.value.length == 6))
    {
        g.btnNext.onmouseover = HandleButtonMouseOver;
        g.btnNext.onmouseout  = HandleButtonMouseOut;
        g.btnNext.className="buttons";
        g.btnNext.disabled = false;
        g.btnNext.onclick  = ActivationSvc_NextBtnHandler;
    }
    else
    {
        g.btnNext.className="buttons-disabled";
        g.btnNext.disabled = true;
    }
}

var g_ActivSvc_Reload = true;
function ActivationSvc_NextBtnHandler()
{
    g_Activation_CODE_ENTERED = g.ActCodeBox1.value + '-' +
        g.ActCodeBox2.value + '-' +
        g.ActCodeBox3.value + '-' +
        g.ActCodeBox4.value + '-' +
        g.ActCodeBox5.value + '-' +
        g.ActCodeBox6.value + '-' +
        g.ActCodeBox7.value;

    g_ConfirmID_A  = g.ActCodeBox1.value;
    g_ConfirmID_B  = g.ActCodeBox2.value;
    g_ConfirmID_C  = g.ActCodeBox3.value;
    g_ConfirmID_D  = g.ActCodeBox4.value;
    g_ConfirmID_E  = g.ActCodeBox5.value;
    g_ConfirmID_F  = g.ActCodeBox6.value;
    g_ConfirmID_G  = g.ActCodeBox7.value;

    try
    {
        g_Activation_CODE_ENTERED_status = window.external.SetConfirmationID(g_Activation_CODE_ENTERED);
    }
    catch(e)
    {
        g_Activation_CODE_ENTERED_status = 0;
    }

    DisableAllButtons();
    if (g_Activation_CODE_ENTERED_status == 0)
    {
        GoNavigate(CKPT_DONE);
    }
    else
    {
        g_Load_InstallID = false;
        var L_ConfirmIDInvalid_Text = "The confirmation ID is invalid. Please check the number and try again.";
        alert(L_ConfirmIDInvalid_Text);
        g_ActivSvc_Reload = false;
        GoNavigate(CKPT_ACTIVSVC);
    }
}

function ActivationSvc_ProdkeyBtnHandler()
{
    DisableAllButtons();
    ReturnToTelephonePage = true;
    g_Load_InstallID = false;

    // Must also remember the Contents of the confirmation ID typed in by the user.
    g_ConfirmID_A  = g.ActCodeBox1.value;
    g_ConfirmID_B  = g.ActCodeBox2.value;
    g_ConfirmID_C  = g.ActCodeBox3.value;
    g_ConfirmID_D  = g.ActCodeBox4.value;
    g_ConfirmID_E  = g.ActCodeBox5.value;
    g_ConfirmID_F  = g.ActCodeBox6.value;
    g_ConfirmID_G  = g.ActCodeBox7.value;

    g_ActivationStatus = ERR_ACT_DEDICATED_PID_ENTRY;
    GoNavigate(CKPT_ACT_MSG);
}

function PhoneCountries_Changed()
{
    g.ChosenPhoneNumber.innerHTML = "<B>" + g_Phone_Number_Array[g.selPhoneCountry.selectedIndex] + "</B>";
    g.ChosenTollNumber.innerHTML  = "<B>" + g_Toll_Number_Array[g.selPhoneCountry.selectedIndex]  + "</B>";

    // We want to remember the country selected whenever we go back to the Telephone page (activsvc.htm)
    g_Country_Selected_Index = g.selPhoneCountry.selectedIndex;
}

var g_Country_Selected_Index = 0;
var g_Phone_Number_Array = new Array(500);
var g_Toll_Number_Array =  new Array(500);
function GetPhoneCountries()
{
    var g_PhoneCountries = "";

    try
    {
        g_PhoneCountries = LangObj.get_PhoneCountries();

    }
    catch(e)
    {
        g_PhoneCountries = "API call error: get_PhoneCountries";
    }

    var i;
    var PhoneOption;
    var ModulusResult;
    var PhoneCounter=0;
    var TollCounter =0;
    var regexp1=/\t/;                                                // Define our regexp1 to a "TAB" keycode.
    var Opt_PhoneCountry_Array = g_PhoneCountries.split(regexp1);    // Let's split our tab delimited g_PhoneCountries string and put it into an array.
    var L_SelectYourLocation_Text = "Select your location";


    // Add the "Select your location" option in the select list
    PhoneOption      = g.document.createElement("OPTION");
    PhoneOption.text = L_SelectYourLocation_Text;
    g.selPhoneCountry.add(PhoneOption);
    g_Toll_Number_Array[TollCounter] = "";
    g_Phone_Number_Array[PhoneCounter] = "";
    TollCounter = TollCounter + 1;
    PhoneCounter = PhoneCounter + 1;

    for(i=0; i < Opt_PhoneCountry_Array.length; i++)
    {
        ModulusResult = i % 3;
        if (ModulusResult == 0)
        {
            PhoneOption      = g.document.createElement("OPTION");
            PhoneOption.text = Opt_PhoneCountry_Array[i];
            g.selPhoneCountry.add(PhoneOption);
        }
        else if (ModulusResult == 1)
        {
            g_Toll_Number_Array[TollCounter] = Opt_PhoneCountry_Array[i];
            TollCounter = TollCounter + 1;
        }
        else
        {
            g_Phone_Number_Array[PhoneCounter] = Opt_PhoneCountry_Array[i];
            PhoneCounter = PhoneCounter + 1;
        }
    }
    g.ChosenPhoneNumber.innerHTML = "<B>" + g_Phone_Number_Array[g_Country_Selected_Index] + "</B>";
    g.ChosenTollNumber.innerHTML  = "<B>" + g_Toll_Number_Array[g_Country_Selected_Index]  + "</B>";
    g.selPhoneCountry.selectedIndex = g_Country_Selected_Index;

}

function BackBtnHandler()
{
    GoNavigate(CKPT_ACTIV);
}

var ReturnToTelephonePage = false;
var g_ConfirmID_A = "";
var g_ConfirmID_B = "";
var g_ConfirmID_C = "";
var g_ConfirmID_D = "";
var g_ConfirmID_E = "";
var g_ConfirmID_F = "";
var g_ConfirmID_G = "";
var g_Load_InstallID = true;
var g_Activation_Install_ID_Full = "";
function ActivationSvc_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    ReturnToTelephonePage = false;


    // We want to pre-populate the Confirmation ID fields with values entered by the user, on an event this page is loaded the second time around.
    g.ActCodeBox1.value = g_ConfirmID_A;
    g.ActCodeBox2.value = g_ConfirmID_B;
    g.ActCodeBox3.value = g_ConfirmID_C;
    g.ActCodeBox4.value = g_ConfirmID_D;
    g.ActCodeBox5.value = g_ConfirmID_E;
    g.ActCodeBox6.value = g_ConfirmID_F;
    g.ActCodeBox7.value = g_ConfirmID_G;


    // Show "Back" button if we came from the first page.
    if (g_CameFromFirstPage)
    {
        g.btnBack.style.display = "inline";
    }

    InitButtons();

    // Override basic button behavior.
    // We want to force the back button to navigate to the first page "literally".
    if (g_CameFromFirstPage)
    {
        g.btnBack.onclick = BackBtnHandler;
    }

    IsConfirmIDComplete();  // Enable the Next button if all the Confirmation ID fields are complete
    GetPhoneCountries();

    g.btnProdkey.onclick = ActivationSvc_ProdkeyBtnHandler;
    g.btnProdkey.onmouseover = HandleButtonMouseOver;
    g.btnProdkey.onmouseout  = HandleButtonMouseOut;


    if (g_Country_Selected_Index==0)
    {
        g_FirstFocusElement = g.selPhoneCountry;
    }
    else if (!g.btnNext.disabled)
    {
        g_FirstFocusElement = g.btnNext;
    }
    else
    {
        g_FirstFocusElement = g.ActCodeBox1;
    }

    if (g_FirstFocusElement != null)
        window.setTimeout("DoFocus();",1000);
}



//// areg1.htm  ///////////////////////


var g_Reg1RadioSticky = null;
function areg1_LoadMe()
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    if (g_Reg1RadioSticky == null)
        g.btnNext.disabled = true;
    else if (g_Reg1RadioSticky == 1)
        g.rb_reg_1.checked = true;
    else if (g_Reg1RadioSticky == 2)
        g.rb_reg_2.checked = true;

    InitButtons();

    if (g.btnNext.disabled)
        g_FirstFocusElement = g.btnBack;
    else
        g_FirstFocusElement = g.btnNext;
    window.setTimeout("DoFocus();",1500);
}

function WPA_Reg1RadioClicked()
{
    // if they click on either button, enable the Next button
    if(g.btnNext.disabled && (g.rb_reg_1.checked || g.rb_reg_2.checked))
    {
        if (g.rb_reg_1.checked)
            g_Reg1RadioSticky = 1;
        else if (g.rb_reg_2.checked)
            g_Reg1RadioSticky = 2;

        g.btnNext.disabled = false;
        g.btnNext.onclick = GoNext;
        g.btnNext.focus();
    }
}


//// reg3.htm  ///////////////////////

var StateAbbrevs = new Array("","AL","AK","AZ","AR","CA","CO","CT","DC","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY");
var FullStateNames = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Washington, D.C.","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming");
var ProvinceNames = new Array("","Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territories","Nova Scotia","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon");

// need ability to map state name string to index into StateAbbrevs
var g_StateName2IndexMap= new ActiveXObject("Scripting.Dictionary");
var g_ProvinceName2IndexMap= new ActiveXObject("Scripting.Dictionary");

g_ProvinceName2IndexMap.CompareMode = 1;  // text compare
g_StateName2IndexMap.CompareMode = 1;  // text compare

// init hash table
var ii;
for(ii=1;ii<=FullStateNames.length;ii++) {
    // add both full name and abbrev to hash table
  g_StateName2IndexMap.Add(FullStateNames[ii-1].toUpperCase(),ii);
  g_StateName2IndexMap.Add(StateAbbrevs[ii].toUpperCase(),ii);

  if(ii < ProvinceNames.length) {
     g_ProvinceName2IndexMap.Add(ProvinceNames[ii].toUpperCase(),ii);
  }
}

var L_Postal_Text = "Postal or <u>Z</u>IP code:";
var L_AsteriskPostal_Text = "*Postal or <u>Z</u>IP code:";
var L_Province_Text= "State/<u>P</u>rovince:";
var L_AsteriskProvince_Text= "*State/<u>P</u>rovince:";

var L_Canada_Text="Canada";
var L_UnitedStates_Text="United States";

function Reg3UserCountryChanged() {

    // AGENT: notify Agent of the change


    g_Country=g.selCountry.options(g.selCountry.selectedIndex).text;

    if(g_Country == L_UnitedStates_Text) {
        if(g.selUSState.style.display!="inline") {
          g.selUSState.style.display="inline";
        }

        g.selCAProvince.style.display="none";
        g.UserStateTextBox.style.display="none";

        // when changing to US, try to translate any textbox string to state index
        if(g.UserStateTextBox.value!="") {
          var res=g_StateName2IndexMap.Item(g.UserStateTextBox.value.toUpperCase());
          if(res!=null) {
             g.selUSState.selectedIndex=res;
          }
        }
        g.LabelZIP.innerHTML = L_AsteriskPostal_Text;
        g.StateLabel.innerHTML = L_AsteriskProvince_Text;
    } else if(g_Country == L_Canada_Text) {
        g.selUSState.style.display="none";
        g.selCAProvince.style.display="inline";
        g.UserStateTextBox.style.display="none";

        // when changing to Canada, try to translate any textbox string to province index
        if(g.UserStateTextBox.value!="") {
          var res=g_ProvinceName2IndexMap.Item(g.UserStateTextBox.value.toUpperCase());
          if(res!=null) {
             g.selCAProvince.selectedIndex=res;
          }
        }
        g.LabelZIP.innerHTML = L_AsteriskPostal_Text;
        g.StateLabel.innerHTML = L_AsteriskProvince_Text;
    } else {
        g.selUSState.style.display="none";
        g.selCAProvince.style.display="none";
        g.UserStateTextBox.style.display="inline";
        g.LabelZIP.innerHTML = L_Postal_Text;
        g.StateLabel.innerHTML = L_Province_Text;
    }

    g_CountryIdx=g.selCountry.selectedIndex;

    Reg3UserStateChanged();
}

var L_FullName_Text="*<u>F</u>ull Name:";

function Reg3UserStateChanged() {

    // AGENT: notify Agent of the change

    // BUGBUG: ok for no notify on change to textbox?

    if(g.selUSState.style.display!="none")
    {
        g_StateIdx=g.selUSState.selectedIndex;
        g_State=g.selUSState.options(g.selUSState.selectedIndex).text;
        g.StateLabel.htmlFor="selUSState";
    }
    else if (g.selCAProvince.style.display!="none")
    {
         g_StateIdx=g.selCAProvince.selectedIndex;
         g_State=g.selCAProvince.options(g.selCAProvince.selectedIndex).text;
         g.StateLabel.htmlFor="selCAProvince";
    }
    else
    {
        g_State = g.UserStateTextBox.value;
        g.StateLabel.htmlFor="UserStateTextBox";
    }
}


// store field info here:

var g_FirstName=InfoObj.get_FirstName();
//var g_MiddleName=InfoObj.get_MiddleInitial();  //    InfoObj.get_MiddleName();  BUGBUG need to add this fn
var g_LastName=InfoObj.get_LastName();
var g_Address1=InfoObj.get_Address1();
var g_Address2=InfoObj.get_Address2();
var g_City=InfoObj.get_City();
var g_ZipCode=InfoObj.get_Zip();
var g_EmailAddr= InfoObj.get_PrimaryEmail();
var g_Country=InfoObj.get_Country();
var g_CountryIdx=-1;
var g_State=InfoObj.get_State();
var g_StateIdx=0;

function Reg3SaveSettings() {
    g_FirstName=g.UserFirstName.value;
    //g_MiddleName=g.UserMiddleName.value;

    if (IsKoreanLocale())
        g_LastName="";
    else
        g_LastName=g.UserLastName.value;

    g_Address1=g.UserAddress.value;
    g_Address2=g.UserAddress2.value;
    g_ZipCode=g.UserZipCode.value;
    g_EmailAddr=g.UserEmailAddress.value;
    g_City=g.UserCity.value;
    g_Country=g.selCountry.options(g.selCountry.selectedIndex).text;

    if(g.UserStateTextBox.style.display!="none")
    {
        g_State=g.UserStateTextBox.value;
    }
    else if (g.selUSState.style.display!="none")
    {
        g_State=g.selUSState.options(g.selUSState.selectedIndex).text;
    }
    else
    {
        g_State=g.selCAProvince.options(g.selCAProvince.selectedIndex).text;
    }

    InfoObj.set_FirstName(g_FirstName);
    InfoObj.set_LastName(g_LastName);
    // InfoObj.set_MiddleInitial(g_MiddleName);
    InfoObj.set_Country(g_Country);
    InfoObj.set_State(g_State);
    InfoObj.set_Address1(g_Address1);
    InfoObj.set_Address2(g_Address2);
    InfoObj.set_PrimaryEmail(g_EmailAddr);
    InfoObj.set_Zip(g_ZipCode);
    InfoObj.set_City(g_City);

    TapiObj.set_CountryIndex(g.selCountry.selectedIndex);
    InfoObj.set_CountryID(TapiObj.get_CountryID());

    // Microsoft policy states that MSupdate should always be true whenever a user registers.
    InfoObj.set_MSUpdate(true);

    InfoObj.set_MSOffer(false);
    if ((g_PostToMS==true) && (g.sharems.checked))
        InfoObj.set_MSOffer(true);

    InfoObj.set_OtherOffer(false);
    if ((g_PostToMS==true) && (g.sharemsPartners.checked))
        InfoObj.set_OtherOffer(true);
}

// We want the Reg3 checkboxes to be unchecked by default.
InfoObj.set_MSOffer(false);
InfoObj.set_OtherOffer(false);
function Reg3_LoadMe()
{
    InitFrameRef();
    CheckContrastMode();

    GetPageTitle();

    g_FirstFocusElement = g.UserFirstName;

    if (IsFarEastLocale())
    {

      /*For JPN, CHT, CHS,
        Last Name
        First Name
        Country/Region
        Province
        City
        Address
        Zip
        E-Mail

        For KOR only,
        Full Name
        Country/Region
        Province
        City
        Address
        Zip
        E-Mail
      */
        g.MainPageCell.style.display="none";  // hide while we change order

        // no middle name for far east langs
        //g.MiddleNameRow.style.display="none";

        g.FieldTable.moveRow(1,0);  // move lastname in front of first
        g.FieldTable.moveRow(6,2);  // move country to after firstname
        g.FieldTable.moveRow(6,3);  // move province to after country
        g.FieldTable.moveRow(6,4);  // move city to after province

        g.FE_ZIPLabel.innerHTML=g.LabelRight.innerHTML;
        g.FE_ZIPInput.innerHTML=g.MenuRight.innerHTML;
        g.FE_ZIPRow.style.display="inline";

        g.LabelRight.innerHTML="";
        g.MenuRight.innerHTML="";

        // no reason to limit these lengths for FE, so just make them match others
        g.UserZipCode.size=30;
        g.UserZipCode.maxlength=120;

        g.UserStateTextBox.size=30;
        g.UserStateTextBox.maxlength=120;

        g_FirstFocusElement = g.UserLastName;

        if (IsKoreanLocale()) {
            g.LastNameRow.style.display="none";
            g.LabelFirstName.innerHTML=L_FullName_Text;
            g_FirstFocusElement = g.UserFirstName;
        }

        g.MainPageCell.style.display="inline";
    }

    // limit width of country menu since some text options are very long
    g.selCountry.style.width=g.UserEmailAddress.offsetWidth;

    g.UserFirstName.value=g_FirstName;
    //g.UserMiddleName.value=g_MiddleName;
    g.UserLastName.value=g_LastName;
    g.UserAddress.value=g_Address1;
    g.UserAddress2.value=g_Address2;
    g.UserZipCode.value=g_ZipCode;
    g.UserEmailAddress.value=g_EmailAddr;
    g.UserCity.value=g_City;

    // placeholder idx 0 option is needed to fix 101447
    // Due to a possible mshtml bug, the cursor is shifted right when the menu
    // expands to its full width.

    g.selUSState.remove(0);

    for (var i = 0; i < StateAbbrevs.length; i++) {
       var oOption  = g.document.createElement("OPTION");
       oOption.text = StateAbbrevs[i];
       if (StateAbbrevs[i] == g_State)
       {
           g_StateIdx = i;
       }
       g.selUSState.add(oOption);
    }

    for (i = 0; i < ProvinceNames.length; i++) {
       oOption  = g.document.createElement("OPTION");
       oOption.text = ProvinceNames[i];
       if (ProvinceNames[i] == g_State)
       {
           g_StateIdx = i;
       }
       g.selCAProvince.add(oOption);
    }

    var fTapi = TapiObj.IsTAPIConfigured();  // init TAPI
/*
    var ilen = TapiObj.get_NumOfCountry(); // get num of countries, also inits COM obj storage
    for (var i = 0; i < ilen; i++)
    {
        var oOption  = g.document.createElement("OPTION");
        oOption.text = TapiObj.get_CountryNameForIndex(i);
        g.selCountry.add(oOption);
    }
*/

    g_CountryIdx = TapiObj.get_CountryIndex();

    if(g_CountryIdx>=0)
    {
        g.selCountry.selectedIndex=g_CountryIdx;
        if(g_Country ==  L_UnitedStates_Text)
        {
            g.selUSState.selectedIndex=g_StateIdx;
        }
        else if(g_Country == L_Canada_Text)
        {
            g.selCAProvince.selectedIndex=g_StateIdx;
        }
        else
            g.UserStateTextBox.value=g_State;
    }
    else
    {
        // get default value
        g.selCountry.selectedIndex = TapiObj.get_CountryIndex();
    }

    Reg3UserCountryChanged();
    Reg3UserStateChanged();

    var MSoffer_Checked = InfoObj.get_MSOffer();
    if (MSoffer_Checked)
        g.sharems.checked = true;
    else
        g.sharems.checked = false;

    var MSotheroffer_Checked = InfoObj.get_OtherOffer();
    if (MSotheroffer_Checked)
        g.sharemsPartners.checked = true;
    else
        g.sharemsPartners.checked = false;

    InitButtons();

    g.error_mesg.innerHTML = L_RequiredField_Text;
    g.error_mesg.style.display="inline";

    var L_CNIL_Text = "<p>";
    var L_CnilStyleDisplay_Text = "none";

    g.cnil_mesg.innerHTML = L_CNIL_Text;
    g.cnil_mesg.style.display=L_CnilStyleDisplay_Text;

    window.setTimeout("DoFocus();",1000);
}
function GetCurrentProvince() {
    if(g.selCountry.options(g.selCountry.selectedIndex).text == L_UnitedStates_Text) {
        return g.selUSState.options(g.selUSState.selectedIndex).text;
    } else if(g.selCountry.options(g.selCountry.selectedIndex).text == L_Canada_Text) {
        return g.selCAProvince.options(g.selCAProvince.selectedIndex).text;
    } else return g.UserStateTextBox.value;
}

function GetCurrentCountry() {
    return g.selCountry.options(g.selCountry.selectedIndex).text;
}

var L_Email_Text="Please enter a valid E-mail address or leave the E-mail text box empty.";
var L_EnterValid_Text=" * Please fill in the required fields.";
var L_RequiredField_Text="* indicates required information";

var g_PostToMS = false;
var g_PostToOEM = false; // no oem stuff when we are in appmode.
var POST_TO_OEM = 1;
var POST_TO_MS = 2;
var bPostChkBxStateSaved = false;

// Update status pane and navigate
function ShownavigatetoPrivacy()
{
    Navigate("actsetup\\aprvcyMS.htm");
    SetTimerShowIFrame(100);
}

function navigatetoPrivacy(PrivPage)
{
    if (g_CurrentCKPT == CKPT_REGISTER3)
       Reg3SaveSettings();

    if (g_CurrentCKPT == CKPT_REGISTER1)
    {
        if (g.rb_reg_1.checked)
            g_Reg1RadioSticky = 1;
        else if (g.rb_reg_2.checked)
            g_Reg1RadioSticky = 2;
        else
            g_Reg1RadioSticky = null;
    }

    ShowIFrame('False');
    window.setTimeout("ShownavigatetoPrivacy();",500);
}

function ShownavigatetoActPolicy()
{
    Navigate("actsetup\\apolicy.htm");
    SetTimerShowIFrame(100);
}

function navigatetoActPolicy()
{
    if (g.rb_act_1.checked)
        g_ActivationRadioSticky = 1;
    else if (g.rb_act_2.checked)
        g_ActivationRadioSticky = 2;
    else if (g.rb_act_3.checked)
        g_ActivationRadioSticky = 3;
    else
        g_ActivationRadioSticky = null;

    ShowIFrame('False');
    window.setTimeout("ShownavigatetoActPolicy();",500);
}

function VerifyReg3Fields() {
       g.error_mesg.style.display="none";
       var LastErrorField = null;

       var CurReg3ErrStringArray = new Array();

       // user needs to complete input of address/name
       // this dynamically builds the list of erroneous fields to give to the user

       if(g.UserEmailAddress.value != "") {
           // do some validation on email address
           // Note special regexpr char like '\S' must be double-\'d because they are inside a string
             var re = new RegExp("^\\s*\\S+@\\S+\\.\\S\\S+","");
             if(re.exec(g.UserEmailAddress.value) == null) {
                 LastErrorField = g.UserEmailAddress;
                 g.LabelEmail.className = "text-error";
             } else {
                 g.LabelEmail.className = "text-primary";
             }
       }

       var CurCountry=GetCurrentCountry();

       // dont require state or zip except for US/Canada
       if ((CurCountry == L_UnitedStates_Text)||(CurCountry == L_Canada_Text)) {
          if(g.UserZipCode.value == "") {
            LastErrorField = g.UserZipCode;
            g.LabelZIP.className = "text-error";
          } else {
             g.LabelZIP.className = "text-primary";
          }

          if(GetCurrentProvince() == "") {
             if(g.selUSState.style.display!="none") {
                LastErrorField = g.selUSState;
             } else {
                LastErrorField = g.selCAProvince;
             }
             g.StateLabel.className = "text-error";

          } else {
             g.StateLabel.className = "text-primary";
          }
       }


       if(g.UserCity.value == "") {
          LastErrorField = g.UserCity;
          g.LabelCity.className = "text-error";
       } else {
          g.LabelCity.className = "text-primary";
       }

       if(g.UserAddress.value == "") {
          LastErrorField = g.UserAddress;
          g.LabelAddress.className = "text-error";
       } else {
          g.LabelAddress.className = "text-primary";
       }

       if((g.UserLastName.value == "") && (g.LastNameRow.style.display!="none")) {
          LastErrorField = g.UserLastName;
          g.LabelLastName.className = "text-error";
       } else {
          g.LabelLastName.className = "text-primary";
       }

       if(g.UserFirstName.value == "") {
          g.LabelFirstName.className = "text-error";
          LastErrorField = g.UserFirstName;
       } else {
          g.LabelFirstName.className = "text-primary";
       }

       if(LastErrorField==null) {
           return true;
       }

       // handle error

       if(LastErrorField==g.UserEmailAddress) {
          g.error_mesg.innerText = L_Email_Text;
       } else {
          g.error_mesg.innerText = L_EnterValid_Text;
       }

       g.error_mesg.className = "text-error";
       g.error_mesg.style.display="inline";

        try
        {
            g.btnNext.disabled=false;
        }
        catch(e) {}
        try
        {
            g.btnBack.disabled=false;
        }
        catch(e) {}
        try
        {
            g.btnSkip.disabled=false;
        }
        catch(e) {}
        InitButtons();

        LastErrorField.focus();

       return false;
}

// Function: Start_CheckEnableNextButton
// Description: This function is called everytime a keyup
//      event fires on a edit box for first, middle, or last
//      name. We then see if we should enable or disable the
//      next button based on if every field has a value.
//      First || Last
//
function Start_CheckEnableNextButton()
{
    try
    {
        if (g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (Start_CheckLengthRequirement() &&
        Start_CheckLengthNotEqualSpaces())
    {
        g.btnNext.disabled = false;
    }
    else
    {
        g.btnNext.disabled = true;
    }
    InitButtons();
}

function Start_CheckLengthRequirement()
{
    if ((g.edt_FirstName.value.length != 0) ||
         (g.edt_LastName.value.length != 0))
        return true;
    else
        return false;
}

function Start_CheckLengthNotEqualSpaces()
{
    if ((g.edt_FirstName.value.length != NumberOfSpaces(g.edt_FirstName.value)) ||
         (g.edt_LastName.value.length != NumberOfSpaces(g.edt_LastName.value)))
        return true;
    else
        return false;
}
// END start.htm





//////////////////////////////////////////////////////////////////////////////////////
// General Default LoadMe function
//////////////////////////////////////////////////////////////////////////////////////
function _Default_LoadMe(SimpleBack, SimpleNext)
{
    InitFrameRef();
    CheckContrastMode();

    if (g.btnNext != null)
        g_FirstFocusElement = g.btnNext;
    else if (g.btnSkip != null)
        g_FirstFocusElement = g.btnSkip;
    else if (g.btnBack != null)
        g_FirstFocusElement = g.btnBack;

    InitButtons(SimpleBack, SimpleNext);
    if (g_FirstFocusElement != null)
        window.setTimeout("DoFocus();",1000);
    else
        g.document.body.focus();
}


function New_Default_LoadMe(SimpleBack, SimpleNext)
{
    InitFrameRef();
    GetPageTitle();
    CheckContrastMode();

    if (g.btnNext != null)
        g_FirstFocusElement = g.btnNext;
    else if (g.btnSkip != null)
        g_FirstFocusElement = g.btnSkip;
    else if (g.btnBack != null)
        g_FirstFocusElement = g.btnBack;

    InitButtons(SimpleBack, SimpleNext);

    window.setTimeout("DoFocus();",1000);
}


//////////////////////////////////////////////////////////////////////////////////////
// MISC Functions
//////////////////////////////////////////////////////////////////////////////////////


// Page Navigation

// InitCKPT, PushCKPT, PopCKPT, CKPTFromVal are meant to handle the behavior for GoBack.
// We only go back to certain pages (i.e., Mouse Tutorial, Sound Check).
// And on some of the pages, we only go back if they haven't been
// completed (i.e., EULA, PID).
//
// So, we push checkpoints if we intend to all coming back to that page.
// We pop checkpoints if we no longer want to come back (e.g., we've
// completed that page.

function InitCKPT()
{
    dnCKPT[CKPT_ACTIV]     = new CheckPoint("actsetup\\activ.htm",          0,     0,     0,     0);
    dnCKPT[CKPT_ACTDONE]   = new CheckPoint("actsetup\\actdone.htm",        0,     0,     0,     0);
    dnCKPT[CKPT_ACTIVERR]  = new CheckPoint("actsetup\\activerr.htm",       0,     0,     0,     0);
    dnCKPT[CKPT_ACTIVSVC]  = new CheckPoint("actsetup\\activsvc.htm",       0,     0,     0,     0);
    dnCKPT[CKPT_REGISTER1] = new CheckPoint("actsetup\\areg1.htm",          0,     0,     0,     0);
    dnCKPT[CKPT_REGISTER3] = new CheckPoint("actsetup\\ausrinfo.htm",       0,     0,     0,     0);
    dnCKPT[CKPT_ACTCONN]   = new CheckPoint("actsetup\\actconn.htm",        0,     0,     0,     0);
    dnCKPT[CKPT_ACTLAN]    = new CheckPoint("actsetup\\actlan.htm",         0,     0,     0,     0);
    dnCKPT[CKPT_REGDIAL]   = new CheckPoint("actsetup\\adrdyreg.htm",       0,     0,     0,     0);
    dnCKPT[CKPT_ACT_MSG]   = new CheckPoint("actsetup\\adeskerr.htm",       0,     0,     0,     0);
    dnCKPT[CKPT_DONE]      = new CheckPoint("actsetup\\aregdone.htm",       0,     0,     0,     0);
    PopCKPT();
}

function PushCKPT(ckpt)
{
  if (ckpt > 0 && ckpt < CKPT_MAX)
  {
    var tos = 0;
    try
    {
      tos = ApiObj.get_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, TOS_REG_VALUE);
    }
    catch (e) {}
    ApiObj.set_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, tos.toString(), ckpt);
    ApiObj.set_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, TOS_REG_VALUE, ++tos);
    g_CurrentCKPT = ckpt;
  }
}

function PopCKPT(ckptCheck)
{
  var ckpt = 0;
  try
  {
    var tos = ApiObj.get_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, TOS_REG_VALUE);
    if (tos > 0)
    {
      ckpt = ApiObj.get_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, (tos - 1).toString());

      if (null == ckptCheck || ckpt == ckptCheck)
      {
        ApiObj.set_RegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, TOS_REG_VALUE, --tos);
        ApiObj.DeleteRegValue(HKEY_LOCAL_MACHINE, OOBE_MAIN_REG_KEY + CKPT_REG_KEY, tos.toString());
      }
    }
  }
  catch (e) {}

  if (ckpt > 0 && ckpt < CKPT_MAX)
  {
    g_CurrentCKPT = ckpt;
  }
  else
    g_CurrentCKPT = null;
}

function URLFromCKPT(ckpt)
{
  var str = "";
  if (ckpt > 0 && ckpt < CKPT_MAX)
  {
    str = dnCKPT[ckpt].strURL;
  }
  return str;
}

function IndexFromCKPT(ckpt, status)
{
  var index = 0;
  if (ckpt > 0 && ckpt < CKPT_MAX)
  {
    var checkpoint = dnCKPT[ckpt];
    index = checkpoint.rgindex[status];
  }
  return index;
}



function IsLocalFile()
{
    try
    {
        return (-1 != g.location.protocol.indexOf("file"));
    }
    catch (e)
    {
        return false;
    }
}


//////////////////////////////////////////////////////////////////////////////////////
// public navigation APIs
//////////////////////////////////////////////////////////////////////////////////////


function SetBack(strURL)
{
    g_OEMAddBackURL = strURL;
}

function GoCancel(ckpt)
{
    trace("GoCancel: CurrentCKPT = " + g_CurrentCKPT);

    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    DisableAllButtons();

    switch (g_CurrentCKPT)
    {
        case CKPT_REGDIAL:
            if (InActivation_AppMode())
            {
                g_DoActivation = false;
                ShowIFrame('False');
                window.setTimeout("ExitWPA();",1000);
            }
            else
            {
                GoNavigate(CKPT_DONE);
            }
            break;
        case CKPT_REGISTER3:
            g_PostToMS = false;
            GoNavigate(CKPT_REGDIAL);
            break;

        case CKPT_ACTLAN:
            ActLan();
            break;
    }
}


function GoBack(ckpt)
{
    trace("GoBack: CurrentCKPT = " + g_CurrentCKPT);

    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    DisableAllButtons();

    if (g_CurrentCKPT == g_DialCKPT)
        ResetDialing();

    if(g_CurrentCKPT == CKPT_REGISTER1)
    {
        if (g.rb_reg_1.checked)
            g_Reg1RadioSticky = 1;
        else if (g.rb_reg_2.checked)
            g_Reg1RadioSticky = 2;
        else
            g_Reg1RadioSticky = null;
    }

    if(g_CurrentCKPT == CKPT_REGISTER3)
    {
        Reg3SaveSettings();  // save field settings in case we return to page
    }

    var ckptPrevious = g_CurrentCKPT;
    PopCKPT();

    if (ckptPrevious == g_CurrentCKPT)
    {
        // This handles the case where the current page pushed itself on the stack.
        PopCKPT();
    }

    if (g_CurrentCKPT > 0 && g_CurrentCKPT < CKPT_MAX)
    {
        GoNavigate(g_CurrentCKPT);
    }
}

function StatusNavigate()
{
    var iMove = IndexFromCKPT(g_CurrentCKPT, g_status) - window.external.get_StatusIndex;
    while (iMove > 0)
    {
        window.external.MoveNext();
        --iMove;
    }
    while (iMove < 0)
    {
        window.external.MovePrevious();
        ++iMove;
    }
}

////////////////////////////////////////////////////////////////////
// DON'T MUCK WITH THE POSITIONING OF THE CASES IN THE SWITCHS BELOW
////////////////////////////////////////////////////////////////////

function ShowGoNavigate()
{
var ckptGoHere = g_ckpt_target;
    switch (ckptGoHere)
    {
    case CKPT_REGDIAL:
        trace("GoNavigate: CKPT_REGDIAL");

        // Check if we are already connected
        ResetConnectedToInternetEx();
        if (!ConnectedToInternetEx(true))
        {
            // If not, try AutoDial
            g_InitAutodial = window.external.InternetAutodial();

            if (!g_InitAutodial)
            {
                // We can't assume user has modem here
                if (HasNetwork() && HasModem())
                {
                    GoNavigate(CKPT_ACTCONN);
                }
                else if (HasNetwork())
                {
                    GoNavigate(CKPT_ACTLAN);
                }
                else if (HasModem())
                {
                    PushCKPT(ckptGoHere);  // sets g_CurrentCKPT = ckptGoHere;
                    Navigate(URLFromCKPT(CKPT_REGDIAL));
                }
                else
                {
                    GoNavigate(CKPT_ACTIVERR);
                }

                SetTimerShowIFrame(15000);
                break;
            }
            else
            {
                g_Internet = INTERNET_YES;
            }
            
        }

        IcsConnect(ICS_CONN_TYPE_REG);
        SetTimerShowIFrame(ACTIVATION_TIMEOUT);
        break;

    case CKPT_ACT_MSG:
        trace("GoNavigate: CKPT_ACT_MSG");
        PushCKPT(ckptGoHere);  // sets g_CurrentCKPT = ckptGoHere;
        Navigate(URLFromCKPT(ckptGoHere));
        SetTimerShowIFrame(5000);
        break;

    default:
        trace("GoNavigate: default (" + ckptGoHere + " = " +
              URLFromCKPT(ckptGoHere) + ")");
        PushCKPT(ckptGoHere);  // sets g_CurrentCKPT = ckptGoHere;
        Navigate(URLFromCKPT(ckptGoHere));
        SetTimerShowIFrame(1200);
        break;
    }
}

var g_ckpt_target = null;
var g_AfterConnectionDone = false;
function GoNavigate(ckptGoHere)
{
    try
    {
        if (g_bStartup == false)
        {
            if (IsLocalFile())
            {
                if (g.event != null)
                {
                    g.event.returnValue = false;
                    g.event.cancelBubble = true;
                }
            }
        }
        else
            g_bStartup = false;

    }
    catch(e)
    {
        return;
    }

    g_ckpt_target = ckptGoHere;

    var L_GeneratingInstall_Text = "Generating new Installation ID...";
    var L_RetrievingCountry_Text = "Retrieving Installation ID...";
    var L_ValidatingConn_Text    = "Verifying activation...";


    if (ckptGoHere==CKPT_REGDIAL)
    {
        ShowIFrame('False', L_CheckConnectivity_Text);
        Span_WPA_MainTitle.innerText = L_BlankTitle_Text;
    }
    else  if (ckptGoHere==CKPT_ACTIVSVC)
    {
        if (g_ActivSvc_Reload)
        {
            if (g_Load_InstallID)
                ShowIFrame('False', L_GeneratingInstall_Text);
            else
                ShowIFrame('False', L_RetrievingCountry_Text);

            Span_WPA_MainTitle.innerText = L_BlankTitle_Text;
        }
        else
        {
            g_ActivSvc_Reload = true;
        }
    }
    else if (ckptGoHere==CKPT_ACT_MSG)
    {
        if (g_AfterConnectionDone)
        {
            g_AfterConnectionDone = false;
            ShowIFrame('False', L_ValidatingConn_Text);
            Span_WPA_MainTitle.innerText = L_BlankTitle_Text;
        }
        else
            ShowIFrame('False');
    }
    else
    {
        ShowIFrame('False');
    }

    window.setTimeout("ShowGoNavigate();",500);
}

function ExitWPA()
{
    window.external.Finish();
}

// Description: Disable all the buttons
// Used to prevent script error caused by
// double clicking or rapid clicking
// of two different buttons. E.g. when someone click
// next and back quickly.
//
function DisableAllButtons()
{
    g.document.body.style.cursor="wait";
    try
    {
        g.btnNext.className="buttons-disabled";
        g.btnNext.disabled=true;
    }
    catch(e) {}
    try
    {
        g.btnBack.className="buttons-disabled";
        g.btnBack.disabled=true;
    }
    catch(e) {}
    try
    {
        g.btnSkip.className="buttons-disabled";
        g.btnSkip.disabled=true;
    }
    catch(e) {}
    try
    {
        g.btnProdkey.className="buttons-disabled";
        g.btnProdkey.disabled=true;
    }
    catch(e) {}
    try
    {
        g.btnQuit.className="buttons-disabled";
        g.btnQuit.disabled=true;
    }
    catch(e) {}
    try
    {
        g.btnTelephone.className="buttons-disabled";
        g.btnTelephone.disabled=true;
    }
    catch(e) {}

}

function GoQuit()
{
    trace("GoQuit: CurrentCKPT = " + g_CurrentCKPT);

    // var L_strCloseWindow_Text ="Click OK to exit registration reminder.";
    // if (confirm(L_strCloseWindow_Text))
    DisableAllButtons();
    window.external.Finish();
}

function GoNext()
{
    trace("GoNext: CurrentCKPT = " + g_CurrentCKPT);
    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    DisableAllButtons();

    switch (g_CurrentCKPT)
    {
        case CKPT_ACTIV:
            if (g.rb_act_1.checked)
            {
                g_ActivationRadioSticky = 1;
                g_DoActivation = true;

                if (CheckForAnyConnection())
                {
                    if (TapiObj.IsTapiServiceRunning())
                    {
                        GoNavigate(CKPT_REGISTER1);
                    }
                    else
                    {
                        GoNavigate(CKPT_REGDIAL);
                    }
                }
                else
                {
                    g_PostToMS = false;
                    GoNavigate(CKPT_ACTIVERR);
                }
            }
            else if (g.rb_act_2.checked)
            {
                g_ActivationRadioSticky = 2;
                g_DoActivation = false;
                g_CameFromFirstPage = true;
                GoNavigate(CKPT_ACTIVSVC);
            }
            else
            {
                g_ActivationRadioSticky = 3;
                g_DoActivation = false;
                ShowIFrame('False');
                window.setTimeout("ExitWPA();",1000);
            }
            break;

        case CKPT_REGISTER1:
            if (g.rb_reg_1.checked)
            {
                g_Reg1RadioSticky = 1;
                g_PostToMS = true;
                GoNavigate(CKPT_REGISTER3);
            }
            else
            {
                g_Reg1RadioSticky = 2;
                g_PostToMS = false;
                GoNavigate(CKPT_REGDIAL);
            }
            break;

        case CKPT_ACTIVERR:
            GoNavigate(CKPT_ACTIVSVC);
            break;
        case CKPT_ACTIVSVC:
            GoNavigate(CKPT_DONE);
            break;
        case CKPT_REGISTER3:
            if(VerifyReg3Fields())
            {
                Reg3SaveSettings();
                GoNavigate(CKPT_REGDIAL);
            }
            break;
        case CKPT_ACTCONN:
            if (g.rb_conn_lan.checked)
            {
                g_ActConnRadioSticky = 1;
                GoNavigate(CKPT_ACTLAN);
            }
            else
            {
                g_ActConnRadioSticky = 2;
                PushCKPT(CKPT_REGDIAL);
                Navigate(URLFromCKPT(CKPT_REGDIAL));
            }
            break;
        case CKPT_ACTLAN:

            ProxySettingsObj.UseAuto = g.cb_auto_detect.checked;
            ProxySettingsObj.UseProxy = g.cb_use_proxy.checked;
            ProxySettingsObj.Server = g.txt_proxy_url.value;
            ProxySettingsObj.Port = g.txt_proxy_port.value;

            window.external.set_ProxySettings(
                ProxySettingsObj.UseAuto,
                ProxySettingsObj.UseScript,
                ProxySettingsObj.ScriptUrl,
                ProxySettingsObj.UseProxy,
                ProxySettingsObj.Server + ((ProxySettingsObj.Port == "") ? "" : (":" + ProxySettingsObj.Port))
                );

            ActLan();
            break;
        case CKPT_REGDIAL:
            GoNavigate(CKPT_DONE);
            break;
        case CKPT_ACT_MSG:
            if ( g_ActivationStatus != ERR_ACT_SUCCESS )
            {
                GoNavigate(CKPT_ACTIVSVC);
                break;
            }
            // Fall through
        case CKPT_DONE:
            window.external.Finish();
            break;

        default:
            // BUGBUG should we remove the default altogether?
            break;
    }
}


// BUGBUG temporary until MSN changes code
function GoOffline()
{
    GoNext();
}


// Button Event Handlers and Initialization
function SetLastButtonText()
{
    if (g.btnNext != null)
        g_LastButtonText = g.btnNextText;
    else if (g.btnBack != null)
        g_LastButtonText = g.btnBackText;
    else if (g.btnRestore != null)
        g_LastButtonText = g.btnRestoreText;
    else if (g.btnCancel != null)
        g_LastButtonText = g.btnCancelText;
}

// Function: InitFrameRef
// Description: Sets up globals to point to buttons
//    Since the buttons exist on the child frame,
//    we want to have quick access to them without
//    going through the collections.
//    WARNING: Call this function at the top of XXX_LoadMe()
//
function InitFrameRef()
{

    g_LastButtonText = null;
    g_FirstFocusElement = null;
    g_LastKeyDown = null;

    g = document.frames("msoobeMain");
    g.document.body.style.backgroundColor = "transparent";

    try
    {
        g.document.body.onkeydown = OnKeyDown;
        SetLastButtonText();
    }
    catch(e){}
}

function HideButtons(buttons)
{
    if (null != g.btnBack && (buttons & HIDE_BACK))
    {
        g.btnBack.Hide = true;
    }

    if (null != g.btnNext && (buttons & HIDE_NEXT))
    {
        g.btnNext.Hide = true;
    }


    if (null != g.spanCancel && (buttons & HIDE_CANCEL))
    {
        g.btnSkip.Hide = true;
    }

    if (null != g.spanRestore && (buttons & HIDE_RESTORE))
    {
        g.btnRestore.Hide = true;
    }

}

function HandleButtonMouseOver()
{
//   if((!this.disabled)&&(this.tagName=="BUTTON"))
//      this.className="buttons-hover";
}

function HandleButtonMouseOut()
{
//   if((!this.disabled)&&(this.tagName=="BUTTON"))
//      this.className="buttons";
}

function InitButtons(SimpleBack, SimpleNext)
{
    if(g.btnSkip!=null) {
      g.btnSkip.onmouseover = HandleButtonMouseOver;
      g.btnSkip.onmouseout  = HandleButtonMouseOut;

      if(!g.btnSkip.disabled) {
          g.btnSkip.onclick = GoCancel;

// dont enable onfocus,onblur handlers until issues in 88615 are resolved
//          g.btnSkip.onfocus = HandleButtonMouseOver;
//          g.btnSkip.onblur = HandleButtonMouseOut;

          g.btnSkip.className="buttons";
      } else {
        g.btnSkip.className="buttons-disabled";
      }
    }

    if (g.btnNext != null)
    {
        g.btnNext.onmouseover = HandleButtonMouseOver;
        g.btnNext.onmouseout  = HandleButtonMouseOut;

        if (!g.btnNext.disabled)
        {
            if (SimpleNext == null)
            {
                g.btnNext.onclick = GoNext;
            }
            else
            {
                g.btnNext.onclick = SimpleNavNext;
            }
            g.btnNext.className="buttons";
        }
        else
        {
            g.btnNext.className="buttons-disabled";
        }
    }

    if (g.btnBack != null)
    {
        g.btnBack.onmouseover = HandleButtonMouseOver;
        g.btnBack.onmouseout  = HandleButtonMouseOut;

        if (!g.btnBack.disabled)
        {
            if (SimpleBack == null)
            {
                g.btnBack.onclick = GoBack;
            }
            else
            {
                g.btnBack.onclick = SimpleNavBack;
            }
            g.btnBack.className="buttons";
        }
        else
        {
            g.btnBack.className="buttons-disabled";
        }
    }

    try
    {
        if(g.btnQuit != null) {
          g.btnQuit.onmouseover = HandleButtonMouseOver;
          g.btnQuit.onmouseout  = HandleButtonMouseOut;


          if(g.btnQuit.disabled == false) {
              g.btnQuit.onclick = GoQuit;
              g.btnQuit.className="buttons";
          } else {
            g.btnQuit.className="buttons-disabled";
          }
        }
    } catch(e) {}

    window.setTimeout("EnableDefaultCursor();",500);
}

function EnableDefaultCursor()
{
    g.document.body.style.cursor="default";
}

var g_LastKeyDown = null;
function OnKeyDown()
{
    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (g.event.altKey)
    {
        g_LastKeyDown = String.fromCharCode(g.event.keyCode);
        if (g_LastKeyDown != null)
            g_LastKeyDown = g_LastKeyDown.toUpperCase();
    }
    else
        g_LastKeyDown = null;
}

// VALIDATION ROUTINES
function KeyPressIsNumeric()
{
    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (!IsNumeric(g.event.keyCode))
    {
        g.event.keyCode = 0;
        g.event.returnValue = false;
    }
}

function IsNumeric(keyCode)
{
    if ((keyCode >= 48/*0*/)  && (keyCode <= 57/*9*/))
        return true;
    else
        return false;
}

function IsSpecial(keyCode)
{
// BUGBUG DISABLED FOR BETA
/*
    var bFound = false;
    var iPosition = 0;
    for (;iPosition < g_SpecialChars.length; iPosition++)
    {
        if (g_SpecialChars.charCodeAt(iPosition) == keyCode)
        {
            bFound = true;
            break;
        }
    }
    return bFound;
*/
return false;
}

function KeyPressIsValid()
{
    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (!IsAlpha(g.event.keyCode) &&
        !IsSpecial(g.event.keyCode) &&
        !IsNumeric(g.event.keyCode))
    {
        g.event.keyCode = 0;
        g.event.returnValue = false;
    }
}

function KeyPressIsAlpha()
{
    try
    {
        if (IsLocalFile() && g.event == null)
            return;
    }
    catch(e)
    {
        return;
    }

    if (!IsAlpha(g.event.keyCode))
    {
        g.event.keyCode = 0;
        g.event.returnValue = false;
    }
}

function IsAlpha(keyCode)
{
// BUGBUG DISABLED FOR BETA
/*
    var strKeyCode = String.fromCharCode(keyCode);
    var re1 = new RegExp("\w");
    var re2 = new RegExp("\D");

    strKeyCode.match(re1);
    strKeyCode.match(re2);
    //return ((strKeyCode.match(re1) != null)  && (strKeyCode.match(re2) != null));
*/
//    if ((keyCode >= 97/*a*/ && keyCode <= 122/*z*/) ||
//        (keyCode >= 65/*A*/ && keyCode <= 90 /*Z*/))
        return true;
//    else
//        return false;
}

function NumberOfSpaces(strValue)
{
/*
    var NASexp = RegExp("\s");
    var result = strValue.match(NASexp);
    return ((result == null) || (result.length != strValue.length));
*/
    var iSpaceCount = 0;
    for (iPosition = 0; iPosition < strValue.length; iPosition ++)
    {
        if (strValue.charAt(iPosition) == ' ')
        {
            iSpaceCount++;
        }
    }
    return iSpaceCount;
}
function KeyCodeToUpper()
{
    var strKeyCode = String.fromCharCode(g.event.keyCode);
    strKeyCode = strKeyCode.toUpperCase();
    g.event.keyCode = strKeyCode.charCodeAt(0);
}

// END VALIDATION ROUTINES

var vCurItem = 0;

function SetupPageLayout()
{
    var WPAWindowHeight = document.body.clientHeight;
    var WPAWindowWidth  = document.body.clientWidth;

    if(0 != window.external.Directions.get_AppMode())
    {
        document.all.ifrmMainFrame.style.height = WPAWindowHeight - 93;
        document.all.ifrmMainFrame.style.width  = WPAWindowWidth;
    }

    WPABackground.src = 'images/wpaback.jpg';
    WPAKey.src        = 'images/wpakey.jpg';
    WPATop.src        = 'images/wpatop.jpg';
    WPABottom.src     = 'images/wpabtm.jpg';
    WPAFlag.src       = 'images/wpaflag.jpg';

    WPABottom.style.top = WPAWindowHeight - 45;
    WPAKey.style.left   = WPAWindowWidth - 237;
    WPAKey.style.top    = WPAWindowHeight - 315;

}

function CheckForAnyConnection()
{
    var Capabilities = GetConnectionCapabilities();

    return (Capabilities != CONNECTIONTYPE_INVALID &&
            Capabilities != CONNECTIONTYPE_NONE);
}


var g_fSIFTimer = false;
var g_iSIFTimerID;
function SetTimerShowIFrame(iMilliSeconds)
{
    // This function is intended to wrap SetTimer calls to ShowIFrame
    // so that we don't get multiple overlapping calls to Show the IFrame
    if (g_fSIFTimer)
    {
        try
        {
            window.clearTimeout(g_iSIFTimerID);
        }
        catch(e) {}
        g_fSIFTimer = false;
    }

    g_iSIFTimerID = window.setTimeout("ShowIFrame();", iMilliSeconds);
    g_fSIFTimer = true;
}

var g_ShowTransition = false;
function ShowIFrame(ShowIt, loadingstatus)
{
    // Kill an existing timers
    if (g_fSIFTimer)
    {
        try
        {
            window.clearTimeout(g_iSIFTimerID);
        }
        catch(e) {}
        g_fSIFTimer = false;
    }

    if (g_ShowTransition)
    {
        WPATransContainer.filters[0].Apply();
    }

    if (ShowIt == null)
    {
        // Show Iframe
        WPA_DIV2.style.visibility="visible";
        WPA_DIV1.style.visibility="hidden";
        PageStatus.style.visibility="hidden";
        WPAProgressbar.style.visibility = "hidden";

        if (g_ShowTransition)
        {
            WPATransContainer.filters[0].Play();
        }
    }
    else
    {
        // Hide Iframe
        WPA_DIV2.style.visibility="hidden";
        WPA_DIV1.style.visibility="visible";

        if (g_ShowTransition)
        {
            WPATransContainer.filters[0].Play();
        }

        // Show progress text...
        if (loadingstatus!=null)
        {
            PageStatus.style.visibility="visible";
            PageStatus.innerHTML=loadingstatus;
            WPAProgressbar.style.visibility = "hidden";  // lets hide this for now...
        }
        else
        {
            PageStatus.style.visibility="hidden";
            WPAProgressbar.style.visibility = "hidden";
        }
    }
}

window.onresize = SetupPageLayout;
var g_Already_Activated;
function InitApplication()
{

    // Make sure all the services have started up
    window.external.ComputerNameChangeComplete(false);
    WPATransContainer.style.display="inline";

    try
    {
        g_Already_Activated = window.external.NeedActivation();
    }
    catch(e)
    {
        g_Already_Activated = 999;
    }

    // 0 means activation is not needed or has already occurred.


    if (g_Already_Activated == 0)
    {
        // If we're here, Windows is already activated and all we need is to show CKPT_ACTDONE.
        SetupPageLayout();
        InitFrameRef();
        g_status = STATUS_OFF;
        g_DoActivation = false;
        InitCKPT();
        if (0 != DirObj.get_AppMode)
        {
            do
            {
                PopCKPT();
            }
            while (null != g_CurrentCKPT);
        }
        GoNavigate(CKPT_ACTDONE);
        SetTimerShowIFrame(900);
    }
    else if (g_Already_Activated == 999)
    {
        window.external.Finish();
    }
    else
    {
        SetupPageLayout();
        g_bStartup = true;
        InitFrameRef();
        GetConnectionCapabilities();
        g_status = STATUS_OFF;
        g_DoActivation = true;
        CheckForAnyConnection();
        InitCKPT();
        // if we are in appmode, we must nuke the stack and restart each time
        if (0 != DirObj.get_AppMode)
        {
            do
            {
                PopCKPT();
            }
            while (null != g_CurrentCKPT);
        }
        GoNavigate(CKPT_ACTIV);
        SetTimerShowIFrame(900);
    }
}

function loadTransitionFilter()
{
    document.all.WPATransContainer.style.display = "none";
    document.all.WPATransContainer.style.position = "absolute";
    document.all.WPATransContainer.style.top = 0;
    document.all.WPATransContainer.style.left = 0;
    document.all.WPATransContainer.style.width = "100%";
    document.all.WPATransContainer.style.height = "100%";

    if ((window.screen.colordepth >= 16) && window.external.UseFadeEffect())
    {
        document.all.WPATransContainer.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=0.2,overlap=0.8)";

        try
        {
            if (WPATransContainer.filters[0])
            {
                g_ShowTransition = true;
            }
        }
        catch(e)
        {
        }
    }
}

</script>

</HEAD>

<BODY topMargin=0 bgcolor="#4E6FD6" leftMargin=0 onload="loadTransitionFilter();InitApplication();" scroll=no tabIndex=-1 rightMargin=0>
    <!-- WPA images, dynamic layout positioning will be done in SetupPageLayout() function  -->
    <IMG ID=WPABackground style="LEFT: 0px; TOP: 0px; POSITION: absolute; z-index:-99;" alt="">
    <IMG ID=WPAKey        style="LEFT: 0px; TOP: 0px; POSITION: absolute; z-index:-98;" alt="">
    <IMG ID=WPATop        style="LEFT: 0px; TOP: 0px; POSITION: absolute; z-index:-97;" alt="">
    <IMG ID=WPABottom     style="LEFT: 0px; TOP: 0px; POSITION: absolute; z-index:-96;" alt="">

    <!-- Don't alter this table structure. It's designed to support BiDi and Non-BiDi. -->
    <TABLE WIDTH="95%" BORDER=0 style="POSITION: absolute; LEFT: 20px; TOP: 0px;" CELLPADDING=0 CELLSPACING=0>
    <TR>
        <TD nowrap VALIGN=MIDDLE>
        <SPAN id=Span_WPA_MainTitle class="title" style="height: 28px;" tabIndex=-1>
        </SPAN>
        </TD>

        <TD WIDTH="99%">&nbsp;
        </TD>

        <TD VALIGN=TOP>
        <IMG ID=WPAFlag alt="">
        </TD>
    </TR>
    </TABLE>

    <span ID="WPATransContainer">

          <!-- First Content (by design, don't remove) -->
          <span ID="WPA_DIV1" STYLE="POSITION: absolute; left:0; top:0; width=100%; height=100%; background-Color: transparent;">
          <table border=0 width="100%" height="100%" class="text-primary">
          <tr>
              <td valign=middle align=center>
                  <span id=PageStatus></span>
                  <br>
                  <span id=WPAProgressbar style="visibility:hidden;"><img src="images/progress.gif"></span>
              </td>
          </tr>
          </table>
          </span>

          <!-- Actual Content -->
          <span id="WPA_DIV2" style="visibility: hidden; POSITION: absolute; LEFT: 0px; TOP: 48px; width=100%; height=100%;" tabIndex=-1>
          <IFRAME ALLOWTRANSPARENCY="true" frameBorder=no width="100%" height="100%" id=ifrmMainFrame name=msoobeMain src="about:blank" tabIndex=0></IFRAME>
          </span>
    </span>
</BODY>
</HTML>