﻿var agreement = {

    jsonservice : new JSONService(),

    jsonData : null,

    userId : null,

    actions : {},
    
    loginData : null,
    
    loginText : "",
    
    curpwd : "",
    
    newpwd : "",
    
    update: function() {
    
        if(agreement.loginData!=null)    
        {       
                var rdPrivateYes = document.getElementById('rdPrivateYes').checked == true ? "Y" : "N";
                agreement.jsonservice.loadScript("goalsupdate_0001", "services/agreement.aspx?action=add&userid=" + agreement.loginData.login.userid + "&pub="+rdPrivateYes+"&callback=agreement.showChangePassword&expires=5");
        }
        
    },
    
    
    showChangePassword : function() {
        var html = [];
        html[html.length] = '<table cellpadding="5" cellspacing="0" width="500px">';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td class="edit-title" width="100%" colspan = "2">&nbsp;Change Password</td>';
        html[html.length] = '     </tr>';    
        
        html[html.length] = '    <tr>';
        html[html.length] = '        <td align="center">';        
        html[html.length] = '            <div id="pswMsg"></div>  ';
        html[html.length] = '        </td>';
        html[html.length] = '    </tr>';
        
        html[html.length] = '    <tr>';
        html[html.length] = '        <td align="right" style="text-align:center" valign="top" nowrap colspan="3">';
        html[html.length] = '           <img src="assets/infoicon.jpg" style="background-color:Gray"/> The new password should contain letters <u>and</u> numbers only.'
        html[html.length] = '        </td>';
        html[html.length] = '    </tr>';
        
        html[html.length] = '    <tr>';
        html[html.length] = '        <td align="right" nowrap>';
        html[html.length] = '            Current Password :   ';
        html[html.length] = '        </td>';
        html[html.length] = '        <td align="left" nowrap>';
        html[html.length] = '            &nbsp;<input type="password" id="txtcurrentPassword" value="" />';
        html[html.length] = '            <div id="validtxtcurrentPassword" style="display:none;padding-left:3px;" class="Validation-control"></div>';
        html[html.length] = '        </td>';
        html[html.length] = '    </tr>';
        html[html.length] = '    <tr>';
        html[html.length] = '        <td align="right" nowrap>';
        html[html.length] = '            New Password :   ';
        html[html.length] = '        </td>';
        html[html.length] = '        <td align="left">';
        html[html.length] = '            &nbsp;<input type="password" id="txtNewPassword" value=""  />';
        html[html.length] = '            <div id="validtxtnewPassword" style="display:none;padding-left:3px;" class="Validation-control"></div>';
        html[html.length] = '        </td>';
        html[html.length] = '    </tr>';
        html[html.length] = '    <tr>';
        html[html.length] = '        <td align="right" nowrap>';
        html[html.length] = '            Re-enter new Password:   ';
        html[html.length] = '        </td>';
        html[html.length] = '        <td align="left">';
        html[html.length] = '            &nbsp;<input type="password" id="txtReenterPassword" value=""  />';
        html[html.length] = '            <div id="validtxtConfirmPassword" style="display:none;padding-left:3px;" class="Validation-control"></div>';
        html[html.length] = '        </td>';
        html[html.length] = '    </tr>';       

        html[html.length] = '     <tr>';
        html[html.length] = '         <td class="edit-title" width="100%" colspan = "2" align="right"><input type="button" style="width:80px;" value="Save" name="Save" onclick="agreement.savePasswordInfo();"  /></td>';
        html[html.length] = '     </tr>'; 
        html[html.length] = '</table>';
		
        
        var editDiv = document.getElementById('editDiv')
        if(editDiv)
        {
            while(editDiv.hasChildNodes()){
                editDiv.removeChild(editDiv.firstChild);
            }
            editDiv.innerHTML = html.join('');
            shadow.show(editDiv,false);
        }
    },
    
    savePasswordInfo : function(){
            try
            {  
                var returnValue = true;
                var focusControl = null;
                       
	            var txtcurrentPassword = document.getElementById('txtcurrentPassword') && document.getElementById('txtcurrentPassword').value.replace(/^\s|\s$/g, ""),
	                txtNewPassword = document.getElementById('txtNewPassword') && document.getElementById('txtNewPassword').value.replace(/^\s|\s$/g, "") ,
	                txtReenterPassword = document.getElementById('txtReenterPassword') && document.getElementById('txtReenterPassword').value.replace(/^\s|\s$/g, "")  ;
	                
	                if (txtcurrentPassword == "") 
	                {
                        document.getElementById("validtxtcurrentPassword").innerHTML="Please enter current password.";
                        document.getElementById("validtxtcurrentPassword").style.display="block";
                        if(focusControl==null)
                            focusControl = document.getElementById("txtcurrentPassword");
                        returnValue = false;
                    }
                    else
                    {
                          document.getElementById("validtxtcurrentPassword").style.display="none";
                    }
	                
	                if (txtNewPassword == "") 
	                {
                        document.getElementById("validtxtnewPassword").innerHTML="Please enter new password.";
                        document.getElementById("validtxtnewPassword").style.display="block";
                        if(focusControl==null)
                            focusControl = document.getElementById("txtNewPassword");
                        returnValue = false;
                    }
                    else
                    {
                        document.getElementById("validtxtnewPassword").style.display="none";
                    }

                    if (txtReenterPassword == "") 
	                {
                        document.getElementById("validtxtConfirmPassword").innerHTML="Please re-enter new password.";
                        document.getElementById("validtxtConfirmPassword").style.display="block";
                        if(focusControl==null)
                            focusControl = document.getElementById("txtReenterPassword");
                        returnValue = false;
                    }
                    else
                    {
                        document.getElementById("validtxtConfirmPassword").style.display="none";
                    }

            	     if(!returnValue)
            	     {
            	        return false;
            	     }           
	                
	                
	                 var pwdRegex = /^([a-zA-Z]+[0-9]+[a-zA-Z]*)$|([0-9]+[a-zA-Z]+[a-zA-Z]*)$/;                 	                 
	                 if (!pwdRegex.test(txtNewPassword)) {
	                    document.getElementById("validtxtnewPassword").innerHTML="Password should contain combination of letters and digits";
                        document.getElementById("validtxtnewPassword").style.display="block";
                        if(focusControl==null)
                            focusControl = document.getElementById("txtNewPassword");
                        return false;
	                  }
	                  else
	                  {
	                        document.getElementById("validtxtnewPassword").style.display="none";
	                  }
	                
	                if(txtNewPassword==txtReenterPassword){                              
	                    var url = "&userid="+agreement.userId+"&password="+encodeURIComponent(txtcurrentPassword)+"&new_password="+encodeURIComponent(txtNewPassword)+"&isFirstLogin=true";
	                    agreement.curpwd = txtcurrentPassword;
	                    agreement.newpwd = txtNewPassword;
	                    agreement.updatepassword(url);
	                }
	                else
	                {
	                    alert('Re enter password is mismatched');
	                }
	       }
	       catch(ex)
	       {
	       
	       }     
    },
    
    updatepassword : function(url) {
        agreement.jsonservice.loadScript("userspwdupdate_0001", "services/users.aspx?action=update"+url+"&callback=agreement.addCallBack&expires=5");
    },
    
    addCallBack : function(jsonData)
    {       
            var location = "";          
            var objJson = eval('('+jsonData+')')
	        if(objJson.success == "false")
	        {
	            alert(objJson.message);	
	            return;        
	        }
	        else
	        {
	            shadow.hide();
	            alert(objJson.message);
	            agreement.loginText = agreement.loginText.replace("pwd:'" + agreement.curpwd + "',","pwd:'" + agreement.newpwd + "',");            
	            agreement.loginData = eval("(" + agreement.loginText + ")");
	        }

                
            agreement.createCookie("rememberIdPwd", agreement.loginText, -1);
            if (document.getElementById("remember_id_pwd").checked == true) {
                agreement.createCookie("rememberIdPwd", agreement.loginText, 60);
            }
            agreement.createCookie("pencilauth", agreement.loginText);
            
            switch (agreement.loginData.login.rcode) 
            {
                case "BP":
                        if (agreement.loginData.login.pid === "0")
                            location = "bpprofile.htm";
                        else
                            location = "pprofile.htm?pid=" + agreement.loginData.login.pid;
                    break;

                case "SP":   
                        location = "spprofile.htm";
                        break;
    
                case "PA":
                    location = "cprofile.htm?id=" + agreement.loginData.login.userid;
                    break;
                case "G":
                    location = "bpprofile.htm";
                    break;
                    
                case "S":
                case "PC":
                case "CM":
                case "A":
                    location = "notifications.htm";
                    break;
            }
            
            var url = null;
            var regexS = "[\\?&]url=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            
            if (results != null) {
                url = results[1];
                
            }

            if(url!=null)
            {
                document.location = url;
            }    
            else
            {
                document.location = location;
            }

        
    },


    showagreement: function() {
        var strHtml = [];
        
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%" height="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">TERMS OF USE</td>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right"></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2" height="100%">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%" height="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td style="width:100%;height:100%;" valign="top">'
        
        strHtml[strHtml.length] = '                         <div class="agreement">';
        

        strHtml[strHtml.length] = '                                 Welcome.  We appreciate your participation in the PENCIL program and hope you  benefit from our website, www.pencil.org (the “Site”).  By using the Site you agree to be bound by the terms of this legally binding electronic agreement (the “Terms of Use”), whether or not you register as a member of the Site (a “Member”).  If you wish to become a Member and make use of the services available on the Site (the “Services”), please read these Terms of Use.  If you object to anything in these Terms of Use or our Privacy Policy, do not use the Site or the Services.  The Terms of Use are subject to change by PENCIL at any time, effective upon posting on the Site.  You are bound by any such revisions and should therefore periodically visit this page to review the then current Terms of Use.  By accessing and browsing the Site, you signify your acceptance of these Terms of Use without limitation or qualification.<br /><br />';
        strHtml[strHtml.length] = '                                 Access.  In order to access the Site and use the Services, you must have access to the World Wide Web, either directly or through devices that access web-based content, and pay any service fees associated with such access.  In addition, you must use all equipment necessary to make such connection to the World Wide Web, including a computer and modem or other access device.  PENCIL is not responsible for providing you with Internet access or hardware or other software needed to access the Services.  PENCIL is not responsible for any issues that may arise relating to your use or inability to use the Services due to your Internet, hardware or software arrangements.<br /><br />';
        strHtml[strHtml.length] = '                                 Registration.  In order to take advantage of the Services, you will need to register to become a Member and obtain a user name and password.  If you choose to register, PENCIL will collect certain personal information from you, as described in our Privacy Policy.  All registration information about you must be accurate, complete, current, and you may not use any aliases or other means to mask your true identity.  You further agree to maintain and update your registration data as required to keep it accurate, current, and complete.  Your account is for your sole, personal use, you may not authorize others to use your account, and you may not assign or otherwise transfer your account to any other person or entity.  You are responsible for the security of your password and will be solely liable for any use or unauthorized use under such password.<br /><br />';
        strHtml[strHtml.length] = '                                 Communications.  By becoming a Member, you agree to accept and consent to receiving email communications initiated from PENCIL or through PENCIL including, without limitation, emails containing a message from another Member.  You may opt-out of receiving email communications sent from PENCIL or through PENCIL.  However, PENCIL reserves the right to send you notices about your account even if you opt out of all voluntary email notifications. PENCIL further reserves the right to use or disclose any information as needed to satisfy any law, regulation or legal request, to protect the integrity of the Site, to fulfill your requests, or to cooperate in any law enforcement investigation or an investigation on a matter of public safety.<br /><br />';
        strHtml[strHtml.length] = '                                 Submission License.  The Site may include various forums, blogs and chat rooms where you can post your ideas, observations and comments on designated topics.  PENCIL cannot guarantee that other users will not use the ideas that you share.  Therefore, if you have an idea that you would like to keep confidential and/or do not want others to use, do not post it to the Site.<br /><br />';
        strHtml[strHtml.length] = '                                 THESE TERMS OF USE AFFECT YOUR LEGAL RIGHTS AND YOUR PARTICIPATION AND SUBMISSION HEREUNDER CAUSES YOU TO ENTER INTO A LEGAL AND BINDING AGREEMENT WITH PENCIL.  PLEASE READ THIS VERY CAREFULLY AND MAKE SURE YOU UNDERSTAND YOUR RIGHTS AND OBLIGATIONS BEFORE SUBMITTING ANY MATERIALS.  Any submission(s) you make on this Site that contain content, including artwork, audio recordings, copy, images, music, photography, text, video recordings, ideas, written materials and/or other materials (“User Content”) are governed by the following license terms (“License”):<br /><br /> ';

        strHtml[strHtml.length] = '                                 1. You hereby grant to PENCIL an irrevocable, nonexclusive, royalty-free perpetual license to use and exploit your User Content, in whole or in part, in any and all manner and media throughout the world; and the right to use your name, image, likeness and biographical data in connection with the User Content.  PENCIL shall be entitled to assign or sublicense all or a portion of the rights and licenses granted herein and/or this License in its entirety, without payment to you.<br />';
        strHtml[strHtml.length] = '                                 2. You hereby acknowledge and agree that: (a) PENCIL shall have the right to crop, edit, alter or arrange the User Content in any way it desires in PENCIL\'s sole discretion; (b) PENCIL shall not have any obligation to provide you with any credit when using your User Content, but in the event PENCIL chooses to provide you with credit the size and placement of the credit shall be at PENCIL\'s sole discretion; (c) you shall waive any “moral rights” that you may have in the User Content; and (d) you are not entitled to any compensation or other payment from PENCIL in connection with the User Content.  You understand that PENCIL will be acting in reliance upon your grant of rights, representations, warranties and indemnities in this License and may incur substantial expense in reliance upon this grant of rights, representations, warranties and indemnities should PENCIL use your User Content.<br /><br />';

        strHtml[strHtml.length] = '                                 You represent and warrant that: (a) you have the full power and authority to grant the License described herein and to perform all of your obligations set forth in this License; (b) you are the author of the User Content and that each and every element of the User Content is an original work created by you; (c) you are the sole and exclusive owner of the User Content and all of the trademark and copyrights therein; (d) no third party is entitled to any compensation or payment as a condition for PENCIL\'s use and exploitation of the User Content; and (e) the User Content conforms to the Acceptable Use Policy described below.<br /><br />';

        strHtml[strHtml.length] = '                                 Acceptable Use Policy (“AUP”).  PENCIL expects all of its users to be respectful of other people.  If you notice any violation of this Acceptable Use Policy or other unacceptable behavior by any user, you should report such activity to PENCIL here.<br /><br />';

        strHtml[strHtml.length] = '                                 You are solely responsible for the User Content that you post on the Site or transmit to other users and agree that you will not hold PENCIL responsible or liable for any User Content from other users that you access on the Site.  Any User Content you provide to PENCIL should reflect your honest opinions, findings, beliefs or experience, and are within your personal knowledge.<br /><br />';

        strHtml[strHtml.length] = '                                 Categories of prohibited User Content below are merely examples and are not intended to be exhaustive.  PENCIL will make the sole determination as to whether or not User Content is acceptable for the Site.  Without limitation, you agree that you will not post or transmit to other users anything that contains User Content that:<br /><br />';

        strHtml[strHtml.length] = '                                 •	is defamatory, abusive, obscene, profane or offensive;<br /> ';
        strHtml[strHtml.length] = '                                 •	infringes or violates another party\'s intellectual property rights (such as music, videos, photos or other materials for which you do not have written authority from the owner of such materials to post on the Site); <br />';
        strHtml[strHtml.length] = '                                 •	violates any party\'s right of publicity or right of privacy;<br />';
        strHtml[strHtml.length] = '                                 •	is threatening, harassing or that promotes racism, bigotry or hatred of any kind against any group or individual;<br />';
        strHtml[strHtml.length] = '                                 •	promotes or encourages violence against a person;<br />';
        strHtml[strHtml.length] = '                                 •	is inaccurate, false or misleading in any way, including, but not limited to User Content that falsely impersonates any person or organization, misrepresents an affiliation with another person or organization, or that contains slanderous or libelous comments about others;<br />';
        strHtml[strHtml.length] = '                                 •	is illegal or promotes any illegal activities;<br />';
        strHtml[strHtml.length] = '                                 •	promotes illegal or unauthorized copying of another person\'s copyrighted work or links to them or providing information to circumvent security measures;<br />';
        strHtml[strHtml.length] = '                                 •	contains “masked” profanity (e.g., F*@#)<br />';
        strHtml[strHtml.length] = '                                 •	contains software viruses or any other computer code, files or programs designed to interrupt, destroy or limit the functionality of any computer software or hardware or telecommunications equipment; or<br />';
        strHtml[strHtml.length] = '                                 •	contains any unauthorized advertising, promotional materials, junk mail, spam, chain letters, pyramid schemes, or any other form of solicitation.<br /><br />';

        strHtml[strHtml.length] = '                                         PENCIL is under no obligation to screen or monitor User Content, but may review User Content from time to time at its sole discretion to review compliance with this Acceptable Use Policy.  PENCIL will make all determinations as to what User Content is appropriate in its sole discretion.  PENCIL may include, edit or remove any User Content at any time without notice.<br /><br />';

        strHtml[strHtml.length] = '                                         You understand that when using the Site, you will be exposed to User Content from a variety of sources, and that PENCIL is not responsible for the accuracy, usefulness, safety, or intellectual property rights of or relating to such User Content.<br /><br /> ';

        strHtml[strHtml.length] = '                                         You may not use spiders, robots, data-mining techniques or other automated devices or programs to catalog, download or otherwise reproduce, store or distribute content available on the Site.  You may not harvest or collect e-mail addresses or other contact information of other users of the Site by electronic means.  Further, you may not use any such automated means to manipulate the Site or attempt to exceed the limited authorization and access granted to you under these Terms of Use.  You may not resell use of, or access to, or link the Site to any third party. <br /><br />';

        strHtml[strHtml.length] = '                                         Termination of Access.  In addition to any right or remedy that may be available to PENCIL under these Terms of Use or applicable law, PENCIL may suspend, limit or terminate your account, or all or a portion of your access to the Site, at any time with or without notice and with or without cause.  In addition, PENCIL may refer any information on illegal activities, including your identity, to the proper authorities.<br /><br /> ';

        strHtml[strHtml.length] = '                                         Indemnity.  You agree to defend, indemnify and hold harmless PENCIL, its affiliates and all of their officers, directors, employees, business partners and agents, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, and expenses (including but not limited to attorney\'s fees) arising from: (i) any breach by you of any of these Terms of Use, (ii) your User Content, (iii) your use of materials or features available on the Site (except to the extent a claim is based upon infringement of a third-party right by materials created by PENCIL) or (iv) a violation by you of applicable law or any agreement or terms with a third party to which you are subject. <br /><br />';

        strHtml[strHtml.length] = '                                         Intellectual Property.  You should assume that all materials, designs, text and images (collectively, the “Materials”) contained in the Site are either the copyrighted property of PENCIL unless otherwise noted, or are the copyrighted property of third parties.  You may not modify, alter or change any Materials or distribute, publish, transmit, reuse, repost or use the content of the Site for public or commercial purposes.  Unauthorized use of the Materials is strictly prohibited and is a violation of the rights of PENCIL, and/or third parties, including, without limitation, under copyright laws, trademark laws, the laws of privacy and publicity.  PENCIL neither warrants nor represents that your use of Materials displayed on the Site will not infringe rights of third parties not owned by or affiliated with PENCIL. <br /><br />';

        strHtml[strHtml.length] = '                                         This Site may contain trademarks, names, titles, logos, images, designs, copyrights and other proprietary materials owned by PENCIL (the “Trademarks”).  Nothing contained on the Site should be construed as granting, by implication, estoppel or otherwise, any license or right to use any Trademark displayed on the Site, or any license or right to use any other trademark owned by any other third party.  In the event that you misuse any Trademark in violation of these Terms of Use, PENCIL will aggressively enforce its intellectual property rights to the fullest extent of the law, including the seeking of criminal prosecution. <br /><br />';

        strHtml[strHtml.length] = '                                         Limitation of Liability/No Warranty.  PENCIL makes no representations that the Materials in this Site are appropriate or available for use in other countries aside from the United States.  Those who do access this Site from other countries are solely responsible for compliance with local laws of that country.  THE SITE, INCLUDING ALL CONTENT MADE AVAILABLE ON OR ACCESSED THROUGH THE SITE, IS PROVIDED “AS IS” AND PENCIL MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHATSOEVER FOR THE CONTENT ON THE SITE.  FURTHER, TO THE FULLEST EXTENT PERMISSIBLE BY LAW, PENCIL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, NONINFRINGEMENT, TITLE, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  PENCIL DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SITE OR ANY MATERIALS OR CONTENT CONTAINED THEREIN WILL BE COMPLETELY SECURE, UNINTERRUPTED OR ERROR FREE, THAT DEFECTS WILL BE CORRECTED, OR THAT THE SITE OR THE SERVER THAT MAKES IT AVAILABLE IS FREE OF VIRUSES OR OTHER HARMFUL COMPONENTS.  PENCIL SHALL NOT BE LIABLE FOR THE USE OF THE SITE, INCLUDING, WITHOUT LIMITATION, THE CONTENT AND ANY ERRORS CONTAINED THEREIN PROVIDED BY THIRD PARTIES.  IN NO EVENT WILL PENCIL BE LIABLE UNDER ANY THEORY OF TORT, CONTRACT, STRICT LIABILITY OR OTHER LEGAL OR EQUITABLE THEORY FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR OTHER CONSEQUENTIAL DAMAGES, LOST PROFITS, LOST DATA, LOST OPPORTUNITIES, COSTS OF COVER, EXEMPLARY, PUNITIVE, PERSONAL INJURY/WRONGFUL DEATH, EACH OF WHICH IS HEREBY EXCLUDED BY AGREEMENT OF THE PARTIES REGARDLESS OF WHETHER OR NOT PENCIL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  Please note that some jurisdictions may not allow the exclusion of implied warranties, so some of the above exclusions may not apply to you.  Check your local laws for any restrictions or limitations regarding the exclusion of implied warranties. <br /><br />';

        strHtml[strHtml.length] = '                                         Eligibility.  You must be at least eighteen (18) years of age to register as a Member or use the Site. Membership is void where prohibited.  By using the Site, you represent and warrant that you have the right, authority and capacity to enter into these Terms of Use and to abide by all of the terms and conditions contained herein. <br /><br />';

        strHtml[strHtml.length] = '                                         Third Party Links.  This Site may link to other sites not maintained by or related to PENCIL.  Such hyperlinks are provided as a service to users and are not sponsored by, endorsed or otherwise affiliated with this Site or with PENCIL.  PENCIL has not reviewed all of the sites linked to the Site and is not responsible for the content of any off-site pages or links to any other sites.  Viewing all other sites is at your own risk. <br /><br />';

        strHtml[strHtml.length] = '                                         Digital Millennium Copyright Act (DMCA) Notice.  Materials may be made available via the Site by third parties not within our control (such as User Content).  PENCIL is under no obligation to, although PENCIL reserves the right to, review content used in connection with the Site for the inclusion of illegal or impermissible content.  However, PENCIL respects the copyright interests of others.  It is our policy not to permit materials known by PENCIL to infringe another party\'s copyright to remain on the Site.  It is also our policy to terminate relationships regarding content with third parties who repeatedly infringe the copyrights of others. <br /><br />';

        strHtml[strHtml.length] = '                                         If you believe any materials on the Site infringe a copyright, you should provide PENCIL with written notice that at a minimum contains:<br /> ';

        strHtml[strHtml.length] = '                                         1. A physical or electronic signature of a person authorized to act on behalf of the owner of an exclusive right that is allegedly infringed; <br />';
        strHtml[strHtml.length] = '                                         2. Identification of the copyrighted work claimed to have been infringed, or, if multiple copyrighted works at a single online site are covered by a single notification, a representative list of such works at that site; <br />';
        strHtml[strHtml.length] = '                                         3. Identification of the material that is claimed to be infringing or to be the subject of infringing activity and that is to be removed or access to which is to be disabled, and information reasonably sufficient to permit PENCIL to locate the material;<br /> ';
        strHtml[strHtml.length] = '                                         4. Information reasonably sufficient to permit PENCIL to contact the complaining party, such as an address, telephone number, and, if available, an electronic mail address at which the complaining party may be contacted; <br />';
        strHtml[strHtml.length] = '                                         5. A statement that the complaining party has a good faith belief that use of the material in the manner complained of is not authorized by the copyright owner, its agent, or the law; and <br />';
        strHtml[strHtml.length] = '                                         6. A statement that the information in the notification is accurate, and under penalty of perjury, that the complaining party is authorized to act on behalf of the owner of an exclusive right that is allegedly infringed.<br /><br /> ';

        strHtml[strHtml.length] = '                                         All DMCA notices should be sent to our designated agent as follows: <br />';

        strHtml[strHtml.length] = '                                         PENCIL<br />';
        strHtml[strHtml.length] = '                                         Attn: DMCA Questions<br />';
        strHtml[strHtml.length] = '                                         30 W. 26th Street, 5th Floor<br />';
        strHtml[strHtml.length] = '                                         New York, NY 10010<br /><br />';

        strHtml[strHtml.length] = '                                         Miscellaneous.  These Terms of Use are governed and interpreted under the laws of the state of New York.  YOU HEREBY EXPRESSLY CONSENT TO EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS LOCATED IN THE STATE OF NEW YORK FOR ALL MATTERS ARISING IN CONNECTION WITH THESE TERMS OF USE OR YOUR ACCESS OR USE OF THE SITE. <br /><br />';
        strHtml[strHtml.length] = '                                         Any claims asserted by you in connection with the Site must be asserted in writing to PENCIL within one (1) year of the date such claim first arose, or such claim is forever waived by you.  Each claim shall be adjudicated individually, and you agree not to combine your claim with the claim of any third party. <br /><br />';
        strHtml[strHtml.length] = '                                         If any portion of these Terms of Use is deemed unlawful, void or unenforceable, then that part shall be deemed severable and will not effect the validity and enforceability of any remaining provisions.<br /><br />';
        strHtml[strHtml.length] = '                                         These Terms of Use set forth the entire understanding and agreement between you and PENCIL with respect to the Site.  You acknowledge that any other agreements between you and PENCIL with respect to the Site are superseded and of no force or effect. <br /><br />';
        strHtml[strHtml.length] = '                                         Both you and PENCIL acknowledge and agree that no partnership is formed and neither of you nor PENCIL has the power or the authority to obligate or bind the other.<br /><br /> ';
        strHtml[strHtml.length] = '                                         No waiver of any provision or of any breach of these Terms of Use shall constitute a waiver of any other provisions or any other or further breach.  In the event that any provision of these Terms of Use shall be illegal or otherwise unenforceable, such provision shall be severed, and the balance of the Terms of Use shall continue in full force and effect.<br />';
        
        
        strHtml[strHtml.length] = '                         </div>';
        
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';

        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td style="width:100%;height:100%;">'
        strHtml[strHtml.length] = '                         <input type="checkbox" id="chkAccept"  />'
        strHtml[strHtml.length] = '                         I HAVE READ THIS AGREEMENT AND AGREE TO ALL OF THE PROVISIONS CONTAINED ABOVE.'
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';

        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td style="width:100%;height:100%;">'
        strHtml[strHtml.length] = '                         Allow other PENCIL Partners to contact me through PENCIL’s website for the sole purpose of hearing more about my Partnership. I understand my email address and contact information will not be revealed, and I can always choose to opt-out of this feature by changing the settings in My Profile.';
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';
                
        strHtml[strHtml.length] = '                           <tr>';
        strHtml[strHtml.length] = '                               <td align="left">';
        strHtml[strHtml.length] = '                                   Yes : <input type="radio" value="Y" name="private" id="rdPrivateYes" checked/>';
        strHtml[strHtml.length] = '                                   No : <input type="radio" value="N" name="private" id="rdPrivateNo" />';
        strHtml[strHtml.length] = '                               </td>';
        strHtml[strHtml.length] = '                           </tr>';
        
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2" class="edit-title" align="middle"><input type="button" value="Accept" onclick="agreement.accept()" /><input type="button" value="Decline" onclick="agreement.decline();" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';

        var editDiv = document.getElementById('editDiv');
            editDiv.innerHTML = strHtml.join('');
            shadow.show(editDiv, false);
    },
    
    
    accept : function(){
    
        var chkAccept = document.getElementById('chkAccept').checked;
            
            
            if(!chkAccept)
            {
                alert('Please Accept To Terms Of Use Agreement');
                return;
            }
            
            agreement.update();
            
    },
    
    
    decline : function() {

        agreement.createCookie("pencilauth", "", -1);
        document.location = "default.htm";
        return null;
    },
    
    createCookie : function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    }    

 
};




