YAHOO.namespace("sonoma");var Y = YAHOO.util;
YAHOO.sonoma.macFileUrl='http://sonomawireworks.com/accountManagerUI/files/RiffWorksT4.dmg';
YAHOO.sonoma.winFileUrl='http://sonomawireworks.com/accountManagerUI/files/InstallRiffWorksT4.exe';
YAHOO.sonoma.accountManagerUrl = "/accountManager/";
YAHOO.sonoma.memberProfileLoc = "http://www.riffworld.com/Members";
YAHOO.sonoma.maint = false;
var sonomaKeySignupSlider = function(el) {
    if (!el) { }
    this.init(el); 
};

function sonomaParseInt(mixed) {
	var trimmed = mixed.replace(/[^0-9]/g,'');
	return parseInt(trimmed);
}

sonomaKeySignupSlider.prototype = {
    init: function(params){
        
        var ft = document.getElementsByTagName("embed");
        Y.Dom.setStyle(ft, "display", "none");
        Y.Dom.setStyle(ft, "visibility", "hidden");
            
        
        var tft = document.getElementsByTagName("object");
        Y.Dom.setStyle(tft, "display", "none");
        Y.Dom.setStyle(tft, "visibility", "hidden");
        
        var fti = document.getElementsByTagName("iframe");
        Y.Dom.setStyle(fti, "visibility", "hidden");
        

        
        
        var tempOverLay = document.createElement("div");
        tempOverLay.id="tempSignInOverlay";
        tempOverLay.style.visibility="hidden";
        tempOverLay.innerHTML="<div class=\"hd\"></div><div class=\"bd\"><ul id=\"tempLoadingStep\" class=\"sonomaSlider\"><li class=\"step\"><span class=\"loading\">Loading...</span> or <a href=\"#\" class=\"sonomaKeyNav close\">cancel</a></li></ul></div><div class=\"ft\" id=\"tempOverlayFooter\"><div class=\"footerDiv\" id=\"tempGeneralFooter\" style=\"display:block\"><a href=\"#\" class=\"sonomaKeyNav goToTerms\">Terms of Service</a> <a href=\"#\" class=\"sonomaKeyNav goToPrivacyPolicy\">Privacy Policy</a></div></div>";
        document.body.appendChild(tempOverLay);


        this.tempSignInOverlay = new YAHOO.widget.Panel("tempSignInOverlay", { fixedcenter:false, visible:false, width:"680px",modal:true, close:true } );
        
        
        var t = Y.Dom.getElementsByClassName("container-close","span","tempSignInOverlay");
        for(i=0;i<t.length;i++){
            Y.Event.on(t[i],"click",function(){ this.tempSignInOverlay.destroy();},this,true);
        }
        var tbd = Y.Dom.getElementsByClassName("bd","div","tempSignInOverlay")[0];
        tbd.style.height="500px";
        this.tempSignInOverlay.render();
        this.tempSignInOverlay.center();
        this.tempSignInOverlay.show();
        
        this.curLoc=window.location.href;
        var handleSuccess = function(o){
            //set params
            this.params = eval("("+params+")");
            //set download type
            this.params.downloadType = (navigator.appVersion.indexOf("Mac")!=-1?"Mac":"Windows");
            //prepare overlay
            this.prevFooter=false;
            var overLay = document.createElement("div");
            overLay.id="signInOverlay";
            overLay.style.visibility="hidden";
            overLay.innerHTML = o.responseText;
            document.body.appendChild(overLay);
            this.signInOverlay = new YAHOO.widget.Panel("signInOverlay", { fixedcenter:false, visible:false, width:"680px",modal:true, close:false } );
            this.signInOverlay.render();
            this.signInOverlay.center();
            
            this.signInOverlay.destroyEvent.subscribe(function() { 
                var ft = document.getElementsByTagName("embed");
                Y.Dom.setStyle(ft, "display", "inline");
                Y.Dom.setStyle(ft, "visibility", "visible");
                    
                
                var tft = document.getElementsByTagName("object");
                Y.Dom.setStyle(tft, "display", "inline");
                Y.Dom.setStyle(tft, "visibility", "visible");
                var fti = document.getElementsByTagName("iframe");
                Y.Dom.setStyle(fti, "visibility", "visible");
                
                window.location.hash = "#";
            });
            
            
            var t = Y.Dom.getElementsByClassName("container-close","span","signInOverlay");
            for(i=0;i<t.length;i++){
                Y.Event.on(t[i],"click",function(){ this.signInOverlay.destroy();},this,true);
            }
          
            
            this.bd = Y.Dom.getElementsByClassName("bd","div","signInOverlay")[0];
            this.returnEl=false;
            
            this.curPos = 0;
            this.slideSpeed = .2;
            this.accountManagerUrl = YAHOO.sonoma.accountManagerUrl;

            switch(this.params.type){
                case "signUp":
                    
                    this.goToSection("signUp");
                break;
                case "logIn":
                   
                    this.goToSection("logIn");            
                break;
                case "changePassword":
                    this.goToSection("changePassword");
                break;
                case "editAccountInfo":
                    this.goToSection("editAccountInfo");
                break;
            }
            this.el.style.top=0;
            this.el.style.display="block";
            
            var signupc = this.params.askForDownload?"uDownLoadSignUp":"uNoDownLoadSignUp";
            document.getElementById(signupc).style.display="block";
            var nButtons = Y.Dom.getElementsByClassName("sonomaKeyNav","","signInOverlay");
            var tempThis=this;
            for(i=0;i<nButtons.length;i++){
                if(Y.Dom.hasClass(nButtons[i],"nextStep")){
                    Y.Event.on(nButtons[i],"click",this.nextStep,this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"prevStep")){
                    Y.Event.on(nButtons[i],"click",this.prevStep,this,true);
                }
                
                
                else if(Y.Dom.hasClass(nButtons[i],"returnToPrevious")){
                    Y.Event.on(nButtons[i],"click",this.returnToPrevious,this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"goToTerms")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("terms"); },this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"goToPrivacyPolicy")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("privacyPolicy"); },this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"downloadNextStep")){
                    Y.Event.on(nButtons[i],"click",this.downloadNextStep,this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"close")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.signInOverlay.destroy();},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"finish-login")){
                    Y.Event.on(nButtons[i],"click",function(e){ window.location=this.curLoc; },this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"needKey")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("signUp");},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"haveKey")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("logIn");},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"forgotUserName")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("forgotUserName");},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"forgotPassword")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("forgotPassword");},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"goToLogIn")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("logIn");},this,true);
                }
                
                else if(Y.Dom.hasClass(nButtons[i],"changePassword")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("changePassword");},this,true);
                }
                else if(Y.Dom.hasClass(nButtons[i],"editAccountInfo")){
                    Y.Event.on(nButtons[i],"click",function(e){ Y.Event.stopEvent(e); this.goToSection("editAccountInfo");},this,true);
                }
            }
            Y.Event.on("logInForm","submit",function(e){
                this.loaderizeButton("logInSubmitButton");
                this.logIn(e);
            },this,true);
            
            Y.Event.on("forgotPasswordForm","submit",function(e){
                this.loaderizeButton("resetPasswordSubmit");
                this.resetPassword(e);
            },this,true);
            
            Y.Event.on("forgotUserNameForm","submit",function(e){
                this.loaderizeButton("forgotUserNameSubmit");
                this.retrieveUserName(e);
            },this,true);
            
            Y.Event.on("changePasswordForm","submit",function(e){
                this.loaderizeButton("changePasswordSubmit");
                this.changePassword(e);
            },this,true);
            
            Y.Event.on("editAccountForm","submit",function(e){
                this.loaderizeButton("editAccountSubmit");
                this.editAccountInfo(e);
            },this,true);
            

            
            Y.Event.on("userNameStepForm","submit",function(e){
                this.loaderizeButton("userNameContinueButton");
                this.userNameContinue(e);
            },this,true);
            
            
            
            Y.Event.on("informationStepForm","submit",function(e){
                this.loaderizeButton("signUpContinueButton");
                this.signUpContinue(e);
            },this,true);
            
            Y.Event.on(Y.Dom.getElementsByClassName("skOutsideLink","a","signInOverlay"),"click",function(){
                window.location.hash="#";
            });
            
            
            
                
            this.slideWidth = Y.Dom.getFirstChild(this.el).offsetWidth;
            var haL = Y.Dom.getElementsByClassName("check-availability","a","signInOverlay");
            for(i=0;i<haL.length;i++){
                Y.Event.on(haL[i],"click",this.checkUserNameAvailability,this,true);
            }
            this.tempSignInOverlay.destroy();

            if(YAHOO.env.ua.gecko<=1.8 && YAHOO.env.ua.gecko>0){
                Y.Dom.getElementsByClassName("input-c", "div","signInOverlay",function(){ this.style.display="none"; });
                var f = function(){ Y.Dom.getElementsByClassName("input-c", "div","signInOverlay",function(){ this.style.display="block"; }); };
                setTimeout(f,0);
            }
            
            
            
            
            
            this.signInOverlay.show();
            
            

            
            
            
        };
        var callbacks = { success: handleSuccess, argument: {"params":params}, scope:this,cache:false};
        Y.Connect.asyncRequest('GET', "/accountManagerUI/scripts/sonomaKeyContent.html", callbacks);
    },
    loaderizeButton:function(buttonEl){
        if(typeof(buttonEl=="string")){buttonEl=document.getElementById(buttonEl); }
        this.hiddenButton=buttonEl;
        var loader = document.createElement("span");
        loader.innerHTML = "Please Wait...";
        Y.Dom.addClass(loader,"loading");
        this.loaderSpan = loader;
        this.hiddenButton.style.display="none";
        Y.Dom.insertAfter(this.loaderSpan,this.hiddenButton);
    },
    unLoaderizeButton:function(){
      this.loaderSpan.parentNode.removeChild(this.loaderSpan);
      this.hiddenButton.style.display="block";  
    },
    changePassword:function(e){
        if(e){Y.Event.stopEvent(e);}
        var oldp=document.getElementById("cPassOld");
        var password1=document.getElementById("cPassNew1");
        var password2=document.getElementById("cPassNew2");
        this.clearErrors("changePasswordStep");
        var valid=true;
        if(!password1.value || password1.value==""){
            valid = false;
            this.attachError(password1,"Enter a password","changePasswordStep");
        }
        if(!password2.value || password2.value==""){
            valid = false;
            this.attachError(password2,"Confirm your password","changePasswordStep");
        }
        if(password1.value.length<5){
            valid=false;
            this.attachError(password1,"Password must be at least 5 characters","changePasswordStep");
        }
        if(password1.value != password2.value){
            valid=false;
            this.attachError(password1," ","changePasswordStep");
            this.attachError(password2,"Confirmation must match original password","changePasswordStep");
        }

        var rexpn=new RegExp(/[^a-zA-Z0-9_]/);
        
        
        if(rexpn.exec(password1.value)!=null){
            valid=false;
            this.attachError(password1,"Password can only contain letters and numbers","changePasswordStep");
            this.attachError(password2," ","changePasswordStep");
        }
        
        var handleSuccess = function(o){
                
            var isV = sonomaParseInt(o.responseText);
            var valid = o.argument.valid;
            
            
            
            if(isV==0){
                
                this.attachError(oldp,"Invalid Password","changePasswordStep");
                valid=false;
            }
            else if(isV==1){
                if(valid){
                    var finishchange = function(p){
                        var successful = sonomaParseInt(p.responseText);
                        if(successful==1){
                            this.plainGoToIndex(1);
                        }
                        else{
                            this.systemError(p.responseText);
                        }
                    };
                    var pcallbacks = { success: finishchange, scope:this};
                    var url=this.accountManagerUrl+"?action=edit&username="+escape(this.params.userName)+"&password="+escape(oldp.value)+"&newpassword="+password1.value;
                    Y.Connect.asyncRequest('GET',url,pcallbacks);
    
                }
            }
            else{
                this.systemError(o.responseText);
            }
            this.unLoaderizeButton();
           
            
        };
        
        var callbacks = { success: handleSuccess, scope:this, argument:{"valid":valid}};
        var url=this.accountManagerUrl+"?action=isvalid&password="+escape(oldp.value)+"&username="+escape(this.params.userName);
        Y.Connect.asyncRequest('GET', url, callbacks);
        
        
    },
    editAccount:function(e){
        if(e){Y.Event.stopEvent(e);}
    
    },
    showFooter:function(whichFooter){
        var ll = Y.Dom.getElementsByClassName("current","div","overlayFooter");
        for(i=0;i<ll.length;i++){
            this.prevFooter=ll[i].id;
            Y.Dom.removeClass(ll[i],"current");
        }
        if(whichFooter && whichFooter != ""){
            Y.Dom.addClass(whichFooter,"current");
        }
    },
    goToSection:function(section){
        this.bd = Y.Dom.getElementsByClassName("bd","div","signInOverlay")[0];
        if(typeof(this.el)!="undefined"){
            this.el.style.display="none";
        }
        if(YAHOO.sonoma.maint != true){;
            switch(section){
                case "signUp":
                    this.el = document.getElementById("signupSteps");
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="get_your_sonoma_key">Get Your Sonoma Key</h1>');
                    if(this.params.downloadNow){
                        this.initDownload("step1");
                    }
                    this.bd.style.height="500px";
                    this.showFooter("signUpFooter");
                    if(typeof(this.signupSteps)=="undefined"){
                        this.signupSteps = Y.Dom.getElementsByClassName("step","li","signupSteps");
                    }
                    this.signupIndex=0;
                    
                    this.currentSlide=this.signupSteps[0];
                break;
                case "logIn":
                    this.el = document.getElementById("loginSteps");
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="sonoma_key_login">SonomaKey Login</h1>');
                    this.bd.style.height="275px";
                    this.showFooter("logInFooter");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                break;
                case "terms":
                    if(!this.returnEl){this.returnEl=this.el;}
                    this.el=document.getElementById("terms");
                    this.bd.style.height="500px";
                    this.showFooter("generalFooter");
                break;
                case "privacyPolicy":
                    if(!this.returnEl){this.returnEl=this.el;}
                    this.el=document.getElementById("privacyPolicy");
                    this.bd.style.height="500px";
                    this.showFooter("generalFooter");
                break;
                case "forgotUserName":
                    
                    this.el=document.getElementById("forgotUserNameSteps");
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="sonoma_key_forgot_username">SonomaKey: Forgot Username</h1>');
                    this.bd.style.height="275px";
                    this.showFooter("generalFooter");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                    break;
                case "forgotPassword":
                    this.el=document.getElementById("forgotPasswordSteps");
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="sonoma_key_forgot_password">SonomaKey: Forgot Password</h1>');
                    this.bd.style.height="275px";
                    this.showFooter("generalFooter");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                    break;
                case "changePassword":
                    this.el=document.getElementById("changePasswordSteps");
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="sonoma_key_change_password">SonomaKey: Change Password</h1>');
                    this.bd.style.height="500px";
                    this.showFooter("generalFooter");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                    break;
                case "editAccountInfo":
                    this.el=document.getElementById("editAccountSteps");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                    this.setupAccountInfo();
                    this.returnEl=false;
                    this.signInOverlay.setHeader('<h1 class="sonoma_key_account_info">SonomaKey: Account Information</h1>');
                    this.bd.style.height="500px";
                    this.showFooter("generalFooter");
                    
                    break;
                case "systemError":
                    this.el=document.getElementById("errorSteps");
                    this.currentSlide=Y.Dom.getChildren(this.el)[0];
                    this.returnEl=false;
                    this.bd.style.height="500px";
                    
                    break;
            }
        }
        else{
            this.el=document.getElementById("maintenanceSteps");
            this.currentSlide=Y.Dom.getChildren(this.el)[0];
            this.returnEl=false;
            this.signInOverlay.setHeader('');
            this.bd.style.height="500px";
            this.showFooter(false);
            if(this.params.downloadNow){
                this.initDownload("maintStep");
            }
        }
        this.el.style.display="block";        
        var t = Y.Dom.getElementsByClassName("step","li",this.el);
        for(i=0;i<t.length;i++){
            t[i].style.display="none";
        }
        t[0].style.display="block";
        t[0].style.left="0";
        
        
        if(typeof(this.params.contextMsg)=="string"&&this.params.contextMsg!=""){
            var title=this.params.contextMsgTitle;
            var body=this.params.contextMsg;
            if(typeof(this.params.contextMsgLinkText)!="undefined"&&this.params.contextMsgLinkText!=""){
                body = body + ' <a href="'+this.params.contextMsgLinkUrl+'">'+this.params.contextMsgLinkText+'</a>';
            }
            this.insertContextMessage(this.currentSlide,title,body,false);
            this.params.contextMsg = false;
        }
        
        
    },
    setupAccountInfo:function(){
        
        
        
        var handleSuccess = function(o){
            
            var u = eval("("+o.responseText+")");
            if(typeof(u.firstname)!="undefined" && u.firstname!=""){
                var f=document.getElementById("editAccountForm");
                f.ai_fn.value=u.firstname;
                f.ai_ln.value=u.lastname;
                f.ai_em1.value=u.email;
                f.ai_em2.value=u.email;
                f.ai_zip.value=u.zipcode;
                f.ai_news.checked=u.newsletter==1?"checked":false;
                
                var so=f.ai_country.options;
                for(i=0;i<so.length;i++){
                    if(so[i].value==u.countryiso3){
                        so[i].selected="selected";
                        f.ai_country.selectedIndex=i;
                    }
                }
                
                for(i=0; i<f.elements.length;i++){
                    Y.Event.on(f.elements[i],"click",function(){
                        document.getElementById("ai_pw_container").style.display="block";
                    });
                }
                this.plainGoToIndex(1);
            }
            else{
                this.systemError(o.responseText);
            }
            
            
            
            
        };
    
        var callbacks = { success: handleSuccess, scope:this};
        var url=this.accountManagerUrl+"?action=getinfo&username="+this.params.userName;
        Y.Connect.asyncRequest('GET', url, callbacks);
    
    },
    editAccountInfo: function(e){
        
        if(e){Y.Event.stopEvent(e);}
        this.clearErrors("editAccountStep");
        var f=document.getElementById("editAccountForm");
        if(f.ai_pw.value!=""){
            var vSuccess=function(p){
                if(sonomaParseInt(p.responseText)==1){
                    var valid=true;
                    if(!f.ai_em1.value || f.ai_em1.value==""){
                        valid = false;
                        this.attachError(f.ai_em1,"Enter an Email Address" ,"editAccountStep");
                    }
                    
                    if(!f.ai_em2.value || f.ai_em2.value==""){
                        valid = false;
                        this.attachError(f.ai_em2,"Confirm your Email Address" ,"editAccountStep");
                    }
                    if(!f.ai_fn.value || f.ai_fn.value==""){
                        valid = false;
                        this.attachError(f.ai_fn,"Enter a First Name" ,"editAccountStep");
                    }
                    if(f.ai_fn.value.length<2){
                        valid = false;
                        this.attachError(f.ai_fn,"First Name must contain a minimum of 2 characters " ,"editAccountStep");
                    }
                    if(!f.ai_ln.value || f.ai_ln.value==""){
                        valid = false;
                        this.attachError(f.ai_ln,"Enter a Last Name" ,"editAccountStep");
                    }
                    if(f.ai_ln.value.length<2){
                        valid = false;
                        this.attachError(f.ai_ln,"Last Name must contain a minimum of 2 characters " ,"editAccountStep");
                    }
                    if(!f.ai_country.value || f.ai_country.value==""){
                        valid = false;
                        this.attachError(f.ai_country,"Select a Country" ,"editAccountStep");
                    }
                    if(!f.ai_zip.value || f.ai_zip.value==""){
                        valid = false;
                        this.attachError(f.ai_zip,"Enter a Zip/Postal Code" ,"editAccountStep");
                    }
                    if(!isValidEmail(f.ai_em1.value)){
                        valid = false;
                        this.attachError(f.ai_em1,"Enter a valid email address" ,"editAccountStep");
                    }
                    if(f.ai_em1.value != f.ai_em2.value){
                        valid=false;
                        this.attachError(f.ai_em1," " ,"editAccountStep");
                        this.attachError(f.ai_em2,"Confirmation must match original email address" ,"editAccountStep");
                    }
                    if(valid){
                        var handleSuccess = function(o){
                            if(o.argument.valid){
                                if(sonomaParseInt(o.responseText)==1){
                                    this.plainGoToIndex(2);
                                }
                                else{
                                   this.systemError(o.responseText);
                                }
                            }
                            this.unLoaderizeButton();
                        };
                        var aiNewsletterValue = f.ai_news.checked?"1":"0";
                        var callbacks = {success: handleSuccess,scope:this,argument:{"valid":valid}};
                        var url=this.accountManagerUrl+"?action=edit"+
                                "&username="+escape(this.params.userName)+
                                "&password="+escape(f.ai_pw.value)+
                                "&email="+escape(f.ai_em1.value)+
                                "&firstname="+escape(f.ai_fn.value)+
                                "&lastname="+escape(f.ai_ln.value)+
                                "&countryiso3="+escape(f.ai_country.value)+
                                "&zipcode="+escape(f.ai_zip.value)+
                                "&newsletter="+escape(aiNewsletterValue);
                        Y.Connect.asyncRequest('GET', url, callbacks);
                    }
                    else{
                        this.unLoaderizeButton();
                    }
                }
                else if(sonomaParseInt(p.responseText)==0){
                    this.attachError(f.ai_pw,"Password is not correct.","editAccountStep");
                    valid=false;
                    this.unLoaderizeButton();
                }
                else{
                    this.systemError(p.reponseText);
                }
                    
            };
            var callbacks = {success: vSuccess,scope:this};
            var url=this.accountManagerUrl+"?action=isvalid&username="+escape(this.params.userName)+"&password="+escape(f.ai_pw.value);
            Y.Connect.asyncRequest('GET',url,callbacks);
        }
        else{
            this.attachError(f.ai_pw, "Please Enter a Password","editAccountStep");
            this.unLoaderizeButton();
        }
    },
    resetPassword: function(e){
        if(e){Y.Event.stopEvent(e);}
        var tl = Y.Dom.getElementsByClassName("errorMessage","div","forgotPasswordStep");
        for(i=0;i<tl.length;i++){
            tl[i].parentNode.removeChild(tl[i]);
        }
        var handleSuccess = function(o){
            var isAv = sonomaParseInt(o.responseText);
            if(isAv==1){
                //do something
                this.plainGoToIndex(1);
            }
            else if(isAv==0){
                var msgC = document.createElement("div");
                Y.Dom.addClass(msgC,"errorMessage");
                var t=document.createElement("div");
                Y.Dom.addClass(t,"top");
                msgC.appendChild(t);
                var par = document.createElement("p");
                par.innerHTML = 'Sorry! That Email Address is not associated with any SonomaKey. <a href="http://www.sonomawireworks.com/support.php">Contact Support</a> for help.';
                msgC.appendChild(par);
                var t=document.createElement("div");
                Y.Dom.addClass(t,"bottom");
                msgC.appendChild(t);
                Y.Dom.insertBefore(msgC,Y.Dom.getElementsByClassName("fieldContainer","div","forgotPasswordStep")[0]);
                
            }
            else{
                this.systemError(o.responseText);
            }
            this.unLoaderizeButton();
        };
        var email=document.getElementById("fpEmail").value;
        var callbacks = { success: handleSuccess, scope:this};
        var url=this.accountManagerUrl+"?action=forgotpassword&email="+escape(email);
        Y.Connect.asyncRequest('GET', url, callbacks);
    },
    retrieveUserName: function(e){
        if(e){Y.Event.stopEvent(e);}
        var tl = Y.Dom.getElementsByClassName("errorMessage","div","forgotUserNameStep");
        for(i=0;i<tl.length;i++){
            tl[i].parentNode.removeChild(tl[i]);
        }
        var handleSuccess = function(o){
            var isAv = sonomaParseInt(o.responseText);
            if(isAv==1){
                //do something
                this.plainGoToIndex(1);
            }
            else if(isAv==0){
                var msgC = document.createElement("div");
                Y.Dom.addClass(msgC,"errorMessage");
                var t=document.createElement("div");
                Y.Dom.addClass(t,"top");
                msgC.appendChild(t);
                var par = document.createElement("p");
                par.innerHTML = 'Sorry! That Email Address is not associated with any SonomaKey. <a href="http://www.sonomawireworks.com/support.php">Contact Support</a> for help.';
                msgC.appendChild(par);
                var t=document.createElement("div");
                Y.Dom.addClass(t,"bottom");
                msgC.appendChild(t);
                Y.Dom.insertBefore(msgC,Y.Dom.getElementsByClassName("fieldContainer","div","forgotUserNameStep")[0]);
            }
            else{
                this.systemError(o.responseText);
            }
            this.unLoaderizeButton();
        };
        var email=document.getElementById("fuEmail").value;
        var callbacks = { success: handleSuccess, scope:this};
        var url=this.accountManagerUrl+"?action=forgotusername&email="+escape(email);
        Y.Connect.asyncRequest('GET', url, callbacks);
    },
    returnToPrevious:function(e){
        if(e){Y.Event.stopEvent(e);}

        this.el.style.display="none";
        this.el=this.returnEl;
        this.el.style.display="block";
        this.bd.style.height=this.el.offsetHeight+"px";
        this.el.style.top=0;
        if(this.prevFooter && this.prevFooter!=""){
            this.showFooter(this.prevFooter);
            this.prevFooter=false;
        }
    },
    downloadNextStep:function(e){
        if(e){Y.Event.stopEvent(e);}
        if(document.getElementById("downloadRiffworksCheck").checked){
            this.nextStep();
            this.initDownload("userNameStep");
        }
        else{ this.nextStep();}
    },
    insertContextMessage:function(step,title,message,classname){
        var msg = document.createElement("div");
        Y.Dom.addClass(msg,"contextMessage");
        var t=document.createElement("div");
        Y.Dom.addClass(t,"top");
        msg.appendChild(t);
        var t = document.createElement("div");
        Y.Dom.addClass(t,"message");
        if(classname){
            Y.Dom.addClass(t,classname);
        }
        var titleH=document.createElement("h2");
        titleH.innerHTML = title;
        t.appendChild(titleH);
        var par = document.createElement("p");
        par.innerHTML = message;
        t.appendChild(par);
        msg.appendChild(t);
        var t = document.createElement("div");
        Y.Dom.addClass(t,"bottom");
        msg.appendChild(t);
        var t = Y.Dom.getFirstChild(step);
        Y.Dom.insertBefore(msg,t);
    },
    removeContextMessages:function(step){
        var tl = Y.Dom.getElementsByClassName("contextMessage","div",step);
        
        for(i=0;i<tl.length;i++){
            tl[i].parentNode.removeChild(tl[i]);
        }
    },
    userNameContinue: function(e){
        if(e){Y.Event.stopEvent(e);}
        var valid = true;
        var userName = document.getElementById("userName");
        var password1 = document.getElementById("password1");
        var password2 = document.getElementById("password2");
        this.clearErrors("userNameStep");
        if(!userName.value || userName.value==""){
            valid = false;
            this.attachError(userName,"Enter a User Name","userNameStep");
        }
        if(userName.value.length<4){
            valid=false;
            this.attachError(userName,"Username must be at least 4 characters","userNameStep");
        }
        if(!password1.value || password1.value==""){
            valid = false;
            this.attachError(password1,"Enter a password","userNameStep");
        }
        if(!password2.value || password2.value==""){
            valid = false;
            this.attachError(password2,"Confirm your password","userNameStep");
        }
        if(password1.value.length<5){
            valid=false;
            this.attachError(password1,"Password must be at least 5 characters","userNameStep");
        }
        if(password1.value != password2.value){
            valid=false;
            this.attachError(password1," ","userNameStep");
            this.attachError(password2,"Confirmation must match original password","userNameStep");
        }

        var rexpn=new RegExp(/[^a-zA-Z0-9_]/);
        if(rexpn.exec(userName.value)!=null){
            valid=false;
            this.attachError(userName,"User Name can only contain letters and numbers","userNameStep");
        }
        
        if(rexpn.exec(password1.value)!=null){
            valid=false;
            this.attachError(password1,"Password can only contain letters and numbers","userNameStep");
            this.attachError(password2," ","userNameStep");
        }
        
        if(userName.value && userName.value!=""){
            var handleSuccess = function(o){
                
                var isAv = sonomaParseInt(o.responseText);
                var valid = o.argument.valid;
                var arSpan = document.getElementById("availableResult");
                if(isAv==0){
                    
                    Y.Dom.replaceClass(arSpan,"available","not_available");
                    arSpan.innerHTML = "Not Available";
                    this.attachError(o.argument.userName,"User Name not available","userNameStep");
                    valid=false;
                    
                }
                else if(isAv==1){
                    Y.Dom.replaceClass(arSpan,"not_available","available");
                    arSpan.innerHTML = "Available!";
                    if(valid){
                        this.userName = o.argument.userName.value;
                        this.password = o.argument.password.value;
                        document.getElementById("userNamePreview").innerHTML = this.userName;
                        
                        this.nextStep();
                    }
                }
                else{
                    this.systemError(o.responseText);
                }
                
                this.unLoaderizeButton();
                Y.Dom.getElementsByClassName("check-availability","a",this.el,function(){ Y.Dom.removeClass(this,"checking");});
                
            };
            Y.Dom.getElementsByClassName("check-availability","a",this.el,function(){ Y.Dom.addClass(this,"checking");});
            var callbacks = { success: handleSuccess, scope:this, argument:{"valid":valid,"userName":userName,"password":password1}};
            var url=this.accountManagerUrl+"?action=isavailable&username="+userName.value;
            Y.Connect.asyncRequest('GET', url, callbacks);
        }
        else{
            var arSpan = document.getElementById("availableResult");
            Y.Dom.replaceClass(arSpan,"available","not_available");
            arSpan.innerHTML = "Not Available";
            this.unLoaderizeButton();
        }

        
        
    },
    
    signUpContinue: function(e){
        if(e){Y.Event.stopEvent(e);}
        var valid = true;
        
        var username = document.getElementById("userName");
        var password = document.getElementById("password1");
        
        var email = document.getElementById("email");

        var email_confirm = document.getElementById("email_confirm");

        var firstname = document.getElementById("firstname");

        var lastname = document.getElementById("lastname");

        var country = document.getElementById("country");

        var zipcode = document.getElementById("zipcode");

        var howdidyouhear = document.getElementById("howdidyouhear");

        var newsletter = document.getElementById("newsletter");

        var user_agreement = document.getElementById("user_agreement");

        
        this.clearErrors("informationStep");
        
        if(!email.value || email.value==""){
            valid = false;
            this.attachError(email,"Enter an Email Address" ,"informationStep");
        }
        
        if(!email_confirm.value || email_confirm.value==""){
            valid = false;
            this.attachError(email_confirm,"Confirm your Email Address" ,"informationStep");
        }
        
        
       
        if(firstname.value.length<2){
            valid = false;
            this.attachError(firstname,"First Name must contain a minimum of 2 characters " ,"informationStep");
        }
        
        var rexpn=new RegExp(/^[a-z]+(\'|-|\.\s|\s)?[a-z]+$/i);
        if(rexpn.exec(firstname.value)==null){
            valid=false;
            this.attachError(firstname,"Please enter a valid first name.","informationStep");
        }
        if(lastname.value.length<2){
            valid = false;
            this.attachError(lastname,"Last Name must contain a minimum of 2 characters " ,"informationStep");
        }
        if(rexpn.exec(lastname.value)==null){
            valid=false;
            this.attachError(lastname,"Please enter a valid last name.","informationStep");
        }
        if(!country.value || country.value==""){
            valid = false;
            this.attachError(userName,"Select a Country" ,"informationStep");
        }
        if(!zipcode.value || zipcode.value==""){
            valid = false;
            this.attachError(zipcode,"Enter a Zip/Postal Code" ,"informationStep");
        }
        
        if(!howdidyouhear.value || howdidyouhear.value==""){
            valid = false;
            this.attachError(howdidyouhear,"Tell us how you heard about us" ,"informationStep");
        }
        if(!user_agreement.checked){
            valid = false;
            this.attachError(user_agreement,"You must agree to our User Agreement to continue" ,"informationStep");
        }
        if(!isValidEmail(email.value)){
            valid = false;
            this.attachError(email,"Enter a valid email address" ,"informationStep");
        }
        if(email.value != email_confirm.value){
            valid=false;
            this.attachError(email," " ,"informationStep");
            this.attachError(email_confirm,"Confirmation must match original email address" ,"informationStep");
        }
        if(valid){
            var handleEmailSuccess = function(p){
                if(sonomaParseInt(p.responseText)==1){
                    var handleSuccess = function(o){
                        if(sonomaParseInt(o.responseText)==1){
                            document.getElementById("finishUsernameContainer").innerHTML=username.value;
                            document.getElementById("finishProfileLink").href=YAHOO.sonoma.memberProfileLoc+""+username.value;
                            this.performLogin(username.value,password.value,function(){ YAHOO.sonoma.signInSlider.nextStep(); YAHOO.sonoma.signInSlider.unLoaderizeButton(); });
                        }
                        else {
                            this.systemError(o.responseText);
                        }

                    };
                    var newsletterValue = newsletter.checked?"1":"0";
                    var callbacks = { success: handleSuccess, scope:this, argument:{"valid":valid}};
                    var url=this.accountManagerUrl+"?action=create"+
                    "&username="+escape(username.value)+
                    "&password="+escape(password.value)+
                    "&email="+escape(email.value)+
                    "&firstname="+escape(firstname.value)+
                    "&lastname="+escape(lastname.value)+
                    "&countryiso3="+escape(country.value)+
                    "&zipcode="+escape(zipcode.value)+
                    "&howdidyouhear="+escape(howdidyouhear.value)+
                    "&newsletter="+escape(newsletterValue);
                    if(this.params.referrer&&this.params.referrer!=""){
                        url = url+"&referrer="+escape(this.params.referrer);
                    }
                    Y.Connect.asyncRequest('GET', url, callbacks);
                }
                else{
                   this.attachError(email,"Email address is already taken.","informationStep");
                   this.unLoaderizeButton();
                } 
                
            };
            var eCallbacks = {success: handleEmailSuccess,scope:this,argument:{"valid":valid}};
            var url=this.accountManagerUrl+"?action=isemailavailable&email="+email.value;
            Y.Connect.asyncRequest('GET',url,eCallbacks);
        }
        else{
            this.unLoaderizeButton();
        }
        
        
        
    },
    systemError: function(text){
        
            
            
        try{   
            var errorList = eval("("+text+")");
            var errorMessage = "";
            for(i in errorList){
                var error = errorList[i];
                errorMessage = errorMessage = "<br />"+error.field+": "+error.error_message;
            }   
            var msgC = document.createElement("div");
            Y.Dom.addClass(msgC,"errorMessage");
            var t=document.createElement("div");
            Y.Dom.addClass(t,"top");
            msgC.appendChild(t);
            var par = document.createElement("p");
            par.innerHTML = "There are missing or invalid entries."+errorMessage;
            msgC.appendChild(par);
            var t=document.createElement("div");
            Y.Dom.addClass(t,"bottom");
            msgC.appendChild(t);
            Y.Dom.insertBefore(msgC,Y.Dom.getElementsByClassName("fieldContainer","div",this.currentSlide)[0]);
            
            this.unLoaderizeButton();
            
        }
        catch(err){
            
            text = text.replace(/(<([^>]+)>)/ig,"");
            text = text.replace(/\n\n/g, "\n");
            this.goToSection("systemError");
            document.getElementById("systemErrorText").innerHTML = text;
        }

    
    
    
    },
    clearErrors:function(step){
        
        var stepEl = document.getElementById(step);
        Y.Dom.getElementsByClassName("skError","li",stepEl,function(){
            Y.Dom.removeClass(this,"skError");
            var labelCon = Y.Dom.getElementsByClassName("label-c","div",this)[0];
            var t = Y.Dom.getElementsByClassName("note","div",labelCon);
            for(i=0;i<t.length;i++){
                t[i].parentNode.removeChild(t[i]);
            }
        });
        Y.Dom.getElementsByClassName("first-error","li",stepEl,function(){
            Y.Dom.removeClass(this,"first-error");
            var labelCon = Y.Dom.getElementsByClassName("label-c","div",this)[0];
            var t = Y.Dom.getElementsByClassName("note","div",labelCon);
            for(i=0;i<t.length;i++){
                t[i].parentNode.removeChild(t[i]);
            }
        });
        
        var t=Y.Dom.getElementsByClassName("errorMessage","div",stepEl);
        for(i=0;i<t.length;i++){
            t[i].parentNode.removeChild(t[i]);
        }
    },
    attachError:function(inputEl,message,step){
        var parentLi = findParentByTagName(inputEl,"li");
        if(Y.Dom.hasClass(parentLi,"first")){
            if(!Y.Dom.hasClass(parentLi,"first-error")){
                Y.Dom.addClass(parentLi,"first-error");
            }
        }
        else{
            if(!Y.Dom.hasClass(parentLi,"skError")){
                Y.Dom.addClass(parentLi,"skError");
            }
        }
        var labelCon = Y.Dom.getElementsByClassName("label-c","div",parentLi)[0];
        var r = document.createElement("div");
        Y.Dom.addClass(r,"note");
        r.innerHTML = message;
        labelCon.appendChild(r);
        
        if(!Y.Dom.getElementsByClassName("errorMessage","div",step).length){
            var msgC = document.createElement("div");
            Y.Dom.addClass(msgC,"errorMessage");
            var t=document.createElement("div");
            Y.Dom.addClass(t,"top");
            msgC.appendChild(t);
            var par = document.createElement("p");
            par.innerHTML = "There are missing or invalid entries. Please correct the items indicated below.";
            msgC.appendChild(par);
            var t=document.createElement("div");
            Y.Dom.addClass(t,"bottom");
            msgC.appendChild(t);
            Y.Dom.insertBefore(msgC,Y.Dom.getElementsByClassName("fieldContainer","div",step)[0]);
        }
    
    },
    removeError:function(inputEl){
        var parentLi = findParentByTagName(inputEl,"li");
        Y.Dom.removeClass(parentLi,"error");
        var labelCon = Y.Dom.getElementsByClassName("label-c","div",parentLi)[0];
        Y.Dom.getElementsByClassName("note","div",labelCon,function(){this.parentNode.removeChild(this);});
    },
    checkUserNameAvailability: function(e){
        
        if(e){Y.Event.stopEvent(e);}
        var userName = document.getElementById("userName").value;
        
        if(userName && userName!=""){
            Y.Dom.getElementsByClassName("check-availability","a",this.el,function(){ Y.Dom.addClass(this,"checking");});
            var handleSuccess = function(o){
                var isAv = sonomaParseInt(o.responseText);
                var arSpan = document.getElementById("availableResult");
                if(isAv==0){
                    Y.Dom.replaceClass(arSpan,"available","not_available");
                    arSpan.innerHTML = "Not Available";
                }
                else if(isAv==1){
                    Y.Dom.replaceClass(arSpan,"not_available","available");
                    arSpan.innerHTML = "Available!";
                }
                else{
                    this.systemError(o.responseText);
                }
                Y.Dom.getElementsByClassName("check-availability","a",this.el,function(){ Y.Dom.removeClass(this,"checking");});
            };
            
            var callbacks = { success: handleSuccess, scope:this};
            var url=this.accountManagerUrl+"?action=isavailable&username="+userName;
            Y.Connect.asyncRequest('GET', url, callbacks);
        }
        else{
            var arSpan = document.getElementById("availableResult");
            Y.Dom.replaceClass(arSpan,"available","not_available");
            arSpan.innerHTML = "Not Available";
        }
        
    },
    show: function(e){
        if(e){Y.Event.stopEvent(e);}
        this.signInOverlay.show();
    },
    nextStep: function(e){
        if(e){Y.Event.stopEvent(e);}
        window.location.hash = "#";
        this.signupSteps[this.signupIndex+1].style.display="block";
        var newLeft = 0 - this.slideWidth;
        var slideOut=new Y.Anim(this.signupSteps[this.signupIndex],{left:{to: newLeft}},this.slideSpeed,Y.Easing.easeOut);
        var slideIn=new Y.Anim(this.signupSteps[this.signupIndex+1],{left:{to: 0}},this.slideSpeed,Y.Easing.easeOut);
        slideIn.onComplete.subscribe(function(){
            this.signupSteps[this.signupIndex].style.display="none";
            this.signupSteps[this.signupIndex].style.left=this.slideWidth+"px";
            this.signupIndex = this.signupIndex+1;
            this.currentSlide=this.signupSteps[this.signupIndex];
        },this,true);
        slideOut.animate();
        slideIn.animate();
    },
    prevStep: function(e){
        if(e){Y.Event.stopEvent(e);}
        
        this.signupSteps[this.signupIndex-1].style.display="block";
        this.signupSteps[this.signupIndex-1].style.left="-"+this.slideWidth+"px";
        
        var slideOut=new Y.Anim(this.signupSteps[this.signupIndex],{left:{to: this.slideWidth}},this.slideSpeed,Y.Easing.easeOut);
        var slideIn=new Y.Anim(this.signupSteps[this.signupIndex-1],{left:{to: 0}},this.slideSpeed,Y.Easing.easeOut);
        slideIn.onComplete.subscribe(function(){
            this.signupSteps[this.signupIndex].style.display="none";
            this.signupIndex = this.signupIndex-1;
            this.currentSlide=this.signupSteps[this.signupIndex];
        },this,true);
        slideOut.animate();
        slideIn.animate();
    },
    plainGoToIndex: function(index){
        var t=Y.Dom.getElementsByClassName("step","li",this.el);
        t[index-1].style.display="none";
        t[index-1].style.left=this.slideWidth+"px";
        t[index].style.display="block";
        t[index].style.left=0;
        
        this.currentSlide=t[index];
    },
    logIn: function(e){
        if(e){Y.Event.stopEvent(e);}
        this.clearErrors("logInStep");
        
        
        var username=document.getElementById("logInUserName").value;
        var password=document.getElementById("logInPassword").value;
        var valid = true;
        if(!username || username==""){
            valid = false;
            this.attachError(document.getElementById("logInUserName"),"Please enter a username" ,"logInStep");
        }
        if(!password || password==""){
            valid = false;
            this.attachError(document.getElementById("logInPassword"),"Please enter a password" ,"logInStep");
        }
        if(valid){
            var handleSuccess = function(o){
                var isAv = sonomaParseInt(o.responseText);
                if(isAv==1){
                    var redirect = this.params.redirect;
                    this.performLogin(username,password,function(){ 
                        if(redirect && redirect!=""){
                            window.location=redirect;
                        } else{
                            window.location=YAHOO.sonoma.signInSlider.curLoc;
                        }
                    });
                }
                else if(isAv==0){
                    var msgC = document.createElement("div");
                    Y.Dom.addClass(msgC,"errorMessage");
                    var t=document.createElement("div");
                    Y.Dom.addClass(t,"top");
                    msgC.appendChild(t);
                    var par = document.createElement("p");
                    par.innerHTML = "Sorry! Username and password do not match.";
                    msgC.appendChild(par);
                    var t=document.createElement("div");
                    Y.Dom.addClass(t,"bottom");
                    msgC.appendChild(t);
                    Y.Dom.insertBefore(msgC,Y.Dom.getElementsByClassName("fieldContainer","div","logInStep")[0]);
                    this.unLoaderizeButton();
                }
                else{
                    this.systemError(o.responseText);
                }
                
                
            };
            
            var callbacks = { success: handleSuccess, scope:this};
            var url=this.accountManagerUrl+"?action=isvalid&username="+escape(username)+"&password="+escape(password);
            
            Y.Connect.asyncRequest('GET', url, callbacks);
        }
        else{
            this.unLoaderizeButton();
        }
        
        
        
            
    },
    performLogin: function(username,password,onComplete){
        this.loginIframe = document.createElement("iframe");
        this.loginIframe.id="accountManagerIFRAME";
        this.loginIframe.width="0";
        this.loginIframe.height="0";
        this.loginIframe.frameBorder="0";
        document.body.appendChild(this.loginIframe);
        var ifrSrc = this.accountManagerUrl+"?action=login&username="+username+"&password="+password;
        this.loginIframe.src=ifrSrc;
        this.onLoginComplete=onComplete;
        
        this.checkLoginComplete();
        
    },
    checkLoginComplete: function(){
        
        
        var tIframe = document.getElementById("accountManagerIFRAME"); 
        var t=tIframe.contentWindow.document;
        
        try{ 
            var content = tIframe.contentWindow.document.body.innerHTML; 
            if(trim(content)=="SUCCESS"){ 
                var t = this.onLoginComplete; 
                t(); 
            } 
            else{ 
                setTimeout("YAHOO.sonoma.signInSlider.checkLoginComplete()",10); 
            } 
        } 
        catch(err){ 
           // setTimeout("YAHOO.sonoma.signInSlider.checkLoginComplete()",10); 
           // @insane mmw
           return;
        }     
    },
    initDownload:function(step){
        if(this.params.downloadType=="Mac"){
            var msg = "Downloading for <strong>"+this.params.downloadType+"</strong>. <a href=\"#\" id=\"alternateDownloadLink\">I need the Windows version instead</a>";
        }
        else{
            var msg = "Downloading for <strong>"+this.params.downloadType+"</strong>. <a href=\"#\" id=\"alternateDownloadLink\">I need the Mac version instead</a>";
        }
        this.insertContextMessage(step,"Thanks! RiffWorks T4 downloading now... ",msg,"download");
        Y.Event.on("alternateDownloadLink","click",function(e){
            if(e){Y.Event.stopEvent(e);}
            this.removeContextMessages(step);
            this.params.downloadType = this.params.downloadType=="Mac"?"Windows":"Mac";
            this.initDownload(step);
        },this,true);
        
        
        var hashVal = "resumeDownload";
        if(this.params.referrer&&this.params.referrer!=""){
            hashVal=hashVal+"&"+this.params.referrer;
        }
        window.location.hash = hashVal;
        
        /*
        
        */
        if(YAHOO.env.ua.ie>0 && YAHOO.env.ua.ie < 7){
            var frm = document.createElement("form");
            frm.action=this.params.downloadType=="Mac"?YAHOO.sonoma.macFileUrl:YAHOO.sonoma.winFileUrl;
            var ti = document.createElement("input");
            ti.type="hidden";
            ti.name="t";
            frm.appendChild(ti);
            document.body.appendChild(frm);
            frm.submit();
        }
        else{
            var ifr = document.createElement("iframe");
            ifr.width="0";
            ifr.height="0";
            ifr.frameBorder="0";
            document.body.appendChild(ifr);
            ifr.src = this.params.downloadType=="Mac"?YAHOO.sonoma.macFileUrl:YAHOO.sonoma.winFileUrl;
        }
        
        
        
        
    }
    
};

YAHOO.util.Event.onDOMReady(function(){
    var aList = Y.Dom.getElementsByClassName("sonomaKeyPopUp","a");
    var attr;
    for(i=0;i<aList.length;i++){
        Y.Event.on(aList[i],"click",function(e) { 
        	Y.Event.stopEvent(e);
      		if (this.getAttribute('rel')) {attr = this.getAttribute('rel');} else {attr = this.getAttribute('params');}
        	YAHOO.sonoma.signInSlider = new sonomaKeySignupSlider(attr);
        });
    }

    var str = window.location.hash;
    if(str.slice(0,15)=="#resumeDownload"){ 
        var reff=str.slice(16);

        var prms = "{type:'signUp',downloadNow:true,askForDownload:false";
        if(reff!=""){ prms = prms+",referrer:'"+reff+"'";}
        prms = prms+"}";
        YAHOO.sonoma.signInSlider = new sonomaKeySignupSlider(prms);
    }
});

function findParentByTagName(el, tag) {
    if (typeof(el) == "string") {
        el = document.getElementById(el);
    }
    var parent = el.parentNode;
    while (parent.tagName.toLowerCase() != tag.toLowerCase()) {
        parent = parent.parentNode;
    }
    return parent;
};


function isValidEmail(str) {
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if(str.indexOf(at)==-1 || str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr || str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.indexOf(at,(lat+1))!=-1 || str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot || str.indexOf(dot,(lat+2))==-1 || str.indexOf(" ")!=-1){
        return false;
    }
    else{
        return true;
    }
};

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
};

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
};

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
};
