/////////////////////////////////////////
//                                     //
// http://glu.agarty.ru # Агарти М.С.  //
//                                     //
//                                     //
//        "GLUпые Новости"             //
//                                     //
/////////////////////////////////////////


    var IE;
    var browserd = navigator.appName;

    if(browserd == 'Microsoft Internet Explorer'){
        IE = true;
    }
    else{
        IE = false;
    }


// Показ\скрытыие выпадающего меню или элемента
	var oldsubmenu;
	var timeOnMenu;
	function showmenu(obj) {

		if (timeOnMenu) {
			clearTimeout(timeOnMenu);
		}

		if (oldsubmenu) hide(oldsubmenu, true);
		oldsubmenu=obj;
		show(obj, true);
    }

   function hidemenu() {
   		if (oldsubmenu) timeOnMenu=setTimeout("hide(oldsubmenu, true)", 500);

   }

//Подсветка при наведении, клике
	function flushover(id, nam) {		id.className=nam;
		}

	function flushout(id, nam) {
		id.className=nam;
		}

	var oldid;
	function flushing(id) {     //alert(id);
		var theObj = getObject(id);

	  if (oldid)	oldid.background = "none";
      oldid=theObj;
      theObj.background = "#0f0";


	}

//Показ\скрытие по нажатию

	var now;
	function hideimg(body) {
	  if (nowid && nowid == now) change(nowid);
	  if (event.keyCode==27) change(nowid);
	  now = nowid;
	}

	function change_row(ids, row, total) {

	 for (a=1; a <= total; a++) {	 	id=document.getElementById(ids + a);

        //if (older && older != id) hide(older, false, true);

		if (id.style.display != "none") {
			row.style.backgroundColor="#597B97";
			hide(id, false, true);
			nowid=null;
		}
		else {			row.style.backgroundColor="#800";
			show(id, false, true);
			nowid=id;
		}
		//older2=older=id;
     }

    }

    var older;
    var nowid;
    var nowtime;
    var timeOnMen;
    function change(id, timer) {    	 if (document.getElementById(id)) {
	    	var theObj = getObject(id);

	       if (timeOnMen) {
				clearTimeout(timeOnMen);
			}

			if (older && older != theObj) hide(older);

	    	if (theObj.visibility && theObj.visibility == "visible") { hide(theObj); nowid=null; }
	    	else { show(theObj); nowid=id; }

	    	older2=older=theObj;
	        nowtime = timer * 1000;

	    	if (timer) timeOnMen=setTimeout("hide(older2)", nowtime);
	  	}
    }


    function change_r(id, cat) {
	     if (document.getElementById(id)) {
		    	var theObj = getObject(id);

       		    if (!theObj) theObj=getByID(id).style;

		    	if (theObj.visibility && theObj.visibility == "visible" || theObj.display == "block") {
		    		hide(theObj);
		    		//if (cat) document.getElementById(cat).innerHTML='[+]';
		    	}
		    	else {
		    		 show(theObj);
		    	     //if (cat) document.getElementById(cat).innerHTML='[-]';
		    	}
	     }
    }

//Элементы объекта
   function getObject(obj)
   	{
	var theObj;
   		if (document.layers) {
   			if (typeof obj == "string") return document.layers(obj);
   			else return obj;
   			}

   		if (document.all) {
   			if (typeof obj == "string")
   				{
   					if (typeof document.all(obj) != null)  return document.all(obj).style;
   					else return null;
   				}
   			else return obj.style;
   		}

   		if (document.getElementById) {
   			if (typeof obj == "string") return document.getElementById(obj).style;
   			else return obj.style;
      	}
      	return null;
    }

// Функции показа\скрытие элемента по событию
   function show(obj, menu, table_tr) {
	if (menu == true) var theObj = getObject(obj);
	else var theObj = obj;

	  if (!table_tr) {
		if (typeof theObj.visibility != "undefined") theObj.visibility = "visible";
		if (typeof theObj.display != "undefined") theObj.display = "block";
	  }
	  else  obj.style.display = IE ? "block" : "table-row";
   }

  function hide(obj, menu, table_tr) {
  		table_tr = table_tr ? true : false;

		if (menu == true) var theObj = getObject(obj);
		else var theObj = obj;

	  if (!table_tr) {
		if (typeof theObj.visibility != "undefined" && !table_tr) theObj.visibility = "hidden";
		if (typeof theObj.display != "undefined") theObj.display = "none";
	  }
	  else obj.style.display = "none";
    }

