var blogURL = 'http://www.filmetari.com/';

var incPath = '/wp-content/themes/filmetari/scripts/';


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function validateRec() {

	reason = "";



	var tfld = trim(document.recpost.friend_email.value);

	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;

	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;



	

	if (document.recpost.friend_email.value == "") {

		reason += "Campul Email este gol.<br />";

	}

	else if (!emailFilter.test(tfld)) {              //test email for illegal characters

		reason += "Introduceti o adresa de email valida.<br />";

	}

	if (document.recpost.friend_email.value.match(illegalChars)) {

		reason += "Campul Email contine caractere nepermise.<br />";

	}



	if (reason != "") {

		document.getElementById("errorRec").innerHTML = reason;

	}



	else {

		postTitle = document.recpost.post_title.value;

		postURL = document.recpost.post_url.value;

		friendEmail = document.recpost.friend_email.value;

		doRec(postTitle,postURL,friendEmail);

	}

}

function doRec(postTitle,postURL,friendEmail) {

	var xmlHttp=null;



	try {

		// Firefox, Opera 8.0+, Safari, IE7

		xmlHttp=new XMLHttpRequest();

	}



	catch(e) {

		// Old IE

		try {

			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

		}

		

		catch(e) {

			alert ("Your browser does not support XMLHTTP!");

			return;  

		}

	}



	var message = "Salut,\n\nUn prieten ti-a recomandat urmatorul articol:\n" + postTitle + "\n" + postURL + "\n\nLectura placute,\nEchipa FilmeTari.com\nhttp://www.filmetari.com";

	var fileURL = blogURL + incPath + "send.a.friend.php";

	var params = "email=" + friendEmail + "&message=" + message;

	

	xmlHttp.open("POST",fileURL,false);

	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

	xmlHttp.send(params);


	if (xmlHttp.responseText == 'success'){

		document.getElementById("errorRec").innerHTML = "Recomandarea ta a fost trimisa!";

	}

	else {

		document.getElementById("errorRec").innerHTML = xmlHttp.responseText;

	}

}