// JavaScript Document


var d=new Date();
var monthname=new Array("janvārī","februārī","martā","aprīlī","maijā","jūnijā","jūlijā","augustā","septembrī","oktobrī","novembrī","decembrī");

var TODAY =  d.getFullYear() + ". g. " + d.getDate() + ". " + monthname[d.getMonth()];

function checkWholeForm(theForm,theCode) {
    var why = "";

//    why += checkPhone(theForm.phone.value);
//    why += checkUsername(theForm.username.value);
      why += isEmptyVards(theForm.Vards.value);
	  why += checkEmail(theForm.epasts.value);
      why += checkPassword(theForm.pieejaskods.value,theCode);
	  why += isEmptypazinojums(theForm.pazinojums.value);
//    why += isDifferent(theForm.different.value);
//    for (i=0, n=theForm.radios.length; i<n; i++) {
//        if (theForm.radios[i].checked) {
//            var checkvalue = theForm.radios[i].value;
//            break;
//        } 
//    }
//    why += checkRadio(checkvalue);
//    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Lūdzu ierakstiet Jūsu e-pasta adresi!\nYou didn't enter an email address.\n\n";
   return error;
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Lūdzu ierakstiet Jūsu e-pasta adresi!\nPlease enter a valid email address.\n\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Lūdzu ierakstiet Jūsu e-pasta adresi!\nThe email address contains illegal characters.\n\n";
       }
    }
return error;
} 

// non-empty Vards

function isEmptyVards(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Lūdzu ierakstiet Jūsu vārdu!\nPlease enter your name.\n\n"
  }
return error;	  
}

// non-empty pazinojums

function isEmptypazinojums(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Lūdzu ierakstiet Jūsu tekstu!\nPlease enter your message.\n\n"
  }
return error;	  
}

// Check password

function checkPassword(parole,theCode) {
	var error = "";
  if (parole!= theCode) {
     error = "Pārbaudiet drošības kodu!\nPlease check the Security code.\n\n"
  }
	return error;
}
