var wpcocontent = 1;

jQuery(document).ready(function() {
	jQuery("[id*=checkboxall]").click(function() {
		var status = this.checked;
		
		jQuery("[id*=checklist]").each(function() {
			this.checked = status;	
		});
	});
	
	jQuery("input[id*=checkinvert]").click(function() {
		this.checked = false;
	
		jQuery("input[id*=checklist]").each(function() {
			var status = this.checked;
			
			if (status == true) {
				this.checked = false;
			} else {
				this.checked = true;
			}
		});
	});
});

function wpco_scroll(selector) {
	var targetOffset = jQuery(selector).offset().top;
    jQuery('html,body').animate({scrollTop: targetOffset}, 500);
}

function wpcochangedisplay(number, value) {
	jQuery('#displayproducts' + number).hide();
	jQuery('#remoteproducts' + number).hide();
	jQuery('#displaycategories' + number).hide();
	
	if (value == "products" || value == "remoteproducts") {	
		jQuery('#displayproducts' + number).show();
		
		if (value == "remoteproducts") {
			jQuery('#remoteproducts' + number).show();
		}
	} else if (value == "categories") {
		jQuery('#displaycategories' + number).show();
	}
}

/* Add to cart function */
function wpco_addtocart(form, productid, number) {
	var formvalues = jQuery("#addtocart" + productid).serialize();
	var mytime = new Date().getTime();
	
	jQuery('#submit' + productid).hide();
	jQuery('#message' + productid).hide();
	jQuery('#loading' + productid).show();
	
	jQuery.post(wpcoAjax + "?cmd=add_to_cart&number=" + number + "&mytime=" + mytime + "", formvalues, function(data) {	
		jQuery("#" + number).html(data);
		wpco_scroll(jQuery('#' + number));
		
		jQuery('#submit' + productid).show();
		jQuery('#loading' + productid).hide();
	});
}

function wpco_gencouponcode() {
	var mytime = new Date().getTime();
	jQuery("#couponcodeloading").show();
	jQuery("#couponcodelink").hide();
	
	jQuery.post(wpcoAjax + "?cmd=gen_coupon_code&mytime=" + mytime, false, function(data) {
		jQuery("#couponcodecol").html(data);
		jQuery("#couponcodeloading").hide();
		jQuery("#couponcodelink").show();
	});
}

function wpco_emptycart(number) {
	wpco_scroll(jQuery("#" + number));
	var mytime = new Date().getTime();
	
	jQuery.post(wpcoAjax + "?cmd=empty_cart&number=" + number + "&mytime=" + mytime + "", false, function(data) {
		jQuery("#" + number).html(data);
	});
}