//daConfirm v1.1 Original code - Ivan Ognev. Rewritten by Eugene Krotov
i = 1;
function daConfirm(titleHTML, contentHTML, buttonsArray, cancelButton, messageClass) {
  $('.daConfirm').remove();//Удаляем другие информационные окна
  if (titleHTML == null) titleHTML = '';
  if (contentHTML == null) contentHTML = '';
  if (messageClass == null) messageClass = 'info';
  var buttons = '';
  for (key in buttonsArray) {
	  e = buttonsArray[key];
	  name = e['name'];
	  func = e['function'];
	  if (typeof(name) != "undefined" && typeof(func) != "undefined") {
		  buttons = buttons + '<input type="button" value="'+ name +'" onClick = "daClick(\''+func+'\');">';
		  i++;
	  }
  }
  buttons = buttons + '<input type="button" value="'+cancelButton+'" onclick="hideConfirm();">'
  //Кнопка по умолчанию
  /*var button = '';
  if ( (buttonText != null) && (buttonText != '') ) button = '<input type="button" value="'+buttonText+'" onclick="hideConfirm();">';*/
  //Рисуем окно
  var windowTable = '<table cellpadding="0" class="daConfirm '+messageClass+'"><tr class="daConfirmT"><td class="daConfirmTC" colspan="3">'+titleHTML+'</td></tr><tr class="daConfirmC"><td class="daConfirmCL"></td><td class="daConfirmCC">'+contentHTML+'</td><td class="daConfirmCR"></td></tr><tr class="daConfirmB"><td class="daConfirmBL"></td><td class="daConfirmBC">'+buttons+'</td><td class="daConfirmBR"><i></i></td></tr></table>';
  showConfirm(windowTable);
  //$('body').prepend(windowTable);
  //Позиционируем окно
  var st = getBodyScrollTop();
  $('.daConfirm').css('width', $('.daConfirm').css('max-width'));
  var y = ( $(window).height() / 2 ) - ($('.daConfirm').height() / 2) + st;
  var x = ( $(window).width() / 2 ) - ($('.daConfirm').width() / 2);
  $('.daConfirm').css({'top':y, 'left':x});
}

function showConfirm(param) {
	$('body').prepend(param);
	$('.daConfirm').fadeIn("slow");
}

function hideConfirm() {
	$(".daConfirm").fadeOut("slow", function () {
					       $(".daConfirm").remove();
					    });
}

function getBodyScrollTop() {
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function daClick(f) {
	t = setTimeout(f, 1);
	hideConfirm();
}
