/* Script to log in to EWay.com */

// Login and registration functions
var vpath="https://www.eway.com/ce/eway/";
function forgotPassword(x) {
  document.UserLogin.nuser_id.value = document.DummyLogin.nuser_id.value;
  document.UserLogin.action = vpath + "pre_login.forgot_password_request";
  document.UserLogin.submit();
  window.location.reload( false );
} 

function preventSubmit() {
  document.UserLogin.npassword.focus();
  return false;
}

function toBenson() {
	document.UserLogin.submit();
	
}

function checkValues() { 
  document.UserLogin.nuser_id.value = document.DummyLogin.nuser_id.value; 
  var strUser = document.UserLogin.nuser_id.value; 
  if (strUser.length <= 0) { 
     alert("Your User ID is required")
     setFocus();
     return false;
  } else {
     if (document.UserLogin.npassword.value == "") { 
        document.UserLogin.npassword.focus();
        return false;
     } else {
        return true;
     }
  }
} 

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 var nDays = 30;
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

//function setCookie(name, value, expires, path, domain, secure)
//{
//    document.cookie= name + "=" + escape(value) +
//        ((expires) ? "; expires=" + expires.toGMTString() : "") +
//        ((path) ? "; path=" + path : "") +
//        ((domain) ? "; domain=" + domain : "") +
//        ((secure) ? "; secure" : "");
//		
//}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function setHiddenSaveUserid() {
  if (document.save_userid_form.save_userid.checked == true) {
     document.UserLogin.save_userid.value = "Y";
	 setCookie("sfcc.userid", document.DummyLogin.nuser_id.value);
  } else {
     document.UserLogin.save_userid.value = "";
	 deleteCookie("sfcc.userid");
  }
}




