$(document).ready(function(){init()});function getParameterByName(b){b=b.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var a="[\\?&]"+b+"=([^&#]*)";var d=new RegExp(a);var c=d.exec(window.location.href);if(c==null){return""}else{return c[1]}}function init(){clearForms();attachListeners();setUserID();getOutageMessage();getLoginMessage();if(getParameterByName("login")=="true"){$("div#login .top").css("background-image","url(/images/top-cust.gif)");$("div#login .top span").css("background-image","url(/images/top-right-cust.gif)");$("div#login .center-content").css("background-image","url(/images/rightside-cust.gif)");$("div#login .bottom").css("background-image","url(/images/bottom-cust.gif)");$("div#login .bottom span").css("background-image","url(/images/bottom-right-cust.gif)");$("div#login .liquid-round").css("background-image","url(/images/leftside-cust.gif)")}if(window.location.hostname=="wwwtr.bnsf.com"){portalLoginURL="https://customertr.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer"}if(getParameterByName("dev")=="true"){portalLoginURL="http://customerdv.bnsf.com/_layouts/BNSF.PasswordReset/EmailPassword.aspx"}else{if(getParameterByName("trial")=="true"){portalLoginURL="https://customertr.bnsf.com/_layouts/BNSF.PasswordReset/EmailPassword.aspx"}}}function clearForms(){var b;for(b=0;(b<document.forms.length);b++){document.forms[b].reset();for(var a=0;a<document.forms[b].elements.length;a++){swapClass(document.forms[b].elements[a],"invalidField","regularField")}}}function createCookie(c,e,f,d){if(f){var b=new Date();b.setTime(b.getTime()+(f*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+escape(e)+";expires="+a+"; path=/"+((d)?";domain="+d:"")}function readCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return f.substring(e.length,f.length)}}return null}function eraseCookie(a,b){createCookie(a,"",-1,b)}function setUserID(){var a=readCookie("custptlID");if(a!=null){$("form[name='custLogin_form'] input[name='LoginUsername']").removeClass("userNameText").val(a);$("form[name='custLogin_form'] input[name='remember']").attr("checked","checked")}}function getOutageMessage(){if(outage){$("#outage_message").html(customMessage[customMsgNbr]).removeClass("hide")}}function getLoginMessage(){var a=readCookie("custportal");if(a!=null){if(unescape(unescape(a)).indexOf("Change Password")>=0||unescape(unescape(a)).indexOf("ChangePassword")>=0){$("form[name='custLogin_form']").addClass("hide");$("form[name='custChangePW_form']").removeClass("hide");a=a.substring(15)}if(unescape(unescape(a)).indexOf("You have successfully logged out.")>=0){eraseCookie("AMAuthCustCookie","bnsf.com")}$("#login_message").html(unescape(unescape(a))).removeClass("hide");eraseCookie("custportal","bnsf.com")}}function swapClass(b,a,c){b.className=b.className.replace(a,c)}function trim(b,a){return ltrim(rtrim(b,a),a)}function ltrim(b,a){a=a||"\\s";return b.replace(new RegExp("^["+a+"]+","g"),"")}function rtrim(b,a){a=a||"\\s";return b.replace(new RegExp("["+a+"]+$","g"),"")}function validateLogin(c){var j=new Array();j[0]="Username";j[1]="Password";j[2]="Remember Me";var g=new Array();g[0]="Old Password";g[1]="New Password";g[2]="Confirm Password";var a;if(c.name=="custLogin_form"){a=j}else{if(c.name=="custChangePW_form"){a=g}}var k=true;var f="";var b=-1;for(var d=(c.elements.length-1);d>=0;d--){if((c.elements[d].type=="text"||c.elements[d].type=="password")){if(trim(c.elements[d].value)==""){f="Please enter a valid value for the '"+a[d]+"' field.";swapClass(c.elements[d],"regularField","invalidField");b=d;k=false}else{swapClass(c.elements[d],"invalidField","regularField")}}}if(c.name=="custChangePW_form"){try{if(c.elements.NewPassword.value!=c.elements.ConfirmNewPassword.value){f="Your new passwords did not match. Please enter the same password in both input fields below.";b=1;k=false}if(c.elements.NewPassword.value.toLowerCase().search("password")!=-1){f="Your password cannot contain the keyword 'Password' (case insensitive).";b=1;k=false}if(c.elements.NewPassword.value.length<6||c.elements.NewPassword.value.length>16){f="Your password must be between 6 - 16 characters in length.";b=1;k=false}}catch(h){}}if(f.length>0){$("#login_message").html(f).removeClass("hide");c.elements[b].focus()}if(k&&c.name!="custChangePW_form"){if(c.elements.remember.checked==true){createCookie("custptlID",trim(c.elements[0].value).toUpperCase(),90)}else{eraseCookie("custptlID")}}return k}function attachListeners(){var a="https://customer.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer";if(getParameterByName("pub")=="true"){a="https://customerpub.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer"}if(window.location.hostname=="wwwtr.bnsf.com"){a="https://customertr.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer";if(getParameterByName("pub")=="true"){a="https://customerpubtr.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer"}}if(getParameterByName("dev")=="true"){a="http://customerdv.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer"}else{if(getParameterByName("trial")=="true"){a="https://customertr.bnsf.com/_layouts/Bnsf.Authentication/Login.ashx?org=customer"}}$("form[name='custLogin_form']").attr("action",a);$("form[name='custChangePW_form']").attr("action",a);$("form[name='custLogin_form']").bind("submit",function(){var b=$("form[name='custLogin_form'] input[name='LoginUsername']").val().toUpperCase();$("form[name='custLogin_form'] input[name='LoginUsername']").val(b);return validateLogin(this)});$("form[name='custChangePW_form']").bind("submit",function(){return validateLogin(this)});$("form[name='custLogin_form'] input[name='LoginUsername']").focus(function(){$(this).removeClass("userNameText")});$("form[name='custLogin_form'] input[name='LoginUsername']").blur(function(){if($(this).val().length==0){$(this).addClass("userNameText")}});$("form[name='custLogin_form'] input[name='LoginPassword']").focus(function(){$(this).removeClass("passwordText")});$("form[name='custLogin_form'] input[name='LoginPassword']").blur(function(){if($(this).val().length==0){$(this).addClass("passwordText")}});$("form[name='custLogin_form'] input[name='remember']").click(function(){$(this).next().focus()});$("form[name='custChangePW_form'] input[name='OldPassword']").focus(function(){$(this).removeClass("oldpasswordText")});$("form[name='custChangePW_form'] input[name='OldPassword']").blur(function(){if($(this).val().length==0){$(this).addClass("oldpasswordText")}});$("form[name='custChangePW_form'] input[name='NewPassword']").focus(function(){$(this).removeClass("newpasswordText")});$("form[name='custChangePW_form'] input[name='NewPassword']").blur(function(){if($(this).val().length==0){$(this).addClass("newpasswordText")}});$("form[name='custChangePW_form'] input[name='ConfirmNewPassword']").focus(function(){$(this).removeClass("confirmpasswordText")});$("form[name='custChangePW_form'] input[name='ConfirmNewPassword']").blur(function(){if($(this).val().length==0){$(this).addClass("confirmpasswordText")}})};
