//cookie
var screen_width = window.screen.width;
var screen_height = window.screen.height;
var now = new Date();
now.setTime(now.getTime()+(24*60*60*31*1000)); //1 month
document.cookie = "alicecms_="+screen_width+"x"+screen_height+"; path=/; expires="+now.toGMTString();


//patterns
var pattern_text = /^[a-zA-Z]{4,10}$/;
var pattern_pass = /^[a-zA-Z0-9]{6,20}$/;


//functions
function bagAdd() {
	$('.button-bag').click(  
	  function() {
		  var product_id = $(this).attr('id');
		  product_id = product_id.match(/\d{3,9}/g);
		  var quantity = $('#q'+product_id).val();

		  $.ajax({
				  type: "POST",
				  url: "/.s.bagw", 
				  data: "ajax=1&product_id="+product_id+'&quantity='+quantity,
				  async: false,
				  success: function(data) { 
						if (data==1) {
						  location.reload();
						} else {
						  return false;  
						}
					  } 
				});
	  });
}

function bagMod() {
	$('.button-bagmod').click(  
	  function() {
		  var product_bag_id = $(this).attr('id');
		  var quantity = $('#q'+product_bag_id).val();

		  $.ajax({
				  type: "POST",
				  url: "/.s.bagmodw", 
				  data: "ajax=1&product_bag_id="+product_bag_id+'&quantity='+quantity,
				  async: false,
				  success: function(data) {
						if (data==1) { 
						  location.reload();
						} else {
						  return false;  
						}
					  } 
				});
	  });
}

function bagDel() {
	$('.button-bagdel').click(  
	  function() {
		  var product_bag_id = $(this).attr('id');
		  product_bag_id = product_bag_id.substr(1);
		  var quantity = 0;

		  $.ajax({
				  type: "POST",
				  url: "/.s.bagmodw", 
				  data: "ajax=1&product_bag_id="+product_bag_id+'&quantity='+quantity,
				  async: false,
				  success: function(data) { 
						if (data==1) { 
						  location.reload();
						} else {
						  return false;  
						}
					  } 
				});
	  });
}

function bagSale() {
	$('.button-bagsale').click(  
	  function() {
		  var product_bag_id = $(this).attr('id');
		  product_bag_id = product_bag_id.substr(1);
	 	  var product_sale_code = $(this).attr('alt');

		  $.ajax({
				  type: "POST",
				  url: "/.s.bagsalew", 
				  data: "ajax=1&product_bag_id="+product_bag_id+"&product_sale_code="+product_sale_code,
				  async: false,
				  success: function(data) { 
		
						if (data==1) { 
						  location.reload();
						} else {
						  return false;  
						}
					  } 
				});
	  });
}

//accordion
function ac(cl) {
	var s = cl+' > a';
	$(s).next(':not(.active)').hide(); 
	$(s).click(function(){
		if( $(this).next().is(':hidden') ) {
			$(s).removeClass('active').next().slideUp();
			$(s).parent().removeClass('active'); //for css
			$(this).toggleClass('active').next().slideDown();
			$(this).parent().toggleClass('active'); //for css
		} else {
			$(this).next().slideUp()
		}
		return false;
	});
}






//init
$(document).ready(function() {
	bagAdd();
	bagMod();
	bagDel();
	bagSale();
	
	//search
	//$("#q2").defaultValue("Keresendő szó, kifejezés");
	
	//search autocomplete
	$("#q2").autocomplete("/autocomplete.php", {
			selectFirst: false,
            width:208

	});

});




function validateEmail(email) {
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(email)) {
	 	return true;
	} else {
		return false;
	}
}

