function toggleUserAgreement(){
    var elem = document.getElementById('user_agreement');
     if(elem.style.display != 'none')
     {
       elem.style.display = 'none';
     }
     else
     {
       elem.style.display = 'block';
     }
	/*deals with inital hide */
	elem.style.position = 'relative';
	elem.style.left = '0px';
}

var auth_module = new Object();
auth_module.AC_LOGIN   = new Object();
auth_module.AC_NEWUSER = new Object();
auth_module.AC_FORGOT  = new Object();
auth_module.AC_WELCOME = new Object();

// constants used in conjunction with ajaxlogin page
auth_module.AUTH_SUCCESS   = 1;
auth_module.AC_LOGIN.name  = "l";
auth_module.AC_NEWUSER.name= "n";
auth_module.AC_FORGOT.name = "f";

auth_module.AUTH_MSGBOX = 
    '<div id="authTitle"></div>' +
    '<form name="loginForm" onsubmit="auth_module.submitPage(); return false;"' +
    '    method="POST" action="">' +
    '<div id="authErrorMsg"></div>' +
    '<div id="authSuccessMsg"></div>' +
    '<div id="authForm">' +
    '    <table id="login"><tr>' +
    '        <td id="col1">E-mail Address:</td>' +
    '        <td><input size="25" name="userEmail" id="userEmail"' +
    '            onkeyup="auth_module.tabnext(event, 0)" /></td>' +
    '    </tr></table>' +
    '    <div id="authContent"></div>' +
    '</div>' +
    '</form>' +
    '<div class="center" id="authSwitch"></div>' +
    '<br />';

auth_module.AC_LOGIN.title   = "<b>Sign in</b> with your Graceful Tools account.";
auth_module.AC_NEWUSER.title = "<b>New to Graceful Tools</b>? Sign up for an account.";
auth_module.AC_FORGOT.title  = "<b>Forgot your password?</b> Let us mail it to you.";
auth_module.AC_WELCOME.title = "<b>Thank You for Registering!</b>";

auth_module.AC_LOGIN.content =
    '<table id="login"><tr>' +
    '    <td id="col1">Password:</td>' +
    '    <td><input size="25" name="userPassword" type="password" id="userPassword"' +
    '        onkeyup="auth_module.tabnext(event, 2)" /></td>' +
    '</tr><tr></table><table id="login">' +
    '    <td colspan="2" class="center submit">' +
    '        <br />' +
    '        <input type="submit" value="Sign In" id="authSubmit"' +
    '            onkeyup="auth_module.tabnext(event, 3)" />' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' +
    '        <input type="button" onclick="hidePopWin(true)" value="Cancel"' +
    '            id="authCancel" onkeyup="auth_module.tabnext(event, 4)" />' +
    '    </td>' +
    '</tr>' +
    '</table>' +
    '</form>';
auth_module.AC_NEWUSER.content =
    '<table id="login"><tr>' +
    '    <td id="col1">Password:</td>' +
    '    <td><input size="25" name="userPassword" type="password" id="userPassword"' +
    '        onkeyup="auth_module.tabnext(event, 1)" /></td>' +
    '</tr><tr>' +
    '    <td>Confirm Password:</td>' +
    '    <td><input size="25" name="confirmPassword" type="password" id="confirmPassword"' +
    '        onkeyup="auth_module.tabnext(event, 2)" /></td>' +
    '</tr><tr><td colspan="2" class="center"><div style="display:none;" id="user_agreement">' +
    '<textarea cols="57" rows="8">USER AGREEMENT \n\n'+
    'Effective Date: January 1, 2009\n\n'+