//Непомню, гавно какое-то
 function checked(id) {

   document.getElementById(id).checked = true;

 }

//Проверка
 function conf(query) {  if (query == "del_anime") query = "Вы действительно хотите удалить элемент из списка?";
  if (confirm(query)) return true;
  else return false;

 }

//Считает количество символов в поле
function strlen(inp) {    total=inp.value.length;
	document.getElementById("strlen_count").innerHTML=total;
}

 // Добавление тегов BB-code в поле ввода
function bbcode(tag, param, frm){
var forma = frm;

		if (param == null || param == false) {
			doInsert("[" + tag + "]", "[/" + tag + "]", forma);
		}

		else if (param == 2) doInsert("[" + tag + "]", false, forma);

		else doInsert("[" + tag + "=" + param + "]", "[/" + tag + "]", forma);
}

function doInsert(ibTag, ibClsTag, forma)
{
	var obj_ta = forma;

  if (document.getSelection) {    var sel = document.selection;
    var rng = sel.createRange();
  }
  else if (document.selection && document.selection.createRange && obj_ta.caretPos) {

    var sel = document.selection;
    //var rng =  document.post_besit.u_message.createTextRange;
    var rng = obj_ta.caretPos;
  }

  else if (!ibClsTag) {    var rng = obj_ta.caretPos;
  }

  else alert('Вначале выделите текст');

	//var sel = document.selection;
	//var rng = sel.createRange();
	rng.colapse;
	if((sel.type == "Text" || sel.type == "None") && rng != null)
	{
		if(ibClsTag != "" && rng.text.length > 0){
		ibTag += rng.text + ibClsTag;
		obj_ta.focus();
	    }
		else {
		ibTag += rng.text;
		obj_ta.focus();
		}
		rng.text = ibTag;
	}

}

//Добавление кода (смайлик и вся херня)
function add(ad, promt, field) {
	text = ' ' + ad + ' ';
	var obj_ta = document.getElementById(field);

	if (obj_ta.createTextRange && obj_ta.caretPos) {

		 if (promt == true) {	 		query=prompt(ad+" - Введите ссылку");
	 		if (query != '' && typeof query != "undefined" && query != null) {
            	var caretPos = document.getElementById(field).caretPos;
	        	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? '' : ' ['+ad+']' + query + '[/'+ad+'] ';
				document.getElementById(field).focus();
			}
		 }

		 else{		 	var caretPos = document.getElementById(field).caretPos;
	        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
			document.getElementById(field).focus();
		 }

	}

	else {
	     if (promt == true) {		 	query=prompt(ad+' - Введите ссылку');
		 	if (query != '' && typeof query != "undefined" && query != null) {
            	document.getElementById(field).value  += " ["+ad+"]" + query + "[/"+ad+"] " ;
				document.getElementById(field).focus();
			}
		 }

		 else{
			document.getElementById(field).value  += text;
			document.getElementById(field).focus();
		}
	}
}

//Карету мне, карету!
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

//Фотогалерея

 function img(i, names, attr) { 	var sh = document.getElementById('sh');
    if (sh.checked) return false;

 	var newImg = new Image();
 	var lin;

 	if (names=="adm") lin="adm";
 	else lin="thumb";
 	s= "/img.php?"+lin+"=" + i;
 	var path = document.getElementById(i);
    newImg.src = "/img.php?"+lin+"=" + i;
    myimg=document.getElementById('imgload');
    //alert(myimg.src);
    myimg.src = newImg.src;

    nams=document.getElementById('nam');
    //alert(nam.firstChild.nodeValue);
    nams.firstChild.nodeValue = names;

    atr=document.getElementById('atrib');
    //alert(atr.firstChild.nodeValue);
    atr.firstChild.nodeValue= attr;

    dow=document.getElementById('down');
    dow.href = "/img.php?link=" + i;

 }

function loc(url, val) {   if (val !== "false") location.href="/index.php?mode=" + url + val;}

function user(action, uid, w, h) { if (w) var width = w; else var width = 600;

 if (h) var height = h;
 else var height =500;

 var top= (screen.availHeight/2) - (height/2) - 30;
 var left= (screen.availWidth/2) - (width/2);

 if (action == "edit") {
 	window.open("/share/user_control.php?edit=" + uid, "edit_user", "scrollbars, width="+ width + ", height="+ height + ", top="+ top + ", left=" + left);

 }

 else if (action == "add") {
  window.open("/share/user_control.php?add=" + uid, "add_user", "scrollbars, width="+ width + ", height="+ height + ", top="+ top + ", left=" + left );


 }

 else if (action == "pass") {
 	  window.open("/share/pass_recovery.php", "pass_rec", "scrollbars, width="+ width + ", height="+ height + ", top="+ top + ", left=" + left );

 }
}

