/* JS CODE */
var GB_ROOT_DIR = "/lib/js/greybox/";

function include(script_filename) 
{
    document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
}

function includeCSS(css_filename) 
{
	document.write('<' + 'link');
    document.write(' language="javascript"');
    document.write(' href="' + css_filename + '" rel="stylesheet" type="text/css"/>');
}

function preloadImg(path)
{
	var img = new Image();
	img.src = path;
}

function showBusySplash()
{
	document.getElementById('BusyBack').style.display = 'block';
}

function hideBusySplash()
{
	document.getElementById('BusyBack').style.display = 'none';
}

function AJAX_loadDivContent(id,uri)
{
	Target = document.getElementById(id)
	if(!Target) { return false; }
	
	showBusySplash();
		
   	JsHttpRequest.query(
          uri, // backend
       	{ },
           // Function is called when an answer arrives. 
           function(result, errors) {
               // Write errors to the debug div.
           	   hideBusySplash();
                // Write the answer.
				
                if (result) {
                  Target.innerHTML = result;
			   }
           },
           true
       );
}


function AJAX_loadPhoto(id,uri)
{
	saveScrollPos();

	Target = document.getElementById(id)
	if(!Target) { return false; }
	
	showBusySplash();
		
   	JsHttpRequest.query(
          uri,
       	{ },
           function(result, errors) {
				
                if (result) {
				
                  Target.innerHTML = result;
				  if(scrollpos_Y) restoreScrollPos();
			      hideBusySplash();
			   }
           },
           true
       );

}

function AJAX_onPhotoLoad()
{	
	if(scrollpos_Y) restoreScrollPos();
	hideBusySplash();
}

var scrollpos_X = 0;
var scrollpos_Y = 0;

function saveScrollPos() 
{ 
  scrollpos_X = document.documentElement.scrollLeft; 
  scrollpos_Y = document.documentElement.scrollTop; 
} 

function restoreScrollPos() 
{
   document.documentElement.scrollLeft = scrollpos_X; 
   document.documentElement.scrollTop = scrollpos_Y;
} 

function LockScrolling()
{
	saveScrollPos();
	document.body.style.overflow='hidden';
}

function UnlockScrolling()
{
	document.body.style.overflow='visible';
	restoreScrollPos();	
}

var newWindow = null;

function OpenWindow (Url,Title, Width, Height) {
  	var win_opt = "toolbar=0,location=0,directories=0,status=0,menubar=0,";
  	win_opt += "scrollbars=1,resizable=1,copyhistory=0,";
  	win_opt += "width=" + Width + ",height=" + Height;
  	newWindow = window.open('',Title,win_opt);
  	if (newWindow != null) {
    if (newWindow.opener == null)
      newWindow.opener = self;
      newWindow.location.href = Url;
	  newWindow.resizeTo(Width,Height);
     if (newWindow.focus) newWindow.focus();
  }
}