'To review material modifications and their effective dates scroll to the bottom of the page.\n\n'+
'1.	Parties.  The parties to this legal Agreement are you, and Graceful Tools Inc (GT).  If you are not acting on behalf of yourself as an individual, then "you", "your", and "yourself" means your company or organization.  All references to “we”, "us", "our", "this website" or "this site" shall be construed to mean this gracefultools.com website business and GT.\n\n'+
'2.	Agreement.  The legal Agreement between you and GT consists of this USER AGREEMENT, plus our Terms of Use and Privacy Policy which are incorporated herein and accessible on this site’s home page.  If there is any conflict between this USER AGREEMENT and the Terms of Use, this USER AGREEMENT shall take precedence.\n\n'+
'3.	Modification of Agreement.  We reserve the right to modify this Agreement at any time by posting an amended Agreement that is always accessible through a link on this site\'s home page and/or by giving you prior notice of a modification.  You should check this Agreement periodically for modifications by scrolling to the bottom of this page for a listing of material modifications and their effective dates. IF ANY MODIFICATION IS UNACCEPTABLE TO YOU, YOUR ONLY RECOURSE IS TO TERMINATE THIS AGREEMENT. YOUR CONTINUED USE OF THIS SITE FOLLOWING OUR POSTING OF AN AMENDED AGREEMENT OR PROVIDING YOU NOTICE OF A MODIFICATION WILL CONSTITUTE BINDING ACCEPTANCE.'+
'4.	Subscription Eligibility.  Subscriptions are not available to minors under the age of 13 and any user that has been suspended or removed from the system.\n\n'+
'5.	Subscription Services.  Subscription services include access to Graceful Tools for the following services including: event management, appointment confirmation, meeting scheduling and survey administration. ("Services").  We reserve the right to update and modify the Services from time to time.\n\n'+
'6.	Subscription Use And Restrictions.  Subject to the terms and conditions of this Agreement, our Terms of Use, and our Privacy Policy, you may access and use this site\'s Services, but only for your own internal purposes.  All rights not expressly granted in this Agreement are reserved by us and our licensors.\n\n'+
'	6.1	You will be granted a single login ID and password for each subscription that you purchase, and your access and use the Services will be limited to one person at a time per ID and password. You agree not to access (or attempt to access) this site by any means other than through the interface we provide, unless you have been specifically allowed to do so in a separate agreement. You agree not to access (or attempt to access) this site through any automated means (including use of scripts or web crawlers), and you agree to comply with the instructions set out in any robots.txt file present on this site. \n\n'+
'	6.2	You are not authorized to (i) resell, sublicense, transfer, assign, or distribute the site, its Services or content; (ii) modify or make derivative works based upon the site, its Services or content; (iii) except for linking to this site’s home page, create Internet links to the site, its Services or content, or (iv) "frame" or "mirror" any site, its Services or content on any other server or Internet-enabled device. \n\n'+
'	6.3	You are not authorized to use our Services or servers for the propagation, distribution, housing, processing, storing, or otherwise handling in any way lewd, obscene, or pornographic material, or any other material which we deem to be objectionable. The designation of any such materials is entirely at our sole discretion.\n\n'+
'7.	Ownership.  We are the sole owner of this website business, the Services, and any suggestions, ideas, enhancement requests, feedback, recommendations or other information provided by you or any other party relating to this site or the Services.  This Agreement is not a sale and does not convey to you any rights of ownership.  Our name, logo, and the product/services names associated with this site are our proprietary trademarks (and our licensors’, where applicable), and no right or license is granted to use them.\n\n'+
'8.	Termination.  You agree that we may terminate your account and access to the Services for cause without prior notice, upon the occurrence of any one of the following: (i) any material breach of this Agreement, including without limitation any failure to pay fees as they become due or any unauthorized use of the site or Services, or (ii) requests by law enforcement or other government agencies.  Termination of your account includes (i) removal of access to all Services, and (ii) deletion of your login data, password, and all related information.  Further, you agree that all terminations shall be made in our sole discretion, and that we will not be liable to you or any third-party for any termination of your account or access to Services.  If we elect to terminate this Agreement for cause, we may elect, in our sole discretion, not to refund any prepaid fees or other amounts to you.  \n\n'+
'9.	Your Account-Related Responsibilities.  You are responsible for maintaining the confidentiality of your login ID, password, and any additional information that we may provide regarding accessing your account. If you knowingly share your login ID and password with another person who is not authorized to use the Services, this Agreement is subject to termination for cause.  You agree to immediately notify us of any unauthorized use of your login ID, password, or account or any other breach of security regarding the subscription services. \n\n'+
'10.	Subscription Fees.  Initially, subscription services are offered free of charge.  However, we reserve the right to charge subscription fees upon notice to you in the future.  If you elect to pay subscription fees, fees may be by credit card online at this site, or by any other method approved by us.  Fees are non-refundable, unless expresly provided otherwise on this site or in this Agreement.  If for any reason we are unable to charge your credit card with the full amount of the fees, or if we are charged back for any fee previously charged to your credit card, you agree that we may pursue all available remedies to enforce the payment obligation, including without limitation, suspension or termination of your subscription  license.\n\n'+
'11.	Warranty Disclaimers.  EXCEPT AS MAY BE PROVIDED IN ANY SEPARATE WRITTEN AGREEMENTS SIGNED BY THE PARTIES, THE SERVICES, CONTENT, AND/OR PRODUCTS ON THIS SITE ARE PROVIDED “AS-IS”, AND NEITHER WE NOR ANY OF OUR LICENSORS MAKE ANY REPRESENTATION OR WARRANTY WITH RESPECT TO SUCH PRODUCTS, SERVICES, AND/OR CONTENT.  EXCEPT AS MAY BE PROVIDED IN ANY SEPARATE WRITTEN AGREEMENT SIGNED BY THE PARTIES OR SEPARATE AGREEMENT ORIGINATING FROM THIS SITE, THIS SITE AND ITS LICENSORS SPECIFICALLY DISCLAIM, TO THE FULLEST EXTENT PERMITTED BY LAW, ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, RELATING TO THIS SITE OR PRODUCTS, SERVICES AND/OR CONTENT ACQUIRED FROM THIS SITE, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, COMPLETENESS, TIMELINESS, CORRECTNESS, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE.  THIS SITE AND ITS LICENSORS DO NOT REPRESENT OR WARRANT THAT THIS SITE, ITS PRODUCTS, SERVICES, AND/OR CONTENT: (A) WILL BE SECURE, TIMELY, UNINTERRUPTED OR ERROR-FREE OR OPERATE IN COMBINATION WITH ANY OTHER HARDWARE, SOFTWARE, SYSTEM OR DATA, (B) WILL MEET YOUR REQUIREMENTS OR EXPECTATIONS, OR (C) WILL BE FREE OF VIRUSES OR OTHER HARMFUL COMPONENTS. THESE DISCLAIMERS CONSTITUTE AN ESSENTIAL PART OF THIS AGREEMENT.  NO PURCHASE OR USE OF THE ITEMS OFFERED BY THIS SITE IS AUTHORIZED HEREUNDER EXCEPT UNDER THESE DISCLAIMERS.  IF IMPLIED WARRANTIES MAY NOT BE DISCLAIMED UNDER APPLICABLE LAW, THEN ANY IMPLIED WARRANTIES ARE LIMITED IN DURATION TO THE PERIOD REQUIRED BY APPLICABLE LAW.  SOME STATES OR JURISDICTIONS DO NOT ALLOW LIMITATIONS ON HOW LONG AN IMPLIED WARRANTY MAY LAST, SO THE ABOVE LIMITATIONS MAY NOT APPLY TO YOU.\n\n'+
'12.	Limitation of Liability.  IN NO EVENT SHALL EITHER PARTY\'S AGGREGATE LIABILITY EXCEED THE AMOUNTS ACTUALLY PAID BY AND/OR DUE FROM YOU, IF ANY, IN THE SIX (6) MONTH PERIOD IMMEDIATELY PRECEDING THE EVENT GIVING RISE TO SUCH CLAIM.  IN NO EVENT SHALL EITHER PARTY AND/OR ITS LICENSORS BE LIABLE TO ANYONE FOR ANY INDIRECT, PUNITIVE, SPECIAL, EXEMPLARY, INCIDENTAL, CONSEQUENTIAL OR OTHER DAMAGES OF ANY TYPE OR KIND (INCLUDING LOSS OF DATA, REVENUE, PROFITS, USE OR OTHER ECONOMIC ADVANTAGE) ARISING OUT OF, OR IN ANY WAY CONNECTED WITH THE SERVICES, INCLUDING WITHOUT LIMITATION THE USE OR INABILITY TO USE THE SERVICES, OR FOR ANY CONTENT OBTAINED FROM OR THROUGH THE SERVICES OR THIS SITE, ANY INTERRUPTION, INACCURACY, ERROR OR OMISSION, REGARDLESS OF CAUSE, EVEN IF THE PARTY FROM WHICH DAMAGES ARE BEING SOUGHT OR SUCH PARTY\'S LICENSORS HAVE BEEN PREVIOUSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\n\n'+
'13.	Intended For Use Only In The United States.  This site is intended for use only from within the United States. We do not represent that this site is appropriate for use elsewhere.  Access to this site from locations where its contents are illegal is not authorized.\n\n'+
'14.	Onward Transfer of Personal Information Outside Your Country of Residence.  Any personal information which we may collect on this site will be stored and processed in our servers located only in the United States.  If you reside outside the United States, you consent to the transfer of personal information outside your country of residence to the United States.\n\n'+
'15.	Export Control.  This site provides Services and uses software and technology that may be subject to United States export controls administered by the U.S. Department of Commerce, the United States Department of Treasury Office of Foreign Assets Control, and other U.S. agencies and the export control regulations of Switzerland and the European Union. The user of this site ("User") acknowledges and agrees that the site and Services shall not be used in, and none of the underlying information, software, or technology may be transferred or otherwise exported or re-exported to, countries to which the United States, Switzerland and/or the European Union maintains an embargo (collectively, "Embargoed Countries"), or to or by a national or resident thereof, or any person or entity on the U.S. Department of Treasury\'s List of Specially Designated Nationals or the U.S. Department of Commerce\'s Table of Denial Orders (collectively, "Designated Nationals"). The lists of Embargoed Countries and Designated Nationals are subject to change without notice. By using the subscription service, you represent and warrant that you are not located in, under the control of, or a national or resident of an Embargoed Country or Designated National. You agree to comply strictly with all U.S., Swiss and European Union export laws and assume sole responsibility for obtaining licenses to export or re-export as may be required. \n\n'+
'16.	Registration Data.  Registration is required for you to establish an account at this site.  You agree (i) to provide certain current, complete, and accurate information about you as prompted to do so by our online registration form ("Registration Data"), and (ii) to maintain and update such Registration Data as required to keep such information current, complete and accurate.  You warrant that your Registration Data is and will continue to be accurate and current, and that you are authorized to provide such Registration Data.  You authorize us to verify your Registration Data at any time.  If any Registration Data that you provide is untrue, inaccurate, not current or incomplete, we retain the right, in its sole discretion, to suspend or terminate rights to use your account.  Solely to enable us to use information you supply us internally, so that we are not violating any rights you might have in that information, you grant to us a nonexclusive license to (i) convert such information into digital format such that it can be read, utilized and displayed by our computers or any other technology currently in existence or hereafter developed capable of utilizing digital information, and (ii) combine the information with other content provided by us in each case by any method or means or in any medium whether now known or hereafter devised.\n\n'+
'17.	How We Treat Postings To This Site.  We will not treat information that you post to areas of this site that are viewable by others as proprietary, private, or confidential.  We have no obligation to monitor posts to this site or to exercise any editorial control over such posts; however, we reserve the right to review such posts and to remove any material that, in our judgment, is not appropriate.  Posting, transmitting, promoting, using, distributing or storing content that could subject us to any legal liability, whether in tort or otherwise, or that is in violation of any applicable law or regulation, or otherwise contrary to commonly accepted community standards, is prohibited, including without limitation information and material protected by copyright, trademark, trade secret, nondisclosure or confidentiality agreements, or other intellectual property rights, and material that is obscene, defamatory, constitutes a threat, or violates export control laws. \n\n'+
'18.	Defamation; Communications Decency Act Notice.  This site is a provider of “interactive computer services” under the Communications Decency Act, 47 U.S.C. Section 230, and as such, our liability for defamation and other claims arising out of any postings to this site by third parties is limited as described therein.  We are not responsible for content or any other information posted to this site by third parties.  We neither warrant the accuracy of such postings or exercise any editorial control over such posts, nor do we assume any legal obligation for editorial control of content posted by third parties or liability in connection with such postings, including any responsibility or liability for investigating or verifying the accuracy of any content or any other information contained in such postings.\n\n'+
'19.	Monitoring.  We reserve the right to monitor your access and use of this website without notification to you.  We may record or log your use in a manner as set out in our Privacy Policy that is accessible through the Privacy Policy link on this site’s home page. \n\n'+
'20.	Privacy And Security.  You may access, read, and print our policies regarding privacy and security through the Privacy Policy link on our site\'s home page.  As stated in our Privacy Policy, we reserve the right to modify our terms regarding privacy and security from time to time.  In your review of our Privacy Policy, please note our policies regarding email notice to you and your rights to opt out of such emails.  Provided that we comply with the security policies specified in our Privacy Policy, we will not, under any circumstances, be held responsible or liable for situations where information or transmissions are accessed by third parties through illegal or illicit means or through the exploitation of security vulnerabilities in our site and network.  We will promptly report to you any unauthorized access to your information promptly upon discovery, and we will use diligent efforts to promptly remedy any security vulnerability that permitted the unauthorized access.  If notification to persons affected by the unauthorized access is required, you agree to be solely responsible for any and all such notifications at your expense. \n\n'+
'21.	Notices.  We may give notice to you by means of (i) a general notice in your account information, (ii) by electronic mail to your e-mail address on record in your Registration Data, or (iii) by written communication sent by first class mail or pre-paid post to your address on record in your Registration Data.  Such notice shall be deemed to have been given upon the expiration of forty eight (48) hours after mailing or posting (if sent by first class mail or pre-paid post) or twelve (12) hours after sending (if sent by email).  You may give notice to us (such notice shall be deemed given when received by us) at any time by any of the following: (a) by letter sent by confirmed facsimile to us at the following fax number, 888-974-7284; or (b) by letter delivered by nationally recognized overnight delivery service or first class postage prepaid mail to us as follows: Graceful Tools Inc., 644 S California Ave, , Palo Alto, CA 94306, in either case, addressed to the attention of “President of the Company”.  Notices will not be effective unless sent in accordance with the above requirements.\n\n'+
'22.	Arbitration.  Except for actions to protect intellectual property rights and to enforce an arbitrator’s decision hereunder, all disputes, controversies, or claims arising out of or relating to this Agreement or a breach thereof shall be submitted to and finally resolved by arbitration under the rules of the American Arbitration Association (“AAA”) then in effect.  There shall be one arbitrator, and such arbitrator shall be chosen by mutual agreement of the parties in accordance with AAA rules.  The arbitration shall take place in Palo Alto, California, USA, and may be conducted by telephone or online.  The arbitrator shall apply the laws of the State of California, USA to all issues in dispute.  The controversy or claim shall be arbitrated on an individual basis, and shall not be consolidated in any arbitration with any claim or controversy of any other party.  The findings of the arbitrator shall be final and binding on the parties, and may be entered in any court of competent jurisdiction for enforcement. Enforcements of any award or judgment shall be governed by the United Nations Convention on the Recognition and Enforcement of Foreign Arbitral Awards.  Should either party file an action contrary to this provision, the other party may recover attorney\'s fees and costs up to $1000.00.\n\n'+
'23.	Jurisdiction And Venue.  The courts of Santa Clara County in the State of California, USA and the nearest U.S. District Court shall be the exclusive jurisdiction and venue for all legal proceedings that are not arbitrated under this Agreement.\n\n'+
'24.	Severability.   If any provision of this Agreement is declared invalid or unenforceable, such provision shall be deemed modified to the extent necessary and possible to render it valid and enforceable.  In any event, the unenforceability or invalidity of any provision shall not affect any other provision of this Agreement, and this Agreement shall continue in full force and effect, and be construed and enforced, as if such provision had not been included, or had been modified as above provided, as the case may be.\n\n'+
'25.	Force Majeure.  We shall not be liable for damages for any delay or failure of delivery arising out of causes beyond our reasonable control and without our fault or negligence, including, but not limited to, Acts of God, acts of civil or military authority, fires, riots, wars, embargoes, Internet disruptions, hacker attacks, or communications failures.\n\n'+
'26.	U.S. Government End-Users. The software for this site consists of "commercial items," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government end-users of this site acquire only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States.\n\n'+
'27.	Survival.  Those clauses the survival of which is necessary for the interpretation or enforcement of this Agreement shall continue in full force and effect in accordance with their terms notwithstanding the expiration or termination hereof, such clauses to include, without limitation, the following: License Restrictions, Warranty Disclaimer, Limitation of Liability, Privacy And Security, Notices, Arbitration, Jurisdiction and Venue, Severability, Force Majeure, and Miscellaneous.\n\n'+
'28.	Miscellaneous.  This Agreement, our Terms of Use, and our Privacy Policy (collectively the "Graceful Tools Terms and Conditions") constitute the entire understanding of the parties with respect to this site and merges all prior communications, representations, and agreements.  If any provision of these Graceful Tools Terms and Conditions is held to be unenforceable for any reason, such provision shall be reformed only to the extent necessary to make it enforceable.  These Graceful Tools Terms and Conditions shall be construed under the laws of the State of California, USA, excluding rules regarding conflicts of law.  The application the United Nations Convention of Contracts for the International Sale of Goods is expressly excluded.  This license is written in English, and English is its controlling language.  If you are located outside the U.S., then the following provisions shall apply: (i) Les parties aux presentes confirment leur volonte que cette convention de meme que tous les documents y compris tout avis qui siy rattache, soient rediges en langue anglaise (translation: "The parties confirm that this Agreement and all related documentation is and will be in the English language."); and  (ii) you are responsible for complying with any local laws in your jurisdiction which might impact your right to import, export or use this site, and you represent that you have complied with any regulations or registration procedures required by applicable law to make this agreement enforceable.</textarea>'+
'</div></td></tr><tr><td colspan="2"><span class="nowrap"><input type="checkbox" name="agreeTOS" ' +
    '        id="agreeTOS"> I have read and agree to the <a href="javascript:void(0);" onclick="toggleUserAgreement();">User Agreement</a>.</span></td>' +
    '</tr><tr><td colspan="2" class="left">' +
    '    <span class="nowrap"><input type="checkbox" name="userContactPref" ' +
    '        checked="1" id="userContactPref" onclick="toggleUserAgreement();"> Email me when Graceful Tools ' +
    '            gets better</span></td>' +
    '</tr><tr></table><table id="login">' +
    '    <td colspan="2" class="center submit">' +
    '        <br />' +
    '        <input type="submit" value="Sign Up" id="authSubmit"' +
    '            onkeyup="auth_module.tabnext(event, 3)" />' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' +
    '        <input type="button" onclick="hidePopWin(true)" value="Cancel"' +
    '            id="authCancel" onkeyup="auth_module.tabnext(event, 4)" />' +
    '    </td>' +
    '</tr>' +
    '</table>' +
    '</form>';