function screens(screend, w, h){
 var width = 450;
 var height =350;

 var top= (screen.availHeight/2) - (height/2) - 30;
 var left= (screen.availWidth/2) - (width/2);

 window.open("/share/catalog/"+screend, "screenf", "scrollbars, width="+ width + ", height="+ height + ", top="+ top + ", left=" + left );
}

function win(loc, w, h, wname, mods) { if (w) var width = w;
 else var width = 600;

 if (h) var height = h;
 else var height =500;
 var top= (screen.availHeight/2) - (height/2) - 30;
 var left= (screen.availWidth/2) - (width/2); window.open(loc,"screenf", mods + wname + ", width="+ width + ", height="+ height + ", top="+ top + ", left=" + left );

}

function alerts(query) {	if (confirm(query)) return true;
	else return false;
}

function addsubcat(category) {
	var subcatname=prompt("Введите название подкатегории:", "");

	if (subcatname) {      document.getElementById("subcat").value=subcatname;
      document.getElementById("cat").value=category;
      document.getElementById("subcat_form").submit();
	}

}

function getsubcats(cat) {
	if (cat) {       var cats=sndReq(cat);
	}

}

function openw(loc, w, h, wname, mods) {
 if (w) var width = w;
 else var width = 600;

 if (h) var height = h;
 else var height =500;

 var top= (screen.availHeight/2) - (height/2) - 30;
 var left= (screen.availWidth/2) - (width/2);
 window.open(loc,wname , mods + ", width="+ width + ", height="+ height + ", top="+ top + ", left=" + left );

}

function is_object(obj) {	if (typeof obj == "object") return true;
	else return false;
}

function is_string(str) {	if (typeof obj == "string") return true;
	else return false;
}


function change_img(obj, img) {
	if (is_object(obj)) obj.src=img;
	else document.getElementById(obj).src=img;
}

function check_box(id, erss) {	var chk=document.getElementById(id);
	if (chk.checked) {		chk.checked=false;
	}
	else chk.checked=true;

	if (erss) enables_rss();
}

function enables_rss() {	var blog_chk=document.getElementById("blog").checked;
    var news_chk=document.getElementById("news").checked;
    var events_chk=document.getElementById("events").checked;
    var photo_chk=document.getElementById("photo").checked;
    var disabled_rss=true;

    if (blog_chk || news_chk || events_chk || photo_chk) disabled_rss=false;

    document.getElementById("feed_rss").disabled=disabled_rss;
}

function clear_value(field) {	document.getElementById(field).value="";
}

function del(id, confr, addt) {	if (conf(confr)) {		document.location.href="/mail/?del="+id+addt;
	}
}

//Выбрать объект по ID
function getByID(IDobj) {	 return document.getElementById(IDobj);
}

var nowISFULL=false;
function full_view(idDiv) {	if (!nowISFULL) {
		var Div=getByID(idDiv);
		var bodyHeight=getByID("MAINDIV").offsetHeight;
		var bodyWidth=getByID("MAINDIV").offsetWidth;
		Div.style.height=bodyHeight + "px";
		Div.style.width=bodyWidth + "px";

		nowISFULL=true;
	} else nowISFULL=false;

	change_r(idDiv);

	if (nowISFULL) {
		var himg = getByID("fullscreenIMG").clientHeight;

		if (himg > 200) getByID("fullscreenBODYTEXT").style.height=himg + 10 + "px";
	    else IE ? getByID("fullscreenBODYTEXT").style.height = "200px" : getByID("fullscreenBODYTEXT").style.minHeight = "200px";

		if (IE) {			var wimg = getByID("fullscreenIMG").clientWidth;
			if (wimg > 250) getByID("fullscreenIMG").style.width = "250px"
		}

		var height = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
		var top = window.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

	    var fscreenDIV = getByID("fullscreenDIV").clientHeight;
	    position_top = (height - fscreenDIV)/2;
	    getByID("fullscreen").style.paddingTop= top + position_top + "px";
	 }


}

