var swfu;
var window_callback;
var DATE_FORMAT = 'M d, yy';

/**
 * showMessage
 *
 * Display a status message
 */
function showMessage(block, msg) {
	s = (arguments[2]) ? arguments[2] : 'ok';
	speed = (arguments[3] != undefined) ? arguments[3] : 3000;
	
	if (speed > 0) {
		$('#' + block)
			.html(msg)
			.removeClass()
			.addClass(s + ' message')
			.fadeIn('slow')
			.animate({opacity: 1.0}, speed)
			.fadeOut('slow', function() {$(this).html('');});
	} else {
		$('#' + block)
			.html(msg)
			.removeClass()
			.addClass(s + ' message')
			.fadeIn('slow');
	}
}

/**
 * animateScroll
 *
 * Animate scrolling to the top of a scrolling div
 * @param block jQuery selector of the div to scroll
 */
function animateScroll (block) {
  
  // Scroll to the top of the page to see the effect of the selection
  if (block) {
    $(block).animate({scrollTop: 0}, 200);
  } else {
    alert ('jQuery selector required');
  }
  
}

/**
 * Remove non-numeric values except for decimal
 */
function toNumber(val) {
	
  return val.replace(/[^0-9\.]/g, '');
}

/**
 * Add commas to a number
 */
function addCommas(nStr, pre) {
	
  if (!pre) pre = '';
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return pre + x1 + x2;
}

/**
 * Get province/state options based on country
 */
function getProvinces(country, provInput, provs) {
	
  if (provs[country]) {
		provInput.options.length = 0;
		provInput.options[0] = new Option('-- select province/state --', "");
		for (p in provs[country])
		{
			provInput.options[provInput.options.length] = new Option(provs[country][p], p);
		}
		$(provInput.parentNode.parentNode).fadeIn('fast');
		$(provInput).fadeIn('fast');
	} else {
	  $(provInput.parentNode.parentNode).fadeOut('fast'); $(provInput).fadeOut('fast');
	}
}

/**
 * Generate option tags for a select list
 */
function loadDropDown(target, list) {
	var o = '';
	
	for (var i = 0; i < list.length; i++) {
    o += '<option';
		if (list[i].value != undefined) o += ' value="' + list[i].value + '"';
		o += '>' + list[i].text + '</option>';
  }
  $(target).html(o);
}