auth_module.AC_FORGOT.content =
    '<table id="login"><tr>' +
    '    <td class="center submit">' +
    '        <br />' +
    '        <input type="submit" value="Send My Password" id="authSubmit"' +
    '            onkeyup="auth_module.tabnext(event, 3)" />' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' +
    '        <input type="button" onclick="hidePopWin(true)" value="Cancel"' +
    '            id="authCancel" onkeyup="auth_module.tabnext(event, 4)" />' +
    '    </td>' +
    '</tr>' +
    '</table>' +
    '</form>';
auth_module.AC_WELCOME.content =
    'Whether you\'re planning a thousand-person event or just meeting ' +
    'friends for coffee, we want to help you plan it gracefully. To get ' +
    'started, please check your email. Once you click the link to verify '+
    'your email address, you\'ll have access to all of our Graceful Tools '+
    '-- absolutely free!<br /><br />' +
    '<div id="login"><div class="center submit"><input type="button" ' +
    '    onclick="auth_module.finishSubmit()" value="OK" /></div></div>';

auth_module.AC_LOGIN.switch_link   = '<a href="javascript:void(0)" onclick=' +
    '"auth_module.setContent(auth_module.AC_LOGIN)">I am an existing user</a>';
auth_module.AC_NEWUSER.switch_link = '<a href="javascript:void(0)" onclick=' +
    '"auth_module.setContent(auth_module.AC_NEWUSER)">New? Sign up now!</a>';
