function valid_login(form) {
	if (form.username.value == "") {
		alert ("Va rugam completati campul User");
		form.username.focus();
		return false;
	}
	if (form.password.value == "") {
		alert ("Va rugam completati campul Parola");
		form.password.focus();
		return false;
	}
	return true;
}

function valid_register(form, update){

	if (form.user.value=="") {
		alert("Va rugam completati campul User");
		form.user.focus();
		return false;
	}

	var is_update_profile = document.getElementById('schimbare_parola');
	if (is_update_profile != undefined)
		var can_update_profile = is_update_profile.style.display;
	else var can_update_profile = false;

	if (can_update_profile == '')
		can_update_profile = true;
	else can_update_profile = false;

	if (update == undefined || (form.pass && can_update_profile)) {
		if ((form.pass.value=="") || (form.pass.value != form.pass2.value)) {
			alert ("Va rugam completati campul Parola");
			if (form.pass.value != form.pass2.value)
				form.pass2.focus();
			else
				form.pass.focus();
			return false;
		}
	}
//	if (form.numeclient.value == "") {
//		alert ("Introduceti numele");
//		form.numeclient.focus();
//		return false;
//	}
//	if (form.prenume.value == "") {
//		alert ("Introduceti prenumele");
//		form.prenume.focus();
//		return false;
//	}
	if (form.email.value=="") {
		alert("Va rugam completati campul Email");
		form.email.focus();
		return false;
	}
	if (!email_valid(form.email.value,"Va rugam introduceti o adresa de mail valida")) {
		alert("Va rugam introduceti o adresa de mail valida");
		form.email.focus();
		return false;
	}
//	return false;
//	alert(form.zi.value);

	if (form.zi.value == "" || form.zi.value == "0") {
		alert ("Va rugam completati campul Zi nastere");
		form.zi.focus();
		return false;
	}
//	return false;

	if (form.luna.value == "" || form.luna.value == "0") {
		alert ("Va rugam completati campul Luna nastere");
		form.luna.focus();
		return false;
	}
	if (form.an.value == "" || form.an.value == "0") {
		alert ("Va rugam completati campul An nastere");
		form.an.focus();
		return false;
	}
	if ((!form.sex[0].checked) && (!form.sex[1].checked)) {
		alert ("Va rugam completati campul Sex");
		return false;
	}
//	if (form.telefon.value == "") {alert ("Introduceti numarul de telefon"); return false;}
//	if (form.strada.value == "") {
//		alert ("Introduceti numele strazii");
//		form.strada.focus();
//		return false;
//	}
//	if (form.numar.value == "") {
//		alert ("Introduceti numarul");
//		form.numar.focus();
//		return false;
//	}
	//if (form.codpostal.value == "") {alert ("Introduceti Codul postal"); return false;}
	if (form.judet.value == "" || form.judet.value == "0") {
		alert ("Va rugam completati campul Judet");
		form.judet.focus();
		return false;
	}
//	if (form.oras.value == "") {
//		alert ("Oras");
//		form.oras.focus();
//		return false;
//	}
//	if (form.tara.value == "") {
//		alert ("Introduceti Tara");
//		form.tara.focus();
//		return false;
//	}

	if (form.security.value=="") {
		alert("Va rugam completati codul de siguranta");
		form.security.focus();
		return false;
	}
	
	if (update == undefined) {
		if (!form.termeni.checked) {
			alert ("Trebuie sa fiti de acord cu prevederile `Termeni si Conditii`, `Politica de confidentialitate` si `Dezvaluirea datelor cu caracter personal`");
			form.termeni.focus();
			return false;
		}

	}
	return true;
}

function schimba_vot(vot) {
	for (i=1;i<=vot;i++) {
		document.getElementById('vot'+i).src = 'images/rank-single.gif';
	}

	for (i=parseInt(vot)+1;i<=5;i++) {
		document.getElementById('vot'+i).src = 'images/bg-rank-single.gif';
	}

	if (vot)
		document.getElementById('vot').value = vot;

}

function valid_comentariu(form){

	if (form.vot.value == '0') {
		alert('Va rugam alegeti un punctaj');
		return false;
	}

	if (form.comentariu.value == '') {
		alert('Va rugam completati campul Comentariu');
		form.comentariu.focus();
		return false;
	}

	return true;
}
function email_valid(email) {
	var	emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;

	if (email == '') {
		return false;
	}

	if (!emailRegExp.test(email)) {
		return false;
	}

	return true;
}

function valid_abonare_newsletter(form){

	if (form.email.value == '') {
		alert('Va rugam completati campul Email');
		form.email.focus();
		return false;
	}

	if (!email_valid(form.email.value)) {
		alert('Va rugam introduceti o adresa de mail valida');
		form.email.focus();
		return false;
	}

	if (!form.confident.checked) {
		alert('Trebuie sa fii de acord cu termenii de confidentialitate');
		form.confident.focus();
		return false;
	}

	return true;
}

