var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=600,width=730');
	if (window.focus) {newwindow.focus()}
}

function clear_field(field,name)
{
		if(field.value==name){
			field.value="";
		}
}

function check_login()
{	
	if (document.login.email.value=="" || document.login.email.value=="adresa@email") {
		alert("Va rugam adaugati adresa de e-mail pentru a continua.");
		document.login.email.focus();
		return false;
	}
	
	if (document.login.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.login.password.focus();
		return false;
	}
	return true;
}

function check_update()
{	
	if (document.profile.name.value=="") {
		alert("Va rugam adaugati numele pentru a continua.");
		document.profile.name.focus();
		return false;
	}

	if (document.profile.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.profile.password.focus();
		return false;
	}

	if (document.profile.password.value!=document.profile.password_again.value) {
		alert("La rescriere parola nu se potriveste.");
		document.profile.password.focus();
		return false;
	}
	return true;
}

function check_new_pass()
{	
	if (document.new_pass.old_pass.value=="") {
		alert("Va rugam adaugati parola actuala pentru a continua.");
		document.new_pass.old_pass.focus();
		return false;
	}

	if (document.new_pass.password.value=="") {
		alert("Va rugam adaugati parola noua pentru a continua.");
		document.new_pass.password.focus();
		return false;
	}

	if (document.new_pass.password.value!=document.new_pass.password_again.value) {
		alert("La rescriere parola noua nu se potriveste.");
		document.new_pass.password_again.focus();
		return false;
	}
	return true;
}

function check_register()
{
	if (document.register.name.value=="") {
		alert("Va rugam adaugati Numele pentru a continua.");
		document.register.name.focus();
		return false;
	}

	if (document.register.email.value=="") {
		alert("Va rugam adaugati adresa de e-mail pentru a continua.");
		document.register.email.value="";
		document.register.email.focus();
		return false;
	} else {
		ast=document.register.email.value.indexOf("@");
		dot=document.register.email.value.lastIndexOf(".");
		if(!(ast>0 && dot>0 && dot>ast)){
			alert("Va rugam adaugati o adresa de e-mail valida pentru a continua.");
			document.register.email.focus();
			return false;
	}}

	if (document.register.email_again.value!=document.register.email.value) {
		alert("Atentie, adresa de e-mail este gresita la rescriere.");
		document.register.email_again.focus();
		return false;
	}
	
	if (document.register.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.register.password.focus();
		return false;
	}

	if (document.register.password_again.value!=document.register.password.value) {
		alert("Atentie, parola este gresita la rescriere.");
		document.register.password_again.focus();
		return false;
	}

	if (document.register.code.value==""){
		alert("Va rugam adaugati codul de siguranta din imaginea de mai sus pentru a continua.");
		document.register.code.focus();
		return false;
	}
/*	
	if (document.register.conditii.checked==false) {
		alert("Pentru a continua trebuie sa fiti de acord cu regulamentul.");
		document.register.conditii.focus();
		return false;
	}
*/
	return true;
}

function check_fpassword_form(){
	if (document.f_password.fpass_email.value=="") {
		alert("Va rugam adaugati adresa de e-mail pentru a continua.");
		document.f_password.fpass_email.focus();
		return false;
	}
	
	return true;	
}

function check_add()
{	
	if (document.post_add.type.value=="0") {
		alert("Va rugam selectati o categorie.");
		document.post_add.type.focus();
		return false;
	}

	if (document.post_add.sub_type.value==""){
		alert("Va rugam selectati o subcategorie.");
		document.post_add.sub_type.focus();
		return false;
	}

	if (document.post_add.location.value=="") {
		alert("Va rugam selectati o localitate.");
		document.post_add.location.focus();
		return false;
	}

	if (document.post_add.op_type.value=="") {
		alert("Va rugam selectati tipul de anunt.");
		document.post_add.op_type.focus();
		return false;
	}

	if (document.post_add.delivery.value=="") {
		alert("Va rugam selectati modul de livrare.");
		document.post_add.delivery.focus();
		return false;
	}

	if (document.post_add.prod_state.value=="") {
		alert("Va rugam selectati starea produsului.");
		document.post_add.prod_state.focus();
		return false;
	}

	if (document.post_add.description.value=="") {
		alert("Va rugam adaugati descrierea.");
		document.post_add.description.focus();
		return false;
	}

	return true;
}

function check_add_company()
{	
	if (document.add_form.name.value=="") {
		alert("Va rugam sa adaugati numele companiei.");
		document.add_form.name.focus();
		return false;
	}

	if (document.add_form.address.value=="") {
		alert("Va rugam sa adaugati adresa.");
		document.add_form.address.focus();
		return false;
	}

	if (document.add_form.location.value=="") {
		alert("Va rugam sa selectati localitatea.");
		document.add_form.location.focus();
		return false;
	}

	if (document.add_form.description.value=="") {
		alert("Va rugam sa adaugati descrierea companiei.");
		document.add_form.description.focus();
		return false;
	}

	if (document.add_form.cod_f.value=="") {
		alert("Va rugam sa adaugati codul fiscal.");
		document.add_form.cod_f.focus();
		return false;
	}

	if (document.add_form.category1.value=="") {
		alert("Va rugam sa selectati categoria principala.");
		document.add_form.category.focus();
		return false;
	}

	if (document.add_form.sub_category1.value=="") {
		alert("Va rugam sa selectati subcategoria principala.");
		document.add_form.category.focus();
		return false;
	}

	categories = document.getElementsByName('category[]');
	sub_categories = document.getElementsByName('sub_category[]');
	
	for (var i = 0; i < categories.length; i++){
		j=i+2
		if (categories[i].value==""){
			alert("Va rugam sa selectati categoria "+j+".");
			return false;
		}
		if (sub_categories[i].value==""){
			alert("Va rugam sa selectati subcategoria "+j+".");
			return false;
		}
	}
	
	if (document.add_form.contact_name.value=="") {
		alert("Va rugam sa adaugati numele persoanei de contact.");
		document.add_form.contact_name.focus();
		return false;
	}

	if (document.add_form.contact_position.value=="") {
		alert("Va rugam sa adaugati functia persoanei de contact.");
		document.add_form.contact_position.focus();
		return false;
	}

	if (document.add_form.contact_department.value=="") {
		alert("Va rugam sa adaugati departamentul persoanei de contact.");
		document.add_form.contact_department.focus();
		return false;
	}

	if (document.add_form.contact_email.value=="") {
		alert("Va rugam sa adaugati e-mailul de contact.");
		document.add_form.contact_email.focus();
		return false;
	}

	if (document.add_form.contact_phone.value=="") {
		alert("Va rugam sa adaugati telefonul de contact.");
		document.add_form.contact_phone.focus();
		return false;
	}

	return true;
}

function check_message()
{
	if (document.msg_add.message.value=="") {
		alert("Va rugam adaugati textul mesajului.");
		document.msg_add.message.focus();
		return false;
	}	

	return true;
}

function change_keep_image(newImage, keep_image)
{
	if (newImage == ""){
		document.getElementById(keep_image).checked = true;
	}
	else{
		document.getElementById(keep_image).checked = false;
	}
}

function delete_new_image(keep_image, image)
{
	if (keep_image){
		document.getElementById(image).value = "";
	}
}
