
function emptystr(theElement) {
	if  ((theElement==null) || (theElement.length == 0))
		return true;
	else
		return false;
}

//formulat de contact
function isEmail(theElement, theElementName) {
  str = theElement.value;
  if (!(result = ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1)))) {
    alert( theElementName + " trebuie sa fie de forma:\nex: nume@domeniu.ro" );
    theElement.focus();
  } 
  return result;
}

function isString(theElement, theElementName) {
   var newValue = theElement.value;
   var newLength = newValue.length;
   var extraChars=new String(",.- ");
   var search;
   for(var i = 0; i != newLength; i++) {
      aChar = newValue.substring(i,i+1);
      search = extraChars.indexOf(aChar);
      aChar = aChar.toUpperCase();
      if(search == -1 && (aChar < "A" || aChar > "Z") ) {
        alert( "ATENTIE!\n" + theElementName +  " trebuie sa contina doar litere!" );
	    theElement.focus(); 
	 	return false;
      }
   }
   return true;
}

function isNumber(theElement, theElementName)
{
  s = theElement.value;
  if ( (s == "") || (isNaN(Math.abs(s)) && (s.charAt(0) != '#')))
  {
      if ( isNumber.arguments.length  == 1 ) 
         alert( " Valoarea trebuie sa fie un numar." );
      else  
         alert( theElementName +  " trebuie sa fie de tip numeric!\nex: 0740123456 pentru mobil\nsau 0264123456 pentru fix" );
    theElement.focus(); 
    return false;
  }
  return true;
}

function verifica(){
	if (emptystr(document.all.item("nume").value)){
		alert('Va rugam sa va introduceti numele!');
		document.newform.nume.focus();
		return false;
	}
	else 
	if(!isString(document.all.item("nume"),'Numele')) return false;	
	
	if (emptystr(document.all.item("email").value)){
		alert('Va rugam  sa va introduceti adresa de e-mail!');
		document.newform.email.focus();
		return false;
	}
	else 
	if(!isEmail(document.all.item("email"), 'Emailul'))	return false;
	
	if (emptystr(document.all.item("telefon").value)){
		alert('Va rugam  sa va introduceti numarul de telefon!');
		document.newform.telefon.focus();
		return false;
	}
	else 
	if(!isNumber(document.all.item("telefon"), 'Telefonul')) return false;

	if (emptystr(document.all.item("subiect").value)){
		alert('Va rugam sa introduceti subiectul mesajului!');
		document.newform.subiect.focus();
		return false;
	}
			
	if (emptystr(document.all.item("mesaj").value)){
		alert('Va rugam  sa va introduceti mesajul!');
		document.newform.mesaj.focus();
		return false;
	}

	if (emptystr(document.all.item("verification").value)){
		alert('Va rugam sa introduceti numarul de verificare!');
		document.newform.verification.focus();
		return false;
	}
	else 
	if(!isNumber(document.all.item("verification"))) return false;

	return true;
}

//contact form
function isEmail(theElement, theElementName) {
  str = theElement.value;
  if (!(result = ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1)))) {
    alert( "ATTENTION!\n" + theElementName + " must be like:\nex: name@domain.com" );
    theElement.focus();
  } 
  return result;
}

function isString(theElement, theElementName) {
   var newValue = theElement.value;
   var newLength = newValue.length;
   var extraChars=new String(".-, ");
   var search;
   for(var i = 0; i != newLength; i++) {
      aChar = newValue.substring(i,i+1);
      search = extraChars.indexOf(aChar);
      aChar = aChar.toUpperCase();
      if(search == -1 && (aChar < "A" || aChar > "Z") ) {
        alert( "ATTENTION!\n" + theElementName +  " have to be composed of letters !" );
	    theElement.focus(); 
	 	return false;
      }
   }
   return true;
}

function isNumber(theElement, theElementName)
{
  s = theElement.value;
  if ( (s == "") || (isNaN(Math.abs(s)) && (s.charAt(0) != '#')))
  {
      if ( isNumber.arguments.length  == 1 ) 
         alert( "The value has to be a number" );
      else  
         alert( "ATTENTION!\n" + theElementName +  " have to be composed of numbers!\nex: 40740123456 for mobile\nor 40264123456 for phone" );
    theElement.focus(); 
    return false;
  }
  return true;
}

function verify(){
	if (emptystr(document.all.item("nume").value)){
		alert('Please enter your name !');
		document.newform.nume.focus();
		return false;
	}
	else 
	if(!isString(document.all.item("nume"),'The name')) return false;	

	if (emptystr(document.all.item("email").value)){
		alert('Please enter your e-mail !');
		document.newform.email.focus();
		return false;
	}
	else 
	if(!isEmail(document.all.item("email"), 'The e-mail'))	return false;
	
	if (emptystr(document.all.item("telefon").value)){
		alert('Please enter your phone number !');
		document.newform.telefon.focus();
		return false;
	}
	else 
	if(!isNumber(document.all.item("telefon"), 'The phone number')) return false;

	if (emptystr(document.all.item("subiect").value)){
		alert('Please enter a subject for your message !');
		document.newform.subiect.focus();
		return false;
	}

	if (emptystr(document.all.item("mesaj").value)){
		alert('Please enter your message !');
		document.newform.mesaj.focus();
		return false;
	}

	if (emptystr(document.all.item("verification").value)){
		alert('Please enter the verification code !');
		document.newform.verification.focus();
		return false;
	}
	else 
	if(!isNumber(document.all.item("verification"))) return false;

	return true;
} 

//////////////////////

function textCounter(field, cntfield, maxlimit)
{	
	if (field.value.length > maxlimit)
	{
	field.value = field.value.substring(0, maxlimit);
	}
	else
	{
	cntfield.value = maxlimit - field.value.length;
	}
}

/////////////////////