/////////////////////////////////////////
//                                     //
// http://glu.agarty.ru # Агарти М.С.  //
//                                     //
//                                     //
//        "GLUпые Новости"             //
//                                     //
/////////////////////////////////////////
//      Special For Rochet             //
//        from [AMC]                   //
/////////////////////////////////////////

//Функция отображения региона
function show_region(town) {   //alert(town);
   if (town == "Москва") {     hide('regions', true);
   }
   else show('regions', true);

}

function show_region2(town) {
   //alert(town);
   if (town == "Москва" || town == "Москва и Московская область") {
     show('regions', true);
   }
   else hide('regions', true);

}

// Очистка формы
	function cleared(form) {		var inTxt = document.forms[1].getElementsByTagName('input');
		var inSel = document.forms[1].getElementsByTagName('select');
        var inArea = document.forms[1].getElementsByTagName('textarea');

		// INPUT
		for (var i = 0; i < inTxt.length; i++) {
			if (inTxt[i].type == 'text') inTxt[i].value ='';
			if (inTxt[i].type == 'radio') inTxt[i].checked = false;
			if (inTxt[i].type == 'checkbox') inTxt[i].checked = false;
		}

        // SELECT
        for (var i = 0; i < inSel.length; i++) {
			inSel[i].value = '';
		}

		// TEXTAREA
        for (var i = 0; i < inArea.length; i++) {
			inArea[i].value = '';
		}

	}

// Показ\скрытыие выпадающего меню или элемента
	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) {
		id.className="select";
		}

	function flushout(id) {
		id.className="normal";
		}

	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;
	}

    var older;
    var nowid;
    function change(id) {    	var theObj = getObject(id);

		if (older && older != theObj) hide(older);

    	if (theObj.visibility == "visible") { hide(theObj); }
    	else { show(theObj); }

    	older=theObj;
    }

//Элементы объекта
   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) {	if (menu == true) var theObj = getObject(obj);
	else var theObj = obj;

	if (typeof theObj.visibility != "undefined") theObj.visibility = "visible";
	if (typeof theObj.display != "undefined") theObj.display = "block";
   }

  function hide(obj, menu)
	{
		if (menu == true) var theObj = getObject(obj);
		else var theObj = obj;
		if (typeof theObj.visibility != "undefined") theObj.visibility = "hidden";
		if (typeof theObj.display != "undefined") theObj.display = "none";
    }

//Непомню, гавно какое-то
 function check(id) {

   document.getElementById(id).checked = true;

 }

 // Добавление тегов BB-code в поле ввода
function bbcode(tag, param)
	{
		if (param == null) {
			doInsert("[" + tag + "]", "[/" + tag + "]");
		}
		else doInsert("[" + tag + "=" + param + "]", "[/" + tag + "]");
	}

function doInsert(ibTag, ibClsTag)
{
	var obj_ta = document.post_besit.u_message;

  if (document.getSelection) {
    var sel = document.selection;
    var rng = sel.createRange();
  }
  else if (document.selection && document.selection.createRange && document.post_besit.u_message.caretPos) {

    var sel = document.selection;
    //var rng =  document.post_besit.u_message.createTextRange;
    var rng = document.post_besit.u_message.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;
		document.post_besit.u_message.focus();
	    }
		else {
		ibTag = "";
		document.post_besit.u_message.focus();
		alert('Вначале выделите текст');
		}
		rng.text = ibTag;
	}

}

//Добавление кода (смайлик и вся херня)
function add(ad,promt) {
	text = ' ' + ad + ' ';
	if (document.post_besit.u_message.createTextRange && document.post_besit.u_message.caretPos) {

		 if (promt = true) {
	 		query=prompt(ad+" - Введите ссылку");
	 		if (query != '' && typeof query != "undefined" && query != null) {
            	var caretPos = document.post_besit.u_message.caretPos;
	        	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? '' : ' ['+ad+']' + query + '[/'+ad+'] ';
				document.post_besit.u_message.focus();
			}
		 }

		 else{
		 	var caretPos = document.post_besit.u_message.caretPos;
	        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
			document.post_besit.u_message.focus();
		 }

	}

	else {

	     if (promt = true) {
		 	query=prompt(ad+' - Введите ссылку');
		 	if (query != '' && typeof query != "undefined" && query != null) {
            	document.post_besit.u_message.value  += " ["+ad+"]" + query + "[/"+ad+"] " ;
				document.post_besit.u_message.focus();
			}
		 }

		 else{
			document.post_besit.u_message.value  += text;
			document.post_besit.u_message.focus();
		}
	}
}

//Карету мне, карету!
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

//Фотогалерея

 function img(i, names, attr) {
 	var newImg = new Image();
 	var lin;

 	if (names=="adm") lin="adm";
 	else lin="thumb";

 	s= "/img.php?"+lin+"=" + i;
    newImg.src = i;
    myimg=document.getElementById('imgload');
    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 my_submit()
				{
				if(window.confirm("Отказ от правил мультилистинга приведет к прекращению предоставления доступа к ресурсу. Вы уверены в том, что хотите отказаться?")) return true;
				else return false;
				}

function my_answer(form) {
		var ans=prompt("Введите Ваши предложения", ["Ваше предложения"]);
		form.message.value = ans;
		form.submit();
}

function sub_conf() { if(window.confirm("ВНИМАНИЕ! Будет произведено удаление. Вы уверены?")) return true;
 else return false;
}

function dis_rep() {
	var sh = document.getElementById('repairm');
	if (sh.checked) {		document.salecommercial.repairm2.disabled=true;
		document.salecommercial.repairyear.disabled=true;
	}
	else {		document.salecommercial.repairm2.disabled=false;
		document.salecommercial.repairyear.disabled=false;
	}
}

//Только цифры
         function num(id) {

            var el = id.value;
        	var mt = el.search(/\D/g);

			if (mt != "-1" && el != '' && typeof el != "undefined" && el != null) {

				//alert ("Поле может содержать только цифры!");
				id.value= el.replace(/\D/g, "");
				return false;

			}

         }
