function show(id)
{
	var val = "#" + id;
	var val2 = "#q" + id;
	$(val).css( "display", "block" );
	$(val2).css( "display", "none" );
}
function hide(id) {
	var val = "#" + id;
	var val2 = "#q" + id;
	$(val).css( "display", "none" );
	$(val2).css( "display", "block" );
}
function toggle(id) {
   	$(id).toggle("slow");
}
function dbl_clk(ar) {
    var val = "#" + ar;
    $(val).html("<img src='des/icon/ready.gif'> отправка");
}
function adv_ref(id) {
   	$.get("mod/adv_ref.php", { id: id } );
}
function get_data(id,ar1,ar2,ets) {
	var fl="mod/"+ar1+".php";
	var d_id="#"+ar2;
	var id2=id+"|"+ets;
	$.post(fl, {id: id2}, onAjaxSuccess);
	function onAjaxSuccess(data) {  $(d_id).html(data); }
}
//Popup dialog
function popup(message) {
	// get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();
	
	// calculate the values for center alignment
	var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).fadeIn('fast');
	$('#dialog-box').fadeIn('slow');
	
	// display the message
	$('#dialog-message').html(message);
}
function send(mk,id,to)
{	
	var val = "#" + mk;
	$(val).html("<form name='lka' action='#0' method='post' onSubmit=\"if(document.lka.send.click!=true) { return false; }\"><table border='0' width='100%' cellspacing='0' cellpadding='2'><tr><td width='150'><font class='Text1c'>Ваш email </font></td><td width='90%'><input type='text' id='mail' name='mail' style='width:100%'></td></tr><tr><td width='100%' colspan='2'><font class='Text1c'>Сообщение </font></td></tr><tr><td colspan='2'><textarea id='body' class='mail' style='WIDTH: 100%;' name='body' rows='4' cols='50'></textarea></td></tr><tr><td><input type='submit' class='but1' name='send' value='отправить' onClick=\"send2('"+mk+"','"+id+"','"+to+"')\"></td><td  align='right'><a  class='more2' href='#0' onClick=\"hide('"+mk+"');\">скрыть</a></td></tr></table></form>");
	$(val).animate({opacity: "show"}, 800);
}
function send2(mk,id,to)
{
	var dv = "#" + mk;
	var val = document.getElementById('body').value;
	var em = document.getElementById('mail').value;
	if((em == "")||(val == "")) {alert("Заполнены не все поля!");}
	else {
		$.get("mod/mes_add.php", { t: mk, mes: val, mail: em,  id: id, to: to } );
		$(dv).html("<font class='red'>сообщение отправлено</font>");
	}
}
function del_ob(id,t) {
	var val = "tr.no" + id;
	var val2 = "#ob_d" + id;
	var lk='mod/est_del.php?id='+id+'&type='+t;
	if( confirm('Вы действительно хотите удалить этот объект?') ){ 
		$.get(lk);
		$(val).addClass('red');
		$(val2).html("Удалено");
	}
}

function view_obj(lev,id,ar,bd,ph) {
	if(lev==1)	{
		$.post('mod/est_kv_view.php', {idob: id, st: ar, brd: bd, ph: ph}, onAjaxSuccess);
		var val = "#ob_ed" ;
	}
	if(lev==2)	{
		$.post('mod/est_zag_view.php', {idob: id, st: ar, brd: bd, ph: ph}, onAjaxSuccess);
		var val = "#ob_ed" ;
	}
	if(lev==3)	{
		$.post('mod/est_com_view.php', {idob: id, st: ar, brd: bd, ph: ph}, onAjaxSuccess);
		var val = "#ob_ed" ;
	}
	function onAjaxSuccess(data)
	{
	  $(val).html(data);
	  $('.slidedeck').slidedeck();
	}
}
function photo_go(id,type,ob,lev) {
	var lk='mod/pic_go.php?id='+id+'&t='+type+'&obj='+ob+'&lev='+lev;
	$.get(lk);
	var val="#hd" +id;
	$(val).html("главное фото");
}
function pic(val,t) {
	$.post(
	  'estate/view_est.php',
	  {
	    id: val
	  },
	  onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
	  var dst = "#" + t;
	  $(dst).html(data);
	}
}
function pic_vh(id) {
	$.post(
	  'mod/ph_view_r.php',
	  {
	    id: id
	  },
	  onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
	  $("#nc").html(data);
	}
}
function photo_del(id) {
	$.get('mod/pic_del.php?id='+id);
	var val="#p" + id;
	$(val).empty();
	$("#upl").css( "display", "block" );
}
function save_pic() {
	var img = document.getElementById('id_img').value;
	var x1 = document.getElementById('x1').value;
	var w = document.getElementById('w').value;
	var y1 = document.getElementById('y1').value;
	var h = document.getElementById('h').value;
	$.get( 'mod/pic_save.php?img='+img+"&w="+w+"&h="+h+"x1="+x1+"&y1="+y1);
	function get_pic() {
		var pic="<font class='zag1'>Фото сохранено.</font><br/><img src=us_pic/100x100/"+img+".jpg>";
	 	$("#pre_pic").html(pic);
	}
	setTimeout(get_pic, 1000);
}
function checkAll(oForm, cbName, checked)
{
for (var i=0; i < oForm[cbName].length; i++) oForm[cbName][i].checked = checked;
}

