
	

// Ввод только цифр в текстовое поле 
function EnsureNumeric(){
	var k = window.event.keyCode; 
   	if ((k < 48 || k > 57) && k != 8) 
    window.event.returnValue = false; 
}

function search(let){
	var oForm = document.forms.search;
	oForm.letter.value=let;
	oForm.page.value=1;
	oForm.submit();	
}

function search_sort(sort){
	var oForm = document.forms.search;
	oForm.sort.value=sort;
	oForm.page.value=1;
	oForm.submit();	
}




	



var cur_div="";
    function quickreply2(dtid, isError,isEdit){

		if (1){
	  		if(dtid!=0){
	  			var targetname = "replyDiv" + dtid;
	  		}else{
	  			var targetname = "addcomment";
	  		}
	        var topDiv=document.getElementById("addcomment");
	        if(!topDiv){
	        	return true;
	        }
	        if(cur_div!=""){
	        	temp=cur_div.innerHTML;
	        	cur_div.innerHTML="";
	        	cur_div = document.getElementById(targetname);
	        	cur_div.innerHTML = temp;
	        }else {
	        	if(targetname != "addcomment"){
	        		cur_div = document.getElementById(targetname);
	        		cur_div.innerHTML = topDiv.innerHTML;
	        		topDiv.innerHTML="";
	        	}
	        }
	        
	        if(isEdit){
	    		document.getElementById("headerr").innerText="Редактировать:";
	    		document.getElementById("comments").value=document.getElementById("editTD"+dtid).value;
	    		document.getElementById("isEdit").value="1";
	    	}else{
	    		document.getElementById("headerr").innerText="Добавить комментарий:";
	    		document.getElementById("comments").value="";
				document.getElementById("isEdit").value="";
	    	}
	        if(document.getElementById("Perror").name!="unreg") {
	    	    if(isError){
		        	var Perr=document.getElementById("Perror");
		        	Perr.innerHTML="";
		        }
	        	window.setTimeout(function () { document.getElementById("comments").focus(); }, 250);
	        	document.getElementById("parent").value = dtid;
	        }
   		}else{
        	if(dtid==0){
        		return false;
        	}

        }
        return false;
    }




	var cur_div="";
    function quickreply(dtid){
  		document.getElementById("parent").value = dtid;
  		document.getElementById("isEdit").value = "otv";

		if (1){
	  		if(dtid!=0){
	  			var targetname = "replyDiv" + dtid;
	  		}else{
	  			var targetname = "addcomment";
	  		}
	        var topDiv=document.getElementById("addcomment");
	        topDiv.style.display = "block";
	        if(!topDiv) {
	        	return true;
	        }
	        if(cur_div!=""){
	        	temp=cur_div.innerHTML;
	        	cur_div.innerHTML="";
	        	cur_div = document.getElementById(targetname);
	        	cur_div.innerHTML = temp;
	        }
	        else{
	        	if(targetname != "addcomment"){
	        		cur_div = document.getElementById(targetname);
	        		cur_div.innerHTML = topDiv.innerHTML;
	        		topDiv.innerHTML="";
	        	}
	        }
   		}
        else{
        	if(dtid==0){
        		return false;
        	}
        }
        
              
        var textDiv = document.getElementById("textDiv");
		var handleBottom = document.getElementById("handleBottom");
		var comments = document.getElementById("comments");
			
        new dragObject(handleBottom, null, new Position(15), new Position(500), null, BottomMove, null, false);
		function BottomMove(newPos, element){
					y = newPos.Y;
					textDiv.style.height = (y + 2) + 'px';
				 	if(element != handleBottom)
				    handleBottom.style.top = y + 'px';			  
			  		comments.style.height = (y - 2) + 'px';
		}	
		  
        
        return false;
    }





function editfoto(id){
	var oForm = document.forms.add_img;	
		document.getElementById("imgg").value = id;
			document.getElementById("issEdit").value = 'editi';
			oForm.submit();
				

	
}


function AddImg(){
		var oForm = document.forms.add_img;	
		
			document.getElementById("issEdit").value = 'addimg';
			oForm.submit();
		
		
				

	
}

function deleteI(id){
if(confirm("Вы уверены что хотите удалить эту фотографию?")){
	
	var oForm = document.forms.add_img;	
		
			document.getElementById("issEdit").value = 'deleteimg';
			document.getElementById("imgg").value = id;
			oForm.submit();
		
}	
				

	
}







function OffN(new_id){
	
		var oForm = document.forms.neworg;	
		document.getElementById("new").value = new_id;
		document.getElementById("isEdit").value = 'off_n';
		oForm.submit();		
	
}