var login = {
    count :  0,
    renew: "",
    myjsonservice : new JSONService() ,        
     
    partnerShipData : null ,
     
    fetchPartnership : function(){
        
        var objJson = eval('('+login.readCookie("pencilauth")+')');
        if(objJson != null){
            login.myjsonservice.loadScript("loginpartnerfetch_0001", "services/users.aspx?action=fetch&callback=login.holdPartnersData&expires=5&userid="+objJson.login.userid+"");
        }
        else{
            login.renderHtml("login1");
        }
    },
     
    holdPartnersData : function(strJSON){
        login.partnerShipData = eval("(" + strJSON + ")") ;
        login.renderLoginHtml("login1");
    },
     
    renderLoginHtml: function(idDiv) { 
        var objJson = eval('('+login.readCookie("pencilauth")+')'),
        location = "";
        switch (objJson.login.rcode) {
            case "BP":
                if (objJson.login.pid === "0")
                    location = "bpprofile.htm";
                else
                    location = "pprofile.htm?pid=" + objJson.login.pid; 
                break;

            case "SP":   
                location = "spprofile.htm";
                break;

            case "PA":
                location = "cprofile.htm?id=" + objJson.login.userid;
                break;
                
            case "G":
                location = "bpprofile.htm";
                break;    

            case "S":
            case "PC":
            case "CM":
            case "A":
                location = "notifications.htm";
                break;
        }
        
            var url = null;
            var regexS = "[\\?&]url=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            if (results!=null) {
                location = results[1];
                document.location = location;
                
            }

        
        var strHtml = '';
            strHtml += '       <table class="home-login" border="0" cellpadding="2" cellspacing="0" width="190px">';
            strHtml += '           <tr>';
            strHtml += '               <td colspan="2" align="left">';
            if(login.partnerShipData.rows.length > 0)
	        {
	            strHtml += '       <div style="font-weight: bold;padding-top:20px;padding-left:10px;">';
	            strHtml += '   	    Welcome ';
	            strHtml += login.partnerShipData.rows[0].firstname + ' '+login.partnerShipData.rows[0].lastname +',';
	            strHtml += '       </div>';
	            strHtml += '       <div style="padding-top:20px;padding-left:10px;">';
	            strHtml += '   	    <a href="'+location+'">Please click here</a> for viewing your default page.';
	            strHtml += '       </div>';
	        }		   
            strHtml += '                </td>';
            strHtml += '            </tr>';
            strHtml += '        </table>';
            document.getElementById(idDiv).innerHTML = strHtml;
            return !1;
        } ,         
    
    renderHtml: function(idDiv) {
    login.renew = $.query.get('rn');
        var objJson = eval('(' + login.readCookie("rememberIdPwd") + ')'),
            struserId = "",
            strPasswd = "",
            checked = false;

        if (objJson !== null) {
            struserId = objJson.login.un;
            strPasswd = objJson.login.pwd;
            checked = true;
        }

        var strHtml = '';
        strHtml += '       <table class="home-login" border="0" cellpadding="2" cellspacing="0" width="190px">';
        strHtml += '           <tr>';
        strHtml += '               <td colspan="2" align="left"><img src="assets/pencil_login.gif" style="border:0" /><br /></td>';
        strHtml += '           </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td>Email</td>';
        strHtml += '                <td><input type="text" id="username" style="width: 100px;" value="' + struserId + '"  /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td>Password</td>';
        strHtml += '                <td><input type="password" id="password" style="width: 100px;"  value="' + strPasswd + '" /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr >';
        strHtml += '                <td></td>';
        strHtml += '                <td><a href="javascript:login.forgotPassword();" class="forgot">Forgot Password?</a></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';

        if (checked)
            strHtml += '                <td colspan="2"><input type="checkbox" id="remember_id_pwd" checked /><span style="font-size:xx-small">Remember ID and Password</span></td>';
        else
            strHtml += '                <td colspan="2"><input type="checkbox" id="remember_id_pwd"  /><span style="font-size:xx-small">Remember ID and Password</span></td>';

        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td colspan="2" align="right"><img src="assets/login.gif" style="cursor:hand;" id="submitBtn"  onclick="login.verifyuser(event);" /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td colspan="2"><span id="errormessage" /></td>';
        strHtml += '            </tr>';
        strHtml += '        </table>';
        
        
        
        var regexS = "[\\?&]url=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results != null) {
            mybread.render('Login');
        }
        
        if(document.getElementById(idDiv) != null)
        {
        document.getElementById(idDiv).innerHTML = strHtml;
        document.getElementById('username').focus();
        //$("input").keypress(function(e) { login.verifyuser(e); });
        $("input[id='username']").keypress(function(e) { login.verifyuser(e); });
        $("input[id='password']").keypress(function(e) { login.verifyuser(e); });
        }

        
        
    },
    
    success: function(responseText) {  
        var objJson = eval("(" + responseText + ")");
        if (objJson.login.userid !== undefined) {
            login.count=0;
            agreement.userId = objJson.login.userid;
            if(objJson.login.isnew=="Y"){
                agreement.loginText = responseText;
                agreement.loginData = objJson;
                agreement.showagreement();    
                return;
            }
            else if(objJson.login.isFirstLogin == "Y")
            {
                agreement.loginText = responseText;
                agreement.loginData = objJson;
                agreement.showChangePassword();    
                return;
            }

            //success create a cookie and store the userid, and send the user to appropriate home page
            login.createCookie("rememberIdPwd", responseText, -1);
            if (document.getElementById("remember_id_pwd").checked == true) {
                login.createCookie("rememberIdPwd", responseText, 60);
            }

            login.createCookie("pencilauth", responseText);
            var location = "";
            switch (objJson.login.rcode) {
                case "BP":
                    if (objJson.login.pid === "0")
                        location = "bpprofile.htm";
                    else
                        location = "pprofile.htm?pid=" + objJson.login.pid;
                    break;

                case "SP":   
                    if (objJson.login.pid === "0")
                        location = "spprofile.htm";
                    else
                        location = "pprofile.htm?pid=" + objJson.login.pid;
                    break;
    
                case "PA":
                    location = "cprofile.htm?id=" + objJson.login.userid;
                    break;
                case "G":
                    location = "bpprofile.htm";
                    break;

                case "S":
                case "PC":
                case "CM":
                case "A":
                    location = "notifications.htm";
                    break;
            }
            
            
            var url = null;
            var regexS = "[\\?&]url=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            if (results!=null) {
                url = results[1];
            }
            
            
            if(url!=null)
            {
                document.location = url;
            }    
            else
            {
                document.location = location;
            }
            
        }
        else {
            //document.getElementById("errormessage").innerHTML = objJson.login.message;  
            login.count=login.count+1;
            var ErrorMessage;
            if(login.count==1){
                ErrorMessage='Username and/or password not recognized.';  
            }
            else if(login.count==2){
                ErrorMessage='Username and/or password not recognized. If you do not remember your password, click ‘Forgot Password?’ below.';  
            }
            else if(login.count>2){
                ErrorMessage='Username and/or password not recognized. If you have not registered, please apply to become a PENCIL Partner today. Or contact PENCIL at (646) 638-0565 or Partnership@pencil.org.';  
            }
                                
            var html = [];
            html[html.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
            html[html.length] = '     <tr>';
            html[html.length] = '         <td colspan="2">';
            html[html.length] = '             <table cellspacing="0" cellpadding="5" border="0" width="100%">';
            html[html.length] = '                 <tr>';
            html[html.length] = '                   <td></td>';
            html[html.length] = '                   <td>'+ ErrorMessage +'</td>';
            html[html.length] = '                   </tr>';
            html[html.length] = '             </table>';
            html[html.length] = '         </td>';
            html[html.length] = '     </tr>';
            html[html.length] = '     <tr>';
            html[html.length] = '         <td colspan="2"  align="right"><input type="button" id="errorOkbtn" value="OK" onclick="login.setbackFocus();" /></td>';
            html[html.length] = '     </tr>';
            html[html.length] = '</table>';

            var selectType = document.getElementById('selectApplication');
            if (selectType) {
                selectType.innerHTML = html.join('');
                shadow.show(selectType, false);
                var errorOkbtn = document.getElementById('errorOkbtn');
                    errorOkbtn.focus();
            }

        }
    },
    
    setbackFocus : function(){
    
        shadow.hide();
        var username = document.getElementById('username');
            username.focus();
    },
    
    failure: function(responseText) {
        document.getElementById("errormessage").innerHTML = responseText;
    },

    verifyuser: function(e) {
        
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        
        if(e.which == 13 || e.type =="click")
        {
            if (username == "") {
                alert('Please enter your username!!!');
                document.getElementById("username").focus();
                return;
            }
            if (password == "") {
                alert('Please enter your password!!!');
                document.getElementById("password").focus();
            }
            //finall all ok so fire the ajax call;
            var myajax = new ajax();
            var params = "username=" + username + "&password=" + password;
            document.getElementById("errormessage").innerHTML = "";
            myajax.load("services/login.aspx", login.success, login.failure, params);
        
        }
        
    },

    createCookie: function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },

    apply: function() {
                
        var html = [];
        html[html.length] = '<div style="padding-top: 20px;">';
        html[html.length] = '</div>';
        html[html.length] = '<div style="font-weight: bold; padding-left: 20px; font-size: 16px; width: 380px;';
        html[html.length] = '    color: #001640; font-family: Arial;">';
        html[html.length] = '    START a PENCIL Partnership</div>';
        html[html.length] = '<div style="font-weight: bold; padding-left: 20px; font-size: 12px; width: 380px;';
        html[html.length] = '    color: #001640; font-family: Arial; padding-top: 10px;">';
        html[html.length] = '    What &nbsp;type of application are you interested in?</div>';
        html[html.length] = '<div style="width: 260px; height: 17px; padding-top: 30px; padding-left: 55px;">';
        html[html.length] = '    <input type="radio" id="radBP" name="register" checked />';
        html[html.length] = '    Business Partner Application<br />';
        html[html.length] = '    <br />';
        html[html.length] = '    <input type="radio" id="radSP" name="register" />';
        html[html.length] = '    School Application';
        html[html.length] = '</div>';
        html[html.length] = '<div style="padding-top: 20px;padding-left:300px;">';
        html[html.length] = '    <input type="button" id="submit" value="Continue" onclick="login.register();" />';
        html[html.length] = '    <input type="button" id="cancel" value="Cancel" onclick="shadow.hide();" />';
        html[html.length] = '</div>';

        var selectType = document.getElementById('selectType');
        if (selectType) {
            selectType.innerHTML = html.join('');
            shadow.show(selectType, false);
        }
    },

    forgotPassword: function() {
        var html = [];
        html[html.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td class="edit-title" width="100%">Forgot Password</td>';
        html[html.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2">';
        html[html.length] = '             <table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '                 <tr>';
        html[html.length] = '                   <td colspan="2" align="left"><b>Please enter your Email address:</b></td>';
        html[html.length] = '                 </tr>';
        html[html.length] = '                 <tr>';
        html[html.length] = '                   <td>Email:</td>'
        html[html.length] = '                   <td><input type="text" id="txtLogin" /></td>';
        html[html.length] = '                 </tr>';
        html[html.length] = '             </table>';
        html[html.length] = '         </td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2" class="edit-title" align="right"><input type="button" id="submit" value="Continue" onclick="login.update();" />&nbsp;<input type="button" value="Cancel" onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '</table>';        
        
        

        var selectType = document.getElementById('selectApplication');
        if (selectType) {
            selectType.innerHTML = html.join('');
            shadow.show(selectType, false);
        }
    },

    register: function() {
        var radBP = document.getElementById('radBP') && document.getElementById('radBP').checked,
            location = "";
        if (radBP) {
            location = "bpregister.htm";
        }
        else {
            location = "spregister.htm";
        }
        document.location = location;
    },

    readCookie: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    update: function() {
        var objJson = new JSONService(),
	        loginid = document.getElementById('txtLogin') && document.getElementById('txtLogin').value;

        //if (/^([\w]+)(\.[\w]+)*@([\w\-]+)(\.[\w]{2,4})(\.[a-z]{2})?$/i.test(strEmail))
         //{
            objJson.loadScript('forgotpass_001', 'services/login.aspx?action=update&loginid=' + loginid + '&callback=login.updateCallBack');
        //}
        //else {
          //  alert('Please provide valid email.');
            //return false;
        //}
    },

    updateCallBack: function(jsonData) {
        var message = eval('('+jsonData+')');
        alert(message.message);
        shadow.hide();
    },
    
    
    renderHtmlForLocation: function(idDiv) {
    login.renew = $.query.get('rn');
//    document.getElementById('txtExtUser').style.display = 'none';
//    document.getElementById('imgLogin').style.display = 'none';
//    document.getElementById('tdNewUser').style.display = 'none';
//     document.getElementById('imgStartPart').style.display = 'none';
//     document.getElementById('lnkBack').style.display = '';
    
        var objJson = eval('(' + login.readCookie("rememberIdPwd") + ')'),
            struserId = "",
            strPasswd = "",
            checked = false;

        if (objJson !== null) {
            struserId = objJson.login.un;
            strPasswd = objJson.login.pwd;
            checked = true;
        }

        var strHtml = '';
        strHtml += '       <table border="0" cellpadding="2" cellspacing="0">';
        strHtml += '           <tr>';
        strHtml += '               <td colspan="2" align="left" style="font-family:Arial;font-weight:bold; font-size:13;padding-bottom:10px;">Existing User Login</td>';
        strHtml += '           </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td width="70px">User Name</td>';
        strHtml += '                <td width="175px"><input type="text" id="username" style="width: 90%;" value="' + struserId + '"  /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td>Password</td>';
        strHtml += '                <td><input type="password" id="password" style="width: 90%;"  value="' + strPasswd + '" /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr >';
        strHtml += '                <td></td>';
        strHtml += '                <td><a href="javascript:login.forgotPassword();" class="forgot">Forgot Password?</a></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';

        if (checked)
            strHtml += '                <td colspan="2"><input type="checkbox" id="remember_id_pwd" checked /><span style="font-size:xx-small">Remember ID and Password</span></td>';
        else
            strHtml += '                <td colspan="2"><input type="checkbox" id="remember_id_pwd"  /><span style="font-size:xx-small">Remember ID and Password</span></td>';

        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td colspan="2" align="right" style="padding-right:20px;"><img src="assets/login.gif" style="cursor:hand;" id="submitBtn"  onclick="login.verifyuser(event);" /></td>';
        strHtml += '            </tr>';
        strHtml += '            <tr>';
        strHtml += '                <td colspan="2"><span id="errormessage" /></td>';
        strHtml += '            </tr>';
        strHtml += '        </table>';
        
        
        
        var regexS = "[\\?&]url=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results != null) {
            mybread.render('Login');
        }
        
        
        document.getElementById(idDiv).innerHTML = strHtml;
        document.getElementById('username').focus();
        //$("input").keypress(function(e) { login.verifyuser(e); });
        $("input[id='username']").keypress(function(e) { login.verifyuser(e); });
        $("input[id='password']").keypress(function(e) { login.verifyuser(e); });

    }
};
//login.renderHtml("login1");
login.fetchPartnership();
