var digits = "1234567890";
function trimStr(str)
{
	firstInd=str.length;
	lastInd=0;
	for(i=0; i<str.length; i++)
	{
		if (str.charAt(i) != " ")
		{
			if (i < firstInd)
			{
				firstInd = i;
			}
			if (i > lastInd)
			{
				lastInd = i;
			}
		}
	}
	if(firstInd > lastInd) return "";
	return str.substring(firstInd,lastInd+1);
}


function isValidCardNumber(str)
{   
  for(k = 0; k < 16; k++)
    { if(  (str[k] < "0") || (str[k] > "9") ) return false;
    }
  return true;
}

function validateForm()
{
      var cardNum = trimStr(document.LoginForm.DE_LS_IP_ATTM_USER_NM.value);
      var passwd = trimStr(document.LoginForm.DE_LS_IP_ATTM_USER_PSSW.value);
      document.LoginForm.DE_LS_IP_ATTM_USER_NM.value=cardNum;
      document.LoginForm.DE_LS_IP_ATTM_USER_PSSW.value = passwd;
      var error = 0;
      if(cardNum.length != 16)
	{ error = 1;
	}
      else
      { if(!isValidCardNumber(cardNum))
          { error = 1;
          }
      }
      if(error == 1)
      {  if(getDisplayLang() == "E")
	 	alert("Please enter your 16 digit PC MasterCard number.\n\nSelect \"OK\" to enter your PC MasterCard number.\n");
	else 
        	alert("Veuillez entrer le numéro à 16 chiffres de votre carte MasterCard.\n\nCliquez sur \"OK\" pour entrer le numéro de votre carte MasterCard.\n");
        document.LoginForm.DE_LS_IP_ATTM_USER_NM.focus();
        return false;
      }
      if(passwd.length <= 0)
      { 
		if(getDisplayLang() == "F")
			alert("Veuillez entrer votre mot de passe.\n\nCliquez sur \"OK\"  pour entrer votre mot de passe.\n");
		else
      		alert("Please enter your password.\n\nSelect \"OK\" to enter your password.\n");
        document.LoginForm.DE_LS_IP_ATTM_USER_PSSW.focus();
        return false;
      }
      return true;
}

function ResetLoginPage()
{
  if(validateForm())
    {   document.LoginForm.DE_LS_ATTM_USER_NM.value = document.LoginForm.DE_LS_IP_ATTM_USER_NM.value;
	document.LoginForm.DE_LS_ATTM_USER_PSSW.value = document.LoginForm.DE_LS_IP_ATTM_USER_PSSW.value;
	document.LoginForm.DE_LS_IP_ATTM_USER_NM.value = "";
	document.LoginForm.DE_LS_IP_ATTM_USER_PSSW.value = "";
		if(getDisplayLang() == "F")
		   document.LoginForm.action = getUrlStr(secure01Url_fr, null);
		else
           document.LoginForm.action = getUrlStr(secure01Url_en, null);
/*	document.LoginForm.action = getUrlStr(secure01Url,null); */
	document.LoginForm.submit();
    }
}

function forgotPassword()
{
  if(getDisplayLang() == "F")
     return intelliData_preschoicefinancial_cgi_bin_cgi_chip_forgot_pswd_fr;
  else
     return intelliData_preschoicefinancial_cgi_bin_cgi_chip_forgot_pswd_en;
}

function registerPassword()
{ 
  if(getDisplayLang() == "F")
     return intelliData_preschoicefinancial_cgi_bin_cgi_chip_select_pswd_fr;
  else
     return intelliData_preschoicefinancial_cgi_bin_cgi_chip_select_pswd_en;
}

function registerPasswordPopup()
{ h = registerPassword();
  openWindow3(h, 800, 600);
}

function registerPasswordReplace()
{ 
  top.location.href = registerPassword();
  
}

function forgotPasswordPopup()
{ h = forgotPassword();
  openWindow3(h, 800, 600);
}

function forgotPasswordReplace()
{ top.location.href = forgotPassword();
}


