// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){
  // NOTE: We are trimming the jQuery collection down to the
  // first element in the collection.
  if (this.size() > 1){
    this.eq( 0 ).print();
    return;
  } else if (!this.size()){
    return;
  }
 
  // ASSERT: At this point, we know that the current jQuery
  // collection (as defined by THIS), contains only one
  // printable element.
 
  // Create a random name for the print frame.
  var strFrameName = ("printer-" + (new Date()).getTime());
 
  // Create an iFrame with the new name.
  var jFrame = $( "<iframe name='" + strFrameName + "'>" );
 
  // Hide the frame (sort of) and attach to the body.
  jFrame
    .css( "width", "1px" )
    .css( "height", "1px" )
    .css( "position", "absolute" )
    .css( "left", "-9999px" )
    .appendTo( $( "body:first" ) )
  ;
 
  // Get a FRAMES reference to the new frame.
  var objFrame = window.frames[ strFrameName ];
 
  // Get a reference to the DOM in the new frame.
  var objDoc = objFrame.document;
 
  // Grab all the style tags and copy to the new
  // document so that we capture look and feel of
  // the current document.
 
  // Create a temp document DIV to hold the style tags.
  // This is the only way I could find to get the style
  // tags into IE.
  var jStyleDiv = $( "<div>" ).append(
    $( "style" ).clone()
    );
  // Write the HTML for the document. In this, we will
  // write out the HTML of the current element.
  objDoc.open();
  objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
  objDoc.write( "<html>" );
  objDoc.write( "<body>" );
  objDoc.write( "<head>" );
  objDoc.write( "<title>" );
  objDoc.write( document.title );
  objDoc.write( "</title>" );
  objDoc.write( jStyleDiv.html() );
  objDoc.write( "</head>" );
  objDoc.write( this.html() );
  objDoc.write( "</body>" );
  objDoc.write( "</html>" );
  objDoc.close();
 
  // Print the document.
  objFrame.focus();
  objFrame.print();
 
  // Have the frame remove itself in about a minute so that
  // we don't build up too many of these frames.
  setTimeout(
    function(){
      jFrame.remove();
    },
    (60 * 1000)
    );
}

function doPEditChenge(urldescr, divdescr, value, type_id) {
  descr = $("#loader");
  win_id = $("#"+divdescr+"");
  win_id.html(descr.html());     
  var w = $(window);
  win_id.css("width","720px");
  win_id.css("top", (Math.abs(w.height()-670))/2+w.scrollTop() + "px");
  win_id.css("left", (w.width()-win_id.width())/2.5+w.scrollLeft() + "px");
  win_id.slideToggle("slow");
  
  if (urldescr && value) {
    $.ajax({
      type: "POST",
      data: "type_id="+value+"&summa="+$('#bank_summa').val()+"&number="+$('#bank_number').val()+"&site_type="+$('#site_type').val()+"",
      url: urldescr,
      cache:false,
      success: function(page) {
        win_id.empty().html(page);
        //runScripts(win_id.getElementsByTagName('SCRIPT'));
        $("#print_button").css("top",(w.height()-$("#"+divdescr+"").height())/2+w.scrollTop() + "px");
        $("#print_button").css("left",(w.width()-$("#"+divdescr+"").width())/2+w.scrollLeft() + 100 + "px");
        $("#print_button").slideToggle("slow");
      }
    });
  }
}

function fnPaysWinClose() {
  $("#content_block").slideToggle("slow");
  descr = $("#loader");
  win_id = $("#content_block");
  win_id.html(descr.html());  
}


function print_preview() {
   var winH = 600; var winW = 530;
   var vieWin = window.open('', '_blank', "top=100,left=100,width="+(winW)+",height="+(winH)+",status=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,location=0");
   vieWin.document.clear();
   print_div = '<div id="print_but" class="pbdiv"><input type="button" value="Распечатать" onClick="pageprint()" /></div>';
   htmlcode = '<html><head><title>Версия для печати</title><style>HTML, BODY { width:529px; font:normal 11px Tahoma;} H2 {font:normal 14px Tahoma;} .pbdiv { margin-top:30px; width:529px; text-align:center; } .top {text-align:center; width:440px; } .bottom {text-align:left;} INPUT { background:none; width: 105px; height: 23px; text-align: center; font:normal 11px Tahoma; border: 1px solid #000; padding:0; margin:0; cursor: pointer; }</style><script>function pageprint() {document.getElementById("print_but").style.visibility="hidden"; window.print(); }</script></head><body><div class="top"><h2>Пятая международная конференция</h2><h2>Российская Школа Колоректальной Хирургии</h2><h2>Дата проведения - 23 июня 2011 г.</h2></div><img height="362" width="514" src="/image/school/5/map.jpg" /><p class="bottom">Отель Рэдиссон САС Славянская<br />Москва, площадь Европы д.2<br /><p>Внимание! Обязательно наличие паспорта.</p></p>'+print_div+'</body></html>';
   vieWin.document.write(htmlcode);
   vieWin.document.close();
}


