/**
* This fuction is used to
* send article using ajax
*
* @access   public
* @param    null
*           
* @return   null
*/

function sendArticle(){

	if(validateEmailFields())	{
		document.getElementById('loader').style.display='';		
		document.getElementById('send_msg').innerHTML = '';
		params='action=sendArticle&';		
		params += "id="+document.getElementById( 'hidArticleId' ).value+'&';
		params += "toName="+document.getElementById( 'toName' ).value+'&';
		params += "toEmail="+document.getElementById('toEmail').value+'&';
		params += "fromName="+document.getElementById( 'fromName').value+'&';
		params += "fromEmail="+document.getElementById( 'fromEmail').value+'&';		
		params += "emailMessage="+document.getElementById( 'emailMessage').value;		

	url = window.location.pathname;
	http = getHTTPObject(); // We create the HTTP Object
	
	
		
	http.open("POST", url, true);
    //With the below lines we are basically saying that the data send is in the format of a form submission.
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);//We also give the length of the parameters we are sending.
    http.setRequestHeader("Connection", "close");	
	

	http.onreadystatechange = function (){HttpResponse()};
	http.send(params);
	}
	//document.getElementById("frmLundG").submit();
}

/**
* This fuction is used to
* handle ajax response
*
* @access   public
* @param    null
*           
* @return   null
*/

function HttpResponse(){
	if (http.readyState == 4)
	{  
		// only if "OK"
        if (http.status == 200)
		{
			
			 var response  = http.responseText;

			  document.getElementById('loader').style.display='none';			  
			  document.getElementById('send_msg').innerHTML = response;
			  document.forms[0].reset();

			

		}
	}
	

}

/**
* This fuction is used for
* field validation 
*
* @access   public
* @param    null
*           
* @return   null
*/

function validateEmailFields(){

	
  if(document.getElementById("toName").value.match(/^ *$/)){
		alert("Please enter the name.");	
		document.getElementById("toName").focus();
		return false ;
	}
	else if(checkEmail(document.getElementById("toEmail").value)!=true){	
		document.getElementById("toEmail").focus();
		return false ;
	}
	else if(document.getElementById("fromName").value.match(/^ *$/)){
		alert("Please enter your name.");
		document.getElementById("fromName").focus();
		return false ;
	}
	else if(checkEmail(document.getElementById("fromEmail").value)!=true){	
		document.getElementById("fromEmail").focus();
		return false ;
	}
	return true;
}
