// JavaScript Document
//
// 02-May-05 Sort out image paths
// 27-May-05 Sort out Resize Image and add Resize Element

var browser=navigator.appName;

var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var current_image;

if ((browser == "Microsoft Internet Explorer") & (version == "4")) browser = "IE";

function refreshParent() 
{
  window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)
		
 {
    window.opener.progressWindow.close()
  }
  window.close();
}
function resize_image(id,def_w,resize) 
{
  var elem = document.getElementById(id);

  if (elem == undefined || elem == null) return false;
  
  ratio =  document.body.clientWidth/1024;
  
  if (ratio < 0.6) ratio = 0.6;
  if (ratio > 1.8) ratio = 1.8;
  
  ratio = Math.round((ratio*10)+0.5)/10;


  // Smaller/Larger only resize one way. Prevents logos being too big/small
  
  if ((resize == "S") & (document.body.clientWidth > 1024)) ratio = 1;
  if ((resize == "L") & (document.body.clientWidth < 1024)) ratio = 1;
  
  elem.height = elem.height * def_w / elem.width * ratio; 
  
  elem.width  = def_w * ratio; 
}
function resize_font(id,font_size)
{  
  if ((font_size == "") || (font_size == 0))font_size = 12;

  ratio =  document.body.clientWidth/1024;
  
  if (ratio < 0.7) ratio = 0.7;
  if (ratio > 1.8) ratio = 1.8;
  
  ratio = Math.round((ratio*10)+0.5)/10;
             
  font_size = font_size * ratio; 
  
  font_size = Math.round(font_size);
    
  if (font_size < 8) font_size = 9;
  if (font_size >32) font_size = 32;
       
  if (document.layers)          document.layers[id].fontSize = font_size + 'px';
  if (document.getElementById)  document.getElementById(id).style.fontSize = font_size + 'px';  

  //alert(id+" "+font_size+"px");

}
function resize_element(id,def_w) 
{
  var elem = document.getElementById(id);

  if (elem == undefined || elem == null) return false;
  
  ratio =  document.body.clientWidth/1024;
  
  if (ratio < 0.6) ratio = 0.6;
  if (ratio > 1.8) ratio = 1.8;
  
  ratio = Math.round((ratio*10)+0.5)/10;
  
  h = elem.height * def_w / elem.width * ratio; 
  
  w  = (def_w * ratio); 
  
  document.getElementById(id).style.width = w+"px";
  document.getElementById(id).style.height = h+"px";
  
}		

function popUp(URL) 
{
closepopUp;
popup_window = window.open(URL,'Config','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=400,left = 490,top = 312');
}
function closepopUp()
{
 if(false == popup_window.closed) popup_window.close();
}

function confirmDelete()
{
var agree=confirm("Are you sure you wish to delete this entry?");
if (agree)
	return true ;
else
	return false ;
}
function mouseOver(menuid,path)
{
document.getElementById(menuid).style.backgroundImage = "url('"+path+menuid+"_menu_over.gif')";
}
function mouseOut(menuid,path)
{
document.getElementById(menuid).style.backgroundImage = "url('"+path+menuid+"_menu.gif')";
}
function ImageOver(imageid,path,image)
{
if (document.getElementById(imageid))
{

    document.getElementById(imageid).style.display                 = 'none';
    document.getElementById('hover_image').style.display           = 'block';

    width = document.getElementById('hover_default').width;
    height = document.getElementById('hover_default').height;
    align = document.getElementById('hover_default').align;
    hspace = document.getElementById('hover_default').hspace;
    vspace = document.getElementById('hover_default').vspace;
        
    document.getElementById('hover_image').innerHTML = "<img width='"+width+"' height='"+height+"' align='"+align+"' vspace='"+vspace+"' hspace='"+hspace+"' src='"+path+image+"'/>";
}
}
function ImageOut(imageid)
{
if (document.getElementById(imageid))
{
      document.getElementById('hover_image').style.display = 'none';
      document.getElementById(imageid).style.display       = 'block';
}
}

function fn_show(id)
{
      if (document.layers) document.layers[id].display = "block"
      if (document.getElementById) document.getElementById(id).style.display = "block"
}
function fn_hide(id)
{
      if (document.layers) document.layers[id].display = "none"
      if (document.getElementById) document.getElementById(id).style.display = "none"
}
function hidePopup() 
{
      help_id = "popup_box";
      frame_id = "popup_frame";

      //document.getElementById(id).style.visibility = "hidden";
      //document.all[id].style.visibility = "hidden";
      //document.getElementById(id).visibility = "hide";
            
      if (document.layers) document.layers[help_id].visibility = "hide"
      if (document.getElementById) document.getElementById(help_id).style.visibility = "hidden"
      if (document.layers) document.layers[frame_id].visibility = "hide"
      if (document.getElementById) document.getElementById(frame_id).style.visibility = "hidden"
         
}
function showHelp(id,buttonobj) 
{
      var left;
      var top;
      var right;
     
      help_id = "help_text_"+id;
      
      box_id   = "popup_box";
      frame_id = "popup_frame";
                                       
      document.getElementById(box_id).style.visibility = "visible";
      document.getElementById(frame_id).style.visibility = "visible";

      // Position in correct place on the page
      
      left  = getLeftPos(buttonobj) + 25;
      top   = getTopPos(buttonobj) + 25;
      
      if (typeof help_width=="undefined") help_width = 300;
            
      right = left + help_width;
      
      if (right > 1024)  left  = right - help_width - 200;
      if (left < 200)   left  = left + 200;
          
      document.getElementById(box_id).style.left = left + 2 + 'px';
      document.getElementById(box_id).style.top = top + 2 + 'px';
      
      document.getElementById(frame_id).style.left = left + 'px';
      document.getElementById(frame_id).style.top = top + 'px';
      	    
      document.getElementById(box_id).innerHTML = document.getElementById(help_id).innerHTML;
	      	
} 
function getLeftPos(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    
  var page = 0;
  var margin = 0;
          
  return curleft;
  }

  function getTopPos(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
        
  var page = 0;
  var page1 = 0;
  
  return curtop;
  
  }
  
