// JavaScript Document

function ShowBlock(layername)
{
  if (document.getElementById && document.getElementById(layername) != null)
   {
     for (i = 1; i < 4; i++)
     {
      iddiv = 'divid'+i;
	  if (iddiv != layername)
       {
         divi = document.getElementById(iddiv);
         if(divi.style.display=='block')
         divi.style.display = 'none';
       }
       }

	 div = document.getElementById(layername);
        if(div.style.display=='block')
           div.style.display = 'none';
        else
           div.style.display = 'block';
   }
}

function ShowSentense(Divid)
{
  if (document.getElementById && document.getElementById(Divid) != null)
   {
		div = document.getElementById(Divid);
		if (div.style.display == 'block')
		 {
			div.style.display='none';
			 if(document.getElementById(Divid+"_pic"))
			  {
				 document.getElementById(Divid+"_pic").style.background = "url(images/plus.gif) no-repeat 0px 5px";
			   }
		  }
		  else
		  {
			div.style.display='block';
			 if(document.getElementById(Divid+"_pic"))
			 {
				 document.getElementById(Divid+"_pic").style.background = "url(images/minus.gif) no-repeat 0px 5px";
			}
		  }

	 }

}

function trim(s) {
  var i,j;
  for (i = 0; i < s.length && s.charAt(i) == " "; i++);
  for (j = s.length-1; j >= 0 && s.charAt(j) == " "; j--);
  if(i<=j)
    return s.substring(i, j+1);
  else
    return '';
}
function CheckValue(thisname, sourse_text)
{
  var keyword_value = trim(thisname.value);
  if(keyword_value=='')
    thisname.value=sourse_text;
}
function HideValue(thisname, sourse_text)
{
  var keyword_value = trim(thisname.value);
  if(keyword_value==sourse_text)
    thisname.value='';
}
function getObjectPosition(obj)
{
        var x = 0, y = 0;
        while( obj!= null )
        {
          x+= obj.offsetLeft;
          y+= obj.offsetTop;
          obj = obj.offsetParent;
        }
        return new Array(x, y)
}
function setLayerVisibility( id, on )
{
        obj = document.getElementById(id);
        if(on) obj.className = 'menuhover';
        else obj.className = '';
		var layer = document.getElementById('vmd'+id);
        layer.style.visibility = on ? 'visible' : 'hidden';
}
function checkMenuVisibility()
{
        if ( !is_cursor_on_menu && last_menu_id )
        {
                setLayerVisibility(last_menu_id);
                last_menu_id = 0;
        }
}
function setMenuPosition(id)
{
        var parent = document.getElementById(id);
        var coord = getObjectPosition(parent);

        var parent_right = coord[0] + parent.offsetWidth;
        var parent_bottom = coord[1] + parent.offsetHeight;
        var menu_left = coord[0] + (0);
        var menu_top = coord[1] + (0);

		if( menu_top < parent_bottom ) menu_top = parent_bottom;

        var menu = document.getElementById('vmd'+id);

        var menuWidth = menu.offsetWidth;
        var menuHeight = menu.offsetHeight;

		if (document.documentElement && document.documentElement.clientHeight)
		  {
			  windowWidth = document.documentElement.clientWidth;
              windowHeight = document.documentElement.clientHeight;
           }

		else if (document.body)
		  {
              windowWidth = document.body.clientWidth;
              windowHeight = document.body.clientHeight;

           }


        var scrollTop = document.body.scrollTop;
        var scrollLeft = document.body.scrollLeft;

		if( menuHeight + menu_top > windowHeight + scrollTop ) menu_top = windowHeight + scrollTop - menuHeight;
        if( menu_top < scrollTop ) menu_top = scrollTop;

        if( menuWidth + menu_left > windowWidth + scrollLeft ) menu_left = windowWidth + scrollLeft - menuWidth;
        if( menu_left < scrollLeft ) menu_left = scrollLeft;

        menu.style.top = menu_top+'px';
        menu.style.left = menu_left+'px';


}

function changeM( id, on )
{
        if( on && last_menu_id != id )
        {
                if( last_menu_id ) setLayerVisibility(last_menu_id);
                last_menu_id = id;
                setMenuPosition(id);
                setLayerVisibility( id, on );
        }
        is_cursor_on_menu = on;
        setTimeout('checkMenuVisibility()',200);
}


var picsOut=new Array();
var picsOver=new Array();
var objCount = 1;

function preload(name, first, first1) {

  picsOut[objCount] = new Array(2);
  picsOut[objCount][0] = new Image();
  picsOut[objCount][0].src = first;
  picsOut[objCount][1] = name;

  picsOver[objCount] = new Array(2);
  picsOver[objCount][0] = new Image();
  picsOver[objCount][0].src = first1;
  picsOver[objCount][1] = name;
  objCount++;
}

function changeImage(imgId,type,id)
{
	if(document.images)
	{
	  divpar = imgId+'-box';
	  img = document.getElementById(imgId);
	  div = document.getElementById(divpar);
	  if(type == "over")
	  {
	   img.src = picsOver[id][0].src;
	   div.style.backgroundColor = '000000';
	  }
	  else
	  {
	    img.src = picsOut[id][0].src;
	    if(id == 1)
	     div.style.backgroundColor = '003366';
		if(id == 2)
	     div.style.backgroundColor = '33618F';
		if(id == 3)
	     div.style.backgroundColor = '6A87A4';

      }
	}
}

var pics=new Array();
function preload2(name, first) {
  pics[name] = new Image();
  pics[name].src = first;
}
function setImage(imgId)
{
	if(document.images) {
		document.images.big.src = pics['img'+imgId].src;
	}
}
