function validaCorreo(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true)
  } else {
    return (false);
  }
}



function Abrir(theURL) {
	var leftmargin = (screen.width - 500) / 2;
	var topmargin = (screen.height - 450) / 2;
	var features = 'width=520,height=450,scrollbars=yes';
	features=features + ',top=' + topmargin + ',left='+ leftmargin
	  window.open(theURL,'Productos',features);
}


(function($)
{
    $.fn.externalLink = function()
    {        
        this.each(function()
        {
			$(this).find('a[rel="external"]')
				 .bind('click', function() { window.open($(this).attr('href')); return false; })				
        });
        return this;
    };
})(jQuery);


jQuery(document).ready(function(){
	$('.acordeon').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
	padre=
	$('#sm'+$('#activo').attr('rel')).next().toggle('slow');
	$('#sm'+$('#activo').attr('rel')).addClass('activo');
	
	$('#cancelaroferta').click(function() {
										
		$('#mensaje-frm').css('display','none');
		$('#fondo-mensaje').css('display','block');
		$('#mensaje-login').css('display','block');
		
		botonAceptar="<br /><a href=\"#\" title=\"Aceptar - Cerrar ventana\" onclick=\"$('#mensaje-login').css('display','none'); $('#fondo-mensaje').css('display','none');\">aceptar</a>";
										
		$.ajax({
		   type: "POST",
		   url: "/templates/funcs/eliminar-oferta.php",
		   cache: false,
		   data: "id="+$(this).attr('rel')+"&val="+$(this).attr('rev'),
		   error: function(){   
				$('#mensaje-login').html('<p>'+botonAceptar+'Error enviado petici&oacute;n<br />Int&eacute;ntelo mas tarde.</p>');						
		   },
		   success: function(msg){
				if(msg=='si'){
					 $('#mensaje-login').html('<p>'+botonAceptar+'Oferta eliminada</p>');
					 window.location='/tu-aje/gestionar-ofertas.xhtml';
				}else if(msg=='si2'){
					 $('#mensaje-login').html('<p>'+botonAceptar+'Oferta reactivada</p>');
					 window.location='/tu-aje/gestionar-ofertas.xhtml';	
				}else{
					$('#mensaje-login').html('<p>'+botonAceptar+'Error enviado petici&oacute;n<br />Int&eacute;ntelo mas tarde.</p>');
				}
		   }
		 });				  
	});
});