function valid_parola_forgot(form) {

	if (form.email.value == '') {
		alert('Va rugam completati campul Email');
		form.email.focus();
		return false;
	}

	if (!email_valid(form.email.value)) {
		alert('Va rugam introduceti o adresa de mail valida');
		form.email.focus();
		return false;
	}

	return true;
}

function valid_contact(form){

	if (form.user.value == '') {
		alert('Va rugam completati campul Nume');
		form.user.focus();
		return false;
	}

	if (form.email.value == '') {
		alert('Va rugam completati campul Email');
		form.email.focus();
		return false;
	}

	if (!email_valid(form.email.value)) {
		alert('Va rugam introduceti o adresa de mail valida');
		form.email.focus();
		return false;
	}

	if (form.mesaj.value == '') {
		alert('Va rugam completati campul Mesaj');
		form.mesaj.focus();
		return false;
	}

	if (form.security_code.value == '') {
		alert('Va rugam completati campul Cod de securitate');
		form.security_code.focus();
		return false;
	}
	
	if (!form.termeni.checked) {
		alert ("Trebuie sa fiti de acord cu prevederile `Termeni si Conditii`");
		form.termeni.focus();
		return false;
	}
	if (!form.confident.checked) {
		alert ("Trebuie sa fiti de acord cu Politica de Confidentialitate");
		form.confident.focus();
		return false;
	}
	if (!form.dezvaluire.checked) {
		alert ("Trebuie sa fiti de acord cu Dezvaluirea datelor cu caracter personal");
		form.dezvaluire.focus();
		return false;
	}

	return true;
}

function valid_cautare(form) {

	if (form.cuvant.value == '') {
		alert('Nu ai introdus nimic pentru a cauta');
		form.cuvant.focus();
		return false;
	}

	if (form.cuvant.value.length <= 3) {
		alert('Cuvant prea scurt');
		form.cuvant.focus();
		return false;
	}

	return true;
}

