var description = new Array();
description[0] = "Create Business Analyst Account, Create BAO Account, Business Analyst Login, and BAO Account Login";

var cU = "baouserid", cP = "baouserpw";


function onLoadInitializer(){ 
  document.getElementById('password').onkeypress = function (e) {handleKeyPress(e,'submitFrmLogin')};
  document.frmLogin.username.focus();

}

function removeC(){
    del_cookie(cU);
    del_cookie(cP);
    onLoadInitializer();
}


function checkLoggedIn() {
    var nm = getCookie(cU);
    var ps = getCookie(cP);

    if (nm != null && nm.length > 0 && ps != null && ps.length > 0 ) {
        document.frmLogin.username.value = nm;
        document.frmLogin.password.value = ps;
        submitFrmLogin("", false);
    }  else {
        document.getElementById('password').onkeypress = function (e) {handleKeyPress(e,'submitFrmLogin')};
        document.frmLogin.username.focus();
    }

}

function submitFrmLogin(queryString, bEditAcct) {

    var frmActionUrl = document.frmLogin.casBaseURL.value + "/promos/index.cfm?event=ecas.authenticate";

    document.frmLogin.ReturnUrl.value = document.frmLogin.ReturnUrl.value;
    document.frmLogin.FailUrl.value = document.frmLogin.FailUrl.value;

    if (document.frmLogin.username.value.length == 0)
        alert("Please enter your Username.");
    else if (document.frmLogin.password.value.length == 0)
        alert("Please enter your Password");
    else {
        //remember me?
        if (document.frmLogin.rememberMe.checked) {
            //need to escape username
            setCookie("baouserid", document.frmLogin.username.value, 365);
            setCookie("baouserpw", document.frmLogin.password.value, 365);
        }
        //edit accout?
        if (bEditAcct) {
            document.frmLogin.editAcct.value = "checked";
            document.frmLogin.editAcct.disabled = false;
            frmActionUrl = document.frmLogin.casBaseURL.value + "/CAS/index.cfm";

        }

        if (queryString != null && queryString.length > 0 && queryString != 'null') {
            queryString = queryString.replace("errorCode", "ec");
            document.frmLogin.ReturnUrl.value = document.frmLogin.ReturnUrl.value + '?' + queryString;
            document.frmLogin.FailUrl.value = document.frmLogin.FailUrl.value + '?' + queryString;
        }
        document.frmLogin.action = frmActionUrl;
        document.frmLogin.submit();
    }
}

function clickPickUpReportButton(){
  document.getElementById('pickUpReportButtonLink').onclick();
}

  var WINDOW_REPORTS = '';

function showPreviousReportsWindow(url){
      var email = document.getElementById('emailAddress').value;
      var orderNumber = document.getElementById('orderNumber').value;
      url += '?e=' + email + '&o=' + orderNumber;
      if (!WINDOW_REPORTS.closed && WINDOW_REPORTS.location){
        WINDOW_REPORTS.location.href = url;
      }
      else{
        WINDOW_REPORTS=window.open(url,'name','scrollbars=yes,width=500,height=500,resizable=yes');
        if (!WINDOW_REPORTS.opener) WINDOW_REPORTS.opener = self;
      }
	if (window.focus) {WINDOW_REPORTS.focus()}
	return false;
  }


function handleKeyPress(e,callFunction){
    var keycode;
    if (!e){
      e = window.event;
      keycode = e.keyCode;
    }else{
      keycode = e.which;
    }
    if(keycode == 13){
      window[callFunction]();
    }
    return true;
  }

function wOpen(url, name, w, h)
{
    w += 32;
    h += 96;
    var win = window.open(url, name, 
    'width=' + w + ', height=' + h + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=no');
    win.resizeTo(w, h);
    win.focus();
}

function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ "; path=/; "+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}



function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function del_cookie(name) {
    document.cookie=name+"=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;";
}