function ZoomImage(id,buttonobj,path) 
{    
      var left;
      var top;

      help_id = "popup_box";
      frame_id = "popup_frame";
                      
      document.getElementById(help_id).style.visibility = "visible";
      document.getElementById(frame_id).style.visibility = "visible";

      // Position in correct place on the page
      
      left  = getLeftPos(buttonobj) + 15;
      top   = getTopPos(buttonobj) + 15;



      // Width of current Image
      
	  width	= buttonobj.offsetWidth; 
 	  height = buttonobj.offsetHeight; 
      

      
	    
      if (typeof zoom_factor_default=="undefined")  zoom_factor_default   = 1.5;    
	    if (typeof zoom_factor_large=="undefined")    zoom_factor_large     = 2;
	    if (typeof zoom_factor_medium=="undefined")   zoom_factor_medium    = 2.5;
	    if (typeof zoom_factor_small=="undefined")    zoom_factor_small     = 3.5;
	 
      image_zoom_width = width * zoom_factor_default;
      image_zoom_height = height * zoom_factor_default;
	    
	    check = width;
	    
      if (height > width) check  = height;
      

	    
	    if (check < 400) 
		  {
		  image_zoom_width = width * zoom_factor_large;
		  image_zoom_height = height * zoom_factor_large;
      }

   	  if (check < 250) 
	  {
          image_zoom_width = width * zoom_factor_medium;
		  image_zoom_height = height * zoom_factor_medium;
      }

	  if (check < 100) 
	  {
          image_zoom_width = width * zoom_factor_small;
		  image_zoom_height = height * zoom_factor_small;
      }
      
      // Calculate the available width & height
                         
      avail_width   = window.innerWidth - 30;    
      avail_height  = window.innerHeight - 30;
            
      if (browser == "IE")
      {                
      avail_width   = document.documentElement.offsetWidth - 30;      
      avail_height  = document.documentElement.offsetHeight - 30;    
      }
      
      // If the Image bigger than available then resize the image
      
      if (image_zoom_width > avail_width) 
      {
          ratio = (avail_width - 20)/image_zoom_width;
      
          image_zoom_width  = image_zoom_width * ratio;
          image_zoom_height = image_zoom_height * ratio;
          left              = 10;
      }
      
      if (image_zoom_height > avail_height) 
      {   
          ratio = (avail_height -20 )/ image_zoom_height;
          image_zoom_width = image_zoom_width * ratio;
          image_zoom_height = image_zoom_height * ratio;
          top              = 10;
      }
      
      // 
      
      right   = left + image_zoom_width;
      bottom  = top + image_zoom_height;
 
      if (right > avail_width)    left = avail_width - image_zoom_width - 20;
      if (bottom > avail_height)  top  = avail_height - image_zoom_height - 20;
      
      if (top < 0) top = 10;
      if (left < 0) left = 10;
      



      if (browser != "IE")
      {
      document.getElementById(help_id).style.position = "fixed";
      document.getElementById(frame_id).style.position = "fixed";
      }
      
      document.getElementById(help_id).style.left = left + 2 + 'px';
      document.getElementById(help_id).style.top = top + 2 + 'px';
      document.getElementById(frame_id).style.left = left + 2 + 'px';
      document.getElementById(frame_id).style.top = top + 2 + 'px'; 
      
      document.getElementById(frame_id).style.width = image_zoom_width;                
      document.getElementById(help_id).style.width = image_zoom_width;  
      
      document.getElementById(frame_id).style.height = image_zoom_height;                
      document.getElementById(help_id).style.height = image_zoom_height;  
   
      document.getElementById(help_id).innerHTML = "<img id='loading' src='"+path+"$$$loading.gif'>"+"<img style='display:none;'id='zoom' onload='flip_images();' title='Click to Close' width='"+image_zoom_width+"' onclick='hidePopup()'"+' src="'+path+id+'">';
      
}  

function flip_images()
{
      document.getElementById('loading').style.display = 'none';
      document.getElementById('zoom').style.display = 'block';
} 		



