$(document).ready(function(){
		
		
    $("#label_display").tablesorter({ 
        // pass the headers argument and assing a object 
        headers: { 
            // assign the secound column (we start counting zero) 
            0: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }
        } 
    });  	
	
	$(".print").click(function(event){
		event.preventDefault();
		
		var load = window.open('/customer_print_queue_do.php','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
	});
	
	$(".add_print").click(function(event){
		event.preventDefault();
		thisItem = $(this);
		
		if($(this).hasClass("in_queue")) {
			alert("Already in queue");
		} else {
			$.ajax({
				url: $(this).attr("href"),
				success: function(data) {
					$(thisItem).addClass("in_queue");
					$(thisItem).after('<img src="/images/checkmark.png" width="16" height="16" hspace="5" border="0" />');
				}
			});
		}
		
	});
	
	if($("#pdf_download #uuid").size() > 0) {
		//alert('processing');
		uuid = $("#pdf_download #uuid").val();
		$.ajax({
			url: "/customer_print_pdf.php?uuid=" + uuid,
			timeout: 1000000,
			success: function(data) {
				$("#download_link").html(data); //need to removed
				$("#busy_image").hide();
				//openApplet(); //need to add
 			}
		});
	}
	
/*
	$("#print-queue-form #button").click(function(){
		if(navigator.javaEnabled()){
			//alert('You have java installed!');
			return true
		}
		else{
			alert('You must have java installed in order to print labels! Once this window is closes a new window will open to the location where it can be installed.');
			window.open ("http://www.java.com/en/download/","Java Download");
			return false;
		}
		
		
	});
	*/

	
});

 

function openApplet(){
		uuid = $("#pdf_download #uuid").val();
		uuid = uuid_encode(uuid);
		document.location = "pdf_viewer.php?uuid="+uuid;
		$.ajax({
			url: "pdf_viewer.php?uuid=" + uuid,
			timeout: 1000000,
			success: function(data) {
 			}
		});
}

function uuid_encode(data) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];
     if (!data) {
        return data;
    }
    //data = this.utf8_encode(data + ''); 
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++); 
        bits = o1 << 16 | o2 << 8 | o3;
 
        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);    } while (i < data.length);
 
    enc = tmp_arr.join('');
 
    switch (data.length % 3) {    case 1:
        enc = enc.slice(0, -2) + '==';
        break;
    case 2:
        enc = enc.slice(0, -1) + '=';        break;
    }
    return enc;
}