auth_module.AC_FORGOT.switch_link  = '<a href="javascript:void(0)" onclick=' +
    '"auth_module.setContent(auth_module.AC_FORGOT)">I forgot my password</a>';
auth_module.AC_WELCOME.switch_link = '';

auth_module.AC_LOGIN.switch_text = "<br />" +auth_module.AC_NEWUSER.switch_link
    + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + auth_module.AC_FORGOT.switch_link;
auth_module.AC_NEWUSER.switch_text= "<br />" + auth_module.AC_LOGIN.switch_link
    + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + auth_module.AC_FORGOT.switch_link;
auth_module.AC_FORGOT.switch_text = "<br />" + auth_module.AC_LOGIN.switch_link
    + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + auth_module.AC_NEWUSER.switch_link;
auth_module.AC_WELCOME.switch_text = '';

/* display login box. jumps to url when done, or false to stay on page */
auth_module.showLogin = function (url)
{
    auth_module.auth_destination = url;

    // if already good, straight redirect
    if(!LETSAUTH)
    {
        auth_module.currentPage = auth_module.AC_LOGIN;
        auth_module.finishSubmit();
        return;
    }
        
    showPopWin(auth_module.AUTH_MSGBOX, 550, 540, null, false);
    auth_module.setContent(auth_module.AC_LOGIN);
    getObj("popupTitleBar").style.display = "none";
    getObj("popupFrame").style.height = "auto";
    getObj("userEmail").focus();

    // all of these functions return false to reject keypress default behavior
    return false;
}

