
/**
 * AJAX load rates for a given fax number.
 * @param website_root The base URL of the pamfax website.
 */
function pf_get_rate_for_number(website_root)
{
    var currency_code = $('#currency_code').val();
    var fax_number = $('#fax_number').val();

    if('' == fax_number)
    {
        $('#please_enter_fax_number').fadeIn();
        return;
    }
    $('#please_enter_fax_number').hide();

    $('#rates_table_loading').show();
    setCookie('currency_code', currency_code, false, '/');
    $('#rates_table').hide().load(website_root+'/ajax/get_rates.php',
        {
            'fax_number' : fax_number,
            'currency_code': currency_code
        }, function () {
            $('#rates_table_loading').hide();
            $('#rates_table').fadeIn();
        });
}

/**
 * Helper function for rates pages.
 */
function ShowZone(zone,plan)
{
	if( zone < 1)
		document.getElementById('current_map_'+plan).style.display = 'inline';
	else
		document.getElementById('current_map_'+plan).style.display = 'none';
	for(var i=1; i<=7; i++)
	{
		if( i == zone )
		{
			document.getElementById('map_'+plan+'_'+i).style.display = 'inline';
			var price = document.getElementById('zone_price_'+plan+'_'+i).value;
			$('#price_at_zone_'+plan).html('<b>'+price+'</b>');
		}
		else
		{
			document.getElementById('map_'+plan+'_'+i).style.display = 'none';
		}
	}
}

function ShowFaxInInfo(website_root,country_id,state_code)
{
	var data = {website_root:website_root,country_id:country_id};
	if( state_code )
		data.state_code = state_code;
	
	$.get(website_root+'../ajax/get_country_info.php',data,function(d){ eval(d); });
}


var global_ping_interval = false;
jQuery(document).ready( function()
{
	global_ping_interval = setInterval(Ping, 2 * 60 * 1000);
});

function Ping()
{
	// keep session alive
	try {
		jQuery.get(wwwfullroot + "index.php", {state: "ping"});
	} catch(ex) {}
}

// transforms all inputs with type=button into skinned buttons
// make sure the image path is correct (relative to the doc root)
function ConvertButtonsCI(prefix)
{
	jQuery("input[type=button][noci!=true], input[type=submit][noci!=true], input[type=reset][noci!=true]").each( function()
	{
		var orig = jQuery(this);
		var nb = jQuery('<button class="btn_pamfax" type="'+orig.attr('type')+'_"/>')
			.append('<div class="btn_pamfax_left"></div>')
			.append('<div class="btn_pamfax_mid">'+jQuery(this).attr('value')+'</div>')
			.append('<div class="btn_pamfax_right"></div>')
			.css({
				border: 0,
				padding: 0,
				margin: 0,
				marginLeft: 5,
				cursor: 'pointer',
				backgroundColor: 'transparent'
			})
			.click( function(){ orig.click(); })
			.find('div')
				.css({
					border: 0,
					margin: 0,
					float: 'left',
					height: 26,
					backgroundPosition: '0 0',
					backgroundRepeat: 'repeat-x',
					cursor: 'pointer'
				})
			.end()
			.find('.btn_pamfax_left')
				.css({
					backgroundImage: 'url('+prefix+'../portal/skins/pamconsult/images/pf20/btn_small_left.png)',
					width: 7
				})
			.end()
			.find('.btn_pamfax_mid')
				.css({
					backgroundImage: 'url('+prefix+'../portal/skins/pamconsult/images/pf20/btn_small_mid.png)',
					whiteSpace: 'nowrap',
					overflow: 'hidden',
					paddingTop: 5,
					height: 21
				})
			.end()
			.find('.btn_pamfax_right')
				.css({
					backgroundImage: 'url('+prefix+'../portal/skins/pamconsult/images/pf20/btn_small_right.png)',
					width: 7
				})
			.end()
			.mouseover( function()
			{
				if( jQuery(this).hasClass('disabled') )
					return;
				jQuery(this).find('div').css({backgroundPosition: '0 -26px'});
			})
			.mouseout( function()
			{
				if( jQuery(this).hasClass('disabled') )
					return;
				jQuery(this).find('div').css({backgroundPosition: '0 0'});
			}).mousedown( function()
			{
				if( jQuery(this).hasClass('disabled') )
					return;
				jQuery(this).find('div').css({backgroundPosition: '0 -52px'});
			}).mouseup( function()
			{
				if( jQuery(this).hasClass('disabled') )
					return;
				jQuery(this).find('div').css({backgroundPosition: '0 0'});
			});
		jQuery(this).hide().after(nb);
	});
}