/*
 * This embed keyboard is included .com, .net, @ keys, not included capslock key,
 * included the main interface called
 */

/************************* the following interfaces are called when the form is submitted *************************/

/* called when the form is submitted to check if zip code is valid,
 * parameter is the current zip component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateZip(zipInput,isRequired)
{
	return validateZipImpl(zipInput,isRequired);
}

/* called when the form is submitted to check if amount is valid,
 * parameter is the current amount component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateAmount(amountInput,desc,isRequired)
{
	return validateAmountImpl(amountInput,desc,isRequired);
}

/* called when the form is submitted to check if phone number is valid,
 * parameter is the current phone component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validatePhone(phoneInput,isRequired)
{
	return validatePhoneImpl(phoneInput,isRequired);
}

/* called when the form is submitted to check if date is valid,
 * parameter is the current date component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateDate(dateInput,desc,isRequired)
{
	return validateDateImpl(dateInput,desc,isRequired);
}

/* called when the form is submitted to check if ssn is valid,
 * parameter is the current ssn component,if this field is required,
 * please set isRequired = true, or set isRequired = false,
 * will be used the hidden social security number component which id is 'socialSecurity',
 * please check if this component is exist.
 */
function validateSSN(ssnInput,isRequired)
{
	return validateSSNImpl(ssnInput,isRequired);
}

/* called when the form is submitted to check if email is valid,
 * parameter is the current email component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateEmail(emailInput,isRequired)
{
	return validateEmailImpl(emailInput,isRequired);
}

/* called when the form is submitted to check if first name is valid,
 * parameter is the current first name component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateFirstName(firstNameInput,desc,isRequired)
{
	return validateFirstNameImpl(firstNameInput,desc,isRequired);
}

/* called when the form is submitted to check if last name is valid,
 * parameter is the current last name component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateLastName(lastNameInput,desc,isRequired)
{
	return validateLastNameImpl(lastNameInput,desc,isRequired);
}

/* called when the form is submitted to check if address is valid,
 * parameter is the current address component,if this field is required,
 * please set isRequired = true, or set isRequired = false
 */
function validateAddress(addressInput,desc,isRequired)
{
	return validateAddressImpl(addressInput,desc,isRequired);
}

/***************************** the following interfaces are called when physical keyboard is pressed ***************************/

/* called when physical keyboard is pressed to check if zip code is valid,
 * parameter is the current zip component
 */
function checkZip(zipInput)
{
	return checkZipImpl(zipInput);
}

/* called when physical keyboard is pressed to check if amount is valid,
 * parameter is the current amount component
 */
function checkAmount(amountInput,desc)
{
	return checkAmountImpl(amountInput,desc);
}

/* called when physical keyboard is pressed to check if phone number is valid,
 * parameter is the current phone number component
 */
function phoneMask(phoneInput)
{
	return phoneMaskImpl(phoneInput);
}

/* called when physical keyboard is pressed to check if date is valid,
 * parameter is the current date component
 */
function dateMask(dateInput)
{
	return dateMaskImpl(dateInput);
}

/* called when physical keyboard is pressed to check if social security number is valid,
 * parameter is the current ssn component, will be used the hidden social security number
 * component which id is 'socialSecurity', please check if this component is exist.
 */
function ssnMask(ssnInput)
{
	return ssnMaskImpl(ssnInput);
}

/* called when embed keyboard is focused on normal component */
function showKeyboard(object)
{
	showKeyboardImpl(object);
}

/* called when embed keyboard is focused on normal component
 * we can set the position on the screen with X, Y
 */
