function openJQUIPopup(page, action, params, dialog_title, w_width, w_height){
	if (typeof(w_width)=='undefined'){
		var w_width = 700;
	}
	
	if (typeof(w_height)=='undefined'){
		var w_height = 500;
	}
	
	if (typeof(params)=='undefined'){
		var params = "";
	}
	
	$('<div class="popupContainer" id="jq_popup">loading...</div>').
        dialog({
            stack: false,
            modal: true,
            title: dialog_title,
            width: w_width,
            height: w_height,
            close: function () {
                $(this).dialog("destroy").remove();
            },
            open: function() {
                //start_loading_dialog();
            }
        }).
        load(
            'ajax_handler.php',
            {
				'page': page,
				'action': action,
				'params': params
            }
        );
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500,left = 0,top = 0');");
}


    function checkLength(field, prefix) {
        var max = 35;
        var currentFieldValue = document.getElementById(field).value;
        var currentFieldLength = currentFieldValue.length;

        if (currentFieldLength > max) {
            currentFieldValue = currentFieldValue.substr(0,35);
            document.getElementById(field).value = currentFieldValue;
            var pos = prefix.length;
            field = field.substr(pos,field.length);
            document.getElementById(field+'1').innerHTML = (max - (currentFieldLength - 1));
        }

        max = '';
        currentFieldValue = '';
        currentFieldLength = '';
    }

function update_qty_in_shopping_cart(id, rowId)
{
    var prod_qty_obj = document.getElementById('product_quantities[' + id + ']');

    var formObj = document.cart_quantity;
    var total_qty = 0;
    var reg = new RegExp("size_"+ rowId+"_.+", "i");
    for (var i=0;i < formObj.length;i++)
    {
        fldObj = formObj.elements[i];
        if(reg.exec(fldObj.id))
        {
            if(fldObj.value != '')
            {
                total_qty = parseInt(total_qty) + parseInt(fldObj.value);
            }
        }
    }
    prod_qty_obj.value = total_qty;
}

function isNumber(e)
{
    var key;
	var keychar;
	var reg;

    if(window.event) {
	   key = e.keyCode;
	}else if(e.which) {
	   key = e.which;
	}else {
	   return true;
	}
	//allow for backspace and delete
	if (key == 8 || key == 127) {
		return true;
	}

	//allow keys 1-0
	if ((key > 43 && key < 58) && key != 47) {
		return true;
	}

	//strange, why use regular expression for 10 keys?
	//i'm leaving this, in case the above doesn't work on other keyboards.
    keychar = String.fromCharCode(key);
	reg = /(^-?[1-9](\d{1,2}(\,\d{3})*|\d*)|^0{1})$/;
	return reg.test(keychar);
}

function rowOverEffect(object)
{
    if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object)
{
    if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

$().ready(function() {
    $('#size_chart_link').click(function() {
        $($('#size_chart').html()).dialog({
            modal: true,
            title: "Size Chart",
            width: 580
        });
    });

    $('#chart_link').click(function() {
        $($('#size_chart').html()).dialog({
            modal: true,
            title: "Size Chart",
            width: 580
        });
    });
});

function size_chart_us_sizes() {
    $('.us_size').css('display', 'block');
    $('.unit').css('display', 'inline');
    $('.metric_size').css('display', 'none');
}
function size_chart_metric_sizes() {
    $('.metric_size').css('display', 'block');
    $('.unit').css('display', 'inline');
    $('.us_size').css('display', 'none');
}