var debug = true;
var debugDiv = null;
var cookieName = "lightedMenuItem";
var parentClassNameStorage = null;


var hintDiv = null;
var hintSpan = null;
var hintContainer = null;
var hintContainerId = "hintContainerId";
var hintSpanId = "hintSpanId";
var hintDivCSSClassName = "hintDiv";
var hintSpanCSSClassName = "hintSpan";

// Hint container
function installHintContainer(_width, _height) {
	if (hintDiv = document.createElement("DIV")) {
		with(hintDiv){
			style.visibility="hidden";
			className=hintDivCSSClassName;
		}
	  // Creating SPAN for hint message	
      hintSpan = document.createElement("SPAN");
	  hintSpan.id = hintSpanId;
	  hintSpan.className = hintSpanCSSClassName;
      hintDiv.appendChild(hintSpan);
	  // Attach DIV to container	
	  var hintContainer = document.getElementById(hintContainerId);
	  //hintContainer.style.width = _width;
	  hintContainer.appendChild(hintDiv);
	} else {
		window.status = "Cannot create DIV";
	}
}

function showHint(hintMsg){
    var _hintSpan = document.getElementById(hintSpanId);
    hint = '<div>' + hintMsg + '&nbsp;<img src="/content/Image/_images/hintBorder.gif" border="0" width="1px" height="12px"><div>';
    _hintSpan.innerHTML =  hint;
	hintDiv.style.visibility = "visible";
}

function hideHint(){
    var _hintSpan = document.getElementById(hintSpanId);
	_hintSpan.innerHTML = "";
	hintDiv.style.visibility = "hidden";
}

/*
 * Light and put out parent menu item
 */
function lightParent(_topMenuPos){
	pId = getTopMenuIdByPosition(_topMenuPos);
	id = "e0_"+pId+"i";
	if (__parent = document.getElementById(id)) {
		__parent.className = "m0l0iover";
	} else {
		//_debug("Cannot get element with ID["+id+"]");
	}
}

function putOutParent(_topMenuPos){
	pId = getTopMenuIdByPosition(_topMenuPos);
	if (pId != menuTopId) {
		id = "e0_"+pId+"i";
		if (__parent = document.getElementById(id)) {
			__parent.className = "m0l0iout";
		} else {
			//_debug("Cannot get element with ID["+id+"]");
		}
	} 
}

/*
 * Light Active Menu Section 
 */
function lightOnActiveMenuItem(){
	id = "e0_"+menuTopId+"i";
	if (_menuItem = document.getElementById(id)) {
		_menuItem.className = "m0l0iover";
	}
}

function lightOffActiveMenuItem(){
	id = "e0_"+menuTopId+"i";
	if (_menuItem = document.getElementById(id)) {
		_menuItem.className = "m0l0iout";
	}
}

function _fireEvent(obj, eventName){
	if (!obj.fireEvent(eventName)) {
		obj.dispatchEvent(eventName);	
	}
}


/*
 * Get TOP Level menu ID by Caption-name 
 */
function getTopMenuIdByName(menuName) {
	var mId = null;
	for(i=0; i<TOPITEMS.length; i++){
		if (TOPITEMS[i][1] == menuName) {
			mId = TOPITEMS[i][0];
			break;
		}
	}
	return mId;
}

/*
 * Get TOP Level menu ID by Position
 */
function getTopMenuIdByPosition(position) {
	return TOPITEMS[position][0];
}



function storeMenuItem(menuItemId){
	setCookie(cookieName, menuItemId);
}

function restoreMenuItem(){
	return getCookie(cookieName);
}



/*
 * Working with cookies
 * Setter Getter
 */
function setCookie(cookieName, cookieValue){
	document.cookie = cookieName + "=" + escape(cookieValue) + ";";
}

function getCookie(name) {
  var start = document.cookie.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0,name.length)))
    return null;
  if (start == -1)
    return null;
  var end = document.cookie.indexOf(';',len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}




/*
 * Used in Software Manufacturing Cycle preview
 */
function showBigPicture(imgLink){
  var args = "width=580,height=620,left=110,top=50,scrollbars=no,resizable=no";
  var bigIm = window.open('/content/_other/how_we_work/smc/index.html', "BigPicture", args);
}




/*
 * TRIM Analogue function
 */
function trim(sString) {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function nn6SetSearchField() {
	document.searchform.query.value = 'search';
	return true;
}


/*
 * Debug section
 */
function installDebugWindow() {
	_width = 500;
	_height = 300;
	if (!debug) return false;
	if (debugDiv = document.createElement("DIV")) {
		with(debugDiv){
			style.visibility="visible";
			style.width = _width;
			style.height = _height;
			style.zIndex="1";
		}
	  // Creating SPAN for hint message	
      hintSpan = document.createElement("SPAN");
	  hintSpan.id = hintSpanId;
	  hintSpan.className = hintSpanCSSClassName;
      document.body.appendChild(debugDiv);
	} else {
		window.status = "Cannot create DIV";
	}
}

function _debug(_obj) {
    if (!debugDiv) {
    	installDebugWindow();
    }
    if (debugDiv) debugDiv.innerHTML += _obj + "<br>\n";
}

//