function displayPrintButton(TITLE_OF_BUTTON) {
  if ((navigator.appName.indexOf("Netscape") > -1 &&
      parseInt(navigator.appVersion) >= 4) ||
      (navigator.appName.indexOf("Microsoft") > -1 &&
      parseInt(navigator.appVersion) >= 4) ) {
      document.write
        ("<INPUT TYPE=submit NAME=suboot2 VALUE='"+TITLE_OF_BUTTON+"'  onClick='printCurrentPage();'>");
        }
    }

function printCurrentPage() {
    if (navigator.appName.indexOf("Microsoft") > -1 &&
        navigator.appVersion.indexOf("5.") == -1) {
      // IE4
      OLECMDID_PRINT = 6;
      OLECMDEXECOPT_DONTPROMPTUSER = 2;
      OLECMDEXECOPT_PROMPTUSER = 1;
      WebBrowser =
        '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(OLECMDID_PRINT,  OLECMDEXECOPT_DONTPROMPTUSER);
      WebBrowser1.outerHTML = "";
      }
    else {
      // N4 IE5
      window.print();
      }
    }
function ShowHide(elem, icon_elem){
  var s = elem.style;
  s.display = (s.display != 'none') ? 'none': '';
  if(icon_elem) { icon_elem.innerHTML = (s.display != 'none') ? '[+]': '[&ndash;]'; }
}

function view_sale(id) {
	$.post(
	  'estate/sale.php',
	  {
	    sid: id
	  },
	  onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
	  $('#sl').html(data);
	  $('#sl').animate({opacity: "show"}, 800);
	}
}
function view_phkat(id) {
	$.post(
	  'estate/phkat.php',
	  {
	    sid: id
	  },
	  onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
	  $('#sl').html(data);
	  $('#sl').css( "visibility", "visible" );
	}
}
function sl_close() {
	$('#sl').css( "visibility", "hidden" );
}
function set_rn() {
	$('#rn1').html("<img src='img/ready.gif'>");
	var rnIndex = document.getElementById('region').value;
	$.post(
	  'mod/set_rn.php',
	  {
	    reg: rnIndex
	  },
	  onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
	  $('#rn1').html(data);
	}
}
function set_nasp() {
	$('#nasp1').html("<img src='img/ready.gif'>");
	var rnIndex = document.getElementById('rn').value;
	var reg = document.getElementById('region').value;
	$.get(
	  'mod/set_nasp.php', {rn: rnIndex, reg: reg}, onAjaxSuccess);
	function onAjaxSuccess(data)
	{
	  $('#nasp1').html(data);
	}
}
function set_des() {
	$('#des1').html("<img src='img/ready.gif'>");
	var tp = document.getElementById('typef').value;
	$.get('mod/set_des.php', {tp: tp}, onAjaxSuccess);
	function onAjaxSuccess(data)
	{
	  $('#des1').html(data);
	}
}
function set_adr() {
	$('#adr').html("<img src='img/ready.gif'>");
	var reg = document.getElementById('region').value;
	var rnIndex = document.getElementById('rn').value;
	var nas = document.getElementById('nasp').value;
	var des = document.getElementById('des').value;
	
	$.get(
	  'mod/set_adr.php', {rn: rnIndex, nas: nas, reg: reg, des: des}, onAjaxSuccess);
	
	function onAjaxSuccess(data)
	{
	  $('#adr').html(data);
	  $('#adr2').css( "display", "block" );
	  $('#mtr').css( "display", "block" );
	  $('#mtr2').css( "display", "block" );
	}
}
function set_kv() {
	var id = document.getElementById('obj').value;
	if(id==2010) { $('#kom').css( "display", "block" ); }
	else { $('#kom').css( "display", "none" ); }
}
function res() {
	$('#res').html("<input type='radio' name='pay_board' value='3'> Опубликовать на 7 дней (50 руб)<br/>	<input type='radio' name='pay_board' value='4'> Опубликовать на 30 дней (180 руб)");
	$('#res2').html("<input type='radio' name='pay_ph' value='1'> Опубликовать на 7 дней (50 руб)<br/>	<input type='radio' name='pay_ph' value='2'> Опубликовать на 30 дней (180 руб)");
}
function show_adr()
{
	$('#adr_rw').css( "display", "block" );
}
function hide_adr(val) {
	$('#adr_rw').css( "display", "none" );
	$.post(
	  'estate/set_adr.php',
	  {
	    tid: val
	  }
	);
	document.forms.fadr.reset();
}