auth_module.showForget = function (url)
{
    auth_module.auth_destination = url;

    showPopWin(auth_module.AUTH_MSGBOX, 500, 240, null, false);
    auth_module.setContent(auth_module.AC_FORGOT);
    getObj("popupTitleBar").style.display = "none";
    getObj("popupFrame").style.height = "auto";
    getObj("userEmail").focus();
    getObj("authSwitch").innerHTML = "";
    
    return false;
}

/* set the login box to display the appropriate content */
auth_module.setContent = function (content)
{
    // hide the e-mail box?
    if(content == auth_module.AC_WELCOME) {
        getObj("login").style.display = "none";
    } else {
        getObj("login").style.display = "";
    }

    auth_module.currentPage = content;
    getObj("authTitle").innerHTML   = content.title;
    getObj("authContent").innerHTML = content.content;
    getObj("authSwitch").innerHTML  = content.switch_text;
    getObj("authErrorMsg").innerHTML= "";

    return false;
}

auth_module.tabnext = function(e, current)
{
    // we only need tab hack for FF
    if(navigator.userAgent.indexOf("Firefox") == -1 )
        return;

    if((window.event ? keynum = e.keyCode : keynum = e.which) == 9)
    {
        switch(current)
        {
        case 2:
            getObj("authSubmit").focus(); return;
        case 3:
            getObj("authCancel").focus(); return;
        case 4:
            getObj("userEmail").focus(); return;
        }
        switch(auth_module.currentPage)
        {
        case auth_module.AC_LOGIN:
            switch(current)
            {
            case 0:
                getObj("userPassword").focus(); return;
            }
        case auth_module.AC_NEWUSER:
            switch(current)
            {
            case 0:
                getObj("userPassword").focus(); return;
            case 1:
                getObj("confirmPassword").focus(); return;
            }
        case auth_module.AC_FORGOT:
            switch(current)
            {
            case 0:
                getObj("authSubmit").focus(); return;
            }
        }
    }
}