function showKeyboardXY(object,screenX,screenY)
{
	showKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on email component */
function showEmailKeyboard(object)
{
	showEmailKeyboardImpl(object);
}

/* called when embed keyboard is focused on email component
 * we can set the position on the screen with X, Y
 */
function showEmailKeyboardXY(object,screenX,screenY)
{
	showEmailKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on amount component */
function showAmountKeyboard(object)
{
	showAmountKeyboardImpl(object);
}

/* called when embed keyboard is focused on amount component
 * we can set the position on the screen with X, Y
 */
function showAmountKeyboardXY(object,screenX,screenY)
{
	showAmountKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on zip component */
function showZipKeyboard(object)
{
	showZipKeyboardImpl(object);
}

/* called when embed keyboard is focused on zip component
 * we can set the position on the screen with X, Y
 */
function showZipKeyboardXY(object,screenX,screenY)
{
	showZipKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on phone component */
function showPhoneKeyboard(object)
{
	showPhoneKeyboardImpl(object);
}

/* called when embed keyboard is focused on phone component
 * we can set the position on the screen with X, Y
 */
function showPhoneKeyboardXY(object,screenX,screenY)
{
	showPhoneKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on date component */
function showDateKeyboard(object)
{
	showDateKeyboardImpl(object);
}

/* called when embed keyboard is focused on date component
 * we can set the position on the screen with X, Y
 */
function showDateKeyboardXY(object,screenX,screenY)
{
	showDateKeyboardImplXY(object,screenX,screenY);
}

/* called when embed keyboard is focused on ssn component */
function showSSNKeyboard(object)
{
	showSSNKeyboardImpl(object);
}

/* called when embed keyboard is focused on ssn component
 * we can set the position on the screen with X, Y
 */
function showSSNKeyboardXY(object,screenX,screenY)
{
	showSSNKeyboardImplXY(object,screenX,screenY);
}

/* find element in document by id,
 * parameter o is the component's id
 */
function $find(o)
{
  return document.getElementById(o);
}

/* set the focus for current component,
 * parameter o is the component's id
 */
function $setfocus(o)
{
  return $find(o).focus();
}

/*
 * trim the component's value
 */
String.prototype.trim = function() 
{
  return this.replace(/^\s+|\s+$/g,"");
}

/*
 * check if target object's value is empty
 */
function isNull(obj)
{
  obj.value = obj.value.trim();
  return obj.value == "";
}

/************************ the following program is the implement for above interfaces **************************/
var targetObject=null;
var CapsLockValue=1;
var screenW=screen.width;
var screenH=screen.height;
var isAmount=false;
var isZip=false;
var isPhone=false;
var isSSN=false;
var isDate=false;
var defaultX=100;
var defaultY=380;
var fieldArray=new Array();
var nowField=0;

function showKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=false;
  isPhone=false;
  isSSN=false;
  isDate=false;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showKeyboardImpl(object)
{
  showKeyboardImplXY(object, defaultX, defaultY);
}

function showEmailKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=false;
  isPhone=false;
  isSSN=false;
  isDate=false;
  $find("emailDiv").style.display="block";
  $find("nonEmailDiv").style.display="none";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showEmailKeyboardImpl(object)
{
  showEmailKeyboardImplXY(object,defaultX,defaultY);
}

function showAmountKeyboardImplXY(object,screenX,screenY)
{
  isAmount=true;
  isZip=false;
  isPhone=false;
  isSSN=false;
  isDate=false;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showAmountKeyboardImpl(object)
{
  showAmountKeyboardImplXY(object, defaultX, defaultY);
}

function showZipKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=true;
  isPhone=false;
  isSSN=false;
  isDate=false;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showZipKeyboardImpl(object)
{
  showZipKeyboardXY(object, defaultX, defaultY);
}

function showPhoneKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=false;
  isPhone=true;
  isSSN=false;
  isDate=false;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showPhoneKeyboardImpl(object)
{
  showPhoneKeyboardXY(object, defaultX, defaultY);
}

function showDateKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=false;
  isPhone=false;
  isSSN=false;
  isDate=true;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showDateKeyboardImpl(object)
{
  showDateKeyboardXY(object, defaultX, defaultY);
}

function showSSNKeyboardImplXY(object,screenX,screenY)
{
  isAmount=false;
  isZip=false;
  isPhone=false;
  isSSN=true;
  isDate=false;
  $find("emailDiv").style.display="none";
  $find("nonEmailDiv").style.display="block";
  targetObject = object;
  $find("softkeyboard").style.display="block";
  setKeyboardLocation(screenX,screenY);
}

function showSSNKeyboardImpl(object)
{
  showSSNKeyboardXY(object, defaultX, defaultY);
}

// close keyboard
function closekeyboard()
{
  $find("softkeyboard").style.display="none";
}

// input the digit/character/symbol
function addValue(newValue)
{
  //var musicObj = $find("softkeyboard_music");
  //musicObj.innerHTML="<embed src=\"trackdemo/gray/kb_01/key_sound.wav\" autostart=\"true\" loop=\"false\" hidden=\"true\">";
  if (CapsLockValue==0)
  {
	  newValue = newValue.toLowerCase();
  }
  else
  {
	  newValue = newValue.toUpperCase();
  }
  targetObject.value+=newValue;
  if (isZip)
  {
	  validateKeyboardZip();
  }
  else if (isAmount)
  {
	  validateKeyboardAmount();
  }
  else if(isPhone)
  {
      validateKeyboardPhone();
  }
  else if(isDate)
  {
	  validateKeyboardDate();
  }
  else if(isSSN)
  {
	  validateKeyboardSSN();
  }
}

// call backspace key
function callbackspace()
{
  var length=targetObject.value.length;
  var num=targetObject.value.substring(0,length-1);
  targetObject.value=num;
  if (isSSN)
  {
	  var hiddenSSN = $find("socialSecurity");
	  hiddenSSN.value=hiddenSSN.value.substring(0,hiddenSSN.value.length-1);
  }
  $find(targetObject.id).focus();
}

// set field key
function setFieldArray(obj)
{
	fieldArray=obj;
}

function callPreviousfield()
{
	if(nowField>0)
		nowField=nowField-1;
	if(fieldArray.length>0)
	{
			$find(fieldArray[nowField]).focus();
	}
}
// call nextfield key
function callNextfield()
{
	if(nowField<fieldArray.length-1)
		nowField=nowField+1;
	if(fieldArray.length>0)
	{
			$find(fieldArray[nowField]).focus();
	}	
}

// clear input context
function clearkeyboard()
{
  targetObject.value="";
}

// switch uppercase / lowercase
function setCapsLock(obj)
{
  if (CapsLockValue==0)
  {
    CapsLockValue=1;
	obj.style.background="url(/kiosk_resources/gray/kb/capslock_off.png)";
  }
  else
  {
	CapsLockValue=0;
	obj.style.background="url(/kiosk_resources/gray/kb/capslock_on.png)";
  }
}

// set keyboard's position on the screen
function setKeyboardLocation(screenX,screenY)
{
  var kb = $find("softkeyboard");
  kb.style.position="absolute";
  kb.style.left=screenX;
  kb.style.top=screenY;
}

function imgSwap(oImg)
{
  var strOver= "_on"    // image to be used with mouse over
  var strOff = "_off"   // normal image

  var strImg = oImg.style.background
  if (strImg.indexOf(strOver) != -1)
    oImg.style.background = strImg.replace(strOver,strOff)
  else
    oImg.style.background = strImg.replace(strOff,strOver)
}

var style="<style>";
style+="@media print {.keyboardNoPrint{display:none;}}";
style+="</style>";

document.write(style);

document.write ('<div class=\"keyboardNoPrint\">');
document.write ('  <div align=\"center\" id=\"softkeyboard\" name=\"softkeyboard\" style=\"position:absolute;left:0;top:0;width:517px;z-index:180;display:none\">');
document.write ('  <table width=\"780\" height=\"200\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('  <tr>');
document.write ('  <td width=\"590\">');
document.write ('    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('    <tr>');
document.write ('    <td>');
document.write ('      <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('      <tr>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/q_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'q\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/w_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'w\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/e_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'e\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/r_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'r\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/t_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'t\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/y_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'y\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/u_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'u\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/i_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'i\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/o_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'o\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/p_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'p\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      </tr>');
document.write ('      </table>');
document.write ('    </td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td align=\"center\">');
document.write ('      <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('      <tr>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/a_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'a\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/s_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'s\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/d_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'d\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/f_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'f\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/g_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'g\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/h_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'h\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/j_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'j\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/k_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'k\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/l_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'l\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/line_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'-\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      </tr>');
document.write ('      </table>');
document.write ('    </td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td align=\"center\">');
document.write ('      <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('      <tr>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/z_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'z\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/x_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'x\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/c_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'c\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/v_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'v\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/b_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'b\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/n_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'n\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/m_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'m\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/underscore_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'_\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/backspace_off.png);width:120px;height:60px;cursor:pointer;border:0;\" onclick=\"callbackspace();\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      </tr>');
document.write ('      </table>');
document.write ('    </td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td align=\"center\">');
//hidden email keys
document.write ('      <div id=\"emailDiv\" style=\"display:none\">');
document.write ('      <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('      <tr>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/com_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'.com\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/net_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'.net\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/space_off.png); width:180px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\' \');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/@_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'@\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/nextfield_off.png);width:131px;height:60px;cursor:pointer;border:0;\" onclick=\"callNextfield();\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/previousfield_off.png);width:131px;height:60px;cursor:pointer;border:0;\" onclick=\"callPreviousfield();\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      </tr>');
document.write ('      </table>');
document.write ('      </div>');
//show non-email keys
document.write ('      <div id=\"nonEmailDiv\" style=\"display:block\">');
document.write ('      <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('      <tr>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/space_off.png); width:180px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\' \');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/nextfield_off.png);width:131px;height:60px;cursor:pointer;border:0;\" onclick=\"callNextfield();\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/previousfield_off.png);width:131px;height:60px;cursor:pointer;border:0;\" onclick=\"callPreviousfield();\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('      </tr>');
document.write ('      </table>');
document.write ('      </div>');
document.write ('    </td>');
document.write ('    </tr>');
document.write ('    </table>');
document.write ('  </td>');

document.write ('  <td valign=\"middle\">');
document.write ('    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('    <tr>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/divider.png); width:24px;height:230px;border:0;\"></td>');
document.write ('    </tr>');
document.write ('    </table>');
document.write ('  </td>');

document.write ('  <td>');
document.write ('    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">');
document.write ('    <tr>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/1_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'1\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/2_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'2\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/3_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'3\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/4_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'4\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/5_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'5\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/6_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'6\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/7_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'7\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/8_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'8\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/9_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'9\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    </tr>');

document.write ('    <tr>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/dot_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'.\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/0_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'0\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    <td><input type=button style=\"background:url(/kiosk_resources/gray/kb/jin_off.png);width:60px;height:60px;cursor:pointer;border:0;\" onclick=\"addValue(\'#\');\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\"></td>');
document.write ('    </tr>');
document.write ('    </table>');
document.write ('  </td>');

document.write ('  </tr>');
document.write ('  </table>');

document.write ('  </div>');
document.write ('</div>');

//The following is the module for checking email, amount, zip, phone, date, social security number
regExpArray = new Array();
regExpArray["phone"] = /^[0-9][0-9]{8}[0-9]$/;
regExpArray["zip"] = /^[A-Z0-9][A-Z0-9\s]*[A-Z0-9]$/;
regExpArray["email"] = /^[A-Z0-9\.\_\-]+@[A-Z0-9]+\.[A-Z0-9]+/;
regExpArray["firstName"] = /^[a-zA-Z][a-zA-Z\s]*[a-zA-Z\s]$/;	
regExpArray["middleName"] = /[a-zA-Z]/;
regExpArray["lastName"] = /^[a-zA-Z][a-zA-Z\-\s]*[a-zA-Z\s]$/;
regExpArray["address"] = /^[a-zA-Z0-9\s\/][a-zA-Z0-9\s\/\.#\-]*[a-zA-Z0-9\.\s\/]$/;

numericReg = /(^\d\d*\.\d*$)|(^\d\d*$)|(^\.\d\d*$)/;
integerReg = /(^\d\d*\d*$)|(^\d\d*$)|(^\d\d*$)/;
badPhone = /1111111111|2222222222|3333333333|4444444444|5555555555|6666666666|7777777777|8888888888|9999999999|0000000000/;
canadaZip = /^[A-Z][0-9][A-Z][\s][0-9][A-Z][0-9]$/;

function validateRegExp(theField)
{
  if(!regExpArray[theField.id]) return true;
  boolTest = regExpArray[theField.id].test(theField.value);
  if(!boolTest)
  {
	return false;
  }
  return true;
}

function inFocus(theInput)
{
  if(!theInput.disabled)
  {
 	theInput.focus();
	if(theInput.type == "text")	theInput.select();
  }
  theInput.style.color = "red";
}

function outFocus(theInput)
{
  theInput.style.color = "black";
  $find(theInput.id).focus();
}

function showError(vis, errMsg, errId)
{
  popUp=$find("errorPopUp");
  if(!popUp)
  {
	tbody = document.getElementsByTagName("body")[0];
	tnode = document.createElement("div");         // Create the layer.
	tnode.style.position="absolute";               // Position absolutely
    tnode.style.top="0px";                         // In the top
    tnode.style.left="0px";                        // Left corner of the page
    tnode.style.overflow="hidden";                 // Try to avoid making scroll bars            
    tnode.style.display="none";                    // Start out Hidden
    if (screen.width == 1280 && screen.height == 1024)
    {
	    tnode.style.width="1280px";
	    tnode.style.height="1024px";
	    tnode.style.background = "url('/kiosk_resources/images/msg_bg_1280x1024.png') no-repeat";
	  }
	  else
	  {
	    tnode.style.width="1024px";
	    tnode.style.height="768px";
	    tnode.style.background = "url('/kiosk_resources/images/msg_bg.png') no-repeat";
	  }	    
    tnode.id="errorPopUp";                   	   // Name it so we can find it later
	tbody.appendChild(tnode);                      // Add it to the web page
	popUp=$find("errorPopUp");   // Get the object.		
  }	
  if(vis)
  {
  	if (screen.width == 1280 && screen.height == 1024)
    {
      popUp.innerHTML = "<div style='position:absolute;top:372px;left:400px;'>" 
		                  + "<table width='450' height='280' border='0' cellspacing='0' cellpadding='0'>" 
	                    + "<tr><td align='center' valign='bottom' height='40' style='font-size:1.7em;font-family:Arial;color:#FFFFFF;'>Information</td></tr>"
   	                  + "<tr><td align='center' valign='center' height='180' style='font-size:1.2em;font-family:Arial;'>" + errMsg + "</td></tr>"
	                    + "<tr><td align='center' valign='bottom' height='40'><input type='button' id='embedOKBTN' style=\"background:url(/kiosk_resources/images/ok_btn_off.png);width:137px;height:54px;border:0;\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\" onclick='showError(false, \"\", \"" + errId + "\");'></td></tr>"
					            + "</table>" 
					            + "</div>";
		}
		else
		{
      popUp.innerHTML = "<div style='position:absolute;top:245px;left:285px;'>" 
		                  + "<table width='450' height='280' border='0' cellspacing='0' cellpadding='0'>" 
	                    + "<tr><td align='center' valign='bottom' height='40' style='font-size:1.7em;font-family:Arial;color:#FFFFFF;'>Information</td></tr>"
   	                  + "<tr><td align='center' valign='center' height='180' style='font-size:1.2em;font-family:Arial;'>" + errMsg + "</td></tr>"
	                    + "<tr><td align='center' valign='bottom' height='40'><input type='button' id='embedOKBTN' style=\"background:url(/kiosk_resources/images/ok_btn_off.png);width:137px;height:54px;border:0;\" onmouseover=\"imgSwap(this)\" onmouseout=\"imgSwap(this)\" onclick='showError(false, \"\", \"" + errId + "\");'></td></tr>"
					            + "</table>" 
					            + "</div>";
		}
	popUp.style.zIndex = 1500;
	popUp.style.display = "block";
    $find('embedOKBTN').focus();	
  }
  else
  {
	popUp.style.display = "none";
 	eval($find(errId));
	$find(errId).focus();
	inFocus($find(errId));
  }  
}

function showMsg(msg,id)
{
  showError(true, msg, id);
}

function imgSwap(oImg)
{
  var strOver= "_on";    // image to be used with mouse over
  var strOff = "_off";   // normal image

  var strImg = oImg.style.background;
  if (strImg.indexOf(strOver) != -1)
    oImg.style.background = strImg.replace(strOver,strOff);
  else
    oImg.style.background = strImg.replace(strOff,strOver);
}

function checkKeycode(eButton)
{
  try
  {
    if ((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
    {
  	  window.event.keyCode = eval(window.event.keyCode) - 32;
	}
  }
  catch(e)
  {
  }
}

function makeCAP(obj)
{
  try
  {	
    obj.value = obj.value.toUpperCase();
  }
  catch(e)
  {
  }
}

//called when embed keyboard is pressed
function validateKeyboardZip()
{
  var country = $find("country");
  if (!country) return;
  var isUS = country.options[country.selectedIndex].value == 'US';
  if (isUS)
  {
    if (targetObject.value.length>5)
    {
	  targetObject.value = targetObject.value.substring(0, 5);
    }
    if(!integerReg.test(targetObject.value))
    { 
	  targetObject.value="";
 	  showMsg("Zip code must be digits.", targetObject.id);
	  return false;
    }
    if($find("state")!=null||$find("city")!=null)
    {
  	  loadStateCity(targetObject);
    }
  }
  else
  {
    if (targetObject.value.length>7)
    {
	  targetObject.value = targetObject.value.substring(0, 7);
    }
	if (targetObject.value.length==3)
	{
		targetObject.value += " ";
	}
	if (targetObject.value.length==7)
	{
      if(!canadaZip.test(targetObject.value))
      { 
	    targetObject.value="";
 	    showMsg("Sorry, Invalid Zip Code!<br><br>Format: <font color='red'>K1A 0B1</font>", targetObject.id);
	    return false;
      }
	}
  }
  outFocus(targetObject);
  return true;
}

//called when physical keyboard is pressed
function checkZipImpl(zipInput)
{
  var country = $find("country");
  if (!country) return;
  var isUS = country.options[country.selectedIndex].value == 'US';
  if (isUS)
  {
    zipInput.value = zipInput.value.trim();
    if (zipInput.value.length > 5)
    {
      zipInput.value = zipInput.value.substring(0, 5);
    }
    if(zipInput.value.length > 0 && !integerReg.test(zipInput.value))
    { 
	  zipInput.value="";
	  showMsg("Zip code must be digits.", zipInput.id);
	  return false;
    }
  }
  else
  {
    if (zipInput.value.length>7)
    {
	  zipInput.value = zipInput.value.substring(0, 7);
    }
	if (zipInput.value.length==3)
	{
		zipInput.value += " ";
	}
	if (zipInput.value.length==7)
	{
      if(!canadaZip.test(zipInput.value))
      { 
	    zipInput.value="";
 	    showMsg("Sorry, Invalid Zip Code!<br><br>Format: <font color='red'>K1A 0B1</font>", zipInput.id);
	    return false;
      }
	}
  }
  outFocus(zipInput);
  return true;
}

//called when the form is submitted
function validateZipImpl(zipInput,isRequired)
{
  var country = $find("country");
  if (!country) 
  {
    if (isRequired && isNull(zipInput))
    {
	  showMsg("Zip code can not be empty.", zipInput.id);
	  return false;
    }
    if(!integerReg.test(zipInput.value))
    { 
	  showMsg("Zip code must be digits.", zipInput.id);
	  return false; 
    }
    if (zipInput.value.length != 5)
    {
      showMsg("Zip code must be 5 characters.", zipInput.id);
	  return false;
    }
  }
  else
  {
  	var isUS = country.options[country.selectedIndex].value == 'US';
  	zipInput.value = zipInput.value.trim();
  	if (isUS)
  	{
    	if (isRequired && isNull(zipInput))
    	{
	  	showMsg("Zip code can not be empty.", zipInput.id);
	  	return false;
    	}
    	if(!integerReg.test(zipInput.value))
    	{ 
	  	showMsg("Zip code must be digits.", zipInput.id);
	  	return false; 
    	}
    	if (zipInput.value.length != 5)
    	{
      	showMsg("Zip code must be 5 characters.", zipInput.id);
	  		return false;
    	}
  	}
  	else
  	{
    	if(!canadaZip.test(zipInput.value))
    	{ 
 	  	showMsg("Sorry, Invalid Zip Code!<br><br>Format: <font color='red'>K1A 0B1</font>", zipInput.id);
	  	return false;
    	}
  	}
  }
  outFocus(zipInput);
  return true;
}

//called when embed keyboard is pressed
function validateKeyboardAmount()
{
  targetObject.value = targetObject.value.trim();
  if (targetObject.value == "-")
  {
	return true;
  }
  if(targetObject.value.length > 0 && !numericReg.test(Math.abs(targetObject.value)))
  { 
	targetObject.value="";
	showMsg("Sorry, amount value must be numbers.", targetObject.id);
	return false; 
  }
  outFocus(targetObject);
  return true;
}

//called when physical keyboard is pressed
function checkAmountImpl(numObj,desc)
{
  numObj.value = numObj.value.trim();
  if (numObj.value == "-")
  {
	return true;
  }
  if(numObj.value.length > 0 && !numericReg.test(Math.abs(numObj.value)))
  { 
	numObj.value="";
	showMsg("Sorry, " + desc + " must be numbers.", numObj.id);
	return false; 
  }
  outFocus(numObj);
  return true;
}

//called when the form is submitted
function validateAmountImpl(amountInput,desc,isRequired)
{
  amountInput.value = amountInput.value.trim();
  if (isRequired && isNull(amountInput))
  {
	showMsg(desc + " can not be empty.", amountInput.id);
	return false;
  }
  if(amountInput.value.length > 0 && !numericReg.test(Math.abs(amountInput.value)))
  { 
	showMsg("Sorry, " + desc + " must be numbers.", amountInput.id);
	return false; 
  }
  outFocus(amountInput);
  return true;
}

//called when embed keyboard is pressed
function validateKeyboardPhone()
{
  return phoneMaskImpl(targetObject);
}

//called when physical keyboard is pressed
function phoneMaskImpl(phoneInput)
{
  var evt = getEvent();
  var keyPressed=evt.keyCode || evt.charCode;
  if (keyPressed==8)
  {
      var length=phoneInput.value.length;
      var num=phoneInput.value.substring(0,length-1);
      phoneInput.value=num;
  }
  if(phoneInput.value.length == 1 && phoneInput.value.charAt(0) != "(") { phoneInput.value = "(" + phoneInput.value; }
  else if(phoneInput.value.length == 4){ phoneInput.value += ")"; }
  else if(phoneInput.value.length == 8){ phoneInput.value += "-"; }
  else if(phoneInput.value.length >= 13)
  { 
	phoneInput.value = phoneInput.value.substring(0, 13);
	outFocus(phoneInput);
  }

  phoneChars = /[()-]/g;
  tmpPhone = phoneInput.value.replace(phoneChars, "");
  if(phoneInput.value.length > 1 && !integerReg.test(tmpPhone))
  {
    showMsg("Phone number must be digits.", phoneInput.id);
	phoneInput.value="";
	return false;
  }
}

//called when the form is submitted
function validatePhoneImpl(phoneInput,isRequired)
{
  phoneInput.value = phoneInput.value.trim();
  if (isRequired && isNull(phoneInput))
  {
	showMsg("Phone number can not be empty.", phoneInput.id);
	return false;
  }
  phoneChars = /[()-]/g;
  tmpPhone = phoneInput.value.replace(phoneChars, "");
  if(!integerReg.test(tmpPhone))
  {
    showMsg("Phone number must be digits.", phoneInput.id);
	return false;
  }
  if(badPhone.test(tmpPhone)) 
  { 
	showMsg("Phone number can not<br>be all the same number.", phoneInput.id);
	return false; 
  }
  if(!validateRegExp(tmpPhone))
  { 
	showMsg("Please enter a valid phone number.", phoneInput.id);
	return false; 
  }
  if(phoneInput.value.length < 13)
  {
	showMsg("Phone number must be at least 10 digits.", phoneInput.id); 
	return false;
  }
  outFocus(phoneInput);
  return true;
}

//called when embed keyboard is pressed
function validateKeyboardDate()
{
  return dateMask(targetObject);
}

//called when physical keyboard is pressed
function dateMaskImpl(dateInput)
{
  var evt = getEvent();
  var keyPressed=evt.keyCode || evt.charCode;
  if (keyPressed==8)
  {
      var length=dateInput.value.length;
      var num=dateInput.value.substring(0,length-1);
      dateInput.value=num;
  }
  if (dateInput.value.length == 2 && dateInput.value.charAt(2) != "/") { dateInput.value = dateInput.value + "/";}
  else if(dateInput.value.length == 5) { dateInput.value += "/"; }
  else if(dateInput.value.length >= 10)
  {
	  dateInput.value = dateInput.value.substring(0,10);
	  outFocus(dateInput);
  }
  tmpChars = /[\/\/]/g;
  tmpDate = dateInput.value.replace(tmpChars, "");
  if(!integerReg.test(tmpDate))
  {
	dateInput.value="";
	dateInput.focus();
	return false;
  }
  if (dateInput.value.length>=10)
  {
    y = dateInput.value.substring(6,10);
    if (parseInt(y,10) < 1900 || parseInt(y,10) > 3000)
    {
	  dateInput.value=dateInput.value.substring(0,6);
	  showMsg("Invalid year! <br><br> 1900 - 3000 is valid now!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	  return false;
    }
  }
  if (dateInput.value.length>=5)
  {
    d = dateInput.value.substring(3,5);
    if (parseInt(d,10) > 31 || parseInt(d,10) < 1)
    {
	  dateInput.value=dateInput.value.substring(0,3);
	  showMsg("Invalid day! <br><br> 1 - 31 is valid!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	  return false;
    }
  }
  if (dateInput.value.length>=2)
  {
    m = dateInput.value.substring(0,2);
    if (parseInt(m,10) > 12 || parseInt(m,10) < 1)
    {
	  dateInput.value="";
	  showMsg("Invalid month! <br><br> 1 - 12 is valid!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	  return false;
    }
  }
  return true;
}

//called when the form is submitted
function validateDateImpl(dateInput,desc,isRequired)
{
  dateInput.value = dateInput.value.trim();
  if (isRequired && isNull(dateInput))
  {
	showMsg(desc + " can not be empty.", dateInput.id);
	return false;
  }
  tmpChars = /[\/\/]/g;
  tmpDate = dateInput.value.replace(tmpChars, "");
  if(!integerReg.test(tmpDate))
  {
    showMsg(desc + " must be digits.", dateInput.id);
	return false;
  }
  if(dateInput.value.length != 10)
  {
	showMsg(desc + " must be included 8 digits.<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id); 
	return false;
  }
  if(dateInput.value.charAt(2) != "/" || dateInput.value.charAt(5) != "/")
  {
	showMsg("Invalid date! <br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	return false;
  }
  m = dateInput.value.substring(0,2);
  d = dateInput.value.substring(3,5);
  y = dateInput.value.substring(6,10);
  if (parseInt(m,10) > 12 || parseInt(m,10) < 1)
  {
	dateInput.value="";
	showMsg("Invalid month! <br><br> 1 - 12 is valid!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	return false;
  }
  if (parseInt(d,10) > 31 || parseInt(d,10) < 1)
  {
    dateInput.value=dateInput.value.substring(0,3);
	showMsg("Invalid day! <br><br> 1 - 31 is valid!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	return false;
  }
  if (parseInt(y,10) < 1900 || parseInt(y,10) > 3000)
  {
    dateInput.value=dateInput.value.substring(0,6);
	showMsg("Invalid year! <br><br> 1900 - 3000 is valid now!<br><br>--&nbsp;The formatter should be like <font color='#FF0000'>'12/31/2009'</font>&nbsp;--", dateInput.id);
	return false;
  }
  outFocus(dateInput);
  return true;
}

//called when embed keyboard is pressed
function validateKeyboardSSN()
{
	return ssnMaskImpl(targetObject);
}

//called when physical keyboard is pressed
function ssnMaskImpl(ssnInput)
{
	var evt = getEvent();
	var keyPressed=evt.keyCode || evt.charCode;
    if(keyPressed==8)
	{ 
	  obj =	$find("socialSecurity");
	  if(obj.value.length==1)
	  {
	  	obj.value="";
	  }
	  if(obj.value.length>1)
	  {
	  	obj.value=obj.value.substring(0,obj.value.length-1);
	  	var str=obj.value.substring(ssnInput.value.length-1);
	  	ssnInput.value=ssnInput.value.substring(0,ssnInput.value.length-1)+str;
	  }
	}
	else
	{
	  if(ssnInput.value.length==1)
	  {
		  obj =	$find("socialSecurity");
		  obj.value = ssnInput.value;
	  }
      if(ssnInput.value.length>1)
      {
  	    var str=ssnInput.value.substring(ssnInput.value.length-1);
  	    obj = $find("socialSecurity");
  	    if(ssnInput.value.length == 3||ssnInput.value.length == 6)
  	    { 
  	  	  obj.value = obj.value+str+"-";
  	  	  ssnInput.value=ssnInput.value.substring(0,ssnInput.value.length-2)+"*"+str+"-";
  	    }
  	    else if(ssnInput.value.length == 5||ssnInput.value.length == 8)
  	    {
  	  	  obj.value = obj.value+str;
  	  	  ssnInput.value=ssnInput.value.substring(0,ssnInput.value.length-3)+"*-"+str;
  	    }
  	    else if(ssnInput.value.length > 11)
  	    {
  	  	  ssnInput.value = ssnInput.value.substring(0,11);
  	    }
  	    else
  	    {
  	  	  obj.value = obj.value+str;
  	  	  ssnInput.value=ssnInput.value.substring(0,ssnInput.value.length-2)+"*"+str;
  	    }
      }   
    }
    outFocus(ssnInput);
	return true;
}

function getEvent()
{
    if(document.all) return window.event;
    func=getEvent.caller;
    while(func!=null)
    {
        var arg0=func.arguments[0];
        if(arg0)
        {
		    if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
    	    {
			    return arg0;
		    }            
        }
        func=func.caller;
    }
    return null;
}

//called when the form is submitted to check if ssn is valid
function validateSSNImpl(ssnInput,isRequired)
{
	ssnObj = $find("socialSecurity");
	if (isRequired && isNull(ssnInput))
	{
		showMsg("SSN can not be empty.", ssnInput.id);
		return false;
	}
	if (ssnObj.value.length != 11)
	{
		showMsg("Invalid social security number!", ssnInput.id);
		return false;
	}
    outFocus(ssnInput);
    return true;
}

//called when the form is submitted to check if email is valid
function validateEmailImpl(emailInput,isRequired)
{
  emailInput.value = emailInput.value.trim();
  if (isRequired && isNull(emailInput))
  {
	showMsg("Email address can not be empty.", emailInput.id);
    return false;
  }
  if(!validateRegExp(emailInput))
  { 
	showMsg("Please enter a valid email address.", emailInput.id);
	return false;
  }
  outFocus(emailInput);
  return true;
}

//called when the form is submitted to check if first name is valid
function validateFirstNameImpl(firstNameInput,desc,isRequired)
{
  firstNameInput.value = firstNameInput.value.trim();
  if (isRequired && isNull(firstNameInput))
  {
	showMsg(desc + " can not be empty.",firstNameInput.id);
	return false;
  }
  if(firstNameInput.value.length < 2)
  {
	showMsg(desc + " must be longer than 1 letter.",firstNameInput.id);
	return false;
  }
  if(!validateRegExp(firstNameInput))
  { 
	showMsg("Invalid " + desc + ".",firstNameInput.id); 
	return false; 
  }
  outFocus(firstNameInput);
  return true;
}

//called when the form is submitted to check if last name is valid
function validateLastNameImpl(lastNameInput,desc,isRequired)
{
  lastNameInput.value = lastNameInput.value.trim();
  if (isRequired && isNull(lastNameInput))
  {
	showMsg(desc + " can not be empty.",lastNameInput.id);
	return false;
  }
  if(lastNameInput.value.length < 2)
  {
	showMsg(desc + " must be longer than 1 letter.",lastNameInput.id);
	return false;
  }
  if(!validateRegExp(lastNameInput))
  { 
	showMsg("Invalid " + desc + ".",lastNameInput.id); 
	return false; 
  }
  outFocus(lastNameInput);
  return true;
}

//called when the form is submitted to check if address is valid
function validateAddressImpl(addressInput,desc,isRequired)
{
  addressInput.value = addressInput.value.trim();
  if (isRequired && isNull(addressInput))
  { 
    showMsg(desc + " can not be empty.", addressInput.id);
	return false; 
  }
  if(addressInput.value == "NA")
  {
	showMsg(desc + " must not be NA.", addressInput.id); 
	return false; 
  }
  if(addressInput.value == "NONE")
  {
	showMsg(desc + " must not be NONE.", addressInput.id);
	return false; 
  }
  if(addressInput.value.length < 5)
  {
	showMsg(desc + " must be at least 5 characters.", addressInput.id);
	return false; 
  }
  if(!validateRegExp(addressInput))
  { 
	showMsg("Invalid " + desc + ".", addressInput.id);
	return false; 
  }
  outFocus(addressInput);
  return true;
}
/************************ the end **************************/