function fullview(idIMG, idDIV, isPATH) { if (!nowISFULL) { 	if (isPATH) var idSRC= idIMG ? idIMG : "/img/txt_zagl.png";	else var idSRC= getByID(idIMG) ? getByID(idIMG).src : "/img/txt_zagl.png";
	var inner=getByID(idDIV+"_text").innerHTML;

	var fscreen =  '<div align="center"><div id="fullscreenDIV" class="fullscreenBODY">';
	fscreen += '<div class="fullscreenBODYIMG"><div align="center" id="fullscreenBODYIMG"><img id="fullscreenIMG" src="'+idSRC+'" alt="Маленькие Хитрости" border="0" align="texttop"></div></div>';
	fscreen += '<div class="fullscreenBODYTEXT" id="fullscreenBODYTEXT"><div align="right"><b  style="cursor: pointer;" class="red">X</b></div>';
    fscreen += inner+'</div></div></div>';

   	getByID("fullscreen").innerHTML=fscreen;
 }

    full_view("fullscreen");
}


   function ie_maxWidth(obj, width) {
         if (!obj.id || !obj.offsetWidth) return;
        //проверяет ширину картинки и если больше уменьшает, если меньше делает
        //размер автоматическим

        obj.style.width=(obj.offsetWidth > width ? width + "px" : "auto");

        //Убирает ID картинки, что бы не завис IE
        obj.setAttribute("id", "");

   }

   function ie_minWidth(obj, width) {
        if (!obj.id) return;
        //проверяет ширину картинки и если меньше увеличивает, если больше делает
        //размер автоматическим
        obj.style.width=(obj.offsetWidth < width ? width + "px" : "auto");

        //Убирает ID картинки, что бы не завис IE
        obj.setAttribute("id", "");

   }


   function ie_maxHeight(obj, height) {
        if (!obj.id) return;
        //проверяет высоту картинки и если больше уменьшает, если меньше делает
        //размер автоматическим
        obj.style.height=(obj.offsetHeight > height ? height + "px" : "auto");

        //Убирает ID картинки, что бы не завис IE
        obj.setAttribute("id", "");

   }

   function ie_minHeight(obj, height) {
        if (!obj.id) return;
        //проверяет высоту картинки и если меньше увеличивает, если больше делает
        //размер автоматическим
        obj.style.height=(obj.offsetHeight < height ? height + "px" : "auto");

        //Убирает ID картинки, что бы не завис IE
        obj.setAttribute("id", "");

   }

var oldDIV=false;
function change_catalog(idDIV) {
	if (oldDIV == idDIV) return;
	if (oldDIV) {		 hide(oldDIV, 1);
		 getByID(oldDIV + "_link").className="cat_over_link";
	}
	else {		 hide("cat_hitrosti", 1);
	 	 getByID("cat_hitrosti_link").className="cat_over_link";
	}
	show(idDIV, 1);
	getByID(idDIV + "_link").className="cat_press_link";
	oldDIV=idDIV;
}


function setOpacity(id, value) {
    var obj = document.getElementById(id);
    setOpacityO(obj, value);
}
function setOpacityO(obj, value) {	obj.style.opacity = value / 100;
    obj.style.filter = 'alpha(opacity='+value+')';

}
function fade(id, val) {
    if (val) {
        for (var i = 0; i < 101; i++)
            setTimeout('setOpacity("' + id + '",' + i + ');', 3 * i);
    } else {
        for (var i = 100; i > -1; i--)
            setTimeout('setOpacity("' + id + '",' + i + ');', 3 * (100 - i));
    }
}


var oldIdBlock=false;
var block_txt;
var block_img;
var oldSHTIME;
var idBlock;
function show_block(idBlocks) {
		if (oldSHTIME) drop_shtimer();
		idBlock =  idBlocks;
		oldSHTIME=setTimeout("show_block_act()", 300);
}

function drop_shtimer() {	clearTimeout(oldSHTIME);
}

function show_block_act() {	if (oldIdBlock !== idBlock) {		if (oldIdBlock) hide_block(oldIdBlock);		var block=getByID(idBlock);
		var block_text = getByID(idBlock+"_text");
		block_txt = block_text.innerHTML;
		block_img = '<img class="enlarge" src="/img/enlarge.gif" width="16" height="16" border="0" align="absmiddle" OnMouseOver="show_block(\''+idBlock+'\')">';

		block.innerHTML = '<div  OnMouseOut="hide_block(\''+idBlock+'\')" id="'+idBlock+'_div" class="hitrosti_block_body_text">'+block_txt+'</div>';
		oldIdBlock = idBlock;
	}

}



function hide_block(idBlock) {
	var block=getByID(idBlock);
	block.innerHTML=block_img + ' <span id="'+idBlock+'_text">' + block_txt + "</span>";
	oldIdBlock=false;
	idBlock = false;
	oldSHTIME = false;
}

