// Require JS-Query 1.4
// *********************************************

  var urlOff = getContextRoot()+'images/stars/star_off_small.png';
  var urlOn  = getContextRoot()+'images/stars/star_on_small.png';

  /*onmouseout="setStar('country__security_',$('#security').val())"*/
  function setStar(prefix, field, num)
  {
    num = parseInt(num+'');
	  for ( var i = 2 ; i<=num ; i++)
	  {
		  $('#'+prefix+i).attr('src',urlOn);
	  }
    for ( var i = (num+1) ; i<=5 ; i++)
    {
    	$('#'+prefix+i).attr('src',urlOff);
    }
    //$('#'+field).val(num);
  }

  function doTiptip()
  {
	$(".do_tiptip")
	.tipTip({
		defaultPosition:'right',delay:200,edgeOffset:8
	})
	.mouseover(function() {
		this.style.backgroundPosition='bottom';
	})
	.mouseout(function(){
		this.style.backgroundPosition='top';
	});
	
	$("img")
	.tipTip({
		defaultPosition:'right',delay:400,edgeOffset:8
	});
	$("a")
	.tipTip({
		defaultPosition:'right',delay:100,edgeOffset:8
	});
  }
  
//*********************************************

  function startLoad()
  {
	window.scrollTo(0,0);
	$('.video').css('display','none');
	$("body").append('<div id="dont_move" class="loadingOverAll" style=" '+
			'height: ' + $(document).height() + 'px;">'+
			'<img src="/images/loading_transparent.gif" alt="loading"/>'+
			'</div>');
  }

  function endLoad()
  {
	  $('.video').css('display','block');
	  $('#dont_move').remove();
  }


// *********************************************

  //VARIABLE TREE SCRIPT

  function alternate(name)
  {
    var nodes = $('.searchable');
    var count = nodes.length;
    var root = null;
    var line = 1;
    for (var i = 0; i < count; i++)
    {
      if (typeof $(nodes[i].parentNode).attr('tree') != undefined && $(nodes[i].parentNode).attr('tree') == name)
      {
        if (nodes[i].parentNode.style.display == '')
        {
          nodes[i].parentNode.className = nodes[i].parentNode.className.replace(/line[01]/, 'line' + line);
          nodes[i].parentNode.setAttribute('colorIndex', line);
          line = (line + 1) % 2;
        }
      }
    }
  }

  function highlightInNode(node, value)
  {
    var content = node.data ? node.data : node.textContent;
    var searchContent = content.toLowerCase();
    var start = 0;

    var len = value.length;

    while ((pos = searchContent.indexOf(value)) != -1)
    {
      if (pos != 0)
      {
        var newNode = document.createTextNode(content.substring(0, pos));
        node.parentNode.insertBefore(newNode, node);
      }

      var spanNode = document.createElement('span');
      spanNode.className = 'highlight';
      spanNode.innerHTML = content.substring(pos, pos + len);

      node.parentNode.insertBefore(spanNode, node);

      content = content.substring(pos + len);
      searchContent = searchContent.substring(pos + len);
    }

    if (content != '')
    {
      if (node.data)
      {
        node.data = content;
      }
      else
      {
        node.textContent = content;
      }
    }
    else
    {
      node.parentNode.removeChild(node);
    }
  }

  function searchAndHighlightValue(node, value)
  {
    if (node.nodeName == '#text')
    {
      if ((node.data ? node.data : node.textContent).toLowerCase().lastIndexOf(value) != -1)
      {
        highlightInNode(node, value);
        return true;
      }
      return false;
    }

    var children = node.childNodes;
    var count = children.length;
    var result = false;
    for (var i = 0; i < count; i++)
    {
      result = result || searchAndHighlightValue(children[i], value);
    }
    return result;
  }

  var lastFilter = {};

  function filterTree(name, value, maxLevel)
  {
    if (typeof lastFilter[name] != 'undefined') {
      if (lastFilter[name] == value) {
        return ;
      }
    }
    lastFilter[name] = value;

    var orignalValue = value.toLowerCase();
    value = value.replace(/([\\\[\].*+?{}])/g, '\\$1');
    var highlight = true;

    var highlighted = $(".highlight");
    var count = highlighted.length;
    for (var i = 0; i < count; i++)
    {
      $(highlighted[i]).replaceWith($(highlighted[i]).html());
    }

    var content;
    var value;

    var nodes = $('.searchable');
    var count = nodes.length;
    for (var i = 0; i < count; i++)
    {
      if (typeof $(nodes[i].parentNode).attr('tree') == undefined || $(nodes[i].parentNode).attr('tree') != name)
      {
        continue;
      }

      content = $(nodes[i]).html();
      $(nodes[i]).html(content);
      content = $(nodes[i]).html();

      if (value != '' && searchAndHighlightValue(nodes[i], orignalValue))
      {
        nodes[i].parentNode.style.display = '';
      }
      else
      {
        if (value == '')
        {
          nodes[i].parentNode.style.display = '';
        }
        else
        {
          nodes[i].parentNode.style.display = 'none';
        }
      }
    }

    // Display nodes whose parent is visible
    for (var i = 0; i < maxLevel; i++)
    {
      nodes = $('.level' + i);

      var count = nodes.length;
      for (var j = 0; j < count; j++)
      {
        if (typeof $(nodes[j]).attr('tree') == undefined || $(nodes[j]).attr('tree') != name)
        {
          continue;
        }
        if (nodes[j].style.display == '')
        {
          var node = nodes[j].nextSibling;
          while (node != null && node.nodeName == 'TR' && parseInt(node.getAttribute('level'), 10) > i)
          {
            node.style.display = '';
            node = node.nextSibling;
          }
        }
      }
    }

    // Display nodes who have at least one child visible
    for (var i = maxLevel - 1; i >= 0; i--)
    {
      nodes = $('.level' + i);

      var count = nodes.length;
      for (var j = 0; j < count; j++)
      {
        if (nodes[j].style.display == 'none')
        {
          var node = nodes[j].nextSibling;
          while (node != null && node.nodeName == 'TR' && parseInt(node.getAttribute('level'), 10) > i)
          {
            if (node.style.display == '')
            {
              nodes[j].style.display = '';
              break;
            }
            node = node.nextSibling;
          } // while

        }
      }
    }

    alternate(name);
  }


//*********************************************

  function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

  function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

  function eraseCookie(name) {
		createCookie(name,"",-1);
	}

