function isEmpty(str) {
   var emptyString = /^[\t\r\ ]+$/;
   if(str.length == 0 || emptyString.test(str)) {
      return true;	
   }
   else {
      return false;
   }
}

// Check if field is valid
function checkPinField(e)
{
   var correctValue = /^[0-9\-]+$/;
   if(isEmpty(e.value)) {
   document.getElementById("PinField").style.backgroundColor = "#ffffff";
   }
   else {
      if (!correctValue.test(e.value)) 
      {
         //notify about invalid data
         document.getElementById("PinField").style.backgroundColor = "#ffac9f";
      }
      else 
      {
         //correct data
         document.getElementById("PinField").style.backgroundColor = "#7cff93";
         return true;
      }		
}
return false;
}

function validatePinForm(form) {
   var field = checkPinField(form.elements["PinField"]);
   if(!field) {
      alert("Entered PIN CODE format is invalid, please provide correct one.");
      return false;
   }
   else {
      form.action += '/'+form.key.value;
      return true;
   }
}
