var GCIDs = new Array();

$(document).ready(function(){
	
	  if ($('#section').val() == 8){
		  $(".faded").attr('readonly', 'readonly');
	  }

	$('#section').change(function(){
		
		if($('#section').val() == 8){
			$(".faded").attr('readonly', 'readonly');
		}
		else{
			$(".faded").removeAttr('readonly');
		}
		
		});

});


function userFormCheck(frm){
	
	if($('#fname').val().length > 0 &&
	$('#zip').val().length > 0 &&
	$('#email').val().length > 0 &&
	$('#password').val().length > 0 && 
	$('#accountType').val() != ""  ){
		//valid
		$('#'+frm).submit();
	}
	else{
		alert("Group, first name, zip code, email address, and password are required.");
	}
		




	
}


function toggleDisplay(id, val)
{
	 var b = document.getElementById(id);
	 b.className = val;
}


function showAddDealer(){

	$('#accountType').change(function() {
		//alert("doing it. " + this.options[this.selectedIndex].text);
	    if(this.options[this.selectedIndex].text == 'Dealer'){
	    	$('#cust_form').hide();
	    	$('#dealer_form').show();
	    }else{
	    	$('#dealer_form').hide();
	    	$('#cust_form').show();
	    }
	});
	$('.acct').val($('#accountType').val());
	
}


function confirmAction(url, text){
	if (confirm(text)){
		document.location = url;
	}
}

function addGCID(id){
	//alert("added a GCID!");
	GCIDs.push(id);
}

function checkBuyNow(){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	var msg = "All gift certificates MUST have valid a email for the recipient before purchasing!";
	var allow = true;
	//do they have a gift certificate they are purchasing?
	/*if(GCIDs.length > 0){
		//they have GC(s) in the cart, enforce they are filled with valid email before form submission
		for(i=0; i< GCIDs.length; i++){	
			if(!emailPattern.test($("#recipient_"+GCIDs[i]).val())){
				//invalid email entered, deny
				allow = false;
			} 
		}
	}*/
	
	if ($('#shipping_method').val() == '0') {
		allow = false;
		msg = 'Please choose a shipping method.';
	}
	
	if(allow){
		
		/*if(GCIDs.length == 0){
			document.location='index.php?action=billing&type=3';
		}
		else{
			document.GCLength = GCIDs.length;
			for(i=0; i< GCIDs.length; i++){
				document.currenti = i;
				//alert("running through GCIDS creating session entry with "+GCIDs[i]+" and "+$("#recipient_"+GCIDs[i]).val());	
				$.get('lib/addGCRecipToSession.php', { id: GCIDs[i], v: $("#recipient_"+GCIDs[i]).val()}, 
					function(){
						if(document.currenti+1 == document.GCLength){
							document.location='index.php?action=billing&type=3';
						}
					});
			}
		}*/
		document.location='index.php?action=billing&type=3';
		
	}
	else{
		alert(msg);
	}
}

function previewPage(sendurl, senddata){
	alert('Preview is opening in a new window.\nIf you are having trouble viewing the preview,\ncheck to make sure Javascript is enabled.');
}

function checkEmpty(field,form) {
	var a = document.getElementById(form);

	//if (document.getElementById('categorysearch').value == 'none'){
		if (document.getElementById(field).value != ''){
			a.submit();
		}
	//} else {
		//a.submit();
	//}
}
function BrowseServer(field)
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.BasePath = '../ckfinder/' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	

	finder.SelectFunction = SetFileField;
	finder.SelectFunctionData = field ;

	finder.Popup() ;
	
	// It can also be done in a single line, calling the "static"
	// Popup( basePath, width, height, selectFunction ) function:
	// CKFinder.Popup( '../../', null, null, SetFileField ) ;
}

// This is a function which is called when a file is selected in CKFinder.
function SetFileField( fileUrl, data)
{
	//alert(data["selectFunctionData"]);
	document.getElementById( data["selectFunctionData"] ).value = fileUrl ;
}

function ShowFile( fileUrl )
{
	window.open(fileUrl,'_blank', 'fullscreen=0,menubar=0,status=0,toolbar=0');
}

