var EN = 2;
var RO = 1;

errcol="#FFEAEA";
fname_pattern = /^[a-zA-Z][a-zA-Z']{2,}[^']?$/
lname_pattern = /^[a-zA-Z][a-zA-Z ']{2,}[^']?$/
city_pattern = /^[a-zA-Z\-' ]{3,}$/
email_pattern = /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/
user_name_pattern=/^[a-zA-Z0-9]{1}[a-zA-Z0-9\.\_]{5,}$/
user_pattern1=/^[a-zA-Z0-9]+[\.\_]{0,1}[a-zA-Z0-9]*$/
user_pattern2=/^[a-zA-Z0-9\.\_]*[a-z]+[a-zA-Z0-9\.\_]*$/
passwd_pattern=/^[a-zA-Z0-9]{6,}$/
birth_pattern=/^\d{2}\/\d{2}\/\d{4}$/
pass_pattern=/^\d{4}$/
//'

function explode(strng, chr)
{
	myarr=new Array();
	if(strng.length > 0){
		myarr=strng.split(chr);
	}
	return(myarr);
}

function pas1_check(frm) 
{
	var err = '';
	var lang = frm._lang.value;

	frm.first_name.style.backgroundColor=frm.last_name.style.backgroundColor=frm.address.style.backgroundColor=frm.city.style.backgroundColor=frm.day.style.backgroundColor=
        frm.mounth.style.backgroundColor=frm.year.style.backgroundColor=frm.sex.style.backgroundColor=frm.education.style.backgroundColor=
		frm.profession.style.backgroundColor=frm.hear.style.backgroundColor=frm.agree.style.backgroundColor="white";
				

	// first_name //
	if(frm.first_name.value == "") {
		frm.first_name.style.backgroundColor=errcol;
		frm.first_name.focus();
		err += (lang == RO ? "Nu ati completat prenumele\n":"You didn't fill in your first name\n");
	} else {
		if(frm.first_name.value.length < 3) {
			frm.first_name.style.backgroundColor = errcol;
			if(err == "") {
				frm.first_name.focus();
				frm.first_name.select();
			}
			err += (lang == 1 ? "Prenumele contine mai putin de 3 caractere\n":"Your first name length is less than 3 characters\n");
		}
		if(!fname_pattern.test(frm.first_name.value)) {
			frm.first_name.style.backgroundColor=errcol;
			if(err == "") {
				frm.first_name.focus();
				frm.first_name.select();
			}
			err += (lang == 1 ?
				"Prenumele dumneavoastra este invalid(caractere admise: a-z, A-Z,')\n":
				"Your first name is invalid(admited charaters are: a-z,A-Z,')\n");			
		}
	}
	// last_name //
	if(frm.last_name.value == "") {
		frm.last_name.style.backgroundColor=errcol;
		frm.last_name.focus();
		err += (lang == RO ? "Nu ati completat numele\n":"You didn't fill in your last name\n");
	} else {
		if(frm.last_name.value.length < 3) {
			frm.last_name.style.backgroundColor = errcol;
			if(err == "") {
				frm.last_name.focus();
				frm.last_name.select();
			}
			err += (lang == 1 ? "Numele contine mai putin de 3 caractere\n":"Your last name length is less than 3 characters\n");
		}
		if(!lname_pattern.test(frm.last_name.value)) {
			frm.last_name.style.backgroundColor=errcol;
			if(err == "") {
				frm.last_name.focus();
				frm.last_name.select();
			}
			err += (lang == 1 ?
				"Numele dumneavoastra este invalid(caractere admise: a-z, A-Z,', )\n":
				"Your last name is invalid(admited charaters are: a-z,A-Z,', )\n");			
		}
	}
	// address //
	if(frm.address.value == "") {
		frm.address.style.backgroundColor=errcol;
		if(err=="") {
			frm.address.focus();
		}
		err += (lang == RO ? "Nu ati completat adresa\n":"You didn't fill in your address\n");
	} 
	// city //
	if(frm.city.value == "") {
		frm.city.style.backgroundColor=errcol;
		if(err=="") {
			frm.city.focus();
		}
		err += (lang == RO ? "Nu ati completat orasul\n":"You didn't fill in your city\n");
	} else {
		if(!city_pattern.test(frm.city.value)) {
			if(err == "") {
				frm.city.focus();
				frm.city.select();
			}
			err += (lang == 1 ?
				"Numele orasului este invalid(caractere admise: a-z, A-Z, ,',-)\n":
				"City's name is invalid(admited charaters are: a-z,A-Z, ,',-)\n");
		}
	}
	// bday //
	if(frm.day.value=="") {
		frm.day.style.backgroundColor=errcol;
		if(err == "") {
			frm.day.focus();
		}
		err += (lang == 1 ? "Nu ati selectat ziua de nastere\n":"You didn't select your birth day\n");
	}
	// bmounth //
	if(frm.mounth.value == "") {
		frm.mounth.style.backgroundColor=errcol;
		if(err == "") {
			frm.mounth.focus();
		} 
		err += (lang==1 ? "Nu ati selectat luna de nastere\n":"You didn't select your birth mounth\n");
	}
	// byear //
	if(frm.year.value == "") {
		frm.year.style.backgroundColor=errcol;
		if(err == "") {
			frm.year.focus();
		} err += (lang==1 ? "Nu ati selectat anul nasterii\n":"You didn't select your birth year\n");
	}
	// sex //
	if(frm.sex.value=="") {
		frm.sex.style.backgroundColor=errcol;
		if(err == "") {
			frm.sex.focus();
		}
        	err += (lang == 1 ? "Nu ati selectat sexul\n":"You didn't select your sex\n");
	}
	// education //
	if(frm.education.value=="") {
		frm.education.style.backgroundColor=errcol;
		if(err == "") {
			frm.education.focus();
		}
		err += (lang == 1 ? "Nu ati selectat educatia\n":"You didn't select your education\n");
	}
	// profession //
	if(frm.profession.value=="") {
		frm.profession.style.backgroundColor=errcol;
		if(err == "") {
			frm.profession.focus();
		}
		err += (lang == 1 ? "Nu ati selectat profesia\n":"You didn't select your profession\n");
	}
	// hear //
	if(frm.hear.value=="") {
		frm.hear.style.backgroundColor=errcol;
		if(err == "") {
			frm.hear.focus();
		}
		err += (lang == 1 ? "Nu ati raspuns la intrebarea 'Cum ati auzit despre noi'\n":"You didn't answered to the question 'How did you hear about us?'\n");
	}
	// agree ? //
	if(frm.agree.checked==false) {
		frm.agree.style.backgroundColor=errcol;
		if(err == "") {
			frm.agree.focus();
		}
		err += (lang == 1 ? "Nu ati bifat casuta de acord\n":"You didn't check the agreement's box\n");
	}
		
	if(err.length > 0) {
	 	alert(err);
		return(false);
	}
	return(true);
}


function pas2_check(frm) 
{

	var lang = frm._lang.value;
	var err = "";
	var user = "";
	frm.idn.style.backgroundColor=frm.passwd.style.backgroundColor=frm.passwd_again.style.backgroundColor=frm.question.style.backgroundColor=
	frm.answer.style.backgroundColor=frm.alter_email.style.backgroundColor=frm.secure_code.style.backgroundColor="white";
	j=4;

	if(frm.ids) {
		if(frm.ids.length) {
		for(i=0; i<frm.ids.length;i++) {
			if(frm.ids[i].checked==true) {
				j=i;
				switch(frm.ids[i].value) {
					case '0': user=frm.n1.value.substring(0,1) + frm.n2.value; break;
					case '1': user=frm.n2.value.substring(0,1) + frm.n1.value; break;
					case '2': user=frm.n1.value + "." + frm.n2.value; break;
					case '3': user=frm.n2.value + "." + frm.n1.value; break;
					case '4': user=frm.idn.value; break;
				}
			}
		}
		} else {
			user=frm.idn.value;
		}
	} else {
		user=frm.idn.value;
	}
	
	if(user.length==0) {
		err += (lang == RO ? "Nu ati introdus/selectat numele de utilizator\n":"You didn't input/select login id\n");
	} else if (user.length < 6) {
		err += (lang == RO ? "Numele de utilizator este mai mic de 6 caractere\n" : "Your username is less than 6 characters\n");
	} else if(user.length < 30) {
		if(user_pattern1.test(user)) {
			if(user.length >=8 && user.length <= 30) {
				if(!user_pattern2.test(user)) {
					err_msg+=(lang == RO ? "" : "Usernames of 8 or more characters must include at least one alphabetical character!");
				}
			}
		} else {
			err += (lang == RO ? "Nume utilizator invalid (utilizati doar a-z,A-Z,0-9 si maxim 1 '.')\n" : "Invalid username (use only a-z, A-Z, 0-9 and max 1 '.')\n");
		}
	} else {
		err += (lang == RO ? "Numele de utilizator este mai mare de 30 caractere\n" : "Your username has more than 30 characters\n");
	}

	if(err.length > 0) {
		if(j == 4) {
			frm.idn.style.backgroundColor=errcol;
			frm.idn.select();
			frm.idn.focus();
		} else {
			frm.ids[j].style.backgroundColor=errcol;
			frm.ids[j].focus();
		}
	}
	
	if(frm.passwd.value=="") {
		frm.passwd.style.backgroundColor=errcol
			if(err=="") {
				frm.passwd.focus();
			}
			err += (lang == RO ? "Nu ati ales nici o parola\n" : "You didn't choose any password\n");
	} else if(frm.passwd.value.length < 6) {
		frm.passwd.style.backgroundColor=errcol;
		if(err=="") {
			frm.passwd.focus();
			frm.passwd.select();
		}
		err += (lang == RO ? "Parola aleasa este mai mica de 6 caractere\n" : "Your password has less than 6 characters\n");
	}
	
	if(frm.passwd_again.value=="") {
		frm.passwd_again.style.backgroundColor=errcol;
		if(err=="") {
			frm.passwd_again.focus();
		}
		err += (lang == RO ? "Nu ati confirmat parola\n" : "You didn't confirm your password\n");
	} else if((frm.passwd.value.length>=6) && (frm.passwd.value!=frm.passwd_again.value)) {
		frm.passwd.style.backgroundColor=frm.passwd_again.style.backgroundColor=errcol;
		if(err == "") {
			frm.passwd_again.focus();
			frm.passwd_again.select();
		}
		err += (lang == RO ? "Parolele nu coincid\n":"Passwords does not mach\n");
	} else if((frm.passwd.value.length>=6) && (!passwd_pattern.test(frm.passwd.value))) {
		if(err == "") {
			frm.passwd.focus();
			frm.passwd.select();
		}
		err += (lang == RO ? "Parola invalida: folositi caractere (a-z) si numere(0-9)\n" : "Invalid password: use only (a-z) and digits (0-9)\n");
	}

	
	if(frm.question.value=="") {
		frm.question.style.backgroundColor=errcol;
		if(err=="") {
			frm.question.focus();
		}
		err+=(lang==RO ? "Nu ati selectat nici o intrebare secreta\n" : "You didn't select any secret questionstion\n");
	}
	
	if(frm.answer.value==""){
		frm.answer.style.backgroundColor=errcol;
		if(err=="") {
			frm.answer.focus();
		}
		err+=(lang==RO ? "Nu ati raspuns la intrebarea secreta\n" : "You didn't answer to the secret question\n");
	} else {
		er=false;
		switch(frm.question.value) {
			case '0': // place of birth //
				if(!city_pattern.test(frm.answer.value)) {
					err+=(lang==RO ? "Orasul introdus este invalid\n" : "Your birth city is invalid\n");
					er=true;
				}
				break;
            case '1': // date of birth dd/mm/yyyy
				if(birth_pattern.test(frm.answer.value)) {
					date=explode(frm.answer.value,'/');
					day=parseInt(date[0]);
					mounth=parseInt(date[1]);
					year=parseInt(date[2]);
					if(day > 0 && day <= 31 && mounth > 0 && mounth <= 12 && year >= 1900 && year <= 2005)
						break;
				}
				err+=(lang==RO ? "Data de nastere este invalida\n" : "Your birth day is invalid\n");
				er=true;
				break;
			case '2': // last 4 digits.
				if(!pass_pattern.test(frm.answer.value)) {
					err+=(lang==RO ? "Ultimile 4 cifre ale pasaportului sunt invalide\n" : "The last 4 digits of the passport number are invalid\n");
					er=true;
				}
				break;
			default: break;
		}
		if(er) {
			frm.answer.style.backgroundColor=errcol;
			if(err=="") {
				frm.answer.focus();
				frm.answer.select();
			}
		}
	}	
	
	if(frm.alter_email.value=="") {
		frm.alter_email.style.backgroundColor=errcol;
		if(err=="") {
			frm.alter_email.focus();
		}
		err += (lang == RO ? "Nu ati introdus adresa de email alternativa\n" : "You didn't fill in alternative email addressess\n");
	} else if(!email_pattern.test(frm.alter_email.value)) {
		frm.alter_email.style.backgroundColor=errcol;
		if(err == "") {
			frm.alter_email.focus();
			frm.alter_email.select();
		}
		err += (lang == RO ? "Adresa de email alternativa este invalida\n" : "Alternative email addressess is invalid\n");
	}
	
	if(frm.secure_code.value=="") {
		frm.secure_code.style.backgroundColor=errcol;
		if(err=="") {
			frm.secure_code.focus();
		}
		err+=(lang==RO ? "Nu ati introdus codul de securitate\n" : "You didnt fill in security code\n");
	} 
		
	if(err.length > 0) {
		alert(err);
		return(false);
	}
	return(true);
}


function pas3_check(frm) 
{
}
