/*
######################################################################################################################
#
#	PURPOSE OF THIS FILE:
#	Provides external Javascript Routines for the use in the module frontend (view.php)
#
#	INVOKED BY:
#	With WB 2.6.6 a new function was implemented which automatically links an external module frontend.js
#	file to the <head></head> section of a page. The frontend.js is optional. If you want make use
#	of this option, simply place a frontend.js file with the Javascript routiness into the module directory.
#
#	Website Baker versions below 2.6.6 will ignore this file!!!
# 	The frontend.js is invoked from the index.php of your template if you have added the following PHP code
#	lines to the index.php of your template: 
#	<head>
#	...
#	<?php
#	if(function_exists('register_frontend_modfiles')) {
#		register_frontend_modfiles('js');
#	} ?>
#	</head>
#	
#	NOTE:
#	All Javascript functions have to stick to the following naming conventions:
#	mod_MODULE_DIRECTORY_XXXX_f
#
#	mod: shows that the Javascript routine is defined within a module
#	MODULE_DIRECTORY: unique identifier to prevent that CSS styles are overwritten by other modules
#	XXXX: your function name
#	f: identifier for the frontend
#
######################################################################################################################
*/




function newsletterSuscription(o) {  
  	
  	var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (email.test(o)) {
	  doValidate(o);
	} else {
	  doError("Verifique el Correo Electr&oacute;nico");
	};
  
}

function doValidate(o) {
        	$('#messages').removeClass("error");
			$('#messages').removeClass("success");
		  	$('#messages').addClass("normalStatus");
			$('#messages').html('<img src="'+webURL+'/modules/newsletter/images/loading.gif" border="0" style="float:left;" />&nbsp;<label>Enviando solicitud....</label>');
        	
			$.post(webURL+'/modules/newsletter/ajax.php', { email: o }, function(json) {
                  	eval("var args = " + json);
                        if (args.success == true)
                  	{
                  	  	doSuccess(args.msg);
                  	}
                  	else
                  	{
                          doError(args.msg);
                  	}
                  });
    };

function doSuccess(succ_msg) {
          $('#messages').html('<img src="'+webURL+'/modules/newsletter/images/accept.gif" border="0" style="float:left;" />&nbsp;<label>'+succ_msg+'</label>');
          $('#messages').removeClass("error");
		  $('#messages').addClass("success");
 }

 function doError(err_msg) {
          $('#messages').html('<img src="'+webURL+'/modules/newsletter/images/exclamation.gif" border="0" style="float:left;" />&nbsp;<label>'+err_msg+'</label>');
          $('#messages').removeClass("success");
		  $('#messages').addClass("error");
 }