function updateDistPrice() {
	var num = (document.getElementById('wholesaleprice').value *	document.getElementById('distributerprice').value);
	document.getElementById('total').innerHTML = num.toFixed(2);	
}

function checkone(id){
	var pid = "pid_" + id;
	var p = document.getElementById(pid);
	var qty = p.value;
	if(qty == ''){
		p.value = 1;
	}
}


/* ================================== */

function updateCounter(num, id, type){
	if (typeof type == 'undefined' ) type = 'int';
    if (typeof id == 'undefined' ) id = 'cart_total';

	if (type == 'float') {
		$('#'+id).html(num.toFixed(2));	
	} else {
		$('#'+id).html(num);
	}
}

function updateCart(id, qty, price, now){
    // All cart add/update/deletes will go through here

    if (typeof price == "undefined") { price = false; }
    if (typeof now == "undefined") { now = true; }

	$.get('lib/updateCart.php', { prod_id: id, add: qty, price: price, now: now },
	function(data){
        //alert(data);
		var data_arr = data.split("|");
		
		updateCounter(data_arr[0], "cart_items");
		
		updateCounter(data_arr[1], "cart_total");

        flashBG("cartSummary","#FFFF00");

    } );
}

function updateCartGo(id, qty, price, now){

    if (typeof price == "undefined") { price = false; }
    if (typeof now == "undefined") { now = true; }

	$.get('lib/updateCart.php', { prod_id: id, add: qty, price: price, now: now },
	function(data){
		addUpsell('upsell_add');
        setTimeout("location.assign('index.php?action=cart');",250);
    } );
}

function refreshCart() {
    /*
    $.ajax({
        url: "lib/refreshCart.php",
        async: false,
        success: function(){
            location.assign('index.php?action=cart');
        }
    });
    */
    location.assign('index.php?action=cart');
    //$("#total_msg").css({backgroundColor:"green", color:"white", padding:"3px 5px"}).show().fadeOut(1500);
}


function addUpsell(e) {
	$("input[name^='"+e+"']").map( function() {
		var p = $(this).attr('id').split('_');

		if ($(this).attr('checked') == true) {
			$.get('lib/updateCart.php', { prod_id: p[1], add: 1, price: false, now: false },
			function(data){	
		        return data;
		    } );
		}		
	});
}


/* ================================== */



function sendWishlist(wid, recip, sender) {

    $.post('lib/sendWishlist.php', { wid: wid, recip: recip, sender: sender},
	function(data){

		$("#sent_msg").css({backgroundColor:"green", color:"white", padding:"3px 5px"}).show();		//.fadeOut(1500)
  } );
    
    
}



// NEW : uses jQuery instead of all the code at the top of this page. So that can all be removed
function fBoxNew() {
	var boxHeight = $("#floatingBox").outerHeight();
	
	if ( boxHeight > 475 ) {
		var mbOffset = 490;
		var ptOffset = 900;
	} else {
		var mbOffset = 540;
		var ptOffset = 650;	
	}

    var maxBottom = $("#main").outerHeight() - $("#floatingBox").outerHeight()-mbOffset;
    var posTop = $(window).scrollTop();

	if (posTop > ($("#main").outerHeight()-ptOffset)) {
		var y = maxBottom + 'px';
	} else if (posTop > 145) {
		var y = (posTop-144) + 'px';	
	} else {
		var y = '0px';
	}

	$("#floatingBox").css({ top: y, visibility: "visible" });
}




function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function changeQty(elem, qtyelem) {
	var oc = String(elem.onclick);
	var qty = document.getElementById(qtyelem).value;
	var newoc = oc.replace('add=1', 'add='+qty);
	
	return true;
}

function flashBG(elem, color) {
	//document.getElementById(elem).style.backgroundColor=color;
	//setTimeout ( "setBG('"+elem+"', 'transparent')", 1000 );
	var fadeto = $('#'+elem).css('backgroundColor');
	$('#'+elem).stop().css('backgroundColor', color).animate({
		backgroundColor: fadeto
	}, 5000);
}

function setBG(elem, color) {
	document.getElementById(elem).style.backgroundColor=color;
}

