// Function which validates an email address
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

// cross-browser for getElementById
function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

//function which blocks input to a restricted list of characters
function specialchars(myfield, e, dec, special)
{
	var key;
	var keychar;
	
	if (window.event)
		 key = window.event.keyCode;
	else if (e)
		 key = e.which;
	else
		 return true;
	keychar = String.fromCharCode(key);
	
	chars = "0123456789";
	if(special)
		chars += special;
	
	// control keys
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
		return true;
	// numbers & special chars
	else if((chars.indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if(dec && (keychar == ".") && myfield.value.indexOf(".") == -1)
		return true;
	else
		return false;
}

// validarea formularului
function validateFeedback()
{
	d = xGetElementById("contact_form");
	if(d.nume.value == "")
	{
		alert("Nu ati completat numele !");
		d.nume.focus();
		return false;
	}
	if(d.email.value == "")
	{
		alert("Nu ati completat adresa de email !");
		d.email.focus();
		return false;
	}
	if(!isEmailAddr(d.email.value))
	{
		alert("Adresa de email este invalida !");
		d.email.focus();
		return false;
	}
	if(d.subiect.value == "")
	{
		alert("Nu ati completat subiectul !");
		d.subiect.focus();
		return false;
	}
	if(d.mesaj.value == "")
	{
		alert("Nu ati completat mesajul !");
		d.mesaj.focus();
		return false;
	}
	if(d.check.value == "")
	{
		alert("Nu ati completat codul de verificare (anti-spam) !");
		d.check.focus();
		return false;
	}
	return true;
	//d.submit();
}
