﻿function highlightImage(imageId, src) {
    var image = document.getElementById(imageId);
    image.src = 'images/' + src;
}

function blurImage(imageId, src) {
    var image = document.getElementById(imageId);
    image.src = 'images/' + src;
}

function validateTextbox(element) { 
    var textboxValue = trim(element.value);
       
    if (textboxValue == '' || textboxValue == 'Required') {
        element.value = 'Required';
        element.style.backgroundColor = '#FF5967';
        return;
    }
    else {
        element.style.backgroundColor = '#FFFFFF';
    }
}

function clearTextboxValidationMessage(element) {
    var textboxValue = trim(element.value);
    
    if (textboxValue == 'Required') {
        element.value = '';
        element.style.backgroundColor = '#FFFFFF';
    }
}

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function numbersOnly(e, allowDash) {
  var evt = (e) ? e : window.event;
  var key = (evt.keyCode) ? evt.keyCode : evt.which;

  if(key != null) {
    key = parseInt(key, 10);

    if((key < 48 || key > 57) && (key < 96 || key > 105)) {
      if(!isUserFriendlyChar(key, allowDash))
        return false;
    }
    else {
      if(evt.shiftKey)
        return false;
    }
  }

  return true;
}

function isUserFriendlyChar(val, allowDash) {
  // Backspace, Tab, Enter, Insert, and Delete
  if(val == 8 || val == 9 || val == 13 || val == 45 || val == 46)
    return true;

  // Ctrl, Alt, CapsLock, Home, End, and Arrows
  if((val > 16 && val < 21) || (val > 34 && val < 41))
    return true;
    
  // -
  if (allowDash && val == 109)
    return true;

  // The rest
  return false;
}