function compareit(item){
	//each time this is called you need to keep a counter
	//we also need to make sure that it is checked
	
	val = document.getElementById(item).checked;

	if(val==true){
		window.count++;

		if (window.count == 3)
		{
			var rows = document.getElementsByTagName('input');
			for( var i = 0, row; row = rows[i]; i++ ) {
			  if (row.className == "compare" && row.checked == false)
			  {
				  row.disabled = true;
			  }
			}
		}

		if(window.item1==''){
			window.item1 = item;
			return;
		}else if(window.item2==''){
			window.item2 = item;
			return;
		}else if(window.item3==''){
			window.item3 = item;
			return;
		}
	}else if(val==false){
		window.count--;
		if(window.item3 == item){
			window.item3 = '';
		}else if(window.item2 == item){
			window.item2 = '';
		}else if(window.item1 == item){
			window.item1 = '';
		}

		var rows = document.getElementsByTagName('input');
		for( var i = 0, row; row = rows[i]; i++ ) {
		  if (row.className == "compare" && row.checked == false)
		  {
			  row.disabled = false;
		  }
		}
	}
}	

function compare () {
	if(window.count > 3){
		alert("Please choose up to three (3) items to compare.");
	} else if(window.count <= 0) {
		alert("Please choose at least 1 item to compare.");
	}else{
		document.getElementById("item1").value=window.item1.replace(/s_/,"");
		document.getElementById("item2").value=window.item2.replace(/s_/,"");
		document.getElementById("item3").value=window.item3.replace(/s_/,"");

		document.getElementById("compareSubmitForm").submit();
	}
}

function show (elem) {

	d = $('div');
	j=0;
	var cl = new Array()
	for(i=0;i<d.length;i++){
		if(d[i].className == 'visible'){
			d[i].className = 'invisible';
			j++
		}
	}

	document.getElementById(elem).className = 'visible';
}

function deleteImage(name)
{
	$.get('lib/deleteimage.php', { nm: name },
	function(data)
	{
		$('#image_wrap').html(data);
  	});
}


function deleteOrder(id)
{
	if (confirm('Really DELETE order '+id+'?'))
	{
		$.get('../admin/ajax_deleteorder.php', { id: id },
		function(data)
		{
			alert(data);
			window.location.reload();
		});
	}
}


function popup(url, width, height) {
    var tpos = ($(window).height()/2)-(height/2);
    var lpos = ($(window).width()/2)-(width/2);
    
    var par = "location=no,scrollbars=yes,status=no,width="+width+",height="+height+",left="+lpos+",top="+tpos;
    return window.open(url, "", par);
}

function confirmConvClub() {
    popup("lib/convclubfinish.php", 650, 520);

    return true;
}

function finishConvClub(mail) {
    if (typeof mail == "undefined") {
        mail = false;
    }
    $.get('lib/convenienceclub.php', { action: 'finish', mail: mail }, function(data){ 
        //alert(data);
    });
}

function submitForm (elem) {
    $("#"+elem).submit();

    return true;
}

function saveConvClub (id, qty, price, go) {
    if (typeof id == "undefined") {
        id = false;
    }
    if (typeof qty == "undefined") {
        qty = 1;
    }
    if (typeof price == "undefined") {
        price = 0;
    }       
    if (typeof go == "undefined") {
        go = 0;
    }
    
    if (id != false) {
        if (go == 1) {
            popup('lib/convclubmenu.php?id='+id+'&qty='+qty+'&price='+price+'&go='+go, 650, 650);
        } else {
            popup('lib/convclubmenu.php?id='+id+'&qty='+qty+'&price='+price, 650, 650);
        }
    }

    //return true;
}


function saveGiftCert (id, qty, price, go) {
    if (typeof id == "undefined") {
        id = false;
    }
    if (typeof qty == "undefined") {
        qty = 1;
    }
    if (typeof price == "undefined") {
        price = 0;
    }     
    if (typeof go == "undefined") {
        go = 0;
    }
    
    if (id != false) {
        if (go == 1) {
            popup('lib/giftcertificatemenu.php?id='+id+'&qty='+qty+'&price='+price+'&go='+go, 650, 650);
        } else {
            popup('lib/giftcertificatemenu.php?id='+id+'&qty='+qty+'&price='+price, 650, 650);
        }
    }
}


