// JavaScript Document

function NewWindow(mypage, myname, w, h, scroll){
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=1';
  window.open(mypage, myname.replace(' ', '_'), settings);
}

function validateForm()
{
  error = document.getElementById('Error');

  if(document.contact.nume.value == '' || document.contact.nume.value == 'Nume')
  {
    error.innerHTML = 'Numele nu a fost introdus';
//    alert('Numele nu a fost introdus ++ '+ document.contact.nume.value);
    return false;
  }

  if(document.contact.telefon.value == '' || document.contact.telefon.value == 'Telefon')
  {
    error.innerHTML = 'Numarul de telefon nu a fost introdus';
//    alert('Numele nu a fost introdus ++ '+ document.contact.nume.value);
    return false;
  }

  if(document.contact.email.value == '' || document.contact.email.value == 'Email')
  {
    error.innerHTML = 'Adresa de Email nu a fost introdusa';
//    alert('Numele nu a fost introdus ++ '+ document.contact.nume.value);
    return false;
  }

  if(!echeck(document.contact.email.value))
  {
    error.innerHTML = 'Adresa de Email este invalida';
//    alert('Numele nu a fost introdus ++ '+ document.contact.nume.value);
    return false;
  }
  error.innerHTML = '';

  return true;
}

function echeck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		if (lat==-1 || lat==0 || lat==lstr){
		   return false
		}

		if (ldot == -1 || ldot == 0 || ldot == lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true
	}

function submitenter(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13){
      myfield.form.submit();
      return false;
  }
  else
    return true;
}