auth_module.submitPage = function()
{
    var queryStr = URLBASE + "modules/auth/ajaxlogin.z";
    var parameters = "userEmail=" + encodeURI(getObj("userEmail").value) +
        "&request=" + encodeURI(auth_module.currentPage.name);

    switch(auth_module.currentPage)
    {
    case auth_module.AC_NEWUSER:
        // make sure passwords are the same
        if(getObj("userPassword").value != getObj("confirmPassword").value) {
            getObj("authErrorMsg").innerHTML = "Passwords don't match";
            auth_module.shakeBox();
            return false;
        }
        if(getObj("userContactPref").checked)
            parameters += "&userContactPref=1";
        if(!getObj("agreeTOS").checked) {
            getObj("authErrorMsg").innerHTML = "You must accept the User " +
                "Agreement before signing up.";
            auth_module.shakeBox();
            return false;
        }
    case auth_module.AC_LOGIN:
        parameters += "&userPassword="+encodeURI(getObj("userPassword").value);
    }
    var xmlHttp = makeXMLHttpRequest();
    xmlHttp.open("POST",queryStr,true);
    xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState != 4)
            return;
        if(xmlHttp.responseText != auth_module.AUTH_SUCCESS)
        {
            getObj("authErrorMsg").innerHTML  = xmlHttp.responseText;
            auth_module.shakeBox();
        }
        else
            auth_module.finishSubmit();
    };
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
    return false;
}

