/**
*	Content's JavaScript
*
*	@author					MAnuel Cantillo Rodriguez<jmcantillo@dptsportsgroup.com>
*	@author					Manuel Cantillo Rodriguez<malanga31@gmail.com>
*	@copyright				DPT Sports Group 2007
*	@category				we
*	@package				Website Engine
*	@version				1.0
*/


//AJAX
var objAjaxComment = new Ajaxer();


// PAGE
var globalUrl ="";




/**
 *
 * @access public
 * @return void
 **/
function saveComment(id_content, url)
{
	globalUrl = url;
	var errors = false;
	var errorMsg = "";

	var valid_url = /([a-zA-Z0-9~%\?&_-]+\.([a-zA-Z0-9.%=\?&_-]+))+/;
	var nickName = $('nickName').value;
	var gender = $('gender').value;
	var visitorEmail = $('visitorEmail').value;
	var visitorUrl = $('visitorUrl').value;
	var visitorComment = $('visitorComment').value;
	var code = $('code').value;

	objAjaxComment.setURL('/engine/ajax/actionSaveComment.ajax.php');
	objAjaxComment.setParameter('id_content', id_content);
	objAjaxComment.setParameter('nickName', nickName);
	objAjaxComment.setParameter('gender', gender);
	objAjaxComment.setParameter('visitorEmail', visitorEmail);
	objAjaxComment.setParameter('visitorUrl', visitorUrl);
	objAjaxComment.setParameter('visitorComment', visitorComment);
	objAjaxComment.setParameter('code', code);

	objAjaxComment.setComplete( saveComment_response );

	if ( !is_email(visitorEmail) )
	{
		errors =  true;
		errorMsg += " - The e-mail must be an e-mail address \n";
	}


	if ( is_empty(visitorComment) )
	{
		errors =  true;
		errorMsg += " - You must write a comment to add this Comment";
	} // if

	if ( errors  == false )
	{
		objAjaxComment.execute();
	}
	else
	{
		errorMsg = "Sorry, please check the following:\n\n" + errorMsg;
		alert(errorMsg);
	}  // if

} // saveComment




/**
 *
 * @access public
 * @return void
 **/
function saveComment_response()
{
	var result = parseInt(objAjaxComment.getResponseText());

	if( result == 1 )
	{
		  alert("Comment added succesfully.");
		  window.location= globalUrl;
    }
	else if( result == 2 )
	{
        alert("The code that you entered its incorrent.");
    }
	else
	{
		alert("Error adding comment.");
	} // if
} // saveComment_response