function validateOrderConvClub() {
	if (($('#prim_saddr').attr('checked') == true && $('#prim_saddr').val() == '0')) {
		alert('Your primary appears to be invalid, please check your My Address Book settings.');
	} else if (($('#prim_ccard').attr('checked') == true && $('#prim_ccard').val() == '0')) {
		alert('Your primary credit card appears to be invalid, please check your My Wallet settings.');
	} else if (($('#saddr').attr('checked') == true && ($('#addresses').val() == '0' || $('#addresses').val() == 'new'))) {
		alert('The address selected appears to be invalid, please choose a different one or check your My Address Book settings.');
	} else if (($('#ccard').attr('checked') == true && ($('#cards').val() == '0' || $('#cards').val() == 'new'))) { 
		alert('The credit card selected appears to be invalid, please choose a different one or check your My Wallet settings.');		 
	} else { 
		popup("lib/convclubfinish.php", 650, 520);
	}
}


function validateOrderInfo () {
	if (($('#prim_saddr').attr('checked') == true && $('#prim_saddr').val() == '0')) {
		alert('Your primary appears to be invalid, please check your My Address Book settings.');
	} else if (($('#prim_ccard').attr('checked') == true && $('#prim_ccard').val() == '0')) {
		alert('Your primary credit card appears to be invalid, please check your My Wallet settings.');
	} else if (($('#saddr').attr('checked') == true && ($('#addresses').val() == '0' || $('#addresses').val() == 'new'))) {
		alert('The address selected appears to be invalid, please choose a different one or check your My Address Book settings.');
	} else if (($('#ccard').attr('checked') == true && ($('#cards').val() == '0' || $('#cards').val() == 'new'))) { 
		alert('The credit card selected appears to be invalid, please choose a different one or check your My Wallet settings.');		 
	} else {
		// create and show loading screen
		$('body').append('<div style="position:absolute;top:0;left:0;z-index:999;background:#fff;width:100%;height:100%;text-align:center;"><div style="width:300px;height:300px;margin: 10% auto 0 auto;text-align:center;"><img src="images/logo.jpg" alt="MyParrotFood.com" /><br /><img src="images/loader.gif" alt="loading" /><br /><br />Please wait... We are processing your transaction.<br /><br />Please do not close or stop your browser. Depending on your connection speed, this may take a few minutes.</div></div>');
		
		$('#id_frm').submit();
	}
}


function validateDealerInfo () {
	if (($('#prim_saddr').attr('checked') == true && $('#prim_saddr').val() == '0') 
		|| $('#saddr').attr('checked') == true && ($('#addresses').val() == '0' || $('#addresses').val() == 'new')) {
		if (($('#prim_ccard').attr('checked') == true && $('#prim_ccard').val() == '0') 
		|| $('#ccard').attr('checked') == true && ($('#cards').val() == '0' || $('#cards').val() == 'new')) {
			alert('Please select a valid shipping address and payment method');
		} else {
			alert('Please select a valid shipping address');
		}
	} else if (($('#prim_ccard').attr('checked') == true && $('#prim_ccard').val() == '0') 
		|| $('#ccard').attr('checked') == true && ($('#cards').val() == '0' || $('#cards').val() == 'new')) {
		alert('Please select a valid payment method');
	} else {
		if ($('#shipping_method').val() == '0') {
			alert('Please choose a shipping method.');
		} else {
			// create and show loading screen
			$('body').append('<div style="position:absolute;top:0;left:0;z-index:999;background:#fff;width:100%;height:100%;text-align:center;"><div style="width:300px;height:300px;margin: 10% auto 0 auto;text-align:center;"><img src="images/logo.jpg" alt="MyParrotFood.com" /><br /><img src="images/loader.gif" alt="loading" /><br /><br />Please wait... We are processing your transaction.<br /><br />Please do not close or stop your browser. Depending on your connection speed, this may take a few minutes.</div></div>');
						
			$('#id_frm').submit();
		}
	}
}