function deleteN(new_id){
	if(confirm("Вы уверены что хотите удалить эту новость?")){
		var oForm = document.forms.neworg;	
		document.getElementById("new").value = new_id;
		document.getElementById("isEdit").value = 'del_n';
		oForm.submit();		

	}		
}


function deleteQ(com_id){
	if(confirm("Вы уверены что хотите удалить этот вопрос?")){
		var oForm = document.forms.add_coment;	
		document.getElementById("parent").value = com_id;
		document.getElementById("isEdit").value = 'del_q';
		oForm.submit();		

	}		
}



function deleteA(com_id){
	if(confirm("Вы уверены что хотите удалить этот ответ?")){
		var oForm = document.forms.add_coment;	
		document.getElementById("parent").value = com_id;
		document.getElementById("isEdit").value = 'del_a';
		oForm.submit();		

	}		
}

function otvet(){
	var oForm = document.forms.add_coment;	
	oForm.isEdit.value = 'otv';
	
	if(oForm.comments.value==""){
		alert("Ответ не должен быть пустым.");
	}else{
		oForm.submit();
	}
	
}





		// end галерея

function quote2(text){
	var oForm = document.forms.addcomment;
	oForm.comments.value += ' ' + text + ' ';
	oForm.comments.focus();
}

function quote(text){
	var oForm = document.forms.add_comment_org;
	oForm.comments.value += ' ' + text + ' ';
	oForm.comments.focus();
}

function show_smiles(){
	var sOpenPage = "/form_smile.html";
	var oOpenWnd = window.open(sOpenPage,"__oHistory","menubar=0,scrollbars=1,resizable=1,width=400, height=430");
	oOpenWnd.focus();
}




function storeCaret(textEl) {
       if (textEl.createTextRange){
         textEl.caretPos = document.selection.createRange().duplicate();
       }
}

function insertAtCaret (t_area, text_in) {
var textEl=document.getElementById(t_area);

var sign='';

//IE v6.0 Opera v8.x
       if (textEl.createTextRange && textEl.caretPos) {
         var caretPos = textEl.caretPos;
          if(caretPos.text.length>0){
              caretPos.text = '['+text_in+']'+ caretPos.text + '[/'+text_in+']';
              return;
          }else{

              if(textEl.text_in==undefined){
                textEl.text_in=1;
              }

              switch(textEl.text_in){
                case 1:
                    sign='['+text_in+']';
                    textEl.text_in=2;
                break;
                case 2:
                    sign='[/'+text_in+']';
                    textEl.text_in=1;
                break;
            }

             caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? sign + ' ' : sign;
             return;
          }
       }
// Mozilla v1.4 FireFox v1.0 Netscape v7.2 Opera v8.x
    if(textEl.selectionStart!==undefined){
        if(textEl.selectionStart!==textEl.selectionEnd){
            var part_1,part_2,part_3;
            part_1 = textEl.value.substring(0, textEl.selectionStart);
            part_2 = textEl.value.substring(textEl.selectionStart,textEl.selectionEnd);
            part_3 = textEl.value.substring(textEl.selectionEnd,textEl.value.length);
            textEl.value = part_1+'['+text_in+']'+part_2+'[/'+text_in+']'+part_3;
            return;
        }else{

            if(!textEl.getAttribute(text_in)){
                textEl.setAttribute(text_in,1);
            }

                      switch(textEl.getAttribute(text_in)){
                        case '1':
                            sign='['+text_in+']';
                            textEl.setAttribute(text_in,2);
                        break;
                        case '2':
                            sign='[/'+text_in+']';
                            textEl.setAttribute(text_in,1);
                        break;
                    }

            if(!textEl.getAttribute('not_in_focus')){
            textEl.setAttribute('not_in_focus',2);
            }
            var pos;

                      switch(textEl.getAttribute('not_in_focus')){
                        case '1':
                            pos=parseInt(textEl.getAttribute('last_pos'));
                            textEl.setAttribute('last_pos',pos + parseInt(sign.length));
                        break;
                        case '2':
                            pos = parseInt(textEl.selectionStart);
                            textEl.setAttribute('last_pos',pos + parseInt(sign.length));
                            textEl.setAttribute('not_in_focus',1);
                        break;
                    }

            var part_1,part_2;
            part_1 = textEl.value.substring(0, pos);
            part_2 = textEl.value.substring(pos,textEl.value.length);
            textEl.value = part_1+sign+part_2;
            return;
        }
    }



}

function return_focus(obj){
    if(obj.selectionStart!==undefined){
        obj.setAttribute('not_in_focus',2);
    }
}

function bbc_highlight(something, mode){

	something.style.backgroundImage = "url(" + (mode ? "/images/template/bbc_hoverbg.gif)" : "/images/template/bbc_bg.gif)");
}