function active_ph(pay,item,id) {
	var it1="#del"+item;
	var it2="#pay"+item;
	var it3="#str"+item;
	$.get( 'mod/pay_ph.php',  {pay: pay, id: id}, onAjaxSuccess);
	function onAjaxSuccess(data)
	{
	  var data2="размещено до<br>"+data;
	  if(data!=1) {
	  	$(it1).html("<a href='#0' onClick='del_str()'><img src='img/kill_g.gif' border='0' title='Снять с показов'></a>");
	  	$(it2).html(data2);
	  }
	  else {
	  	  if( confirm('Недостаточно средств на балансе! Хотите пополнить баланс?') ){ 
 	window.location.href = "?p=pay1"; }
 	  }
 	  function del_str() {
	  	  if( confirm('Удалить оплаченную строчку? Внимание! Оплата не сохраняется!') ){ 
 			$.get( 'mod/pay_del_ph.php', {id: id} );
 			$(it3).fadeOut(1000);
 		  }
 	  }
	}
}
function del_str_ph(item,id) {
	var it="#str"+item;
	if( confirm('Удалить оплаченную строчку? \n Внимание! Оплата на баланс не возвращается!') ){ 
 		$.get( 'mod/pay_del_ph.php', {id: id} );
 		window.location.href = "?p=us_phkat";
 	}
 }
 function del_str_ph2(tp,ob) {
	if( confirm('Удалить оплаченную строчку? \n Внимание! Оплата на баланс не возвращается!') ){ 
 		window.location.href = "?p=obj_pserv&cmd=del_ph&tp="+tp+"&ob="+ob;
 	}
 }
 function del_str_ob(id,tp,ob) {
	if( confirm('Удалить оплаченный стикер? \n Внимание! Оплата на баланс не возвращается!') ){ 
 		window.location.href = "?p=obj_pserv&cmd=del&tp="+tp+"&ob="+ob+"&id="+id;
 	}
 }
  function del_str_board(tp,ob) {
	if( confirm('Удалить оплаченную позицию? \n Внимание! Оплата на баланс не возвращается!') ){ 
 		window.location.href = "?p=obj_pserv&cmd=del_str&tp="+tp+"&ob="+ob;;
 	}
 }
 function rel_bal() {
 	 $.get( 'mod/rel_bal.php', { }, onAjaxSuccess );
 	 function onAjaxSuccess(data)
	{
		$("#id_bal").html(data);
	}
 }
function order(type,id,pay,des,us,tp) {
	var sl="#sl"+id;
	$(sl).html("<img src='img/ready.gif'>");
	$.get(
	  'estate/payment1.php',
	  {type: type, id: id, pay: pay, us: us, des: des, tp: tp}, onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
		$(sl).html(data);
	}
}
function order2(type,id,pay,des,us,tp) {
	var sl="#sl"+id;
	$("#pays").html("<img src='img/ready.gif'>");
	$.get(
	  'mod/pay_liq.php',
	  {type: type, id: id, pay: pay, us: us, des: des, tp: tp}, onAjaxSuccess
	);
	function onAjaxSuccess(data)
	{
		$("#pays").html(data);
	}
}

(function($) {                    // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }

        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
};

function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);