function saveMyReminder (id, price) {
    if (typeof id == "undefined") {
        id = false;
    }

    if (typeof price == "undefined") {
        price = 0;
    }  
    
    if (id != false) {
        popup('lib/remindersmenu.php?id='+id+'&price='+price, 650, 650);
    }
}


function toggleConvClubItem (id, save) {
    $.get('lib/convclubtoggle.php', { id: id, save: save }, function(data){ if(data=='reload'){ location.reload(); } });
}

function fillTabInfo(id) {
    var inst = FCKeditorAPI.GetInstance("tab");
    inst.SetHTML(html_entity_decode($("#tab"+id).html()));

    $("#tabheader").val($("#tab"+id+"header").val());
    $("#tab_number").val(id);
}

function saveTabInfo(id) {
    var inst = FCKeditorAPI.GetInstance("tab");
    var sValue = inst.GetHTML();

    $("#tab"+id+"header").val($("#tabheader").val());
    $("#tab"+id).val(sValue); //$("#tab").html()

    $('#tab_msg').slideDown(500).fadeOut(5000);
}


function showLoading () {
	$('body').append('<div style="position:absolute;top:0;left:0;z-index:999;background:#fff;width:100%;height:100%;text-align:center;"><div style="width:300px;height:300px;margin: 10% auto 0 auto;text-align:center;"><img src="images/logo.jpg" alt="MyParrotFood.com" /><br /><img src="images/loader.gif" alt="loading" /><br /><br />One moment please...</div></div>');
}


// update shipping method
function setShippingMethod (val) {

	var pArr = val.split('_');
	
	$('#shipper').val(pArr[0]);
	$('#shipping_service').val(pArr[1]);
	$('#shipping_rate').val(pArr[2]);
	
	showLoading();
	
	$('#shipping_form').submit();
}


function saveCard () {
	var c, params = '';
	c = $('#card_menu input, #card_menu select');
	params = c.serialize();

    if ( $('#card_code').val() == '' ) {
        $('#card_code').css('backgroundColor', '#FFE1E1').css('borderColor', '#CC0000');
        alert('Please provide a CVV.');
        return false;
    }

	$.get('lib/saveCard.php', params, 
		function(data) {
			alert(data);
			location.reload();
		}
	);
}

function saveAddress () {
	var c, params = '';
	c = $('#addr_menu input, #addr_menu select');
	params = c.serialize();

	$.get('lib/saveAddress.php', params, 
		function(data) {
			alert(data);
			location.reload();
		}
	);
}

function getForm (type,edit) {
	
	if (edit == undefined) {
		edit = 0;
	}
	
	$.get('lib/getForm.php', { type: type, edit: edit }, function(data) {
        data = '<a class="close-link" href="#" onclick="$(\'#add_new_'+type+'\').hide().html(\'\');return false;" title="close">[x]</a>' + data;

		$('#add_new_'+type).html(data).show('slow');
	});
}

function getBlock (type,id) {	
	$.get('lib/getBlock.php', { type: type, id: id }, function(data) {
        data = '<a class="close-link" href="#" onclick="$(\'#add_new_'+type+'\').hide().html(\'\');return false;" title="close">[x]</a>' + data;

		$('#add_new_'+type).html(data).show('slow');
	});
}

function checkAll (e) {
	$('#'+e+' input[class=checkall]').attr('checked', true);
}

function uncheckAll (e) {
	$('#'+e+' input[class=checkall]').attr('checked', false);
}



function loginAs (e) {
	// submit form e with redirect if user confirms
	// otherwise just submit

	if (confirm('Redirect to User Account?')) {
		$(e).prepend('<input type="hidden" name="login_as" value="1" /><input type="hidden" name="redirect" value="index.php?action=account" />').submit();
	} else {
		$(e).prepend('<input type="hidden" name="login_as" value="1" />').submit();
	}
}




function checkPair (e1, e2) {
	if ($('#'+e1).attr('checked') == false && $('#'+e2).attr('checked') == false) {
		$('#'+e1).attr('checked', true);
	}
}



////////////////////////////////// decode

function html_entity_decode( string, quote_style ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: marc andreu
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
 
    var histogram = {}, symbol = '', tmp_str = '', i = 0;
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    
    return tmp_str;
}

