			$(document).ready(function(){
				$("#selectOptions").change(function() {
					$("#sortresults").submit();
				});
				$('#search').focus( function(){
					$('#search').val('');
				});
				$('#cat_nav h3').click( function() {
					$(this).next('ul').slideToggle()
					.siblings("ul:visible").slideUp("slow");
					$(this).toggleClass("selected_cat");
					$(this).siblings("h3").removeClass("selected_cat");
				});
								
				// click on submit button from login form 
				$("input#login_user_box").live('click',function(){
					var name = $("input#login_name").val();  
					var pass = $("input#login_pass").val();  
					var dealpost = $("input#dealpost").val(); 
					var couponpost = $("input#couponpost").val();	
					var fail = $("input#fail").val();
					// create the parameters for ajax call
					var datastring = 'login_name='+ name + '&login_pass=' + pass + '&dealpost=' + dealpost + '&couponpost=' + couponpost +'&submit=true&fail= '+fail;
					$.ajax({
						type: "POST",
						url: "userlogin.php", 
						data: datastring,
						cache: false,
						success: function(message){
							var first_part_message = message.substr(0,7); // cut first 7 letters from response to check if is == with success string or fail response
							// if fail, reload the login page with warning message
							if (first_part_message !="success"){
								$("#TB_ajaxContent").html(message); // content of the window is reloaded
							}
							// else it success, will make array from success message and url for popup, page will reload, popup will be launched with the url from array[1] 
							else{
								var url = message.split(' ');
								//alert(url);
								//popUp(url[1]);
								tb_remove();
								//$(".login_section").load('login_section.php');
								window.location = window.location.href;//'http://www.absolutesteal.com/search_resultsY.php';
							}
							if (message =='') tb_remove();
							return false;
						} // end success return function
					}); // end ajax call
					return false;
				});	// end click on submit button from login form
				
				$("input#login_fund_box").live('click',function(){
					var name = $("input#flogin_name").val();  
					var pass = $("input#flogin_pass").val();  
					// create the parameters for ajax call
					var datastring = 'flogin_name='+ name + '&flogin_pass=' + pass + '&fsubmit=true';
					$.ajax({
						type: "POST",
						url: "userlogin.php", 
						data: datastring,
						cache: false,
						success: function(message){
							var first_part_message = message.substr(0,7); // cut first 7 letters from response to check if is == with success string or fail response
							// if fail, reload the login page with warning message
							if (first_part_message !="success"){
								$("#TB_ajaxContent").html(message); // content of the window is reloaded
							}
							// else it success, will make array from success message and url for popup, page will reload, popup will be launched with the url from array[1] 
							else{
								var url = message.split(' ');
								//alert(url);
								//popUp(url[1]);
								tb_remove();
								//$(".login_section").load('login_section.php');
								window.location = window.location.href;//'http://www.absolutesteal.com/search_resultsY.php';
							}
							if (message =='') tb_remove();
							return false;
						} // end success return function
					}); // end ajax call
					return false;
				});	// end click on submit button from login form	
				// click on submit button from login form
				$("input#ulogin_user_box").live('click',function(){
					var name = $("input#ulogin_name").val();  
					var pass = $("input#ulogin_pass").val();  
					var dealpost = $("input#dealpost").val(); 
					var couponpost = $("input#couponpost").val();	
					var fail = $("input#fail").val();
					// create the parameters for ajax call
					var datastring = 'login_name='+ name + '&login_pass=' + pass + '&dealpost=' + dealpost + '&couponpost=' + couponpost +'&usubmit=true&fail= '+fail;
					$.ajax({
						type: "POST",
						url: "userloginredir.php", 
						data: datastring,
						cache: false,
						success: function(message){
							var first_part_message = message.substr(0,7); // cut first 7 letters from response to check if is == with success string or fail response
							// if fail, reload the login page with warning message
							if (first_part_message !="success"){
								$("#TB_ajaxContent").html(message); // content of the window is reloaded
							}
							// else it success, will make array from success message and url for popup, page will reload, popup will be launched with the url from array[1] 
							else{
								var url = message.split(' ');
								popUp(url[1]);
								//tb_remove();
								window.location = window.location.href;//window.location.reload();
							}
						} // end success return function
					}); // end ajax call
					return false;
				});	// end click on submit button from login form
					
				// ajax function to add a deal to the mall
				$(".addtomall").live('click',function(){
					var element = $(this);
					var dealid = element.attr("id");
					var url = element.attr("href");
					var info = 'store=' + dealid;

					$('#'+dealid ).parent().find("img").show();
					$.ajax({
						type: "POST",
						url: url,
						data: info,
						success: function(message){
							if (message == 'success'){
								$('#'+dealid ).parent().addClass('already_in_mall');
								$('#'+dealid ).parent().html('Added to your Mall');
							}
							else{
								$('#'+dealid ).parent().find("img").hide();
							}
						}
					});
					return false;
				}); // end ajax function for add/remove deals from storeview
			}); // end document ready
			
			function popUp(URL) {
				day = new Date();
				id = day.getTime();
				eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1024,height=768,left = 328,top = 141');");
			}