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) {
	//ua_comment
	//var targetOffset = jQuery(selector).offset().top;
   // jQuery('html,body').animate({scrollTop: targetOffset}, 500);
}

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

/* Add to cart function */
function wpco_addtocart(form, productid, number) {
	
	//console.log(form);
	//console.log(productid);
	//console.log(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) {	
		//ua_comment
		jQuery("#" + number).html(data);
		//wpco_scroll(jQuery('#' + number));
		
		jQuery('#submit' + productid).show();
		jQuery('#loading' + productid).hide();
	});
	//ua_comment show the cart on the homepage
	var home_cart = document.getElementById('home_cart');
	if( home_cart && home_cart.style.display == 'none' ){
			home_cart.style.display = 'block';
	}
}

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);
	});
}

//ua_comment print only the order items on the admin page
function printIt(printThis)
  {
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
    win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
    win.document.write(printThis);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
    win.close();
  }
	
//ua_comment show or hide the relevant admin boxes for the size/set functionality
function tttc_set_or_not( chkbox ){
	var visSetting = (chkbox.checked) ? "block" : "none"; 
	if( visSetting == 'none' ){
		document.getElementById('products_in_set').style.display = 'none';
		document.getElementById('product_dimensions').style.display = 'block';
		document.getElementById('not_set').name = 'Product[is_set]';
	}else{
		document.getElementById('products_in_set').style.display = 'block';
		document.getElementById('product_dimensions').style.display = 'none';
		document.getElementById('not_set').name = '';
	};
}