function productpopup(destination, name) {
	var name = "product_" + Math.floor(Math.random()*1000000);
	window.open(destination,name,"menubar=no,width=570,height=750,toolbar=no,location=no,scrollbars=yes");
}
function arbitrarypopup(destination) {
	var name = "arbitrary_" + Math.floor(Math.random()*1000000);
	window.open(destination,name,"menubar=no,width=570,height=750,toolbar=no,location=no,scrollbars=yes");
}
function getAnEstimate()
{
	var name = "order_" + Math.floor(Math.random()*1000000);
	window.open("/place-order/", name, "menubar=no,width=850,height=750,toolbar=no,location=no,scrollbars=yes");
}
function getAnEstimateSpecial(product_id)
{
	var name = "order_" + Math.floor(Math.random()*1000000);
	window.open("/place-order/?id=" + product_id, name, "menubar=no,width=850,height=750,toolbar=no,location=no,scrollbars=yes");
}
function viewcart()
{
	window.open("/cart/", "cart", "menubar=no,width=500,height=500,toolbar=no,location=no");
}
function processKey(e)
{
  if (null == e)
    e = window.event ;
  if (e.keyCode == 13)  {
    document.getElementById("updateqty").click();
    return false;
  }
}

function startNewEstimate()
{
	var name = "order_" + Math.floor(Math.random()*1000000);
	window.open("/place-order/?__tcAction=newProject", name, "menubar=no,width=850,height=750,toolbar=no,location=no,scrollbars=yes");

	return false;
}

function loadSavedEstimates()
{
	var name = "order_" + Math.floor(Math.random()*1000000);
	window.open("/place-order/?__tcAction=retrieveEstimate", name, "menubar=no,width=850,height=750,toolbar=no,location=no,scrollbars=yes");

	return false;
}

var qq_uploader;
function qq_file_list()
{
    return $('#upload-form').find('[type=file]').filter(
        function() { return $(this).val(); }
    );
}
function ajax_upload()
{
    if (qq_file_list().length == 0) {
        return true;
    }

    $('#uploadpopup').show();
    $('#uploadpopup').css('position', 'fixed');
    $('#uploadpopup').css('top',
        $(window).height()/2 - $('#uploadpopup').height()/2
    );
    $('#uploadpopup').css('left',
        $(window).width()/2 - $('#uploadpopup').width()/2
    );
    
    pid = $('[name=pid]').val();
    itemid = $('[name=itemid]').val();

    qq_uploader = new qq.FileUploader({
        element: $('#file-uploader'),
        action: '/qq-uploader.php?pid=' + pid + '&itemid=' + itemid,
        maxConnections: 1,
        onComplete: ajax_upload_complete,
        debug: true
    });            

    // tell qq which files to upload
    qq_file_list().each(
        function() {
            qq_uploader._onInputChange(this);
        }
    );

    return false;
}
function ajax_upload_complete(id, fileName, response)
{
    // remove file from file input form
    if (response && response.success) {
        qq_file_list().each(
            function() {
                if ($(this).val().indexOf(fileName) != -1) {
                    $(this).val('');
                    return false;
                }
            }
        );
        if (qq_file_list().length == 0) {
            $('#upload-status-success').show();
        }
    } else {
        $('#upload-status-failure').show();
        qq_uploader._handler.cancelAll();
        qq_file_list().each(function() {
            $(this).val('');
        });
        qq_uploader._filesInProgress = 0;
    }

    if (qq_file_list().length == 0) {
        $('#upload-form').unbind('submit');
        ajax_upload_finish();
    }

}
function ajax_upload_cancel()
{
    $('#uploadpopup').hide();
    qq_uploader._handler.cancelAll();
    qq_uploader._filesInProgress = 0;
    $('.qq-upload-list').first().empty();
    qq_file_list().each(function() {
        $(this).val('');
    });
    return false;
}
function ajax_upload_finish()
{
    if (qq_uploader.getInProgress() == 0) {
        $('#upload-status-pending').hide();
        $('#upload-indicator').remove();
        $('#uploader-stop').hide();
        $('#uploader-continue').show();
    } else {
        setTimeout('ajax_upload_finish()', 1000);
    }
}

var redirandclose = function(destination)
{
	opener.location=destination;
	window.close();
};
var openTerms = function()
{
	var name = "message_" + Math.floor(Math.random()*1000000);
	window.open("/minipopup/termsandconditions/", name, "menubar=no,width=500,height=700,toolbar=no,location=no,scrollbars=1");
};

