
var GlobalOpenedMenuBlkArr = new Array();
var GlobalLastOpenedMenuBlkID = null;
var GlobalLastOpenedSearchQBlkID = null;

function GLSearchQHideOnTimer()
{
		try
		{
        						// закрывем открытые
                            	if (window.GlobalLastOpenedSearchQBlkID != null)
                            	{
                                	if (typeof(window.GlobalLastOpenedSearchQBlkID) == 'object')
                                	{
                                    	window.GlobalLastOpenedSearchQBlkID.style.display = 'none';
                                    	if (window.q_clouseSerachQBlk_onTimer) clearTimeout(window.q_clouseSerachQBlk_onTimer);
                                	}
                            	}
		}
		catch(e)
		{
			alert("GLSearchQHideOnTimer Error: " + e.message);
		}

		return false;
}

function GLMenuHideOnTimer()
{
		try
		{
        						// закрывем открытые
                            	if (window.GlobalLastOpenedMenuBlkID != null)
                            	{
                                	if (typeof(window.GlobalLastOpenedMenuBlkID) == 'object')
                                	{
                                    	//alert("window.GlobalLastOpenedMenuBlkID.id = " + window.GlobalLastOpenedMenuBlkID.id);
                                    	window.GlobalLastOpenedMenuBlkID.style.visibility = 'hidden';


                                    	if (q_clouseBlk_onTimer != null) clearTimeout(q_clouseBlk_onTimer);
                                	}
                            	}
		}
		catch(e)
		{
			alert("GLMenuHideOnTimer Error: " + e.message);
		}

		return false;
}

function Showmenu(IDLINKMenu, IDCurrentLayer, offsetLeftIn, offsetTopIn)
{
	var i,TopPosition,args = Showmenu.arguments;

	if (typeof(IDLINKMenu) != 'undefined') var IDMenuMainObj = document.getElementById(IDLINKMenu);
	if (typeof(IDCurrentLayer) != 'undefined') var CurrentLayer = document.getElementById(IDCurrentLayer);

	if (CurrentLayer && IDMenuMainObj)
	{
				CurrentLayer.style.visibility = 'visible';

				// смена положения
    	    	CurrentLayer.style.left = (IDMenuMainObj.offsetLeft + offsetLeftIn)  + "px";
    	    	CurrentLayer.style.top = (IDMenuMainObj.offsetTop + offsetTopIn)  + "px";

    	    	// подключаем собития
                CurrentLayer.onmouseout = function()
                {
                	q_clouseBlk_onTimer = setTimeout("GLMenuHideOnTimer();", 1250);
                };

                CurrentLayer.onmouseover = function()
                {
                	if (q_clouseBlk_onTimer != null) clearTimeout(q_clouseBlk_onTimer);
                };

                window.GlobalLastOpenedMenuBlkID = CurrentLayer;
	}
}

function Hidemenu(IDCurrentLayer)
{
	try
	{
  		if (typeof(In_id) == "string")
  		{
  			if (In_id.length > 0)
  			{
  				var oOBJ = document.getElementById(In_id);

                if (typeof(oOBJ) == "object")
                {
                	oOBJ.style.visibility = 'hidden';
                }
  			}
  		}
	}
	catch(e)
	{
    	alert("Hidemenu error: "+e.message);
	}
}


function InsertSearchResultInToConteuner(in_serch_textID, in_containerID, in_TBL_ID, in_dataArr, offsetLeftIn, offsetTopIn)
{

	//alert("InsertSearchResultInToConteuner active");

	try
	{
    	//alert("typeof(in_dataArr) = "+typeof(in_dataArr));

    	if (typeof(in_serch_textID) == "string" && typeof(in_containerID) == "string" && typeof(in_TBL_ID) == "string" && typeof(in_dataArr) == "object")
  		{
  			if (in_serch_textID.length > 0 &&in_containerID.length > 0 && in_TBL_ID.length > 0 && in_dataArr.length > 0)
  			{
            	var oOBJ_serch_text = document.getElementById(in_serch_textID);
            	var oOBJ_container = document.getElementById(in_containerID);
            	var oOBJ_TBL = document.getElementById(in_TBL_ID);

            	//alert('typeof(oOBJ_TBL) == ' + typeof(oOBJ_TBL));
                if (oOBJ_serch_text)
                {
	                if (oOBJ_TBL && oOBJ_serch_text.value.length > 3)
	                {
	                    if (oOBJ_container)
		                {
		                	oOBJ_container.style.display = "block";
		                	oOBJ_container.style.left = (oOBJ_serch_text.offsetLeft + offsetLeftIn)  + "px";
		    	    		oOBJ_container.style.top = (oOBJ_serch_text.offsetTop + offsetTopIn)  + "px";
		    	    		oOBJ_container.style.width="300px";
		    	    		oOBJ_TBL.style.width = oOBJ_container.style.width;

		    	    		// подключаем собития
			                oOBJ_container.onmouseout = function()
			                {
			                	window.q_clouseSerachQBlk_onTimer = setTimeout("GLSearchQHideOnTimer();", 1200);
			                };

			                oOBJ_container.onmouseover = function()
			                {
			                	if (window.q_clouseSerachQBlk_onTimer) clearTimeout(window.q_clouseSerachQBlk_onTimer);
			                };

			                window.GlobalLastOpenedSearchQBlkID = oOBJ_container;
		                }

                        var i5 = (oOBJ_TBL.rows.length - 1);

                        while(i5 >= 0)
                        {
                                	//alert("i5 = " + i5 + "\n oOBJ_TBL.rows[i5].innerHTML = " + oOBJ_TBL.rows[i5].outerHTML);
                                    oOBJ_TBL.deleteRow(i5);
                                	i5--;
                        }

                        var tbody = document.createElement("tbody");

	                    for(var i in in_dataArr)
			            {
			            	if (typeof(in_dataArr[i]) != "function")
			            	{
			                	//alert("in_dataArr[i] = "+ in_dataArr[i]);

			                	// ----- link --------------------------------------
			                	var a_link = document.createElement("A");

								a_link.href = "#";
								a_link.title = in_dataArr[i];

								// событие активации линка по клику
								a_link.onclick = function()
				                {

                     				if (oOBJ_serch_text)
                     				{
	                     				oOBJ_serch_text.value = this.title;
	                     				GLSearchQHideOnTimer();
                                    }

				                };

								//a_link.nodeValue = in_dataArr[i];
							    a_link.innerHTML = in_dataArr[i];

							    //------- row ---------------------------------------

			                	var tr = document.createElement("tr");
								var td = document.createElement("td");
							    td.appendChild(a_link);
							    tr.appendChild(td);
                                tbody.appendChild(tr);
			           		}
			       		}

			            oOBJ_TBL.appendChild(tbody);
	                }
	             }
  			}
  		}
	}
	catch(e)
	{
    	alert("InsertSearchResultInToConteuner error: "+e);
	}
}


