//VALIDA FORM INSCRIÃ‡ÃƒO
if (!String.prototype.lTrim) {
      String.prototype.lTrim = function (){
       return this.replace(/^\s*/, "");
      };
    }
    
    if (!String.prototype.rTrim) {
      String.prototype.rTrim = function (){
       return this.replace(/\s*$/, "");
      };
    }
    
    String.prototype.trim = function (){
      return this.lTrim().rTrim();
    };
    
    Array.prototype.hasEmptyElements = function()
    {
      for( var i = 0 ; i < this.length ; i++ )
       if( ( this[ i ] == '' ) || ( this[ i ] == null ) || ( this[ i ] == undefined ) )
          return( true );
                
       return( false );
    }
    
    String.prototype.isMail = function()
    {
     var test;
     var pt1    = this.split( '@' );
     var valid  = '.-_@';
            
        if( ( pt1.length != 2 ) || ( pt1[ 0 ].length == 0 ) || ( pt1[ 1 ].length == 0 ) ) 
            return( false );
        else {
          for( var i = 0 ; i < valid.length - 1 ; i++ ) {
            if( pt1[ 0 ].split( valid.charAt( i ) ).hasEmptyElements() ) return( false );
            if( pt1[ 1 ].split( valid.charAt( i ) ).hasEmptyElements() ) return( false );
           }			
        }
        for( var i = 0 ; i < this.length ; i++ ) {
          var charac = this.toUpperCase().charCodeAt( i );
          
            if( valid.indexOf( String.fromCharCode( charac ) ) == -1 )
            if(!( ( ( charac >= 65 ) && ( charac <= 90 ) ) || ( ( charac >= 48 ) && ( charac <= 57 ) ) ) ) 
               return( false );
        }	
      return( true );
    }
    
    // CRIA ACTION DINAMICAMENTE
    var cadastrarNewsletter = function()
    {
     with(document.subscribe_popup)
     {	
        var validacaoFormulario = function()
        {
            
            if(email.value.trim().length == 0 || !email.value.trim().isMail())
             {
               alert('O endereço de e-mail informado está inválido');
               return false;
             }
    
             if(city_id.options[city_id.options.selectedIndex].value.trim().length == 0)
             {
               alert('Escolha uma cidade para se cadastrar.');
               return false;
             }
            return true;
        }
     
       action = '/subscribe.php' + city_id.options[city_id.options.selectedIndex].value; 	
       method = 'POST'; // GET
    
        if( validacaoFormulario() ){
            submit();	
        }
     }
    }
	
//ABRIR LIGHTBOX	
// ao abrir o lightbox 
if(!getCookie("lightBoxOfertasClube") )
{  
  // executa script de abertura do lightbox; 
  $(document).ready(function() {	

	//$(//'a[name=modal]').click(function(e) {
		//e.preventDefault();
		
		var id = '#subscribe-dialog'; //Faz abrir lightbox ao carregar a pagina
		//var id = $(this).attr('href');

	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(2000); 
	
	//});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	/*$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});*/			
	
});
  
  // (cookie,valor,num_dias)
  setCookie("lightBoxOfertasClube",true,1);
} 
