function clearProducts(products) {
	// Loop through each product in the array
	for (x=0; x<products.length; x++)
	{
		// Get the specific product-stock level
		var product = products[x];
		var item = document.getElementById('product'+product);
		item.style.display = 'none';
	}
}

function highlightMenuItem(menuItem, backgroundPositionNumber, locked) {

	if(locked == 1) {
		document.getElementById(menuItem).style.backgroundPosition = backgroundPositionNumber + ' 0px';
	}
}


function popitup(url) {
	newwindow=window.open(url,'name','height=500,width=700');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitup2(url) {
	newwindow=window.open(url,'name','resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,height=500,width=700');
	if (window.focus) {newwindow.focus()}
	return false;
}

function displayProduct(product) {
	var item = document.getElementById('product'+product);
	item.style.display = 'block';
	var the_id = item.id.replace('product', '');
	$('input.size-'+the_id).attr('checked', 'checked');
}

function myPopup(url,windowname,w,h,x,y){
	window.open(url,windowname,"resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
}

function selectPressCutting(pressRelease, pressReleaseDate) {
	/*
	var pressItem = document.getElementById(pressRelease);
	var pressDate = document.getElementById(pressReleaseDate);

	pressItem.style.border = 'solid #60499f 1px';
	pressDate.style.color = '#60499f';
	*/
}

function unSelectPressCutting(pressRelease, pressReleaseDate) {
	/*
	var pressItem = document.getElementById(pressRelease);
	var pressDate = document.getElementById(pressReleaseDate);

	pressItem.style.border = 'solid transparent 1px';
	pressDate.style.color = '#B3A59F';
	*/
}

function IsDeliverySame_clicked(checkbox) {
    if (checkbox.checked == true) {

    	var billingDetails = document.getElementById('billing-details');
    	billingDetails.style.display = "none";

    	var billingAddress = document.getElementById('billing-address');
    	billingAddress.style.display = "none";

    	document.customer_form.firstName.value = "n/a";
    	document.customer_form.surname.value = "n/a";
    	document.customer_form.phone.value = "n/a";
    	document.customer_form.addressLine1.value = "n/a";
    	document.customer_form.addressLine2.value = "n/a";
    	document.customer_form.city.value = "n/a";
    	document.customer_form.postCode.value = "n/a";

    }
    else
    {
    	var billingDetails = document.getElementById('billing-details');
    	billingDetails.style.display = "block";

    	var billingAddress = document.getElementById('billing-address');
    	billingAddress.style.display = "block";

  	 	document.customer_form.firstName.value = "";
    	document.customer_form.surname.value = "";
    	document.customer_form.phone.value = "";
    	document.customer_form.addressLine1.value = "";
    	document.customer_form.addressLine2.value = "";
    	document.customer_form.city.value = "";
    	document.customer_form.postCode.value = "";
		document.customer_form.firstName.style.display = "block";
    }
}

function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

{
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {
            div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
			div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };

			div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
			div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

this.scrollDown = function() {
        if (this.div_obj) {
            this.scrollCursor += this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
        }
    }

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}

$(document).ready(function()
{
	var tmp_link_checkout = $('#link-checkout').attr('href');
	$('#link-checkout').click(function() {
		if ($('#discount').val() != undefined && $('#discount').val() != '')
			$(this).attr('href', tmp_link_checkout+'?discount='+$('#discount').val());
	});

	if ($('input#sameDeliveryAddress').attr('checked') != undefined && $('input#sameDeliveryAddress').attr('checked') == true) {
		$('#billing-details, #billing-address').hide();
	}

	$('a.lightbox').each(function(){$(this).lightBox();});

	var current_press_page = $('.pnav a.hi');
	var new_press_page = false;
	$('div.press-page').hide();
	$('h2.press-title').hide();

	$('.pnav a').click(function()
	{
		current_press_page.removeClass('hi');
		$(current_press_page.attr('href')).hide();
		$($(this).attr('href')).show();
		$(this).addClass('hi');
		current_press_page = $(this);
		return false;
	});

$('#productImage184').hide();
$('#product180 .productName').html('Rivet Belt: Black-silver');
$('#product184 .productName').html('Rivet Belt: Black-silver');

$('#productImage185').hide();
$('#product181 .productName').html('Rivet Belt: Black-gold');
$('#product185 .productName').html('Rivet Belt: Black-gold');

$('#productImage186').hide();
$('#product176 .productName').html('Stud Belt: Black-silver');
$('#product186 .productName').html('Stud Belt: Black-silver');

$('#productImage187').hide();
$('#product177 .productName').html('Stud Belt: Black-gold');
$('#product187 .productName').html('Stud Belt: Black-gold');

$('#productImage189').hide();
$('#product188 .productName').html('Stud Belt: Brown-gold');
$('#product189 .productName').html('Stud Belt: Brown-gold');

$('#productImage199').hide();
$('#product198 .productName').html('Stud Belt: Grey-silver');
$('#product199 .productName').html('Stud Belt: Grey-silver');

$('#productImage201').hide();
$('#product200 .productName').html('Stud Belt: Brown-gold');
$('#product201 .productName').html('Stud Belt: Brown-gold');

	$('.size input').change(function()
	{
		clearProducts(products);
		displayProduct($(this).val());
		$('input.size-'+$(this).val()).attr('checked', 'checked');
	});

	if ($('#deliveryCountry').val() != 'US') { $('#state-delivery').hide(); }
	if ($('#country').val() != 'US') { $('#state').hide(); }
	$('#country').change(function() { if ($(this).val() == 'US') { $('#state').show(); } else { $('#state').hide(); } });
	$('#deliveryCountry').change(function() { if ($(this).val() == 'US') { $('#state-delivery').show(); } else { $('#state-delivery').hide(); } });

	$('#frm_products_show').change(function ()
	{
		if ($(this).val() == 'all')
		{
			$('.tbl-product-update tr').each(function() { $(this).show(); });
		}
		else if ($(this).val() == 'sale')
		{
			$('.tbl-product-update td.sale').each(function() {
				if ($(this).html() == 'No') { $(this).parent().hide(); } else { $(this).parent().show(); }
			});
		}
		else if ($(this).val() == 'non-sale')
		{
			$('.tbl-product-update td.sale').each(function() {
				if ($(this).html() == 'Yes') { $(this).parent().hide(); } else { $(this).parent().show(); }
			});
		}
		else if ($(this).val() == 'sold-out')
		{
			$('.tbl-product-update td.sold-out a').each(function() {
				if ($(this).html() == 'No') { $(this).parent().parent().hide(); } else { $(this).parent().parent().show(); }
			});
		}
		else if ($(this).val() == 'non-sold-out')
		{
			$('.tbl-product-update td.sold-out a').each(function() {
				if ($(this).html() == 'Yes') { $(this).parent().parent().hide(); } else { $(this).parent().parent().show(); }
			});
		}
		else if ($(this).val() == 'live')
		{
			$('.tbl-product-update td.deprecated a').each(function() {
				if ($(this).html() == 'No') { $(this).parent().parent().hide(); } else { $(this).parent().parent().show(); }
			});
		}
		else if ($(this).val() == 'offline')
		{
			$('.tbl-product-update td.deprecated a').each(function() {
				if ($(this).html() == 'Yes') { $(this).parent().parent().hide(); } else { $(this).parent().parent().show(); }
			});
		}
	});

	$('.tbl-product-update td.sale a').click(function()
	{
		var product = $('td.name', $(this).parent().parent()).html();
		if ($(this).html() == 'Yes') {
			var result = confirm("Are you sure you wish to mark '"+product+"' as a non-sale item?");
		} else {
			var result = confirm("Are you sure you wish to mark '"+product+"' as a sale item?");
		}
		if (!result) { return false; }
	});

	$('.tbl-product-update td.deprecated a').click(function()
	{
		var product = $('td.name', $(this).parent().parent()).html();
		if ($(this).html() == 'Yes') {
			var result = confirm("Are you sure you wish to take '"+product+"' off the website?");
		} else {
			var result = confirm("Are you sure you wish to put '"+product+"' live?");
		}
		if (!result) { return false; }
	});

	$('.tbl-product-update td.sold-out a').click(function()
	{
		var product = $('td.name', $(this).parent().parent()).html();
		if ($(this).html() == 'Yes') {
			var result = confirm("Are you sure you wish to mark '"+product+"' as available?");
		} else {
			var result = confirm("Are you sure you wish to mark '"+product+"' as sold out?");
		}
		if (!result) { return false; }
	});

	$('.show-hide').click(function()
	{
		$('#show-hide-'+$(this).html()).slideToggle();
	});
});