window.changePhotoOnMessage_lastOBJLink = null; // последний помеченный объект

function changePhotoOnMessage(in__load_img_mess_valueArr)
{

	//alert("changePhotoOnMessage active");

	try
	{
    	//alert("typeof(in__load_img_mess_valueArr) = "+typeof(in__load_img_mess_valueArr));

    	if (typeof(in__load_img_mess_valueArr) == "object")
  		{
  			if (in__load_img_mess_valueArr)
  			{
  				//alert("in__load_img_mess_valueArr['src'] = "+in__load_img_mess_valueArr['src']);

  				if (in__load_img_mess_valueArr['src'].length > 0
  					&& in__load_img_mess_valueArr['small'].length > 0
  					&& in__load_img_mess_valueArr['link_foto_ID'].length > 0
  					&& in__load_img_mess_valueArr['title'].length > 0
  					&& in__load_img_mess_valueArr['img_ID'].length > 0
  					&& in__load_img_mess_valueArr['link_img_ID'].length > 0)
  				{
	            	var oOBJ_img_ID = document.getElementById(in__load_img_mess_valueArr['img_ID']);
	            	var oOBJ_link_img_ID = document.getElementById(in__load_img_mess_valueArr['link_img_ID']);
	            	var oOBJ_link_foto_ID = document.getElementById(in__load_img_mess_valueArr['link_foto_ID']);

	            	if (oOBJ_img_ID && oOBJ_link_img_ID && oOBJ_link_foto_ID)
	                {
                    	oOBJ_link_img_ID.href = in__load_img_mess_valueArr['src'];
                    	oOBJ_link_img_ID.title = in__load_img_mess_valueArr['title'];

                    	oOBJ_img_ID.src = in__load_img_mess_valueArr['small'];
                    	oOBJ_img_ID.alt = in__load_img_mess_valueArr['title'];

                    	// в старом объекте меняем оформление на обычное
                    	if (window.changePhotoOnMessage_lastOBJLink)
                    	{
                    		window.changePhotoOnMessage_lastOBJLink.style.fontWeight = 'normal';
                    		window.changePhotoOnMessage_lastOBJLink.style.color = "#006699";
                    	}

                        // в новом объекте меняем оформление на выделенное
                        oOBJ_link_foto_ID.style.fontWeight = 'bold';
                    	oOBJ_link_foto_ID.style.color = "#FF0000";

                        // фиксируем новый объект как старый
                    	window.changePhotoOnMessage_lastOBJLink = oOBJ_link_foto_ID;
	                }
               }
     		}
        }
    }
	catch(e)
	{
    	alert("InsertSearchResultInToConteuner error: "+e);
	}
}

/* вставка option's в select подкатегорий */
function InsertInToCatSub (in_OBJ_ID, in_Arr)
{
	try
	{
    	if(typeof(in_OBJ_ID) != 'undefined' && typeof(in_Arr) != 'undefined')
        {
        	var oOBJ = document.getElementById(in_OBJ_ID);
        	//alert("changeCatSub in_OBJ_ID = "+ in_OBJ_ID);

        	if (typeof(oOBJ) == 'object' && in_Arr.length > 0)
        	{
            	oOBJ.length = 0;

            	for(var i=0; i<in_Arr.length; i++)
	        	{
	            	var opt = document.createElement("OPTION");
		            opt.innerHTML = in_Arr[i].title;
		            opt.value = in_Arr[i].id_categories_sub;

		            oOBJ.appendChild(opt);
		      	}
        	}
        }
	}
	catch(e)
	{
    	alert("InsertInToCatSub error: "+e);
	}
}

// пометить option подкатегории
function changeCatSub (in_OBJ_ID, in_val)
{
	try
	{
    	if(typeof(in_OBJ_ID) != 'undefined' && in_val > 0)
        {
        	var oOBJ = document.getElementById(in_OBJ_ID);
        	//alert("changeCatSub in_OBJ_ID = "+ in_OBJ_ID);

        	if (typeof(oOBJ) == 'object')
        	{
           		var selRows = oOBJ.options;
           		//alert("typeof(selRows) = "+typeof(selRows));

           		for(var iRow = 0; selRows.length > iRow ; iRow++)
           		{
					//alert("selRows[iRow].innerHTML = " + selRows[iRow].innerHTML);
					//alert("selRows[iRow].value = " + selRows[iRow].value);

					if (selRows[iRow].value == in_val)
					{
						selRows[iRow].selected = true;
					}
			    }

        	}
        }
	}
	catch(e)
	{
    	alert("changeCatSub error: "+e);
	}
}