auth_module.finishSubmit = function()
{
    switch(auth_module.currentPage)
    {
    case auth_module.AC_NEWUSER:        // display a little welcome
        auth_module.setContent(auth_module.AC_WELCOME);
        break;
    case auth_module.AC_WELCOME:
    case auth_module.AC_LOGIN:          // take them to the destination page
        if(auth_module.auth_destination)
        {
            if(auth_module.auth_destination instanceof Function)
                auth_module.auth_destination();
            else
                window.location.href = auth_module.auth_destination;
        }
        else // default behavior: refresh
            window.location.reload(true);
        break;
    case auth_module.AC_FORGOT:         // show login page + message
        auth_module.setContent(auth_module.AC_LOGIN);
        getObj("authSuccessMsg").innerHTML  = "A link to change your password"+
            " was e-mailed to you";
    }
}

auth_module.shakeLimit = 4;
auth_module.SHAKE_MOVE_PX = 15;
auth_module.shakeBox = function()
{
    var pos = parseInt(getObj("popupContainer").style.left);
    switch(auth_module.shakeLimit % 4)
    {
    case 0: pos = pos + auth_module.SHAKE_MOVE_PX; break;
    case 1: pos = pos - 2*auth_module.SHAKE_MOVE_PX; break;
    case 2: pos = pos + 2*auth_module.SHAKE_MOVE_PX; break;
    case 3: pos = pos - 2*auth_module.SHAKE_MOVE_PX;
    }
    getObj("popupContainer").style.left = pos + "px";
    if(auth_module.shakeLimit-- > 0)
        setTimeout(auth_module.shakeBox, 50);
    else
        auth_module.shakeLimit = 4; // reset
}

