$(document).ready(function(){
	$('#slideshow').cycle({ 
    	fx:     'scrollHorz',
		speed:  500, 
		timeout:  4000,
    	next:   'a.forward', 
    	prev:   'a.back' 
		
	});
	
	$('a.pause').click(function() { 
   		$('#slideshow').cycle('pause');
	});
	$('a.play').click(function() { 
   		$('#slideshow').cycle('resume');
	});

	$('#slideshow1').cycle({ 
    	fx:     'scrollHorz',
		speed:  500, 
		timeout:  4000,
    	next:   'a.forward', 
    	prev:   'a.back' 
		
	});
	
	$('a.pause').click(function() { 
   		$('#slideshow').cycle('pause');
	});
	$('a.play').click(function() { 
   		$('#slideshow').cycle('resume');
	});	
	

        $("#newsletter").submit(function(){
           return false;
         });  
         $("#news_submit").click(function(){
         	if (isValidEmailAddress($('#email').val())){
				$.post(
                    $("#newsletter").attr("action"), 
                    $("#newsletter").serialize() , 
                    function(data){
                        if (data=='False'){
					        //$.growlUI('Thank you,', 'You are already in our mailing list.');
					        window.location='http://www.ecoist.com/pc/memberthankyou.asp';
                        }else{
                   			//$.growlUI('Thank you, ', 'You are now added to our mailing list.');
                   			window.location='http://www.ecoist.com/pc/signupthankyou.asp';
                   			//alert(data);
                        } 
                        
                    }
                );

         	}else {
         		$.growlUI('Please enter a valid email address.');
         	}
         		
          });
          
         $("#news_submit1").click(function(){
         	if (isValidName($('input#name').val())){
	         	if (isValidEmailAddress($('#email').val())){
					$.post(
	                    $("#newsletter").attr("action"), 
	                    $("#newsletter").serialize() , 
	                    function(data){
	                        if (data=='False'){
						        //$.growlUI('Thank you,', 'You are already in our mailing list.');
						        window.location='http://www.ecoist.com/pc/memberthankyou.asp';
	                        }else{
	                   			//$.growlUI('Thank you, ', 'You are now added to our mailing list.');
	                   			window.location='http://www.ecoist.com/pc/signupthankyou.asp';
	                   			//alert(data);
	                        } 
	                        
	                    }
	                );
	
	         	}else {
	         		$.growlUI('Please enter a valid email address.');
	         		$('#email').focus();
	         	}
	         }else {
	     			$.growlUI('Please enter your First Name.');
	     			$('#name').focus();

	         }	   
			});

          
});


function popitup(url) {
	if(url == '/sample_newsletter.html')
		newwindow=window.open(url,'name','height=922px,width=650px');
	else if (url == '/free_shipping.html')
  		newwindow=window.open(url,'name','height=350px,width=450px,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,');
  	else if (url == '/secure_online_shopping.html')
  		newwindow=window.open(url,'name','height=350px,width=400px,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,');
  	else if (url == 'https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=ecoist.com&lang=en')
  		newwindow=window.open(url,'name','height=280px,width=515px,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,');
  	else if (url == '/eco-points.html')
  		newwindow=window.open(url,'name','height=200px,width=400px,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,');
  	else if (url == 'javascript:void(0)')
  		newwindow=window.open(url,'name','height=200px,width=400px,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,');
	else
		newwindow=window.open(url,'name','height=500,width=500,scrollbars=1');
	return false;
}


function isValidEmailAddress(emailAddress) {
 	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.	[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1		[0-9]{2}|[0-9]{1,2})\]?$)/i);
 	return pattern.test(emailAddress);

}

function isValidName(name) { 
		if ((name == "First Name") || (name == "")) {
			return false;
			
			}else{
				return true;
			}
		
} // end function isvalidname



