
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }



 function checkZip(zip) { // SUOMI
   if(zip.length >=1) {
  	 return true;
 }
 return false;	 
}
 
function checkDate(da,mo,yr) {
 
//  try {
 //  var myDate=new Date();
 // myDate.setYear(yr);
//   myDate.setMonth(mo-1)
//   myDate.setDate(da);    

//  return (myDate.getDate() == (da) && myDate.getYear() == (yr-1900) && myDate.getMonth() == (mo-1));
 // } catch(err) {
  //  ;
// }
if(da >0 && mo > 0 && yr > 0) 
 return true;

return false;
}

function isValidEmail(str) {

   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
 


}


 function checkForm(formi) {
  var ec =0;	
  var ea=new Array(); 
  var emsg="";
  box=eval("formi.confirm");
  if(!box.checked) {
   ea[ec++] = "Du må akseptere vilkårene";
 } 
 if (formi.store_id.value=="0") {
 ea[ec++] = "Velg ditt varehus";
  formi.store_id.style.backgroundColor="#FDDFEE"; 
}
 if (formi.con_password.value != formi.user_password.value || formi.user_password.value.length<=0) {
   formi.con_password.style.backgroundColor="#FDDFEE"; 
   formi.user_password.style.backgroundColor="#FDDFEE"; 
   
   ea[ec]="Gjentatt passord samsvarer ikke.";
   ec++; 

  }
 
if(formi.con_email.value != formi.user_email.value || !isValidEmail(formi.user_email.value) ) {
   
   ea[ec]="Gjentatt e-postadresse samsvarer ikke.";
   formi.con_email.style.backgroundColor="#FDDFEE"; 
   formi.user_email.style.backgroundColor="#FDDFEE"; 
   ec++; 

  }

 if(!checkZip(formi.user_address_zip.value)) {
   ea[ec]="Ugyldig postnummer."; 
   formi.user_address_zip.style.backgroundColor="#FDDFEE";	
   ec++; 
 } 

 if(!checkDate(formi.user_birthday_day.value, formi.user_birthday_month.value, formi.user_birthday_year.value)) {
   formi.user_birthday_day.style.backgroundColor="#FDDFEE";	
   formi.user_birthday_month.style.backgroundColor="#FDDFEE";	
   formi.user_birthday_year.style.backgroundColor="#FDDFEE";	
   ea[ec++]="Ugyldig dato: "+ formi.user_birthday_day.value + "." + formi.user_birthday_month.value + "." + formi.user_birthday_year.value + ".";
 } 
 if(formi.user_gender.value=="----") {
  formi.user_gender.style.backgroundColor="#FDDFEE";	
  ea[ec++]="Velg kjønn";
 }	
 if(formi.user_name_firstname.value.length <=0) {
  formi.user_name_firstname.style.backgroundColor="#FDDFEE";
  ea[ec++]="Mangler fornavn";
 }

 if(formi.user_name_surname.value.length <= 0) {
  formi.user_name_surname.style.backgroundColor="#FDDFEE"
  ea[ec++]="Mangler etternavn";
 }

 if(formi.user_address_street1.value.length<=0) {
  ea[ec++]="Mangler vei-/gatenavn";
 formi.user_address_street1.style.backgroundColor="#FDDFEE";
 }

 if(formi.user_address_city.value.length<=0) {
  ea[ec++]="Mangler poststed";
  formi.user_address_city.style.backgroundColor="#FDDFEE";	
 }
 if(formi.answer.value.length <=0) {
  ea[ec++] = "Mangler tekst fra valideringsbilde"; 
 formi.answer.style.backgroundColor="#FDDFEE";
 }

 if(formi.user_gsm.value.length <=0) {
  ea[ec++] = "Mangler mobiltelefonnummer"; 
 formi.user_gsm.style.backgroundColor="#FDDFEE";
 }

 if(ec == 0) {	
   return true;
 }

 for (j=0;j<ec;j++) {	
   emsg += ea[j] +"\n"; 
 }
 alert(emsg);
 return false;
}
