// JavaScript Document
function toggle(id,speed){
	if(!speed) speed = "slow";
	$("#"+id).toggle(speed);	
}
function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}

function edit_orderitem(oiId,qty,price,product){
    var popID = "popup_window";//Get Popup Name
    var popWidth = 700;
	message = "<form name='editoi' method='post'>Product :"+product+"<br/>Quantity : <input type='text' name='oiEditQty' value='"+qty+"'><br/>Price Each : <input type='text' name='oiEditPrice' value='"+price+"' /><input type='hidden' name='editOiSbmt' value='1' /><input type='hidden' name='editOiId' value='"+oiId+"' />";
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).html(message+'<br/><input type="image" src="/images/ok.gif" class="btn_close" title="Close Window" Border="0" alt="Close" /></form>');
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
});
}


function view_order_admin(orderId){
    var popID = "popup_window";//Get Popup Name
    var popWidth = 700;
	message = "<iframe src='/pageelements/view_order.php?orId="+orderId+"' frameborder='0' scrolling='no' height='600' width='700'></iframe>";
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).html(message+'<br/><a href="print_address.php?orId='+orderId+'" target="_blank"><img src="/images/print_address_label.png" title="Print Address Label" Border="0" alt="Print Address Label" /></a>&nbsp;<a href="print_order.php?orId='+orderId+'" target="_blank"><img src="/images/print_order_details.png" title="Print Order Details" Border="0" alt="Print Order Details" /></a>&nbsp;<a href="#" class="close"><img src="/images/ok.gif" class="btn_close" title="Close Window" Border="0" alt="Close" /></a>');
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
});
}

function view_order(orderId){
    var popID = "popup_window";//Get Popup Name
    var popWidth = 700;
	message = "<iframe src='/pageelements/view_order.php?orId="+orderId+"' frameborder='0' scrolling='no' height='600' width='700'></iframe>";
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).html(message+'<br/><a href="#" class="close"><img src="/images/ok.gif" class="btn_close" title="Close Window" Border="0" alt="Close" /></a>');
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
});
}

function popup(message){
    var popID = "popup_window";//Get Popup Name
    var popWidth = 300;
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).html(message+'<a href="#" class="close"><img src="/images/ok.gif" class="btn_close" title="Close Window" Border="0" alt="Close" /></a>');
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
});
}

function popup_reload(message){
    var popID = "popup_window";//Get Popup Name
    var popWidth = 300;
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).html(message+'<a href="#" class="close"><img src="/images/ok.gif" class="btn_close" title="Close Window" Border="0" alt="Close" /></a>');
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
		location.reload(true);
    });
});
}

function addtobasket(productId){
		var quantity = $('#qty_'+productId).val();
		if(quantity > 0){
			$.post("/ajax/addbasket.php", { product: productId, qty: quantity},function(data){
			$('#basket_text').html(data);
			$('#view_basket').html("<a href=\"/basket.html\">View the items in your basket and/or buy</a>");
			if(productId == 2280) popup_reload(data); else popup(data);
			// update basket values
			}); 
		} else {
			popup('Please enter the quantity you want');	
		}
}

function updatebasket(productId){
		var quantity = $('#qty_'+productId).val();
			$.post("/ajax/updatebasket.php", { product: productId, qty: quantity},function(data){
			$('#basket_text').html(data);
			popup_reload(data);
			// update basket values
			}); 
}

function removevoucher(voucherId){
		var quantity = 0;
			$.post("/ajax/removevoucher.php", { voucher: voucherId},function(data){
			popup_reload(data);
			// update basket values
			}); 
}

function removebasket(productId){
		var quantity = 0;
			$.post("/ajax/updatebasket.php", { product: productId, qty: quantity},function(data){
			$('#basket_text').html(data);
			popup_reload(data);
			// update basket values
			}); 
}
