function sure()
{
    return confirm('Вы уверены ?');
}

function openWin(url, name, width, height)
{
  width  = width  || screen.width*0.9;
  height = height || screen.height*0.75;

  //var 
  win = window.open(url, name, 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,channelmode=0,fullscreen=0');
  if (win)
      win.focus();

  return false;
}

function openWinNoScroll(url, name, width, height)
{
  width  = width  || screen.width*0.9;
  height = height || screen.height*0.75;

  //var 
  win = window.open(url, name, 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,channelmode=0,fullscreen=0');
  if (win)
      win.focus();

  return false;
}

function insertToTextArea(textArea, txt)
{
    //for IE
    if (document.selection) {
            textArea.focus();
            sel = document.selection.createRange();
            sel.text = txt;
    }
    //for MOZILLA/NETSCAPE
    else if (textArea.selectionStart || textArea.selectionStart == "0") {
            var startPos  = textArea.selectionStart;
            var endPos    = textArea.selectionEnd;
            var str       = textArea.value;

            textArea.value = str.substring(0, startPos) + txt + str.substring(endPos, str.length);
    } else {
            textArea.value += txt;
    }

    return true;
}

function writeMessage(show_all)
{  
    return openWin("/index.php?mod=feedback&act=writemessage&show_all="+show_all, "", 600, 400);    
}

function writeIdea(id)
{  
    return openWin("/member/index.php?mod=feedback&act=writeidea&id="+id, "idea", 600, 370);    
}

function writeReview(show_all,sto_id,rid)
{
    return openWin("/member/index.php?mod=storeview&act=writereview&sto_id="+sto_id+"&rid="+rid+"&show_all="+show_all, "", 600, 450);    
}

function printOrders(show_all,ids)
{
    return openWin("/admin/index.php?mod=catalog&act=print&ids="+ids+"&show_all="+show_all, "", 950, 600);    
}

function printVisitka(show_all,ids)
{
    return openWin("/member/index.php?mod=visitka&act=print&ids="+ids+"&show_all="+show_all, "", 950, 600);    
}

function printServbook(show_all)
{
    return openWin("/member/index.php?mod=servbook&act=print&show_all="+show_all, "", 700, 600);    
}

function popupCategory()
{
    return openWin("/admin/index.php?mod=catalog&act=popup_category", "cat", 400, 400);    
}

function popupState()
{
    return openWin("/admin/index.php?mod=catalog&act=popup_state", "state", 400, 400);    
}

function popupSupplier(opt_client_id)
{
    return openWin("?mod=catalog&act=popup_supplier&cid="+opt_client_id, "supplier", 400, 400);        
}

function popupSklad(opt_client_id)
{
    return openWin("?mod=catalog&act=popup_sklad&cid="+opt_client_id, "sklad", 400, 400);        
}

function addPhoto(id)
{
    return openWin("?mod=catalog&act=popup_photo_add&id="+id, "photo", 300, 100);        
}

function popupEngine(id,opt_client_id,opt_client_name,opt_client_phone)
{
    return openWin("?mod=catalog&act=engine_view&id="+id+"&cid="+opt_client_id+"&cname="+opt_client_name+"&cphone="+opt_client_phone, "engine", 630, 800);    
}

function popupBus(id)
{
    return openWin("?mod=catalog&act=bus_view&id="+id, "bus", 630, 800);    
}

function popupDisk(id)
{
    return openWin("?mod=catalog&act=disk_view&id="+id, "bus", 630, 800);    
}

function popupKpp(id)
{
    return openWin("?mod=catalog&act=kpp_view&id="+id, "kpp", 630, 800);    
}

function creditForm(id)
{
    return openWin("?mod=catalog&act=credit_form&id="+id, "credit", 500, 300);    
}

function orderForm(id)
{
    return openWin("?mod=catalog&act=order_form&id="+id, "order", 400, 200);    
}

function orderList(id)
{
    return openWin("?mod=catalog&act=popup_order_list&id="+id, "orderlist", 700, 300);
}

function engineCompleting()
{
    return openWin("/index.php?mod=catalog&act=popup_engine_completing", "completing", 350, 150);
}

function showVideo(id)
{    
    width  = 425;
    height = 344;  
    win = window.open('/index.php?mod=photo&act=show_video&id='+id, 'video', 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,channelmode=0,fullscreen=0');
    if (win)
      win.focus();
    return false;
}

function sendError()
{
    return openWin("/admin/index.php?mod=mail&act=send_error", "senderror", 600, 300);
}

function viewImage(id)
{
    return openWin("/visitor/index.php?mod=photo&act=view_image&id="+id, "view", 640, 640);
}

function viewCar(id_car,order,pos)
{
    var h = (order > 0 ? 700 : 530);
    return openWin("/visitor/index.php?mod=delivery&act=car_view&id_car="+id_car+"&order="+order+"&pos="+pos, "car", 640, h);
}

function winRadio(url,width,height)
{
    win = window.open(url, 'radio', 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,channelmode=0,fullscreen=0');
    if (win)
      win.focus();
    return false;      
}

function myAvto()
{
    return openWin("/member/index.php?mod=servbook&act=my_avto_form", "myavto", 520, 320);    
}

function myAvtoPhoto()
{
    return openWin("/member/index.php?mod=servbook&act=my_avto_photo", "myavtophoto", 520, 290);    
}

function closeWin()
{
    if(opener)
        opener.location = opener.location;
    self.close();
}    

function profileOpinion(uid,type)
{
    return openWin("?mod=client&act=profile_opinion&uid="+uid+"&type="+type, "opinion", 500, 180);    
}

function viewMessage(id)
{
    return openWin("?mod=message&act=message_view&id="+id, "mes", 500, 180);    
}

function pollVoteList(id)
{    
    return openWin("?mod=poll&act=poll_vote_list&id="+id, "vote", 680, 800); 
}

function socialHeader(id)
{
    return openWin("/member/index.php?mod=social&act=social_header&id="+id, "social", 1000, 900);    
}

function kartaSelteam(id)
{
    width  = 1000;
    height = 631;  
    win = window.open('/index.php?mod=photo&act=karta_selteam&id='+id, 'motor', 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,channelmode=0,fullscreen=0');
    if (win)
      win.focus();
    return false;
}