function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
    
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
      entities['38'] = '&amp;';
      entities['60'] = '&lt;';
      entities['62'] = '&gt;';
      entities['160'] = '&nbsp;';
      entities['161'] = '&iexcl;';
      entities['162'] = '&cent;';
      entities['163'] = '&pound;';
      entities['164'] = '&curren;';
      entities['165'] = '&yen;';
      entities['166'] = '&brvbar;';
      entities['167'] = '&sect;';
      entities['168'] = '&uml;';
      entities['169'] = '&copy;';
      entities['170'] = '&ordf;';
      entities['171'] = '&laquo;';
      entities['172'] = '&not;';
      entities['173'] = '&shy;';
      entities['174'] = '&reg;';
      entities['175'] = '&macr;';
      entities['176'] = '&deg;';
      entities['177'] = '&plusmn;';
      entities['178'] = '&sup2;';
      entities['179'] = '&sup3;';
      entities['180'] = '&acute;';
      entities['181'] = '&micro;';
      entities['182'] = '&para;';
      entities['183'] = '&middot;';
      entities['184'] = '&cedil;';
      entities['185'] = '&sup1;';
      entities['186'] = '&ordm;';
      entities['187'] = '&raquo;';
      entities['188'] = '&frac14;';
      entities['189'] = '&frac12;';
      entities['190'] = '&frac34;';
      entities['191'] = '&iquest;';
      entities['192'] = '&Agrave;';
      entities['193'] = '&Aacute;';
      entities['194'] = '&Acirc;';
      entities['195'] = '&Atilde;';
      entities['196'] = '&Auml;';
      entities['197'] = '&Aring;';
      entities['198'] = '&AElig;';
      entities['199'] = '&Ccedil;';
      entities['200'] = '&Egrave;';
      entities['201'] = '&Eacute;';
      entities['202'] = '&Ecirc;';
      entities['203'] = '&Euml;';
      entities['204'] = '&Igrave;';
      entities['205'] = '&Iacute;';
      entities['206'] = '&Icirc;';
      entities['207'] = '&Iuml;';
      entities['208'] = '&ETH;';
      entities['209'] = '&Ntilde;';
      entities['210'] = '&Ograve;';
      entities['211'] = '&Oacute;';
      entities['212'] = '&Ocirc;';
      entities['213'] = '&Otilde;';
      entities['214'] = '&Ouml;';
      entities['215'] = '&times;';
      entities['216'] = '&Oslash;';
      entities['217'] = '&Ugrave;';
      entities['218'] = '&Uacute;';
      entities['219'] = '&Ucirc;';
      entities['220'] = '&Uuml;';
      entities['221'] = '&Yacute;';
      entities['222'] = '&THORN;';
      entities['223'] = '&szlig;';
      entities['224'] = '&agrave;';
      entities['225'] = '&aacute;';
      entities['226'] = '&acirc;';
      entities['227'] = '&atilde;';
      entities['228'] = '&auml;';
      entities['229'] = '&aring;';
      entities['230'] = '&aelig;';
      entities['231'] = '&ccedil;';
      entities['232'] = '&egrave;';
      entities['233'] = '&eacute;';
      entities['234'] = '&ecirc;';
      entities['235'] = '&euml;';
      entities['236'] = '&igrave;';
      entities['237'] = '&iacute;';
      entities['238'] = '&icirc;';
      entities['239'] = '&iuml;';
      entities['240'] = '&eth;';
      entities['241'] = '&ntilde;';
      entities['242'] = '&ograve;';
      entities['243'] = '&oacute;';
      entities['244'] = '&ocirc;';
      entities['245'] = '&otilde;';
      entities['246'] = '&ouml;';
      entities['247'] = '&divide;';
      entities['248'] = '&oslash;';
      entities['249'] = '&ugrave;';
      entities['250'] = '&uacute;';
      entities['251'] = '&ucirc;';
      entities['252'] = '&uuml;';
      entities['253'] = '&yacute;';
      entities['254'] = '&thorn;';
      entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    if (useQuoteStyle != 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    
    if (useQuoteStyle == 'ENT_QUOTES') {
        entities['39'] = '&#039;';
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal)
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}