function gal_open700(url) {
	w = 900;
	h = 550;
	sw = screen.width;
	sh = screen.height;
	l = (sw - w) / 2;
	t = (sh - h) / 2;
	window.open(url, 'Other', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=yes,resizable=no');
	return false;
}



function InsertSmiley(id,smiley) {

    if (document.selection) {
        document.getElementById(id).focus();
        range = document.selection.createRange().text = smiley;
    }

    else if (document.getElementById(id).selectionStart || document.getElementById(id).selectionStart == 0) {
        element = document.getElementById(id);
        var selStart = element.selectionStart;
        var selEnd = element.selectionEnd;
        element.value = element.value.substring(0, selStart) + smiley + element.value.substring(selEnd, element.value.length);

    } else {
        document.getElementById(id).value += smiley;
    }
}
function addURL(fld) {
	var currVal = fld.value;
	var url = prompt('Introduce URL-ul:','http:\/\/');
	if (!url)
		return false;

	var txt = prompt('Scrie aici textul care vrei sa apara ca link sau apasa Enter daca vrei sa fie afisat direct adresa link-ului','Link Text');
	if (!txt || (txt == 'Link Text')) {
		txt = url;
	}
	fld.value = currVal + '' + '<a href="' + url + '" target="_blank">' + txt + '<\a>';
	return false;
}

function validate_adauga_discutie(form)
{
	if (!ck_text(form.subiect,"","Completati campul Subiect !")) return false;
	if (!ck_text(form.mesaj,"","Completati campul Mesaj !")) return false;	
	if ($('input#security') && !$('input#security').val()) {
		alert('Completati codul de securitate !');
		return false;
	}

	
	return true;
}

function schimba_parola(where) {
	if (document.getElementById(where).style.display == "none") {
		document.getElementById(where).style.display = '';
		document.getElementById(where+'_text').style.display = '';

	}
	else {
		document.getElementById(where).style.display = 'none';
		document.getElementById(where+'_text').style.display = 'none';
	}

	return false;
}

function valid_cautare(form) {
	if (form.email1.value !="") {
		if (!email_valid(form.email1.value))  {
			alert("Prima adresa de email este incorecta !");
			form.email1.focus();
			return false;
		}
		else {
			if (form.nume1.value=="") {
				alert ("Introduceti primul nume");
				form.nume1.focus();
				return false;
			}
		}
	}

	if (form.email2.value !="") {
		if (!email_valid(form.email2.value)) {
			alert("A doua adresa de email este incorecta !");
			form.email2.focus();
			return false;
		}
		else {
			if (form.nume2.value=="") {
				alert ("Introduceti al doilea nume");
				form.nume2.focus();
				return false;
			}
		}
	}

	if (form.email3.value !="") {
		if (!email_valid(form.email3.value)) {
			alert("A treia adresa de email este incorecta !");
			form.email3.focus();
			return false;
		}
		else {
			if (form.nume3.value=="") {
				alert ("Introduceti al treilea nume");
				form.nume3.focus();
				return false;
			}
		}
	}

	if (form.email4.value !="") {
		if (!email_valid(form.email4.value)) {
			alert("A patra adresa de email este incorecta !");
			form.email4.focus();
			return false;
		}
		else {
			if (form.nume4.value=="") {
				alert ("Introduceti al patrulea nume");
				form.nume4.focus();
				return false;
			}
		}
	}

	if (form.email5.value !="") {
		if (!email_valid(form.email5.value)) {
			alert("A cincea adresa de email este incorecta !");
			form.email5.focus();
			return false;
		}
		else {
			if (form.nume5.value=="") {
				alert ("Introduceti al cincilea nume");
				form.nume5.focus();
				return false;
			}
		}
	}

	if (!email_valid(form.email0.value))  {
		alert("Adresa domneavoastra de email este incorecta !");
		form.email0.focus();
		return false;
	}
	else {
		if (form.nume0.value=="") {
			alert ("Introduceti numele dumneavoastra");
			form.nume0.focus();
			return false;
		}
	}

	if (form.security_code.value=="") {
		alert("Va rugam completati campul Cod de securitate");
		form.security_code.focus();
		return false;
	}

	return true;
}

function afiseaza_mail() {
	part1="office"
	part2="revistaplafar"
	part3="ro"
	str = part1+String.fromCharCode(eval(64))+part2+String.fromCharCode(eval(46))+part3;
	document.write ("<a href='ma"+"ilto:"+str+"'>"+str+"</a>");
}


function calcul_test(form){

var isOneChecked="false";
var A=0;
var B=0;
var C=0;
var D=0;

var rez="";
//alert ("a");
var nrintreb = form.nrintreb.value;
var nrVarJs = form.nrvar.value;

var nrvar=nrVarJs;

//alert (nrintreb);

if (nrintreb>=1) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_1[i].checked) {
											if (form.aleg_1[i].value=="A") {A++;}
											if (form.aleg_1[i].value=="B") {B++;}
											if (form.aleg_1[i].value=="C") {C++;}
											if (form.aleg_1[i].value=="D") {D++;}
											}

} }
if (nrintreb>=2) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_2[i].checked) {
											if (form.aleg_2[i].value=="A") {A++;}
											if (form.aleg_2[i].value=="B") {B++;}
											if (form.aleg_2[i].value=="C") {C++;}
											if (form.aleg_2[i].value=="D") {D++;}
        									}

}								}
if (nrintreb>=3) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_3[i].checked)  {
											if (form.aleg_3[i].value=="A") {A++;}
											if (form.aleg_3[i].value=="B") {B++;}
											if (form.aleg_3[i].value=="C") {C++;}
											if (form.aleg_3[i].value=="D") {D++;}
        									}

}								}
if (nrintreb>=4) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_4[i].checked)  {
											if (form.aleg_4[i].value=="A") {A++;}
											if (form.aleg_4[i].value=="B") {B++;}
											if (form.aleg_4[i].value=="C") {C++;}
											if (form.aleg_4[i].value=="D") {D++;}
        									}

								}
}
if (nrintreb>=5) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_5[i].checked)  {
											if (form.aleg_5[i].value=="A") {A++;}
											if (form.aleg_5[i].value=="B") {B++;}
											if (form.aleg_5[i].value=="C") {C++;}
											if (form.aleg_5[i].value=="D") {D++;}
        									}

								}
}
if (nrintreb>=6) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_6[i].checked)  {
											if (form.aleg_6[i].value=="A") {A++;}
											if (form.aleg_6[i].value=="B") {B++;}
											if (form.aleg_6[i].value=="C") {C++;}
											if (form.aleg_6[i].value=="D") {D++;}
        									}

								}
}
if (nrintreb>=7) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_7[i].checked)  {
											if (form.aleg_7[i].value=="A") {A++;}
											if (form.aleg_7[i].value=="B") {B++;}
											if (form.aleg_7[i].value=="C") {C++;}
											if (form.aleg_7[i].value=="D") {D++;}
        									}

								}
}
if (nrintreb>=8) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_8[i].checked) {
											if (form.aleg_8[i].value=="A") {A++;}
											if (form.aleg_8[i].value=="B") {B++;}
											if (form.aleg_8[i].value=="C") {C++;}
											if (form.aleg_8[i].value=="D") {D++;}
        									}

								}
}
if (nrintreb>=9) {
for (var i=0; i < nrvar; i++) {
	if(form.aleg_9[i].checked) {
											if (form.aleg_9[i].value=="A") {A++;}
											if (form.aleg_9[i].value=="B") {B++;}
											if (form.aleg_9[i].value=="C") {C++;}
											if (form.aleg_9[i].value=="D") {D++;}
        									}

								}
}
	//alert ("A" + A + "B" + B + "C" + C);

	if (!email_valid(form.email.value)) {
	 alert("Adresa de email este incorecta");
	 return false;
  }
    
	if (A+B+C+D != nrintreb) {alert ("Va rog sa raspundeti la toate intrebarile"); return false } else {
		form.rezA.value = A;
		form.rezB.value = B;
		form.rezC.value = C;
		form.rezD.value = D;
		/*
		alert (document.ftest.rezA.value);
		alert (document.ftest.rezB.value);
		alert (document.ftest.rezC.value);
		*/
	}
	if (!form.confident.checked) {alert('Trebuie sa fiti de acord cu Politica de Confidentialitate'); return false;}

	return true;
}
