 function lib_open_img_window(src,width,height){ 
   if(width==0)
     width=500;
   width+=20;
   if(height==0)
     height=400;
   height+=20;
   if(height>600)
     height=600;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/img_preview.php?src='+src,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }

 function open_window(win,params,width,height){ 
   if(width==0)
     width=500;
   width+=40;
   if(height==0)
     height=400;
   height+=40;
   if(height>600)
     height=600;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   if(params!='')
     win+=params
   info=window.open(win,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }

 function open_descr(id,color){
   width=820;
   height=550;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/descr.php?id='+id+'&color='+color,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 
 
function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  else if (window.opera && document.createElement)
  {
	var a = document.createElement('A');
	if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}

function windowPopup(wUrl, wWidth, wHeight, wScrolls) 
{
    var xPos = (screen.availWidth  / 2) - (wWidth / 2);
    var yPos = (screen.availHeight / 2) - (wHeight / 2);
    if (!wScrolls) {
        wScrolls = 'yes';        
    } else {
        wScrolls = 'no';
    }
    window.open(wUrl, '', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars='+wScrolls+',status=no,toolbar=no,width='+wWidth+',height='+wHeight+',left='+xPos+',top='+yPos);
}


 function open_semail(phone,id){
 //alert(id);
   width=1000;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/admin/search_email.php?id='+id+'&phone='+phone,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
   
 }
 
  function open_stat_get(id, sklad){
 //alert(id);
   width=1000;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/admin/sklad_stat_get.php?id='+id+'&sklad='+sklad,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
   
 }
 
  function open_zak_get(id, sklad){
 //alert(id);
   width=1000;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/admin/sklad_zak_get.php?id='+id+'&sklad='+sklad,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
   
 }
 
  function open_delta_get(id1, id2, sklad){
 //alert(id);
   width=1000;
   height=700;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/admin/sklad_delta_get.php?id1='+id1+'&id2='+id2+'&sklad='+sklad,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
   
 }

  function open_response(id){
   width=420;
   height=350;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/response.php?id='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 
  function open_friend(id){
   width=420;
   height=450;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/friend.php?id='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
 
 
  function banking(id){
   width=720;
   height=550;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/kvitok.php?id='+id,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }

 function open_seindex(index){
 //alert(id);
   width=500;
   height=300;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/admin/search_index.php?index='+index,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
   
 }
 
 
 function open_modal(ths)
{
    sms_mail_wid = $(ths).attr('id').replace(/(.)+_/, '');

    $('#modal_sms').before('<div id="modal_sms_before" onclick="$(\'#modal_sms_before\').remove();$(\'#modal_sms\').hide();" style="position:fixed;width:100%;height:100%;top:0px;left:0px;background:black;opacity:0.3;">');
    $('#modal_sms').after('</div>');

    $('#sms_mail_to').val($(ths).attr('alt'));

    $('#sms_to_type').html($(ths).attr('id').replace(/_(.?)+/, ''));

    /*$("#select_pattern option").each(function () {
        $(this).val($(this).val().replace(/#WID#/, $(ths).attr('id').replace(/(.)+_/, '')));
    });*/

    $('#modal_sms').show();
}

function insert_pattern()
{
    $('#modal_sms_text').val($('#modal_sms_text').val()+$('#select_pattern option:selected').val().replace(/#WID#/,sms_mail_wid));

    $('#select_pattern option:selected').removeAttr('selected');
}
 
function close_sms_modal()
{
    $('#modal_sms_text').val("");

    $('#modal_sms_before').remove();

    $('#modal_sms_loading').remove();

    $('#modal_sms').hide();
}

function send_sms()
{
    $('#modal_sms').before(
            '<div id="modal_sms_loading" style="padding:5px;z-index:1;border:double;position:fixed;left:30%;top:30%;background:black;height:300px;width:40%;opacity:0.3;">' +
            '<img src="/img/loading.gif" alt="loading" style="position: relative;left: 42.5%;width: 15%;height: 25%;top: 45%;">' +
            '</div>');

    $.post("sms_mail_send.php", { send_message_id: send_message_id, sms_mail_to: $('#sms_mail_to').val(), message: $('#modal_sms_text').val(), type: $('#sms_to_type').html()},
       function(data) {

           if(data == 'OK')
           {
               close_sms_modal();

               alert('Сообщение успешно отправлено.');

               //window.location = window.location;
           }
           else
           {
               $('#modal_sms_loading').remove();
               
               alert(data);
           }
    });
}
