﻿//Login functionality and validation of login dialogs

    //CHECK FOR IE6
    function is_ie6()
    {
        // return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
        
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1)
        {
            // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        }
        //return version;
        if (version < 7)
        {
            // if client is using IE6 or lower, run this code
            return true;
        }
        return false;
        
    }

    //Get query string parameters
    function getQueryParam(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else 
            return results[1]; 
    }

 function getTrimmedValue(fieldname)
    {
    var str = document.getElementById(fieldname).value;

    str = str.replace(/\s+/g,'');

    document.getElementById(fieldname).value = str;
    
     return str;
    }
    
    function onkeyupLogin(e)
    {    
        if (!e) 
            {var e = window.event;}           
        
        if(IsBackWardsInput(e))
        {
        }
        else
        {
            isValidLogin(e,getTrimmedValue('usernameinput'), getTrimmedValue('passwordinput'));
        }   
            
    }
    
    function isIE()
    {
        return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
    }
    
    
    function IsBackWardsInput(e)
    {
         var _keyCode;        
        
        var targ;
        if (e.target) targ = e.target;
	    else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
        
        if(isIE())
        {
            //do not do any validation for these keycodes    
            //35 , 36  , 37  , 39
                        
            var keycode;
            if (window.event) keycode = window.event.keyCode;
            else if (e) keycode = e.which;           
            _keyCode = keycode;
                        
            
            //9 && true --> backtab
            if(_keyCode == 9)// && e.shiftKey)
            {
                doSetCaretPositionLast(targ.id);
            }
                                    
            if(_keyCode == 35 || _keyCode == 36 || _keyCode == 37 || _keyCode == 39)
            {
                return true;
            }
            else
            {
                return false;
            } 
            
        }
        else
        {
           //do not do any validation for these keycodes    
           //end  	35 , home 	36 , up arrow  38   , down arrow    40  
           
           _keyCode = e.keyCode;    
                //9 && true --> backtab
           if(_keyCode == 9)// && e.shiftKey)
           {           
               doSetCaretPositionLast(targ.id);
           }
                              
           if(_keyCode == 35 || _keyCode == 36 || _keyCode == 38 || _keyCode == 40)
           {
              return true;
           }
           else
           {
               return false;
           }   
        }    
    }
    
    
    
   /*
   **  Sets the caret (cursor) position of the specified text field.
   **  Valid positions are 0-oField.length.
   */
   function doSetCaretPositionLast (field) {
    
    var oField = document.getElementById(field);
     // IE Support
     if (document.selection) { 

       // Set focus on the element
       oField.focus ();
  
       // Create empty selection range
       var oSel = document.selection.createRange ();
  
       // Move selection start and end to 0 position
       oSel.moveStart ('character', -oField.value.length);
  
       // Move selection start and end to desired position
       oSel.moveStart ('character', oField.value.length);
       oSel.moveEnd ('character', oField.value.length);
       oSel.select ();
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0') {
       oField.selectionStart = oField.value.length;
       oField.selectionEnd = oField.value.length;
       oField.focus ();
     }
   }

   function checkCharValid(inputstring) //valid for SAP password module
   {
       var legalChars = "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
       var thisChar;
       var counter = 0;
       for (var i = 0; i < inputstring.length; i++) {
           thisChar = inputstring.substring(i, i + 1);
           if (legalChars.indexOf(thisChar) >= 0) {
               counter++;
           }
       }
       if (counter == (inputstring.length)) {
           return true;
       }
       else {
           return false;
       }
   }

    
    
      
       function onkeyupSetEmail(e)
    {  
    if (!e) 
    {var e = window.event;}
    setEmail();
      }
      
       function onkeyupRegistrationStep1(e)
    {  
    if (!e) 
         {var e = window.event;}
         
         if(IsBackWardsInput(e))
         {
         }
         else
         {         
            isValidRegistrationStep1(getTrimmedValue('customernumberinput'),getTrimmedValue('pincodeinput'));
         }
      }
      
       function onkeyupRegistrationStep2(e)
    {  
    if (!e) 
    {var e = window.event;}
        if(IsBackWardsInput(e))
        {
        }
        else
        {  
            isValidRegistrationStep2(getTrimmedValue('newusernameinput'),getTrimmedValue('newpasswordinput'),getTrimmedValue('confirmpasswordinput'),getTrimmedValue('emailinput'));
        }
      }
  
    function onkeyupPasswordRecovery(e)
    {  
    if (!e) 
    {var e = window.event;}
    isValidEmailRecovery(getTrimmedValue('forgottenpasswordemailinput'));
      }
      
      function isNumeric(num){ 
    return !isNaN(num) 
} 
           

    
    function checkUsername (usernameinput, isRegistration) {
         var error = "";
          var username="";  
            
           username = usernameinput;
             
             if(isRegistration==false || username.length >0)
             {
                 if (username == "" && isRegistration == false) {
                    error = errorTextUserName1;  //"Användarnamn: Får inte vara tomt.\n";
                     }
                 
                 if ((username.length < 4) || (username.length > 31)) {
                    error = errorTextUserName2;//"Användarnamn: Minst 4 tecken.\n";
                    }
             }            
            
            if (username.length == 8 && isRegistration == true && isNumeric(username) == true && (username.substring(0,1) =='1' || 
            username.substring(0,1) =='2')) {
            error = errorTextUserName3; //"Användarnamn: Får ej likna ett kundnummer.\n";
            }

        var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/               
           ///\W/; // allow only letters, numbers, and underscores
            if (illegalChars.test(username)) {
               error = errorTextUserName4; //"Användarnamn: Ogiltligt tecken.\n";
            }           
           
            if (error=="")
            {           
                return true;
            }
            else 
            {
               if(isRegistration){
                document.getElementById(errorRegistration2SpanId).innerHTML = error;}
                else
                {document.getElementById(errorSpanId).innerHTML = error;}
               return false;
            }                  
        }
        
        function checkConfirmPassword(passwordinput1, passwordinput2)
        {
        var error = "";   
                  
            if (passwordinput1 != passwordinput2) {
                error = errorTextPassword1;//"Lösenord: Bekräfta lösenordet igen.\n";
            }
            
          if (error=="")
            {      
                return true;
            }
            else 
            {
                document.getElementById(errorRegistration2SpanId).innerHTML = error;
               return false;
            }                       
        }
        
    
    function checkPassword (passwordinput, isRegistration) {
        var error = "";   
        var password="";
          
               password=passwordinput;  
           
            if (password == "") {
                error = errorTextPassword2; //"Lösenord: Får inte vara tomt.\n";
            }
                    
         
            
            if ((password.length < 6) || (password.length > 8)) {
            error = errorTextPassword3; //"Lösenord: Minst 6 tecken.\n";
            }     
            
            else if (!(((password.search(/[a-z]+/) > -1)
              || (password.search(/[A-Z]+/) > -1))
              && (password.search(/[0-9]+/) > -1))) {
              error = errorTextPassword4; //"Lösenord: Minst en bokstav och minst en siffra.\n";
          }


          if (!checkCharValid(password)) {
              error = errorTextPassword5; //Lösenord ogiltligt tecken.
          }
                           
                 
             if (error=="")
            {      
                return true;
            }
            else 
            {
                if(isRegistration){
                document.getElementById(errorRegistration2SpanId).innerHTML = error;}
                else
                {document.getElementById(errorSpanId).innerHTML = error;}
               
               return false;
            }                               
        }
        
        function isValidLogin(e,username, password)
        {       
        var isValidUserName = false;
        var isValidPassword = false;
        if(checkUsername(username,false))
        {   isValidUserName=true;
            if(checkPassword(password,false))
            {
            isValidPassword=true;
            }
        }        
        
            if(isValidUserName && isValidPassword)
            {
             document.getElementById(errorSpanId).className='hidden';
             document.getElementById(loginButtonId).disabled=false;
            }         
            else
            {
             document.getElementById(errorSpanId).className='error';
              document.getElementById(loginButtonId).disabled=true;             
            }  
        }
        
        function echeck(str) 
        {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){		    
		    return false
		 }

 		 return true					
	}
	
	
	
