/*
Foundation.MicroLogin
Copyright © 2005-2010 Scott Nesin, all rights reserved.
Documentation: http://FoundationDotJS.org/Foundation.MicroLogin.htm
*/
/*
   ***** Preprocessed code, any modifications will be lost. *****
     Foundation.js, object oriented JavaScript framework:
     http://FoundationDotJS.org/
     Preprocessed for speed:
     http://FoundationDotJS.org/Foundation.Preprocessor.htm
*/
Foundation.MicroLogin=function()
{
   Foundation.FloatControl.apply(this,arguments);
   this.loggedIn=this.resource("loggedIn");
   this.userId=this.resource("userId");
   this.password=this.resource("password");
   this.rememberPassword=this.resource("rememberPassword");
   this.submitInProgress=false;
   this.submitClicked=false;
   this.sendPasswordClicked=false;
};
Foundation.MicroLogin.$parentClass=Foundation.FloatControl;
if (!Foundation.FloatControl.$childClasses) Foundation.FloatControl.$childClasses=new Array();
Foundation.FloatControl.$childClasses.push(Foundation.MicroLogin);
Foundation.MicroLogin.$constructor=Foundation.FloatControl.$constructor ? Foundation.FloatControl.$constructor : function(){};
Foundation.MicroLogin.$interfaces=new Array();
Foundation.MicroLogin.$name="MicroLogin";
Foundation.MicroLogin.$childClasses=new Array();
Foundation.MicroLogin.$container=Foundation;
Foundation.MicroLogin.prototype={
   constructor:Foundation.MicroLogin,   
   canShowFloat:function()
   {
      return !this.getLoggedIn() && Foundation.FloatControl.prototype.canShowFloat.call(this);
   },   
   getLoggedIn:function()
   {
      return this.loggedIn;
   },   
   setLoggedIn:function(loggedIn)
   {
      if (loggedIn!=this.loggedIn)
      {
         var oldValue=this.loggedIn;
         this.onLoggedInChanged(this.loggedIn=loggedIn,oldValue);
      }
   },   
   onLoggedInChanged:function(newValue,oldValue)
   {
      if (newValue)
         this.hideFloat();
   },   
   validateValue:function(value,valueType)
   {
      var validation=this.resource(valueType+"Validation");
      return validation ? validation.call(this,value) : true;
   },   
   getValidationStyle:function(value,valueType)
   {
      var validation;
      var style;
      if (value.length==0)
         style=this.resource(valueType+"EmptyStyle");
      else
         if (this.validateValue(value,valueType))
            style=this.resource(valueType+"ValidStyle");
         else
            style=this.resource(valueType+"InvalidStyle");
      if (style==null)
         style="";
      return style;
   },   
   getFloatHtml:function()
   {
      var rememberPasswordName=this.resource("rememberPasswordName");
      var sendPasswordName=this.resource("sendPasswordName");
      var action=this.resource("action");
      var method=this.resource("method");
      if (action=="Foundation.MicroLogin.action.htm")
         method="GET";
      this.submitClicked=false;
      this.sendPasswordClicked=false;
      return Foundation.FloatControl.prototype.getFloatHtml.call(this,'onSubmit',this.event("onSubmit(event)").htmlEncode()
                               ,'submitFrameOnLoadEvent',this.event("submitFrameOnLoadEvent(event)").htmlEncode()
                               ,'frameId',this.elementId("iframe")
                               ,'action',action.htmlEncode()
                               ,'method',method.htmlEncode()
                               ,'userIdId',this.elementId("userId")
                               ,'userIdName',this.resource("userIdName").htmlEncode()
                               ,'userIdTitle',this.resource("userIdTitle").htmlEncode()
                               ,'userIdValue',this.userId.htmlEncode()
                               ,'userIdStyle',this.getValidationStyle(this.userId,"userId").htmlEncode()
                               ,'userIdOnKeyUp',this.event("userIdOnKeyUp(event)")
                               ,'passwordId',this.elementId("password")
                               ,'passwordName',this.resource("passwordName").htmlEncode()
                               ,'passwordTitle',this.resource("passwordTitle").htmlEncode()
                               ,'passwordValue',this.password.htmlEncode()
                               ,'passwordStyle',this.getValidationStyle(this.password,"password").htmlEncode()
                               ,'passwordOnKeyUp',this.event("passwordOnKeyUp(event)")
                               ,'rememberPasswordDisplay',rememberPasswordName ? "table-row" : "none"
                               ,'rememberPasswordId',this.elementId("rememberPassword")
                               ,'rememberPasswordName',rememberPasswordName.htmlEncode()
                               ,'rememberPasswordTitle',this.resource("rememberPasswordTitle").htmlEncode()
                               ,'rememberPasswordValue',this.rememberPassword ? "checked" : ""
                               ,'submitId',this.elementId("submit")
                               ,'submitName',this.resource("submitName").htmlEncode()
                               ,'submitTitle',this.resource("submitTitle").htmlEncode()
                               ,'submitOnClick',this.event("submitOnClick(event)")
                               ,'sendPasswordDisplay',sendPasswordName ? "inline" : "none"
                               ,'sendPasswordId',this.elementId("sendPassword")
                               ,'sendPasswordName',sendPasswordName.htmlEncode()
                               ,'sendPasswordTitle',this.resource("sendPasswordTitle").htmlEncode()
                               ,'sendPasswordOnClick',this.event("sendPasswordOnClick(event)")
                               );
   },   
   focusToFloat:function(boundElement)
   {
      var u=this.getElement("userId");
      var p=this.getElement("password");
      if (u)
         if (u.value.trim().length>0 &&
             p && p.value.trim().length==0)
            p.focus();
         else
            u.focus();
   },   
   saveFloatData:function()
   {
      var e=this.getElement("userId");
      if (e)
         this.userId=e.value.trim();
      e=this.getElement("password");
      if (e)
         this.password=e.value;
      e=this.getElement("rememberPassword");
      if (e)
         this.rememberPassword=e.checked;
   },   
   userIdOnKeyUp:function(event)
   {
      var e=this.getElement("userId");
      if (e)
         e.style.cssText+=";"+this.getValidationStyle(e.value,"userId");
   },   
   passwordOnKeyUp:function(event)
   {
      var e=this.getElement("password");
      if (e)
         e.style.cssText+=";"+this.getValidationStyle(e.value,"password");
   },   
   onSubmitWarning:function(value,valueType)
   {
      var warning=null;
      if (value.length==0)
         warning=this.resource(valueType+"EmptyWarning");
      if (!warning &&
          !this.validateValue(value,valueType))
         warning=this.resource(valueType+"InvalidWarning");
      if (warning)
      {
         this.incrementFloatCount(event);
         alert(warning);
         this.decrementFloatCount(event);
         this.getElement(valueType).focus();
         return true;
      }
      return false;
   },   
   submitOnClick:function(event)
   {
      this.submitClicked=true;
      this.sendPasswordClicked=false;
   },   
   sendPasswordOnClick:function(event)
   {
      this.submitClicked=false;
      this.sendPasswordClicked=true;
   },   
   onSubmit:function(event)
   {
      this.saveFloatData();
      if (this.onSubmitWarning(this.userId,"userId") ||
          this.onSubmitWarning(this.password,"password"))
         return false;
      this.submitInProgress=true;
      if (event && event.ctrlKey && this.resource("canDebug"))
         this.getElement("iframe").style.display="block";
      return true;
   },   
   testResult:function(text,testType)
   {
      var test=this.resource(testType+"Expression");
      if (text.search(test)>=0)
      {
         var msg=this.resource(testType+"Message",'1',RegExp.$1);
         if (msg)
         {
            this.incrementFloatCount();
            alert(msg);
            this.decrementFloatCount();
         }
         this[testType]();
         return true;
      }
      return false;
   },   
   submitFrameOnLoadEvent:function(event)
   {
      if (this.submitInProgress)
      {
         this.submitInProgress=false;
         var body=this.getElement("iframe").contentWindow.document.body;
         var text=body.innerText || body.textContent;
         (this.testResult(text,"loginSuccess") ||
          this.testResult(text,"loginError") ||
          this.testResult(text,"sendPasswordSuccess") ||
          this.testResult(text,"sendPasswordError") ||
          this.testResult(text,"unknownResult"));
      }
   },   
   loginSuccess:function()
   {
      this.setLoggedIn(true);
   },   
   loginError:function()
   {
   },   
   sendPasswordSuccess:function()
   {
   },   
   sendPasswordError:function()
   {
   },   
   unknownResult:function()
   {
   },   
   getUserId:function()
   {
      var e=this.getElement("userId");
      return e ? e.value : null;
   },   
   setUserId:function(value)
   {
      this.userId=value;
      var e=this.getElement("userId");
      if (e)
      {
         e.value=value;
         this.userIdOnKeyUp(null);
      }
   },   
   getPassword:function()
   {
      var e=this.getElement("password");
      return e ? e.value : null;
   },   
   getRememberPassword:function()
   {
      var e=this.getElement("rememberPassword");
      return e ? e.checked : false;
   },
   dispose:function()
   {
      if (Foundation.FloatControl.prototype.dispose) Foundation.FloatControl.prototype.dispose.call(this);
   },
   resource:Foundation.FloatControl.prototype.resource,
   event:Foundation.FloatControl.prototype.event,
   elementId:Foundation.FloatControl.prototype.elementId,
   getElement:Foundation.FloatControl.prototype.getElement,
   getElementValue:Foundation.FloatControl.prototype.getElementValue,
   parseElementId:Foundation.FloatControl.prototype.parseElementId,
   attachEvent:Foundation.FloatControl.prototype.attachEvent,
   detachEvent:Foundation.FloatControl.prototype.detachEvent,
   bindToElement:Foundation.FloatControl.prototype.bindToElement,
   bindEvents:Foundation.FloatControl.prototype.bindEvents,
   unbindFromElement:Foundation.FloatControl.prototype.unbindFromElement,
   unbindEvents:Foundation.FloatControl.prototype.unbindEvents,
   getScriptSearchKeys:Foundation.FloatControl.prototype.getScriptSearchKeys,
   getResourceFolder:Foundation.FloatControl.prototype.getResourceFolder,
   getResourcePath:Foundation.FloatControl.prototype.getResourcePath,
   setValue:Foundation.FloatControl.prototype.setValue,
   compareValues:Foundation.FloatControl.prototype.compareValues,
   onValueChanged:Foundation.FloatControl.prototype.onValueChanged,
   getValue:Foundation.FloatControl.prototype.getValue,
   parseValue:Foundation.FloatControl.prototype.parseValue,
   getDisabled:Foundation.FloatControl.prototype.getDisabled,
   setDisabled:Foundation.FloatControl.prototype.setDisabled,
   onDisabledChanged:Foundation.FloatControl.prototype.onDisabledChanged,
   getInnerHtml:Foundation.FloatControl.prototype.getInnerHtml,
   getHtml:Foundation.FloatControl.prototype.getHtml,
   getActiveFloatBoundElement:Foundation.FloatControl.prototype.getActiveFloatBoundElement,
   bindFloatEvents:Foundation.FloatControl.prototype.bindFloatEvents,
   floatBoundOnFocus:Foundation.FloatControl.prototype.floatBoundOnFocus,
   floatBoundOnBlur:Foundation.FloatControl.prototype.floatBoundOnBlur,
   floatBoundOnKeyDown:Foundation.FloatControl.prototype.floatBoundOnKeyDown,
   getFloatActivationSelected:Foundation.FloatControl.prototype.getFloatActivationSelected,
   setFloatActivationSelected:Foundation.FloatControl.prototype.setFloatActivationSelected,
   floatActivationSelectedOnChange:Foundation.FloatControl.prototype.floatActivationSelectedOnChange,
   activateFloat:Foundation.FloatControl.prototype.activateFloat,
   getActivateFloatHtml:Foundation.FloatControl.prototype.getActivateFloatHtml,
   getFloatElement:Foundation.FloatControl.prototype.getFloatElement,
   combineFloatStyle:Foundation.FloatControl.prototype.combineFloatStyle,
   setFloatFocusEvents:Foundation.FloatControl.prototype.setFloatFocusEvents,
   floatChildOnFocus:Foundation.FloatControl.prototype.floatChildOnFocus,
   floatChildOnBlur:Foundation.FloatControl.prototype.floatChildOnBlur,
   setFloatHtml:Foundation.FloatControl.prototype.setFloatHtml,
   startFloatActivation:Foundation.FloatControl.prototype.startFloatActivation,
   floatActivationPeriodExpired:Foundation.FloatControl.prototype.floatActivationPeriodExpired,
   floatActivationActivity:Foundation.FloatControl.prototype.floatActivationActivity,
   maybeShowFloatActivation:Foundation.FloatControl.prototype.maybeShowFloatActivation,
   maybePopulateFloat:Foundation.FloatControl.prototype.maybePopulateFloat,
   createFloat:Foundation.FloatControl.prototype.createFloat,
   getActivationFloatSize:Foundation.FloatControl.prototype.getActivationFloatSize,
   getFloatSize:Foundation.FloatControl.prototype.getFloatSize,
   getFloatPosition:Foundation.FloatControl.prototype.getFloatPosition,
   positionFloat:Foundation.FloatControl.prototype.positionFloat,
   isFloatShown:Foundation.FloatControl.prototype.isFloatShown,
   updateFloat:Foundation.FloatControl.prototype.updateFloat,
   showFloat:Foundation.FloatControl.prototype.showFloat,
   synchFloat:Foundation.FloatControl.prototype.synchFloat,
   setFloatBoundElementValue:Foundation.FloatControl.prototype.setFloatBoundElementValue,
   floatBoundElementOnChange:Foundation.FloatControl.prototype.floatBoundElementOnChange,
   abortFloat:Foundation.FloatControl.prototype.abortFloat,
   hideFloat:Foundation.FloatControl.prototype.hideFloat,
   floatOnFocus:Foundation.FloatControl.prototype.floatOnFocus,
   floatOnBlur:Foundation.FloatControl.prototype.floatOnBlur,
   floatOnMouseDown:Foundation.FloatControl.prototype.floatOnMouseDown,
   floatOnMouseUp:Foundation.FloatControl.prototype.floatOnMouseUp,
   floatOnMouseOver:Foundation.FloatControl.prototype.floatOnMouseOver,
   floatOnMouseMove:Foundation.FloatControl.prototype.floatOnMouseMove,
   floatOnMouseOut:Foundation.FloatControl.prototype.floatOnMouseOut,
   focusToDefaultElement:Foundation.FloatControl.prototype.focusToDefaultElement,
   synchActiveFloatBoundElement:Foundation.FloatControl.prototype.synchActiveFloatBoundElement,
   floatOnDoubleClick:Foundation.FloatControl.prototype.floatOnDoubleClick,
   incrementFloatCount:Foundation.FloatControl.prototype.incrementFloatCount,
   decrementFloatCount:Foundation.FloatControl.prototype.decrementFloatCount,
   resetFloatCount:Foundation.FloatControl.prototype.resetFloatCount
};
Foundation.MicroLogin.resourcePack={
      canDebug:true,
      action:"Foundation.MicroLogin.action.htm",
      method:"POST",
      userIdName:"userId",
      passwordName:"password",
      rememberPasswordName:"rememberPassword",
      submitName:"login",
      sendPasswordName:"sendPassword",
      userIdValidation:Foundation.validateEmailFormat,
      userIdEmptyStyle:"background-color:#ffffff",
      userIdValidStyle:"background-color:#eeffee",
      userIdInvalidStyle:"background-color:#ffeeee",
      userIdEmptyWarning:"User Id cannot be empty",
      userIdInvalidWarning:"The format of the email address is invalid.",
      passwordValidation:null,
      passwordEmptyStyle:"",
      passwordValidStyle:"",
      passwordInvalidStyle:"",
      passwordEmptyWarning:"Password cannot be empty",
      passwordInvalidWarning:"The format of the password is invalid.",
      activateFloatHtml:"Click here to log in",
      floatHtml:"<form action=\"%action\" method=\"%method\" target=\"%frameId\" style=\"display:inline\" onsubmit=\"return %onSubmit\">"+
                "<table cellspacing=0 cellpadding=0>"+
                "<tr><td nowrap align=right><label for=\"%userIdId\">%userIdTitle</label></td><td><input type=text id=\"%userIdId\" name=\"%userIdName\" size=30 value=\"%userIdValue\" style=\"%userIdStyle\" onkeyup=\"%userIdOnKeyUp\"></td></tr>"+
                "<tr><td nowrap align=right><label for=\"%passwordId\">%passwordTitle</label></td><td><input type=password id=\"%passwordId\" name=\"%passwordName\" size=30 value=\"%passwordValue\" style=\"%passwordStyle\" onkeyup=\"%passwordOnKeyUp\"></td></tr>"+
                "<tr style=\"display:%rememberPasswordDisplay\"><td align=right><input type=checkbox id=\"%rememberPasswordId\" name=\"%rememberPasswordName\" %rememberPasswordValue></td><td nowrap><label for=\"%rememberPasswordId\">%rememberPasswordTitle</label></td></tr>"+
                "<tr><td align=center colspan=2><input type=submit id=\"%submitId\" name=\"%submitName\" value=\"%submitTitle\" onclick=\"%submitOnClick\"><span style=\"display:%sendPasswordDisplay\">&nbsp;&nbsp;&nbsp;<input type=submit id=\"%sendPasswordId\" name=\"%sendPasswordName\" value=\"%sendPasswordTitle\" onclick=\"%sendPasswordOnClick\"></span></td></tr>"+
                "</table>"+
                "</form>"+
                "<iframe id=\"%frameId\" name=\"%frameId\" src=\"about:blank\" onload=\"%submitFrameOnLoadEvent\" style=\"display:none\"></iframe>",
      loginStatus:"Login: %m",
      userIdTitle:"Email:",
      passwordTitle:"Password:",
      rememberPasswordTitle:"Remember password",
      submitTitle:"Log In",
      sendPasswordTitle:"Send Password",
      loggedIn:false,
      userId:"",
      password:"",
      rememberPassword:false,
      loginSuccessExpression:/LOGIN:\s*Success/i,
      loginSuccessMessage:null,
      loginErrorExpression:/LOGIN:\s*([\S \t]+)/i,
      loginErrorMessage:"Error logging in:\n%1",
      sendPasswordSuccessExpression:/SEND PASSWORD:\s*(Password\s+sent\s+to\s+\S+)/i,
      sendPasswordSuccessMessage:"%1",
      sendPasswordErrorExpression:/SEND PASSWORD:\s*([\S \t]+)/i,
      sendPasswordErrorMessage:"Error sending password:\n%1",
      unknownResultExpression:/(.*)/i,
      unknownResultMessage:"Unknown error:\n%1"
   }
;
Foundation.MicroLogin.getTypePath=Foundation.FloatControl.getTypePath;
Foundation.MicroLogin.resource=Foundation.FloatControl.resource;
Foundation.MicroLogin.getById=Foundation.FloatControl.getById;
Foundation.MicroLogin.getFirst=Foundation.FloatControl.getFirst;
Foundation.MicroLogin.getNext=Foundation.FloatControl.getNext;
Foundation.MicroLogin.isInstanceOf=Foundation.FloatControl.isInstanceOf;
Foundation.MicroLogin.resourcePackFromElement=Foundation.FloatControl.resourcePackFromElement;
Foundation.MicroLogin.bindToElement=Foundation.FloatControl.bindToElement;
Foundation.MicroLogin.getCssName=Foundation.FloatControl.getCssName;
Foundation.MicroLogin.bindToElements=Foundation.FloatControl.bindToElements;
Foundation.MicroLogin.getCssRules=Foundation.FloatControl.getCssRules;
Foundation.MicroLogin.writeToPage=Foundation.FloatControl.writeToPage;
Foundation.MicroLogin.$constructor();

