
/*  Standard functions  */

function top() {
  window.scrollTo(0, 0);
}

function back() {
  history.back();
}

function newWindow(url,width,height)
{
  width   = ( width ) ? width: 300;
  height  = ( height ) ? height: 200;
  eval("var f=window.open('slika.asp?s=" + url + "','slike','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + width + ",height=" + height + "');f.focus();");
}

function trim (string) {
// If the string is not empty
  if (string) {
    return string.replace(/^\s*|\s*$/g, "");
  }
  else {
    return "";
  }
}

function isValidEmailAddress (emailAddress) {
  // If a simple regular expression doesn't work
  if(!new RegExp(/^test$/).test("test")) {
    return true;
  }
  
  // If the email address is empty
  if (trim(emailAddress) == "") {
    return false;
  }
  else {
    return new RegExp(/^[^@]+@[^@]+\.[^@]{2,}$/).test(trim(emailAddress));
  }
}

function checkForm() {
  fali = "";
  if ( document.ecard.posIme.value == "" ) {
    fali = fali + "\n- Vaše ime";
  }
  if ( document.ecard.posMail.value == "" ) {
    fali = fali + "\n- Vašu e-mail adresu";
  }
  else {
    if (!isValidEmailAddress(document.ecard.posMail.value)) fali = fali + "\n- Vaša e-mail adresa nije pravilno unesena";
  }
  if ( document.ecard.primMail.value == "" ) {
    fali = fali + "\n- E-mail osobe kojoj želite poslati poruku";
  }
  else {
    if (!isValidEmailAddress(document.ecard.primMail.value))   fali = fali + "\n- E-mail osobe kojoj šaljete poruku nije pravilno unesena";
  }
  if (document.ecard.subject.value == "") fali = fali + "\n- Naziv poruke";
  if (document.ecard.poruka.value == "")   fali = fali + "\n- Tekst poruke";
  
  if (fali != "")
    alert("Niste upisali sve potrebne podatke!" + "\n\n" + "Molimo upišite:" + fali)
  else
    document.ecard.submit();
}