function emailCheck2 (emailStr) {
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. 

alert("Email address seems incorrect (check @ and .'s)");*/
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

//if (checkTLD && domArr[domArr.length-1].length!=2 && 
//domArr[domArr.length-1].search(knownDomsPat)==-1) {
////alert("The address must end in a well-known domain or two letter " + "country.");
//return false;
//}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

      
        
        function checkEmail(emailinput)
        {
         var error = "";   
          var inputstring="";
          
          inputstring=emailinput; 
        
            var emailFilter=/^.+@.+\..{2,3}$/;            

            if (!(emailFilter.test(inputstring))) { 
                   error = errorTextEmail1; //"Email: Ogiltig adress.\n";
            }            
            
            if(!echeck(emailinput))
            {
             error = errorTextEmail1; //"Email: Ogiltig adress.\n";
            }
            
             if(!emailCheck2(emailinput))
            {
             error = errorTextEmail1; //"Email: Ogiltig adress.\n";
            }                           
            
            var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
            if (inputstring.match(illegalChars)) {
               error = errorTextEmail2; //"Email: Adressen innehåller otillåtna tecken.\n";
                }   
                
                if (error=="")
                {      
                    return true;
                }
                else 
                {
                    document.getElementById(errorRegistration2SpanId).innerHTML = error;
                   return false;
                }                  
        }
        
        function checkCustomerNumber(customernumberinput)
        {
                var error = "";   
                var inputstring="";
          
               inputstring=customernumberinput;  
           
            if (inputstring == "") {
                error = errorTextBusinessPartner1; //"Kundnummer: Får inte vara tomt.\n";
            }
            
             if (inputstring.length != 8 && (inputstring.substring(0,1) !='1' || 
            inputstring.substring(0,1) !='2')) {
            error = errorTextBusinessPartner2; //"Kundnummer: 8 siffror.\n";
            }                       
            
            if (error=="")
            {      
                return true;
            }
            else 
            {
                document.getElementById(errorRegistration1SpanId).innerHTML = error;
               return false;
            }              
        }
        
        function checkPincode(pincodeinput)
        {
               var error = "";   
                var inputstring="";
          
               inputstring=pincodeinput;  
           
            if (inputstring == "") {
                error = errorTextPinCode1; //"Pinkod: Får inte vara tomt.\n";
            }
            
            if ((inputstring.length < 4) || (inputstring.length > 4)) {
            error = errorTextPinCode2; //"Pinkod: 4 siffror.\n";
            } 
            
            if (error=="")
            {      
                return true;
            }
            else 
            {
                document.getElementById(errorRegistration1SpanId).innerHTML = error;
               return false;
            }           
        }    
        
        function isValidRegistrationStep1 (customernumber, pincode)
        {
        var isValidCustomerNumber = false;
        var isValidPinCode = false;
        
        if(checkCustomerNumber(customernumber))
        {   isValidCustomerNumber=true;
            if(checkPincode(pincode))
            {                
                isValidPinCode=true;                         
            }
        }        
        
            if(isValidCustomerNumber && isValidPinCode)
            {
             document.getElementById(errorRegistration1SpanId).className='hidden';
             document.getElementById(registrationStep1ButtonId).disabled=false;
            }         
            else
            {
             document.getElementById(errorRegistration1SpanId).className='error';  
              document.getElementById(registrationStep1ButtonId).disabled=true;           
            }           
        }
        
        function isValidRegistrationStep2 (username, password1, password2, email)
        {
        var isValidUserName = false;
        var isValidPassword = false;
        var isValidEmail = false;        
        
        if(checkUsername(username,true))
        {   isValidUserName=true;
            if(checkPassword(password1,true))
            {
                if (checkConfirmPassword(password1,password2))
                     {
                         isValidPassword=true;
                         if (checkEmail(email))
                         {isValidEmail=true;}                     
                     }
            }
        }        
        
            if(isValidUserName && isValidPassword && isValidEmail)
            {
             document.getElementById(errorRegistration2SpanId).className='hidden';
             document.getElementById(registrationStep2ButtonId).disabled=false;
            }         
            else
            {
             document.getElementById(errorRegistration2SpanId).className='error';   
              document.getElementById(registrationStep2ButtonId).disabled=true;          
            }          
        }
        
        function isValidEmailRecovery (inputstring)
        {        
          var error = "";
          var username="";  
            
           username = inputstring;
             
         if (username == "" && isRegistration == false) {
            error = errorTextEmailRecovery1; // "Användarnamn/Kundnummer: Får inte vara tomt.\n";
             }
         
         if ((username.length < 4) || (username.length > 30)) {
            error = errorTextEmailRecovery2; //"Användarnamn/Kundnummer: Minst 4 tecken.\n";
            }  

        var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/ 
          // allow only letters, numbers, and underscores
            if (illegalChars.test(username)) {
               error = errorTextEmailRecovery3; //"Användarnamn/Kundnummer: Ogiltligt tecken.\n";
            }           
           
            if (error=="")
            {           
             document.getElementById(errorPasswordRecoverySpanId).className='hidden';
             document.getElementById(passwordRecoveryButtonId).disabled=false;
            }
            else 
            {
               document.getElementById(errorPasswordRecoverySpanId).innerHTML = error;
               document.getElementById(errorPasswordRecoverySpanId).className='error';
               document.getElementById(passwordRecoveryButtonId).disabled=true;
            } 
        }
        
        function setEmail()
        {       
        // get the current URL         
        var url = window.location.toString(); 
        //get the parameters 
        url.match(/\?(.+)$/); 
        var params = RegExp.$1; 
        // split up the query string and store in an 
        // associative array 
        var params = params.split("&"); 
        var queryStringList = {};  for(var i=0;i<params.length;i++) {     
        var tmp = params[i].split("=");     
        queryStringList[tmp[0]] = unescape(tmp[1]); }  
        // print all querystring in key value pairs 
        for(var i in queryStringList)     
            {
                if (i=='email' && document.getElementById('emailinput').value == "")
                {
                document.getElementById('emailinput').value=queryStringList[i];
                }            
            }
        }


        $(document).ready(function() {
     
        //login dialog
        $("#loginDialog").dialog({ bgiframe: true, title: '', show: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 start', modal: true, resizable: false, draggable: true });
        //register dialog
        $("#registerDialog").dialog({ bgiframe: true, title: '', show: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 start', modal: true, resizable: false, draggable: true });
        //register email and password dialog
        $("#registerEmailDialog").dialog({ bgiframe: true, title: '', show: 'slide', hide: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 start', modal: true, resizable: false, draggable: true });
        //register error dialog
        $("#registerErrorDialog").dialog({ bgiframe: true, title: '', show: 'slide', hide: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 errorlogin', modal: true, resizable: false, draggable: true });
        //password recovery dialog
        $("#passwordRecoveryDialog").dialog({ bgiframe: true, title: '', show: 'slide', hide: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 forgottpassord', modal: true, resizable: false, draggable: true });
        //password recovery error dialog
        $("#IE6LoginDialog").dialog({ bgiframe: true, title: '', show: 'slide', hide: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474 ie6login', modal: true, resizable: false, draggable: true });
        $("#servicewindowDialog").dialog({ bgiframe: true, title: '', show: 'slide', hide: 'slide', autoOpen: false, width: 474, dialogClass: 'jqueryDialog474', modal: true, resizable: false, draggable: true });
     
       $("#mCloseIE6LoginInput").click(function() {
      
           $('#IE6LoginDialog').dialog("close");
           $("#loginDialog").dialog("open"); 
       });
       
       $("#mCloseServiceWindowLoginInput").click(function() {
      
           $('#servicewindowDialog').dialog("close");
       });
       

        if (getQueryParam("login") != "" || getQueryParam("loginerror") != "")
        {
            if (getQueryParam("servicewindowstart") != "" && getQueryParam("servicewindowend") != "")
            {            
                $("#servicewindowDialog").dialog("open");  
            }
            else
            {
                if(is_ie6())
                {                           
                    $("#IE6LoginDialog").dialog("open");                                                 
                }
                else
                {
                    $("#loginDialog").dialog("open");
                }
            }
        }

        if (getQueryParam("register") != "" && getQueryParam("registererror") == "") {
            $("#registerDialog").dialog("open");
        }
         else if (getQueryParam("registererror") != "" && getQueryParam("usernameerror")!="") {
           document.getElementById(errorRegistration2SpanId).innerHTML = errorTextUsernameUnavailable;
               document.getElementById(errorRegistration2SpanId).className='error';   
              document.getElementById(registrationStep2ButtonId).disabled=true; 
            $("#registerEmailDialog").dialog("open");
        }
        else if (getQueryParam("registererror") != "" && getQueryParam("usernameerror")=="") {
            $("#registerErrorDialog").dialog("open");
        }

        if (getQueryParam("registeremail") != "") {
            setEmail();
            $("#registerEmailDialog").dialog("open");           
        }
        
         if (getQueryParam("passwordrecoveryerror") != "") {         
               document.getElementById(errorPasswordRecoverySpanId).innerHTML = errorTextEmailRecoveryUser;
               document.getElementById(errorPasswordRecoverySpanId).className = 'error';
            $("#passwordRecoveryDialog").dialog("open");
        }

     

        $("#mRegisterInput").click(function() {
            $("#registerDialog").dialog("open");
            $('#loginDialog').dialog("close");
        });

        $("#mRegisterLink").click(function() {
            $("#registerDialog").dialog("open");
            $('#loginDialog').dialog("close");
        });

        $("#mRegisterBackInput").click(function() {
            $('#loginDialog').dialog("open");
            $("#registerDialog").dialog("close");
        });

        $("#mTryAgainInput").click(function() {
            $("#registerDialog").dialog("open");
            $("#registerErrorDialog").dialog("close");
        });

        $("#mForgottenPassword").click(function() {
            $("#passwordRecoveryDialog").dialog("open");
            $('#loginDialog').dialog("close");
        });             
    });


    var loginButtonId;
    var errorSpanId;
    var errorRegistration1SpanId;
    var errorRegistration2SpanId;
    var errorPasswordRecoverySpanId;
    var errorTextId1;

    var registrationStep1ButtonId;
    var registrationStep2ButtonId;
    var passwordRecoveryButtonId;

    var errorTextUserName1;
    var errorTextUserName2;
    var errorTextUserName3;
    var errorTextUserName4;
    var errorTextPassword1;
    var errorTextPassword2;
    var errorTextPassword3;
    var errorTextPassword4;
    var errorTextPassword5;
    var errorTextEmail1;
    var errorTextEmail2;
    var errorTextEmail3;
    var errorTextBusinessPartner1;
    var errorTextBusinessPartner2;
    var errorTextBusinessPartner3;
    var errorTextPinCode1;
    var errorTextEmailRecovery1;
    var errorTextEmailRecovery2;
    var errorTextEmailRecovery3;

    var errorTextEmailRecoveryUser;
    var errorTextUsernameUnavailable;

    var emailRegex;

   

    function loginEnterClick(e, buttonid) {
        if (e.keyCode == 13) {
            document.getElementById(buttonid).click();
        }
    }



   
