// object to control the login and security of the site

// object to manage the login to the site and manage the login coocie

login = function()
{
    this.CurrentUser = {};
    this.haveCookie = null;
    this.UserName = null;
    this.cm =null; // cookie manager
    this.loginDiv = null;
    this.newUserForm = null;
    this.updateUserForm = null;
    this.target = null;
    this.newUserDetail = {};
    this.updateUserDetail = {};
    this.passwordAprove=null;
    this.formNewUser = null;
    this.formlogin = null;
    this.init();
    
    
};
login.prototype = {
    CookieName : "zazim-user",
    loginurl : "security/login.aspx?",
    firstLoginurl : "security/FirstLogin.aspx?",
    newUserUrl :"security/newUser.aspx?",
    updateUserUrl :"security/updateUser.aspx?",
    sendPasswordUrl :"security/sendPassword.aspx?",
    cookieloginurl : "security/cookieLogin.aspx?",
    logoffUrl : "security/logoff.aspx?",
    newUserForm : null,
    loginDiv : null,
    init : function()
    {
        /* create forms */
        /* login form */
        
        this.formlogin = new createForm({width:300,height:170,blockScreen:true,closebtn:true,title:'כניסת משתמש רשום',analyticsname:'login'});
        this.formlogin.parent = this;
        this.formlogin.is_valid_email = function(email)
        {
            return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);    
        };
        this.formlogin.submit = function()
        {   
            var data = this.getFormValsObj();
            var msg="";
            if(data.email == "") msg+="לא הוזנה כתובת דואר.";
            if(msg == "")
            {
                if(!this.is_valid_email(data.email))
                    msg+="כתובת מייל לא חוקית"
            }
            if(msg != "") msg+="\n";
            if(data.password == "")
                msg+="לא הוזנה סיסמא."
            if(msg !="") 
                alert(msg); 
            else
            {
                this.hide();
                this.parent.doLogin(false,data.email,data.password);
            }
        };
        
        this.formlogin.forgatPass = function()
        {
            var data = this.getFormValsObj();
            var msg="";
            if(data.email == "") msg+="לא הוזנה כתובת דואר.";
            if(msg == "")
            {
                if(!this.is_valid_email(data.email))
                    msg+="כתובת מייל לא חוקית"
            }
            
            if(msg !="") 
                alert(msg); 
            else
            {
                this.hide();
                this.parent.reSendPassword();
            }
        };
        this.formlogin.addDiv({text:'דואר אלקטרוני:',style:'login-txt',width:75});
        this.formlogin.addField({type:'text',name:'email',style:'login-txt',width:170});
        this.formlogin.addDiv({text:'סיסמא:',style:'login-txt',width:75});
        this.formlogin.addField({type:'pass',name:'password',style:'login-txt',width:170});
        this.formlogin.addDiv({text:'',style:'login-txt',width:75});
        this.formlogin.addField({type:'chk',name:'remember',style:'login-txt',width:170,text:'זכור אותי במחשב זה.'});
        this.formlogin.addDiv({text:'',style:'login-br',width:10,height:5});
        this.formlogin.addDiv({text:'',style:'login-txt',width:25});
        this.formlogin.addBtn({width:100,text:'כניסה',style:'login-btns'}).on('click',this.formlogin.submit,this.formlogin);
        this.formlogin.addDiv({text:'',style:'login-txt',width:20});
        this.formlogin.addBtn({width:100,text:'שכחתי סיסמא',style:'login-btns'}).on('click',this.formlogin.forgatPass,this.formlogin);
        this.formlogin.addDiv({text:'',style:'login-br',width:10,height:5});
        var d1=this.formlogin.addDiv({text:'רישום משתמש חדש>>',style:'login-reg-new-user'}).on('click',function(){this.formNewUser.show();this.formlogin.hide();},this);
        
        
        
        
        
        /* new user form */
        
        this.formNewUser = new createForm({width:310,height:390,blockScreen:true,closebtn:true,title:'רישום משתמש חדש',analyticsname:'new_user'});
        this.formNewUser.parent = this;
        this.formNewUser.is_valid_email = function(email)
        {
            return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);    
        };
        this.formNewUser.submit = function()
        {
            var data = this.getFormValsObj();
            
            var msg="";
            if(data.fname == "") {if(msg!="") msg+="\n"; msg+="חובה להזין שם"; }
            if(data.lname == "") {if(msg!="") msg+="\n"; msg+="חובה להזין שם משפחה"; }
            if(data.email == "") {if(msg!="") msg+="\n"; msg+="חובה להזין דואר אלקטרוני"; }
            if(data.password == "") {if(msg!="") msg+="\n"; msg+="חובה להזין סיסמא"; }
            if(data.passwordver == "") {if(msg!="") msg+="\n"; msg+="חובה להזין אימות סיסמא"; }
            if(data.cap == "") {if(msg!="") msg+="\n"; msg+="חובה להזין את המילה בתמונה"; }
            if(data.prefix == "") {if(msg!="") msg+="\n"; msg+="חובה לבחור קידומת"; }
            if(data.phone == "") {if(msg!="") msg+="\n"; msg+="חובה להזין מספר טלפון"; }
            if(!data.iagree) {if(msg!="") msg+="\n"; msg+="חובה לאשר את תקנון האתר"; }
            if(msg != "")
            {
                alert(msg);
                return;
            }
            if(data.password != data.passwordver){ if(msg!="") msg+="\n"; msg+="אין התאמה בין הסיסמאות";}
            if( data.phone.length != 7 || isNaN(parseFloat(data.phone)) )
            { 
                if(msg!="") msg+="\n"; 
                msg+="מספר הטלפון שהוזן אינו חוקי";
            }
            if(data.password.length <5){if(msg!="") msg+="\n"; msg+="הסיסמא צריכה להיות בת 5 תוים לפחות";}
            if(!this.is_valid_email(data.email)){if(msg!="") msg+="\n"; msg+="כתובת המייל שהוזנה אינה חוקית";}
            
            if(msg != "")
            {
                alert(msg);
                return;
            }
            this.hide();
            this.parent.addNewUser();
            
        };
        this.formNewUser.addDiv({text:'*שם:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'fname',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'*שם משפחה:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'lname',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'חברה:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'company',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'*טלפון נייד:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'phone',style:'login-txt',width:110});
        this.formNewUser.addField({type:'select',name:'prefix',style:'login-txt',width:65,value:':בחר|050|052|054|057',dvalue:''});
        this.formNewUser.addDiv({text:'*דואר אלקטרוני:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'email',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'*סיסמא:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'pass',name:'password',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'*אימות סיסמא:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'pass',name:'passwordver',style:'login-txt',width:170});
        this.formNewUser.addDiv({text:'',style:'login-txt',width:105,height:55});
        this.formNewUser.cap= this.formNewUser.addDiv({style:'x-cap',width:163,height:55});
        this.formNewUser.addDiv({text:'*המילה בתמונה:',style:'login-txt',width:85});
        this.formNewUser.addField({type:'text',name:'cap',style:'login-txt',width:170});
        this.formNewUser.addField({type:'chk',name:'iagree',style:'new-user-i-agree',width:270,text:'קראתי את תקנון האתר ואני מסכים לתנאיו'});
        this.formNewUser.addField({type:'chk',name:'allow_email',style:'new-user-i-agree',width:270,text:'מעוניין לקבל דיוורים ופרסומים מהאתר'});
        this.formNewUser.addDiv({text:'',style:'login-txt',width:105});
        this.formNewUser.addBtn({name:'inroll',width:163,text:'הרשם',style:'new-user-btn'}).on('click',this.formNewUser.submit,this.formNewUser);
        this.formNewUser.cap.dom.title = "לחץ כאן להחלפת תמונה";
        this.formNewUser.cap.on('click',function(){
        if(!this.capcount)
            {
                this.capcount =0;
            }
            this.cap.dom.style.backgroundImage ="url("+hosturl+ "security/JpegImage.aspx?cap=" + this.capcount + ")";
            this.capcount++;
        },this.formNewUser);
        this.formNewUser.showme = this.formNewUser.show;
        this.formNewUser.show = function(){
            if(!this.capcount)
            {
                this.capcount =0;
            }
            this.cap.dom.style.backgroundImage ="url("+hosturl+ "security/JpegImage.aspx?cap=" + this.capcount + ")";
            this.capcount++;
            this.showme();
        };
        
        /* add ff changes */
        if(!Ext.isIE)
        {   
            this.formNewUser.fieldArray.prefix.dom.style.marginRight = "-10px";
            this.formNewUser.cap.dom.style.marginRight = "-10px";
            this.formNewUser.btnArray.inroll.dom.style.marginRight = "-10px";
        }
        
        
        
    },
    doLogOff : function()
    {
        Ext.Ajax.request({
                url :hosturl + this.logoffUrl,
                success : function(ans){
                
                  this.cm.Write("",0);
                  this.updateUserDetail = null;
                  this.CurrentUser = null;
                  this.isLogin = false;
                  this.loginChange('guest',null);  
                },
                failure :function(){alert('חיבור לשרת נכשל אנא בדוק את חיבור האינטרנט');},
                scope : this
            });
    },
    TestCookie : function()
    {

        this.cm = new this.cookieManager(this.CookieName);
        if(this.cm.Read() == null)
        {
            this.haveCookie = false;
            this.doLogin(true,"","");
            return true;
        }
        else
        {
            this.haveCookie = true;
            this.doLogin(true,this.cm.Read().split("|")[0],this.cm.Read().split("|")[1]);
            return true;
        }
    },
    cookieManager : function(name)
    {
     this.CookieName = name;
     this.Exp = 3;
     this.Write=function(value,days)
     {	
	    var date = new Date();
	        date.setTime(date.getTime()+( ( days || this.Exp  )*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
            document.cookie =  ( this.CookieName ) +"="+value+expires+"; path=/";
     }
     this.Read = function() 
     {
        var nameEQ = (this.CookieName ) + "=";
        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;
      }
    },
    CreateLoginForm : function(x,y,width,height)
    {
       
    },
    hideLoginForm : function()
    {
        this.formlogin.hide();
    },
    showLoginForm : function(x,y,width,height)
    {   
        
        this.formlogin.show();
    },
    showNewUserForm : function()
    {
        this.formNewUser.show();
    },
    createBlokeer : function()
    {
        this.blockdiv = Ext.get(document.createElement('div'));
        this.blockdiv.dom.style.width = Ext.getBody().getWidth() + "px";
        this.blockdiv.dom.style.height =   "2000px";
        this.blockdiv.dom.style.position = "absolute";
        this.blockdiv.dom.style.top=0;
        this.blockdiv.dom.style.left=0;
        this.blockdiv.dom.style.backgroundColor = "gray";
        var val=4;
        this.blockdiv.dom.style.MozOpacity = val;
        this.blockdiv.dom.style.opacity = val/10;
        this.blockdiv.dom.style.filter = 'alpha(opacity=' + val*10 + ')';
        this.blockdiv.appendTo(Ext.getBody());
        this.blockdiv.dom.style.display="none";
        this.blockdiv.dom.style.zIndex =10000;
    },
    BlookScreen : function()
    {
        if(!this.blockdiv)
        {
            this.createBlokeer();
            this.blockdiv.dom.style.display="block";
        }
        else
        {
            this.blockdiv.dom.style.display="block";
        }
        
    },
    unBlookScreen : function()
    {
        if(this.blockdiv)
            this.blockdiv.dom.style.display="none";
    },
    noScroll : function(evt)
    {
        evt.preventDefault();
        return false;
    },
    CreateBtn : function(width,text)
    {
        var btn = Ext.get(document.createElement('div'));
        btn.dom.className = "x-form-btn";
        btn.dom.style.width = width + "px";
        
        var div = Ext.get(document.createElement('div'));
        div.dom.className = "right";
        div.appendTo(btn);
        
        var div = Ext.get(document.createElement('div'));
        div.dom.className = "middel";
        div.dom.style.width = width - 6 + "px";
        div.dom.innerHTML = text;
        div.appendTo(btn);
        
        var div = Ext.get(document.createElement('div'));
        div.dom.className = "left";
        div.appendTo(btn);
        
        return btn;
    },
    is_valid_email : function(email)
    {
        return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);    
    },
    reSendPassword : function()
    {
        // marker
        Ext.Ajax.request({
            url :hosturl + this.sendPasswordUrl,
            success : function(ans){
                var rez = eval(ans.responseText);
                if(rez[0]== false)
                {
                    
                    alert(rez[1]);
                }
                else
                {
                    alert('קוד אימות חדש נשלח לכתובת הדואר.');
                }
                
            },
            failure :function(){alert('חיבור לשרת נכשל אנא בדוק את חיבור האינטרנט');},
            params :{email:this.formlogin.getVal("email")},
            scope : this
        });
        
    },
    doLogin : function(cookie , _email , _pass)
    {   
        var loginurl;
        var loginparams;
        if(cookie == true)
        {
            this.doCookieLogin = true;
            loginurl = this.loginurl;
            loginparams = {email : _email, pass: _pass };
        }
        else
        {
            this.doCookieLogin = false;
            loginurl = this.loginurl;
            loginparams = {email : _email, pass: _pass  };
            
        }
        
        
        try
        {
        Ext.Ajax.request({
            url :hosturl + loginurl,
            success : this.onLoginComplete,
            failure :function(){this.onLoginComplete('[false]');},
            params :loginparams,
            scope : this
        });
        }
        catch(e){this.onLoginComplete('[false]');}
    },
    onLoginComplete : function(ans)
    {   
        var rez;
        if(ans.responseText)
             rez = eval(ans.responseText);
        else
            rez = eval(ans);
            
        if(rez[0] == false )
        {
            
            this.cm.Write("",0);
            this.updateUserDetail = null;
            this.CurrentUser = null;
            this.isLogin = false;
            this.loginChange('guest',null);
            if(this.doCookieLogin == false)
            {
                alert('כתובת מייל או סיסמא שגויים');
            }
            
        }
        else
        {
            
            this.loginChange('user',rez[3]);
            
            if(this.doCookieLogin == false)
            {
                if(this.formlogin.getVal('remember'))
                    this.cm.Write(rez[0] + "|" + rez[2] ,3);
                else
                    this.cm.Write("",0);
                
            }
            else
            {
                if(rez[0] != 'zazimLoginBySessionId')
                    this.cm.Write(rez[0] + "|" + rez[2] ,3);
            }
            this.UserName = rez[1];
            this.updateUserDetail = rez[3];
            this.CurrentUser = rez[3];
            this.isLogin = true;
            //this.showUserTopMenu(rez[1]);
            
            if(this.doCookieLogin == false)
            {
                this.hideLoginForm();
            }
        }
    },
    
    onLoginError : function(err)
    {
        alert('חיבור לשרת ניכשל  \n אנא נסה שוב מאוחר יותר');
    },
    CreateNewUserForm : function(x,y,width,height)
    {
        return;
    },
    replaceCap : function()
    {
        if(!this.capcount)
        {
            this.capcount =0;
        }
        Ext.fly('capImg').dom.src =hosturl+ "security/JpegImage.aspx?cap=" + this.capcount;
        this.capcount++;
    },
    updateUserFormData : function(evt,src,c)
    {   
        
        var trg;
        var num =0;
        if(src.id.indexOf('update_user') == -1)
        {
          trg=this.newUserDetail;
          num=9;
        }
        else
        {
            trg=this.updateUserDetail;
            num=12;
        }
        if(src.type == "checkbox")
        {
            trg[src.id.substr(num)] =src.checked;
        }
        else
        {
               trg[src.id.substr(num)] =src.value;
        }
    },
    CreateUpdateUserForm : function(x,y,width,height)
    {
        
        /* new user form */
        if(!this.updateUserForm)
        {
            this.updateUserForm = new createForm({width:310,height:305,blockScreen:true,closebtn:true,title:'עדכון פרטים',analyticsname:'update_user'});
            this.updateUserForm.parent = this;
            this.updateUserForm.is_valid_email = function(email)
            {
                return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);    
            };
            this.updateUserForm.submit = function()
            {
                var data = this.getFormValsObj();
                var msg="";
                if(data.fname == "") {if(msg!="") msg+="\n"; msg+="חובה להזין שם"; }
                if(data.lname == "") {if(msg!="") msg+="\n"; msg+="חובה להזין שם משפחה"; }
                if(data.email == "") {if(msg!="") msg+="\n"; msg+="חובה להזין דואר אלקטרוני"; }
                if(data.cap == "") {if(msg!="") msg+="\n"; msg+="חובה להזין את המילה בתמונה"; }
                if(data.prefix == "") {if(msg!="") msg+="\n"; msg+="חובה לבחור קידומת"; }
                if(data.phone == "") {if(msg!="") msg+="\n"; msg+="חובה להזין מספר טלפון"; }
                if(msg != "")
                {
                    alert(msg);
                    return;
                }
                if(data.password != data.passwordApprov){ if(msg!="") msg+="\n"; msg+="אין התאמה בין הסיסמאות";}
                if( data.phone.length != 7 || isNaN(parseFloat(data.phone)) )
                { 
                    if(msg!="") msg+="\n"; 
                    msg+="מספר הטלפון שהוזן אינו חוקי";
                }
                if(data.password != "")
                    if(data.password.length <5){if(msg!="") msg+="\n"; msg+="הסיסמא צריכה להיות בת 5 תוים לפחות";}
                if(!this.is_valid_email(data.email)){if(msg!="") msg+="\n"; msg+="כתובת המייל שהוזנה אינה חוקית";}
                
                if(msg != "")
                {
                    alert(msg);
                    return;
                }
                this.hide();
                this.parent.updateUser();
                
            };
            this.updateUserForm.addDiv({text:'*שם:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'text',name:'fname',style:'login-txt',width:170});
            this.updateUserForm.addDiv({text:'*שם משפחה:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'text',name:'lname',style:'login-txt',width:170});
            this.updateUserForm.addDiv({text:'חברה:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'text',name:'company',style:'login-txt',width:170});
            this.updateUserForm.addDiv({text:'*טלפון נייד:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'text',name:'phone',style:'login-txt',width:110});
            this.updateUserForm.addField({type:'select',name:'prefix',style:'login-txt',width:65,value:':בחר|050|052|054|057',dvalue:''});
            this.updateUserForm.addDiv({text:'*דואר אלקטרוני:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'text',name:'email',style:'login-txt',width:170});
            this.updateUserForm.addDiv({text:'*סיסמא:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'pass',name:'password',style:'login-txt',width:170});
            this.updateUserForm.addDiv({text:'*אימות סיסמא:',style:'login-txt',width:85});
            this.updateUserForm.addField({type:'pass',name:'passwordApprov',style:'login-txt',width:170});
            this.updateUserForm.addField({type:'chk',name:'allow_email',style:'new-user-i-agree',width:270,text:'מעוניין לקבל דיוורים ופרסומים מהאתר'});
            
            // marker
            this.updateUserForm.addDiv({text:'',style:'login-txt',width:105});
            this.updateUserForm.addBtn({name:'update',width:163,text:'עדכן',style:'new-user-btn'}).on('click',this.updateUserForm.submit,this.updateUserForm);
            this.updateUserForm.addDiv({text:'',style:'login-txt',width:105});
            this.updateUserForm.addBtn({name:'sms',width:163,text:'SMS אפשר קבלת',style:'new-user-btn'});
            /* add ff changes */
            if(!Ext.isIE)
            {   
                this.updateUserForm.fieldArray.prefix.dom.style.marginRight = "-10px";
                this.updateUserForm.btnArray.update.dom.style.marginRight = "-10px";
                this.updateUserForm.btnArray.sms.dom.style.marginRight = "-10px";
            }
        }
        
        
    },
    allowSms : function()
    {
        if(this.updateUserDetail.sms == 0)
        {
           this.hideUpdateUserForm();
           // add new code to create and show sms screen !!!!!
           /*
           smarta.editForm.testMobailNumber(null,{checked:true});
           */
           
            smsm.replaceCap();
            smsm.smsApproveForm.setFormVals();
            smsm.smsApproveForm.show();
        }
        else if(this.updateUserDetail.sms == 2)
        {
            this.hideUpdateUserForm();
            Ext.Ajax.request({
                   url:hosturl + 'sms/reAllowSms.aspx?',
                   success: function (conn, response, options){
                                var ans = eval(conn.responseText);
                                if(ans[0] == true)
                                {
                                    this.updateUserDetail.sms = 1;
                                    this.CurrentUser.sms = 1;
                                    alert('חודש משלוח הודעות SMS');
                                    
                                }
                                else
                                {
                                    alert(ans[1]);
                                }
                                
                            },
                   failure: function (conn, response, options) {alert('כישלון בחיבור לשרת בדוק את תקינות חיבור האינטרנט'); this.hideScreenBloker();
                   },
                   
                   scope : this
                   
                });
            
        }
        
        
    },
    disallowSms : function()
    {
        this.hideUpdateUserForm();
            Ext.Ajax.request({
                   url:hosturl + 'sms/disAllowSms.aspx?',
                   success: function (conn, response, options){
                                var ans = eval(conn.responseText);
                                if(ans[0] == true)
                                {
                                    this.updateUserDetail.sms = 2;
                                    this.CurrentUser.sms = 2;
                                    alert('הודעות SMS מושהות');
                                }
                                else
                                {
                                    alert(ans[1]);
                                }
                                
                            },
                   failure: function (conn, response, options) {alert('כישלון בחיבור לשרת בדוק את תקינות חיבור האינטרנט'); this.hideScreenBloker();
                   },
                   
                   scope : this
                   
                });
    },
    showUpdateUserForm : function()
    {
        //debugger;
        if(!this.updateUserForm)
            this.CreateUpdateUserForm(0,0);
            
        this.updateUserForm.show();
        
        var vals ="phone("+this.updateUserDetail.phone+")";
        vals+="|prefix("+this.updateUserDetail.prefix+")";
        vals+="|fname("+this.updateUserDetail.fname+")";
        vals+="|lname("+this.updateUserDetail.lname+")";
        vals+="|company("+this.updateUserDetail.company+")";
        vals+="|email("+this.updateUserDetail.email+")";
        vals+="|allow_email("+this.updateUserDetail.allow_email+")";
        
        this.updateUserForm.setFormValsFromString(vals,true);
        
        /* set btn for sms change */
        
        
        
        if(this.updateUserDetail.sms == 0 || this.updateUserDetail.sms == 2)
        {
            this.updateUserForm.btnArray.sms.dom.innerHTML = this.updateUserForm.btnArray.sms.dom.innerHTML.replace(/השהה/,"אפשר");
            this.updateUserForm.btnArray.sms.removeAllListeners();
            this.updateUserForm.btnArray.sms.on('click',this.allowSms,this);
            
        }
        else if(this.updateUserDetail.sms == 1)
        {
            this.updateUserForm.btnArray.sms.dom.innerHTML = this.updateUserForm.btnArray.sms.dom.innerHTML.replace(/אפשר/,"השהה");
            this.updateUserForm.btnArray.sms.removeAllListeners();
            this.updateUserForm.btnArray.sms.on('click',this.disallowSms,this);
        }
    },
    hideUpdateUserForm : function()
    {
        this.updateUserForm.hide();
    },
    addNewUser : function()
    {   
        Ext.Ajax.request({
            url :hosturl + this.newUserUrl,
            success : this.newUserAns,
            failure :function(){alert('שגיאה בחיבור לשרת אנא בדוק את תקינות החיבור האינטרנט');},
            params :{data:this.formNewUser.getFormVals()},
            scope : this
        });
    },
    newUserAns : function(conn, response, options)
    {
        var ans =  eval(conn.responseText);
        //this.newUserForm.dom.style.zIndex = 10001;
        if (ans[0] == true)
        {
            var msg="נתוני המשתמש נשמרו בהצלחה\n";
            msg+="קוד אימות נשלח לכתובת הדואר\n";
            msg+="בכניסה ראשונה לאתר יש להקיש את קוד האימות במקום הסיסמא\n";
            alert(msg);
        }
        else
        {   
            alert(ans[1]);
        }
    },
    updateUser : function()
    {   
        this.updateUserForm.form.dom.style.zIndex = 10000;
        
        Ext.Ajax.request({
            url :hosturl + this.updateUserUrl,
            success : function(a,b,c)
            {
                this.updateUserForm.form.dom.style.zIndex = 10003;
                var rez = eval(a.responseText);
                if(rez[0]== 1) // password no match
                {
                    alert(rez[1]);
                }
                else if(rez[0]== 2) // no user found
                {
                    this.cm.Write("" + "|" + "" ,0);
                    //this.CurrentUser = null;
                    
                    //this.showGuestTopMenu();
                    this.hideUpdateUserForm();
                    this.doLogOff();
                    alert(rez[1]);
                }
                else if(rez[0]== 3) //  new email address mail sent
                {
                    this.cm.Write("" + "|" + "" ,0);
                    //this.CurrentUser = null;
                    
                    //this.showGuestTopMenu();
                    this.hideUpdateUserForm();
                    this.doLogOff();
                    alert(rez[1]);
                    
                }
                else if(rez[0]== 4) // new email addres mail not sent
                {
                    this.cm.Write("" + "|" + "" ,0);
                    //this.CurrentUser = this.updateUserDetail;
                    this.doLogOff();
                    alert(rez[1]);
                    
                }
                else if(rez[0]== 5)
                {
                    //this.cm.Write(rez[0] + "|" + rez[2] ,3);
                    this.UserName = this.updateUserDetail.fname;
                    this.CurrentUser = rez[2];
                    this.updateUserDetail = rez[2];
                    this.isLogin = true;
                    this.loginChange('user',rez[2]);
                    this.hideUpdateUserForm();
                    alert("פרטיך עודכנו בהצלחה");
                }   
                
            },
            failure :function(){alert('שגיאה בחיבור לשרת אנא בדוק את תקינות החיבור האינטרנט');},
            params :{data:this.updateUserForm.getFormVals()},
            scope : this
        });
        
    },
    /* function to ovveride by all screens using login file
       will recive user type and user detail if user is logged in
       all changes to screen and other modules should be made from this function only!!!
       no changes will be made by the login type to any other module nor data will be sent.
    */
    loginChange : function(type,user)
    {
        //debugger;
        if(type == 'user' && user != null )
        {   
            showUserTopMenu(user.fname);
            smsm.smsApproveForm.setDvalue('phone',user.phone);
            smsm.smsApproveForm.setDvalue('prefix',user.prefix);
            
        }
        else if(type == 'guest' && user == null)
        {
            showGuestTopMenu();
            smsm.smsApproveForm.setDvalue('phone','');
            smsm.smsApproveForm.setDvalue('prefix','');
        }
        try
        {
            
            loginChange(type,user);
            
            // save username and password
        }
        catch(ex)
        {
        }
    }
    
}
