﻿$(function() {
    jQuery('#shadow').hide();
    jQuery('#alertBox').hide();
});

jQuery('#alertBox input.closeAlert').livequery('click', function(evt) {
	var showRate = (jQuery.browser.msie ? 0 : 250);
	jQuery('#alertBox').hide(showRate);
	jQuery('#shadow').hide();
});

function alertBox(title, content, buttons, showIcon) {
	var html = '';
	if (showIcon) {
		html = '<div id="alertIcon"></div>';
	}
	html += content;
	if (buttons == null || buttons.length == 0) {
		html += '<div id="alertButtons"><input type="button" class="button closeAlert" value="OK" /></div>';
	} else {
		html += '<div id="alertButtons">';
		for(x=0; x < buttons.length; x++) {
			html += '<input id="alertBtn' + x + '" type="button" class="button closeAlert" value="' + buttons[x].text + '"/>';
		}
		html += '</div>';
	}	
	jQuery("#alertBox td.title").html(title);
	jQuery("#alertBox td.alert").html(html);
	if (buttons != null && buttons.length > 0) {
		for (x=0; x < buttons.length; x++) {
			if (buttons[x].fn) {
				//alert(buttons[x].fn);
				jQuery('#alertBtn' + x).click(buttons[x].fn);
			}
		}
	}
	jQuery("#shadow").width(jQuery(document).width()).height(jQuery(document).height()).show();
	var showRate = (jQuery.browser.msie ? 0 : 250);
	jQuery("#alertBox").show(showRate);
}