// JavaScript Document
/////////////////////////////////////////////////////////////////
function show_recomanda(){
	$('#salveaza').hide();
	$("#recomanda").fadeIn(300);
}

/////////////////////////////////////////////////////////////////
function show_salveaza(){
	$('#recomanda').hide();
	$("#salveaza").fadeIn(300);
}

/////////////////////////////////////////////////////////////////
function checkEmail(email){
	var regex = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,4}$/ 
	if (!regex.test(email)) return false; 
	return true; 
} 	

/////////////////////////////////////////////////////////////////
function trimite_recomandare(){
	var options = {
    beforeSubmit: function(formArray, jqForm) {
				if (formArray[1].value==""){
					alert("Scrie numele tau!");
					return false;
				}else if (formArray[2].value==""){
					alert("Scrie adresa prietenului!");
					return false;
				}else if (!checkEmail(formArray[2].value)){
					alert("Adresa de email este invalida!");
					return false;
				}
    },
		success: function(data) {
			$('#re_raspuns').fadeIn(300, function (){
				setTimeout(function(){
					$("#re_raspuns").fadeOut(400);
				}, 2000);
			});
		},
		resetForm: true

	};

	$('#recomanda').ajaxSubmit(options);
}

/////////////////////////////////////////////////////////////////
function trimite_salvare(){
	var options = {
    beforeSubmit: function(formArray, jqForm) {
				if (formArray[1].value==""){
					alert("Scrie adresa ta de email!");
					return false;
				}else if (!checkEmail(formArray[1].value)){
					alert("Adresa de email este invalida!");
					return false;
				}
    },
		success: function(data) {
			$('#s_raspuns').fadeIn(300, function (){
				setTimeout(function(){
					$("#s_raspuns").fadeOut(400);
				}, 2000);
			});
		},
		resetForm: true

	};

	$('#salveaza').ajaxSubmit(options);
}

///////////////////////////////////////////////////////////////
function alert_comentariu(bStare){
	if (bStare)	$('#panel_email').fadeIn(300);
	else $('#panel_email').fadeOut(300);
}

/////////////////////////////////////////////////////////////////
function getElem(elemID){
	var obj;
	if (document.all){
		obj = document.all(elemID)
	}else if (document.getElementById){
		obj = document.getElementById(elemID)
	}else if (document.layers){
		obj = document.layers[elemID]
	}
	return obj;
}


///////////////////////////////////////////////////////////
function schimba_news(img, id){
	document.stare.id.value = id;
	
	var options = {
		success: function(data) {
			if (img.src.indexOf("0.gif")!=-1) img.src = "images/1.gif";
			else img.src = "images/0.gif";
		},
		resetForm: false

	};

	$('#stare').ajaxSubmit(options);
	
}


/////////////////////////////////////////////////////////////
function startList() {
	$("form").each(function(){
  	if (this.action == "") this.action=window.location.href;
	});
	
	if (!getElem("filtru")) return;
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("filtru");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
					this.childNodes[3].style.display = "block";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
					this.childNodes[3].style.display = "none";
				}
			}
		}
	}
}

window.onload = startList;
