/*
Strip whitespace from the beginning and end of a string
*/
function trim(str){
   return str.replace(/^\s+|\s+$/g,'');
}

/*
   Check if a string is in valid email format. 
*/
function isEmailValid(email){
  var indexOfPoint = email.lastIndexOf('.');
  var indexOfAt = email.indexOf('@');
  return ((indexOfAt > 2) && (indexOfPoint > (indexOfAt + 2))); 
}

function isValidJpgFile(file){
  return file.length > 4 && (file.lastIndexOf('.jpg') == (file.length - 4));
}

function esteNumeleValid(name){
  return name.length >= 3;
}

function confirmDelete(description){
  return confirm("Esti sigur ca vrei sa stergi " + description); 
}

function containsLink(text){
  return text.indexOf("http://") >= 0 || text.indexOf("www.") >= 0;
}

function replaceUnallowedChars(text) {
  return text.replace(/'/g, "`").replace(/"/g, "&quot;");
}

function esteTelefonValid(phone){
  var nrOfDecimals = 0;
  for (var i = 0; i < phone.length; i++){
    if (phone.charAt(i) >= '0' && phone.charAt(i) <= '9'){
      nrOfDecimals++;
    }
  }
  return nrOfDecimals >= 10;
}
