﻿function validate()
{
  var theForm=document.aspnetForm;
  if(theForm.ctl00$ContentPlaceHolder1$txtOrgNo.value=="")
  {
    alert("Vennligst fyll inn Org. Nr.");
    theForm.ctl00$ContentPlaceHolder1$txtOrgNo.focus();
    return false;
  }
  if(theForm.ctl00$ContentPlaceHolder1$txtcptname.value=="")
  {
    alert("Vennligst fyll inn feltet Navn.");
    theForm.ctl00$ContentPlaceHolder1$txtcptname.focus();
    return false;
  }
 if(theForm.ctl00$ContentPlaceHolder1$txtcctName.value=="")
  {
    alert("Vennligst fyll inn feltet Kontaktperson.");
    theForm.ctl00$ContentPlaceHolder1$txtcctName.focus();
    return false;
  }
  if(theForm.ctl00$ContentPlaceHolder1$txtcctTitle.value=="")
  {
    alert("Vennligst fyll inn feltet Tittel.");
    theForm.ctl00$ContentPlaceHolder1$txtcctTitle.focus();
    return false;
  }
  if(theForm.ctl00$ContentPlaceHolder1$txtAdr1.value=="")
  {
    alert("Vennligst fyll inn Besøksadresse.");
    theForm.ctl00$ContentPlaceHolder1$txtAdr1.focus();
    return false;
  }
   if(theForm.ctl00$ContentPlaceHolder1$txtPnrAdr1.value=="")
  {
    alert("Vennligst fyll inn feltet Postnr.");
    theForm.ctl00$ContentPlaceHolder1$txtPnrAdr1.focus();
    return false;
  }
   if(theForm.ctl00$ContentPlaceHolder1$txtcptPareaAdr1.value=="")
  {
    alert("Vennligst fyll inn feltet Poststed.");
    theForm.ctl00$ContentPlaceHolder1$txtcptPareaAdr1.focus();
    return false;
  }
  
   if(theForm.ctl00$ContentPlaceHolder1$txtcptAdr2.value=="")
  {
    alert("Vennligst fyll inn feltet Postadresse.");
    theForm.ctl00$ContentPlaceHolder1$txtcptAdr2.focus();
    return false;
  }
   if(theForm.ctl00$ContentPlaceHolder1$txtcptPnrAdr2.value=="")
  {
    alert("Vennligst fyll inn feltet Postnr.");
    theForm.ctl00$ContentPlaceHolder1$txtcptPnrAdr2.focus();
    return false;
  }
   if(theForm.ctl00$ContentPlaceHolder1$txtcptPareAdr2.value=="")
  {
    alert("Vennligst fyll inn feltet Poststed.");
    theForm.ctl00$ContentPlaceHolder1$txtcptPareAdr2.focus();
    return false;
  }
  
//  if(theForm.ctl00$ContentPlaceHolder1$txtcptEmail.value=="")
//  {
//    alert("Vennligst fyll inn feltet E-post.");
//    theForm.ctl00$ContentPlaceHolder1$txtcptEmail.focus();
//    return false;
//  }
//   else 
   if(theForm.ctl00$ContentPlaceHolder1$txtcptEmail.value!="" && !isEmailValid(theForm.ctl00$ContentPlaceHolder1$txtcptEmail.value))
    {
	    alert("Please enter a valid e-mail address.");
	    theForm.ctl00$ContentPlaceHolder1$txtcptEmail.focus();
	    return false;	
	}
  
//  if(theForm.ctl00$ContentPlaceHolder1$txtcptHomepage.value=="")
//  {
//    alert("Please fill in the field site.");
//    theForm.ctl00$ContentPlaceHolder1$txtcptHomepage.focus();
//    return false;
//  }
//  if(theForm.ctl00$ContentPlaceHolder1$txtMerInfo.value=="")
//  {
//    alert("Vennligst fyll inn feltet More Information.");
//    theForm.ctl00$ContentPlaceHolder1$txtMerInfo.focus();
//    return false;
//  }
  
if(theForm.ctl00$ContentPlaceHolder1$txtname.value=="")
  {
    alert("Please fill in your name field.");
    theForm.ctl00$ContentPlaceHolder1$txtname.focus();
    return false;
  }

  if(theForm.ctl00$ContentPlaceHolder1$txtemail.value=="" && theForm.ctl00$ContentPlaceHolder1$txtphone.value=="")
  {
    //alert("Vennligst fyll inn feltet Ditt telefonnr.");
    alert("Your phone or your e-mail address are required.");
    theForm.ctl00$ContentPlaceHolder1$txtphone.focus();
    return false;
  }
  
//if(theForm.ctl00$ContentPlaceHolder1$txtemail.value=="")
//  {
//    alert("Vennligst fyll inn feltet Din epostadresse.");
//    theForm.ctl00$ContentPlaceHolder1$txtemail.focus();
//    return false;
//  }
//  else
//  {
        if(theForm.ctl00$ContentPlaceHolder1$txtemail.value!="" && !isEmailValid(theForm.ctl00$ContentPlaceHolder1$txtemail.value))
	    {
		    alert("Vennligst skriv inn en gyldig Din epostadresse.");
		    theForm.ctl00$ContentPlaceHolder1$txtemail.focus();
		    return false;	
		}
  
//  }
  if(theForm.ctl00$ContentPlaceHolder1$txtComments.value=="")
  {
    alert("Vennligst fyll inn feltet Dine kommentarer.");
    theForm.ctl00$ContentPlaceHolder1$txtComments.focus();
    return false;
  }
  return true;
  
}
function isEmailValid(sEmail) 
{
	if (sEmail.value == '' || sEmail.indexOf('.') == 0 || sEmail.indexOf('.') == -1 || sEmail.indexOf('@') == 0 || sEmail.indexOf('@') == -1 || sEmail.indexOf('.') == sEmail.length - 1 || sEmail.indexOf(',') >= 0) 
	return false;	
	else 

	return true;
}	

