
function ltrim( source ){
     var index = 0;
     while( source.charAt(index) == " " ) index++;
     return source.substr(index);
 }

 function rtrim( source ){
     var index = source.length - 1;
     while( source.charAt(index) == " " ) index--;
     return source.substring(0, index + 1);
 }

 function trim( source ){
     return ltrim(rtrim(source));
 }

function setCookie(name, value, flag)
// using example:
// setCookie("counter", 4, true); 
{
var COOKIE;

  if (flag) 
  {
  	COOKIE = name + "=" + value + "; domain=" + location.protocol + "//" + location.hostname;
  } else 
  {
  	COOKIE = name + "=" + value + ";";  
  }
//  alert(COOKIE);
  document.cookie = COOKIE;
}

function getCookie(name) 
// using example:
// var name = getCookie("name"); 
{
var RESULT;

  if (document.cookie) {
  var startPos, endPos; 
  
  startPos = document.cookie.search(name) + name.length + 1; 

   if(document.cookie.indexOf(";", startPos) != -1)
      endPos = document.cookie.indexOf(";", startPos);  
   else
      endPos = document.cookie.length;
      
  RESULT = document.cookie.substring(startPos, endPos);
  } else {
  return false;
  }

return RESULT;
}

function getAllCookies() 
// using example:
// var cookies = new Array(), name; 
// cookies = getAllCookies(); 
// name = cookies["name"]; 
{
var RESULT = new Array();

  if (document.cookie) {
  var strings = new Array(); 
  var temp = new Array();
  
  strings = document.cookie.split(";");

  for (var i=0; i<strings.length; i++) {
   temp = strings[i].split("=");
   RESULT[trim(temp[0])] = trim(temp[1]);
  }
  
  } else {
  return false;
  }

return RESULT;
}


function show_menu_level(id)
{
	var div = document.getElementById("submenu_"+id);
//alert(div.style.display);
	if(div.style.display=="none")
	{
		div.style.display = "inline";
		setCookie("submenu_"+id, "inline", false);
	}
	else if(div.style.display=="inline")
	{
		div.style.display = "none";
		setCookie("submenu_"+id, "none", false);
	}
	
}

function set_view_levels(menu_type)
{
	if (menu_type == 'quick_fix')
	{
		arCookies = getAllCookies();
		for (key in arCookies) {
	//	alert("*"+key+"--"+arCookies[key]);
			if (key.substring(0, 8) == "submenu_")
			{
				div = document.getElementById(key);
	//			alert(key+" - "+arCookies[key]);
				div.style.display = arCookies[key];
			}
		}
	}
}

// Отображение текстовой строки
function text_view(text)
{
	document.write(text);
}

/*Функции для добавления, изменения, удаления элементов формы и вообще элементов*/
function AddElemEnd(parent, value, text) 
{ 
     // Добавление элемента в список (в конец) 
	 collection = document.getElementById(parent);
	 
     opt = document.createElement("OPTION"); 
     collection.add(opt); 
     opt.innerText = trim(text); 
     opt.value = value; 
} 

function AddElemBeg(parent, value, text) 
{ 
     // Добавление элемента в список (в начало) 
	 collection = document.getElementById(parent);
	 
     opt = document.createElement("OPTION"); 
     collection.add(opt, 0); 
     opt.innerText = text; 
     opt.value = value; 
} 

function GetCountElem(listname) { 
     // Получения количества элементов в списке 
	 collection = document.getElementById(listname);

	 return collection.options.length; 
} 

function DelElem(listname, delnum) { 
     // Удаление первого элемента из списка 
	 collection = document.getElementById(listname);
     collection.remove(delnum); 
} 

function GetValElem(listname, elemnum) { 
     // Получение значения первого элемента списка 
	 collection = document.getElementById(listname);
     return collection.options(elemnum).value; 
} 

function GetTextElem(listname, elemnum) { 
     // Получение текста первого элемента списка 
	 collection = document.getElementById(listname);
     return collection.options(elemnum).text; 
} 

function GetSelectedIndex(listname) { 
     // Получение индекса выделенного элемента списка 
	 collection = document.getElementById(listname);
     return collection.options.selectedIndex; 
} 

function SelectItem(listname, selectnum) { 
     // Выделение элемента списка 
	 collection = document.getElementById(listname);
     collection.selectedIndex = selectnum; 
} 

function DelAllElem(listname) { 
     // Удаление всех элементов списка 
	 collection = document.getElementById(listname);
     i = collection.options.length; 
     while(i!=0) 
	 { 
          collection.remove(0); 
          i--; 
     } 
} 



/*Конец блока функций по для добавлению, изменению, удалению элементов формы и вообще элементов*/


