/**
    * @Method : addFavorite
    * @Purpose:This method is used for adding the article as favorite.
**/
function addFavorite(){
	new Ajax.Request('/articles/addFavorite', {
			asynchronous: true,
			parameters: Form.serialize($('view_article')),
			onSuccess: function(msg){
				//alert(msg.responseText);
				if(msg.responseText!=""){
					alert(msg.responseText)
				}
				
			}
		});
}


/**
    * @Method : ValidateShareArticleWithFriend
    * @Purpose:This method is used to validate share a friend form.
**/

function ValidateShareArticleWithFriend(id){
	var errorString = "";
	var sendersName 	= trim(document.getElementById('ArticleSendersName').value);
	var FriendsEmail0	= trim(document.getElementById('ArticleFriendsEmail0').value);
	var FriendsEmail1	= trim(document.getElementById('ArticleFriendsEmail1').value);
	var FriendsEmail2	= trim(document.getElementById('ArticleFriendsEmail2').value);
	
	
	if(sendersName == "")
		errorString = errorString + "Your Name can't be blank<br>";
	
	if(FriendsEmail0 == "" && FriendsEmail1 == "" && FriendsEmail2 == ""){
		errorString = errorString + "Enter atleast one email of your friend<br>";
	}
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(FriendsEmail0 != ''){
		var address = FriendsEmail0;
		if(reg.test(address) == false) {
			errorString = errorString + "One of friends email you have entered is invalid <br>";	
		}
	}
	
	if(FriendsEmail1 != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = FriendsEmail1;
		if(reg.test(address) == false) {
			errorString = errorString + "One of friends email you have entered is invalid <br>";	
		}
	}
	
	if(FriendsEmail2 != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = FriendsEmail2;
		if(reg.test(address) == false) {
			errorString = errorString + "One of friends email you have entered is invalid <br>";	
		}
	}
	
	
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrorShareFrnd").innerHTML = errorDiv+errorString+"</p>";
		
		
	}else{
		document.getElementById("share_a_friend").submit();
	}
	
	return false;
}