(function($) {
    
    function replyLink(){
        $('#reply_link').click(function(){
            function replyForm(){
                $.ajax({
                    type: "POST",
                    url: $('#reply_form').attr('action'),   
                    data: $('#calc_form').serialize() + '&' + $('#reply_form').serialize() + '&' + 'price='+$('#calc .res .price').text(),
                    success: function(msg){
                        alert(msg);
                        location.reload(true);     
                    }
                });
            }
            $.get('/index.php5?module=other&class=reply&action=showForm&todo=reply',function(reply){
                $('#reply').remove();
                $('body').prepend(reply);
                $('#reply').height($(document).height());
                $('#reply .popup').css({
                    'top': $(document).scrollTop()+100+'px', 
                    'margin-top': '0px'
                });
                $('#reply_form').submit(function(){
                    replyForm();   
                    return false;
                });
                
            });
            return false;
        });
    }
    
    $(document).ready(function(){
        replyLink();
    });
})(jQuery);    

  function showbig(picname){
    window.open('/includes/foto.php5?pic='+picname,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=30,height=30');
  }
  
  function PreLoad(source){
    var NewImage = new Image();
    NewImage.src = source;
  }
  
  function prepareSubmit(frm){
    var len = frm.all("editbox").length; if (!len) len = 1;
    for (var i=0; i<len; i++)
      frm.all("codebox", i).innerText = frm.all("codebox", i).style.display ? borderOn(frm.all("codebox", i).innerText) : borderOn(frm.all("editbox", i).innerHTML);
  }
   
 function menuProcess(menuId){
 	 if(menuId.style.display == 'none'){
     menuId.style.display = 'block';
   }else{
   	 menuId.style.display = 'none';
   }
 }
 
 function btShowFunctionArguments(name){
	 btChangeFunctionArgumentsBlock(name,'none','block','block');
 }
 
 function btHideFunctionArguments(name){
	 btChangeFunctionArgumentsBlock(name,'block','none','none');
 }
 
 function btChangeFunctionArgumentsBlock(name,plus,minus,arguments){
 	 document.getElementById('backtrace_img_plus_'+name).style.display = plus;
 	 document.getElementById('backtrace_img_minus_'+name).style.display = minus;
 	 document.getElementById('backtrace_arguments_'+name).style.display = arguments;
 }
 
  function processTree(elementId,isTop){
 	 tbl = document.getElementById('dir_'+elementId);
 	 img = document.getElementById('img_'+elementId);
 	 
 	 if(tbl.style.display != 'none'){
 	 	 tbl.style.display = 'none';
 	 	 img.alt = 'Раскрыть';
 	 	 if(isTop)
 	 	   img.src = '/images/design/tree_plus.gif';
 	 	 else
 	 	   img.src = '/images/design/tree_sub_plus.gif';
 	 }else{
 	 	 tbl.style.display = 'block';
 	 	 img.alt = 'Закрыть';
 	 	 if(isTop)
 	 	   img.src = '/images/design/tree_minus.gif';
 	 	 else
 	 	   img.src = '/images/design/tree_sub_minus.gif';
 	 }
 }
 
 /** 
 * Преобразует многомерный обьект данных в строковое представление
 */
 function Dump(d,l) {
    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "    ";
            s += k+": " + Dump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "  ";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
 }
 function  print_r(arr){
	alert(Dump(arr));
 }
 
 /** 
 * Создаёт копию обьекта (для передачи не по ссылки)
 */
 function clone(d) {
	var s = new Array();
	if(typeof(d) == "object"){
		for (var k in d)
			s[k] = clone(d[k]);  
	}else
		s = d;
	return s;
 }
 
 /** v 1.1
 * Выдаёт окончание
 *
 * @param int $count - Количество элементов
 * @param str $word - название элемента в ед. числе
 * @return str - название в указанном количестве
 */
function rus_case(count, word){
	var sp_count = (1 * count % 100 - 1 * count % 10) == 10;
	var count = 1 * count % 10;
	var mod = word.substr(word.length-1, 1);
	if(count == 1 && !sp_count)
		return word;
	switch (mod){
		case 'а' :
			if((count==2 || count==3 || count==4) && !sp_count)
				return word.substr(0, word.length-1) + 'ы';
			else
				return word.substr(0, word.length-1);
		case 'ь' :
			if((count==2 || count==3 || count==4) && !sp_count)
				return word.substr(0, word.length-1) + 'я';
			else
				return word.substr(0, word.length-1) + 'ей';
		case 'е' :
			if((count==2 || count==3 || count==4) && !sp_count)
				return word.substr(0, word.length-1) + 'я';
			else
				return word.substr(0, word.length-1) + 'й';
		default:
			if((count==2 || count==3 || count==4) && !sp_count)
				return word + 'а';
			else
				return word + 'ов';
	}
 }
 (function($) {
  $(document).ready(function(){
    if(typeof sIFR == "function"){
      sIFR.replaceElement(named({
        nWidth:700,
        nHeight:25,
        sSelector:"#main-part-title",
        sFlashSrc:"/images/flash/sifr_AlexandraScript.swf",
        sColor:"#67064b",
        sLinkColor:"#67064b",
        sBgColor:"transparent",
        sHoverColor:"#67064b",
        sWmode:"transparent",
        nPaddingTop:0,
        nPaddingBottom:0,
        sFlashVars:"textalign=left&offsetTop=0"
      }));
    };
  })
})(jQuery);
