// creates the home page with js and doc.write, does all work for registration, password etc.
// this is at home.html level, so parent means index.html even when loaded
// 10-20-11: modify the home page write up, eliminate dead link to japanese or spanish test.
// 10-19-11: use bVALIDLIC, linkStyleUL
// 10-18-11: expired license redirect
// v 1.21 bug in Texas A & M during registration...
// v 1.20 invite button
// v 1.19: redirect to myAccount on expiration, username cookie write modified
// v 1.18: No auto log in - redirect...
// v 1.17 filter fields during login for ', " etc.
// v 1.16 change alertLocal slightly as popupT.js has changed.
// v 1.15: sendPW v 1.14: pushed. temp for Tech de Monterry. A lot of changes in writecookie..
// v 1.13: link to newmyaccount v 1.12: message of day
// cosmetic v 1.11 features images instead of video; 1.10 eliminate reg.js
// v 1.9: tab header bug..
// v 1.11: timeout login as visitor
//
Home = Class.create();

//variables in the scope of this class

Object.extend(Home.prototype, {

    // message of the day is prepared here...
    initialize: function(){
        var sMirrorMsg = 'To reliably access TEST, bookmark two independent locations: ';
        sMirrorMsg +='<ul><font color="#0088bb"><li/>www.thermofluids.net<font color="#555555">: Multiple servers make this most reliable.</font><p/>';
        sMirrorMsg +='<li/>www.iddl.vt.edu/TEST/<font color="#555555">: Mirror in the east coast of USA.</font><p/>';
        sMirrorMsg +='<li/>www.sfsb.hr/test/<font color="#555555">: Mirror in Europe.</font><p/>';
        sMirrorMsg +='<li/>www.fing.edu.uy/if/mirror/TEST/<font color="#555555">: Mirror in South America.</font><p/>';
        sMirrorMsg +='</font></ul><p/><font color="#000000">If your institution is interested in mirroring (for faster access speed), please let us know at support@thermofluids.net.</font>';

        var sCacheMsg = 'This latest update of TEST (version 10.303) includes several improvements, some are obvious and some are subtle.<p/>';
        sCacheMsg += 'If a page does not look right (blank or unforatted page, unresponsive links, etc.), clear the browser cache and reload a fresh copy from <i>www.thermofluids.net</i>. ';

        switch (parent.sBROWSER.toLowerCase()){
            case 'ie':
                sCacheMsg += "<p/>Since you are using "+ parent.sBROWSER +", do the following: (a) Select Tools>Internet Options from the Internet Explorer menu, (b) select the General (default) tab, (c) click the 'Delete...' button in the 'Browsing history' block, (d) select all checkboxes, and (e) click the 'Delete' button.   ";
                break;
            case 'firefox':
                sCacheMsg += "<p/>Since you are using "+ parent.sBROWSER +", do the following: (a) Select Tools>Options from the Firefox menu, (b) select the Privacy tab, and (c) click on the link 'clear your recent history'. ";
                break;
            case 'chrome':
                sCacheMsg += "<p/>Since you are using "+ parent.sBROWSER +", do the following: (a) Select Tools (wrench icon) >Options from the Chrome menu, (b) click on 'Under the Hood' tab, and (c) click the 'Clear browsing data...' button.";
                break;
            case 'safari':
                sCacheMsg += "<p/>Since you are using "+ parent.sBROWSER +", do the following: (a) Select Tools (wrench icon) >Options from the Chrome menu,(b) click the 'Clear browsing data...' button, (c) select all checkboxes, and (d) click the 'Clear browsing data' button.";
                break;
            default : sMsg = "Do the following: (a) Select Tools>Options from the Firefox menu, (b) select the Privacy tab, and (c) click on the link 'clear your recent history'. ";
        }

        this.sMsgOfDay = sCacheMsg ;
        this.oMODExpirs = new Date(2012,3,15);
    },

    // inset popup in home page, sElement popup identifier.
    alertFloat: function (sElement, sMessage){
        var oPopup = new PopupT(sElement);
        oPopup.alertFloat(sMessage);
    },
    // inset popup in any element
    alertInElement: function (sElement, sMessage){
        var oPopup = new PopupT(sElement);
        oPopup.alert(sMessage);
    },
    // inset popup in home page
    alertLocal: function (sMessage){
        var oPopup = new PopupT('alertBox');
        oPopup.alert(sMessage);
        xRemoveClass($('alertBox'), 'hide');
        xAddClass($('alertBox'), 'show');
    },
    // inset popup in home page with cyan bg
    alertLocalSoft: function (sMessage){
        var oPopup = new PopupT('alertBox');
        oPopup.alertSoft(sMessage);
        xRemoveClass($('alertBox'), 'hide');
        xAddClass($('alertBox'), 'show');
    },
    //trap Enter for different account activities
    handleEnter: function(){
        var args = $A(arguments);
        var e = args.shift(); // Event object
        var oThis = args.shift();
        var sBlock = args.shift();
        var keyPressed = e.which || e.keyCode;
        if (keyPressed == 13 ) {
            if (sBlock == 'login') this.handleLogInClick();
            if (sBlock == 'sendpw') this.handleSendPWClick();
            if (sBlock == 'changepw') this.handleChangePWClick();
            if (sBlock == 'createac') this.handleCreateACClick();
        }
    },


    //site checkbox has been clicked or unchecked.
    handleSiteLogInClick: function(){
        if($('sitebox').checked){
            $('userid').value = '';
            this.handleLogInClick();
        }
    },

    //test if email is really an email
    bTestEmail: function(sID){
        //return true;
        var sPattern = '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
        var orPattern  =  new RegExp(sPattern,"gi");
        return sID.search(orPattern) != -1;
    },
    //test if only english alphabets are used, utf8 will allow us to have any char now...
    bTestAToZ: function(s,n){
        return s.trim().length>=n;
    },
    //test if pw is acceptable
    bTestPW: function(sPW){
        //var sPattern = "[^A-Za-z 0-9 \.,\?'""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*";
        //var sPattern = '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
        //var sPattern = '^[A-Za-z0-9\$\%\*\!\@]+';
        //var orPattern  =  new RegExp(sPattern,"gi");
        //return sPW.search(orPattern) != -1;
        return true;
    },

    //php based ajax call for login.
    handleLogInClick: function(){
        //0. check site checkbox, read email and password
        var bSite = $('sitebox').checked;
        var sID = $('userid').value.trim();
        if (sID == '')bSite = true;
        //if(sID.trim() == '') bSite = true;
        var sPW = $('password').value.trim();
        var bEmail;
        if (!bSite) bEmail = this.bTestEmail(sID);
        if(!bSite && !bEmail){
            this.alertLocal("The login id is the email you used during creation of the TEST account. If you do not have an account, create one in seconds by clicking the 'create an account' link above.  ");
            return;
        }
        if(bSite){
            document.getElementById('userid').value = '';
            document.getElementById('password').value = '';
        }
        $('loginbutton').disable();

        //php based ajax call
        //PHPSERVLETPATH is the target URL set by iDEBUG in GlbalHome
        var oBlogSynch = new SynchronizerPHP("ajaxcodes/phpcurl/", parent.PHPSERVLETPATH);
        var sInJSON = '{"sID": "' + sID + '", "sPW": "' + sPW +'"}';
        oBlogSynch.standardUpdate(sInJSON, 'authenticator.php', this.logInCallback, this);
    },


    // callback after all the cookie arrive
    logInCallback: function() {
        // 0. get data from json
        var args = $A(arguments);
        var oSynchronizer = args.shift(); // to nullify
        var sJSON = args.shift();  // all info comes back in it
        var oThis = args.shift();   // want this

        // 5. enable login button even before the try block
        try{
            // 7. extract inJson
            var oRpatt = /\{.*\}/; //extract json from verbose return string
            var asJson = sJSON.match(oRpatt);
            if( asJson!=null && asJson.length == 1) sJSON = asJson[0];
            var oInData = eval("(" + sJSON + ")"); // object containing form data

            // 10. handle error and warning
            if(oInData.iError >0) {
                $('loginbutton').enable();
                oThis.alertBadLogin(oThis,oInData.iError);
                return;
            }

            // 15. set globals
            parent.iWARNING = oInData.iWarning; //warning message cannot be displayed as render will be called again..
            //parent.bottomPanel.showLogout();
            parent.bLOGIN = true;
            parent.GLOBALCOOKIE = oInData.sCookie;//index must be a parent
            parent.sSERVEREXP = oInData.sServerExp;//index must be a parent
            var oD = new Date(oInData.iRegistrationTime*1000);
            parent.sREGYEAR = oD.getFullYear();
            parent.tEXPIRATION = oThis.tGetExpTime(parent.COOKIELIFE); // maybe bring cookielife from server?
            parent.setGlobalVars(); //update the web cookie and other vars ...
            //
            // 20. write cookies if permitted for easy tabbing, next login, myaccount access, by individual user.
            if (parent.GLOBALCOOKIE.indexOf('user@site.edu') == -1)  oThis.writeCookies(oThis,oInData);

            //25. expired license in web edition? send to myAccount login page

            if(parent.asCOOKIEITEM[parent.accessIndex] == 0 && parent.asCOOKIEITEM[parent.mediaIndex]=="WEB") {
                var oExpiryDate = new Date(parent.asCOOKIEITEM[parent.expiryIndex] * 1000); //time in msec
                var nDiff = (oExpiryDate.getTime()-oD.getTime())/(1000*3600*24).toFixed(0);
                var bNewUser = (nDiff<100);
                parent.bottomPanel.changeClassName("myAccount");
                //new and old students
                var sMyAccount = parent.MYACCOUNTURL.split('.')[0]+'fwd'; //homelicense.html
                if     (oInData.iClassification == 1 && bNewUser) sMyAccount = sMyAccount+'STDNEW'+'.html';
                else if(oInData.iClassification == 1 && !bNewUser) sMyAccount = sMyAccount+'STDOLD'+'.html';
                else if(oInData.iClassification == 2 && bNewUser) sMyAccount = sMyAccount+'EDUNEW'+'.html';
                else if(oInData.iClassification == 2 && !bNewUser) sMyAccount = sMyAccount+'EDUOLD'+'.html';
                else if(oInData.iClassification == 3 && bNewUser) sMyAccount = sMyAccount+'PRONEW'+'.html';
                else if(oInData.iClassification == 3 && !bNewUser) sMyAccount = sMyAccount+'PROOLD'+'.html';
                else sMyAccount = sMyAccount+'.html';
              //alert('filename: '+sMyAccount);
                //self.location = sMyAccount;
                window.open(sMyAccount, 'licenseWindow');
                //return;
            }
            parent.bottomPanel.showLogout();

            // 25. reload page, login block will be wiped out by the render method...
            self.location = "home.html"; // this will call render again...
        }
        catch(err){
            oSynchronizer = null;
            // allow limited entry...
            alert("The mirror you are accessing TEST from is not fully updated. Redirecting you to a more up-to-date server...");
            parent.location.href = "http://thermofluids.sdsu.edu";
            return;
        }
        oSynchronizer = null;
        return;
    },

    //padd now with iLife s and return t in msec
    tGetExpTime: function (iCOOKIELIFE){
        var oToday = new Date();
        var tLife = iCOOKIELIFE*1000; //in msec
        oToday.setTime(oToday.getTime()+tLife);
        var tEXPIRATION = oToday.getTime();
        return tEXPIRATION;
    },

    // display alert messages, failed login attempt..
    alertBadLogin: function(oThis, iError){
        var sMsg = "";
        switch (iError){
            case 5:
                sMsg = "Your login id is valid, but the password did not match. In case you do not remember the password, you can have it mailed to you by following the 'Forgot password?' link above. Also, you can reset your password to something simple to remember by following the 'Change password' link above. If the problem persists, please contact us at support@thermofluids.net.";
                //$('password').style.backgroundColor = '#ff5555';
                xRemoveClass($('password'), 'yellowbg');
                xAddClass($('password'), 'redbg');

                break;
            case 10:
                sMsg = "The email address that you entered does not match with any user account. If you do not have a TEST account, you can create one in seconds by following the 'Create an Account' link in the login block.";
                //$('userid').style.backgroundColor = '#ff5555';
                xRemoveClass($('userid'), 'yellowbg');
                xAddClass($('userid'), 'redbg');


                break;
            case 15:
                sMsg = "You are already logged in from several different IP addresses. Either you forgot to logout or someone else is using your account (if you suspect so, please change your password by following the link above). We have initiated a server-side logout, which will take 15 minutes. Please try to login again after 15 minutes. We regret this inconvenience. ";
                break;
            case 20:
                sMsg = "The server is trying to log you out from your unfinished sessions. The default time interval is 15 minutes. Please try after some time.  ";
                break;
            case 50:
                sMsg = "It appears that your campus does not have a site license yet. For a free academic site license, log onto MyAccount (click the MyAccount tab on the task bar) where you can make the licensing request.";
                break;
            case 100:
                sMsg = "Error: There was a problem connecting to the TEST user database. If the problem persists, please report this error (Error code 100) to support@thermofluids.net.";
                break;
            default : sMsg = "Please check your network connection and try again. If the problem persists, please report this error message (id:" + iError + ") to support@thermofluids.net. Thank you!";
        }
        oThis.alertLocal(sMsg);
    },


    // display alert messages, failed login attempt..
    alertBadWarning: function(oThis, iWarning){
        var sMsg = "";
        switch (iWarning){
            case 5:
                sMsg = "You are currently logged in from another IP address. Perhaps, you forgot to logout from your previous session. When you are done with the current session, please remember to logout. ";
                oThis.alertLocalSoft(sMsg);
                break;
            case 10:
                sMsg = "When you open TEST on a new tab, there is no need to enter your login id or password again, just click the login button. ";
                oThis.alertLocalSoft(sMsg);
                break;
            case 25:
                sMsg = "You are seeing this message because: (i) your internet access is experiencing problem, (ii) you are accessing a mirror that is not updated correctly, (iii) the registration server of TEST is down (very unlikely), or (iv) there is a problem with your account. <p/>Please try to access TEST from www.thermofluids.net, thermofluids.sdsu.edu, or test.sdsu.edu and try again.  If you see this message everytime you try to log in, please contact us so that we can correct the problem (support@thermofluids.net). We regret this inconvenience.";
                 oThis.alertLocal(sMsg);
               break;
            default : sMsg = "Please check your network connection and try again. If the problem persists, please report this warning (id:" + iWarning + ") to support@thermofluids.net. Thank you!";
        }
        //oThis.alertLocal(sMsg);
    },


    // set more globals and set a cookie if permitted (only for ind. user, not site)
    writeCookies: function(oThis, oInData){
        //0. set ThermoCookie  2 hours expiration time in parent for cookielife sec -  2 hours?

        var oToday = new Date();
        var iLife = parent.COOKIELIFE*1000; //in msec
        oToday.setTime(oToday.getTime()+iLife);

        //5. name the cookie and set it? Need to delete in bottom.logout
        var sCookieName = 'ThermoCookie';
        document.cookie = sCookieName+"="+oInData.sCookie + "; expires="+oToday.toGMTString()+"; path=/";

        //10. Is cookie allowed? Read it to test.
        var sRead = '';
        sRead = document.cookie;

        // 15. if cookies are prohibited return;
        if (sRead.indexOf('ThermoCookie') == -1) return;


        // 20. get current user id in a different way (mexico debuggin can't access $('userid') in IE.
        var currentname = '';
        currentname = oInData.sCookie.split(':')[oTop.emailIndex];

      
        //25. username cookie is rewritten with the latest email in front.
        var usernames = oThis.getCookie('username');
        var k = usernames.indexOf(currentname);
        if(k > 0) {
            var sr=':'+currentname;
            usernames = usernames.replace(sr,'');
        }
        var newusernames = currentname +':'+usernames;
        this.setCookie('username',newusernames,180);
        //alert('new cookie read: '+oThis.getCookie('username'));

    },


    //no ajax call yet. from render. first try to read cookie for easy tabbing. also to expire old logins as users come back home
    loadCookie: function() {
        //0. web edition?


        if(parent.sMEDIA=="LOCAL"){
            return;
        }

        //5. test ram cookie life if already set
        var oToday = new Date();
        var tNow =  oToday.getTime(); //in msec
        var tEXPIRATION = parent.tEXPIRATION

        //10. If RAM cookie expired, logout..
        if(tEXPIRATION>0 && tNow>tEXPIRATION) {
            parent.bottomPanel.handleLogout();
            return;
        }

        //15. now try reading cookie, if privacy is too high return...
        var sRead = document.cookie;
        if(!sRead) {
            //alert('cookie could not be found');
            return;
        }
        //20.  read ThermoCookie
        var sCookie = this.getCookie('ThermoCookie');
        if(sCookie == "" ||  sCookie == null) return;
        //if(sCookie == null ) return;

        // 25. cookie still exists, bypass ajax login; set RAM cookie and render takes care of the rest..
        parent.bLOGIN = true;
        parent.GLOBALCOOKIE = sCookie;//index must be a parent
        parent.tEXPIRATION = this.tGetExpTime(parent.COOKIELIFE);
        //alert('set timer for : life='+parent.COOKIELIFE +' exp = '+parent.tEXPIRATION);
        parent.setGlobalVars(); //update the web cookie and other vars ...
        parent.bottomPanel.showLogout();
    },

    //multiple passes...
    render: function(){
        //0. first see if the cookie exists (for tabbing etc.), note that the header has been written already..
        this.loadCookie(); // in case cookie exists bypass login (on a tab)...

        // 5. set default or from cookie
        var lastName = parent.asCOOKIEITEM[parent.lastNameIndex];
        var modeColor=" #d07500 "; var width=" width=80% ";//
        var modeColorWidth, secondString="My Account", firstString="";

        var bAlert = false;
        parent.bVALIDLIC = true; //valid license is false by default
        var sAlertMsg = '';
        var sMsg = 'To take advantage of all resources offered by TEST, please log in. You can create a free account to check out TEST in minutes by visiting the \'create an account\' link above.';

        //6. Permanent facebook like mark:
        if(parent.bWEB){
            //document.write('<div>'+
//            '<iframe src="http://www.facebook.com/plugins/like.php?href=www.thermofluids.net&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=recommend&amp;font=tahoma&amp;colorscheme=light&amp;height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px;" allowTransparency="true"></iframe>'+
//            '</div>');
        document.write('<div class="fb-like" data-href="www.thermofluids.net" data-send="true" data-width="500" data-height="20" data-show-faces="false" data-action="recommend"></div>');
        }

        // based on login, loca/web, create messages first (lot of if else)
        //10. on the web, not logged in, and no past account (Mr, Guest)
        if(parent.asCOOKIEITEM[parent.accessIndex] == 0 && parent.asCOOKIEITEM[parent.mediaIndex]=="WEB" && lastName == "Guest") {
            //10.0 draw login block, form needed?
            parent.bVALIDLIC = false;
            document.write('<div id = "loginblock">');
            document.write('</div>');
            this.renderLoginBlock(); // put it inside the above div

            //10.20. auto suggest userid only..
            sMsg = 'To take advantage of all resources offered by TEST, please log in. You can create a free account (see the link above) to check out TEST in minutes.'
            var sUserIDs = this.getCookie('username');
            if(sUserIDs!=""){
                var asUserID = sUserIDs.split(':');
                var oSuggestionProvider = new SuggestionProvider(asUserID);
                var oTextbox = new AutoSuggestControl($('userid'), oSuggestionProvider);
            }
        }

        // 20. local accounts or web logged in success (first time or in tab through cookie cookie found), or web expired.
        else {
            var sFirst, sSecond, sModeColor, sModeColorL;

            // 20.0 handle site license greetings and login messages first, valid or expired
            if (parent.asCOOKIEITEM[parent.saluteIndex]=="Site") { //site license
                sFirst = ' Greetings, Site-Licensed User!';
                sSecond = parent.asCOOKIEITEM[parent.lastNameIndex];
                sMsg = 'Each session lasts for 2 hours or until you log out. To extend/upgrade your license beyond '+getExpiryDate()+', please have your instructor contact prof.bhattacharjee@gmail.com.';
            }
            // 20.5 personal a/c (local or web), successful login, valid or expired
            else {
                sFirst =  ' Greetings, ' + parent.asCOOKIEITEM[parent.saluteIndex] + ' '  +parent.asCOOKIEITEM[parent.lastNameIndex] + '!';
                sSecond = 'Registered User Since ' + parent.sREGYEAR + '. ';
                if (parent.sREGYEAR == '1000' && !parent.bWEB) sSecond = 'You are running TEST locally.';
                if (parent.sREGYEAR == '1000' && parent.bWEB) sSecond = 'Remember to Logout from Each Tab';
                sMsg ='Go to MyAccount tab to extend/upgrade the license, which expires on  '+getExpiryDate()+'.';
            }

            // 20.10 Web and Local: Customize messages for different access levels, expired license etc.

            //20.10.0 Guest access, bLOGIN=true, bWEB=true - license must have expired
            if(parent.asCOOKIEITEM[parent.accessIndex] == 0 && parent.asCOOKIEITEM[parent.mediaIndex]=="WEB") { //expired license
                sModeColor="#d07500 "; sModeColorL = "#e08510" ;
                sSecond="**License Alert**";
                parent.bVALIDLIC = false;
                bAlert = true;
                sMsg ='Visit the MyAccount page to extend/upgrade your license, which expired on  '+getExpiryDate()+'.';

                //if license has expired, user is taken back to myAccount, where the following message is displayed.
                sAlertMsg = 'Your license to use TEST has expired. Although some of the modules of TEST will still work, most will not without a valid license.<p>Log on to your account (from the MyAccount tab on the task bar) where you can extend/upgrade your license in seconds.';

                if(parent.asCOOKIEITEM[parent.saluteIndex]=="Site") sAlertMsg = 'The site license for your campus has expired. Please inform your instructor, who can get the license renewed by contacting prof.bhattacharjee@gmail.com. ';
            }

            //20.10.5 Local  -- no cd license.txt found (except the default one)
            else if(parent.asCOOKIEITEM[parent.accessIndex] == 0 && parent.asCOOKIEITEM[parent.mediaIndex]=="LOCAL") { //local, no license.txt or expired license.txt
                sModeColor=" #d07500 ";
                sFirst="Install license.txt file to activate TEST.";
                sSecond="Visit the MyAccount page to download license.txt.";
                parent.bVALIDLIC = false;
                bAlert = true;
                sAlertMsg = 'You are seeing this message because either you have not installed the license file or it has expired.'
            +'<p/>For TEST to run locally, a valid license file must be downloaded and saved in your local installation. '
            +'<p/>Visit <i>www.thermofluids.net</i>, log on to the MyAccount page, and click the "Get CDROM License" button. The license should arrive in your inbox in less than a minute as an attachment named "license.txt". Make sure you check the SPAM folder of your mailbox.'
            +'<p/>In your locally installed copy of TEST (say, in a folder called myTEST) you will find an existing "license.txt" file in the myTEST/testcenter folder. Simply replace the old "license.txt" with the newly arrived file.  This will activate the locally installed copy of TEST and keep it operating until the license expires.'
            +'<p/>You can keep on extending the life of the local installation by updating the license file; however, we recommend that you check out the online version of TEST once in a while to see when it is time for you to obtain a new CD (we recommend that you renew the CD once every year). <p>If you have questions, visit the Forum and post your question on an appropriate topic. You can also write to us at support@thermofluids.net.';
            }

            // 20.10.10 evaluation - set header for evaluation from guest
            else if(parent.asCOOKIEITEM[parent.accessIndex] ==5) { //evaluation?
                if(parent.bWEB){
                    $('headerPart1').src = "testcentericons/headerPart1Evaluation.jpg";
                    $('headerPart2').src = "testcentericons/headerPart2Evaluation.jpg";
                }
                sModeColor="#4aa02c";
            }
            // 20.10.15 academic
            else if(parent.asCOOKIEITEM[parent.accessIndex] ==10) { //academic
                if(parent.bWEB){
                    $('headerPart1').src = "testcentericons/headerPart1Academic.jpg";
                    $('headerPart2').src = "testcentericons/headerPart2Academic.jpg";
                }
                sModeColor="#5555aa";
            }
            // 20.10.20 prof.
            else if(parent.asCOOKIEITEM[parent.accessIndex] ==15) { // professional
                if(parent.bWEB){
                    $('headerPart1').src = "testcentericons/headerPart1Professional.jpg";
                    $('headerPart2').src = "testcentericons/headerPart2Professional.jpg";
                }
                sModeColor="#5555aa";
            }
            // 20.15 write greetings part1 and 2. draw logout (in case cookie caused the login..
            document.write('<table align=center width=100% bgcolor=dddddd  height=20 ><tr><td BGCOLOR='+sModeColor+' width = "50%" align="center"><font color=#ffffff face=verdana size=-1>' + sFirst +  ' <font></td><td  bgcolor='+sModeColor+' width = "50%" align="center"><font color=#ffffff face=verdana size=-1>' + sSecond +  '</font></td></tr></table>');
            //alert('calling bottom.showlogout');
            if(parent.bWEB) parent.bottomPanel.showLogout();
        }



        // 25. boxes used for alert during login and permanent message after login.
        document.write('<div id = "alertBox" class="alertBox"></div>');
        document.write('<div id = "messageBox" class="messagebox"></div>');
        document.write('<div id = "postBox" class="postbox"></div>');

        // 30. bAlert may be set in the else block above..
        if(bAlert) this.alertLocal(sAlertMsg);
        //else if (parent.bWEB && !parent.bLOGIN){
        else if (parent.bWEB && !parent.bVISITED){
            var oDate = new Date();
            //if (oDate < this.oMODExpirs) this.alertLocal(this.sMsgOfDay);
            if (oDate < this.oMODExpirs) this.alertLocalSoft(this.sMsgOfDay);
            parent.bVISITED = true;
        }
        this.sSetLoginMsg(sMsg);

        // 35. table starts with feature video clips, quote by Arnold
        document.write('<table bgcolor=ffffff border=0 width=100% cellpadding=5 cellspacing=0 >');
        this.writeVideoClip();
        document.write('<tr><td>');
        document.write('<p>');
        document.write('<img src="testcentericons/quote.gif" nosave valign=top border=0 alt="Click here for a Feature Tour">');

        document.write('</td></tr><tr valign=bottom><td valign="Bottom"> <p><font face="verdana" size="-1">');

        // 30. welcome message
        document.write('Welcome  to TEST - a visual platform to analyze  thermofluids problems,  verify hand calculations, pursue what-if '+
            'scenarios,  visualize thermal systems, and engage in a life-long journey to master thermodynamics.</p>'+
            '<p><font face="verdana" size="-1">Created for students, educators, and practicionars of thermodynamics, TEST offers smart thermodynamic tables for property evaluation and analysis  tools for  mass, energy, entropy, and exergy analysis of open and closed systems. Customized applications for specific systems such as IC engines, gas and vapor power cycles, refrigeration, HVAC, combustion, chemical equilibrium, and gas dynamics are all tightly integrated under the general thermodynamic umbrella. </p>' +
            '<p><font size="-1" face="verdana">Beside the <em>daemons - </em> dedicated web-based  calculators with a friendly graphical interface - you will find other useful modules such as an animation library, rich internet applications (RIA\'s), traditional charts and tables, manual and TEST solutions of hundreds of engineering problems, and fifteen chapters of examples and problems to supplement any thermodynamics textbook.</p>'+
            '<p><font face="verdana" size="-1">Go through the <em>Tutorial</em>, specifically the Getting Started and My First TEST Solution sections, before you create an account (takes less than a minute) and start exploring TEST. Once you conclude that TEST can be a useful tool for you, visit the MyAccount page to upgrade your account, order a CD for local installation, or request a site license for your institution. TEST is freely distributed to educators and students of any academic institution. If you are an educator, please write directly to prof.bhattacharjee@gmail.com to obtain a permanent license.  </p>  '+
            '<p><font face="verdana" size="-1">If you have any question or comment, visit the Forum. There, you can search and browse discussions organized into various thermodynamic topics. Any well-posed thermodynamic question will be addressed by the moderators expeditously. You will be notified as soon as an answer is posted.'+
            '</td></tr>'+
            '</table>');

        // 40. warning has been set after login..
        if(parent.iWARNING >0) {
            this.alertBadWarning(this, parent.iWARNING);
        }
    },


    // called by home.html it writes graphic header  writeHomeHeader
    renderHeader: function(){
        //alert("rendering header");
        var headerPart1, headerPart2;
        if(getExpiryStatus()) parent.asCOOKIEITEM[parent.accessIndex]="0";
        var lastName = parent.asCOOKIEITEM[parent.lastNameIndex];
        switch(parent.asCOOKIEITEM[parent.accessIndex]) {
            case "0": // either not registered or expired license, distinguish the two through last name. "Guest" cannot be anyone's lastname

                headerPart1="headerPart1Guest"; headerPart2="headerPart2Guest";
                footnote=new String("Guest Mode/WEB: This is the default mode with very limited access. You may browse the Tutorial or the Slide Show pages to learn about TEST, but you must log in in order to use TEST effectively. ");
                message=new String('<br><table width=100%  boder=2 cellpadding=2 cellspacing=0><tr><td><font face="verdana" size="-1" color=blue><hr>Activation Procedure: You must activate this locally installed distribution of TEST. Activation means downloading a license file and save it in a particular folder. The following instructions assume that you have already copied the entire content of the CD into a local folder named \"myTEST\" (in your C drive or desktop) and bookmarked this local page in your favorite browser (Firefox/IE/Safari). More detailed instructions can be found in the README.txt file in the CD.<ol><li>If you are not connected to the Internet, go to step-2. Click on the MyAccount tab on the Task Bar (or next to the greetings  above). It will take you to the TEST registration site, where you must log in to access your account. If you do not have an account, you can create one in minutes following the \"create an account\" link. In case you forgot your password it will be emailed to you as long as you remember your login id (the email address you use during registration). <p>After you log in, you can see your account status in the MyAccount page. There you will see a button  "Send CDROM License" prominantly displayed (among other options). Click on it to receive the license file "license.txt" as an email attachment (should take less than a minute; make sure you check your spam folder just in case the machine generated mail is treated as spam by your email application). The license file contains the expiration date of your subscription and the type of subscription (educational vs. professional). Log out of the MyAccount page and check your email. After the "license.txt" file arrives as an attachment, save it in the "testcenter" folder, located inside the "myTEST" folder (where you copied the content of the CD). The new file replaces an old  file by the same name ("license.txt") copied from the CD. <p>Launch TEST again (using your local bookmark or clicking the index.html file in the "myTEST" folder).  A personalized greetings on the home page will indicate that TEST has been successfully activated. Also, this instruction block will disappear and appear again only after your license will have expired.<p><li>If your computer does not have a network connection, you have to go to a different networked computer and visit www.thermofluids.net, click the MyAccount tab, and get the "license.txt" file as described in Step-1. After the file arrives, copy it into a floppy disk or some other moveable media, and transfer it to the "myTEST/testcenter" folder in your non-networked computer.  <p><li>Once activated, the local edition of TEST does not require any network connection (except for accessing the solution manual). After your license period expires, these instructions will reappear on this page. To extend your license, go to the MyAccount page, renew your license,  obtain a fresh "license.txt" file to update/upgrade your existing license. Users who renew license before the expiration date receive a substantial discount. <p><li>If you received the cd from a colleague, follow the same procedure starting at Step-1. Of course, you have to create an account first by registering (click on "create an account" in the login block of the TEST home page). </ol><hr></font></td></tr></table>');

                if(parent.sMEDIA=="WEB"&& lastName=="Guest") message='<div class="messagebox"><div class = "news" >ACCESS SPEED OF THE FORUM PROGRESSIVELY INCREASES AS YOU ACCESS IT MORE OFTEN. THE FORUM NOW WORKS IN CHROME ALSO. </div>To test if your institution has a site license, simply click the Log In button above. Academic site license is free and can be activated in minutes for your campus. If you are an educator, create a personal account (in seconds) and then send an email to Prof. Bhattacharjee (prof.bhattacharjee@gmail.com) to upgrade your account. Also, to set up the free site license, include the first two nodes of the IP address of your campus.   </div>';
                if(parent.sMEDIA=="WEB" && getExpiryStatus()){ //account expired, web user
                    message=new String('Dear '+parent.asCOOKIEITEM[parent.saluteIndex] + ' ' + lastName +',\n\nYour license to use TEST needs to be renewed, which apparently expired on '+getExpiryDate()+'. Close this \nwindow and go to MyAccount page, where you can renew/upgrade your license in a minute. If you are an educator, please write directly to prof.bhattacharjee@gmail.com for a permanent academic license.\n\nThank you for your support! \n\nS. Bhattacharjee, Author of TEST\n');
                    message= '<div class="messageboxred">Your license to use TEST needs to be renewed, which apparently expired on '+getExpiryDate()+'. Go to the MyAccount page, where you can renew/upgrade your license in minutes. <p>If you are an educator, please write directly to prof.bhattacharjee@gmail.com to extend/upgrade your academic license.</div>';
                }

                if(parent.sMEDIA=="LOCAL"){
                    headerPart1="headerPart1GuestLocal";
                    footnote=new String("Guest Mode/Local Edition: This is the default mode with very limited access. You must activate this local edition in order to use TEST effectively.");

                }


                break;
            case "5":
                headerPart1="headerPart1Evaluation"; headerPart2="headerPart2Evaluation";
                footnote=new String("Evaluation Mode: This mode gives you almost as much access as the Academic Mode for a limited period of time. In the Evaluation Mode run a few daemons to make sure that everything works before upgrading your license to Academic or Professional Mode.");

                if(parent.sMEDIA=="LOCAL"){
                    headerPart1="headerPart1EvaluationLocal";
                }
                break;
            case "10":
                headerPart1="headerPart1Academic"; headerPart2="headerPart2Academic";
                footnote=new String("Academic Mode/Web Edition: This mode gives you access to an adequate set of working substances used in thermodynamics education.  Web Edition means you are accessing the latest version of TEST. The access speed is, however, limited by the speed of your connection. If you would like to run TEST locally to enjoy its native performance, order a TEST-CD. The Professional Edition of TEST contains a much larger data base and comes with a CD for local installation. ");

                if(parent.sMEDIA=="LOCAL"){
                    headerPart1="headerPart1AcademicLocal";
                    footnote=new String("Academic Mode/Local Edition: This mode gives you access to an adequate set of working substances used in thermodynamics education. Local installation means access speed is at its fastest and no Internet connection is necessary. The Professional Edition of TEST contains a much larger data base. ");

                }
                break;
            case "15":
                headerPart1="headerPart1Professional"; headerPart2="headerPart2Professional";
                footnote=new String("Professional Mode/Web Edition: This mode gives you complete access to the growing list of working substances available in the TEST database. Web Edition means you are accessing the latest version of TEST. The access speed is, however, limited by the speed of your connection. For best access, obtain a license with a CD so that you can run TEST locally for speed and access the Web Edition to use the latest version from anywhere. ");

                if(parent.sMEDIA=="LOCAL"){
                    headerPart1="headerPart1ProfessionalLocal";
                    footnote=new String("Professional Mode/Local Edition: This mode gives you complete access to the growing list of working substances available in the TEST database. Local installation means access speed is at its fastest. Occasionally access TEST on line to see if the on line version has improved sufficiently to justify an upgrade.");

                //alert('got it');

                }
                break;
            default:
                break;
        }
        //document.write("<script> function checkUser(){if(parent.asCOOKIEITEM[6] == 'subrata@thermo.sdsu.edu'){window.location = \"http://thermo.sdsu.edu/testcenterdev/registration/jsserver/admin/adminlogin.html\";} else{ return;}} <\/script>");
        //document.write('<tr><td bgcolor=#ffffff valign=top align=center width=20%><img src="testcentericons/testLogoEd.jpg" Alt="TEST Logo" nosave border=0 width=100 height=90 usemap="#m_testLogoEd"><map name="m_testLogoEd"><area shape="rect" coords="17,0,24,6" href='+oTop.ADMINURL+'><area shape="rect" coords="25,0,31,6" href="http://energy.sdsu.edu/awstats/awstats.pl?config=energy.sdsu.edu"><area shape="rect" coords="80,12,90,20" onClick= oHome.checkUser()></map></td><td width=75% valign=top align=middle ><a onmouseout = "goUnTip()" onmouseover = "goTip(\'Bookmark www.thermofluids.net<br/>and a mirror for reliable access\')" href="javascript:void(0)" onclick = "goTopHref(\'http://www.thermofluids.net\')" ><img id = "headerPart1" src="testcentericons/'+headerPart1+'.jpg" nosave border=0 width=590 height=90></a></td><td bgcolor=#ffffff valign=top align=middle width=5%><img id = "headerPart2" src="testcentericons/'+headerPart2+'.jpg" width=40 height=90  alt="About TEST-Pro" border=0></td></tr>');
 //bad..document.write('<tr><td bgcolor=#ffffff valign=top align=center width=20%><img src="testcentericons/testLogoEd.jpg" Alt="TEST Logo" nosave border=0 width=100 height=90 usemap="#m_testLogoEd"><map name="m_testLogoEd"><area shape="rect" coords="17,0,24,6" onclick = "goTopHref(\' '+oTop.ADMINURL+' \')" ><area shape="rect" coords="25,0,31,6" href="http://energy.sdsu.edu/awstats/awstats.pl?config=energy.sdsu.edu"><area shape="rect" coords="80,12,90,20" onClick= oHome.checkUser()></map></td><td width=75% valign=top align=middle ><a onmouseout = "goUnTip()" onmouseover = "goTip(\'Bookmark www.thermofluids.net<br/>and a mirror for reliable access\')"  style = "cursor:pointer;" onclick = "goTopHref(\'http://www.thermofluids.net\')" ><img id = "headerPart1" src="testcentericons/'+headerPart1+'.jpg" nosave border=0 width="590" height="90" align="right"></a></td><td bgcolor=#ffffff valign=top align=middle width=5%><img id = "headerPart2" src="testcentericons/'+headerPart2+'.jpg"  width="40" height="90"   onmouseout = "goUnTip()" onmouseover = "goTip(\'Different TEST-modes are<br/>explained in the MyAccount page\')"  border=0></td></tr>');
        //good document.write('<tr><td bgcolor=#ffffff valign=top align=center width=20%><img src="testcentericons/testLogoEd.jpg" Alt="TEST Logo" nosave border=0 width=100 height=90 usemap="#m_testLogoEd"><map name="m_testLogoEd"><area shape="rect" coords="17,0,24,6" href='+oTop.ADMINURL+'><area shape="rect" coords="25,0,31,6" href="http://energy.sdsu.edu/awstats/awstats.pl?config=energy.sdsu.edu"><area shape="rect" coords="80,12,90,20" onClick= oHome.checkUser()></map></td><td width=75% valign=top align=middle ><a onmouseout = "goUnTip()" onmouseover = "goTip(\'Bookmark www.thermofluids.net<br/>and a mirror for reliable access\')"  style = "cursor:pointer;" onclick = "goTopHref(\'http://www.thermofluids.net\')" ><img id = "headerPart1" src="testcentericons/'+headerPart1+'.jpg" nosave border=0 width=590 height=90></a></td><td bgcolor=#ffffff valign=top align=middle width=5%><img id = "headerPart2" src="testcentericons/'+headerPart2+'.jpg" width=40 height=90  alt="About TEST-Pro" border=0></td></tr>');
        document.write('<tr><td bgcolor=#ffffff valign=top align=center width=20%><img src="testcentericons/testLogoEd.jpg" Alt="TEST Logo" nosave border=0 width=100 height=90 usemap="#m_testLogoEd"><map name="m_testLogoEd"><area style="cursor:default;" shape="rect" coords="17,0,24,6" onclick = "goTopHref(\' '+oTop.ADMINURL+' \')"><area  style="cursor:default;" shape="rect" coords="25,0,31,6" href="http://energy.sdsu.edu/awstats/awstats.pl?config=energy.sdsu.edu"><area  style="cursor:default;" shape="rect" coords="80,12,90,20" onClick= oHome.checkUser()></map></td><td width=75% valign=top align=middle ><a onmouseout = "goUnTip()" onmouseover = "goTip(\'Bookmark www.thermofluids.net<br/>and a mirror for reliable access\')"  style = "cursor:pointer;" onclick = "goTopHref(\'http://www.thermofluids.net\')" ><img id = "headerPart1" src="testcentericons/'+headerPart1+'.jpg" nosave border=0 width=590 height=90></a></td><td bgcolor=#ffffff valign=top align=middle width=5%><img id = "headerPart2" src="testcentericons/'+headerPart2+'.jpg" width=40 height=90  alt="About TEST-Pro" border=0></td></tr>');
    },


    //go to admin file, change shubhangi's location
    checkUser: function (){
        //window.location = parent.registrationURL + "jsserver/admin/adminlogin.html";
        window.location = parent.registrationURL + "jsserver/adminlogin.html";
        //window.location = "http://thermo.sdsu.edu/testcenterdev/registration/jsserver/admin/adminlogin.html";
    },
    //tip will work only if tip js files are added in the html file, in this case home.html (through home.js).
    goTip: function (){
        var args = $A(arguments);
        var e = args.shift(); // Event object
        var oThis = args.shift();
        var sTip = args.shift();
        Tip(sTip, OFFSETY, -4, OFFSETX, 20, DELAY, 1000);
    },
    //tip will work only if tip js files are added in the html file, in this case home.html (through home.js).
    goUnTip: function (){
        UnTip('');
    },
    writeInvite: function () {
        var s = '<table  border=0 cellpadding=0 cellspacing=0 height=50 >';
        s += '<tr><td  align=left class="linkStyle" colspan=2 ><INPUT  type=button  value="Invite.." name="invite" id="invite" class="testButton" /></td></tr></table>';
        document.write(s);
        $('invite').onclick = this.handleInvite.bindAsEventListener(this, this);
        $('invite').onmouseover = this.goTip.bindAsEventListener(this,this, 'Edit the letter before<br> sending it to a friend.');
        $('invite').onmouseout = this.goUnTip.bindAsEventListener(this,this);
    },

    //invite button on the left col has been clicked.
    handleInvite: function(){
        var args = $A(arguments);
        var e = args.shift(); // Event object
        var oThis = args.shift();
        var sBlock = args.shift();
        var sEmail = parent.asCOOKIEITEM[parent.emailIndex];
        var sFirst =  parent.asCOOKIEITEM[parent.firstNameIndex];
        var sLast =  parent.asCOOKIEITEM[parent.lastNameIndex];

        //5. rule out bad cases
        if(!parent.bLOGIN){
            this.alertLocal("Thanks for trying to invite a friend to TEST. Please log onto the web version of TEST at www.thermofluids.net and try again. The invitation function requires the user to be logged in.");
            return;
        }
        if(sEmail.indexOf('@site.edu') != -1){
            this.alertLocal("Thanks for trying to invite a friend to TEST. You have to be logged in to your personal account to invite a friend.");
            return;
        }
       //alert('invigte trapped: '+sFirst);
        var oMailer = new GenericPost('postBox','Invite a friend to check out TEST'); //element postBox has been already created
        oMailer.setToField('yourFriend@somemail.com');
        oMailer.setSubject('A cool thermo site you may find useful...');
        oMailer.setBody('Hi xxx, \n\nI have stumbled upon this interesting portal, www.thermofluids.net, that lets you do sophisticated thermal calculations inside a browser environment.\n\nI thought you would like to check it out. It has analysis tools (java applets, animations, rich internet applications, thermodynamic plot generators) for all sorts of thermodynamic topics - from property evaluation of hundreds of substances to IC Engines Cycles, Gas Turbine Cycles, Steam Power Cycles, Refrigeration and Heat Pump, HVAC, Combustion, Equilibrium, and Gas Dynamics analysis. Moreover, it allows what-if studies through a unique graphical interface. Standards tables and charts, hundreds of solved problems, and a Forum that links professionals, educators, and students are some of the other resources tightly integrated into this site. \n\nGive it a try (the Tutorial has everything to get one started). I think you may like using TEST:) \n\n' + sFirst   );
        oMailer.setFromName(sFirst + ' '+sLast);
        oMailer.setNote('Edit the email address of your friend and the body of the letter as you see fit (please do not forget to correct your friend\'s name) before you click the Send button above. The From field is not editable. <p/>Thank you for taking the time to help the TEST project. ');
        oMailer.setFromEmail(sEmail);
        xRemoveClass($('postBox'),'hide');
    },


    //number of days left for license expiration, get from cookie.
    getExpiryDays: function () {

        //var expiryDate = new Date(ThermoCookieList[expiryIndex] * 1000);
        var expiryDate = new Date(parent.asCOOKIEITEM[parent.expiryIndex] * 1000); //time in msec
        var today = new Date();
        var diff=((expiryDate.getTime()-today.getTime())/(24*3600*1000)).toFixed(0);
        //if(diff>3650) diff="-";  ??
        return diff;
    },

    // constructor calls this to make message
    sSetLoginMsg: function(sMsg){
        if ($('messageBox'))$('messageBox').innerHTML = sMsg;
    },

    // right under login message, do camtasia video
    writeVideoClip: function (){
        var iRandom = Math.floor(Math.random()*3);
        var asFeature = [];
        asFeature[0] = 'features/featureA.html';
        asFeature[1] = 'features/featureB.html';
        asFeature[2] = 'features/featureC.html';
        //if(getExpiryStatus()=="true") ThermoCookieList[accessIndex]="0";
        if(getExpiryStatus()) parent.asCOOKIEITEM[parent.accessIndex]="0";
        if(parent.sMEDIA=="WEB"  && parent.asCOOKIEITEM[parent.accessIndex] != 0) {
        }
        else{

            var s = "<tr ><td valign='top' align=left><iframe  id='videoClip' frameborder='0' scrolling='no' valign = 'top' align = 'left' width='582' height = '335' marginheight='0px' marginwidth='0px' src='"+asFeature[iRandom]+"'></iframe></td></tr>";
            document.write(s);
        }
    },


    //image for Web Edition vs. Web Mirror etc.
    writeMirror: function(){
        var mirrorFile="webEdition.jpg";
        if(parent.sMEDIA=="WEB") mirrorFile="webMirror.jpg";
        document.write('<img src=testcentericons/'+mirrorFile+'>');
    },



    // from w3school.com
    setCookie: function (sCookieName,value,iLifeInDays) {
        var oToday = new Date();
        oToday .setDate(oToday .getDate()+iLifeInDays);
        var usernames = escape(value);
        document.cookie=sCookieName+ "=" +usernames+((iLifeInDays==null) ? "" : ";expires="+oToday .toGMTString());
    },

    // return a string like email1: email2: email3
    getCookie: function (sCookieName){
        if (document.cookie.length>0){
            iStartIndex=document.cookie.indexOf(sCookieName + "=");
            if (iStartIndex!=-1){
                iStartIndex=iStartIndex + sCookieName.length+1;
                iEndIndex=document.cookie.indexOf(";",iStartIndex);
                if (iEndIndex==-1) iEndIndex=document.cookie.length;
                return unescape(document.cookie.substring(iStartIndex,iEndIndex));
            }
        }
        return "";
    },

    sGetLoginHTML: function(){
        var s = '';
        //s += "<input type=hidden name=operation value=\"login\">";
        s += "<table width='100%' bgcolor='dddddd' border='0' cellpadding='0' cellspacing='0'>";

        s += "<tr>";
        s += "  <td width='5'>&nbsp;</td>";
        //alert('url = '+oTop.SIGNUPURL);
        s += '  <td height=20 colspan=1><font face=verdana size=-1> Log in or <span class="linkStyleUL" id = "createaclabel">create an account</span></font></td>';

        s += "  <td width='2'>&nbsp;</td>";
        s += '  <td height=20  colspan=3>[ <span  class="linkStyleUL"   id = "sendpwlabel"  >Forgot password?</span>&nbsp;&nbsp;&nbsp;<span  class="linkStyleUL"   id = "changepwlabel"  >Change password</span>&nbsp; ]</td>';
        s += "</tr>";

        s += "<tr>";
        s += "  <td width='5'>&nbsp;</td>";
        s += "  <td width='190' height='5' valign='middle'><font face='verdana' size='-2'>Login id (e-mail address):</font></td>";
        s += "  <td width='5'>&nbsp;</td>";
        s += "  <td  height='5' colspan='3' valign='middle'><font face='verdana' size='-2'>Password: (No id or password is necessary with site license.)</font></td>";
        s += "</tr><tr>";

        //10.5 userid and password
        s += "  <td width='5'>&nbsp;</td>";
        s += "  <td width='190' height='5' valign='top'><font face='verdana' size='-1'><INPUT class='yellowbg' name='userid'   type = text id='userid' size='30' maxlength='40' tabindex='1'></font></td>";
        s += "  <td width='2'>&nbsp;</td>";
        s += "  <td  width = 100 height='5' valign='top'><font face='verdana' size='-1'><INPUT  class='yellowbg' name='password' type=password id='password' size='15' maxlength='15' tabindex='2'></font></td>";
        s += "  <td  colspan=2  >";
        s += "  <INPUT  type=button  value='Log In' name='loginbutton' id='loginbutton' /> <INPUT type=checkbox  value=NO name='sitebox' id='sitebox' tabindex='4' /><font face='verdana' size='-1'>Site License</font></td>";
        s += "</tr>";

        s += "<tr>";
        s += "  <td width='5'>&nbsp;</td>";
        s += "  <td colspan='5'>";
        s += "  <span style='font-family:arial; font-size:10px;'>  To test if your campus/corporation has a site license, select the Site License checkbox. </span></td>";
        s += "</tr>";

        s += "</table>";
        return s;
    },

    //innerHTML for forgot password block
    sGetSendPWHTML: function(){
        var s = '';
        s += "<div style = 'background-color : #ccffff; padding: 10px; padding-right: 0px;'>";
        s += "<div class = 'simplefont blocktitle'> Retrieve your password</div>"
        s += "<div class = 'inputexample'> Login id (ex: pat@example.com):</div>"
        s += "<div><INPUT class = 'textstyle blue'  id='userid'  type = 'text' size='30' maxlength='60' tabindex='1'>";
        s += "<INPUT class = 'buttonstyle' type='button'  value='Send Password' id='sendpwbutton' />  ";
        s += "<INPUT class = 'buttonstyle' type='button'  value='Cancel' id='sendpwcancelbutton' /> </div>";
        s += "<div class = 'simplefont'> The password will be emailed to you immediately. Check your inbox and spam folder.</div>"
        s += "</div>";
        return s;
    },

    //innerHTML for change password block
    sGetChangePWHTML: function(){
        var s = '';
        //s += "<div style = 'background-color : #ccff99; padding: 10px; padding-right: 0px;'>";
        s += "<div style = 'background-color : #ddffaa; padding: 10px; padding-right: 0px; '>";
        s += "<div class = 'simplefont blocktitle'> Change your password</div>"
        s += "<div class = 'inputexample'> Login id (ex: pat@example.com):<span style='padding-left: 20px;'>Current Password:</span><span style='padding-left: 7px;'>New Password:</span><span style='padding-left: 18px;'>Confirm New Password:</span></div>"
        s += "<div><INPUT class = 'textstyle blue'  id='userid'  type = 'text' size='25' maxlength='60' tabindex='1'>";
        s += "<INPUT class = 'textstyle blue'  id='oldpw'  type = 'password' size='14' maxlength='10' tabindex='2'>";
        s += "<INPUT class = 'textstyle red'  id='newpw'  type = 'password' size='14' maxlength='10' tabindex='3'>";
        s += "<INPUT class = 'textstyle red'  id='newpw2'  type = 'password' size='14' maxlength='10' tabindex='4'>";
        s += "<div><INPUT class = 'buttonstyle' type='button'  value='Change Password' id='changepwbutton' />";
        s += "<INPUT class = 'buttonstyle' type='button'  value='Cancel' id='changepwcancelbutton' /> </div>";
        s += "<div class = 'simplefont'> The new password will become effective immediately.</div>"
        s += "</div>";
        return s;
    },


    //innerHTML for account creation block
    sGetCreateACHTML: function(){
        var s = "<div style = 'background-color : #eeffee; padding: 10px; padding-right: 10px; '>";
        s += "<div class = 'simplefont blocktitle'> Creating an account is as easy as 1-2-3</div>"
        s += '<fieldset>'+
        '<legend>'+
        'Step-1 of 3: Your unique identification at thermofluis.net:'+
        '</legend>'+
        '<table border="0" cellspacing="5" width = "100%">'+
        '<tr>'+

        '<td class="tdata" width = "15%"><label id="emailL" class = "label3">Email</label></td>'+
        '<td width="35%"><input id="signUpEmail" name="signUpEmail" type="text" class="wide" maxlength = "64"  /></td>'+


        '<td class="tdata"  width = "20%"><label id="emailReL" class = "label3">Re-enter Email</label></td>'+
        '<td  width = "30%"><input id="signUpReEmail" name="signUpReEmail" type="text" class="wide"  maxlength = "64" /></td>'+
        '</tr>'+
        '<tr>'+

        '<td class="tdata" ><label id="lastNameL" class = "label3">Last Name</label></td>'+
        '<td><input id="signUpLname" name="signUpLname" type="text"  maxlength = "64" /></td>'+


        '<td class="tdata" ><label id="firstNameL" class = "label3">First Name</label></td>'+
        '<td><input id="signUpFname" name="signUpFname" type="text"  maxlength = "64" /></td>'+
        '</tr>'+

        '<tr>'+
        '<td class="tdata"><label id="titleL" class = "label3">Title</label></td>'+
        '<td><select id="signUpTitle" name="signUpTitle">'+
        '<option  selected="selected" value= "Select One">Select One</option><option  value="Dr.">Dr.</option><option value="Prof.">Prof.</option><option value="Mr.">Mr.</option><option value="Ms.">Ms.</option><option value="Mrs.">Mrs.</option><option value="Sr.">Sr.</option><option value="Sra.">Sra.</option><option value="Srta.">Srta.</option><option value="Sri.">Sri.</option><option value="Smt.">Smt.</option>'+
        '</select></td>'+
        '<td class="tdata"><label id="actypeL" class = "label3">Account Type</label></td>'+
        '<td><select id="signUpType" name="signUpType">'+
        '<option selected="selected" value= "Select One">Select One</option><option  value= "Student">Student</option><option value= "Educator">Educator</option><option value= "Professional">Professional</option><option value= "Other">Other</option>'+
        '</select></td>'+
        '</tr>'+

        '<tr>'+
        '<td colspan=2 align="left" width="100%" id = "pInfoMsgTD" class="hide"></td>'+
        '</tr>'+
        '</table>'+
        '</fieldset>';

        // step-2-----------------
        s += '<div id = "step2">';
        s += '<fieldset>'+
        '<legend>'+
        'Step-2 of 3: Personal information based on Account Type:'+
        '</legend>'+
        '</fieldset></div>';

        // step-3-----------------
        s += '<div id = "step3">';
        s += '<fieldset>'+
        '<legend>'+
        'Step-3 of 3: Create the account:'+
        '</legend>'+
        '<table border="0" cellspacing="5" width="98%">'+


        '<tr>'+
        '<td class="tdata" width="30%"><label id="sourceL" class = "label3">How did you hear about TEST?</label></td>'+
        '<td  width="70%" align="left"><select id="signUpWhere" name="signUpWhere">'+
        '<option value="Select One" selected="selected" >Select One</option><option value="Internet search">Internet search</option><option value="From a friend/colleague">From a friend/colleague</option><option value = "From a professor" >From a professor</option><option value = " >From a student</option><option value = "From a brochure" >From a brochure</option><option value = "From an article" >From an article</option><option value = "From a textbook" >From a textbook</option><option value = "Other source" >Other source</option>'+
        '</select></td>'+
        '</tr>'+

        '<tr>'+
        '<td class="simplefont " style="padding-top: 15px; padding-bottom: 5px; font-size: 11px; color: #bb0000;" colspan="2"> <span id="acceptmessage" class="hide" >By clicking on \"I accept\" below you are agreeing not to create multiple accounts without approval from support@thermofluids.net. <span></td>'+
        '</tr>'+

        '<tr>'+
        '<td  align="left"><input type="button" value = "Create my TEST account." id="createacbutton"></td>'+
        '<td  align = "left"><input id="createaccancelbutton" value ="Cancel" type="button" ></td>'+
        '</tr>'+

        '<tr>'+
        '<td class="simplefont " style="padding-top: 15px; padding-bottom: 5px; font-size: 11px; " colspan="2"> If you encounter any problem with account creation, please let us know at support@thermofluids.net. Thank you!</td>'+
        '</tr>'+

        '</fieldset></div>';
        s += "</div>";
        return s;
    },

    //initial login block in a div.
    renderLoginBlock: function(){
        $('loginblock').innerHTML = this.sGetLoginHTML();
        $('password').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'login');
        $('userid').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'login');
        $('loginbutton').onclick = this.handleLogInClick.bindAsEventListener(this, this);
        $('sitebox').onclick = this.handleSiteLogInClick.bindAsEventListener(this, this);
        $('sendpwlabel').onclick = this.renderSendPWBlock.bindAsEventListener(this, this);
        $('changepwlabel').onclick = this.renderChangePWBlock.bindAsEventListener(this, this);
        $('createaclabel').onclick = this.renderCreateACBlock.bindAsEventListener(this, this);
        var sEmail = '';
        var asCookie = this.getCookie('username').split(':');
        if(asCookie.length>0) sEmail = asCookie[0];
        //alert ('username cookie = '+ this.getCookie('username'));
        if(sEmail==''){
            $('userid').focus();
            return;
        }
        $('userid').value = sEmail;
        $('password').focus();
    },


    //forgot password block
    renderSendPWBlock: function(){
        //0. remove alerbox
        xRemoveClass($('alertBox'), 'show');
        xAddClass($('alertBox'), 'hide');
        //5. html and event handlers
        $('loginblock').innerHTML = this.sGetSendPWHTML();
        $('sendpwcancelbutton').onclick = this.renderLoginBlock.bindAsEventListener(this, this);
        $('sendpwbutton').onclick = this.handleSendPWClick.bindAsEventListener(this, this);
        $('userid').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'sendpw');

        //10. auto suggest userid only..
        var sUserIDs = this.getCookie('username');
        if(sUserIDs!=""){
            var asUserID = sUserIDs.split(':');
            var oSuggestionProvider = new SuggestionProvider(asUserID);
            var oTextbox = new AutoSuggestControl($('userid'), oSuggestionProvider);
        }
    },
    //forgot password block
    renderChangePWBlock: function(){
        //0. remove alerbox
        xRemoveClass($('alertBox'), 'show');
        xAddClass($('alertBox'), 'hide');
        //5. html and event handlers
        $('loginblock').innerHTML = this.sGetChangePWHTML();
        $('changepwcancelbutton').onclick = this.renderLoginBlock.bindAsEventListener(this, this);
        $('changepwbutton').onclick = this.handleChangePWClick.bindAsEventListener(this, this);
        $('userid').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'changepw');
        $('newpw').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'changepw');
        $('newpw2').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'changepw');
        //10. auto suggest userid only..
        var sUserIDs = this.getCookie('username');
        if(sUserIDs!=""){
            var asUserID = sUserIDs.split(':');
            var oSuggestionProvider = new SuggestionProvider(asUserID);
            var oTextbox = new AutoSuggestControl($('userid'), oSuggestionProvider);
        }
    },

    //account creation block
    renderCreateACBlock: function(){
        //0. remove alerbox
        xRemoveClass($('alertBox'), 'show');
        xAddClass($('alertBox'), 'hide');
        //5. html and event handlers
        $('loginblock').innerHTML = this.sGetCreateACHTML();
        $('signUpType').onchange = this.handleTypeChange.bindAsEventListener(this, this);
        $('createaccancelbutton').onclick = this.renderLoginBlock.bindAsEventListener(this, this);
        $('createacbutton').onclick = this.handleCreateACClick.bindAsEventListener(this, this);
        $('signUpEmail').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');
        $('signUpReEmail').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');
        $('signUpLname').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');
        $('signUpFname').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');

    //$('sendpwcancelbutton').onclick = this.renderLoginBlock.bindAsEventListener(this, this);
    //$('sendpwbutton').onclick = this.handleSendPWClick.bindAsEventListener(this, this);
    //$('userid').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'sendpw');

    },


    //remove ' " from a string
    sSterilize: function(s){
        s = s.replace(/\'/g,'');
        s = s.replace(/\"/g,'');
        s = s.replace(/\&/g,' and ');
        return s;
    },
    //create a/c by making a ws call.
    handleCreateACClick: function(){
        //0. check input
        xRemoveClass($('alertBox'), 'show');
        xAddClass($('alertBox'), 'hide');
        xRemoveClass($('emailL'), 'highLight');xRemoveClass($('emailReL'), 'highLight');xRemoveClass($('lastNameL'), 'highLight');xRemoveClass($('firstNameL'), 'highLight');
        xRemoveClass($('titleL'), 'highLight');xRemoveClass($('actypeL'), 'highLight');xRemoveClass($('collegeL'), 'highLight');
        xRemoveClass($('addressL'), 'highLight');xRemoveClass($('countryL'), 'highLight');xRemoveClass($('licenseL'), 'highLight');
        xRemoveClass($('addressL'), 'highLight');xRemoveClass($('sourceL'), 'highLight');

        var sID = this.sSterilize($('signUpEmail').value);
        //5. regexp email
        if(!this.bTestEmail(sID)){
            this.alertLocal("Error in Step-1: Please check your input in the Email field. You will receive your password and all other communication at this address. ");
            xAddClass($('emailL'),'highLight');
            return;
        }
        var sID2 = this.sSterilize($('signUpReEmail').value);
        //5. regexp email
        if(sID != sID2){
            this.alertLocal("Error in Step-1: Please check your input in the Re-enter Email field. The two emails you entered must match.");
            xAddClass($('emailReL'),'highLight');
            return;
        }
        //10. regexp names
        var sLastname =  this.sSterilize(this.sSterilize($('signUpLname').value));
        if(!this.bTestAToZ(sLastname,2)){
            this.alertLocal("Error in Step-1: Please check your input in the Last Name field. The last name must have at least two characters. ");
            xAddClass($('lastNameL'),'highLight');
            return;
        }
        var sFirstname =  this.sSterilize($('signUpFname').value);
        if(!this.bTestAToZ(sFirstname, 1)){
            this.alertLocal("Error in Step-1: Please check your input in the First Name field.  ");
            xAddClass($('firstNameL'),'highLight');
            return;
        }
        var sTitle = this.sSterilize($('signUpTitle').value);
        if(sTitle == 'Select One'){
            this.alertLocal("Error in Step-1: Please select an option in the \"Title\" field.");
            xAddClass($('titleL'),'highLight');
            return;
        }
        var sClassification = $('signUpType').selectedIndex; // 1: student; 2: educator; 3 professional; 4: other;
        if(sClassification == 0){
            this.alertLocal("Error in Step-1: Please select an option in the \"Account Type\" field.");
            xAddClass($('actypeL'),'highLight');
            return;
        }
        var sDepartment = this.sSterilize($('signUpCollege').value);
        if(sDepartment == 'Select One'){
            this.alertLocal("Error in Step-2: Please select an option in the \"College/Department\" field.");
            xAddClass($('collegeL'),'highLight');
            return;
        }
        var sOrganization = this.sSterilize($('address').value);
        if(!this.bTestAToZ(sOrganization,3)){
            this.alertLocal("Error in Step-2: Please check your input in the \"University/Company\" field. The minimum length is 3 letters.");
            xAddClass($('addressL'),'highLight');
            return;
        }
        var sWebpage = this.sSterilize($('webpage').value);
//        if(!this.bTestAToZ(sWebpage)){
//            this.alertLocal("Error in Step-2: Please check your input in the \"Web Page/Univ. Name\" field. ");
//            return;
//        }
        var sCountry = this.sSterilize($('signUpCountry').value);
        if(sCountry == 'Select One'){
            this.alertLocal("Error in Step-2: Please select an option in the \"Country\" field.");
            xAddClass($('countryL'),'highLight');
            return;
        }
        var sLicense = '';
        if($('signUpLicense')) {
            var i = $('signUpLicense').selectedIndex;
            sLicense = $('signUpLicense').options[i].value;
        }
        //alert('iLice = '+iLicense);
        if(sLicense == 'Select One'){
            this.alertLocal("Error in Step-2: Please select an option in the \"Campus License\" field.");
            xAddClass($('licenseL'),'highLight');
            return;
        }
        var sWhere = $('signUpWhere').value;
        if(sWhere == 'Select One'){
            this.alertLocal("Error in Step-3: Please select an option in the \"How did you..\" field.");
            xAddClass($('sourceL'),'highLight');
            return;
        }
        //15. create json

        $('createacbutton').disable();
        $('createaccancelbutton').disable();

        //10. php based ajax call
        var oBlogSynch = new SynchronizerPHP("ajaxcodes/phpcurl/", parent.PHPSERVLETPATH+'myaccount/');
        var sInJSON = '{"sEmail": "' + sID + '", "sFirstname": "' + sFirstname + '","sLastname": "' + sLastname + '","sClassification": "' + sClassification + '","sTitle": "' + sTitle + '","sDepartment": "' + sDepartment + '","sOrganization": "' + sOrganization + '","sWebpage": "' + sWebpage + '","sCountry": "' + sCountry + '","sWhere": "' + sWhere + '","sLicense": "' + sLicense + '"}';
        //sInJSON = escape(sInJSON);
        oBlogSynch.standardUpdate(sInJSON, 'createAC.php', this.createACCallback, this);
    },

    //change step2 block based on student, faculty, professional...
    handleTypeChange: function(){
        var sType = $('signUpType').value;
        $('step2').innerHTML = this.sGetStep2HTML(sType);
        $('address').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');
        $('webpage').onkeypress = this.handleEnter.bindAsEventListener(this, this, 'createac');
        if(sType == 'Student' || sType == 'Other'){
            xRemoveClass($('acceptmessage'), 'hide');
            xAddClass($('acceptmessage'), 'show');
            $('createacbutton').value = 'I accept. Create my TEST account.'
        }
        else{ // professional, educators
            xRemoveClass($('acceptmessage'), 'show');
            xAddClass($('acceptmessage'), 'hide');
            $('createacbutton').value = 'Create my TEST account.'
        }
    },

    //php based ajax call for sending pw.
    handleSendPWClick: function(){
        //0. check site checkbox, read email and password
        var sID = $('userid').value;
        //5. regexp email
        if(!this.bTestEmail(sID)){
            this.alertLocal("Please check your input. The login id is the email address you used during account creation. Your password is tied to that email address only. ");
            return;
        }
        $('sendpwbutton').disable();

        //10. php based ajax call
        var oBlogSynch = new SynchronizerPHP("ajaxcodes/phpcurl/", parent.PHPSERVLETPATH+'myaccount/');
        var sInJSON = '{"sID": "' + sID + '"}';
        oBlogSynch.standardUpdate(sInJSON, 'sendPW.php', this.sendPWCallback, this);
    },


    //php based ajax call for sending pw.
    handleChangePWClick: function(){
        //0. test if userid is an email
        var sID = $('userid').value;
        if(!this.bTestEmail(sID)){
            this.alertLocal("Please check your input. The login id is the email address you used during account creation. Your password is tied to that email address only. ");
            return;
        }
        //5. test if the two new passwords are equal
        var sPW = $('oldpw').value.trim();
        var sNewPW = $('newpw').value.trim();
        var sNewPW2 = $('newpw2').value.trim();
        if(sNewPW != sNewPW2){
            this.alertLocal("The two entries for the new password do not match. Please type in your new password again. ");
            //xRemoveClass($('alertBox'), 'hide');
            //xAddClass($('alertBox'), 'show');
            return;
        }

        //10. no funny char in password
        if(!this.bTestPW(sID)){
            this.alertLocal("The password you choose can only contain the following characters: A-Z, a-z, 0-9, and $%*!@. ");
            return;
        }
        //15. Make ws call
        var oBlogSynch = new SynchronizerPHP("ajaxcodes/phpcurl/", parent.PHPSERVLETPATH+'myaccount/');
        var sInJSON = '{"sID": "' + sID + '", "sPW": "' + sPW +'", "sNewPW": "' + sNewPW +'"}';
        oBlogSynch.standardUpdate(escape(sInJSON), 'changePW.php', this.changePWCallback, this);
    },

    // callback after ac creation
    createACCallback: function() {
        // 0. get data from json
        var args = $A(arguments);
        var oSynchronizer = args.shift(); // to nullify
        var sJSON = args.shift();  // all info comes back in it
        var oThis = args.shift();   // want this

        // 5. enable login button even before the try block
        $('createacbutton').enable();
        $('createaccancelbutton').enable();

        try{
            // 5. extract inJson
            var oRpatt = /\{.*\}/; //extract json from verbose return string
            var asJson = sJSON.match(oRpatt);
            if( asJson!=null && asJson.length == 1) sJSON = asJson[0];
            var oInData = eval("(" + sJSON + ")"); // object containing form data

            // 10. handle error and warning
            if(oInData.iError == 10) {
                oThis.alertLocal("You already have an account under the email address you supplied. If you do not recall the password, use the \"Forgot password\" link in the login block to retrieve it.");
                return;
            }
            else if(oInData.iError > 10) {
                oThis.alertLocal("This is an unexpected error. Please try one more time to create the account and if you still face a problem, please write to us at support@thermofluids.net. We regret this inconvenience. ");
                return;
            }

            // 10. alert success
            oThis.alertLocalSoft("Your account has been successfully created. <p/>Please check your inbox and spam folder. Depending on how often your inbox is updated, you should recive an email from thermofluids.net in 10-60 seconds. ");
            oThis.renderLoginBlock();
            xRemoveClass($('alertBox'), 'hide');
            xAddClass($('alertBox'), 'show');
            return;
        }
        catch(err){
            oSynchronizer = null;
            alert("Unexpected Error: If you could email this message to support@thermofluids.net, it will be appreciated. Thank you in advance. Error Message in SendPW: "+err.description);
            return;
        }
        oSynchronizer = null;
        return;
    },


    // callback after pw is sent
    sendPWCallback: function() {
        // 0. get data from json
        var args = $A(arguments);
        var oSynchronizer = args.shift(); // to nullify
        var sJSON = args.shift();  // all info comes back in it
        var oThis = args.shift();   // want this

        // 5. enable login button even before the try block
        $('sendpwbutton').enable();

        try{
            // 5. extract inJson
            var oRpatt = /\{.*\}/; //extract json from verbose return string
            var asJson = sJSON.match(oRpatt);
            if( asJson!=null && asJson.length == 1) sJSON = asJson[0];
            var oInData = eval("(" + sJSON + ")"); // object containing form data

            // 10. handle error and warning
            if(oInData.iError >0) {
                oThis.alertBadLogin(oThis,oInData.iError);
                return;
            }

            // 10. alert success
            oThis.alertLocalSoft("Your password is on its way. Please check your inbox and spam folder. Depending on how often your inbox is updated, you should recive an email from thermofluids.net in 10-60 seconds. ");
            oThis.renderLoginBlock();
            xRemoveClass($('alertBox'), 'hide');
            xAddClass($('alertBox'), 'show');
            return;
        }
        catch(err){
            oSynchronizer = null;
            alert("Unexpected Error: If you could email this message to support@thermofluids.net, it will be appreciated. Thank you in advance. Error Message in SendPW: "+err.description);
            return;
        }
        oSynchronizer = null;
        return;
    },


    // callback after pw is sent
    changePWCallback: function() {
        // 0. get data from json
        var args = $A(arguments);
        var oSynchronizer = args.shift(); // to nullify
        var sJSON = args.shift();  // all info comes back in it
        var oThis = args.shift();   // want this

        // 5. enable login button even before the try block
        $('changepwbutton').enable();

        try{
            // 5. extract inJson
            var oRpatt = /\{.*\}/; //extract json from verbose return string
            var asJson = sJSON.match(oRpatt);
            if( asJson!=null && asJson.length == 1) sJSON = asJson[0];
            var oInData = eval("(" + sJSON + ")"); // object containing form data

            // 10. handle error and warning
            if(oInData.iError >0) {
                oThis.alertBadLogin(oThis,oInData.iError);
                return;
            }

            // 10. alert success

            oThis.alertLocalSoft("Your password has been changed. You can now log in with your new password. ");
            oThis.renderLoginBlock();
            xRemoveClass($('alertBox'), 'hide');
            xAddClass($('alertBox'), 'show');
            return;
        }
        catch(err){
            oSynchronizer = null;
            alert("Unexpected Error: If you could email this message to support@thermofluids.net, it will be appreciated. Thank you in advance. Error Message in SendPW: "+err.description);
            return;
        }
        oSynchronizer = null;
        return;
    },

    // get country names and abbrev.
        sGetCountryOptions: function(){
//            classta country list..
//            for(var hi=0; hi<states.length; hi++)
//                s += "<option value='"+ states[hi] +"'>"+ states[hi] +"</option>";
//            s +=  '</select></td>'+
            var s;
                        s +=  '<option value = "Select One" selected ="selected">Select One</option><option value=US >United States</option><option value=AF>Afghanistan</option><option value=AL>Albania</option><option value=DZ>Algeria</option><option value=AS>American Samoa</option>'+
            '<option value=AD>Andorra</option><option value=AO>Angola</option><option value=AI>Anguilla</option><option value=AQ>Antarctica</option><option value=AG>Antigua and Barbuda</option><option value=AR>Argentina</option><option value=AM>Armenia</option><option value=AW>Aruba</option><option value=AU>Australia</option><option value=AT>Austria</option><option value=AZ>Azerbaijan</option>'+
            '<option value=BS>Bahamas</option><option value=BH>Bahrain</option><option value=BD>Bangladesh</option><option value=BB>Barbados</option><option value=BY>Belarus</option><option value=BE>Belgium</option><option value=BZ>Belize</option><option value=BJ>Benin</option><option value=BM>Bermuda</option><option value=BT>Bhutan</option><option value=BO>Bolivia</option><option value=BA>Bosnia and Herzegowina</option><option value=BW>Botswana</option><option value=BV>Bouvet Island</option>'+
            '<option value=BR>Brazil</option><option value=IO>British Indian Ocean Territory</option><option value=BN>Brunei Darussalam</option><option value=BG>Bulgaria</option><option value=BF>Burkina Faso</option><option value=BI>Burundi</option><option value=KH>Cambodia</option><option value=CM>Cameroon</option><option value=CA>Canada</option><option value=CV>Cape Verde</option><option value=KY>Cayman Islands</option>'+
            '<option value=CF>CentralAfrican Republic</option><option value=TD>Chad</option><option value=CL>Chile</option><option value=CN>China</option><option value=CX>Christmas Island</option><option value=CC>Cocos (Keeling) Islands</option><option value=CO>Colombia</option><option value=KM>Comoros</option><option value=CG>Congo</option><option value=CK>Cook Islands</option><option value=CR>Costa Rica</option><option value=CI>Cote D\'Ivoire</option>'+
            '<option value=HR>Croatia (local name: Hrvatska)</option><option value=CU>Cuba</option><option value=CY>Cyprus</option><option value=CZ>Czech Republic</option><option value=DK>Denmark</option><option value=DJ>Djibouti</option><option value=DM>Dominica</option><option value=DO>Dominican Republic</option><option value=TP>East Timor</option><option value=EC>Ecuador</option><option value=EG>Egypt</option><option value=SV>El Salvador</option><option value=GQ>Equatorial Guinea</option>'+
            '<option value=ER>Eritrea</option><option value=EE>Estonia</option><option value=ET>Ethiopia</option><option value=FK>Falkland Islands (Malvinas)</option><option value=FO>Faroe Islands</option><option value=FJ>Fiji</option><option value=FI>Finland</option><option value=FR>France</option><option value=FX>France, Metropolitan</option><option value=GF>French Guiana</option><option value=PF>French Polynesia</option>'+
            '<option value=TF>French Southern Territories</option><option value=GA>Gabon</option><option value=GM>Gambia</option><option value=GE>Georgia</option><option value=DE>Germany</option><option value=GH>Ghana</option><option value=GI>Gibraltar</option><option value=GR>Greece</option><option value=GL>Greenland</option><option value=GD>Grenada</option><option value=GP>Guadeloupe</option><option value=GU>Guam</option>'+
            '<option value=GT>Guatemala</option><option value=GN>Guinea</option><option value=GW>Guinea-Bissau</option><option value=GY>Guyana</option><option value=HT>Haiti</option><option value=HM>Heard and Mc Donald Islands</option><option value=HN>Honduras</option><option value=HK>Hong Kong</option><option value=HU>Hungary</option><option value=IS>Iceland</option><option value=IN>India</option><option value=ID>Indonesia</option>'+
            '<option value=IR>Iran (Islamic Republic of)</option><option value=IQ>Iraq</option><option value=IE>Ireland</option><option value=IL>Israel</option><option value=IT>Italy</option><option value=JM>Jamaica</option><option value=JP>Japan</option><option value=JO>Jordan</option><option value=KZ>Kazakhstan</option><option value=KE>Kenya</option><option value=KI>Kiribati</option><option value=KP>Korea, Democratic People\'s Republic of</option>'+
            '<option value=KR>Korea, Republic of</option><option value=KW>Kuwait</option><option value=KG>Kyrgyzstan</option><option value=LA>Lao People\'s Democratic Republic</option><option value=LV>Latvia</option><option value=LB>Lebanon</option><option value=LS>Lesotho</option><option value=LR>Liberia</option><option value=LY>Libyan Arab Jamahiriya</option><option value=LI>Liechtenstein</option><option value=LT>Lithuania</option>'+
            '<option value=LU>Luxembourg</option><option value=MO>Macau</option><option value=MK>Macedonia, the former Yugoslav Republic of</option><option value=MG>Madagascar</option><option value=MW>Malawi</option><option value=MY>Malaysia</option><option value=MV>Maldives</option><option value=ML>Mali</option><option value=MT>Malta</option><option value=MH>Marshall Islands</option><option value=MQ>Martinique</option><option value=MR>Mauritania</option><option value=MU>Mauritius</option>'+
            '<option value=YT>Mayotte</option><option value=MX>Mexico</option><option value=FM>Micronesia, Federated States of</option><option value=MD>Moldova, Republic of</option><option value=MC>Monaco</option><option value=MN>Mongolia</option><option value=MS>Montserrat</option><option value=MA>Morocco</option><option value=MZ>Mozambique</option><option value=MM>Myanmar</option><option value=NA>Namibia</option><option value=NR>Nauru</option>'+
            '<option value=NP>Nepal</option><option value=NL>Netherlands</option><option value=AN>Netherlands Antilles</option><option value=NC>New Caledonia</option><option value=NZ>New Zealand</option><option value=NI>Nicaragua</option><option value=NE>Niger</option><option value=NG>Nigeria</option><option value=NU>Niue</option><option value=NF>Norfolk Island</option><option value=MP>Northern Mariana Islands</option><option value=NO>Norway</option>'+
            '<option value=OM>Oman</option><option value=PK>Pakistan</option><option value=PW>Palau</option><option value=PA>Panama</option><option value=PG>Papua New Guinea</option><option value=PY>Paraguay</option><option value=PE>Peru</option><option value=PH>Philippines</option><option value=PN>Pitcairn</option><option value=PL>Poland</option><option value=PT>Portugal</option><option value=PR>Puerto Rico</option><option value=QA>Qatar</option>'+
            '<option value=RE>Reunion</option><option value=RO>Romania</option><option value=RU>Russian Federation</option><option value=RW>Rwanda</option><option value=KN>Saint Kitts and Nevis</option><option value=LC>Saint Lucia</option><option value=VC>Saint Vincent and the Grenadines</option><option value=WS>Samoa</option><option value=SM>San Marino</option><option value=ST>Sao Tome and Principe</option><option value=SA>Saudi Arabia</option>'+
            '<option value=SN>Senegal</option><option value=CS>Serbia and Montenegro</option><option value=SC>Seychelles</option><option value=SL>Sierra Leone</option><option value=SG>Singapore</option><option value=SK>Slovakia (Slovak Republic)</option><option value=SI>Slovenia</option><option value=SB>Solomon Islands</option><option value=SO>Somalia</option><option value=ZA>South Africa</option><option value=ES>Spain</option><option value=LK>Sri Lanka</option>'+
            '<option value=SH>St. Helena</option><option value=PM>St. Pierre and Miquelon</option><option value=SD>Sudan</option><option value=SR>Suriname</option><option value=SJ>Svalbard and Jan Mayen Islands</option><option value=SZ>Swaziland</option><option value=SE>Sweden</option><option value=CH>Switzerland</option><option value=SY>Syrian Arab Republic</option><option value=TW>Taiwan</option><option value=TJ>Tajikistan</option><option value=TZ>Tanzania, United Republic of</option>'+
            '<option value=TH>Thailand</option><option value=TG>Togo</option><option value=TK>Tokelau</option><option value=TO>Tonga</option><option value=TT>Trinidad and Tobago</option><option value=TN>Tunisia</option><option value=TR>Turkey</option><option value=TM>Turkmenistan</option><option value=TC>Turks and Caicos Islands</option><option value=TV>Tuvalu</option><option value=UG>Uganda</option><option value=UA>Ukraine</option><option value=AE>United Arab Emirates</option>'+
            '<option value=GB>United Kingdom</option><option value=UM>United States Minor Outlying Islands</option><option value=UY>Uruguay</option><option value=UZ>Uzbekistan</option><option value=VU>Vanuatu</option><option value=VA>Vatican City State (Holy See)</option><option value=VE>Venezuela</option><option value=VN>Vietnam</option><option value=VG>Virgin Islands (British)</option><option value=VI>Virgin Islands (U.S.)</option><option value=WF>Wallis And Futuna Islands</option><option value=EH>Western Sahara</option><option value=YE>Yemen</option><option value=ZM>Zambia</option><option value=ZW>Zimbabwe</OPTION>';
            return s;
        },

    //generate html for student/prof/educators account
    sGetStep2HTML: function(sType){

        var s = '';
        if(sType == 'Student'){
            s = '<fieldset>'+
            '<legend>'+
            'Step-2 of 3: Minimal personal information about you:'+
            '</legend>'+
            '<table border="0" cellspacing="5" width="98%">'+

            '<tr>'+

            '<td class="tdata"><label id="collegeL" class = "label3">College/Department</label></td>'+
            '<td><select id="signUpCollege" name="signUpCollege">'+
            '<option value = "Select One" selected ="selected">Select One</option><option value = "Mechanical Engineering" >Mechanical Engineering</option><option value = "Chemical Engineering" >Chemical Engineering</option><option value = "Engineering" >Engineering</option><option value = "Physics" >Physics</option><option value = "Chemistry" >Chemistry</option><option value = "Other" >Other</option>'+
            '</select><div id="tsignUpCollege"></div></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata" width="20%"><label id="addressL" class = "label3">University Name</label></td>'+
            '<td width = "80%" align = "left"><input id="address" name="address" type="text"  maxlength = "64" class="wide" />'+
            '<input id="webpage"  maxlength = "100" type="hidden"  value = "" />' +
            '</td>'+
            '</tr>'+

            '<tr>'+

            '<td class="tdata"><label id="countryL" class = "label3">Country</label></td><td><select id="signUpCountry" name="signUpCountry">';
            s +=  this.sGetCountryOptions();
            s +='</select></td>';
//            for(var hi=0; hi<states.length; hi++)
//                s += "<option value='"+ states[hi] +"'>"+ states[hi] +"</option>";
//            s +=  '</select></td>'+
            '<td>&nbsp;</td>'+
            '<td>&nbsp;</td>'+

            '</tr>'+
            '</table>'+
            '</fieldset>';
            return s;
        }
        //educators
        if(sType == 'Educator'){

            s = '<fieldset id = "educator">'+
            '<legend>'+
            'Step-2 of 3: Personal information to authenticate you as an educator:'+
            '</legend>'+
            '<table border="0" cellspacing="5" width="98%">'+

            '<tr>'+
            '<td class="tdata"><label id="collegeL" class = "label3">College/Department</label></td>'+
            '<td><select id="signUpCollege" name="signUpCollege">'+
            '<option value = "Select One" selected ="selected">Select One</option><option value = "Mechanical Engineering"  >Mechanical Engineering</option><option value = "Chemical Engineering" >Chemical Engineering</option><option value = "Engineering" >Engineering</option><option value = "Physics" >Physics</option><option value = "Chemistry" >Chemistry</option><option value = "Other" >Other</option>'+
            '</select></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata" width="20%"><label id="addressL" class = "label3">University Name</label></td>'+
            '<td width = "70%" align = "left"><input id="address" name="address" type="text"  maxlength = "64" class="wide" /></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata"><label id="webpageL" class = "label3">Web Page</label></td>'+
            '<td><input id="webpage"  maxlength = "64" type = "text" value="http://" class="wide" maxlength = "'+this.iNAMEMAX+'" /> </td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata"><label id="countryL" class = "label3">Country</label></td><td><select id="signUpCountry" name="signUpCountry">';
            s +=  this.sGetCountryOptions();
            s +='</select></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata"><label id="licenseL" class = "label3">Campus License?</label></td>'+
            '<td><select id="signUpLicense" name="signUpLicense" style = "line-height: 2; ">'+
            '<option value = "Select One" selected="selected" >Select One</option><option value = "educatorRegular"  >Let me evaluate TEST first</option><option value = "educatorPlus" >Please upgrade my license and set us up for a campus license.</option>'+
            '</select></td>'+
            '</tr>'+

            '</table>'+
            '</fieldset>';
            return s;
        }
        //professionals, others (address means company name and webpage means univ. name.)
        else if (sType == 'Professional'){

            s = '<fieldset id = "others">'+
            '<legend>'+
            'Step-2 of 3: Minimal professional information about you:'+
            '</legend>'+
            '<table border="0" cellspacing="5" width="98%">'+

            '<tr>'+
            '<td class="tdata"><label id="collegeL" class = "label3">College/Department</label></td>'+
            '<td><select id="signUpCollege" name="signUpCollege">'+
            '<option value = "Select One" selected ="selected">Select One</option><option value = "Mechanical Engineering" >Mechanical Engineering</option><option value = "Chemical Engineering" >Chemical Engineering</option><option value = "Engineering" >Engineering</option><option value = "Physics" >Physics</option><option value = "Chemistry" >Chemistry</option><option value = "Other" >Other</option>'+
            '</select></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata" width="20%"><label id="addressL" class = "label3">Company Name</label></td>'+
            '<td width = "80%" align = "left"><input id="address" name="webpage" type="text"  maxlength = "64" class="wide" /><input id="webpage" type = "hidden"  class="wide" maxlength = "100" /></td>'+
            '</tr>'+
//
//            '<tr>'+
//            '<td class="tdata"><label id="webpageL" class = "label3">Company Website</label></td>'+
//            '<td><input id="address" type = "hidden"  class="wide" maxlength = "100" /> </td>'+
//            '</tr>'+

            '<tr>'+
            '<td class="tdata"><label id="countryL" class = "label3">Country</label></td><td><select id="signUpCountry" name="signUpCountry">';
            s +=  this.sGetCountryOptions();
            s +='</select>';
            s+='</td><td>&nbsp;</td>'+
            '<td>&nbsp;</td>'+
            '</tr>'+

            '</table>'+
            '</fieldset>';
            return s;
        }
        //others (address means company name and webpage means univ. name.)
        else{
            s = '<fieldset id = "others">'+
            '<legend>'+
            'Step-2 of 3: Minimal professional information about you:'+
            '</legend>'+
            '<table border="0" cellspacing="5" width="98%">'+

            '<tr>'+
            '<td class="tdata"><label id="collegeL" class = "label3">Background</label></td>'+
            '<td><select id="signUpCollege" name="signUpCollege">'+
            '<option value = "Select One" selected ="selected">Select One</option><option value = "Mechanical Engineering" >Mechanical Engineering</option><option value = "Chemical Engineering" >Chemical Engineering</option><option value = "Engineering" >Engineering</option><option value = "Physics" >Physics</option><option value = "Chemistry" >Chemistry</option><option value = "Other" >Other</option>'+
            '</select><input id="webpage" name="webpage" type="hidden"  /></td>'+
            '</tr>'+

            '<tr>'+
            '<td class="tdata" width="20%"><label id="addressL" class = "label3">University Name</label></td>'+
            '<td width = "80%" align = "left"><input id="address" name="address" type="text"  maxlength = "64" class="wide" />'+
            '<input id="webpage"  maxlength = "100" type="hidden"  value = "" />' +
            '</td>'+
            '</tr>'+


            '<tr>'+
            '<td class="tdata"><label id="countryL" class = "label3">Country</label></td><td><select id="signUpCountry" name="signUpCountry">';
            s +=  this.sGetCountryOptions();
            s +='</select>';
            s+='</td><td>&nbsp;</td>'+
            '<td>&nbsp;</td>'+
            '</tr>'+

            '</table>'+
            '</fieldset>';
            return s;
        }

    }



});
