// JavaScript Document
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

/* Allow numbers, spaces, ()'s and - */
function checkPhoneNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  /* space, -, ( and ) are ok */
  if (cCode == 32 || cCode == 40 || cCode == 41 || cCode == 45) { return false; }

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

// Many forms use state/province, this sets disabled-ness as required
function changeStateSelect()
{
   var state = document.getElementById('state').value;
   if(state != 'N/A')
   {
     document.getElementById('province').disabled = true;
     document.getElementById('province').value='';
   }
   else
   {
     document.getElementById('province').disabled = false;
   }
}

// Script to run when the DOM is loaded and ready
window.addEvent('domready', function() {

	var pageTips = new Tips($$('.pgTip'),{
		className: 'pgTip',
		showDelay: 0,
		hideDealy: 0,
		offsets: {'x': 12, 'y': 12}
	});
	pageTips.addEvent('show', function(tip){
		tip.fade('in');
	});
	pageTips.addEvent('hide', function(tip){
		tip.fade('out');
	});
});